/** * Returns the current transaction or null if there is no current transaction * in scope. */ public static Transaction currentTransaction() { return serverMgr.getPrimaryServer().currentTransaction(); }
/** * Returns the current transaction or null if there is no current transaction * in scope. */ public static Transaction currentTransaction() { return serverMgr.getDefaultServer().currentTransaction(); }
/** * Returns the current transaction or null if there is no current * transaction in scope. */ public static Transaction currentTransaction() { return serverMgr.getPrimaryServer().currentTransaction(); }
/** * Mark the current transaction as rollback only. */ public static void setRollbackOnly() { serverMgr.getDefaultServer().currentTransaction().setRollbackOnly(); }
@Override public Transaction currentTransaction() { methodCalls.add(MethodCall.of("currentTransaction")); return delegate.currentTransaction(); }
@Override public Company findCompanyUsingSimpleStaticStatement(Integer pid) { // I didn't find a way how to setup EBean so the query is executed statically (using JDBC regular Statement // not PreparedStatement). However, EBean is polite and provides way how to access the underlying JDBC connection // -> therefore we can actually fall back to JDBC way of doing things (which is not such a big deal since we need simple // Statements only rarely): try { String query = "SELECT pid, address, name " + "FROM company " + "WHERE pid = " + pid; Connection connection = ebean.currentTransaction().getConnection(); Statement statement = connection.createStatement(); ResultSet resultSet = statement.executeQuery(query); Company result = null; if (resultSet.next()) { result = new Company(); result.setPid(resultSet.getInt("pid")); result.setAddress(resultSet.getString("address")); result.setName(resultSet.getString("name")); } return result; } catch (SQLException e) { // just wrap checked exceptions as e throw new RuntimeException(e); } }
@Override protected void doEndTxIfActive(Object delegate) { Transaction tx = ebean.currentTransaction(); if (null == tx) { return; } if (TxContext.readOnly()) { ebeanReadOnly.endTransaction(); } else { ebean.commitTransaction(); } }
/** * Create a transaction if one is not already active and set its batch mode * and batch size. */ protected void initTransactionIfRequired() { transaction = server.currentTransaction(); if (transaction == null || !transaction.isActive()) { transaction = server.beginTransaction(); createdTransaction = true; if (persistBatchSize > 1) { logger.info("Creating transaction, batchSize[" + persistBatchSize + "]"); transaction.setBatchMode(true); transaction.setBatchSize(persistBatchSize); } else { // explicitly turn off JDBC batching in case // is has been turned on globally transaction.setBatchMode(false); logger.info("Creating transaction with no JDBC batching"); } } }
/** * Create a transaction if one is not already active and set its batch mode * and batch size. */ protected void initTransactionIfRequired() { transaction = server.currentTransaction(); if (transaction == null || !transaction.isActive()) { transaction = server.beginTransaction(); createdTransaction = true; if (persistBatchSize > 1) { logger.info("Creating transaction, batchSize[" + persistBatchSize + "]"); transaction.setBatchMode(true); transaction.setBatchSize(persistBatchSize); } else { // explicitly turn off JDBC batching in case // is has been turned on globally transaction.setBatchMode(false); logger.info("Creating transaction with no JDBC batching"); } } }
@Override protected void doRollbackTx(Object delegate, Throwable cause) { Transaction tx = ebean.currentTransaction(); if (null == tx) { return; } if (TxContext.readOnly()) { ebeanReadOnly.endTransaction(); } else { logger.warn(cause, "Roll back transaction"); ebean.rollbackTransaction(); } }
/** * Create a transaction if one is not already active and set its batch mode * and batch size. */ protected void initTransactionIfRequired() { transaction = server.currentTransaction(); if (transaction == null || !transaction.isActive()) { transaction = server.beginTransaction(); createdTransaction = true; if (persistBatchSize > 1) { logger.info("Creating transaction, batchSize[" + persistBatchSize + "]"); transaction.setBatchMode(true); transaction.setBatchSize(persistBatchSize); transaction.setBatchGetGeneratedKeys(false); } else { // explicitly turn off JDBC batching in case // is has been turned on globally transaction.setBatchMode(false); logger.info("Creating transaction with no JDBC batching"); } } }