javax.jdo.Transaction.isActive()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(7.1k)|赞(0)|评价(0)|浏览(111)

本文整理了Java中javax.jdo.Transaction.isActive()方法的一些代码示例,展示了Transaction.isActive()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Transaction.isActive()方法的具体详情如下:
包路径:javax.jdo.Transaction
类名称:Transaction
方法名:isActive

Transaction.isActive介绍

[英]Returns whether there is a transaction currently active.
[中]返回当前是否有活动的事务。

代码示例

代码示例来源:origin: apache/hive

/**
 * @return true if there is an active transaction. If the current transaction
 *         is either committed or rolled back it returns false
 */
@Override
public boolean isActiveTransaction() {
 if (currentTransaction == null) {
  return false;
 }
 return currentTransaction.isActive();
}

代码示例来源:origin: apache/hive

throw e;
if (!currentTransaction.isActive()) {
 RuntimeException e = new RuntimeException("commitTransaction was called but openTransactionCalls = "
   + openTrasactionCalls + ". This probably indicates that there are unbalanced " +
debugLog("Commit transaction: count = " + openTrasactionCalls + ", isactive "+ currentTransaction.isActive());
if ((openTrasactionCalls == 0) && currentTransaction.isActive()) {
 transactionStatus = TXN_STATUS.COMMITED;
 currentTransaction.commit();

代码示例来源:origin: apache/hive

/**
 * Opens a new one or the one already created Every call of this function must
 * have corresponding commit or rollback function call
 *
 * @return an active transaction
 */
@Override
public boolean openTransaction() {
 openTrasactionCalls++;
 if (openTrasactionCalls == 1) {
  currentTransaction = pm.currentTransaction();
  currentTransaction.begin();
  transactionStatus = TXN_STATUS.OPEN;
 } else {
  // openTransactionCalls > 1 means this is an interior transaction
  // We should already have a transaction created that is active.
  if ((currentTransaction == null) || (!currentTransaction.isActive())){
   throw new RuntimeException("openTransaction called in an interior"
     + " transaction scope, but currentTransaction is not active.");
  }
 }
 boolean result = currentTransaction.isActive();
 debugLog("Open transaction: count = " + openTrasactionCalls + ", isActive = " + result);
 return result;
}

代码示例来源:origin: apache/hive

private void prepareQuotes() throws SQLException {
 if (dbType == DatabaseProduct.MYSQL) {
  assert pm.currentTransaction().isActive();
  JDOConnection jdoConn = pm.getDataStoreConnection();
  Statement statement = null;
  try {
   statement = ((Connection)jdoConn.getNativeConnection()).createStatement();
   statement.execute("SET @@session.sql_mode=ANSI_QUOTES");
  } finally {
   if(statement != null){
    statement.close();
   }
   jdoConn.close();
  }
 }
}

代码示例来源:origin: apache/hive

/**
 * This run the necessary logic to prepare for queries. It should be called once, after the
 * txn on DataNucleus connection is opened, and before any queries are issued. What it does
 * currently is run db-specific logic, e.g. setting ansi quotes mode for MySQL. The reason it
 * must be used inside of the txn is connection pooling; there's no way to guarantee that the
 * effect will apply to the connection that is executing the queries otherwise.
 */
public void prepareTxn() throws MetaException {
 if (dbType != DatabaseProduct.MYSQL) return;
 try {
  assert pm.currentTransaction().isActive(); // must be inside tx together with queries
  executeNoResult("SET @@session.sql_mode=ANSI_QUOTES");
 } catch (SQLException sqlEx) {
  throw new MetaException("Error setting ansi quotes: " + sqlEx.getMessage());
 }
}

代码示例来源:origin: apache/hive

if (currentTransaction != null && currentTransaction.isActive()) {
 throw rollbackEx; // Throw if the tx wasn't rolled back.

代码示例来源:origin: apache/hive

private boolean ensureDbInit() {
 Transaction tx = pm.currentTransaction();
 boolean doCommit = false;
 if (!tx.isActive()) {
  tx.begin();
  doCommit = true;

代码示例来源:origin: apache/hive

private boolean runTestQuery() {
 Transaction tx = pm.currentTransaction();
 boolean doCommit = false;
 if (!tx.isActive()) {
  tx.begin();
  doCommit = true;
 }
 Query query = null;
 // Run a self-test query. If it doesn't work, we will self-disable. What a PITA...
 String selfTestQuery = "select \"DB_ID\" from " + DBS + "";
 try {
  prepareTxn();
  query = pm.newQuery("javax.jdo.query.SQL", selfTestQuery);
  query.execute();
  return true;
 } catch (Throwable t) {
  doCommit = false;
  LOG.warn("Self-test query [" + selfTestQuery + "] failed; direct SQL is disabled", t);
  tx.rollback();
  return false;
 } finally {
  if (doCommit) {
   tx.commit();
  }
  if (query != null) {
   query.closeAll();
  }
 }
}

代码示例来源:origin: org.apache.hadoop.hive/hive-metastore

/**
 * @return true if there is an active transaction. If the current transaction
 *         is either committed or rolled back it returns false
 */
public boolean isActiveTransaction() {
 if (currentTransaction == null) {
  return false;
 }
 return currentTransaction.isActive();
}

代码示例来源:origin: org.apache.hive/hive-standalone-metastore

/**
 * @return true if there is an active transaction. If the current transaction
 *         is either committed or rolled back it returns false
 */
@Override
public boolean isActiveTransaction() {
 if (currentTransaction == null) {
  return false;
 }
 return currentTransaction.isActive();
}

代码示例来源:origin: edu.berkeley.cs.shark/hive-metastore

/**
 * @return true if there is an active transaction. If the current transaction
 *         is either committed or rolled back it returns false
 */
public boolean isActiveTransaction() {
 if (currentTransaction == null) {
  return false;
 }
 return currentTransaction.isActive();
}

代码示例来源:origin: org.spark-project.hive/hive-metastore

/**
 * @return true if there is an active transaction. If the current transaction
 *         is either committed or rolled back it returns false
 */
public boolean isActiveTransaction() {
 if (currentTransaction == null) {
  return false;
 }
 return currentTransaction.isActive();
}

代码示例来源:origin: org.apache.isis.core/isis-core-runtime

public void startTransaction() {
  final javax.jdo.Transaction transaction = persistenceManager.currentTransaction();
  if (transaction.isActive()) {
    throw new IllegalStateException("Transaction already active");
  }
  transaction.begin();
}

代码示例来源:origin: org.apache.isis.core/isis-core-runtime

public void endTransaction() {
  final javax.jdo.Transaction transaction = persistenceManager.currentTransaction();
  if (transaction.isActive()) {
    transaction.commit();
  }
}

代码示例来源:origin: org.apache.isis.core/isis-core-runtime

public void abortTransaction() {
  final javax.jdo.Transaction transaction = persistenceManager.currentTransaction();
  if (transaction.isActive()) {
    transaction.rollback();
  }
}

代码示例来源:origin: jpox/jpox

/**
 * Method to transition to write-field state.
 * @param sm StateManager.
 * @return new LifeCycle state.
 */
public LifeCycleState transitionWriteField(StateManager sm)
{
  Transaction tx = sm.getPersistenceManager().currentTransaction();
  return changeState(sm, tx.isActive() ? P_DIRTY : P_NONTRANS);
}

代码示例来源:origin: springframework/spring-orm

public boolean hasTransaction() {
  return (this.persistenceManagerHolder != null &&
      this.persistenceManagerHolder.getPersistenceManager() != null &&
      this.persistenceManagerHolder.getPersistenceManager().currentTransaction().isActive());
}

代码示例来源:origin: tzaeschke/zoodb

private static void safeClose(PersistenceManagerFactory pmf, PersistenceManager pm) {
  if (pm != null) {
    if (pm.currentTransaction().isActive()) {
      pm.currentTransaction().rollback();
    }
    pm.close();
  }
  if (pmf != null) {
    pmf.close();
  }
}

代码示例来源:origin: tzaeschke/zoodb

private static void closePM(PersistenceManager pm) {
  if (!pm.isClosed()) {
    if (pm.currentTransaction().isActive()) {
      pm.currentTransaction().rollback();
    }
    pm.close();
  }
}

代码示例来源:origin: tzaeschke/zoodb

@After
public void after() {
  if (pm != null && !pm.isClosed() && pm.currentTransaction().isActive()) {
    pm.currentTransaction().rollback();
  }
  TestTools.closePM();
  pm = null;
  TestTools.removeDb();
}

相关文章