mirror of
https://github.com/zyphlar/LanternPowerMonitor.git
synced 2024-03-08 14:07:47 +00:00
Migrating from from wiringpi to pigpio. This increases the sample rate by a factor of 3 and will allow creation of a board that can monitor over 30 breakers with a single raspberry pi.
This is based on pi4j 2.0 which is in a beta status. I have fixed a few bugs in a local version of pi4j 2.0 to get it to work but I haven't submitted those changes to pi4j yet. This change requires a migration to Java 11 and will *NOT* be backwards compatible. Upgrading to this hub software will require that java 11 and pigpio be installed on the hub. This can be done from an ssh session with the following commands: apt-get update apt-get install openjdk-11-jre-headless apt-get install pigpio Alternatively, you can download a new sd image, reflash your sd card, and re-adopt your hub.
This commit is contained in:
@@ -1,13 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.lanternsoftware.util</groupId>
|
||||
<artifactId>lantern-util-dao</artifactId>
|
||||
<name>lantern-util-dao</name>
|
||||
<version>1.0.0</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<parent>
|
||||
<groupId>com.lanternsoftware.util</groupId>
|
||||
<artifactId>util</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
@@ -38,8 +42,8 @@
|
||||
<optimize>true</optimize>
|
||||
<showDeprecation>true</showDeprecation>
|
||||
<encoding>UTF-8</encoding>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
<source>${maven.compiler.source}</source>
|
||||
<target>${maven.compiler.target}</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package com.lanternsoftware.util.dao;
|
||||
|
||||
import java.util.Arrays;
|
||||
import com.lanternsoftware.util.CollectionUtils;
|
||||
import com.lanternsoftware.util.NullUtils;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
@@ -11,10 +13,6 @@ import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import com.lanternsoftware.util.CollectionUtils;
|
||||
import com.lanternsoftware.util.ITransformer;
|
||||
import com.lanternsoftware.util.NullUtils;
|
||||
|
||||
public abstract class AbstractDaoProxy implements IDaoProxy {
|
||||
private ExecutorService executor;
|
||||
private int maxThreads = 50;
|
||||
@@ -57,37 +55,37 @@ public abstract class AbstractDaoProxy implements IDaoProxy {
|
||||
|
||||
@Override
|
||||
public <T> Future<List<T>> queryAsync(Class<T> _class, DaoQuery _query) {
|
||||
return submit(new QueryExecution<T>(this, _class, _query));
|
||||
return submit(new QueryExecution<>(this, _class, _query));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Future<List<T>> queryAsync(Class<T> _class, DaoQuery _query, DaoSort _sort) {
|
||||
return submit(new QueryExecution<T>(this, _class, _query, _sort));
|
||||
return submit(new QueryExecution<>(this, _class, _query, _sort));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Future<List<T>> queryAsync(Class<T> _class, DaoQuery _query, Collection<String> _fields) {
|
||||
return submit(new QueryExecution<T>(this, _class, _query, _fields));
|
||||
return submit(new QueryExecution<>(this, _class, _query, _fields));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Future<List<T>> queryAsync(Class<T> _class, DaoQuery _query, Collection<String> _fields, DaoSort _sort) {
|
||||
return submit(new QueryExecution<T>(this, _class, _query, _fields, _sort));
|
||||
return submit(new QueryExecution<>(this, _class, _query, _fields, _sort));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T, V> Future<List<V>> queryWithFinalizer(Class<T> _class, DaoQuery _query, Collection<String> _fields, DaoSort _sort, QueryFinalizer<T, V> _finalizer) {
|
||||
return submit(new QueryFinalizerExecution<T, V>(this, _class, _query, _fields, _sort, _finalizer));
|
||||
return submit(new QueryFinalizerExecution<>(this, _class, _query, _fields, _sort, _finalizer));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> DaoPage<T> queryPage(Class<T> _class, DaoQuery _query, Collection<String> _fields, DaoSort _sort, int _offset, int _count) {
|
||||
return new DaoPage<T>(query(_class, _query, _fields, _sort, _offset, _count), count(_class, _query));
|
||||
return new DaoPage<>(query(_class, _query, _fields, _sort, _offset, _count), count(_class, _query));
|
||||
}
|
||||
|
||||
@Override
|
||||
public DaoPage<DaoEntity> queryForEntitiesPage(String _tableName, DaoQuery _query, Collection<String> _fields, DaoSort _sort, int _offset, int _count) {
|
||||
return new DaoPage<DaoEntity>(queryForEntities(_tableName, _query, _fields, _sort, _offset, _count), count(_tableName, _query));
|
||||
return new DaoPage<>(queryForEntities(_tableName, _query, _fields, _sort, _offset, _count), count(_tableName, _query));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -112,22 +110,22 @@ public abstract class AbstractDaoProxy implements IDaoProxy {
|
||||
|
||||
@Override
|
||||
public <T> Future<T> queryOneAsync(Class<T> _class, DaoQuery _query) {
|
||||
return submit(new QueryOneExecution<T>(this, _class, _query));
|
||||
return submit(new QueryOneExecution<>(this, _class, _query));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Future<T> queryOneAsync(Class<T> _class, DaoQuery _query, DaoSort _sort) {
|
||||
return submit(new QueryOneExecution<T>(this, _class, _query, _sort));
|
||||
return submit(new QueryOneExecution<>(this, _class, _query, _sort));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Future<T> queryOneAsync(Class<T> _class, DaoQuery _query, Collection<String> _fields) {
|
||||
return submit(new QueryOneExecution<T>(this, _class, _query, _fields));
|
||||
return submit(new QueryOneExecution<>(this, _class, _query, _fields));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Future<T> queryOneAsync(Class<T> _class, DaoQuery _query, Collection<String> _fields, DaoSort _sort) {
|
||||
return submit(new QueryOneExecution<T>(this, _class, _query, _fields, _sort));
|
||||
return submit(new QueryOneExecution<>(this, _class, _query, _fields, _sort));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -157,7 +155,7 @@ public abstract class AbstractDaoProxy implements IDaoProxy {
|
||||
|
||||
@Override
|
||||
public <T> DaoPage<T> queryImportantPage(Class<T> _class, DaoQuery _query, DaoSort _sort, int _offset, int _count) {
|
||||
return new DaoPage<T>(queryImportant(_class, _query, _sort, _offset, _count), count(_class, _query));
|
||||
return new DaoPage<>(queryImportant(_class, _query, _sort, _offset, _count), count(_class, _query));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -247,22 +245,12 @@ public abstract class AbstractDaoProxy implements IDaoProxy {
|
||||
|
||||
@Override
|
||||
public List<String> queryForField(Class<?> _class, DaoQuery _query, final String _field, DaoSort _sort) {
|
||||
return CollectionUtils.transform(queryForEntities(DaoSerializer.getTableName(_class, getType()), _query, Arrays.asList(_field), _sort), new ITransformer<DaoEntity, String>() {
|
||||
@Override
|
||||
public String transform(DaoEntity _daoEntity) {
|
||||
return DaoSerializer.getString(_daoEntity, _field);
|
||||
}
|
||||
});
|
||||
return CollectionUtils.transform(queryForEntities(DaoSerializer.getTableName(_class, getType()), _query, List.of(_field), _sort), _daoEntity -> DaoSerializer.getString(_daoEntity, _field));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> queryForField(String _tableName, DaoQuery _query, final String _field) {
|
||||
return CollectionUtils.transform(queryForEntities(_tableName, _query, Arrays.asList(_field)), new ITransformer<DaoEntity, String>() {
|
||||
@Override
|
||||
public String transform(DaoEntity _daoEntity) {
|
||||
return DaoSerializer.getString(_daoEntity, _field);
|
||||
}
|
||||
});
|
||||
return CollectionUtils.transform(queryForEntities(_tableName, _query, List.of(_field)), _daoEntity -> DaoSerializer.getString(_daoEntity, _field));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -272,7 +260,7 @@ public abstract class AbstractDaoProxy implements IDaoProxy {
|
||||
|
||||
@Override
|
||||
public <T> Map<String, T> save(Collection<T> _objects) {
|
||||
Map<String, T> ids = new HashMap<String, T>();
|
||||
Map<String, T> ids = new HashMap<>();
|
||||
for (T o : _objects) {
|
||||
String id = save(o);
|
||||
if (NullUtils.isNotEmpty(id))
|
||||
@@ -284,6 +272,8 @@ public abstract class AbstractDaoProxy implements IDaoProxy {
|
||||
@Override
|
||||
public Map<String, DaoEntity> save(Class<?> _class, Collection<DaoEntity> _entities) {
|
||||
Map<String, DaoEntity> ids = new HashMap<>();
|
||||
if (_entities == null)
|
||||
return ids;
|
||||
for (DaoEntity e : _entities) {
|
||||
ids.put(saveEntity(_class, e), e);
|
||||
}
|
||||
@@ -328,12 +318,7 @@ public abstract class AbstractDaoProxy implements IDaoProxy {
|
||||
}
|
||||
|
||||
protected <T> List<T> toObjects(List<DaoEntity> _entities, final Class<T> _class) {
|
||||
return CollectionUtils.transform(_entities, new ITransformer<DaoEntity, T>() {
|
||||
@Override
|
||||
public T transform(DaoEntity _daoEntity) {
|
||||
return DaoSerializer.fromDaoEntity(_daoEntity, _class, getType());
|
||||
}
|
||||
});
|
||||
return CollectionUtils.transform(_entities, _daoEntity -> DaoSerializer.fromDaoEntity(_daoEntity, _class, getType()));
|
||||
}
|
||||
protected DaoQuery prepareQuery(DaoQuery _query) {
|
||||
if (queryPreparer == null)
|
||||
|
||||
@@ -49,7 +49,7 @@ public class JdbcProxy extends AbstractJdbcProxy {
|
||||
else
|
||||
driver = "oracle.jdbc.driver.OracleDriver";
|
||||
try {
|
||||
DriverManager.registerDriver(Class.forName(driver).asSubclass(Driver.class).newInstance());
|
||||
DriverManager.registerDriver(Class.forName(driver).asSubclass(Driver.class).getDeclaredConstructor().newInstance());
|
||||
JdbcProxy proxy = new JdbcProxy(DriverManager.getConnection(_connectionString, _username, _password));
|
||||
proxy.databaseType = _type;
|
||||
return proxy;
|
||||
|
||||
Reference in New Issue
Block a user