Service migration
This commit is contained in:
parent
a004b48604
commit
e51f8429bd
2
pom.xml
2
pom.xml
|
@ -36,7 +36,7 @@
|
|||
<dependency>
|
||||
<groupId>org.gcube.distribution</groupId>
|
||||
<artifactId>gcube-bom</artifactId>
|
||||
<version>2.0.0-SNAPSHOT</version>
|
||||
<version>2.0.0</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
|
|
|
@ -1,30 +1,17 @@
|
|||
package org.gcube.application.geoportal.managers;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.net.URL;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.EntityManagerFactory;
|
||||
import javax.persistence.EntityTransaction;
|
||||
import javax.persistence.SharedCacheMode;
|
||||
import javax.persistence.ValidationMode;
|
||||
import javax.persistence.spi.ClassTransformer;
|
||||
import javax.persistence.spi.PersistenceUnitInfo;
|
||||
import javax.persistence.spi.PersistenceUnitTransactionType;
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.gcube.application.geoportal.model.Record;
|
||||
import org.gcube.application.geoportal.model.db.DBConstants;
|
||||
import org.gcube.application.geoportal.model.db.DatabaseConnection;
|
||||
import org.gcube.application.geoportal.model.db.PostgisTable;
|
||||
import org.gcube.application.geoportal.model.db.PostgisTable.Field;
|
||||
import org.gcube.application.geoportal.model.db.PostgisTable.FieldType;
|
||||
|
@ -39,74 +26,26 @@ import org.gcube.application.geoportal.model.report.ValidationReport.ValidationS
|
|||
import org.gcube.application.geoportal.storage.ContentHandler;
|
||||
import org.gcube.application.geoportal.storage.PostgisDBManager;
|
||||
import org.gcube.application.geoportal.storage.PostgisDBManagerI;
|
||||
import org.gcube.application.geoportal.utils.ISUtils;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.jpa.HibernatePersistenceProvider;
|
||||
|
||||
import jersey.repackaged.com.google.common.collect.ImmutableMap;
|
||||
import lombok.Synchronized;
|
||||
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
|
||||
protected static EntityManagerFactory getEMF() {
|
||||
if(emf==null) {
|
||||
try {
|
||||
DatabaseConnection conn=ISUtils.queryForDB("postgresql", "internal-db");
|
||||
log.debug("Found Internal Database : "+conn);
|
||||
|
||||
emf = new HibernatePersistenceProvider().createContainerEntityManagerFactory(
|
||||
archiverPersistenceUnitInfo(),
|
||||
ImmutableMap.<String, Object>builder()
|
||||
.put(AvailableSettings.JPA_JDBC_DRIVER, "org.postgresql.Driver")
|
||||
.put(AvailableSettings.JPA_JDBC_URL, conn.getUrl())
|
||||
.put(AvailableSettings.DIALECT, org.hibernate.dialect.PostgreSQLDialect.class)
|
||||
.put(AvailableSettings.HBM2DDL_AUTO, org.hibernate.tool.schema.Action.UPDATE)
|
||||
.put(AvailableSettings.SHOW_SQL, true)
|
||||
.put(AvailableSettings.QUERY_STARTUP_CHECKING, false)
|
||||
.put(AvailableSettings.GENERATE_STATISTICS, false)
|
||||
.put(AvailableSettings.USE_REFLECTION_OPTIMIZER, false)
|
||||
.put(AvailableSettings.USE_SECOND_LEVEL_CACHE, false)
|
||||
.put(AvailableSettings.USE_QUERY_CACHE, false)
|
||||
.put(AvailableSettings.USE_STRUCTURED_CACHE, false)
|
||||
.put(AvailableSettings.STATEMENT_BATCH_SIZE, 20)
|
||||
.put(AvailableSettings.JPA_JDBC_USER, conn.getUser())
|
||||
.put(AvailableSettings.JPA_JDBC_PASSWORD, conn.getPwd())
|
||||
.build());
|
||||
|
||||
}catch(Throwable t) {
|
||||
if(defaultProvider==null)
|
||||
throw new RuntimeException("NO INTERNAL DADATABASE. Please contact VRE Manager (Required SE [platform : postgresq, 'GNA-DB' flag : internal-db])",t);
|
||||
else {
|
||||
log.warn("Found default provider. This should happen only in test phase.");
|
||||
emf=defaultProvider.getFactory();
|
||||
}
|
||||
}
|
||||
}
|
||||
return emf;
|
||||
return defaultProvider.getFactory();
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
public static void shutdown() {
|
||||
if(emf!=null) {
|
||||
if(emf.isOpen()) emf.close();
|
||||
emf=null;
|
||||
}
|
||||
defaultProvider.shutdown();
|
||||
}
|
||||
|
||||
public static Record getByID(long id) {
|
||||
|
@ -343,116 +282,4 @@ public abstract class AbstractRecordManager<T extends Record> {
|
|||
|
||||
//*********** PERSISTENCE
|
||||
|
||||
private static PersistenceUnitInfo archiverPersistenceUnitInfo() {
|
||||
|
||||
final List<String> MANAGED_CLASSES=Arrays.asList(new String[] {
|
||||
"org.gcube.application.geoportal.model.Record",
|
||||
"org.gcube.application.geoportal.model.concessioni.Concessione",
|
||||
"org.gcube.application.geoportal.model.concessioni.LayerConcessione",
|
||||
"org.gcube.application.geoportal.model.concessioni.RelazioneScavo",
|
||||
|
||||
"org.gcube.application.geoportal.model.content.AssociatedContent",
|
||||
"org.gcube.application.geoportal.model.content.GeoServerContent",
|
||||
"org.gcube.application.geoportal.model.content.OtherContent",
|
||||
"org.gcube.application.geoportal.model.content.PersistedContent",
|
||||
"org.gcube.application.geoportal.model.content.UploadedImage",
|
||||
"org.gcube.application.geoportal.model.content.WorkspaceContent",
|
||||
|
||||
"org.gcube.application.geoportal.model.gis.ShapeFileLayerDescriptor",
|
||||
"org.gcube.application.geoportal.model.gis.SDILayerDescriptor"});
|
||||
|
||||
|
||||
return new PersistenceUnitInfo() {
|
||||
@Override
|
||||
public String getPersistenceUnitName() {
|
||||
return "ApplicationPersistenceUnit";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPersistenceProviderClassName() {
|
||||
return "org.hibernate.jpa.HibernatePersistenceProvider";
|
||||
}
|
||||
|
||||
@Override
|
||||
public PersistenceUnitTransactionType getTransactionType() {
|
||||
return PersistenceUnitTransactionType.RESOURCE_LOCAL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataSource getJtaDataSource() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataSource getNonJtaDataSource() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getMappingFileNames() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<URL> getJarFileUrls() {
|
||||
try {
|
||||
return Collections.list(this.getClass()
|
||||
.getClassLoader()
|
||||
.getResources(""));
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public URL getPersistenceUnitRootUrl() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getManagedClassNames() {
|
||||
return MANAGED_CLASSES;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean excludeUnlistedClasses() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SharedCacheMode getSharedCacheMode() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ValidationMode getValidationMode() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Properties getProperties() {
|
||||
return new Properties();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPersistenceXMLSchemaVersion() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClassLoader getClassLoader() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addTransformer(ClassTransformer transformer) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClassLoader getNewTempClassLoader() {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,190 @@
|
|||
package org.gcube.application.geoportal.managers;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.net.URL;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.persistence.EntityManagerFactory;
|
||||
import javax.persistence.SharedCacheMode;
|
||||
import javax.persistence.ValidationMode;
|
||||
import javax.persistence.spi.ClassTransformer;
|
||||
import javax.persistence.spi.PersistenceUnitInfo;
|
||||
import javax.persistence.spi.PersistenceUnitTransactionType;
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.gcube.application.geoportal.model.db.DatabaseConnection;
|
||||
import org.gcube.application.geoportal.model.fault.ConfigurationException;
|
||||
import org.gcube.application.geoportal.utils.ISUtils;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.jpa.HibernatePersistenceProvider;
|
||||
|
||||
import jersey.repackaged.com.google.common.collect.ImmutableMap;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
public class DefatulEMFProvider implements EMFProvider {
|
||||
|
||||
private static EntityManagerFactory emf=null;
|
||||
|
||||
|
||||
@Override
|
||||
public EntityManagerFactory getFactory() {
|
||||
if(emf==null) {
|
||||
try {
|
||||
DatabaseConnection conn=ISUtils.queryForDB("postgresql", "internal-db");
|
||||
log.debug("Found Internal Database : "+conn);
|
||||
|
||||
emf = new HibernatePersistenceProvider().createContainerEntityManagerFactory(
|
||||
archiverPersistenceUnitInfo(),
|
||||
ImmutableMap.<String, Object>builder()
|
||||
.put(AvailableSettings.JPA_JDBC_DRIVER, "org.postgresql.Driver")
|
||||
.put(AvailableSettings.JPA_JDBC_URL, conn.getUrl())
|
||||
.put(AvailableSettings.DIALECT, org.hibernate.dialect.PostgreSQLDialect.class)
|
||||
.put(AvailableSettings.HBM2DDL_AUTO, org.hibernate.tool.schema.Action.UPDATE)
|
||||
.put(AvailableSettings.SHOW_SQL, true)
|
||||
.put(AvailableSettings.QUERY_STARTUP_CHECKING, false)
|
||||
.put(AvailableSettings.GENERATE_STATISTICS, false)
|
||||
.put(AvailableSettings.USE_REFLECTION_OPTIMIZER, false)
|
||||
.put(AvailableSettings.USE_SECOND_LEVEL_CACHE, false)
|
||||
.put(AvailableSettings.USE_QUERY_CACHE, false)
|
||||
.put(AvailableSettings.USE_STRUCTURED_CACHE, false)
|
||||
.put(AvailableSettings.STATEMENT_BATCH_SIZE, 20)
|
||||
.put(AvailableSettings.JPA_JDBC_USER, conn.getUser())
|
||||
.put(AvailableSettings.JPA_JDBC_PASSWORD, conn.getPwd())
|
||||
.build());
|
||||
|
||||
}catch(ConfigurationException e) {
|
||||
throw new RuntimeException("Unable to init EMF",e);
|
||||
}
|
||||
}
|
||||
return emf;
|
||||
}
|
||||
|
||||
|
||||
private static PersistenceUnitInfo archiverPersistenceUnitInfo() {
|
||||
|
||||
final List<String> MANAGED_CLASSES=Arrays.asList(new String[] {
|
||||
"org.gcube.application.geoportal.model.Record",
|
||||
"org.gcube.application.geoportal.model.concessioni.Concessione",
|
||||
"org.gcube.application.geoportal.model.concessioni.LayerConcessione",
|
||||
"org.gcube.application.geoportal.model.concessioni.RelazioneScavo",
|
||||
|
||||
"org.gcube.application.geoportal.model.content.AssociatedContent",
|
||||
"org.gcube.application.geoportal.model.content.GeoServerContent",
|
||||
"org.gcube.application.geoportal.model.content.OtherContent",
|
||||
"org.gcube.application.geoportal.model.content.PersistedContent",
|
||||
"org.gcube.application.geoportal.model.content.UploadedImage",
|
||||
"org.gcube.application.geoportal.model.content.WorkspaceContent",
|
||||
|
||||
"org.gcube.application.geoportal.model.gis.ShapeFileLayerDescriptor",
|
||||
"org.gcube.application.geoportal.model.gis.SDILayerDescriptor"});
|
||||
|
||||
|
||||
return new PersistenceUnitInfo() {
|
||||
@Override
|
||||
public String getPersistenceUnitName() {
|
||||
return "ApplicationPersistenceUnit";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPersistenceProviderClassName() {
|
||||
return "org.hibernate.jpa.HibernatePersistenceProvider";
|
||||
}
|
||||
|
||||
@Override
|
||||
public PersistenceUnitTransactionType getTransactionType() {
|
||||
return PersistenceUnitTransactionType.RESOURCE_LOCAL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataSource getJtaDataSource() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataSource getNonJtaDataSource() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getMappingFileNames() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<URL> getJarFileUrls() {
|
||||
try {
|
||||
return Collections.list(this.getClass()
|
||||
.getClassLoader()
|
||||
.getResources(""));
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public URL getPersistenceUnitRootUrl() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getManagedClassNames() {
|
||||
return MANAGED_CLASSES;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean excludeUnlistedClasses() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SharedCacheMode getSharedCacheMode() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ValidationMode getValidationMode() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Properties getProperties() {
|
||||
return new Properties();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPersistenceXMLSchemaVersion() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClassLoader getClassLoader() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addTransformer(ClassTransformer transformer) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClassLoader getNewTempClassLoader() {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void shutdown() {
|
||||
if(emf!=null) {
|
||||
if(emf.isOpen()) emf.close();
|
||||
emf=null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
package org.gcube.application.geoportal.managers;
|
||||
|
||||
import javax.persistence.EntityManagerFactory;
|
||||
|
||||
public interface EMFProvider {
|
||||
public EntityManagerFactory getFactory();
|
||||
public void shutdown();
|
||||
}
|
|
@ -1,9 +0,0 @@
|
|||
package org.gcube.application.geoportal.model.profiledProjects;
|
||||
|
||||
public class Centroid {
|
||||
|
||||
private Double x;
|
||||
private Double y;
|
||||
private Double z;
|
||||
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
package org.gcube.application.geoportal.model.profiledProjects;
|
||||
|
||||
public interface Document {
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
package org.gcube.application.geoportal.model.profiledProjects;
|
||||
|
||||
public class ProfiledConcessioni {
|
||||
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
package org.gcube.application.geoportal.model.profiledProjects;
|
||||
|
||||
import org.gcube.application.geoportal.model.Record;
|
||||
|
||||
public class Project extends Record {
|
||||
|
||||
/**
|
||||
* Project{
|
||||
_id:
|
||||
profile_id:
|
||||
publication :{
|
||||
creation_time:
|
||||
creation_user:
|
||||
last_update_time:
|
||||
last_update_user:
|
||||
version :
|
||||
license :
|
||||
policy : }
|
||||
status : VALID,
|
||||
PUBLISHED,INVALID
|
||||
document : {.....}
|
||||
centroid : {
|
||||
x:
|
||||
y:
|
||||
z:}
|
||||
}
|
||||
|
||||
*
|
||||
*/
|
||||
|
||||
public static enum Status{
|
||||
VALID,INVALID,PUBLISHED
|
||||
}
|
||||
|
||||
private String _id;
|
||||
private String profile_id;
|
||||
private PublicationDetails publication;
|
||||
private Status status;
|
||||
private Document document;
|
||||
private Centroid centroid;
|
||||
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
package org.gcube.application.geoportal.model.profiledProjects;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class PublicationDetails {
|
||||
|
||||
public static enum Policy{
|
||||
OPEN,RESTRICTED,EMBARGOED;
|
||||
}
|
||||
|
||||
private LocalDateTime creation_time;
|
||||
private String creation_user;
|
||||
private LocalDateTime last_update_time;
|
||||
private String last_update_user;
|
||||
private String version;
|
||||
private String license;
|
||||
private String policy;
|
||||
|
||||
}
|
|
@ -28,10 +28,10 @@ public class UseCases {
|
|||
|
||||
try {
|
||||
//CREATE NEW
|
||||
// int numConcessioni=1;
|
||||
// System.out.println("Try to create.. "+numConcessioni);
|
||||
// for(int i=0;i<numConcessioni;i++)
|
||||
// registerNewConcessione();
|
||||
int numConcessioni=1;
|
||||
System.out.println("Try to create.. "+numConcessioni);
|
||||
for(int i=0;i<numConcessioni;i++)
|
||||
registerNewConcessione();
|
||||
|
||||
// long id=conc.getId();
|
||||
|
||||
|
|
|
@ -7,8 +7,8 @@ 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.EMFProvider;
|
||||
import org.gcube.application.geoportal.managers.ManagerFactory;
|
||||
import org.gcube.application.geoportal.model.concessioni.Concessione;
|
||||
import org.gcube.application.geoportal.model.db.DBConstants;
|
||||
|
@ -47,6 +47,11 @@ public class Records {
|
|||
throw new RuntimeException("Unable to init local databse",t1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shutdown() {
|
||||
|
||||
}
|
||||
}); }
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in New Issue