private DataConfig getDefaultDataConfig() { DataConfig dataConfig = RuntimeConfig.getCurrentInstance( session ).getDefaultDataConfig(); if (dataConfig == null) { dataConfig = IntactContext.calculateDefaultDataConfig( session ); } return dataConfig; } }
public void contextDestroyed( ServletContextEvent servletContextEvent ) { log.debug( "LogFactory.release and destroying application" ); LogFactory.release( Thread.currentThread().getContextClassLoader() ); log.debug( "Closing SessionFactory" ); IntactSession intactSession = new WebappSession( servletContextEvent.getServletContext(), null, null ); RuntimeConfig.getCurrentInstance( intactSession ).getDefaultDataConfig().closeSessionFactory(); }
private DaoFactory getDaoFactory() { return DaoFactory.getCurrentInstance( session, RuntimeConfig.getCurrentInstance( session ).getDefaultDataConfig() ); }
public DaoFactory getDaoFactory() { DataConfig dataConfig = RuntimeConfig.getCurrentInstance( session ).getDefaultDataConfig(); return getDaoFactory( dataConfig ); }
private Session getSession() { AbstractHibernateDataConfig abstractHibernateDataConfig = ( AbstractHibernateDataConfig ) IntactContext.getCurrentInstance().getConfig().getDefaultDataConfig(); SessionFactory factory = abstractHibernateDataConfig.getSessionFactory(); Session session = factory.getCurrentSession(); return session; }
private static Session getSession() { AbstractHibernateDataConfig dataConfig = (AbstractHibernateDataConfig) IntactContext.getCurrentInstance().getConfig().getDefaultDataConfig(); return dataConfig.getSessionFactory().getCurrentSession(); } }
public Session getSession() { AbstractHibernateDataConfig abstractHibernateDataConfig = ( AbstractHibernateDataConfig ) IntactContext.getCurrentInstance().getConfig().getDefaultDataConfig(); SessionFactory factory = abstractHibernateDataConfig.getSessionFactory(); Session session = factory.getCurrentSession(); return session; }
private Session getSession() { AbstractHibernateDataConfig abstractHibernateDataConfig = ( AbstractHibernateDataConfig ) IntactContext.getCurrentInstance().getConfig().getDefaultDataConfig(); SessionFactory factory = abstractHibernateDataConfig.getSessionFactory(); Session session = factory.getCurrentSession(); return session; }
private static Session getSession() { AbstractHibernateDataConfig dataConfig = (AbstractHibernateDataConfig) IntactContext.getCurrentInstance().getConfig().getDefaultDataConfig(); return dataConfig.getSessionFactory().getCurrentSession(); } }
/** * Generates the DDL schema * @param dialect the dialect to use (complete class name for the hibernate dialect object) * @return an array containing the SQL statements */ public static String[] generateDropSchemaDDL(String dialect) { Configuration cfg = ((AbstractHibernateDataConfig) IntactContext.getCurrentInstance().getConfig().getDefaultDataConfig()).getConfiguration(); Properties props = new Properties(); props.put(Environment.DIALECT, dialect); return cfg.generateDropSchemaScript(Dialect.getDialect(props)); }
private static UserContext createDefaultUserContext( IntactSession session ) { if ( log.isDebugEnabled() ) { log.debug( "Creating UserContext..." ); } AbstractHibernateDataConfig defaultDataConfig = ( AbstractHibernateDataConfig ) RuntimeConfig.getCurrentInstance( session ).getDefaultDataConfig(); Configuration configuration = defaultDataConfig.getConfiguration(); //configuration.configure(); String currentUser = configuration.getProperty( Environment.USER ); String password = configuration.getProperty( Environment.PASS ); UserContext userContext = new UserContext( currentUser, password ); return userContext; }
private static DaoFactory getDefaultDaoFactory(IntactContext context) { IntactSession session = context.getSession(); return DaoFactory.getCurrentInstance(session, RuntimeConfig.getCurrentInstance(session).getDefaultDataConfig()); }
/** * Generates the DDL schema * @param dialect the dialect to use (complete class name for the hibernate dialect object) * @return an array containing the SQL statements */ public static String[] generateCreateSchemaDDL(String dialect) { Configuration cfg = ((AbstractHibernateDataConfig) IntactContext.getCurrentInstance().getConfig().getDefaultDataConfig()).getConfiguration(); Properties props = new Properties(); props.put(Environment.DIALECT, dialect); return cfg.generateSchemaCreationScript(Dialect.getDialect(props)); }
public void flushSession() { DataConfig dataConfig = RuntimeConfig.getCurrentInstance( session ).getDefaultDataConfig(); dataConfig.flushSession(); // flush the CvContext in to avoid lazy initialization errors clearCvContext(); }
public static DaoFactory getCurrentInstance( IntactContext context ) { return getCurrentInstance( context.getSession(), context.getConfig().getDefaultDataConfig() ); }
public Session getSession() { RuntimeConfig config = RuntimeConfig.getCurrentInstance( intactSession ); DaoFactory daoFactory = DaoFactory.getCurrentInstance( intactSession, config.getDefaultDataConfig() ); if ( !daoFactory.isTransactionActive() ) { if ( config.isAutoBeginTransaction() ) { log.debug( "Auto starting transaction" ); daoFactory.beginTransaction(); // starts or uses an existing transaction } else { throw new AutoBeginTransactionException( "You must begin a transaction manually." ); } } // invoking the method from the session factory because if the session is closed it will automatically // open one return session.getSessionFactory().getCurrentSession(); }
private static void persistSchemaVersion(IntactContext context) { IntactSession session = context.getSession(); SchemaVersion requiredVersion = context.getConfig().getDefaultDataConfig().getMinimumRequiredVersion(); DbInfo dbInfo = new DbInfo(DbInfo.SCHEMA_VERSION, requiredVersion.toString()); if (log.isDebugEnabled()) log.debug("Persisting schema version: " + requiredVersion.toString()); DaoFactory daoFactory = DaoFactory.getCurrentInstance(session, RuntimeConfig.getCurrentInstance(session).getDefaultDataConfig()); context.getDataContext().beginTransaction(); daoFactory.getDbInfoDao().persist(dbInfo); try { context.getDataContext().commitTransaction(); } catch (IntactTransactionException e) { log.error(e); } }
/** * Drops the current schema, emptying the database */ public static void dropSchema() throws IntactTransactionException { if (log.isDebugEnabled()) log.debug("Droping schema"); DataContext dataContext = IntactContext.getCurrentInstance().getDataContext(); if (dataContext.isTransactionActive()) { throw new IllegalStateException("To drop the schema, the transaction must NOT be active"); } dataContext.beginTransaction(); Configuration cfg = ((AbstractHibernateDataConfig) IntactContext.getCurrentInstance().getConfig().getDefaultDataConfig()).getConfiguration(); SchemaExport se = new SchemaExport(cfg); se.drop(false, true); dataContext.commitTransaction(); }
/** * Creates a schema * @param initializeDatabase If false, do not initialize the database (e.g. don't create Institution) */ public static void createSchema(boolean initializeDatabase) throws IntactTransactionException { if (log.isDebugEnabled()) log.debug("Creating schema"); DataContext dataContext = IntactContext.getCurrentInstance().getDataContext(); if (dataContext.isTransactionActive()) { throw new IllegalStateException("To reset the schema, the transaction must NOT be active: "+dataContext.getDaoFactory().getCurrentTransaction()); } dataContext.beginTransaction(); Configuration cfg = ((AbstractHibernateDataConfig) IntactContext.getCurrentInstance().getConfig().getDefaultDataConfig()).getConfiguration(); SchemaExport se = new SchemaExport(cfg); se.create(false, true); dataContext.commitTransaction(); dataContext.beginTransaction(); if (initializeDatabase) { if (log.isDebugEnabled()) log.debug("Initializing database"); IntactConfigurator.initializeDatabase(IntactContext.getCurrentInstance()); } dataContext.commitTransaction(); }
private static void checkSchemaCompatibility( DataConfig dataConfig, IntactSession session ) { SchemaVersion requiredVersion = dataConfig.getMinimumRequiredVersion(); DaoFactory daoFactory = DaoFactory.getCurrentInstance( session, RuntimeConfig.getCurrentInstance( session ).getDefaultDataConfig() ); IntactTransaction tx = daoFactory.beginTransaction(); DbInfo dbInfoSchemaVersion = daoFactory.getDbInfoDao().get( DbInfo.SCHEMA_VERSION ); try { tx.commit(); } catch ( IntactTransactionException e ) { log.error( "Exception commiting " + e ); } SchemaVersion schemaVersion; if ( dbInfoSchemaVersion == null ) { log.warn( "Schema version does not exist. Will be created" ); setSchemaVersionToBePersisted( session ); return; } try { schemaVersion = SchemaVersion.parse( dbInfoSchemaVersion.getValue() ); } catch ( Exception e ) { throw new IntactInitializationError( "Error getting schema version", e ); } log.info( "Schema Version: " + schemaVersion ); if ( !schemaVersion.isCompatibleWith( requiredVersion ) ) { throw new IntactInitializationError( "Database schema version " + requiredVersion + " is required" + " to use this version of intact-core. Schema version found: " + schemaVersion ); } }