protected ClassDescriptor selectClassDescriptor(Map row) throws PersistenceBrokerException { ClassDescriptor result = m_cld; String ojbConcreteClass = (String) row.get(OJB_CONCRETE_CLASS_KEY); if(ojbConcreteClass != null) { result = m_cld.getRepository().getDescriptorFor(ojbConcreteClass); // if we can't find class-descriptor for concrete class, something wrong with mapping if (result == null) { throw new PersistenceBrokerException("Can't find class-descriptor for ojbConcreteClass '" + ojbConcreteClass + "', the main class was " + m_cld.getClassNameOfObject()); } } return result; }
/** * Convert the given PersistenceBrokerException to an appropriate exception * from the org.springframework.dao hierarchy. In case of a wrapped SQLException, * the SQLExceptionTranslator inherited from the superclass gets applied. * May be overridden in subclasses. * @param ex PersistenceBrokerException that occured * @return the corresponding DataAccessException instance * @see #setExceptionTranslator */ public DataAccessException convertOjbAccessException(PersistenceBrokerException ex) { if (ex.getCause() instanceof PersistenceBrokerException) { return convertOjbAccessException((PersistenceBrokerException) ex.getCause()); } else if (ex.getCause() instanceof SQLException) { return convertJdbcAccessException((SQLException) ex.getCause()); } else { throw new OjbOperationException(ex); } }
} catch (PersistenceBrokerException pbe) { logger.error("Unable to store collection to RDBMS: " + pbe.getMessage(), pbe); rollbackTransaction(); throw new PersistenceException("Unable to store instance '" + Persistable.class.getName() + "' from RDBMS: " + pbe.getMessage(), pbe);
pbe.printStackTrace(); rollbackTransaction(); } finally { logger.error("Unable to store instance '" + Persistable.class.getName() + "' from RDBMS: " + pbe.getMessage(), pbe); throw new PersistenceException("Unable to store instance '" + Persistable.class.getName() + "' from RDBMS: " + pbe.getMessage(), pbe);
logger.error("getSelectByPKStatement returned a null statement"); throw new PersistenceBrokerException("getSelectByPKStatement returned a null statement"); logger.error("PersistenceBrokerException during the execution of materializeObject: " + e.getMessage(), e);
protected Object buildOrRefreshObject(Map row, ClassDescriptor targetClassDescriptor, Object targetObject) { Object result = targetObject; FieldDescriptor fmd = null; if(targetObject == null) { // 1. create new object instance if needed // result = ClassHelper.buildNewObjectInstance(targetClassDescriptor); try { result = Class.forName((String) row.get(OJB_CONCRETE_CLASS_KEY)).newInstance(); } catch (Exception e) { throw new PersistenceBrokerException("Unexpected error while try to instantiate concrete PersistentJetspeedPrincipal instance of class: [" +row.get(OJB_CONCRETE_CLASS_KEY), e); } } // 2. fill all scalar attributes of the new object FieldDescriptor[] fields = targetClassDescriptor.getFieldDescriptions(); for (int i = 0; i < fields.length; i++) { fmd = fields[i]; fmd.getPersistentField().set(result, row.get(fmd.getColumnName())); } return result; }
tmpColl = broker.getCollectionByQuery(query); } catch (PersistenceBrokerException e) { throw new PersistenceException("strictObjectQuery caught a low-level PB exception: " + e.getMessage(), e);
/** * Convert the given PersistenceBrokerException to an appropriate exception * from the org.springframework.dao hierarchy. In case of a wrapped SQLException, * the SQLExceptionTranslator inherited from the superclass gets applied. * May be overridden in subclasses. * @param ex PersistenceBrokerException that occured * @return the corresponding DataAccessException instance * @see #setExceptionTranslator */ public DataAccessException convertOjbAccessException(PersistenceBrokerException ex) { if (ex.getCause() instanceof PersistenceBrokerException) { return convertOjbAccessException((PersistenceBrokerException) ex.getCause()); } else if (ex.getCause() instanceof SQLException) { return convertJdbcAccessException((SQLException) ex.getCause()); } else { throw new OjbOperationException(ex); } }
if (con == null) throw new PersistenceBrokerException("Cannot get connection for " + jcd); if (jcd.getUseAutoCommit() == JdbcConnectionDescriptor.AUTO_COMMIT_SET_TRUE_AND_TEMPORARY_FALSE) throw new PersistenceBrokerException("Cannot request autoCommit state on the connection", e);
logger.error("Unable to delete collection to RDBMS: " + pbe.getMessage(), pbe); throw new PersistenceException("Unable to delete instance '" + Persistable.class.getName() + "' from RDBMS: " + pbe.getMessage(), pbe);
/** * Convert the given PersistenceBrokerException to an appropriate exception * from the org.springframework.dao hierarchy. In case of a wrapped SQLException, * the SQLExceptionTranslator inherited from the superclass gets applied. * May be overridden in subclasses. * @param ex PersistenceBrokerException that occured * @return the corresponding DataAccessException instance * @see #setExceptionTranslator */ public DataAccessException convertOjbAccessException(PersistenceBrokerException ex) { if (ex.getCause() instanceof PersistenceBrokerException) { return convertOjbAccessException((PersistenceBrokerException) ex.getCause()); } else if (ex.getCause() instanceof SQLException) { return convertJdbcAccessException((SQLException) ex.getCause()); } else { throw new OjbOperationException(ex); } }
if (!this.isInLocalTransaction) throw new PersistenceBrokerException("Not in transaction, cannot abort");
/** * This method deletes a Persistable from persistent store. * * @param objectToDelete Persistable to delete * @throws IllegalArgumentException If an attempt is made to delete an object that does not implement the Persistable interface * @throws PersistenceException Throws exception if called on null broker or if an error occurred in the delete process */ protected void deleteObject(final Object objectToDelete) throws PersistenceException, IllegalArgumentException { if (broker != null) { try { if (objectToDelete instanceof Persistable) { beginTransaction(); broker.delete(objectToDelete); commitTransaction(); } else { logger.error("Attempt to delete non-Persistable bean instance from RDBMS!"); throw new IllegalArgumentException("Only Persistable instances can be deleted, since these are the only implementations that are persistence-aware!"); } } catch (PersistenceBrokerException pbe) { // If something went wrong: rollback logger.error("Unable to delete instance '" + Persistable.class.getName() + "' from RDBMS: " + pbe.getMessage(), pbe); rollbackTransaction(); throw new PersistenceException("Unable to delete instance '" + Persistable.class.getName() + "' from RDBMS: " + pbe.getMessage(), pbe); } } else { throw new PersistenceException("DeleteObject called on null broker"); } }
if (result == null || result.length() == 0) throw new PersistenceBrokerException( "ojbConcreteClass field for class " + cld.getClassNameOfObject() + " returned null or 0-length string"); throw new PersistenceBrokerException("Unexpected error while try to read 'ojbConcretClass'" + " field from result set using column name " + fld.getColumnName() + " main class" + " was " + m_cld.getClassNameOfObject(), e);
/** * Performs a report query and returns an iterator on the report * * @param query A fully constructed ReportQuery object * @return An iterator on the report query * @throws PersistenceException If the query object is null or the broker is not initialized */ protected Iterator<Object[]> reportQuery(Query query) throws PersistenceException { if (query != null) { if (broker != null) { try { return broker.getReportQueryIteratorByQuery(query); } catch (PersistenceBrokerException e) { throw new PersistenceException("reportQuery caught a low-level PB exception: " + e.getMessage(), e); } } else { throw new PersistenceException("Query called on uninitialized PersistenceBroker"); } } else { throw new PersistenceException("No query specified!"); } }
if (result == null || result.length() == 0) throw new PersistenceBrokerException( "ojbConcreteClass field for class " + cld.getClassNameOfObject() + " returned null or 0-length string"); throw new PersistenceBrokerException("Unexpected error while try to read 'ojbConcretClass'" + " field from result set using column name " + fld.getColumnName() + " main class" + " was " + m_cld.getClassNameOfObject(), e);
/** * Performs a query and returns the count of objects the criteria specified * * @param query A fully constructed Query object * @throws PersistenceException If the query object is null or the broker is not initialized */ protected int countQuery(final Query query) throws PersistenceException { if (query != null) { if (broker != null) { try { return broker.getCount(query); } catch (PersistenceBrokerException e) { throw new PersistenceException("countQuery caught a low-level PB exception: " + e.getMessage(), e); } } else { throw new PersistenceException("Query called on uninitialized PersistenceBroker"); } } else { throw new PersistenceException("No query specified!"); } }
@Override public void retrieveReference(Object obj, String pAttributeName) throws PersistenceBrokerException { // In the new version of the fenix-framework, where we use OIDs allover as foreign keys // this method is no longer called for retrieving references to single objects // (those described by an ObjectReferenceDescriptor). // Now, this method should be used only for retrieving collections. // // So, the code here is the merging of the original // PersistenceBrokerImpl.retrieveReference with the // QueryReferenceBroker.retrieveCollection method, changed to // use OIDs rather the primary keys (which remain to be, // still, the idInternal, to create the SQL queries. ClassDescriptor cld = getClassDescriptor(obj.getClass()); CollectionDescriptor cds = cld.getCollectionDescriptorByName(pAttributeName); if (cds == null) { throw new PersistenceBrokerException("In the Fenix Framework retrieveReference should be called only for collections"); } // this collection type will be used: Class collectionClass = cds.getCollectionClass(); Query fkQuery = getFKQuery((AbstractDomainObject) obj, cld, cds); ManageableCollection result = referencesBroker.getCollectionByQuery(collectionClass, fkQuery, false); cds.getPersistentField().set(obj, result); }
/** * Performs a query and returns an object matching the criteria specified * * @param query A fully constructed Query object * @return Object A Collection of Persistable objects as defined by the query * @throws PersistenceException If the query object is null or the broker is not initialized */ protected Object objectQuery(final Query query) throws PersistenceException { if (query != null) { if (broker != null) { try { return broker.getObjectByQuery(query); } catch (PersistenceBrokerException pbe) { throw new PersistenceException("objectQuery caught a low-level PB exception: " + pbe.getMessage(), pbe); } } else { throw new PersistenceException("Query called on uninitialized PersistenceBroker"); } } else { throw new PersistenceException("No query specified!"); } }
/** * Start transaction on the underlying connection. */ public void localBegin() { if (this.isInLocalTransaction) { throw new TransactionInProgressException("Connection is already in transaction"); } Connection connection = null; try { connection = this.getConnection(); } catch (LookupException e) { /** * must throw to notify user that we couldn't start a connection */ throw new PersistenceBrokerException("Can't lookup a connection", e); } if (log.isDebugEnabled()) log.debug("localBegin was called for con " + connection); if (jcd.getUseAutoCommit() == JdbcConnectionDescriptor.AUTO_COMMIT_SET_TRUE_AND_TEMPORARY_FALSE) { if (log.isDebugEnabled()) log.debug("Try to change autoCommit state to 'false'"); platform.changeAutoCommitState(jcd, connection, false); } this.isInLocalTransaction = true; }