private boolean initializeServerRecord() { PersistenceBroker broker = null; try { broker = PersistenceBrokerFactory.defaultPersistenceBroker(); broker.beginTransaction(); Connection conn = broker.serviceConnectionManager().getConnection(); Statement stmt = conn.createStatement(); // delete previous record for this server and insert a new one stmt.executeUpdate("DELETE FROM FF$LAST_TX_PROCESSED WHERE SERVER = '" + server + "' or LAST_UPDATE < (NOW() - interval 3600 second)"); stmt.executeUpdate("INSERT INTO FF$LAST_TX_PROCESSED VALUES ('" + server + "'," + lastTxNumber + ",null)"); broker.commitTransaction(); return true; } catch (Exception e) { e.printStackTrace(); logger.error("Couldn't initialize the clean thread"); //throw new Error("Couldn't initialize the clean thread"); if (broker != null) { broker.abortTransaction(); } } finally { if (broker != null) { if (broker.isInTransaction()) { broker.abortTransaction(); } broker.close(); } } return false; }
public Object doInPersistenceBroker(PersistenceBroker pb) throws PersistenceBrokerException { pb.store(entity); return null; } });
public Object doInPersistenceBroker(PersistenceBroker pb) throws PersistenceBrokerException { pb.clearCache(); return null; } });
@Override protected void suspendTx() { // close the broker to release the db connection on suspension if (broker != null) { if (broker.isInTransaction()) { broker.abortTransaction(); } broker.close(); broker = null; } super.suspendTx(); }
/** * Aborts transaction on a non-null broker in transaction. * * @throws PersistenceException if a low-level exception is caught * @throws IllegalStateException if a transaction is not already in progress or if broker not initialized */ protected void rollbackTransaction() throws PersistenceException { if (broker != null) { try { if (broker.isInTransaction()) { broker.abortTransaction(); } else { throw new IllegalStateException("Called to rollback a transaction when has not been started yet."); } } catch (PersistenceBrokerException e) { throw new PersistenceException("Could not rollback transaction", e); } } else { throw new IllegalStateException("Called to rollback transaction when broker not properly initialized!"); } }
public static void ensureDomainRoot() { PersistenceBroker broker = PersistenceBrokerFactory.defaultPersistenceBroker(); try { broker.beginTransaction(); Connection conn = broker.serviceConnectionManager().getConnection(); conn.setAutoCommit(false); broker.commitTransaction(); stm.close(); conn.close(); throw new Error(e); } finally { broker.close();
try { broker = PersistenceBrokerFactory.defaultPersistenceBroker(); final Connection connection = broker.serviceConnectionManager().getConnection(); statement = connection.createStatement(); final String query = if (broker.isInTransaction()) { broker.abortTransaction(); broker.close();
/** * returns a java.sql.Connection object from the current broker * * @return ava.sql.Connection object from the current broker or null * @throws LookupException */ protected Connection getConnection() throws LookupException { if (broker != null) { return broker.serviceConnectionManager().getConnection(); } else { return null; } }
if (!pb.isInTransaction()) { pb.beginTransaction(); pb.commitTransaction(); } catch (Throwable t) { t.printStackTrace(); } finally { if (pb != null) { pb.abortTransaction();
void makePersistent(PersistenceBroker pb, int txNumber) throws SQLException, LookupException { Connection conn = pb.serviceConnectionManager().getConnection(); pb.store(obj, ObjectModificationDefaultImpl.INSERT); for (Object obj : objsToStore) { try { pb.store(obj, ObjectModificationDefaultImpl.UPDATE); } catch (OptimisticLockException ole) { pb.removeFromCache(obj); foundOptimisticException = true;
txObject.setPersistenceBrokerHolder(new PersistenceBrokerHolder(pb)); Connection con = pb.serviceConnectionManager().getConnection(); Integer previousIsolationLevel = DataSourceUtils.prepareConnectionForTransaction(con, definition); txObject.setPreviousIsolationLevel(previousIsolationLevel); pb.beginTransaction();
conn = PersistenceBrokerFactory.defaultPersistenceBroker().serviceConnectionManager().getConnection(); PreparedStatement [] pstmts = createPagingPreparedStatementAndCountPreparedStatement(conn, queryContext); pstmtForPaging = pstmts[0]; for (int i = 0; i < queryContext.getLength(); i++) { RowReader rr = PersistenceBrokerFactory.defaultPersistenceBroker().getClassDescriptor( PersistentJetspeedPrincipal.class).getRowReader(); Map<Object, Object> row = new HashMap<Object, Object>(); QueryByCriteria query = new QueryByCriteria(p); p = (PersistentJetspeedPrincipal) PersistenceBrokerFactory.defaultPersistenceBroker() .getObjectByQuery(query); results.add(p); if (!rsForPaging.next()) {
protected ClassDescriptor selectClassDescriptor(Map row) throws PersistenceBrokerException { String[] key = new String[column.length]; for (int i = 0; i < column.length; i++) { key[i] = (String) row.get(column[i]); } Class clazz = null; if (key != null) { clazz = chooseClass(key); } if (clazz == null) { return getClassDescriptor(); } PersistenceBroker broker = null; try { broker = PersistenceBrokerFactory.defaultPersistenceBroker(); ClassDescriptor result = broker.getClassDescriptor(clazz); broker.close(); if (result == null) { return getClassDescriptor(); } else { return result; } } catch (PersistenceBrokerException e) { broker.close(); throw e; } }
public Object doInPersistenceBroker(PersistenceBroker pb) throws PersistenceBrokerException, LookupException, SQLException { return pb.getCollectionByQuery(ManageableArrayList.class, query); } }
public Object doInPersistenceBroker(PersistenceBroker pb) throws PersistenceBrokerException { return pb.getReportQueryIteratorByQuery(query); } });
/** * <p>Releases the broker to the connection pool */ protected void releaseBroker() throws PersistenceException { if (broker != null) { if (broker.close()) { logger.debug("Persistence Broker closed."); broker = null; } else { throw new PersistenceException("Could not close Persistence Broker"); } } }
public Object doInPersistenceBroker(PersistenceBroker pb) throws PersistenceBrokerException { return pb.getObjectByQuery(query); } });
/** * Commits a transaction on a non-null broker. If broker is null, does nothing. * * @throws PersistenceException if a low-level exception is caught * @throws IllegalStateException if a transaction is not already in progress or if broker not initialized */ protected void commitTransaction() throws PersistenceException { //commit transaction if (broker != null) { try { if (broker.isInTransaction()) { broker.commitTransaction(); } else { throw new IllegalStateException("Called to commit a transaction when has not been started yet."); } } catch (TransactionNotInProgressException e) { throw new PersistenceException("Could not commit transaction", e); } catch (TransactionAbortedException e) { throw new PersistenceException("Could not commit transaction", e); } } else { throw new IllegalStateException("Called to commit transaction when broker not properly initialized!"); } }
/** * Begins a transaction on a non-null broker. * * @throws PersistenceException if a low-level exception is caught * @throws IllegalStateException if a transaction is already in progress or if broker not initialized */ protected void beginTransaction() throws PersistenceException, IllegalStateException { //begin transction if (broker != null) { try { if (!broker.isInTransaction()) { broker.beginTransaction(); } else { throw new IllegalStateException("Called to begin transaction when one is already in progress"); } } catch (TransactionInProgressException e) { throw new PersistenceException("Could not start transaction", e); } catch (TransactionAbortedException e) { throw new PersistenceException("Could not start transaction", e); } } else { throw new IllegalStateException("Called to begin transaction when broker not properly initialized!"); } }
protected void doRollback(DefaultTransactionStatus status) { PersistenceBrokerTransactionObject txObject = (PersistenceBrokerTransactionObject) status.getTransaction(); if (status.isDebug()) { logger.debug("Rolling back OJB transaction on PersistenceBroker [" + txObject.getPersistenceBrokerHolder().getPersistenceBroker() + "]"); } txObject.getPersistenceBrokerHolder().getPersistenceBroker().abortTransaction(); }