Example usage for javax.persistence PersistenceException PersistenceException

List of usage examples for javax.persistence PersistenceException PersistenceException

Introduction

In this page you can find the example usage for javax.persistence PersistenceException PersistenceException.

Prototype

public PersistenceException(Throwable cause) 

Source Link

Document

Constructs a new PersistenceException exception with the specified cause.

Usage

From source file:com.nortal.petit.orm.StatementSupport.java

/**
 * Deletes beans by primary key mapping/*ww w. j ava 2 s . c  o m*/
 * 
 * @param beans
 *            Beans to deleted
 */
public <B> void delete(Collection<B> beans) {
    if (CollectionUtils.isEmpty(beans)) {
        return;
    }

    DeleteStatement<B> stm = new DeleteStatement<B>(getJdbcTemplate(), getStatementBuilder(),
            (B[]) beans.toArray());
    if (stm.getMapping().id() != null) {
        stm.exec();
    } else {
        throw new PersistenceException("Model " + beans.iterator().next().getClass().getSimpleName()
                + " does not have primary key mapping");
    }
}

From source file:com.impetus.kundera.ejb.EntityManagerImpl.java

@Override
public final void remove(Object e) {
    if (e == null) {
        throw new IllegalArgumentException("Entity must not be null.");
    }/*from  w ww  .  j a  v a2 s  .  co  m*/

    // Validate
    metadataManager.validate(e.getClass());

    try {

        List<EnhancedEntity> reachableEntities = entityResolver.resolve(e, CascadeType.REMOVE,
                this.client.getType());

        // remove each one
        for (EnhancedEntity o : reachableEntities) {
            log.debug("Removing @Entity >> " + o);

            EntityMetadata m = metadataManager.getEntityMetadata(o.getEntity().getClass());
            m.setDBType(this.client.getType());
            // fire PreRemove events
            eventDispatcher.fireEventListeners(m, o, PreRemove.class);

            session.remove(o.getEntity().getClass(), o.getId());
            dataManager.remove(o, m);
            getIndexManager().remove(m, o.getEntity(), o.getId());

            // fire PostRemove events
            eventDispatcher.fireEventListeners(m, o, PostRemove.class);
        }
    } catch (Exception exp) {
        throw new PersistenceException(exp);
    }
}

From source file:com.impetus.client.cassandra.pelops.PelopsClient.java

/**
 * Method to return list of entities for given below attributes:.
 * /* w  w  w  .j  a  va 2s .c o  m*/
 * @param entityClass
 *            entity class
 * @param relationNames
 *            relation names
 * @param isWrapReq
 *            true, in case it needs to populate enhance entity.
 * @param metadata
 *            entity metadata.
 * @param rowIds
 *            array of row key s
 * @return list of wrapped entities.
 */
public final List find(Class entityClass, List<String> relationNames, boolean isWrapReq,
        EntityMetadata metadata, Object... rowIds) {
    if (!isOpen()) {
        throw new PersistenceException("PelopsClient is closed.");
    }

    Selector selector = Pelops.createSelector(PelopsUtils.generatePoolName(getPersistenceUnit()));
    // selector.

    // PelopsDataHandler handler = new PelopsDataHandler(this);

    List entities = null;
    try {
        // TODO
        entities = handler.fromThriftRow(selector, entityClass, metadata, relationNames, isWrapReq,
                consistencyLevel, rowIds);
    } catch (Exception e) {
        throw new KunderaException(e);
    }

    return entities;
}

From source file:com.impetus.kundera.metadata.MetadataManager.java

@Override
// called whenever a class with @Entity annotation is encountered in the
// classpath.//from   w w  w  . j  ava  2  s  .  c  o m
public final void discovered(String className, String[] annotations) {
    try {
        Class<?> clazz = Class.forName(className);

        // process for Metadata
        EntityMetadata metadata = process(clazz);
        cacheMetadata(clazz, metadata);
        log.info("Added @Entity " + clazz.getName());
    } catch (ClassNotFoundException e) {
        throw new PersistenceException(e.getMessage());
    }
}

From source file:com.impetus.kundera.client.PelopsClient.java

@Override
public final List<SuperColumn> loadSuperColumns(String keyspace, String columnFamily, String rowId,
        String... superColumnNames) throws Exception {
    if (!isOpen())
        throw new PersistenceException("PelopsClient is closed.");
    Selector selector = Pelops.createSelector(poolName, keyspace);
    return selector.getSuperColumnsFromRow(rowId, columnFamily, Selector.newColumnsPredicate(superColumnNames),
            ConsistencyLevel.ONE);//from   ww w. j av  a 2 s .  com
}

From source file:au.com.cybersearch2.classyjpa.entity.ObjectMonitor.java

/**
 * Utilty method to throw PersistenceException for reflection error
 *@param method Name of method to report
 *@param details Error details/*from   www.j  a v a 2s  .com*/
 *@return PersistenceException
 */
private static PersistenceException createReflectionErrorException(String method, String details) {
    throw new PersistenceException(method + " failed due to Java Reflection error: " + details);
}

From source file:com.openmeap.model.ModelManagerImpl.java

@Override
public GlobalSettings getGlobalSettings() {
    GlobalSettings settings = modelService.findByPrimaryKey(GlobalSettings.class, (Long) 1L);
    boolean update = false;
    if (settings == null) {
        settings = new GlobalSettings();
        settings.setServiceManagementAuthSalt(UUID.randomUUID().toString());
        update = true;// w w  w .  j av a2  s .  c  om
    }
    if (settings.getServiceManagementAuthSalt() == null
            || settings.getServiceManagementAuthSalt().trim().length() == 0) {
        settings.setServiceManagementAuthSalt(UUID.randomUUID().toString());
        update = true;
    }
    if (update) {
        try {
            modelService.begin();
            settings = modelService.saveOrUpdate(settings);
            modelService.commit();
        } catch (Exception e) {
            modelService.rollback();
            throw new PersistenceException(e);
        }
    }
    return settings;
}

From source file:com.abiquo.server.core.infrastructure.MachineDAO.java

public List<Machine> findCandidateMachines(final Integer idRack, final Integer idVirtualDatacenter,
        final Long hdRequiredOnDatastore, final Enterprise enterprise) {

    List<Machine> machines;

    if (enterprise.getIsReservationRestricted()) {
        machines = findFirstCandidateMachinesReservedRestricted(idRack, idVirtualDatacenter,
                hdRequiredOnDatastore, enterprise);
    } else {//from ww w.  j  a v  a2s.c o m
        machines = findFirstCandidateMachines(idRack, idVirtualDatacenter, hdRequiredOnDatastore, enterprise);
    }

    // StringBuilder sbcandidates = new StringBuilder();
    List<Integer> candidatesids = new LinkedList<Integer>();
    for (Machine m : machines) {
        candidatesids.add(m.getId());
    }

    // with datastore
    Query datastoreQuery = getSession().createQuery(QUERY_CANDIDATE_DATASTORE);
    datastoreQuery.setLong("hdRequiredOnRepository", hdRequiredOnDatastore);
    datastoreQuery.setParameterList("candidates", candidatesids);

    List<Integer> includedIds = datastoreQuery.list();

    if (includedIds.size() == 0) {
        throw new PersistenceException(String.format(
                "There isn't any machine with the required datastore capacity [%d]", hdRequiredOnDatastore));
    }

    // execute the enterprise exclusion rule
    Query excludedQuery = getSession().createQuery(QUERY_CANDIDATE_NO_ENTERPRISE_EXCLUDED);
    excludedQuery.setParameter("enterpriseId", enterprise.getId());
    List<Integer> excludedMachineIds = excludedQuery.list();

    List<Machine> notExcludedMachines = new LinkedList<Machine>();

    for (Machine m : machines) {
        Integer machineId = m.getId();

        if (!excludedMachineIds.contains(machineId) && includedIds.contains(machineId)) {
            notExcludedMachines.add(m);
        }
    }

    if (notExcludedMachines.size() == 0) {
        throw new PersistenceException("All the candiate machines are excluded by other enterprsies "
                + "with virtual machines deployed on it. Please check the enterprise affinity rules.");
    }

    return notExcludedMachines;
}

From source file:com.nortal.petit.orm.StatementSupport.java

/**
 * Loads bean by primary key mapping/*from w  w  w.j  a va  2  s  .co m*/
 * 
 * @param beanClass
 *            Bean class
 * @param id
 *            Primary key value
 * @return Bean
 */
public <B> B loadById(Class<B> beanClass, Object id) {
    Assert.notNull(id, "id is mandatory");

    LoadStatement<B> stm = loadStm(beanClass);
    BeanMapping<B> mapping = stm.getMapping();
    if (mapping.id() != null) {
        stm.where(mapping.id().name(), id);
    } else {
        throw new PersistenceException("Model " + mapping + " does not have primary key mapping");
    }
    return stm.single();
}

From source file:com.impetus.kundera.client.PelopsClient.java

@Override
public final Map<String, List<SuperColumn>> loadSuperColumns(String keyspace, String columnFamily,
        String... rowIds) throws Exception {

    if (!isOpen())
        throw new PersistenceException("PelopsClient is closed.");

    Selector selector = Pelops.createSelector(poolName, keyspace);
    return selector.getSuperColumnsFromRows(Arrays.asList(rowIds), columnFamily,
            Selector.newColumnsPredicateAll(false, 1000), ConsistencyLevel.ONE);
}