Fixing code

This commit is contained in:
Luca Frosini 2021-03-15 11:56:13 +01:00
parent f376ed0a8d
commit 335bde935f
3 changed files with 23 additions and 11 deletions

View File

@ -38,7 +38,6 @@ public class PersistencePostgreSQL extends PersistenceBackend {
@Override
protected void prepareConnection(PersistenceBackendConfiguration configuration) throws Exception {
logger.trace("prepareConnection()");
url = configuration.getProperty(URL_PROPERTY_KEY);
username = configuration.getProperty(USERNAME_PROPERTY_KEY);
password = configuration.getProperty(PASSWORD_PROPERTY_KEY);
@ -46,7 +45,6 @@ public class PersistencePostgreSQL extends PersistenceBackend {
@Override
protected void openConnection() throws Exception {
logger.trace("openConnection()");
try {
Class.forName("org.postgresql.Driver");
connection = DriverManager.getConnection(url, username, password);
@ -146,7 +144,6 @@ public class PersistencePostgreSQL extends PersistenceBackend {
@Override
protected void reallyAccount(Record record) throws Exception {
logger.trace("reallyAccount()");
String sqlCommand = getSQLInsertCommand(record);
statement.executeUpdate(sqlCommand);
}
@ -156,13 +153,10 @@ public class PersistencePostgreSQL extends PersistenceBackend {
}
@Override
protected void clean() throws Exception {
logger.trace("clean()");
}
protected void clean() throws Exception {}
@Override
protected void closeConnection() throws Exception {
logger.trace("closeConnection()");
statement.close();
connection.commit();
connection.close();
@ -177,4 +171,4 @@ public class PersistencePostgreSQL extends PersistenceBackend {
return connection.isValid(300);
};
}
}

View File

@ -4,6 +4,10 @@
package org.gcube.documentstore.persistence;
import org.gcube.accounting.datamodel.UsageRecord;
import org.gcube.accounting.datamodel.aggregation.AggregatedServiceUsageRecord;
import org.gcube.accounting.datamodel.aggregation.AggregatedStorageUsageRecord;
import org.gcube.accounting.datamodel.usagerecords.ServiceUsageRecord;
import org.gcube.accounting.datamodel.usagerecords.StorageUsageRecord;
import org.gcube.common.authorization.client.exceptions.ObjectNotFound;
import org.junit.Assert;
import org.junit.Test;
@ -52,6 +56,18 @@ public class PersistencePostgreSQLTest extends ContextTest {
}
*/
protected AggregatedServiceUsageRecord getTestAggregatedServiceUsageRecord() throws Exception {
ServiceUsageRecord serviceUsageRecord = TestUsageRecord.createTestServiceUsageRecord();
AggregatedServiceUsageRecord aggregatedServiceUsageRecord = new AggregatedServiceUsageRecord(serviceUsageRecord);
return aggregatedServiceUsageRecord;
}
protected AggregatedStorageUsageRecord getTestAggregatedStorageUsageRecord() throws Exception {
StorageUsageRecord storageUsageRecord = TestUsageRecord.createTestStorageUsageRecord();
AggregatedStorageUsageRecord aggregatedStorageUsageRecord = new AggregatedStorageUsageRecord(storageUsageRecord);
return aggregatedStorageUsageRecord;
}
@Test
public void testSQLStatementString() throws Exception {
UsageRecord usageRecord = TestUsageRecord.createTestServiceUsageRecord();
@ -88,7 +104,9 @@ public class PersistencePostgreSQLTest extends ContextTest {
PersistencePostgreSQL persistencePostgreSQL = (PersistencePostgreSQL) persistenceBackend;
persistencePostgreSQL.newConnection();
for(int i=0; i<10; i++) {
UsageRecord usageRecord = TestUsageRecord.createTestServiceUsageRecord();
UsageRecord usageRecord = getTestAggregatedServiceUsageRecord();
persistencePostgreSQL.insert(usageRecord);
usageRecord = getTestAggregatedStorageUsageRecord();
persistencePostgreSQL.insert(usageRecord);
}
persistencePostgreSQL.commitAndClose();

View File

@ -1,6 +1,6 @@
-- CREATE TYPE operation_result AS ENUM ('SUCCESS', 'FAILED');
CREATE TYPE operation_type AS ENUM ('insert', 'update', 'replace', 'delete', 'invalidate');
CREATE TYPE data_type AS ENUM ('String', 'Time', 'Time_Interval', 'Times_ListOf', 'Text', 'Boolean', 'Number', 'GeoJSON');
CREATE TYPE operation_type AS ENUM ('CREATE', 'READ', 'UPDATE', 'DELETE');
CREATE TYPE data_type AS ENUM ('STORAGE', 'TREE', 'GEO', 'DATABASE', 'LOCAL', 'OTHER');
CREATE TABLE "storageusagerecord"(
id TEXT NOT NULL,
consumer_id TEXT NOT NULL,