Implementing library
This commit is contained in:
parent
9c967f5e32
commit
2efd3e3d09
|
@ -30,6 +30,7 @@ import org.gcube.accounting.analytics.persistence.AccountingPersistenceBackendQu
|
|||
import org.gcube.accounting.analytics.persistence.AccountingPersistenceBackendQueryConfiguration;
|
||||
import org.gcube.accounting.analytics.persistence.AccountingPersistenceQuery;
|
||||
import org.gcube.accounting.datamodel.aggregation.AggregatedServiceUsageRecord;
|
||||
import org.gcube.accounting.datamodel.aggregation.AggregatedStorageStatusRecord;
|
||||
import org.gcube.accounting.datamodel.usagerecords.ServiceUsageRecord;
|
||||
import org.gcube.accounting.persistence.AccountingPersistenceConfiguration;
|
||||
import org.gcube.accounting.utility.postgresql.RecordToDBConnection;
|
||||
|
@ -196,7 +197,7 @@ public class AccountingPersistenceQueryPostgreSQL implements AccountingPersisten
|
|||
query.setTemporalConstraint(temporalConstraint);
|
||||
query.setFilters(filters);
|
||||
query.setContexts(contexts);
|
||||
query.setFieldOfRequesteValues(key);
|
||||
query.setTableFieldToRequest(key);
|
||||
query.setOrderByField(orderingProperty);
|
||||
query.setLimit(limit);
|
||||
|
||||
|
@ -301,6 +302,31 @@ public class AccountingPersistenceQueryPostgreSQL implements AccountingPersisten
|
|||
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortedSet<String> getSpaceProvidersIds() throws Exception {
|
||||
Class<? extends AggregatedRecord<?, ?>> aggregatedRecordClass = AggregatedStorageStatusRecord.class;
|
||||
Connection connection = getConnection(aggregatedRecordClass);
|
||||
try {
|
||||
Statement statement = connection.createStatement();
|
||||
|
||||
Query query = new Query(aggregatedRecordClass);
|
||||
query.setTableFieldToRequest(AggregatedStorageStatusRecord.PROVIDER_ID);
|
||||
String sql = query.getDinstinctValuesQuery();
|
||||
|
||||
SortedSet<String> providersIds = new TreeSet<>();
|
||||
ResultSet resultSet = statement.executeQuery(sql);
|
||||
|
||||
while (resultSet.next()) {
|
||||
String id = resultSet.getString(1);
|
||||
providersIds.add(id);
|
||||
}
|
||||
|
||||
return providersIds;
|
||||
}finally {
|
||||
connection.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UsageValue> getUsageValueQuotaTotal(List<UsageValue> listUsage) throws Exception {
|
||||
return null;
|
||||
|
@ -312,11 +338,6 @@ public class AccountingPersistenceQueryPostgreSQL implements AccountingPersisten
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortedSet<String> getSpaceProvidersIds() throws Exception {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws Exception {
|
||||
// OK
|
||||
|
|
|
@ -31,7 +31,7 @@ public class Query extends PostgreSQLQuery {
|
|||
protected List<Filter> filters;
|
||||
protected Set<String> contexts;
|
||||
|
||||
private String fieldOfRequesteValues;
|
||||
private String tableFieldToRequest;
|
||||
private String orderByField;
|
||||
private Integer limit;
|
||||
|
||||
|
@ -58,8 +58,8 @@ public class Query extends PostgreSQLQuery {
|
|||
this.contexts = contexts;
|
||||
}
|
||||
|
||||
public void setFieldOfRequesteValues(String fieldOfRequesteValues) {
|
||||
this.fieldOfRequesteValues = fieldOfRequesteValues;
|
||||
public void setTableFieldToRequest(String tableFieldToRequest) {
|
||||
this.tableFieldToRequest = tableFieldToRequest;
|
||||
}
|
||||
|
||||
public void setOrderByField(String orderByField) {
|
||||
|
@ -234,7 +234,7 @@ public class Query extends PostgreSQLQuery {
|
|||
|
||||
protected void addGroupAndOrderByForOrderByField() {
|
||||
stringBuffer.append(" GROUP BY ");
|
||||
String dbField = getTableField(fieldOfRequesteValues);
|
||||
String dbField = getTableField(tableFieldToRequest);
|
||||
stringBuffer.append(dbField);
|
||||
stringBuffer.append(" ORDER BY ");
|
||||
stringBuffer.append(orderByField);
|
||||
|
@ -251,7 +251,7 @@ public class Query extends PostgreSQLQuery {
|
|||
}
|
||||
|
||||
protected void addRequestedField() {
|
||||
String dbField = getTableField(fieldOfRequesteValues);
|
||||
String dbField = getTableField(tableFieldToRequest);
|
||||
stringBuffer.append(dbField);
|
||||
requestedTableField.add(dbField);
|
||||
stringBuffer.append(", SUM(");
|
||||
|
@ -315,5 +315,18 @@ public class Query extends PostgreSQLQuery {
|
|||
appendString(recordId);
|
||||
return stringBuffer.toString();
|
||||
}
|
||||
|
||||
public String getDinstinctValuesQuery() {
|
||||
String dbField = getTableField(tableFieldToRequest);
|
||||
requestedTableField.add(dbField);
|
||||
|
||||
newQuery();
|
||||
stringBuffer.append("DISTINCT ");
|
||||
stringBuffer.append(dbField);
|
||||
stringBuffer.append(" FROM ");
|
||||
stringBuffer.append(recordToDBFields.getTableName());
|
||||
|
||||
return stringBuffer.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -81,7 +81,7 @@ public class QueryTest extends ContextTest {
|
|||
query.setTemporalConstraint(temporalConstraint);
|
||||
query.setFilters(filters);
|
||||
query.setContexts(contexts);
|
||||
query.setFieldOfRequesteValues(ServiceUsageRecord.CALLED_METHOD);
|
||||
query.setTableFieldToRequest(ServiceUsageRecord.CALLED_METHOD);
|
||||
query.setOrderByField(AccountingPersistenceQuery.getDefaultOrderingProperties(AggregatedServiceUsageRecord.class));
|
||||
ret = query.getNextPossibleValueQuery();
|
||||
logger.debug(ret);
|
||||
|
|
Loading…
Reference in New Issue