List of usage examples for java.lang ExceptionInInitializerError ExceptionInInitializerError
public ExceptionInInitializerError(String s)
From source file:org.grouter.common.hibernate.HibernateUtilContextAware.java
/** * Create session factories and configurations and store in hibernateConfigMap. On * completion we enter INITIALISED state. *//* w w w . j a v a 2s .co m*/ private static void createSessionFactoriesFromConfigMap() { // read in all config and create session factories Iterator iter = hibernateConfigMap.keySet().iterator(); while (iter.hasNext()) { SessionFactory sessionFactory; String key = (String) iter.next(); HibernateConfigItem hibernateConfigItem = hibernateConfigMap.get(key); String file = hibernateConfigItem.getConfigFile(); Configuration configuration; if (file == null) { log.info("Loading properties config and not from file "); configuration = hibernateConfigItem.getConfiguration(); } else { log.info("Loading properties from : " + file); configuration = new Configuration(); configuration = configuration.configure(file); } try { String sessionFactoryName = configuration.getProperty(Environment.SESSION_FACTORY_NAME); if (sessionFactoryName != null) { log.debug("Looking up SessionFactory in JNDI with name : " + sessionFactoryName); try { Hashtable env = new Hashtable(); env.put(Context.INITIAL_CONTEXT_FACTORY, configuration.getProperty(Environment.JNDI_CLASS)); env.put(Context.URL_PKG_PREFIXES, configuration.getProperty(Environment.JNDI_PREFIX)); env.put(Context.PROVIDER_URL, configuration.getProperty(Environment.JNDI_URL)); Context context = new InitialContext(env); JNDIUtils.printJNDI(context, log); sessionFactory = (SessionFactory) context.lookup(sessionFactoryName); if (sessionFactory == null) { throw new IllegalStateException( "SessionFactory from JNDI lookup returned a null implemenation using file : " + file); } } catch (NamingException ex) { log.error("Failed looking up sessinfactory : " + sessionFactoryName, ex); throw new RuntimeException(ex); } } else { sessionFactory = configuration.buildSessionFactory(); if (sessionFactory == null) { throw new IllegalStateException( "SessionFactory could not be createed from the configuration using file : " + file); } } hibernateConfigItem.setConfiguration(configuration); hibernateConfigItem.setSessionFactory(sessionFactory); // We need to have a default sessionfactory / configuration if (hibernateConfigItem.isDeafult()) { hibernateConfigItemDefault = hibernateConfigItem; } // setInterceptor(configuration, null); // hibernateConfigMap.put(key) } catch (Throwable ex) { log.error("Failed initializing from configuration.", ex); throw new ExceptionInInitializerError(ex); } } currentState = STATE.INITIALISED; log.info("Entered state : " + currentState); }
From source file:br.gov.jfrj.siga.model.dao.HibernateUtil.java
public static void configurarHibernate(Configuration configuration) { try {/*w w w .ja v a 2 s. c o m*/ conf = configuration; serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()) .buildServiceRegistry(); sessionFactory = configuration.buildSessionFactory(serviceRegistry); } catch (final Throwable ex) { // Make sure you log the exception, as it might be swallowed System.out.println("HibernateUtil"); ex.printStackTrace(); HibernateUtil.logger.error("No foi possvel configurar o hibernate.", ex); throw new ExceptionInInitializerError(ex); } }
From source file:cc.redpen.server.api.RedPenService.java
/** * Create a new redpen for the specified language. The validator properties map is a map of validator names to their (optional) properties. * Only validitors present in this map are added to the redpen configuration * * @param lang the language to use * @param validatorProperties a map of redpen validator names to a map of their properties * @return a configured redpen instance/* w ww . j a v a 2s. co m*/ */ public RedPen getRedPen(String lang, Map<String, Map<String, String>> validatorProperties) { Configuration.ConfigurationBuilder configBuilder = Configuration.builder(lang).secure(); // add the validators and their properties validatorProperties.forEach((validatorName, props) -> { ValidatorConfiguration validatorConfig = new ValidatorConfiguration(validatorName); props.forEach(validatorConfig::addProperty); configBuilder.addValidatorConfig(validatorConfig); }); try { return new RedPen(configBuilder.build()); } catch (RedPenException e) { LOG.error("Unable to initialize RedPen", e); throw new ExceptionInInitializerError(e); } }
From source file:com.fiveamsolutions.nci.commons.util.HibernateHelper.java
/** * This builds both the configuration and the session factory. *///from ww w.jav a2s . c o m public synchronized void initialize() { if (configuration == null) { try { configuration = new AnnotationConfiguration(); initializeConfig(); // We call buildSessionFactory twice, because it appears that the annotated classes are // not 'activated' in the config until we build. The filters required the classes to // be present, so we throw away the first factory and use the second. If this is // removed, you'll likely see a NoClassDefFoundError in the unit tests SessionFactory sf = configuration.buildSessionFactory(); sf.close(); modifyConfig(); buildSessionFactory(); } catch (HibernateException e) { LOG.error(e.getMessage(), e); throw new ExceptionInInitializerError(e); } } }
From source file:org.pentaho.platform.repository.hibernate.HibernateUtil.java
protected static boolean initialize() { IApplicationContext applicationContext = PentahoSystem.getApplicationContext(); // Add to entry/exit points list HibernateUtil hUtil = new HibernateUtil(); applicationContext.addEntryPointHandler(hUtil); applicationContext.addExitPointHandler(hUtil); // Look for some hibernate-specific properties... String hibernateConfigurationFile = lookupSetting(applicationContext, "hibernateConfigPath", //$NON-NLS-1$ "settings/config-file", //$NON-NLS-1$ "hibernate/hibernateConfigPath"); //$NON-NLS-1$ String hibernateManagedString = lookupSetting(applicationContext, "hibernateManaged", //$NON-NLS-1$ "settings/managed", //$NON-NLS-1$ "hibernate/hibernateManaged"); //$NON-NLS-1$ if (hibernateManagedString != null) { hibernateManaged = Boolean.parseBoolean(hibernateManagedString); }/*from w w w .j a va 2 s . com*/ try { HibernateUtil.configuration = new Configuration(); HibernateUtil.configuration.setEntityResolver(new PentahoEntityResolver()); HibernateUtil.configuration.setListener("load", new HibernateLoadEventListener()); //$NON-NLS-1$ if (hibernateConfigurationFile != null) { String configPath = applicationContext.getSolutionPath(hibernateConfigurationFile); File cfgFile = new File(configPath); if (cfgFile.exists()) { HibernateUtil.configuration.configure(cfgFile); } else { HibernateUtil.log.error(Messages.getInstance() .getErrorString("HIBUTIL.ERROR_0012_CONFIG_NOT_FOUND", configPath)); //$NON-NLS-1$ return false; } } else { // Assume defaults which means we hope Hibernate finds a configuration // file in a file named hibernate.cfg.xml HibernateUtil.log.error(Messages.getInstance() .getErrorString("HIBUTIL.ERROR_0420_CONFIGURATION_ERROR_NO_HIB_CFG_FILE_SETTING")); //$NON-NLS-1$ HibernateUtil.configuration.configure(); } String dsName = HibernateUtil.configuration.getProperty("connection.datasource"); //$NON-NLS-1$ if ((dsName != null) && dsName.toUpperCase().endsWith("HIBERNATE")) { //$NON-NLS-1$ // IDBDatasourceService datasourceService = (IDBDatasourceService) PentahoSystem.getObjectFactory().getObject("IDBDatasourceService",null); //$NON-NLS-1$ IDBDatasourceService datasourceService = getDatasourceService(); String actualDSName = datasourceService.getDSBoundName("Hibernate"); //$NON-NLS-1$ HibernateUtil.configuration.setProperty("hibernate.connection.datasource", actualDSName); //$NON-NLS-1$ } HibernateUtil.dialect = HibernateUtil.configuration.getProperty("dialect"); //$NON-NLS-1$ /* * configuration.addResource("org/pentaho/platform/repository/runtime/RuntimeElement.hbm.xml"); //$NON-NLS-1$ * configuration.addResource("org/pentaho/platform/repository/content/ContentLocation.hbm.xml"); //$NON-NLS-1$ * configuration.addResource("org/pentaho/platform/repository/content/ContentItem.hbm.xml"); //$NON-NLS-1$ * configuration.addResource("org/pentaho/platform/repository/content/ContentItemFile.hbm.xml"); //$NON-NLS-1$ */ if (!HibernateUtil.hibernateManaged) { HibernateUtil.log.info(Messages.getInstance().getString("HIBUTIL.USER_HIBERNATEUNMANAGED")); //$NON-NLS-1$ HibernateUtil.sessionFactory = HibernateUtil.configuration.buildSessionFactory(); } else { HibernateUtil.factoryJndiName = HibernateUtil.configuration .getProperty(Environment.SESSION_FACTORY_NAME); if (HibernateUtil.factoryJndiName == null) { HibernateUtil.log .error(Messages.getInstance().getErrorString("HIBUTIL.ERROR_0013_NO_SESSION_FACTORY")); return false; } HibernateUtil.log.info(Messages.getInstance().getString("HIBUTIL.USER_HIBERNATEMANAGED")); //$NON-NLS-1$ HibernateUtil.configuration.buildSessionFactory(); // Let hibernate Bind it // to JNDI... // BISERVER-2006: Below content is a community contribution see the JIRA case for more info // -------- Begin Contribution -------- // Build the initial context to use when looking up the session Properties contextProperties = new Properties(); if (configuration.getProperty("hibernate.jndi.url") != null) { //$NON-NLS-1$ contextProperties.put(Context.PROVIDER_URL, configuration.getProperty("hibernate.jndi.url")); //$NON-NLS-1$ } if (configuration.getProperty("hibernate.jndi.class") != null) { //$NON-NLS-1$ contextProperties.put(Context.INITIAL_CONTEXT_FACTORY, configuration.getProperty("hibernate.jndi.class")); //$NON-NLS-1$ } iniCtx = new InitialContext(contextProperties); // --------- End Contribution --------- } Dialect.getDialect(HibernateUtil.configuration.getProperties()); return true; } catch (Throwable ex) { HibernateUtil.log .error(Messages.getInstance().getErrorString("HIBUTIL.ERROR_0006_BUILD_SESSION_FACTORY"), ex); //$NON-NLS-1$ throw new ExceptionInInitializerError(ex); } }
From source file:org.paxle.data.db.impl.CommandDB.java
public CommandDB(URL configURL, List<URL> mappings, Properties extraProperties, ICommandTracker commandTracker, IDocumentFactory commandFactory) { if (configURL == null) throw new NullPointerException("The URL to the hibernate config file is null."); if (mappings == null) throw new NullPointerException("The list of mapping files was null."); try {/* ww w .ja v a2s. c o m*/ this.commandTracker = commandTracker; this.commandFactory = commandFactory; /* =========================================================================== * Init Hibernate * =========================================================================== */ try { Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader()); // Read the hibernate configuration from *.cfg.xml this.logger.info(String.format("Loading DB configuration from URL '%s'.", configURL)); this.config = new Configuration().configure(configURL); // register an interceptor (required to support our interface-based command model) this.config.setInterceptor(new InterfaceInterceptor(this.commandFactory)); // merge with additional properties if (extraProperties != null) { this.config.addProperties(extraProperties); } // post-processing of read properties ConnectionUrlTool.postProcessProperties(this.config); // load the various mapping files for (URL mapping : mappings) { if (this.logger.isDebugEnabled()) this.logger.debug(String.format("Loading mapping file from URL '%s'.", mapping)); this.config.addURL(mapping); } // String[] sql = this.config.generateSchemaCreationScript( new org.hibernate.dialect.DerbyDialect()); // create the session factory this.sessionFactory = this.config.buildSessionFactory(); } catch (Throwable ex) { // Make sure you log the exception, as it might be swallowed this.logger.error("Initial SessionFactory creation failed.", ex); throw new ExceptionInInitializerError(ex); } this.optimizeDbSchema(); cntTotal = this.totalSize(); cntCrawlerQueue = this.size("enqueued"); logger.info("command-db size: " + cntTotal + ", to crawl: " + cntCrawlerQueue); /* =========================================================================== * Init Reader/Writer Threads * =========================================================================== */ this.writerThread = new Writer(); /* =========================================================================== * Init Cache * =========================================================================== */ // configure caching manager this.manager = CacheManager.getInstance(); // init a new cache this.urlExistsCache = new Cache(EHCACHE_NAME, 100000, false, false, 60 * 60, 30 * 60); this.manager.addCache(this.urlExistsCache); // init/open the double URLs cache, initializes the bloom-filter openDoubleURLSet(); } catch (Throwable e) { this.logger.error( String.format("Unexpected '%s' while initializing the command-DB.", e.getClass().getName()), e); throw new RuntimeException(e); } }
From source file:br.gov.jfrj.siga.model.dao.HibernateUtil.java
public static void configurarHibernate(Session session) { try {/*from w w w. j ava 2s .c o m*/ sessionFactory = session.getSessionFactory(); } catch (final Throwable ex) { // Make sure you log the exception, as it might be swallowed HibernateUtil.logger.error("No foi possvel configurar o hibernate.", ex); throw new ExceptionInInitializerError(ex); } }
From source file:com.openkm.dao.HibernateUtil.java
/** * Get instance//from w ww. ja v a2 s . c om */ public static SessionFactory getSessionFactory(String hbm2ddl) { if (sessionFactory == null) { try { // Configure Hibernate Configuration cfg = getConfiguration().configure(); cfg.setProperty("hibernate.dialect", Config.HIBERNATE_DIALECT); cfg.setProperty("hibernate.connection.datasource", Config.HIBERNATE_DATASOURCE); cfg.setProperty("hibernate.hbm2ddl.auto", hbm2ddl); cfg.setProperty("hibernate.show_sql", Config.HIBERNATE_SHOW_SQL); cfg.setProperty("hibernate.generate_statistics", Config.HIBERNATE_STATISTICS); cfg.setProperty("hibernate.search.analyzer", Config.HIBERNATE_SEARCH_ANALYZER); cfg.setProperty("hibernate.search.default.directory_provider", "org.hibernate.search.store.FSDirectoryProvider"); cfg.setProperty("hibernate.search.default.indexBase", Config.HIBERNATE_SEARCH_INDEX_HOME); cfg.setProperty("hibernate.search.default.exclusive_index_use", Config.HIBERNATE_SEARCH_INDEX_EXCLUSIVE); cfg.setProperty("hibernate.search.default.optimizer.operation_limit.max", "500"); cfg.setProperty("hibernate.search.default.optimizer.transaction_limit.max", "75"); cfg.setProperty("hibernate.worker.execution", "async"); // http://relation.to/Bloggers/PostgreSQLAndBLOBs // cfg.setProperty("hibernate.jdbc.use_streams_for_binary", "false"); // Show configuration log.info("Hibernate 'hibernate.dialect' = {}", cfg.getProperty("hibernate.dialect")); log.info("Hibernate 'hibernate.connection.datasource' = {}", cfg.getProperty("hibernate.connection.datasource")); log.info("Hibernate 'hibernate.hbm2ddl.auto' = {}", cfg.getProperty("hibernate.hbm2ddl.auto")); log.info("Hibernate 'hibernate.show_sql' = {}", cfg.getProperty("hibernate.show_sql")); log.info("Hibernate 'hibernate.generate_statistics' = {}", cfg.getProperty("hibernate.generate_statistics")); log.info("Hibernate 'hibernate.search.default.directory_provider' = {}", cfg.getProperty("hibernate.search.default.directory_provider")); log.info("Hibernate 'hibernate.search.default.indexBase' = {}", cfg.getProperty("hibernate.search.default.indexBase")); if (HBM2DDL_CREATE.equals(hbm2ddl)) { // In case of database schema creation, also clean filesystem data. // This means, conversion cache, file datastore and Lucene indexes. log.info("Cleaning filesystem data from: {}", Config.REPOSITORY_HOME); FileUtils.deleteQuietly(new File(Config.REPOSITORY_HOME)); } // Create database schema, if needed sessionFactory = cfg.buildSessionFactory(); if (HBM2DDL_CREATE.equals(hbm2ddl)) { log.info("Executing specific import for: {}", Config.HIBERNATE_DIALECT); InputStream is = ConfigUtils.getResourceAsStream("default.sql"); String adapted = DatabaseDialectAdapter.dialectAdapter(is, Config.HIBERNATE_DIALECT); executeSentences(new StringReader(adapted)); IOUtils.closeQuietly(is); } if (HBM2DDL_CREATE.equals(hbm2ddl) || HBM2DDL_UPDATE.equals(hbm2ddl)) { // Create or update translations for (String res : ConfigUtils.getResources("i18n")) { String oldTrans = null; String langId = null; // Preserve translation changes if (HBM2DDL_UPDATE.equals(hbm2ddl)) { langId = FileUtils.getFileName(res); log.info("Preserving translations for: {}", langId); oldTrans = preserveTranslations(langId); } InputStream isLang = ConfigUtils.getResourceAsStream("i18n/" + res); log.info("Importing translation: {}", res); executeSentences(new InputStreamReader(isLang)); IOUtils.closeQuietly(isLang); // Apply previous translation changes if (HBM2DDL_UPDATE.equals(hbm2ddl)) { if (oldTrans != null) { log.info("Restoring translations for: {}", langId); executeSentences(new StringReader(oldTrans)); } } } // Replace "create" or "update" by "none" to prevent repository reset on restart if (Boolean.parseBoolean(Config.HIBERNATE_CREATE_AUTOFIX)) { log.info("Executing Hibernate create autofix"); hibernateCreateAutofix(Config.HOME_DIR + "/" + Config.OPENKM_CONFIG); } else { log.info("Hibernate create autofix not executed because of {}={}", Config.PROPERTY_HIBERNATE_CREATE_AUTOFIX, Config.HIBERNATE_CREATE_AUTOFIX); } } } catch (HibernateException e) { log.error(e.getMessage(), e); throw new ExceptionInInitializerError(e); } catch (URISyntaxException e) { log.error(e.getMessage(), e); throw new ExceptionInInitializerError(e); } catch (IOException e) { log.error(e.getMessage(), e); throw new ExceptionInInitializerError(e); } } return sessionFactory; }
From source file:com.ikon.dao.HibernateUtil.java
/** * Get instance/*from w w w .ja v a2s . c om*/ */ public static SessionFactory getSessionFactory(String hbm2ddl) { if (sessionFactory == null) { try { // Configure Hibernate Configuration cfg = getConfiguration().configure(); cfg.setProperty("hibernate.dialect", Config.HIBERNATE_DIALECT); cfg.setProperty("hibernate.connection.datasource", Config.HIBERNATE_DATASOURCE); cfg.setProperty("hibernate.hbm2ddl.auto", hbm2ddl); cfg.setProperty("hibernate.show_sql", Config.HIBERNATE_SHOW_SQL); cfg.setProperty("hibernate.generate_statistics", Config.HIBERNATE_STATISTICS); cfg.setProperty("hibernate.search.analyzer", Config.HIBERNATE_SEARCH_ANALYZER); cfg.setProperty("hibernate.search.default.directory_provider", "org.hibernate.search.store.FSDirectoryProvider"); cfg.setProperty("hibernate.search.default.indexBase", Config.HIBERNATE_SEARCH_INDEX_HOME); cfg.setProperty("hibernate.search.default.optimizer.operation_limit.max", "500"); cfg.setProperty("hibernate.search.default.optimizer.transaction_limit.max", "75"); cfg.setProperty("hibernate.worker.execution", "async"); // http://relation.to/Bloggers/PostgreSQLAndBLOBs // cfg.setProperty("hibernate.jdbc.use_streams_for_binary", "false"); // Show configuration log.info("Hibernate 'hibernate.dialect' = {}", cfg.getProperty("hibernate.dialect")); log.info("Hibernate 'hibernate.connection.datasource' = {}", cfg.getProperty("hibernate.connection.datasource")); log.info("Hibernate 'hibernate.hbm2ddl.auto' = {}", cfg.getProperty("hibernate.hbm2ddl.auto")); log.info("Hibernate 'hibernate.show_sql' = {}", cfg.getProperty("hibernate.show_sql")); log.info("Hibernate 'hibernate.generate_statistics' = {}", cfg.getProperty("hibernate.generate_statistics")); log.info("Hibernate 'hibernate.search.default.directory_provider' = {}", cfg.getProperty("hibernate.search.default.directory_provider")); log.info("Hibernate 'hibernate.search.default.indexBase' = {}", cfg.getProperty("hibernate.search.default.indexBase")); if (HBM2DDL_CREATE.equals(hbm2ddl)) { // In case of database schema creation, also clean filesystem data. // This means, conversion cache, file datastore and Lucene indexes. log.info("Cleaning filesystem data from: {}", Config.REPOSITORY_HOME); FileUtils.deleteQuietly(new File(Config.REPOSITORY_HOME)); } // Create database schema, if needed sessionFactory = cfg.buildSessionFactory(); if (HBM2DDL_CREATE.equals(hbm2ddl)) { log.info("Executing specific import for: {}", Config.HIBERNATE_DIALECT); InputStream is = ConfigUtils.getResourceAsStream("default.sql"); String adapted = DatabaseDialectAdapter.dialectAdapter(is, Config.HIBERNATE_DIALECT); executeImport(new StringReader(adapted)); IOUtils.closeQuietly(is); } if (HBM2DDL_CREATE.equals(hbm2ddl) || HBM2DDL_UPDATE.equals(hbm2ddl)) { // Create or update translations for (String res : ConfigUtils.getResources("i18n")) { String oldTrans = null; String langId = null; // Preserve translation changes if (HBM2DDL_UPDATE.equals(hbm2ddl)) { langId = FileUtils.getFileName(res); log.info("Preserving translations for: {}", langId); oldTrans = preserveTranslations(langId); } InputStream isLang = ConfigUtils.getResourceAsStream("i18n/" + res); log.info("Importing translation: {}", res); executeImport(new InputStreamReader(isLang)); IOUtils.closeQuietly(isLang); // Apply previous translation changes if (HBM2DDL_UPDATE.equals(hbm2ddl)) { if (oldTrans != null) { log.info("Restoring translations for: {}", langId); executeImport(new StringReader(oldTrans)); } } } // Replace "create" or "update" by "none" to prevent repository reset on restart if (Boolean.parseBoolean(Config.HIBERNATE_CREATE_AUTOFIX)) { log.info("Executing Hibernate create autofix"); hibernateCreateAutofix(Config.HOME_DIR + "/" + Config.ikon_CONFIG); } else { log.info("Hibernate create autofix not executed because of {}={}", Config.PROPERTY_HIBERNATE_CREATE_AUTOFIX, Config.HIBERNATE_CREATE_AUTOFIX); } } } catch (HibernateException e) { log.error(e.getMessage(), e); throw new ExceptionInInitializerError(e); } catch (URISyntaxException e) { log.error(e.getMessage(), e); throw new ExceptionInInitializerError(e); } catch (IOException e) { log.error(e.getMessage(), e); throw new ExceptionInInitializerError(e); } } return sessionFactory; }
From source file:com.he5ed.lib.cloudprovider.picker.CloudPickerActivity.java
/** * Setup the relevant API instance to interact with server * * @param account of the service API/*from w w w . j a v a2 s . c om*/ */ private void setupApi(CloudAccount account) { // use cloud API class reflection try { Class<?> clazz = Class.forName(account.api); Constructor constructor = clazz.getConstructor(Context.class, Account.class); mApi = (BaseApi) constructor.newInstance(this, account.getAccount()); mApi.prepareApi(this); } catch (ClassNotFoundException e) { e.printStackTrace(); throw new ExceptionInInitializerError("Cloud API can not be found!"); } catch (InstantiationException e) { e.printStackTrace(); throw new ExceptionInInitializerError("Cloud API can not be initialized!"); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (NoSuchMethodException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } mProgressBar.setVisibility(View.VISIBLE); }