List of usage examples for org.hibernate.cfg Configuration getProperty
public String getProperty(String propertyName)
From source file:com.xgestion2.manager.SessionFactoryManager.java
public SessionFactory getSessionFactory() { if (SessionFactoryManager.sessionFactory == null) { try {//from w ww . j a va 2 s . c o m Configuration config = new AnnotationConfiguration().configure(new File("src/hibernate.cfg.xml")); config.setProperty("hibernate.connection.password", Encriptador.Desencriptar(config.getProperty("hibernate.connection.password"))); config.setProperty("hibernate.connection.username", Encriptador.Desencriptar(config.getProperty("hibernate.connection.username"))); sessionFactory = config.buildSessionFactory(); } catch (Exception ex) { FormPrincipal.logger.error("Error: " + ex.toString()); } } return sessionFactory; }
From source file:de.jpdigital.maven.plugins.hibernate4ddl.tests.DdlMojoTest.java
License:Open Source License
/** * Check if the DDL files are generated and have the expected content, but * this time with Envers enabled.// w w w . ja v a2 s. co m * * @throws NoSuchMethodException if something went wrong... * @throws IllegalAccessException if something went wrong... * @throws InvocationTargetException if something went wrong... */ @Test public void generateDdlWithProperties() throws NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { mojo.setOutputDirectory(new File(TEST_DIR)); final String[] packages = new String[] { "de.jpdigital.maven.plugins.hibernate4ddl.tests.entities", "de.jpdigital.maven.plugins.hibernate4ddl.tests.entities2" }; mojo.setPackages(packages); final String[] dialects = new String[] { "hsql", "mysql5", "POSTGRESQL9" }; mojo.setDialects(dialects); mojo.setPersistenceXml(new File(TEST_PERSISTENCE_XML)); assertThat(mojo.getPersistenceXml(), is(notNullValue())); final Configuration configuration = new Configuration(); final Method processMethod = mojo.getClass().getDeclaredMethod("processPersistenceXml", Configuration.class); processMethod.setAccessible(true); processMethod.invoke(mojo, configuration); assertThat(configuration.getProperty("org.hibernate.envers.audit_table_suffix"), is(equalTo("_audit"))); assertThat(configuration.getProperty("org.hibernate.envers.revision_type_field_name"), is(equalTo("rev_type"))); }
From source file:edu.ku.brc.dbsupport.HibernateUtil.java
License:Open Source License
/** * Rebuild the SessionFactory with the given Hibernate Configuration. * <p>//w w w . j av a 2 s . c o m * HibernateUtil does not configure() the given Configuration object, * it directly calls buildSessionFactory(). This method also closes * the old SessionFactory before, if still open. * * @param cfg */ public static void rebuildSessionFactory(final Configuration cfg) { //log.debug("Rebuilding the SessionFactory from given Configuration."); synchronized (sessionFactory) { if (sessionFactory != null && !sessionFactory.isClosed()) { sessionFactory.close(); } if (cfg.getProperty(Environment.SESSION_FACTORY_NAME) != null) { cfg.buildSessionFactory(); } else { sessionFactory = cfg.buildSessionFactory(); } configuration = cfg; } }
From source file:eu.optimis.infrastructureproviderriskassessmenttool.core.historicaldatabase.dao.populate.RiskPropagator.java
License:Apache License
/** * Constructor for initialising hibernate specific connection properties * read from hibernate.cfg.xml in classpath * //from ww w . ja v a 2 s .c o m * @param providerType * the type of provider, valid arguments are "sp", "ip" * @param servicePhase * the phase in which a service is running, valid arguments are * "deployment", "operation" * @param providerId * the human readable providerId or name, e.g. "Atos" * @param serviceId * the not so human readable serviceId hash value, e.g. * "76c44bda-4f5a-4f97-806d-011d174bea44" * @param graphType * the graphType the data will be rendered to in the UI * @throws InitialisationException * thrown on failure to initialise class due to invalid input * parameters */ public RiskPropagator(String providerType, String servicePhase, String providerId, String serviceId, int graphType) throws InitialisationException { super("riskPropagatorThread(" + providerType + "-" + servicePhase + "-" + graphType + ")"); LOGGER.debug("RiskPropagator: Constuctor called for hibernater specific connections properties"); Configuration cfg = null; try { // Fetch the hibernate config cfg = new Configuration().configure(); } catch (HibernateException e) { LOGGER.error("RiskPropagator: Hibernate configuration missing", e); throw new InitialisationException(MESSAGE_INITIALISATION_FAILED, e); } if (cfg != null) { String oldUrl = cfg.getProperty("hibernate.connection.url"); url = oldUrl.substring(0, oldUrl.lastIndexOf('/')) + "/risk_bridge"; username = cfg.getProperty("hibernate.connection.username"); password = cfg.getProperty("hibernate.connection.password"); LOGGER.debug("RiskPropagator: Url is: " + url); // Call generic initialisation code if (!initialise(providerType, servicePhase, providerId, serviceId, graphType)) { throw new InitialisationException(MESSAGE_INITIALISATION_FAILED); } } else { LOGGER.error("RiskPropagator: Hibernate configuration is null"); throw new InitialisationException(MESSAGE_INITIALISATION_FAILED); } }
From source file:fr.keyconsulting.oliphant.NotifyListener.java
License:Open Source License
public static void attachListener(Configuration config) { NotifyListener listener = new NotifyListener(); listener.config = config;/* w w w . j av a 2 s . c o m*/ PostLoadEventListener[] originalPostLoadListeners = config.getEventListeners().getPostLoadEventListeners(); int originalPostLoadListenersSize = java.lang.reflect.Array.getLength(originalPostLoadListeners); PostLoadEventListener[] postLoadEventListeners = new PostLoadEventListener[originalPostLoadListenersSize + 1]; postLoadEventListeners[0] = listener; System.arraycopy(originalPostLoadListeners, 0, postLoadEventListeners, 1, originalPostLoadListenersSize); config.getEventListeners().setPostLoadEventListeners(postLoadEventListeners); PersistEventListener[] originalPersistEventListeners = config.getEventListeners() .getPersistEventListeners(); int originalPersistEventListenersSize = java.lang.reflect.Array.getLength(originalPersistEventListeners); PersistEventListener[] persistEventListeners = new PersistEventListener[originalPersistEventListenersSize + 1]; persistEventListeners[0] = listener; System.arraycopy(originalPersistEventListeners, 0, persistEventListeners, 1, originalPersistEventListenersSize); config.getEventListeners().setPersistEventListeners(persistEventListeners); FlushEntityEventListener[] originalFlushEntityEventListeners = config.getEventListeners() .getFlushEntityEventListeners(); int originalFlushEntityEventListenersSize = java.lang.reflect.Array .getLength(originalFlushEntityEventListeners); FlushEntityEventListener[] flushEntityEventListeners = new FlushEntityEventListener[originalFlushEntityEventListenersSize + 1]; flushEntityEventListeners[0] = listener; System.arraycopy(originalFlushEntityEventListeners, 0, flushEntityEventListeners, 1, originalFlushEntityEventListenersSize); config.getEventListeners().setFlushEntityEventListeners(flushEntityEventListeners); PreUpdateEventListener[] originalPreUpdateEventListeners = config.getEventListeners() .getPreUpdateEventListeners(); int originalPreUpdateEventListenersSize = java.lang.reflect.Array .getLength(originalPreUpdateEventListeners); PreUpdateEventListener[] preUpdateEventListeners = new PreUpdateEventListener[originalPreUpdateEventListenersSize + 1]; preUpdateEventListeners[0] = listener; System.arraycopy(originalPreUpdateEventListeners, 0, preUpdateEventListeners, 1, originalPreUpdateEventListenersSize); config.getEventListeners().setPreUpdateEventListeners(preUpdateEventListeners); try { Class specListClass = Class.forName(config.getProperty("oliphant.specific_listener")); listener.specificNotifyListener = (SpecificNotifyListener) specListClass.newInstance(); listener.specificNotifyListener.prepare(config); } catch (ClassNotFoundException e) { throw new HibernateException(e); } catch (InstantiationException e) { throw new HibernateException(e); } catch (IllegalAccessException e) { throw new HibernateException(e); } String allowStaleString = config.getProperty("oliphant.allow_stale_load"); if ((allowStaleString != null) && (allowStaleString.equals("false"))) { listener.allowStaleLoad = false; } }
From source file:functionaltests.service.SchedulerDbManagerRecoveryTest.java
License:Open Source License
private SchedulerDBManager createDatabase(boolean wipeOnStartup) throws URISyntaxException { String configureFilename = "hibernate-update.cfg.xml"; if (wipeOnStartup) { configureFilename = "hibernate.cfg.xml"; }/*from w ww . ja va2 s . c o m*/ Configuration config = new Configuration().configure( new File(this.getClass().getResource("/functionaltests/config/" + configureFilename).toURI())); if (config.getProperty("hibernate.connection.url").contains(HsqldbServer.HSQLDB)) { String jdbcUrl = "jdbc:hsqldb:file:" + dbFolder.getRoot().getAbsolutePath() + ";create=true;hsqldb.tx=mvcc;hsqldb.write_delay=false"; config.setProperty("hibernate.connection.url", jdbcUrl); } return new SchedulerDBManager(config, wipeOnStartup); }
From source file:gov.nih.nci.caarray.application.ConfigurationHelper.java
License:BSD License
private static DataSource getAdhocDataSource() { MysqlDataSource ds = new MysqlDataSource(); Configuration config = hibernateHelper.getConfiguration(); ds.setUrl(config.getProperty(Environment.URL)); ds.setUser(config.getProperty(Environment.USER)); ds.setPassword(config.getProperty(Environment.PASS)); return ds;/*from w ww.j ava2s. c o m*/ }
From source file:gov.nih.nci.caarray.application.permissions.PermissionsManagementServiceIntegrationTest.java
License:BSD License
private PermissionsManagementService createPermissionsManagementService( GenericDataService genericDataServiceStub) { final CaArrayDaoFactory daoFactory = CaArrayDaoFactory.INSTANCE; final PermissionsManagementServiceBean bean = new PermissionsManagementServiceBean(); bean.setHibernateHelper(this.hibernateHelper); bean.setCollaboratorGroupDao(daoFactory.getCollaboratorGroupDao()); bean.setSearchDao(daoFactory.getSearchDao()); final ServiceLocatorStub locatorStub = ServiceLocatorStub.registerEmptyLocator(); locatorStub.addLookup(GenericDataService.JNDI_NAME, genericDataServiceStub); final MysqlDataSource ds = new MysqlDataSource(); final Configuration config = this.hibernateHelper.getConfiguration(); ds.setUrl(config.getProperty("hibernate.connection.url")); ds.setUser(config.getProperty("hibernate.connection.username")); ds.setPassword(config.getProperty("hibernate.connection.password")); locatorStub.addLookup("java:jdbc/CaArrayDataSource", ds); bean.setGenericDataService(genericDataServiceStub); return bean;/*from www. j a v a2s .c om*/ }
From source file:gov.nih.nci.caarray.application.project.ProjectManagementServiceIntegrationTest.java
License:BSD License
private ProjectManagementService createProjectManagementService( final FileAccessServiceStub fileAccessServiceStub) { final CaArrayDaoFactory daoFactory = CaArrayDaoFactory.INSTANCE; final GenericDataServiceBean genericDataServiceBean = new GenericDataServiceBean(); genericDataServiceBean.setProjectDao(daoFactory.getProjectDao()); genericDataServiceBean.setSearchDao(daoFactory.getSearchDao()); this.genericDataService = genericDataServiceBean; final ProjectManagementServiceBean bean = new ProjectManagementServiceBean(); bean.setProjectDao(daoFactory.getProjectDao()); bean.setFileDao(daoFactory.getFileDao()); bean.setSampleDao(daoFactory.getSampleDao()); bean.setSearchDao(daoFactory.getSearchDao()); bean.setVocabularyDao(daoFactory.getVocabularyDao()); final ServiceLocatorStub locatorStub = ServiceLocatorStub.registerEmptyLocator(); locatorStub.addLookup(FileAccessService.JNDI_NAME, fileAccessServiceStub); locatorStub.addLookup(GenericDataService.JNDI_NAME, this.genericDataService); final MysqlDataSource ds = new MysqlDataSource(); final Configuration config = this.hibernateHelper.getConfiguration(); ds.setUrl(config.getProperty("hibernate.connection.url")); ds.setUser(config.getProperty("hibernate.connection.username")); ds.setPassword(config.getProperty("hibernate.connection.password")); locatorStub.addLookup("java:jdbc/CaArrayDataSource", ds); return bean;//from ww w . ja va2 s .c o m }
From source file:gov.nih.nci.caarray.application.project.ProjectManagementServiceTest.java
License:BSD License
@Before public void setUpService() { MockitoAnnotations.initMocks(this); CaArrayUsernameHolder.setUser(STANDARD_USER); final ProjectManagementServiceBean pmsBean = new ProjectManagementServiceBean(); pmsBean.setProjectDao(this.daoFactoryStub.getProjectDao()); pmsBean.setFileDao(fileDao);/*from w w w . j a v a 2 s.com*/ pmsBean.setSampleDao(this.daoFactoryStub.getSampleDao()); pmsBean.setSearchDao(this.daoFactoryStub.getSearchDao()); pmsBean.setVocabularyDao(this.daoFactoryStub.getVocabularyDao()); locatorStub = ServiceLocatorStub.registerEmptyLocator(); locatorStub.addLookup(FileAccessService.JNDI_NAME, this.fileAccessServiceStub); locatorStub.addLookup(GenericDataService.JNDI_NAME, this.genericDataService); final MysqlDataSource ds = new MysqlDataSource(); final Configuration config = hibernateHelper.getConfiguration(); ds.setUrl(config.getProperty("hibernate.connection.url")); ds.setUser(config.getProperty("hibernate.connection.username")); ds.setPassword(config.getProperty("hibernate.connection.password")); locatorStub.addLookup("java:jdbc/CaArrayDataSource", ds); this.projectManagementService = pmsBean; locatorStub.addLookup(ProjectManagementService.JNDI_NAME, this.projectManagementService); hibernateHelper.setFiltersEnabled(false); this.transaction = hibernateHelper.beginTransaction(); }