protected DaoFactory getDaoFactory() { return getDataContext().getDaoFactory(); }
/** * 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(); }
public void beginTransaction() { beginTransaction( getDefaultDataConfig().getName() ); }
public boolean isTransactionActive() { return isTransactionActive( getDefaultDataConfig().getName() ); }
public void commitTransaction() throws IntactTransactionException { try { commitTransaction( getDefaultDataConfig().getName() ); } catch ( Exception e ) { throw new IntactTransactionException( e ); } }
public int getEntryCount() throws IndexerException { if ( count == null ) { DaoFactory daoFactory = IntactContext.getCurrentInstance().getDataContext().getDaoFactory(); InteractorDao<InteractorImpl> interactorDao = daoFactory.getInteractorDao(); IntactContext.getCurrentInstance().getDataContext().beginTransaction(); count = interactorDao.countInteractorInvolvedInInteraction(); try { IntactContext.getCurrentInstance().getDataContext().commitTransaction(); } catch ( IntactTransactionException e ) { throw new IndexerException( "Error while closing transaction.", e ); } } return count; }
chrono.start(); DaoFactory daoFactory = IntactContext.getCurrentInstance().getDataContext().getDaoFactory(); BaseDao dao = IntactContext.getCurrentInstance().getDataContext().getDaoFactory().getBaseDao(); System.out.println( "Database: " + dao.getDbName() ); System.out.println( "Username: " + IntactContext.getCurrentInstance().getUserContext().getUserId() ); System.out.print( "Loading " + label + "..." ); System.out.flush(); experiments.addAll( IntactContext.getCurrentInstance().getDataContext().getDaoFactory().getExperimentDao().getByShortLabelLike(label)); System.out.println( "done." ); IntactContext.getCurrentInstance().getDataContext().commitAllActiveTransactions();
/** * Drops and creates the schema. Beware that it commits transactions * @param initializeDatabase If false, do not initialize the database (e.g. don't create Institution) */ public static void resetSchema(boolean initializeDatabase) throws IntactTransactionException { if (log.isDebugEnabled()) log.debug("Resetting 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()); } dropSchema(); createSchema(initializeDatabase); } }
private ArrayList getSpeciesTypes() throws SQLException, IntactTransactionException { ArrayList species = new ArrayList(); Statement stmt = null; IntactContext.getCurrentInstance().getDataContext().beginTransaction(); try { stmt = getConnection().createStatement(); ResultSet rs = stmt.executeQuery("SELECT distinct species " + "FROM ia_payg"); while (rs.next()) { species.add(rs.getString(1)); } } finally { if (stmt != null) { try { stmt.close(); } catch (SQLException e) { } } } IntactContext.getCurrentInstance().getDataContext().commitTransaction(); return species; }
private static void commitTransactionAndRollbackIfNecessary() throws PersisterException { try { IntactContext.getCurrentInstance().getDataContext().commitTransaction(); } catch (IntactTransactionException e) { try { IntactContext.getCurrentInstance().getDataContext().getDaoFactory().getCurrentTransaction().rollback(); } catch (IntactTransactionException e1) { throw new PersisterException(e1); } } } }
IntactTransaction tx = IntactContext.getCurrentInstance().getDataContext().getDaoFactory().getCurrentTransaction(); try { tx.commit(); IntactContext.getCurrentInstance().getDataContext().beginTransaction();
/** * 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(); }
protected void commitTransaction() { try { getDataContext().commitTransaction(); } catch (IntactTransactionException e) { throw new IntactException(e); } }
protected void commitTransaction() throws IntactTestException { if (getDataContext().isTransactionActive()) { try { getDataContext().commitTransaction(); } catch (IntactTransactionException e) { throw new IntactTestException(e); } } }
public static void saveOrUpdate(IntactObject ... intactObjects) throws PersisterException { boolean inTransaction = IntactContext.getCurrentInstance().getDataContext().isTransactionActive(); if (!inTransaction) IntactContext.getCurrentInstance().getDataContext().beginTransaction(); for (IntactObject intactObject : intactObjects) { Persister persister = persisterFor(intactObject.getClass()); persister.saveOrUpdate(intactObject); } PersisterContext.getInstance().persistAll(); if (!inTransaction) commitTransactionAndRollbackIfNecessary(); }
protected void beginTransaction() { getDataContext().beginTransaction(); }
/** * Main execution method, which is called after hibernate has been initialized */ public void executeIntactMojo() throws MojoExecutionException, MojoFailureException, IOException { if (IntactContext.getCurrentInstance().getDataContext().isTransactionActive()) { commitTransaction(); } UpdateTargetSpecies updateTargetSpecies = new UpdateTargetSpecies(); updateTargetSpecies.updateAllExperiments(); }
public void exportEntries() throws IndexerException { int current = 0; log.debug( "Starting export of " + count + " interaction(s)." ); while ( current < count ) { DaoFactory daoFactory = IntactContext.getCurrentInstance().getDataContext().getDaoFactory(); InteractionDao idao = daoFactory.getInteractionDao(); IntactContext.getCurrentInstance().getDataContext().beginTransaction(); List<InteractionImpl> interactions = idao.getAll( current, CHUNK_SIZE ); if ( log.isDebugEnabled() ) { log.debug( "Exporting interaction range " + current + ".." + Math.min( count, current + CHUNK_SIZE ) + " out of " + count ); } for ( Interaction interaction : interactions ) { current++; exportEntry( interaction ); } try { IntactContext.getCurrentInstance().getDataContext().commitTransaction(); } catch ( IntactTransactionException e ) { throw new IndexerException( e ); } } }
chrono.start(); DaoFactory daoFactory = IntactContext.getCurrentInstance().getDataContext().getDaoFactory(); BaseDao dao = IntactContext.getCurrentInstance().getDataContext().getDaoFactory().getBaseDao(); System.out.println( "Database: " + dao.getDbName() ); System.out.println( "Username: " + IntactContext.getCurrentInstance().getUserContext().getUserId() ); System.out.print( "Loading " + label + "..." ); System.out.flush(); experiments.addAll( IntactContext.getCurrentInstance().getDataContext().getDaoFactory().getExperimentDao().getByShortLabelLike(label)); System.out.println( "done." ); IntactContext.getCurrentInstance().getDataContext().commitAllActiveTransactions(); } catch (IntactTransactionException e) { e.printStackTrace();
public UpdateTargetSpecies() { if (getDataContext().isTransactionActive()) { throw new IntactException("Transaction must NOT be active when instantiating UpdateTargetSpecies"); } beginTransaction(); CvObjectDao cvObjectDao = getDataContext().getDaoFactory().getCvObjectDao(); newt = (CvDatabase) cvObjectDao.getByPsiMiRef( CvDatabase.NEWT_MI_REF ); if (newt == null) { throw new IllegalStateException("Cv is null: "+ CvDatabase.NEWT + "("+ CvDatabase.NEWT_MI_REF + ")"); } targetSpeciesQualifier = (CvXrefQualifier) cvObjectDao.getByShortLabel( CvXrefQualifier.class, CvXrefQualifier.TARGET_SPECIES ); if (targetSpeciesQualifier == null) { throw new IllegalStateException("Cv is null: "+ CvXrefQualifier.TARGET_SPECIES); } commitTransaction(); }