List of usage examples for javax.persistence PersistenceException PersistenceException
public PersistenceException(Throwable cause)
PersistenceException
exception with the specified cause. From source file:com.impetus.client.redis.RedisClient.java
@Override public <E> List<E> findAll(Class<E> entityClass, String[] columnsToSelect, Object... keys) { Object connection = getConnection(); List results = new ArrayList(); try {//from w w w . j a va 2 s . c om for (Object key : keys) { Object result = fetch(entityClass, key, connection, null); if (result != null) { results.add(result); } } } catch (InstantiationException e) { logger.error("Error during find by key:", e); throw new PersistenceException(e); } catch (IllegalAccessException e) { logger.error("Error during find by key:", e); throw new PersistenceException(e); } return results; }
From source file:icom.jpa.bdk.dao.LabelApplicationDAO.java
public void delete(ManagedIdentifiableProxy obj) { try {/* www . ja v a2 s . co m*/ BdkUserContextImpl userContext = (BdkUserContextImpl) obj.getPersistenceContext().getUserContext(); Persistent pojoTagApp = obj.getPojoIdentifiable(); Persistent pojoEntity = getLabeledEntity(pojoTagApp); BeeId entityId = getBeeId( ((ManagedIdentifiableProxy) pojoEntity.getManagedObjectProxy()).getObjectId().toString()); String resourceType = entityId.getResourceType(); String labelId = obj.getObjectId().toString(); String params = "labelid=" + labelId; PostMethod postMethod = preparePostMethod(resourceType + "/label/remove", entityId.getId(), userContext.antiCSRF, Projection.EMPTY, params); bdkHttpUtil.execute(LabelApplication.class, postMethod, userContext.httpClient); } catch (Exception ex) { throw new PersistenceException(ex); } }
From source file:icom.jpa.bdk.dao.CategoryApplicationDAO.java
public CategoryApplication concludeCreateObject(ManagedIdentifiableProxy obj, DAOContext context, Projection proj) {//from w w w . j av a2s.c om CategoryApplicationUpdater updater = (CategoryApplicationUpdater) context.getUpdater(); /* Identifiable pojoCatApp = obj.getPojoIdentifiable(); Persistent pojoCat = getCategory(pojoCatApp); BeeId catId = getBeeId(((ManagedIdentifiableProxy)pojoCat.getManagedObjectProxy()).getObjectId().toString()); Persistent pojoEntity = getCategorizedEntity(pojoCatApp); BeeId entityId = getBeeId(((ManagedIdentifiableProxy)pojoEntity.getManagedObjectProxy()).getObjectId().toString()); */ try { BdkUserContextImpl userContext = (BdkUserContextImpl) obj.getPersistenceContext().getUserContext(); BeeId id = getBeeId(obj.getObjectId().toString()); String collabId = id.getId(); String resourceType = id.getResourceType(); PutMethod putMethod = preparePutMethod(resourceType, collabId, userContext.antiCSRF, Projection.BASIC); CategoryApplication bdkCategoryApplication = (CategoryApplication) bdkHttpUtil .execute(CategoryApplication.class, putMethod, updater, userContext.httpClient); copyObjectState(obj, bdkCategoryApplication, Projection.BASIC); //BeeId newBeeId = null; // bdkCategoryApplication.getObjectId(); //assignObjectId(pojoCatApp, newBeeId.getId()); obj.getPersistenceContext().recacheIdentifiableDependent(obj); return bdkCategoryApplication; } catch (Exception ex) { throw new PersistenceException(ex); } }
From source file:com.abiquo.server.core.infrastructure.MachineDAO.java
/** * Do not require additional space on the datastore. Used during HA, selects a machine different * of the ''originalHypervisorId'' with the same ''datastoreUuid'' enabled. *//*from www . j ava 2s . co m*/ public List<Machine> findCandidateMachines(final Integer idRack, final Integer idVirtualDatacenter, final Enterprise enterprise, final String datastoreUuid, final Integer originalHypervisorId) { List<Machine> machines = null; if (enterprise.getIsReservationRestricted()) { machines = findFirstCandidateMachinesReservedRestrictedHAExclude(idRack, idVirtualDatacenter, enterprise, originalHypervisorId); } else { Query query = getSession().createQuery(QUERY_CANDIDATE_MACHINES_HA_EXCLUDE_ORIGINAL); query.setInteger("idVirtualDataCenter", idVirtualDatacenter); query.setInteger("idRack", idRack); query.setParameter("state", MachineState.MANAGED); query.setParameter("enterpriseId", enterprise.getId()); query.setParameter("originalHypervisorId", originalHypervisorId); machines = query.list(); } if (machines == null || machines.size() == 0) { Query query = getSession().createQuery(QUERY_CANDIDATE_MACHINES); query.setInteger("idVirtualDataCenter", idVirtualDatacenter); query.setInteger("idRack", idRack); query.setParameter("state", MachineState.MANAGED); query.setParameter("enterpriseId", enterprise.getId()); machines = query.list(); if (machines == null || machines.size() == 0) { throw new PersistenceException(String.format( "There isn't any MANAGED machine on the required rack [%d] and virtual datacenter [%d] available for the current enterpirse [%s]. " + "Pleas check the machine reservation policies.", idRack, idVirtualDatacenter, enterprise.getName())); } else { throw new PersistenceException(String.format( "The only MANAGED machine on the required rack [%d] and virtual datacenter [%d] available for the current enterpirse [%s]" + "is the target of the high availability (so can't be used) ", idRack, idVirtualDatacenter, enterprise.getName())); } } // 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_HA_DATASTOREUUID); datastoreQuery.setParameterList("candidates", candidatesids); datastoreQuery.setParameter("datastoreUuid", datastoreUuid); List<Integer> includedIds = datastoreQuery.list(); if (includedIds.size() == 0) { throw new PersistenceException(String .format("There isn't any machine with the required shared datastore [%s]", datastoreUuid)); } // 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:icom.jpa.bdk.dao.CategoryApplicationDAO.java
public void delete(ManagedIdentifiableProxy obj) { try {/* w ww .ja v a2 s. co m*/ BdkUserContextImpl userContext = (BdkUserContextImpl) obj.getPersistenceContext().getUserContext(); BeeId id = getBeeId(obj.getObjectId().toString()); String collabId = id.getId(); String resourceType = id.getResourceType(); DeleteMethod deleteMethod = prepareDeleteMethod(resourceType, collabId, userContext.antiCSRF); bdkHttpUtil.execute(deleteMethod, userContext.httpClient); } catch (Exception ex) { throw new PersistenceException(ex); } }
From source file:com.javaid.bolaky.domain.pools.entity.Pool.java
@PrePersist public void checkPoolState() { if (this.poolStatus.equals(PoolStatus.DRAFT)) { throw new PersistenceException("cannot persist a pool in a draft state"); }/*from w ww. java 2 s .com*/ }
From source file:icom.jpa.bdk.dao.SimpleContentDAO.java
private void uploadContentBody(ManagedObjectProxy obj, DAOContext context) { try {/*from ww w. j av a 2 s . c o m*/ String resource = "session/upload"; BdkUserContextImpl userContext = (BdkUserContextImpl) obj.getPersistenceContext().getUserContext(); String antiCSRF = userContext.antiCSRF; String uploadScopeId = context.getUploadScopeId(); String uploadContentStreamId = generateUUID(); context.setUploadContentStreamId(uploadContentStreamId); String params = "uploadscope=scope" + uploadScopeId + "&content_id=" + uploadContentStreamId; PostMethod uploadContentMethod = preparePostMethod(resource, antiCSRF, params); Persistent pojoIdentifiable = obj.getPojoObject(); ContentStreamTrait cos = (ContentStreamTrait) getAttributeValue(pojoIdentifiable, SimpleContentInfo.Attributes.contentBody.name()); if (cos != null) { InputStream fis = cos.getFileInputStream(); if (fis != null) { RequestEntity simpleText = new InputStreamRequestEntity(fis); uploadContentMethod.setRequestEntity(simpleText); } } BdkHttpUtil util = BdkHttpUtil.getInstance(); util.upLoadContent(uploadContentMethod, userContext.httpClient); } catch (Exception ex) { throw new PersistenceException(ex); } }
From source file:icom.jpa.bdk.BdkAbstractDAO.java
static public List<Object> listEntities(PersistenceContext context, Class<?> entityClass, PredicateAndSortListParameters predicateAndSortListParameters, String resourceType, String resourceId, Projection proj, String query) { List<Object> bdkEntityList = null; try {//from www. j ava2 s . c o m BdkUserContextImpl userContext = (BdkUserContextImpl) context.getUserContext(); PostMethod method = prepareListPostMethod(resourceType, resourceId, userContext.antiCSRF, proj, query); ListResult bdkEntityListResult = (ListResult) bdkHttpUtil.execute(ListResult.class, method, predicateAndSortListParameters, userContext.httpClient); bdkEntityList = (List<Object>) bdkEntityListResult.getElements(); } catch (Exception ex) { throw new PersistenceException(ex); } return bdkEntityList; }
From source file:icom.jpa.bdk.dao.VersionControlConfigurationDAO.java
public Object concludeCreateObject(ManagedIdentifiableProxy obj, DAOContext context, Projection proj) { VersionControlConfigurationCreator creator = (VersionControlConfigurationCreator) context.getCreator(); try {/* w w w. j a v a 2 s . com*/ BdkUserContextImpl userContext = (BdkUserContextImpl) obj.getPersistenceContext().getUserContext(); BeeId id = getBeeId(obj.getObjectId().toString()); String resourceType = id.getResourceType(); PutMethod putMethod = preparePutMethod(resourceType, userContext.antiCSRF, Projection.BASIC); Object bdkVersionControlConfiguration = bdkHttpUtil.execute(Object.class, putMethod, creator, userContext.httpClient); copyObjectState(obj, bdkVersionControlConfiguration, Projection.BASIC); //BeeId newBeeId = bdkVersionControlConfiguration.getid; //assignObjectId(pojoCatApp, newBeeId.getId()); obj.getPersistenceContext().recacheIdentifiableDependent(obj); return bdkVersionControlConfiguration; } catch (Exception ex) { throw new PersistenceException(ex); } }
From source file:icom.jpa.bdk.dao.EntityDAO.java
public Entity concludeUpdateObject(ManagedIdentifiableProxy obj, DAOContext context, Projection proj) { EntityUpdater updater = (EntityUpdater) context.getUpdater(); try {/*from w ww .j ava 2 s. com*/ BdkUserContextImpl userContext = (BdkUserContextImpl) obj.getPersistenceContext().getUserContext(); BeeId id = getBeeId(obj.getObjectId().toString()); String collabId = id.getId(); String resourceType = id.getResourceType(); String params = getCreateObjectParameters(obj, context); PutMethod putMethod = preparePutMethod(resourceType, collabId, userContext.antiCSRF, proj, params); Entity bdkEntity = (Entity) bdkHttpUtil.execute(getBdkClass(obj), putMethod, updater, userContext.httpClient); if (proj != Projection.EMPTY) { String changeToken = bdkEntity.getSnapshotId(); assignChangeToken(obj.getPojoIdentifiable(), changeToken); } return bdkEntity; } catch (Exception ex) { throw new PersistenceException(ex); } }