org.hibernate.Transaction

Here are the examples of the java api org.hibernate.Transaction taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

1148 Examples 7

19 Source : UserDAO.java
with Apache License 2.0
from yugabyte

@Override
public void save(final User enreplacedy) {
    Session session = openCurrentSession();
    Transaction transaction = session.beginTransaction();
    try {
        session.save(enreplacedy);
        transaction.commit();
    } catch (RuntimeException rte) {
        transaction.rollback();
    }
    session.close();
}

19 Source : ProductDAO.java
with Apache License 2.0
from yugabyte

@Override
public void save(Product enreplacedy) {
    try (Session session = openCurrentSession()) {
        Transaction transaction = session.beginTransaction();
        try {
            session.save(enreplacedy);
        } catch (Exception e) {
            e.printStackTrace();
            transaction.rollback();
        } finally {
            transaction.commit();
        }
    }
}

19 Source : OrderLineDAO.java
with Apache License 2.0
from yugabyte

@Override
public void save(OrderLine enreplacedy) {
    try (Session session = openCurrentSession()) {
        Transaction transaction = session.beginTransaction();
        try {
            session.save(enreplacedy);
        } catch (Exception e) {
            e.printStackTrace();
            transaction.rollback();
        } finally {
            transaction.commit();
        }
    }
}

19 Source : OrderDAO.java
with Apache License 2.0
from yugabyte

@Override
public void save(Order enreplacedy) {
    try (Session session = openCurrentSession()) {
        Transaction transaction = session.beginTransaction();
        try {
            session.save(enreplacedy);
        } catch (Exception e) {
            e.printStackTrace();
            transaction.rollback();
        } finally {
            transaction.commit();
        }
    }
}

19 Source : UserDao.java
with MIT License
from yocaning

// 修改用户
public void updateUser(UserBean user) {
    Session session = hibernateUtil.getSession();
    Transaction ts = session.beginTransaction();
    session.update(user);
    ts.commit();
    session.close();
}

19 Source : UserDao.java
with MIT License
from yocaning

// 添加用户
public void saveUser(UserBean user) {
    Session session = hibernateUtil.getSession();
    Transaction ts = session.beginTransaction();
    session.save(user);
    ts.commit();
    session.close();
}

19 Source : UserDao.java
with MIT License
from yocaning

// 删除用户
public void deleteUser(short userid) {
    Session session = hibernateUtil.getSession();
    Transaction ts = session.beginTransaction();
    UserBean user = findCurruser(userid);
    if (user != null)
        session.delete(user);
    ts.commit();
    session.close();
}

19 Source : RoleDao.java
with MIT License
from yocaning

// 删除角色
public void deleteRole(Integer roleid) {
    Session session = hibernateUtil.getSession();
    Transaction ts = session.beginTransaction();
    RoleBean role = findCurrurole(roleid);
    if (role != null)
        session.delete(role);
    ts.commit();
    session.close();
}

19 Source : RoleDao.java
with MIT License
from yocaning

// 添加角色
public void saveRole(RoleBean role) {
    Session session = hibernateUtil.getSession();
    Transaction ts = session.beginTransaction();
    session.save(role);
    ts.commit();
    session.close();
}

19 Source : RoleDao.java
with MIT License
from yocaning

// 修改角色
public void updateRole(RoleBean role) {
    Session session = hibernateUtil.getSession();
    Transaction ts = session.beginTransaction();
    session.update(role);
    ts.commit();
    session.close();
}

19 Source : OrderDao.java
with MIT License
from yocaning

// 修改起点
public void updateorder(orderBean order) {
    Session session = hibernateUtil.getSession();
    Transaction ts = session.beginTransaction();
    session.update(order);
    ts.commit();
    session.close();
}

19 Source : OrderDao.java
with MIT License
from yocaning

// 删除起点
public void deleteorder(Integer orderid) {
    Session session = hibernateUtil.getSession();
    Transaction ts = session.beginTransaction();
    orderBean order = findCurrorder(orderid);
    if (order != null)
        session.delete(order);
    ts.commit();
    session.close();
}

19 Source : OrderDao.java
with MIT License
from yocaning

// //this.deleterolepower(powerid);
// Connection conn = UserUtil.getConnection();
// PreparedStatement ps = null ;
// ResultSet rs = null;
// String sql = "delete  t_order  where orderid =?";
// try {
// ps = conn.prepareStatement(sql);
// ps.setInt(1, orderid);
// ps.executeUpdate();
// } catch (SQLException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }finally{
// UserUtil.CloseAll(conn, ps, rs);
// }
// }
// 添加起点
public void saveorder(orderBean order) {
    Session session = hibernateUtil.getSession();
    Transaction ts = session.beginTransaction();
    session.save(order);
    ts.commit();
    session.close();
}

19 Source : HibernateQueryInterceptor.java
with MIT License
from yannbriancon

/**
 * Reset previously loaded enreplacedies after the end of a transaction to avoid triggering
 * N+1 queries exceptions because of loading same instance in two different transactions
 *
 * @param tx Transaction having been completed
 */
@Override
public void afterTransactionCompletion(Transaction tx) {
    this.resetNPlusOneQueryDetectionState();
}

19 Source : AbstractTest.java
with Apache License 2.0
from vladmihalcea

protected <T> T doInHibernate(HibernateTransactionFunction<T> callable) {
    T result = null;
    Session session = null;
    Transaction txn = null;
    try {
        session = sessionFactory().openSession();
        callable.beforeTransactionCompletion();
        txn = session.beginTransaction();
        result = callable.apply(session);
        if (txn.getStatus() == TransactionStatus.ACTIVE) {
            txn.commit();
        } else {
            try {
                txn.rollback();
            } catch (Exception e) {
                LOGGER.error("Rollback failure", e);
            }
        }
    } catch (Throwable t) {
        if (txn != null && txn.getStatus() == TransactionStatus.ACTIVE) {
            try {
                txn.rollback();
            } catch (Exception e) {
                LOGGER.error("Rollback failure", e);
            }
        }
        throw new RuntimeException(t);
    } finally {
        callable.afterTransactionCompletion();
        if (session != null) {
            session.close();
        }
    }
    return result;
}

19 Source : AbstractTest.java
with Apache License 2.0
from vladmihalcea

protected <T> T doInHibernate(HibernateTransactionFunction<T> callable) {
    T result = null;
    Session session = null;
    Transaction txn = null;
    try {
        session = sessionFactory().openSession();
        callable.beforeTransactionCompletion();
        txn = session.beginTransaction();
        result = callable.apply(session);
        if (!txn.getRollbackOnly()) {
            txn.commit();
        } else {
            try {
                txn.rollback();
            } catch (Exception e) {
                LOGGER.error("Rollback failure", e);
            }
        }
    } catch (Throwable t) {
        if (txn != null && txn.isActive()) {
            try {
                txn.rollback();
            } catch (Exception e) {
                LOGGER.error("Rollback failure", e);
            }
        }
        throw t;
    } finally {
        callable.afterTransactionCompletion();
        if (session != null) {
            session.close();
        }
    }
    return result;
}

19 Source : AbstractTest.java
with Apache License 2.0
from vladmihalcea

protected void doInHibernate(HibernateTransactionConsumer callable) {
    Session session = null;
    Transaction txn = null;
    try {
        session = sessionFactory().openSession();
        callable.beforeTransactionCompletion();
        txn = session.beginTransaction();
        callable.accept(session);
        if (!txn.getRollbackOnly()) {
            txn.commit();
        } else {
            try {
                txn.rollback();
            } catch (Exception e) {
                LOGGER.error("Rollback failure", e);
            }
        }
    } catch (Throwable t) {
        if (txn != null && txn.isActive()) {
            try {
                txn.rollback();
            } catch (Exception e) {
                LOGGER.error("Rollback failure", e);
            }
        }
        throw t;
    } finally {
        callable.afterTransactionCompletion();
        if (session != null) {
            session.close();
        }
    }
}

19 Source : AbstractTest.java
with Apache License 2.0
from vladmihalcea

protected void doInJDBC(ConnectionVoidCallable callable) {
    Session session = null;
    Transaction txn = null;
    try {
        session = sessionFactory().openSession();
        txn = session.beginTransaction();
        session.doWork(callable::execute);
        if (!txn.getRollbackOnly()) {
            txn.commit();
        } else {
            try {
                txn.rollback();
            } catch (Exception e) {
                LOGGER.error("Rollback failure", e);
            }
        }
    } catch (Throwable t) {
        if (txn != null && txn.isActive()) {
            try {
                txn.rollback();
            } catch (Exception e) {
                LOGGER.error("Rollback failure", e);
            }
        }
        throw t;
    } finally {
        if (session != null) {
            session.close();
        }
    }
}

19 Source : AbstractTest.java
with Apache License 2.0
from vladmihalcea

protected <T> T doInJDBC(ConnectionCallable<T> callable) {
    AtomicReference<T> result = new AtomicReference<>();
    Session session = null;
    Transaction txn = null;
    try {
        session = sessionFactory().openSession();
        txn = session.beginTransaction();
        session.doWork(connection -> {
            result.set(callable.execute(connection));
        });
        if (!txn.getRollbackOnly()) {
            txn.commit();
        } else {
            try {
                txn.rollback();
            } catch (Exception e) {
                LOGGER.error("Rollback failure", e);
            }
        }
    } catch (Throwable t) {
        if (txn != null && txn.isActive()) {
            try {
                txn.rollback();
            } catch (Exception e) {
                LOGGER.error("Rollback failure", e);
            }
        }
        throw t;
    } finally {
        if (session != null) {
            session.close();
        }
    }
    return result.get();
}

19 Source : AbstractTest.java
with Apache License 2.0
from vladmihalcea

protected void doInJDBC(final ConnectionVoidCallable callable) {
    Session session = null;
    Transaction txn = null;
    try {
        session = sessionFactory().openSession();
        txn = session.beginTransaction();
        session.doWork(new Work() {

            @Override
            public void execute(Connection connection) throws SQLException {
                callable.execute(connection);
            }
        });
        if (txn.getStatus() == TransactionStatus.ACTIVE) {
            txn.commit();
        } else {
            try {
                txn.rollback();
            } catch (Exception e) {
                LOGGER.error("Rollback failure", e);
            }
        }
    } catch (Throwable t) {
        if (txn != null && txn.getStatus() == TransactionStatus.ACTIVE) {
            try {
                txn.rollback();
            } catch (Exception e) {
                LOGGER.error("Rollback failure", e);
            }
        }
        throw new RuntimeException(t);
    } finally {
        if (session != null) {
            session.close();
        }
    }
}

19 Source : AbstractTest.java
with Apache License 2.0
from vladmihalcea

protected <T> T doInJDBC(final ConnectionCallable<T> callable) {
    final AtomicReference<T> result = new AtomicReference<T>();
    Session session = null;
    Transaction txn = null;
    try {
        session = sessionFactory().openSession();
        txn = session.beginTransaction();
        session.doWork(new Work() {

            @Override
            public void execute(Connection connection) throws SQLException {
                result.set(callable.execute(connection));
            }
        });
        if (txn.getStatus() == TransactionStatus.ACTIVE) {
            txn.commit();
        } else {
            try {
                txn.rollback();
            } catch (Exception e) {
                LOGGER.error("Rollback failure", e);
            }
        }
    } catch (Throwable t) {
        if (txn != null && txn.getStatus() == TransactionStatus.ACTIVE) {
            try {
                txn.rollback();
            } catch (Exception e) {
                LOGGER.error("Rollback failure", e);
            }
        }
        throw new RuntimeException(t);
    } finally {
        if (session != null) {
            session.close();
        }
    }
    return result.get();
}

19 Source : SessionHolder.java
with MIT License
from Vip-Augus

/**
 * Resource holder wrapping a Hibernate {@link Session} (plus an optional {@link Transaction}).
 * {@link HibernateTransactionManager} binds instances of this clreplaced to the thread,
 * for a given {@link org.hibernate.SessionFactory}. Extends {@link EnreplacedyManagerHolder}
 * as of 5.1, automatically exposing an {@code EnreplacedyManager} handle on Hibernate 5.2+.
 *
 * <p>Note: This is an SPI clreplaced, not intended to be used by applications.
 *
 * @author Juergen Hoeller
 * @since 4.2
 * @see HibernateTransactionManager
 * @see SessionFactoryUtils
 */
public clreplaced SessionHolder extends EnreplacedyManagerHolder {

    private final Session session;

    @Nullable
    private Transaction transaction;

    @Nullable
    private FlushMode previousFlushMode;

    public SessionHolder(Session session) {
        // Check below is always true against Hibernate >= 5.2 but not against 5.0/5.1 at runtime
        super(EnreplacedyManager.clreplaced.isInstance(session) ? session : null);
        this.session = session;
    }

    public Session getSession() {
        return this.session;
    }

    public void setTransaction(@Nullable Transaction transaction) {
        this.transaction = transaction;
        setTransactionActive(transaction != null);
    }

    @Nullable
    public Transaction getTransaction() {
        return this.transaction;
    }

    public void setPreviousFlushMode(@Nullable FlushMode previousFlushMode) {
        this.previousFlushMode = previousFlushMode;
    }

    @Nullable
    public FlushMode getPreviousFlushMode() {
        return this.previousFlushMode;
    }

    @Override
    public void clear() {
        super.clear();
        this.transaction = null;
        this.previousFlushMode = null;
    }
}

19 Source : SessionHolder.java
with MIT License
from Vip-Augus

public void setTransaction(@Nullable Transaction transaction) {
    this.transaction = transaction;
    setTransactionActive(transaction != null);
}

19 Source : HibernateTransactionManager.java
with MIT License
from Vip-Augus

@Override
protected void doCommit(DefaultTransactionStatus status) {
    HibernateTransactionObject txObject = (HibernateTransactionObject) status.getTransaction();
    Transaction hibTx = txObject.getSessionHolder().getTransaction();
    replacedert.state(hibTx != null, "No Hibernate transaction");
    if (status.isDebug()) {
        logger.debug("Committing Hibernate transaction on Session [" + txObject.getSessionHolder().getSession() + "]");
    }
    try {
        hibTx.commit();
    } catch (org.hibernate.TransactionException ex) {
        // replacedumably from commit call to the underlying JDBC connection
        throw new TransactionSystemException("Could not commit Hibernate transaction", ex);
    } catch (HibernateException ex) {
        // replacedumably failed to flush changes to database
        throw convertHibernateAccessException(ex);
    } catch (PersistenceException ex) {
        if (ex.getCause() instanceof HibernateException) {
            throw convertHibernateAccessException((HibernateException) ex.getCause());
        }
        throw ex;
    }
}

19 Source : HibernateTransactionManager.java
with MIT License
from Vip-Augus

@Override
protected void doRollback(DefaultTransactionStatus status) {
    HibernateTransactionObject txObject = (HibernateTransactionObject) status.getTransaction();
    Transaction hibTx = txObject.getSessionHolder().getTransaction();
    replacedert.state(hibTx != null, "No Hibernate transaction");
    if (status.isDebug()) {
        logger.debug("Rolling back Hibernate transaction on Session [" + txObject.getSessionHolder().getSession() + "]");
    }
    try {
        hibTx.rollback();
    } catch (org.hibernate.TransactionException ex) {
        throw new TransactionSystemException("Could not roll back Hibernate transaction", ex);
    } catch (HibernateException ex) {
        // Shouldn't really happen, as a rollback doesn't cause a flush.
        throw convertHibernateAccessException(ex);
    } catch (PersistenceException ex) {
        if (ex.getCause() instanceof HibernateException) {
            throw convertHibernateAccessException((HibernateException) ex.getCause());
        }
        throw ex;
    } finally {
        if (!txObject.isNewSession() && !this.hibernateManagedSession) {
            // Clear all pending inserts/updates/deletes in the Session.
            // Necessary for pre-bound Sessions, to avoid inconsistent state.
            txObject.getSessionHolder().getSession().clear();
        }
    }
}

19 Source : DeleteEntitiesCron.java
with Apache License 2.0
from VertaAI

private void deleteDatasetVersions(Session session) {
    LOGGER.trace("DatasetVersion deleting");
    String alias = "dv";
    String deleteDatasetVersionsQueryString = new StringBuilder("FROM ").append(DatasetVersionEnreplacedy.clreplaced.getSimpleName()).append(" ").append(alias).append(" WHERE ").append(alias).append(".").append(ModelDBConstants.DELETED).append(" = :deleted ").toString();
    Query datasetVersionDeleteQuery = session.createQuery(deleteDatasetVersionsQueryString);
    datasetVersionDeleteQuery.setParameter("deleted", true);
    List<DatasetVersionEnreplacedy> datasetVersionEnreplacedies = datasetVersionDeleteQuery.list();
    if (!datasetVersionEnreplacedies.isEmpty()) {
        try {
            roleService.deleteEnreplacedyResourcesWithServiceUser(datasetVersionEnreplacedies.stream().map(DatasetVersionEnreplacedy::getId).collect(Collectors.toList()), ModelDBServiceResourceTypes.DATASET_VERSION);
            for (DatasetVersionEnreplacedy datasetVersionEnreplacedy : datasetVersionEnreplacedies) {
                try {
                    Transaction transaction = session.beginTransaction();
                    session.delete(datasetVersionEnreplacedy);
                    transaction.commit();
                } catch (OptimisticLockException ex) {
                    LOGGER.info("DeleteEnreplacediesCron : deleteDatasetVersions : Exception: {}", ex.getMessage());
                }
            }
        } catch (OptimisticLockException ex) {
            LOGGER.info("DeleteEnreplacediesCron : deleteDatasetVersions : Exception: {}", ex.getMessage());
        } catch (Exception ex) {
            LOGGER.warn("DeleteEnreplacediesCron : deleteDatasetVersions : Exception:", ex);
        }
    }
    LOGGER.debug("DatasetVersion Deleted successfully : Deleted datasetVersions count {}", datasetVersionEnreplacedies.size());
}

19 Source : DeleteEntitiesCron.java
with Apache License 2.0
from VertaAI

private void deleteExperimentRuns(Session session) {
    LOGGER.trace("ExperimentRun deleting");
    String deleteExperimentRunQueryString = new StringBuilder("FROM ").append(ExperimentRunEnreplacedy.clreplaced.getSimpleName()).append(" expr WHERE expr.").append(ModelDBConstants.DELETED).append(" = :deleted ").toString();
    Query experimentRunDeleteQuery = session.createQuery(deleteExperimentRunQueryString);
    experimentRunDeleteQuery.setParameter("deleted", true);
    experimentRunDeleteQuery.setMaxResults(this.recordUpdateLimit);
    List<ExperimentRunEnreplacedy> experimentRunEnreplacedies = experimentRunDeleteQuery.list();
    List<String> experimentRunIds = new ArrayList<>();
    if (!experimentRunEnreplacedies.isEmpty()) {
        for (ExperimentRunEnreplacedy experimentRunEnreplacedy : experimentRunEnreplacedies) {
            experimentRunIds.add(experimentRunEnreplacedy.getId());
        }
        try {
            deleteRoleBindingsForExperimentRuns(experimentRunEnreplacedies);
        } catch (StatusRuntimeException ex) {
            LOGGER.info("DeleteEnreplacediesCron : deleteExperimentRuns : deleteRoleBindingsForExperimentRuns : Exception: {}", ex.getMessage());
        } catch (Exception ex) {
            LOGGER.warn("DeleteEnreplacediesCron : deleteExperimentRuns : deleteRoleBindingsForExperimentRuns : Exception: ", ex);
        }
        try {
            // Delete the ExperimentRun comments
            Transaction transaction = session.beginTransaction();
            if (!experimentRunIds.isEmpty()) {
                removeEnreplacedyComments(session, experimentRunIds, ExperimentRunEnreplacedy.clreplaced.getSimpleName());
            }
            transaction.commit();
            for (ExperimentRunEnreplacedy experimentRunEnreplacedy : experimentRunEnreplacedies) {
                try {
                    transaction = session.beginTransaction();
                    session.delete(experimentRunEnreplacedy);
                    transaction.commit();
                } catch (OptimisticLockException ex) {
                    LOGGER.info("DeleteEnreplacediesCron : deleteExperimentRuns : Exception: {}", ex.getMessage());
                }
            }
        } catch (OptimisticLockException ex) {
            LOGGER.info("DeleteEnreplacediesCron : deleteExperimentRuns : Exception: {}", ex.getMessage());
        } catch (Exception ex) {
            LOGGER.debug("DeleteEnreplacediesCron : deleteExperimentRuns : Exception:", ex);
        }
    }
    LOGGER.debug("ExperimentRun deleted successfully : Deleted experimentRuns count {}", experimentRunIds.size());
}

19 Source : DeleteEntitiesCron.java
with Apache License 2.0
from VertaAI

private void deleteProjects(Session session) {
    LOGGER.trace("Project deleting");
    String alias = "pr";
    String deleteProjectsQueryString = new StringBuilder("FROM ").append(ProjectEnreplacedy.clreplaced.getSimpleName()).append(" ").append(alias).append(" WHERE ").append(alias).append(".").append(ModelDBConstants.DELETED).append(" = :deleted ").toString();
    Query projectDeleteQuery = session.createQuery(deleteProjectsQueryString);
    projectDeleteQuery.setParameter("deleted", true);
    projectDeleteQuery.setMaxResults(this.recordUpdateLimit);
    List<ProjectEnreplacedy> projectEnreplacedies = projectDeleteQuery.list();
    List<String> projectIds = new ArrayList<>();
    if (!projectEnreplacedies.isEmpty()) {
        for (ProjectEnreplacedy projectEnreplacedy : projectEnreplacedies) {
            projectIds.add(projectEnreplacedy.getId());
        }
        try {
            roleService.deleteEnreplacedyResourcesWithServiceUser(projectIds, ModelDBServiceResourceTypes.PROJECT);
            Transaction transaction = session.beginTransaction();
            String updateDeletedStatusExperimentQueryString = new StringBuilder("UPDATE ").append(ExperimentEnreplacedy.clreplaced.getSimpleName()).append(" exp ").append("SET exp.").append(ModelDBConstants.DELETED).append(" = :deleted ").append(" WHERE exp.").append(ModelDBConstants.PROJECT_ID).append(" IN (:projectIds)").toString();
            Query deletedExperimentQuery = session.createQuery(updateDeletedStatusExperimentQueryString);
            deletedExperimentQuery.setParameter("deleted", true);
            deletedExperimentQuery.setParameter("projectIds", projectIds);
            deletedExperimentQuery.executeUpdate();
            transaction.commit();
            for (ProjectEnreplacedy projectEnreplacedy : projectEnreplacedies) {
                try {
                    transaction = session.beginTransaction();
                    session.delete(projectEnreplacedy);
                    transaction.commit();
                } catch (OptimisticLockException ex) {
                    LOGGER.info("DeleteEnreplacediesCron : deleteProjects : Exception: {}", ex.getMessage());
                }
            }
        } catch (OptimisticLockException ex) {
            LOGGER.info("DeleteEnreplacediesCron : deleteProjects : Exception: {}", ex.getMessage());
        } catch (Exception ex) {
            LOGGER.warn("DeleteEnreplacediesCron : deleteProjects : Exception: ", ex);
        }
    }
    LOGGER.debug("Project Deleted successfully : Deleted projects count {}", projectIds.size());
}

19 Source : AuditLogLocalDAORdbImpl.java
with Apache License 2.0
from VertaAI

public void saveAuditLogs(List<AuditLogLocalEnreplacedy> auditLogEnreplacedies) {
    try (Session session = modelDBHibernateUtil.getSessionFactory().openSession()) {
        Transaction transaction = session.beginTransaction();
        saveAuditLogs(session, auditLogEnreplacedies);
        transaction.commit();
        LOGGER.debug("Audit logged successfully");
    } catch (Exception ex) {
        if (ModelDBUtils.needToRetry(ex)) {
            saveAuditLogs(auditLogEnreplacedies);
        } else {
            throw ex;
        }
    }
}

19 Source : AbstractDAO.java
with Apache License 2.0
from V1toss

/**
 * Template method w/o return.
 * @param action action to do.
 */
private void persist(Action action) {
    Transaction transaction = null;
    try (Session session = HibernateUtil.getFactory().openSession()) {
        transaction = session.beginTransaction();
        action.execute(session);
        transaction.commit();
    } catch (HibernateException he) {
        LOG.error(he.getMessage(), he);
        if (transaction != null) {
            transaction.rollback();
        }
    }
}

19 Source : AbstractDAO.java
with Apache License 2.0
from V1toss

/**
 * Template method with list return.
 * @param action action to do.
 * @return list of objects.
 */
@SuppressWarnings("unchecked")
public List<T> persistGetAll(ActionGet action) {
    Transaction transaction = null;
    List<T> list = new ArrayList<>();
    try (Session session = HibernateUtil.getFactory().openSession()) {
        transaction = session.beginTransaction();
        list = action.executeGet(session);
        transaction.commit();
    } catch (HibernateException he) {
        LOG.error(he.getMessage(), he);
        if (transaction != null) {
            transaction.rollback();
        }
    }
    return list;
}

19 Source : TestDaoService.java
with Apache License 2.0
from tmobile

private void saveEnreplacedy(Object obj) {
    Session session = HibernateConfig.getSessionFactory().getCurrentSession();
    Transaction tx = session.beginTransaction();
    session.save(obj);
    tx.commit();
}

19 Source : DefaultTransactionManager.java
with MIT License
from theonedev

@Override
public void mustRunAfterTransaction(Runnable runnable) {
    Transaction transaction = getTransaction();
    Preconditions.checkState(transaction.isActive());
    Collection<Runnable> runnables = completionRunnables.get(transaction);
    if (runnables == null) {
        runnables = new ArrayList<>();
        completionRunnables.put(transaction, runnables);
    }
    runnables.add(runnable);
}

19 Source : VerifyPlaylistListener.java
with Apache License 2.0
from robinfriedli

@Override
public void afterTransactionCompletionChained(Transaction tx) {
    ordinal = 0;
}

19 Source : InterceptorChain.java
with Apache License 2.0
from robinfriedli

@Override
public void afterTransactionBegin(Transaction tx) {
    if (!INTERCEPTORS_MUTED.get()) {
        first.afterTransactionBegin(tx);
    } else {
        super.afterTransactionBegin(tx);
    }
}

19 Source : InterceptorChain.java
with Apache License 2.0
from robinfriedli

@Override
public void beforeTransactionCompletion(Transaction tx) {
    if (!INTERCEPTORS_MUTED.get()) {
        first.beforeTransactionCompletion(tx);
    } else {
        super.beforeTransactionCompletion(tx);
    }
}

19 Source : InterceptorChain.java
with Apache License 2.0
from robinfriedli

@Override
public void afterTransactionCompletion(Transaction tx) {
    if (!INTERCEPTORS_MUTED.get()) {
        first.afterTransactionCompletion(tx);
    } else {
        super.afterTransactionCompletion(tx);
    }
}

19 Source : CollectingInterceptor.java
with Apache License 2.0
from robinfriedli

@Override
public void afterTransactionCompletionChained(Transaction tx) throws Exception {
    try {
        if (!tx.getRollbackOnly()) {
            afterCommit();
        }
    } finally {
        clearState();
    }
}

19 Source : ChainableInterceptor.java
with Apache License 2.0
from robinfriedli

public void afterTransactionCompletionChained(Transaction tx) throws Exception {
}

19 Source : ChainableInterceptor.java
with Apache License 2.0
from robinfriedli

@Override
public void afterTransactionBegin(Transaction tx) {
    try {
        afterTransactionBeginChained(tx);
    } catch (Throwable e) {
        logger.error("Error in afterTransactionBegin of ChainableInterceptor " + getClreplaced().getSimpleName(), e);
    }
    next.afterTransactionBegin(tx);
}

19 Source : ChainableInterceptor.java
with Apache License 2.0
from robinfriedli

public void afterTransactionBeginChained(Transaction tx) throws Exception {
}

19 Source : ChainableInterceptor.java
with Apache License 2.0
from robinfriedli

@Override
public void beforeTransactionCompletion(Transaction tx) {
    try {
        beforeTransactionCompletionChained(tx);
    } catch (Throwable e) {
        logger.error("Error in beforeTransactionCompletion of ChainableInterceptor " + getClreplaced().getSimpleName(), e);
    }
    next.beforeTransactionCompletion(tx);
}

19 Source : ChainableInterceptor.java
with Apache License 2.0
from robinfriedli

public void beforeTransactionCompletionChained(Transaction tx) throws Exception {
}

19 Source : ChainableInterceptor.java
with Apache License 2.0
from robinfriedli

@Override
public void afterTransactionCompletion(Transaction tx) {
    try {
        afterTransactionCompletionChained(tx);
    } catch (Throwable e) {
        logger.error("Error in afterTransactionCompletion of ChainableInterceptor " + getClreplaced().getSimpleName(), e);
    }
    next.afterTransactionCompletion(tx);
}

19 Source : DatabaseCtx.java
with MIT License
from ria-ee

/**
 * Rollbacks the transaction.
 */
public void rollbackTransaction() {
    log.trace("rollbackTransaction({})", sessionFactoryName);
    Transaction tx = getSession().getTransaction();
    if (tx.isActive() && !tx.wasRolledBack()) {
        tx.rollback();
    }
}

19 Source : DatabaseCtx.java
with MIT License
from ria-ee

/**
 * Commits the transaction.
 */
public void commitTransaction() {
    log.trace("commitTransaction({})", sessionFactoryName);
    Transaction tx = getSession().getTransaction();
    if (tx.isActive() && !tx.wasCommitted()) {
        tx.commit();
    }
}

19 Source : FieldData.java
with MIT License
from pokiuwu

public static void loadNPCFromSQL() {
    Session session = DatabaseManager.getSession();
    Transaction transaction = session.beginTransaction();
    Query loadNpcQuery = session.createNativeQuery("SELECT * FROM npc");
    List<Object[]> results = loadNpcQuery.getResultList();
    for (Object[] r : results) {
        Npc n = NpcData.getNpcDeepCopyById((Integer) r[1]);
        Field f = getFieldById((Integer) r[2]);
        Position p = new Position();
        p.setX((Integer) r[3]);
        p.setY((Integer) r[4]);
        n.setPosition(p);
        n.setCy((Integer) r[5]);
        n.setRx0((Integer) r[6]);
        n.setRx1((Integer) r[7]);
        n.setFh((Integer) r[8]);
        f.addLife(n);
    }
    transaction.commit();
    session.close();
}

19 Source : ErrorDaoImpl.java
with GNU Lesser General Public License v2.1
from phoenixctms

@Override
public void handleCreateTxn(Error error) throws Exception {
    // http://www.koders.com/java/fidDC3AD0DFC450E26BD45E4A8FA856716E422119F3.aspx?s=Closer
    Transaction transaction = this.getSession(true).beginTransaction();
    try {
        this.getSession().save(error);
        transaction.commit();
    } catch (Exception e) {
        transaction.rollback();
        throw e;
    }
}

19 Source : AspDaoImpl.java
with GNU Lesser General Public License v2.1
from phoenixctms

@Override
public void handleRemoveTxn(Long aspId) throws Exception {
    Transaction transaction = this.getSession(true).beginTransaction();
    try {
        removeAsp(aspId);
        transaction.commit();
    } catch (Exception e) {
        transaction.rollback();
        throw e;
    }
}

19 Source : AspDaoImpl.java
with GNU Lesser General Public License v2.1
from phoenixctms

@Override
public void handleRemoveTxn(Asp asp) throws Exception {
    Transaction transaction = this.getSession(true).beginTransaction();
    try {
        removeAsp(asp.getId());
        transaction.commit();
    } catch (Exception e) {
        transaction.rollback();
        throw e;
    }
}

See More Examples