|
|
|
@ -9,8 +9,10 @@ import java.sql.Statement;
|
|
|
|
|
import java.time.OffsetDateTime;
|
|
|
|
|
import java.util.Calendar;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.HashSet;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.Set;
|
|
|
|
|
import java.util.SortedMap;
|
|
|
|
|
import java.util.SortedSet;
|
|
|
|
|
import java.util.TreeMap;
|
|
|
|
@ -84,12 +86,57 @@ public class AccountingPersistenceQueryPostgreSQL implements AccountingPersisten
|
|
|
|
|
this.usageRecordDB = new HashMap<>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public SortedMap<Calendar, Info> getTimeSeries(Class<? extends AggregatedRecord<?, ?>> clz,
|
|
|
|
|
TemporalConstraint temporalConstraint, List<Filter> filters, Set<String> contexts)
|
|
|
|
|
throws Exception {
|
|
|
|
|
Connection connection = getConnection(clz);
|
|
|
|
|
try {
|
|
|
|
|
Statement statement = connection.createStatement();
|
|
|
|
|
|
|
|
|
|
SortedMap<Calendar, Info> result = new TreeMap<>();
|
|
|
|
|
|
|
|
|
|
Query query = new Query(clz);
|
|
|
|
|
query.setTemporalConstraint(temporalConstraint);
|
|
|
|
|
query.setFilters(filters);
|
|
|
|
|
query.setContexts(contexts);
|
|
|
|
|
|
|
|
|
|
String sql = query.getTimeSeriesQuery();
|
|
|
|
|
|
|
|
|
|
List<String> requestedTableField = query.getRequestedTableField();
|
|
|
|
|
RecordToDBMapper recordToDBMapper = query.getRecordToDBMapper();
|
|
|
|
|
|
|
|
|
|
ResultSet resultSet = statement.executeQuery(sql);
|
|
|
|
|
|
|
|
|
|
while (resultSet.next()) {
|
|
|
|
|
OffsetDateTime offsetDateTime = resultSet.getObject(Query.DATE_OF_TIMESERIES_AS_FIELD, OffsetDateTime.class);
|
|
|
|
|
Calendar calendar = getCalendar(offsetDateTime);
|
|
|
|
|
|
|
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
|
|
|
|
|
|
|
for(String tableField : requestedTableField) {
|
|
|
|
|
String usageRecordField = recordToDBMapper.getUsageRecordField(tableField);
|
|
|
|
|
Object object = resultSet.getObject(tableField);
|
|
|
|
|
jsonObject.put(usageRecordField, object);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Info info = new Info(calendar, jsonObject);
|
|
|
|
|
result.put(calendar, info);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}finally {
|
|
|
|
|
connection.close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public SortedMap<Calendar, Info> getTimeSeries(Class<? extends AggregatedRecord<?, ?>> clz,
|
|
|
|
|
TemporalConstraint temporalConstraint, List<Filter> filters)
|
|
|
|
|
throws DuplicatedKeyFilterException, KeyException, ValueException, Exception {
|
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
return null;
|
|
|
|
|
String currentScope = AccountingPersistenceBackendQuery.getScopeToQuery();
|
|
|
|
|
Set<String> contexts = new HashSet<>();
|
|
|
|
|
contexts.add(currentScope);
|
|
|
|
|
return getTimeSeries(clz, temporalConstraint, filters, contexts);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected Calendar getCalendar(OffsetDateTime offsetDateTime) {
|
|
|
|
@ -103,38 +150,7 @@ public class AccountingPersistenceQueryPostgreSQL implements AccountingPersisten
|
|
|
|
|
public SortedMap<Calendar, Info> getNoContextTimeSeries(Class<? extends AggregatedRecord<?, ?>> clz,
|
|
|
|
|
TemporalConstraint temporalConstraint, List<Filter> filters)
|
|
|
|
|
throws DuplicatedKeyFilterException, KeyException, ValueException, Exception {
|
|
|
|
|
Connection connection = getConnection(clz);
|
|
|
|
|
Statement statement = connection.createStatement();
|
|
|
|
|
|
|
|
|
|
SortedMap<Calendar, Info> result = new TreeMap<>();
|
|
|
|
|
|
|
|
|
|
Query query = new Query(clz);
|
|
|
|
|
query.setTemporalConstraint(temporalConstraint);
|
|
|
|
|
query.setFilters(filters);
|
|
|
|
|
String sql = query.getNoContextTimeSeriesQuery();
|
|
|
|
|
|
|
|
|
|
List<String> requestedTableField = query.getRequestedTableField();
|
|
|
|
|
RecordToDBMapper recordToDBMapper = query.getRecordToDBMapper();
|
|
|
|
|
|
|
|
|
|
ResultSet resultSet = statement.executeQuery(sql);
|
|
|
|
|
|
|
|
|
|
while (resultSet.next()) {
|
|
|
|
|
OffsetDateTime offsetDateTime = resultSet.getObject(Query.DATE_OF_TIMESERIES_AS_FIELD, OffsetDateTime.class);
|
|
|
|
|
Calendar calendar = getCalendar(offsetDateTime);
|
|
|
|
|
|
|
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
|
|
|
|
|
|
|
for(String tableField : requestedTableField) {
|
|
|
|
|
String usageRecordField = recordToDBMapper.getUsageRecordField(tableField);
|
|
|
|
|
Object object = resultSet.getObject(tableField);
|
|
|
|
|
jsonObject.put(usageRecordField, object);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Info info = new Info(calendar, jsonObject);
|
|
|
|
|
result.put(calendar, info);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
return getTimeSeries(clz, temporalConstraint, filters, null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@ -145,6 +161,13 @@ public class AccountingPersistenceQueryPostgreSQL implements AccountingPersisten
|
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public SortedSet<NumberedFilter> getFilterValues(Class<? extends AggregatedRecord<?, ?>> clz,
|
|
|
|
|
TemporalConstraint temporalConstraint, List<Filter> filters, String key) throws Exception {
|
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public SortedSet<NumberedFilter> getNextPossibleValues(Class<? extends AggregatedRecord<?, ?>> clz,
|
|
|
|
@ -164,15 +187,7 @@ public class AccountingPersistenceQueryPostgreSQL implements AccountingPersisten
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void close() throws Exception {
|
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public SortedSet<NumberedFilter> getFilterValues(Class<? extends AggregatedRecord<?, ?>> clz,
|
|
|
|
|
TemporalConstraint temporalConstraint, List<Filter> filters, String key) throws Exception {
|
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
return null;
|
|
|
|
|
// OK
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|