use of org.hibernate.cfg.Configuration in project ice by JBEI.
the class HibernateUtil method initialize.
private static synchronized void initialize(Type type) {
if (sessionFactory == null) {
Logger.info("Initializing session factory for type " + type.name());
final Configuration configuration = new Configuration();
try {
if (type == Type.MOCK) {
configuration.setProperty("hibernate.connection.url", "jdbc:h2:mem:test");
configuration.setProperty("hibernate.connection.driver_class", "org.h2.Driver");
configuration.setProperty("hibernate.connection.username", "sa");
configuration.setProperty("hibernate.dialect", "org.hibernate.dialect.H2Dialect");
configuration.setProperty("hibernate.current_session_context_class", "org.hibernate.context.internal.ThreadLocalSessionContext");
configuration.setProperty("hibernate.hbm2ddl.auto", "update");
configuration.setProperty("hibernate.search.default.directory_provider", "org.hibernate.search.store.impl.RAMDirectoryProvider");
} else {
configuration.configure();
}
ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build();
configuration.addAnnotatedClass(org.jbei.ice.storage.model.Entry.class);
configuration.addAnnotatedClass(org.jbei.ice.storage.model.Plasmid.class);
configuration.addAnnotatedClass(org.jbei.ice.storage.model.Strain.class);
configuration.addAnnotatedClass(org.jbei.ice.storage.model.Part.class);
configuration.addAnnotatedClass(org.jbei.ice.storage.model.ArabidopsisSeed.class);
configuration.addAnnotatedClass(org.jbei.ice.storage.model.Link.class);
configuration.addAnnotatedClass(org.jbei.ice.storage.model.SelectionMarker.class);
configuration.addAnnotatedClass(org.jbei.ice.storage.model.Sequence.class);
configuration.addAnnotatedClass(org.jbei.ice.storage.model.Feature.class);
configuration.addAnnotatedClass(org.jbei.ice.storage.model.SequenceFeature.class);
configuration.addAnnotatedClass(org.jbei.ice.storage.model.SequenceFeatureAttribute.class);
configuration.addAnnotatedClass(org.jbei.ice.storage.model.Comment.class);
configuration.addAnnotatedClass(org.jbei.ice.storage.model.Account.class);
configuration.addAnnotatedClass(org.jbei.ice.storage.model.Attachment.class);
configuration.addAnnotatedClass(org.jbei.ice.storage.model.Sample.class);
configuration.addAnnotatedClass(org.jbei.ice.storage.model.AccountPreferences.class);
configuration.addAnnotatedClass(org.jbei.ice.storage.model.Group.class);
configuration.addAnnotatedClass(org.jbei.ice.storage.model.TraceSequence.class);
configuration.addAnnotatedClass(org.jbei.ice.storage.model.TraceSequenceAlignment.class);
configuration.addAnnotatedClass(org.jbei.ice.storage.model.Configuration.class);
configuration.addAnnotatedClass(org.jbei.ice.storage.model.Storage.class);
configuration.addAnnotatedClass(org.jbei.ice.storage.model.Folder.class);
configuration.addAnnotatedClass(org.jbei.ice.storage.model.Parameter.class);
configuration.addAnnotatedClass(org.jbei.ice.storage.model.AnnotationLocation.class);
configuration.addAnnotatedClass(org.jbei.ice.storage.model.BulkUpload.class);
configuration.addAnnotatedClass(org.jbei.ice.storage.model.Permission.class);
configuration.addAnnotatedClass(org.jbei.ice.storage.model.Message.class);
configuration.addAnnotatedClass(org.jbei.ice.storage.model.Preference.class);
configuration.addAnnotatedClass(org.jbei.ice.storage.model.RemotePartner.class);
configuration.addAnnotatedClass(org.jbei.ice.storage.model.Request.class);
configuration.addAnnotatedClass(org.jbei.ice.storage.model.Audit.class);
configuration.addAnnotatedClass(org.jbei.ice.storage.model.Experiment.class);
configuration.addAnnotatedClass(org.jbei.ice.storage.model.ShotgunSequence.class);
configuration.addAnnotatedClass(org.jbei.ice.storage.model.Configuration.class);
configuration.addAnnotatedClass(org.jbei.ice.storage.model.ApiKey.class);
configuration.addAnnotatedClass(org.jbei.ice.storage.model.RemoteClientModel.class);
configuration.addAnnotatedClass(org.jbei.ice.storage.model.RemoteShareModel.class);
configuration.addAnnotatedClass(org.jbei.ice.storage.model.RemoteAccessModel.class);
configuration.addAnnotatedClass(org.jbei.ice.storage.model.ManuscriptModel.class);
configuration.addAnnotatedClass(FeatureCurationModel.class);
sessionFactory = configuration.buildSessionFactory(serviceRegistry);
} catch (Throwable e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}
}
use of org.hibernate.cfg.Configuration in project midpoint by Evolveum.
the class SpringApplicationContextTest method createSQLSchema.
private void createSQLSchema(String fileName, String dialect) throws Exception {
org.hibernate.cfg.Configuration configuration = new Configuration();
configuration.setNamingStrategy(new MidPointNamingStrategy());
configuration.setProperties(sessionFactory.getHibernateProperties());
sessionFactory.getHibernateProperties().setProperty("hibernate.dialect", dialect);
System.out.println("Dialect: " + sessionFactory.getHibernateProperties().getProperty("hibernate.dialect"));
addAnnotatedClasses("com.evolveum.midpoint.repo.sql.data.common", configuration);
addAnnotatedClasses("com.evolveum.midpoint.repo.sql.data.common.container", configuration);
addAnnotatedClasses("com.evolveum.midpoint.repo.sql.data.common.any", configuration);
addAnnotatedClasses("com.evolveum.midpoint.repo.sql.data.common.embedded", configuration);
addAnnotatedClasses("com.evolveum.midpoint.repo.sql.data.common.enums", configuration);
addAnnotatedClasses("com.evolveum.midpoint.repo.sql.data.common.id", configuration);
addAnnotatedClasses("com.evolveum.midpoint.repo.sql.data.common.other", configuration);
addAnnotatedClasses("com.evolveum.midpoint.repo.sql.data.common.type", configuration);
addAnnotatedClasses("com.evolveum.midpoint.repo.sql.data.audit", configuration);
// addAnnotatedClasses("com.evolveum.midpoint.repo.sql.data.poc", configuration);
configuration.addPackage("com.evolveum.midpoint.repo.sql.type");
SchemaExport export = new SchemaExport(configuration);
export.setOutputFile(fileName);
export.setDelimiter(";");
export.execute(true, false, false, true);
}
use of org.hibernate.cfg.Configuration in project dhis2-core by dhis2.
the class HibernateDatabaseInfoProvider method init.
public void init() {
Configuration config = hibernateConfigurationProvider.getConfiguration();
boolean spatialSupport = isSpatialSupport();
String dialect = config.getProperty(KEY_DIALECT);
String driverClass = config.getProperty(KEY_DRIVER_CLASS);
String url = config.getProperty(KEY_URL);
String user = config.getProperty(KEY_USERNAME);
String password = config.getProperty(KEY_PASSWORD);
info = new DatabaseInfo();
if (dialect != null && dialect.lastIndexOf(SEPARATOR) != -1 && dialect.lastIndexOf(DIALECT_SUFFIX) != -1) {
info.setType(dialect.substring(dialect.lastIndexOf(SEPARATOR) + 1, dialect.lastIndexOf(DIALECT_SUFFIX)));
}
if (url != null && url.lastIndexOf(DEL_B) != -1) {
int startPos = url.lastIndexOf(DEL_A) != -1 ? url.lastIndexOf(DEL_A) : url.lastIndexOf(DEL_B);
int endPos = url.lastIndexOf(DEL_C) != -1 ? url.lastIndexOf(DEL_C) : url.length();
info.setName(url.substring(startPos + 1, endPos));
}
info.setUser(user);
info.setPassword(password);
info.setDialect(dialect);
info.setDriverClass(driverClass);
info.setUrl(url);
info.setSpatialSupport(spatialSupport);
}
use of org.hibernate.cfg.Configuration in project API by ca-cwds.
the class ReporterDaoIT method setup.
@Override
@Before
public void setup() {
sessionFactory = new Configuration().configure().buildSessionFactory();
reporterDao = new ReporterDao(sessionFactory);
session = sessionFactory.getCurrentSession();
session.beginTransaction();
}
use of org.hibernate.cfg.Configuration in project API by ca-cwds.
the class OtherClientNameDaoIT method beforeClass.
@SuppressWarnings("javadoc")
@BeforeClass
public static void beforeClass() {
sessionFactory = new Configuration().configure("hibernate.cfg.xml").buildSessionFactory();
otherClientNameDao = new OtherClientNameDao(sessionFactory);
}
Aggregations