|
|
|
@ -62,9 +62,40 @@ public class AccountingPersistenceQueryPostgreSQL implements AccountingPersisten
|
|
|
|
|
protected Set<String> contexts;
|
|
|
|
|
protected Collection<Filter> filters;
|
|
|
|
|
|
|
|
|
|
protected RecordToDBMapping recordToDBMapping;
|
|
|
|
|
|
|
|
|
|
static {
|
|
|
|
|
// One Record per package is enough
|
|
|
|
|
RecordUtility.addRecordPackage(ServiceUsageRecord.class.getPackage());
|
|
|
|
|
RecordUtility.addRecordPackage(AggregatedServiceUsageRecord.class.getPackage());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public AccountingPersistenceQueryPostgreSQL() {
|
|
|
|
|
objectMapper = new ObjectMapper();
|
|
|
|
|
this.objectMapper = new ObjectMapper();
|
|
|
|
|
this.recordToDBMapping = new RecordToDBMapping();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void prepareConnection(AccountingPersistenceBackendQueryConfiguration configuration) throws Exception {
|
|
|
|
|
this.configuration = configuration;
|
|
|
|
|
Map<String, Class<? extends AggregatedRecord<?,?>>> aggregatedRecords = RecordUtility.getAggregatedRecordClassesFound();
|
|
|
|
|
for(String typeName : aggregatedRecords.keySet()) {
|
|
|
|
|
try {
|
|
|
|
|
Class<? extends AggregatedRecord<?,?>> clz = aggregatedRecords.get(typeName);
|
|
|
|
|
recordToDBMapping.addRecordToDB(clz, configuration);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
new RuntimeException(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected Connection getConnection(Class<? extends AggregatedRecord<?, ?>> clz) throws Exception {
|
|
|
|
|
RecordToDBConnection recordDBConnection = recordToDBMapping.getRecordDBInfo(clz);
|
|
|
|
|
if(recordDBConnection == null) {
|
|
|
|
|
recordToDBMapping.addRecordToDB(clz, configuration);
|
|
|
|
|
recordDBConnection = recordToDBMapping.getRecordDBInfo(clz);
|
|
|
|
|
}
|
|
|
|
|
return recordDBConnection.getConnection();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@ -88,35 +119,10 @@ public class AccountingPersistenceQueryPostgreSQL implements AccountingPersisten
|
|
|
|
|
this.filters = (Collection<Filter>) filters;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static {
|
|
|
|
|
// One Record per package is enough
|
|
|
|
|
RecordUtility.addRecordPackage(ServiceUsageRecord.class.getPackage());
|
|
|
|
|
RecordUtility.addRecordPackage(AggregatedServiceUsageRecord.class.getPackage());
|
|
|
|
|
public RecordToDBMapping getRecordToDBMapping() {
|
|
|
|
|
return recordToDBMapping;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected Connection getConnection(Class<? extends AggregatedRecord<?, ?>> clz) throws Exception {
|
|
|
|
|
RecordToDBConnection recordDBInfo = RecordToDBMapping.getRecordDBInfo(clz);
|
|
|
|
|
if(recordDBInfo == null) {
|
|
|
|
|
RecordToDBMapping.addRecordToDB(clz, configuration);
|
|
|
|
|
recordDBInfo = RecordToDBMapping.getRecordDBInfo(clz);
|
|
|
|
|
}
|
|
|
|
|
return recordDBInfo.getConnection();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void prepareConnection(AccountingPersistenceBackendQueryConfiguration configuration) throws Exception {
|
|
|
|
|
this.configuration = configuration;
|
|
|
|
|
Map<String, Class<? extends AggregatedRecord<?,?>>> aggregatedRecords = RecordUtility.getAggregatedRecordClassesFound();
|
|
|
|
|
for(String typeName : aggregatedRecords.keySet()) {
|
|
|
|
|
try {
|
|
|
|
|
Class<? extends AggregatedRecord<?,?>> clz = aggregatedRecords.get(typeName);
|
|
|
|
|
RecordToDBMapping.addRecordToDB(clz, configuration);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
new RuntimeException(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected void addProperty(ObjectNode objectNode, String key, Object value) {
|
|
|
|
|
if(value instanceof Number) {
|
|
|
|
|
|
|
|
|
@ -149,7 +155,7 @@ public class AccountingPersistenceQueryPostgreSQL implements AccountingPersisten
|
|
|
|
|
String sql = query.getTimeSeriesQuery();
|
|
|
|
|
|
|
|
|
|
Set<String> requestedTableField = query.getRequestedTableField();
|
|
|
|
|
RecordToDBFields recordToDBMapper = query.getRecordToDBMapper();
|
|
|
|
|
RecordToDBFields recordToDBMapper = query.getRecordToDBFields();
|
|
|
|
|
|
|
|
|
|
logger.trace("Going to request the following query: {}", sql);
|
|
|
|
|
ResultSet resultSet = statement.executeQuery(sql);
|
|
|
|
@ -232,15 +238,15 @@ public class AccountingPersistenceQueryPostgreSQL implements AccountingPersisten
|
|
|
|
|
String sql = query.getNextPossibleValueQuery();
|
|
|
|
|
|
|
|
|
|
// List<String> requestedTableField = query.getRequestedTableField();
|
|
|
|
|
RecordToDBFields recordToDBMapper = query.getRecordToDBMapper();
|
|
|
|
|
RecordToDBFields recordToDBFields = query.getRecordToDBFields();
|
|
|
|
|
|
|
|
|
|
logger.trace("Going to request the following query: {}", sql);
|
|
|
|
|
ResultSet resultSet = statement.executeQuery(sql);
|
|
|
|
|
|
|
|
|
|
String tableFieldORderingProperty = recordToDBMapper.getTableField(orderingProperty);
|
|
|
|
|
String tableFieldORderingProperty = recordToDBFields.getTableField(orderingProperty);
|
|
|
|
|
|
|
|
|
|
while (resultSet.next()) {
|
|
|
|
|
String tableFieldKey = recordToDBMapper.getTableField(key);
|
|
|
|
|
String tableFieldKey = recordToDBFields.getTableField(key);
|
|
|
|
|
Object value = resultSet.getObject(tableFieldKey);
|
|
|
|
|
|
|
|
|
|
Object numberObject = resultSet.getObject(tableFieldORderingProperty);
|
|
|
|
@ -293,7 +299,7 @@ public class AccountingPersistenceQueryPostgreSQL implements AccountingPersisten
|
|
|
|
|
query.setRecordId(recordId);
|
|
|
|
|
String sql = query.getRecordQuery();
|
|
|
|
|
|
|
|
|
|
RecordToDBFields recordToDBMapper = query.getRecordToDBMapper();
|
|
|
|
|
RecordToDBFields recordToDBFields = query.getRecordToDBFields();
|
|
|
|
|
|
|
|
|
|
ResultSet resultSet = statement.executeQuery(sql);
|
|
|
|
|
resultSet.next();
|
|
|
|
@ -302,7 +308,7 @@ public class AccountingPersistenceQueryPostgreSQL implements AccountingPersisten
|
|
|
|
|
Set<String> requiredFields = instance.getRequiredFields();
|
|
|
|
|
|
|
|
|
|
for(String recordField : requiredFields) {
|
|
|
|
|
String tableField = recordToDBMapper.getTableField(recordField);
|
|
|
|
|
String tableField = recordToDBFields.getTableField(recordField);
|
|
|
|
|
Serializable serializable;
|
|
|
|
|
switch (recordField) {
|
|
|
|
|
case AggregatedRecord.START_TIME: case AggregatedRecord.END_TIME: case AggregatedRecord.CREATION_TIME:
|
|
|
|
|