Add a openConnection and disconnect

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-publishing/document-store-lib@141600 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Alessandro Pieve 2017-01-17 11:04:47 +00:00
parent 08dea0eef3
commit f3bb13279e
4 changed files with 48 additions and 3 deletions

View File

@ -5,11 +5,21 @@
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.wst.common.project.facet.core.builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.validation.validationbuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
@ -17,7 +27,10 @@
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
</natures>
</projectDescription>

View File

@ -38,6 +38,12 @@ public class FallbackPersistenceBackend extends PersistenceBackend {
// Nothing TO DO
}
@Override
protected void openConnection() throws Exception {
// Nothing TO DO
}
/**
* {@inheritDoc}
* This method is synchronized on {@link File} used, so any actions which
@ -70,5 +76,7 @@ public class FallbackPersistenceBackend extends PersistenceBackend {
public void close() throws Exception {
// Nothing TO DO
}
}

View File

@ -89,6 +89,21 @@ public abstract class PersistenceBackend {
*/
protected abstract void prepareConnection(PersistenceBackendConfiguration configuration) throws Exception;
/**
* This method is for open connection
* @throws Exception
*/
protected abstract void openConnection() throws Exception ;
/**
* This method is for disconnect
* @throws Exception
*/
protected void disconnect() throws Exception {
//NOTHING
};
/**
* This method contains the code to save the {@link Record}
*
@ -99,9 +114,13 @@ public abstract class PersistenceBackend {
/***
*
* @param records
* @throws Exception
*/
protected void accountWithFallback(Record... records) {
protected void accountWithFallback(Record... records) throws Exception {
String persistenceName = this.getClass().getSimpleName();
this.openConnection();
for(Record record : records){
try {
//old code
@ -135,6 +154,8 @@ public abstract class PersistenceBackend {
//old code
//PersistenceBackendFactory.renew(this);
countFallback=0;
//disconnect
this.disconnect();
}
}
else{
@ -152,6 +173,7 @@ public abstract class PersistenceBackend {
}
}
}
this.close();
}
/**
@ -217,6 +239,8 @@ public abstract class PersistenceBackend {
public abstract void close() throws Exception;
}

View File

@ -166,9 +166,9 @@ public abstract class PersistenceBackendFactory {
logger.trace("Going to synchronized block in getPersistenceBackend");
synchronized (persistenceBackends) {
persistence = persistenceBackends.get(context);
logger.trace("[getPersistenceBackend]{} {} in context {}", PersistenceBackend.class.getSimpleName(), persistence,context);
//logger.trace("[getPersistenceBackend]{} {} in context {}", PersistenceBackend.class.getSimpleName(), persistence,context);
if(persistence==null){
logger.trace("[getPersistenceBackend]{} {} in context {}", PersistenceBackend.class.getSimpleName(), persistence,context);
/*
* Setting FallbackPersistence and unlocking.
* There will be another thread which will try to discover the