public boolean isTransactionActive() { return isTransactionActive( getDefaultDataConfig().getName() ); }
/** * 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); } }
protected void commitTransaction() throws IntactTestException { if (getDataContext().isTransactionActive()) { try { getDataContext().commitTransaction(); } catch (IntactTransactionException e) { throw new IntactTestException(e); } } }
/** * 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(); }
/** * 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(); }
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(); }
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(); }
/** * 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(); }
if (dataContext.isTransactionActive()) { throw new IntactException("To start the update the transaction must NOT be active. Commit any existing transaction first");
public static void saveOrUpdate(IntactEntry ... intactEntries) throws PersisterException { for (IntactEntry intactEntry : intactEntries) { boolean inTransaction = IntactContext.getCurrentInstance().getDataContext().isTransactionActive(); if (!inTransaction) IntactContext.getCurrentInstance().getDataContext().beginTransaction(); EntryPersister.getInstance().saveOrUpdate(intactEntry); EntryPersister.getInstance().commit(); if (!inTransaction) commitTransactionAndRollbackIfNecessary(); } }
public void updateExperiment(Experiment experiment) { if (getDataContext().isTransactionActive()) { throw new IntactException("Transaction must NOT be active");