Java Code Examples for org.hibernate.cfg.Configuration#getProperty()
The following examples show how to use
org.hibernate.cfg.Configuration#getProperty() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HibernateSessionManager.java From Knowage-Server with GNU Affero General Public License v3.0 | 6 votes |
private static Configuration setDialectPropertyToConfiguration() { Configuration conf = new Configuration(); File hibernateConfigurationFileFile = DAOConfig.getHibernateConfigurationFileFile(); if (hibernateConfigurationFileFile != null) { // for testing conf = conf.configure(hibernateConfigurationFileFile); } else { conf = conf.configure(DAOConfig.getHibernateConfigurationFile()); } String figuredOutValue = conf.getProperty(PROPERTY_DIALECT); if (figuredOutValue != null) { logger.info("Hibernate configuration set dialect to " + figuredOutValue); } else { logger.warn("Property hibernate.dialect not set! Trying to figure out what dialect needs to be used..."); determineDialect(conf); } return conf; }
Example 2
Source File: UnlimitedMessageColumnsMigration.java From sailfish-core with Apache License 2.0 | 5 votes |
public UnlimitedMessageColumnsMigration(Session session, Configuration configuration) throws URISyntaxException { this.session = session; String dialect = configuration.getProperty(AvailableSettings.DIALECT); this.nativeDbQueries = NativeDbQueries.fromDialect(dialect); String url = configuration.getProperty(AvailableSettings.URL); URI full = new URI(url); URI uri = new URI(full.getSchemeSpecificPart()); this.databaseName = uri.getPath().replace("/", ""); }
Example 3
Source File: HibernateSessionManager.java From Knowage-Server with GNU Affero General Public License v3.0 | 5 votes |
/** * Try to figure out which Hibernate dialect to use. * * @param conf Actual Hibernate configuration */ private static void determineDialect(Configuration conf) { String datasourceJndi = conf.getProperty(PROPERTY_DATASOURCE_JNDI); if (datasourceJndi == null) { throw new IllegalStateException("The property hibernate.connection.datasource is not set in file"); } String figuredOutValue = getDialect(datasourceJndi); logger.warn("Property hibernate.dialect set to " + figuredOutValue); conf.setProperty(PROPERTY_DIALECT, figuredOutValue); }
Example 4
Source File: StatementDialectFactoryBean.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
public void init() { Configuration hibernateConfiguration = hibernateConfigurationProvider.getConfiguration(); String dialect = hibernateConfiguration.getProperty( KEY_DIALECT ); statementDialect = dialectMap.get( dialect ); if ( statementDialect == null ) { throw new RuntimeException( "Unsupported dialect: " + dialect ); } }
Example 5
Source File: HibernateUtil.java From unitime with Apache License 2.0 | 5 votes |
public static void fixSchemaInFormulas(Configuration cfg) throws ClassNotFoundException { cfg.buildMappings(); Class dialect = Class.forName(cfg.getProperty("dialect")); String schema = cfg.getProperty("default_schema"); for (Iterator i=cfg.getClassMappings();i.hasNext();) { PersistentClass pc = (PersistentClass)i.next(); for (Iterator j=pc.getPropertyIterator();j.hasNext();) { Property p = (Property)j.next(); for (Iterator k=p.getColumnIterator();k.hasNext();) { Selectable c = (Selectable)k.next(); if (c instanceof Formula) { Formula f = (Formula)c; boolean updated = false; if (schema != null && f.getFormula() != null && f.getFormula().indexOf("%SCHEMA%")>=0) { f.setFormula(f.getFormula().replaceAll("%SCHEMA%", schema)); sLog.debug("Schema updated in "+pc.getClassName()+"."+p.getName()+" to "+f.getFormula()); } if (f.getFormula()!=null && (f.getFormula().indexOf("%TRUE%")>=0 || f.getFormula().indexOf("%FALSE%")>=0)) { if (isPostgress(dialect)) { f.setFormula(f.getFormula().replaceAll("%TRUE%", "'t'").replaceAll("%FALSE%", "'f'")); } else { f.setFormula(f.getFormula().replaceAll("%TRUE%", "1").replaceAll("%FALSE%", "0")); } } if (updated) sLog.debug("Schema updated in "+pc.getClassName()+"."+p.getName()+" to "+f.getFormula()); } } } } }
Example 6
Source File: RobeSessionFactoryFactory.java From robe with GNU Lesser General Public License v3.0 | 5 votes |
@Override protected void configure(Configuration configuration, ServiceRegistry registry) { String prefix = configuration.getProperty("hibernate.prefix"); if (prefix != null) { configuration.setPhysicalNamingStrategy(new RobeHibernateNamingStrategy(prefix)); LOGGER.info("Table Prefix: ", prefix); } }
Example 7
Source File: AbstractUserTypeHibernateIntegrator.java From jadira with Apache License 2.0 | 5 votes |
public void integrate(Configuration configuration, SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) { try { ConfigurationHelper.setCurrentSessionFactory(sessionFactory); String isEnabled = configuration.getProperty(REGISTER_USERTYPES_KEY); String javaZone = configuration.getProperty(DEFAULT_JAVAZONE_KEY); String databaseZone = configuration.getProperty(DEFAULT_DATABASEZONE_KEY); String seed = configuration.getProperty(DEFAULT_SEED_KEY); String currencyCode = configuration.getProperty(DEFAULT_CURRENCYCODE_KEY); String jdbc42Apis = configuration.getProperty(JDBC42_API_KEY); configureDefaultProperties(sessionFactory, javaZone, databaseZone, seed, currencyCode, jdbc42Apis); if (isEnabled != null && Boolean.valueOf(isEnabled)) { autoRegisterUsertypes(configuration); } final boolean use42Api = use42Api(configuration.getProperty(JDBC42_API_KEY), sessionFactory); ConfigurationHelper.setUse42Api(sessionFactory, use42Api); // doIntegrate(configuration, sessionFactory, serviceRegistry); } finally { ConfigurationHelper.setCurrentSessionFactory(null); } }
Example 8
Source File: JACCPreDeleteEventListener.java From cacheonix-core with GNU Lesser General Public License v2.1 | 4 votes |
public void initialize(Configuration cfg){ contextID = cfg.getProperty(Environment.JACC_CONTEXTID); }
Example 9
Source File: JACCPreLoadEventListener.java From cacheonix-core with GNU Lesser General Public License v2.1 | 4 votes |
public void initialize(Configuration cfg){ contextID = cfg.getProperty(Environment.JACC_CONTEXTID); }
Example 10
Source File: JACCPreInsertEventListener.java From cacheonix-core with GNU Lesser General Public License v2.1 | 4 votes |
public void initialize(Configuration cfg){ contextID = cfg.getProperty(Environment.JACC_CONTEXTID); }
Example 11
Source File: JACCPreUpdateEventListener.java From cacheonix-core with GNU Lesser General Public License v2.1 | 4 votes |
public void initialize(Configuration cfg){ contextID = cfg.getProperty(Environment.JACC_CONTEXTID); }
Example 12
Source File: UniqueIdGenerator.java From unitime with Apache License 2.0 | 4 votes |
public static void configure(Configuration config) { sGenClass = config.getProperty("tmtbl.uniqueid.generator"); if (sGenClass==null) sGenClass = "org.hibernate.id.SequenceGenerator"; sDefaultSchema = config.getProperty("default_schema"); sNormalizer = config.createMappings().getObjectNameNormalizer(); }
Example 13
Source File: ConnectionManager.java From spacewalk with GNU General Public License v2.0 | 4 votes |
/** * Create a SessionFactory, loading the hbm.xml files from the specified * location. * @param packageNames Package name to be searched. */ private void createSessionFactory() { if (sessionFactory != null && !sessionFactory.isClosed()) { return; } List<String> hbms = new LinkedList<String>(); for (Iterator<String> iter = packageNames.iterator(); iter.hasNext();) { String pn = iter.next(); hbms.addAll(FinderFactory.getFinder(pn).find("hbm.xml")); if (LOG.isDebugEnabled()) { LOG.debug("Found: " + hbms); } } try { Configuration config = new Configuration(); /* * Let's ask the RHN Config for all properties that begin with * hibernate.* */ LOG.info("Adding hibernate properties to hibernate Configuration"); Properties hibProperties = Config.get().getNamespaceProperties( "hibernate"); hibProperties.put("hibernate.connection.username", Config.get() .getString(ConfigDefaults.DB_USER)); hibProperties.put("hibernate.connection.password", Config.get() .getString(ConfigDefaults.DB_PASSWORD)); hibProperties.put("hibernate.connection.url", ConfigDefaults.get().getJdbcConnectionString()); config.addProperties(hibProperties); // Force the use of our txn factory if (config.getProperty(Environment.TRANSACTION_STRATEGY) != null) { throw new IllegalArgumentException("The property " + Environment.TRANSACTION_STRATEGY + " can not be set in a configuration file;" + " it is set to a fixed value by the code"); } for (Iterator<String> i = hbms.iterator(); i.hasNext();) { String hbmFile = i.next(); if (LOG.isDebugEnabled()) { LOG.debug("Adding resource " + hbmFile); } config.addResource(hbmFile); } if (configurators != null) { for (Iterator<Configurator> i = configurators.iterator(); i .hasNext();) { Configurator c = i.next(); c.addConfig(config); } } // add empty varchar warning interceptor EmptyVarcharInterceptor interceptor = new EmptyVarcharInterceptor(); interceptor.setAutoConvert(true); config.setInterceptor(interceptor); sessionFactory = config.buildSessionFactory(); } catch (HibernateException e) { LOG.error("FATAL ERROR creating HibernateFactory", e); } }
Example 14
Source File: HibernateSessionManager.java From Knowage-Server with GNU Affero General Public License v3.0 | 3 votes |
public static String getDialect() { logger.info("Initializing hibernate Session Factory Described by [" + DAOConfig.getHibernateConfigurationFile() + "]"); Configuration conf = setDialectPropertyToConfiguration(); return conf.getProperty(PROPERTY_DIALECT); }