Search in sources :

Example 1 with ArgumentException

use of org.apache.openjpa.persistence.ArgumentException in project carbon-business-process by wso2.

the class AttachmentMgtDAOConnectionFactoryImpl method getDAOConnection.

// TODO: Throw a proper exception
@Override
public AttachmentMgtDAOConnection getDAOConnection() {
    if (connections.get() != null) {
        return connections.get();
    } else {
        try {
            // At the moment a property-map is not passed when constructing the entity-Manager
            EntityManager entityManager = entityManagerFactory.createEntityManager();
            AttachmentMgtDAOConnectionImpl conn = createAttachmentMgtDAOConnection(entityManager);
            connections.set(conn);
            return conn;
        } catch (ArgumentException argEx) {
            log.fatal("Entity-Manager creation failed.", argEx);
            throw argEx;
        }
    }
}
Also used : EntityManager(javax.persistence.EntityManager) ArgumentException(org.apache.openjpa.persistence.ArgumentException)

Example 2 with ArgumentException

use of org.apache.openjpa.persistence.ArgumentException in project oozie by apache.

the class XTestCase method getCountAndRemoveAll.

private <E> int getCountAndRemoveAll(final EntityManager entityManager, final String queryName, final Class<E> entityClass) {
    try {
        final TypedQuery<E> getAllQuery = entityManager.createNamedQuery(queryName, entityClass);
        final List<E> allEntities = getAllQuery.getResultList();
        final int entitiesCount = allEntities.size();
        for (final E w : allEntities) {
            entityManager.remove(w);
        }
        return entitiesCount;
    } catch (final RollbackException e) {
        log.warn("Cannot get count or remove all entities. [queryName={0};entityClass.name={1}]", queryName, entityClass.getName());
        return 0;
    } catch (final PersistenceException | ArgumentException e) {
        log.warn("Cannot get count or remove all entities. [queryName={0};entityClass.name={1}]", queryName, entityClass.getName());
        return 0;
    }
}
Also used : RUNMODE(org.apache.oozie.test.MiniHCatServer.RUNMODE) PersistenceException(javax.persistence.PersistenceException) ArgumentException(org.apache.openjpa.persistence.ArgumentException) RollbackException(org.apache.openjpa.persistence.RollbackException)

Aggregations

ArgumentException (org.apache.openjpa.persistence.ArgumentException)2 EntityManager (javax.persistence.EntityManager)1 PersistenceException (javax.persistence.PersistenceException)1 RUNMODE (org.apache.oozie.test.MiniHCatServer.RUNMODE)1 RollbackException (org.apache.openjpa.persistence.RollbackException)1