diff --git a/src/main/java/org/gcube/accounting/persistence/AccountingPersistence.java b/src/main/java/org/gcube/accounting/persistence/AccountingPersistence.java index e2650ad..c530be0 100644 --- a/src/main/java/org/gcube/accounting/persistence/AccountingPersistence.java +++ b/src/main/java/org/gcube/accounting/persistence/AccountingPersistence.java @@ -16,10 +16,14 @@ import org.gcube.documentstore.records.Record; */ public class AccountingPersistence { - protected PersistenceBackend persistenceBackend; + protected String scope; protected AccountingPersistence(String scope){ - persistenceBackend = PersistenceBackendFactory.getPersistenceBackend(scope); + this.scope = scope; + } + + private PersistenceBackend getAccountingPersistence(){ + return PersistenceBackendFactory.getPersistenceBackend(this.scope); } /** @@ -33,18 +37,18 @@ public class AccountingPersistence { */ public void account(final Record record) throws InvalidValueException { try { - persistenceBackend.account(record); + getAccountingPersistence().account(record); } catch (org.gcube.documentstore.exception.InvalidValueException e) { throw new InvalidValueException(e); } } public void flush(long timeout, TimeUnit timeUnit) throws Exception { - persistenceBackend.flush(timeout, timeUnit); + getAccountingPersistence().flush(timeout, timeUnit); } public void close() throws Exception{ - persistenceBackend.close(); + getAccountingPersistence().close(); } }