1.0.0.1 #1
|
@ -22,6 +22,8 @@ import javax.persistence.spi.PersistenceUnitInfo;
|
|||
import javax.persistence.spi.PersistenceUnitTransactionType;
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.apache.poi.ss.formula.functions.T;
|
||||
import org.gcube.application.geoportal.managers.AbstractRecordManager.EMFProvider;
|
||||
import org.gcube.application.geoportal.model.Record;
|
||||
import org.gcube.application.geoportal.model.db.DBConstants;
|
||||
import org.gcube.application.geoportal.model.db.DatabaseConnection;
|
||||
|
@ -47,6 +49,18 @@ import lombok.extern.slf4j.Slf4j;
|
|||
@Slf4j
|
||||
public abstract class AbstractRecordManager<T extends Record> {
|
||||
|
||||
public static interface EMFProvider {
|
||||
public EntityManagerFactory getFactory();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public static void setDefaultProvider(EMFProvider provider) {
|
||||
defaultProvider=provider;
|
||||
}
|
||||
|
||||
private static EMFProvider defaultProvider=null;
|
||||
private static EntityManagerFactory emf=null;
|
||||
|
||||
@Synchronized
|
||||
|
@ -76,12 +90,11 @@ public abstract class AbstractRecordManager<T extends Record> {
|
|||
.build());
|
||||
|
||||
}catch(Throwable t) {
|
||||
log.warn("Unable to contact DB from IS, trying local..",t);
|
||||
try{
|
||||
emf=Persistence.createEntityManagerFactory(DBConstants.INTERNAL.DB_NAME);
|
||||
}catch(Throwable t1) {
|
||||
log.error("NO INTERNAL DATABASE FOUND ",t);
|
||||
throw new RuntimeException("NO INTERNAL DATABASE",t);
|
||||
if(defaultProvider==null)
|
||||
throw new RuntimeException("NO INTERNAL DADATABASE. Please contact VRE Manager (Required SE [platform : postgresq, 'GNA-DB' flag : internal-db])");
|
||||
else {
|
||||
log.warn("Found default provider. This should happen only in test phase.");
|
||||
emf=defaultProvider.getFactory();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,17 +13,17 @@ public class CheckContextConfiguration {
|
|||
|
||||
public static void main(String[] args) {
|
||||
TokenSetter.set("/gcube/devNext/NextNext");
|
||||
System.out.println("Checking for internal .. ");
|
||||
ConcessioneManager manager=ManagerFactory.getByRecord(new Concessione());
|
||||
try {
|
||||
manager.commit(false);
|
||||
} catch (ValidationException | PersistenceException | PublishException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}finally {
|
||||
manager.shutdown();
|
||||
}
|
||||
|
||||
// System.out.println("Checking for internal .. ");
|
||||
// ConcessioneManager manager=ManagerFactory.getByRecord(new Concessione());
|
||||
// try {
|
||||
// manager.commit(false);
|
||||
// } catch (ValidationException | PersistenceException | PublishException e) {
|
||||
// // TODO Auto-generated catch block
|
||||
// e.printStackTrace();
|
||||
// }finally {
|
||||
// manager.shutdown();
|
||||
// }
|
||||
System.out.println(ISUtils.queryForDB("postgresql", "internal_db"));
|
||||
System.out.println("Checking for postgis .. ");
|
||||
System.out.println(ISUtils.queryForDB("postgis", "Concessioni"));
|
||||
|
||||
|
|
|
@ -2,11 +2,16 @@ package org.gcube.application.geoportal.db;
|
|||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import javax.persistence.EntityManagerFactory;
|
||||
import javax.persistence.Persistence;
|
||||
|
||||
import org.gcube.application.geoportal.TestModel;
|
||||
import org.gcube.application.geoportal.managers.AbstractRecordManager;
|
||||
import org.gcube.application.geoportal.managers.AbstractRecordManager.EMFProvider;
|
||||
import org.gcube.application.geoportal.managers.ConcessioneManager;
|
||||
import org.gcube.application.geoportal.managers.ManagerFactory;
|
||||
import org.gcube.application.geoportal.model.concessioni.Concessione;
|
||||
import org.gcube.application.geoportal.model.db.DBConstants;
|
||||
import org.gcube.application.geoportal.model.fault.PersistenceException;
|
||||
import org.gcube.application.geoportal.model.fault.PublishException;
|
||||
import org.gcube.application.geoportal.model.fault.ValidationException;
|
||||
|
@ -15,10 +20,14 @@ import org.gcube.application.geoportal.model.report.ValidationReport.ValidationS
|
|||
import org.gcube.application.geoportal.utils.Serialization;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Assert;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
public class Records {
|
||||
|
||||
@AfterClass
|
||||
|
@ -26,7 +35,19 @@ public class Records {
|
|||
AbstractRecordManager.shutdown();
|
||||
|
||||
}
|
||||
@BeforeClass
|
||||
public static void init() {
|
||||
AbstractRecordManager.setDefaultProvider(new EMFProvider() {
|
||||
|
||||
@Override
|
||||
public EntityManagerFactory getFactory() {
|
||||
try{
|
||||
return Persistence.createEntityManagerFactory(DBConstants.INTERNAL.DB_NAME);
|
||||
}catch(Throwable t1) {
|
||||
throw new RuntimeException("Unable to init local databse",t1);
|
||||
}
|
||||
}
|
||||
}); }
|
||||
|
||||
@Test
|
||||
public void Concessioni() throws PersistenceException, ValidationException, PublishException, JsonProcessingException {
|
||||
|
|
Loading…
Reference in New Issue