public Institution getInstitution() throws IntactException { return getConfig().getInstitution(); }
/** * Checks if there is only one value, and then if this value is an accession returns true */ private static boolean isQuerySearchingOnlyOneAc(String[] values) { if (values.length > 1 || values.length == 0) { return false; } String value = values[0]; String institutionPrefix = IntactContext.getCurrentInstance().getConfig().getAcPrefix(); return (value.toUpperCase().startsWith(institutionPrefix) && !value.endsWith("%")); }
/** * Checks if there is only one value, and then if this value is an accession returns true */ private static boolean isQuerySearchingOnlyOneAc( String[] values ) { if ( values.length > 1 || values.length == 0 ) { return false; } String value = values[0]; String institutionPrefix = IntactContext.getCurrentInstance().getConfig().getAcPrefix(); return ( value.toUpperCase().startsWith( institutionPrefix ) && !value.endsWith( "%" ) ); }
private Session getSession() { AbstractHibernateDataConfig abstractHibernateDataConfig = ( AbstractHibernateDataConfig ) IntactContext.getCurrentInstance().getConfig().getDefaultDataConfig(); SessionFactory factory = abstractHibernateDataConfig.getSessionFactory(); Session session = factory.getCurrentSession(); return session; }
public void close() { for (DataConfig dataConfig : getConfig().getDataConfigs()) { if (dataConfig instanceof AbstractHibernateDataConfig) { ((AbstractHibernateDataConfig)dataConfig).getSessionFactory().close(); } } session = null; dataContext = null; currentInstance.set(null); }
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(); } }
private static Session getSession() { AbstractHibernateDataConfig dataConfig = (AbstractHibernateDataConfig) IntactContext.getCurrentInstance().getConfig().getDefaultDataConfig(); return dataConfig.getSessionFactory().getCurrentSession(); } }
/** * The ID is the concatenation of the prefix and a sequence provided by the database, separated * by a dash. * * @param sessionImplementor a hibernate session implementor * @param object the object being persisted * * @return the new generated ID * * @throws HibernateException if something goes wrong */ @Override public Serializable generate( SessionImplementor sessionImplementor, Object object ) throws HibernateException { String prefix = IntactContext.getCurrentInstance().getConfig().getAcPrefix(); String id = prefix + "-" + super.generate( sessionImplementor, object ); log.trace( "Assigning Id: " + id ); return id; }
/** * 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)); }
/** * 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)); }
public static DaoFactory getCurrentInstance( IntactContext context, String dataConfigName ) { return getCurrentInstance( context.getSession(), context.getConfig().getDataConfig( dataConfigName ) ); }
public static DaoFactory getCurrentInstance( IntactContext context ) { return getCurrentInstance( context.getSession(), context.getConfig().getDefaultDataConfig() ); }
/** * 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(); }
private static void persistInstitution(IntactContext context) throws IntactTransactionException { Institution institution = context.getConfig().getInstitution(); if (institution == null) { throw new NullPointerException("Institution is null. Set an institution to the RuntimeConfig first"); } // remove ac, it should not have one at this point to be persisted correctly if (institution.getAc() != null) institution.setAc(null); log.debug("Persisting institution: " + institution.getShortLabel()); DaoFactory daoFactory = getDefaultDaoFactory(context); daoFactory.beginTransaction(); daoFactory.getInstitutionDao().persist(institution); context.getDataContext().commitTransaction(); }
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); } }
/** * Import a testDataset into the database * @param testDataset the dataset to use */ public void importTestDataset(DbUnitTestDataset testDataset) { if (testDataset == null) { throw new NullPointerException("testDataset"); } try { IDataSet dbUnitDataSet = convertTestDatasetToDbUnit(testDataset); DatabaseOperation.INSERT.execute(getDatabaseConnection(), dbUnitDataSet); } catch (Exception e) { throw new IntactException("Exception importing dataset: "+testDataset.getId(), e); } // reset institution List<Institution> institutions = IntactContext.getCurrentInstance().getDataContext().getDaoFactory().getInstitutionDao().getAll(); if (!institutions.isEmpty()) { IntactContext.getCurrentInstance().getConfig().setInstitution(institutions.get(0)); } }
/** * 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 addStartAndEndPercentIfNecessary( QueryTerm term ) { if ( term.hasModifier( QueryModifier.PHRASE_DELIM ) ) { return; } String acPrefix = IntactContext.getCurrentInstance().getConfig().getAcPrefix(); if ( !term.startsWith( acPrefix ) && !term.hasModifier( QueryModifier.WILDCARD_START ) ) { term.addModifier( QueryModifier.WILDCARD_START ); } if ( !term.startsWith( acPrefix ) && !term.hasModifier( QueryModifier.WILDCARD_END ) ) { term.addModifier( QueryModifier.WILDCARD_END ); } }