Fixing code
This commit is contained in:
parent
f376ed0a8d
commit
335bde935f
|
@ -38,7 +38,6 @@ public class PersistencePostgreSQL extends PersistenceBackend {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void prepareConnection(PersistenceBackendConfiguration configuration) throws Exception {
|
protected void prepareConnection(PersistenceBackendConfiguration configuration) throws Exception {
|
||||||
logger.trace("prepareConnection()");
|
|
||||||
url = configuration.getProperty(URL_PROPERTY_KEY);
|
url = configuration.getProperty(URL_PROPERTY_KEY);
|
||||||
username = configuration.getProperty(USERNAME_PROPERTY_KEY);
|
username = configuration.getProperty(USERNAME_PROPERTY_KEY);
|
||||||
password = configuration.getProperty(PASSWORD_PROPERTY_KEY);
|
password = configuration.getProperty(PASSWORD_PROPERTY_KEY);
|
||||||
|
@ -46,7 +45,6 @@ public class PersistencePostgreSQL extends PersistenceBackend {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void openConnection() throws Exception {
|
protected void openConnection() throws Exception {
|
||||||
logger.trace("openConnection()");
|
|
||||||
try {
|
try {
|
||||||
Class.forName("org.postgresql.Driver");
|
Class.forName("org.postgresql.Driver");
|
||||||
connection = DriverManager.getConnection(url, username, password);
|
connection = DriverManager.getConnection(url, username, password);
|
||||||
|
@ -146,7 +144,6 @@ public class PersistencePostgreSQL extends PersistenceBackend {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void reallyAccount(Record record) throws Exception {
|
protected void reallyAccount(Record record) throws Exception {
|
||||||
logger.trace("reallyAccount()");
|
|
||||||
String sqlCommand = getSQLInsertCommand(record);
|
String sqlCommand = getSQLInsertCommand(record);
|
||||||
statement.executeUpdate(sqlCommand);
|
statement.executeUpdate(sqlCommand);
|
||||||
}
|
}
|
||||||
|
@ -156,13 +153,10 @@ public class PersistencePostgreSQL extends PersistenceBackend {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void clean() throws Exception {
|
protected void clean() throws Exception {}
|
||||||
logger.trace("clean()");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void closeConnection() throws Exception {
|
protected void closeConnection() throws Exception {
|
||||||
logger.trace("closeConnection()");
|
|
||||||
statement.close();
|
statement.close();
|
||||||
connection.commit();
|
connection.commit();
|
||||||
connection.close();
|
connection.close();
|
||||||
|
@ -177,4 +171,4 @@ public class PersistencePostgreSQL extends PersistenceBackend {
|
||||||
return connection.isValid(300);
|
return connection.isValid(300);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
|
@ -4,6 +4,10 @@
|
||||||
package org.gcube.documentstore.persistence;
|
package org.gcube.documentstore.persistence;
|
||||||
|
|
||||||
import org.gcube.accounting.datamodel.UsageRecord;
|
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.gcube.common.authorization.client.exceptions.ObjectNotFound;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
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
|
@Test
|
||||||
public void testSQLStatementString() throws Exception {
|
public void testSQLStatementString() throws Exception {
|
||||||
UsageRecord usageRecord = TestUsageRecord.createTestServiceUsageRecord();
|
UsageRecord usageRecord = TestUsageRecord.createTestServiceUsageRecord();
|
||||||
|
@ -88,7 +104,9 @@ public class PersistencePostgreSQLTest extends ContextTest {
|
||||||
PersistencePostgreSQL persistencePostgreSQL = (PersistencePostgreSQL) persistenceBackend;
|
PersistencePostgreSQL persistencePostgreSQL = (PersistencePostgreSQL) persistenceBackend;
|
||||||
persistencePostgreSQL.newConnection();
|
persistencePostgreSQL.newConnection();
|
||||||
for(int i=0; i<10; i++) {
|
for(int i=0; i<10; i++) {
|
||||||
UsageRecord usageRecord = TestUsageRecord.createTestServiceUsageRecord();
|
UsageRecord usageRecord = getTestAggregatedServiceUsageRecord();
|
||||||
|
persistencePostgreSQL.insert(usageRecord);
|
||||||
|
usageRecord = getTestAggregatedStorageUsageRecord();
|
||||||
persistencePostgreSQL.insert(usageRecord);
|
persistencePostgreSQL.insert(usageRecord);
|
||||||
}
|
}
|
||||||
persistencePostgreSQL.commitAndClose();
|
persistencePostgreSQL.commitAndClose();
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
-- CREATE TYPE operation_result AS ENUM ('SUCCESS', 'FAILED');
|
-- CREATE TYPE operation_result AS ENUM ('SUCCESS', 'FAILED');
|
||||||
CREATE TYPE operation_type AS ENUM ('insert', 'update', 'replace', 'delete', 'invalidate');
|
CREATE TYPE operation_type AS ENUM ('CREATE', 'READ', 'UPDATE', 'DELETE');
|
||||||
CREATE TYPE data_type AS ENUM ('String', 'Time', 'Time_Interval', 'Times_ListOf', 'Text', 'Boolean', 'Number', 'GeoJSON');
|
CREATE TYPE data_type AS ENUM ('STORAGE', 'TREE', 'GEO', 'DATABASE', 'LOCAL', 'OTHER');
|
||||||
CREATE TABLE "storageusagerecord"(
|
CREATE TABLE "storageusagerecord"(
|
||||||
id TEXT NOT NULL,
|
id TEXT NOT NULL,
|
||||||
consumer_id TEXT NOT NULL,
|
consumer_id TEXT NOT NULL,
|
||||||
|
|
Loading…
Reference in New Issue