List of usage examples for org.hibernate.cfg Configuration getProperties
public Properties getProperties()
From source file:org.jbpm.identity.hibernate.IdentitySchema.java
License:Open Source License
public IdentitySchema(Configuration configuration) { this.configuration = configuration; this.properties = configuration.getProperties(); this.dialect = Dialect.getDialect(properties); try {//from ww w. ja v a2s.com // get the mapping field via reflection :-( Field mappingField = Configuration.class.getDeclaredField("mapping"); mappingField.setAccessible(true); this.mapping = (Mapping) mappingField.get(configuration); } catch (Exception e) { throw new JbpmException("couldn't get the hibernate mapping", e); } }
From source file:org.jooq.util.jpa.JPADatabase.java
License:Open Source License
@Override protected DSLContext create0() { if (connection == null) { String packages = getProperties().getProperty("packages"); if (isBlank(packages)) { packages = ""; log.warn("No packages defined", "It is highly recommended that you provide explicit packages to scan"); }/* www.j av a 2 s . c o m*/ try { connection = DriverManager.getConnection("jdbc:h2:mem:jooq-meta-extensions", "sa", ""); final Configuration configuration = new Configuration().setProperty("hibernate.dialect", "org.hibernate.dialect.H2Dialect"); ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider( true); scanner.addIncludeFilter(new AnnotationTypeFilter(Entity.class)); for (String pkg : packages.split(",")) { for (BeanDefinition def : scanner.findCandidateComponents(defaultIfBlank(pkg, "").trim())) { configuration.addAnnotatedClass(Class.forName(def.getBeanClassName())); } } configuration.generateSchemaCreationScript(Dialect.getDialect(configuration.getProperties())); SchemaExport export = new SchemaExport(configuration, connection); export.create(true, true); } catch (Exception e) { throw new DataAccessException("Error while exporting schema", e); } } return DSL.using(connection); }
From source file:org.kuali.mobility.database.service.DatabaseServiceImpl.java
License:Open Source License
private String execute(String dialectStr, String delimiter, boolean overrideAlterTable) { PersistenceUnitInfo persistenceUnitInfo = entityManagerFactory.getPersistenceUnitInfo(); Map<String, Object> jpaPropertyMap = entityManagerFactory.getJpaPropertyMap(); jpaPropertyMap.put("hibernate.dialect", dialectStr); Configuration configuration = new Ejb3Configuration().configure(persistenceUnitInfo, jpaPropertyMap) .getHibernateConfiguration(); // KMEDatabaseConfiguration c = (KMEDatabaseConfiguration) configuration; if (overrideAlterTable) { Iterator iter = configuration.getTableMappings(); while (iter.hasNext()) { Table table = (Table) iter.next(); if (table.isPhysicalTable()) { Iterator subIter = table.getForeignKeyIterator(); while (subIter.hasNext()) { ForeignKey fk = (ForeignKey) subIter.next(); if (fk.isPhysicalConstraint()) { subIter.remove(); }/*from ww w . ja v a2 s. c o m*/ } } } } Properties configurationProperties = configuration.getProperties(); Dialect dialect = Dialect.getDialect(configurationProperties); // if (dialect instanceof KMEDialect) { // KMEDialect d = (KMEDialect) dialect; // d.setOverrideAlterTable(overrideAlterTable); // } Properties props = new Properties(); props.putAll(dialect.getDefaultProperties()); props.putAll(configurationProperties); String[] dropSQL = configuration.generateDropSchemaScript(dialect); String[] createSQL = configuration.generateSchemaCreationScript(dialect); Formatter formatter = (PropertiesHelper.getBoolean(Environment.FORMAT_SQL, props) ? FormatStyle.DDL : FormatStyle.NONE).getFormatter(); boolean format = true; formatter = (format ? FormatStyle.DDL : FormatStyle.NONE).getFormatter(); // String delimiter = ";"; StringBuffer output = new StringBuffer(); for (String s : dropSQL) { output.append(formatMe(s, formatter, delimiter)); output.append("\n"); } for (String s : createSQL) { output.append(formatMe(s, formatter, delimiter)); output.append("\n"); } SchemaExport schema = new SchemaExport(configuration); // schema.setFormat(true); // schema.setDelimiter(";"); // schema.setOutputFile("/tmp/schema.sql"); // schema.create(false, false); //org.hibernate.dialect.Oracle10gDialect //org.hibernate.dialect.MySQL5Dialect return output.toString(); }
From source file:org.lncc.martin.ct.dao.hibernate.HibernateUtil.java
License:Open Source License
public Session getConnection() { try {// w w w . j a v a 2s . c o m Configuration cfg = new Configuration().configure("hibernate.cfg.xml"); StandardServiceRegistryBuilder sb = new StandardServiceRegistryBuilder(); sb.applySettings(cfg.getProperties()); StandardServiceRegistry standardServiceRegistry = sb.build(); sessionFactory = cfg.buildSessionFactory(standardServiceRegistry); return sessionFactory.openSession(); } catch (Exception e) { System.out.println("Problemas ao criar Session Factory: " + e); return null; } }
From source file:org.n52.sos.config.sqlite.SQLiteSessionFactory.java
License:Open Source License
private SessionFactory createSessionFactory(Properties properties) { Configuration cfg = new Configuration().addAnnotatedClass(BooleanSettingValue.class) .addAnnotatedClass(FileSettingValue.class).addAnnotatedClass(IntegerSettingValue.class) .addAnnotatedClass(NumericSettingValue.class).addAnnotatedClass(StringSettingValue.class) .addAnnotatedClass(UriSettingValue.class).addAnnotatedClass(ChoiceSettingValue.class) .addAnnotatedClass(AdminUser.class).addAnnotatedClass(CapabilitiesExtensionImpl.class) .addAnnotatedClass(OfferingExtensionImpl.class).addAnnotatedClass(StaticCapabilitiesImpl.class) .addAnnotatedClass(Operation.class).addAnnotatedClass(ProcedureEncoding.class) .addAnnotatedClass(Binding.class).addAnnotatedClass(ObservationEncoding.class) .addAnnotatedClass(DynamicOfferingExtension.class) .addAnnotatedClass(DynamicOwsExtendedCapabilities.class) .addAnnotatedClass(TimeInstantSettingValue.class) .addAnnotatedClass(MultilingualStringSettingValue.class); cfg.registerTypeOverride(new HibernateFileType(), new String[] { "file", File.class.getName() }); cfg.registerTypeOverride(new HibernateUriType(), new String[] { "uri", URI.class.getName() }); cfg.registerTypeOverride(new HibernateTimeInstantType(), new String[] { "timeInstant", TimeInstant.class.getName() }); if (properties != null) { cfg.mergeProperties(properties); }//from w w w . j av a2 s .c o m cfg.mergeProperties(defaultProperties); ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(cfg.getProperties()) .build(); return cfg.buildSessionFactory(serviceRegistry); }
From source file:org.n52.sos.inspire.aqd.persistence.ReportingHeaderSQLiteSessionFactory.java
License:Open Source License
private SessionFactory createSessionFactory(Properties properties) { Configuration cfg = new Configuration().addAnnotatedClass(JSONFragment.class); if (properties != null) { cfg.mergeProperties(properties); }//from w w w. j a v a 2 s. c o m cfg.mergeProperties(defaultProperties); ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(cfg.getProperties()) .build(); return cfg.buildSessionFactory(serviceRegistry); }
From source file:org.olat.core.configuration.SetupPropertiesController.java
License:Apache License
private String getHibernateConnectionUrl() { OLATLocalSessionFactoryBean bean = (OLATLocalSessionFactoryBean) CoreSpringFactory .getBean(OLATLocalSessionFactoryBean.class); Configuration configuration = bean.getConfiguration(); Properties properties = configuration.getProperties(); return (String) properties.get("hibernate.connection.url"); }
From source file:org.olat.test.OlatTestCase.java
License:Apache License
@Before public void printBanner() { final OLATLocalSessionFactoryBean bean = (OLATLocalSessionFactoryBean) CoreSpringFactory .getBean(OLATLocalSessionFactoryBean.class); final Configuration configuration = bean.getConfiguration(); final Properties properties = configuration.getProperties(); final String[] propsOfInterest = new String[] { "hibernate.connection.driver_class", "hibernate.connection.provider_class", "hibernate.connection.url", "hibernate.connection.username", }; final String connectionURL = (String) properties.get("hibernate.connection.url"); hsqlDBConfigured = connectionURL != null && connectionURL.toLowerCase().indexOf("hsqldb") > 0; System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"); for (int i = 0; i < propsOfInterest.length; i++) { System.out.println("++" + propsOfInterest[i] + " -> " + properties.getProperty(propsOfInterest[i])); }//from ww w. j ava 2 s . c o m System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"); printOlatLocalProperties(); System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"); System.out.println("+ OLAT configuration initialized, starting now with junit tests +"); System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"); }
From source file:org.openremote.model.persistence.jpa.H2.java
License:Open Source License
/** * Creates an H2 configuration for Hibernate session factory. * * @param persistenceMode//from ww w . j a va 2 s . c o m * see {@link PersistenceMode} * * @param dbName * file path for the database storage -- only relevant when the persistence mode * is {@link PersistenceMode#ON_DISK} * * @param config * Hibernate configuration to use as the base * * @return * Hibernate session factory */ private static SessionFactory createSessionFactory(PersistenceMode persistenceMode, String dbName, Configuration config) { config.setProperty("hibernate.connection.url", "jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1;MVCC=TRUE"); if (persistenceMode == PersistenceMode.ON_DISK) { config.setProperty("hibernate.connection.url", "jdbc:h2:" + dbName); } config.setProperty("hibernate.connection.driver_class", "org.h2.Driver"); config.setProperty("hibernate.connection.username", "sa"); config.setProperty("hibernate.connection.pool_size", "3"); config.setProperty("hibernate.cache.provider_class", "org.hibernate.cache.internal.NoCacheProvider"); config.setProperty("hibernate.dialect", "org.hibernate.dialect.H2Dialect"); config.setProperty("hibernate.hbm2ddl.auto", "create"); config.setProperty("hibernate.current_session_context_class", "managed"); ServiceRegistry registry = new StandardServiceRegistryBuilder().applySettings(config.getProperties()) .build(); return config.buildSessionFactory(registry); }
From source file:org.optaplanner.examples.app.OptaPlannerExamplesApp.java
License:Apache License
public static void generateXMLFile() { KING = new xmlKing(); //Test DB connectivity String hibernatePropsFilePath = "D:\\Student Data\\Desktop\\optaplanner-distribution-6.1.0.Final\\examples\\sources\\src\\main\\resources\\hibernate.cfg.xml"; //String hibernatePropsFilePath = "org.lsdt.optaplannerLittleSprouts.database.hibernate.cfg.xml"; File hibernatePropsFile = new File(hibernatePropsFilePath); Configuration configuration = new Configuration(); configuration.configure(hibernatePropsFile); ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder() .applySettings(configuration.getProperties()).build(); try {/*from ww w . j a va 2 s . com*/ factory = configuration.buildSessionFactory(serviceRegistry); } catch (Throwable ex) { System.err.println("Failed to create sessionFactory object." + ex); throw new ExceptionInInitializerError(ex); } //Print all users Session session = factory.openSession(); Transaction tx = null; try { tx = session.beginTransaction(); ArrayList<User> users = (ArrayList<User>) session.createQuery("FROM User WHERE type = 'T'").list(); ArrayList<Child> children = (ArrayList<Child>) session.createQuery("FROM Child").list(); ArrayList<Availability> childAvailabilities = (ArrayList<Availability>) session .createQuery("FROM Availability WHERE is_child = 1").list(); ArrayList<Availability> teacherAvailabilities = (ArrayList<Availability>) session .createQuery("FROM Availability WHERE is_child = 0").list(); KING.retrieveUserData(users); KING.retrieveChildAvailabilityData(childAvailabilities); KING.retrieveTeacherAvailabilityData(teacherAvailabilities); KING.retrieveChildData(children); KING.setWeekStart(box.getSelectedItem().toString()); KING.doItAll(box.getSelectedItem().toString()); tx.commit(); } catch (HibernateException e) { if (tx != null) tx.rollback(); e.printStackTrace(); } finally { session.close(); } }