List of usage examples for javax.persistence PersistenceException PersistenceException
public PersistenceException(Throwable cause)
PersistenceException
exception with the specified cause. From source file:icom.jpa.bdk.dao.VersionControlConfigurationDAO.java
public Object concludeUpdateObject(ManagedIdentifiableProxy obj, DAOContext context, Projection proj) { VersionControlConfigurationUpdater updater = (VersionControlConfigurationUpdater) context.getUpdater(); try {//w ww. ja va 2s. c om 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.EMPTY); Object bdkVersionControlConfiguration = bdkHttpUtil.execute(Object.class, putMethod, updater, userContext.httpClient); return bdkVersionControlConfiguration; } catch (Exception ex) { throw new PersistenceException(ex); } }
From source file:jef.database.DbMetaData.java
/** * //from ww w .ja va2 s .c o m * * @param ds * ? * @param parent * ?? * @param dbkey * ?????? */ public DbMetaData(DataSource ds, IUserManagedPool parent, String dbkey) { this.ds = ds; this.parent = parent; this.dbkey = dbkey; this.subtableInterval = JefConfiguration.getInt(DbCfg.DB_PARTITION_REFRESH, 3600) * 1000; this.subtableCacheExpireTime = System.currentTimeMillis() + subtableInterval; this.parent = parent; LogUtil.debug("init database metadata of " + ds); info = DbUtils.tryAnalyzeInfo(ds, false); Connection con = null; try { con = getConnection(false); } catch (SQLException e) { throw DbUtils.toRuntimeException(e); } try { if (info == null) { info = DbUtils.tryAnalyzeInfo(con); } DatabaseDialect profile = info.profile; Assert.notNull(profile); // SQL? this.ddlGenerator = new DdlGeneratorImpl(profile); // ??? this.feature = new MetadataFeature(con.getMetaData()); // ?.??Metadata? calcSchema(feature, profile); // calcTimeDelta(con, profile); if (Math.abs(dbTimeDelta) > 30000) { // ???30 LogUtil.warn( "The time of thie machine is [{}], and database is [{}]. Please adjust date time via any NTP server.", new Date(), getCurrentTime()); } else { LogUtil.debug("The time between database and this machine is {}ms.", this.dbTimeDelta); } } catch (SQLException e) { throw new PersistenceException(e); } finally { LogUtil.debug("finish init database metadata of " + ds); releaseConnection(con); } }
From source file:com.abiquo.server.core.infrastructure.MachineDAO.java
private List<Machine> findFirstCandidateMachinesReservedRestricted(final Integer idRack, final Integer idVirtualDatacenter, final Long hdRequiredOnDatastore, final Enterprise enterprise) { List<Machine> machines = null; List<Machine> reservMachines = findReservedMachines(enterprise); if (reservMachines != null && reservMachines.size() != 0) { List<Integer> reserveds = new LinkedList<Integer>(); for (Machine m : reservMachines) { reserveds.add(m.getId());// www .j a v a 2 s . c o m } Query query = getSession().createQuery(QUERY_CANDIDATE_MACHINES_RESERVED); query.setInteger("idVirtualDataCenter", idVirtualDatacenter); query.setInteger("idRack", idRack); query.setParameter("state", MachineState.MANAGED); query.setParameterList("reserveds", reserveds); machines = query.list(); if (machines == null || machines.size() == 0) { whyNotCandidateMachines(idRack, idVirtualDatacenter, hdRequiredOnDatastore, enterprise, reserveds); } return machines; } else { final String msg = String.format( "Enterprise works in restricted reserved machines mode but no machine is reserved. Current enterprise: %s", enterprise.getName()); throw new PersistenceException(msg); } }
From source file:icom.jpa.bdk.dao.CategoryApplicationDAO.java
public CategoryApplication concludeUpdateObject(ManagedIdentifiableProxy obj, DAOContext context, Projection proj) {//w ww .ja v a 2 s . c o m CategoryApplicationUpdater updater = (CategoryApplicationUpdater) context.getUpdater(); /* Persistent 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.EMPTY); CategoryApplication bdkCategoryApplication = (CategoryApplication) bdkHttpUtil .execute(CategoryApplication.class, putMethod, updater, userContext.httpClient); return bdkCategoryApplication; } catch (Exception ex) { throw new PersistenceException(ex); } }
From source file:com.openmeap.model.ModelServiceImpl.java
@Override public <E extends ModelEntity, T extends ModelEntity> List<T> getOrdered(E entity, String listMethod, Comparator<T> comparator) { EntityManager entityManager = getEntityManager(); entityManager.getTransaction().begin(); entityManager.merge(entity);//from ww w . jav a 2s .com List<T> ents; try { ents = (List<T>) entity.getClass().getMethod(listMethod).invoke(entity); } catch (Exception e) { throw new PersistenceException(e); } Collections.sort(ents, comparator); entityManager.getTransaction().commit(); return ents; }
From source file:icom.jpa.bdk.dao.PresenceDAO.java
public void concludeActivityListUpdate(ManagedIdentifiableProxy obj, PresenceDAOContext context) { ActivityListUpdater lisUpdater = context.activityListUpdater; try {//from www .java 2s .com BdkUserContextImpl userContext = (BdkUserContextImpl) obj.getPersistenceContext().getUserContext(); String resourceType = "my/presence/activities"; PutMethod putMethod = preparePutMethod(resourceType, userContext.antiCSRF, null); bdkHttpUtil.execute(putMethod, lisUpdater, userContext.httpClient); } catch (Exception ex) { throw new PersistenceException(ex); } }
From source file:com.abiquo.server.core.infrastructure.MachineDAO.java
protected List<Machine> findFirstCandidateMachinesReservedRestrictedHAExclude(final Integer idRack, final Integer idVirtualDatacenter, final Enterprise enterprise, final Integer originalHypervisorId) { List<Machine> machines = null; List<Machine> reservMachines = findReservedMachines(enterprise); if (reservMachines != null && reservMachines.size() != 0) { List<Integer> reserveds = new LinkedList<Integer>(); for (Machine m : reservMachines) { reserveds.add(m.getId());/*from w ww. j a v a 2 s . c o m*/ } Query query = getSession().createQuery(QUERY_CANDIDATE_MACHINES_RESERVED_HA_EXCLUDE_ORIGINAL); query.setInteger("idVirtualDataCenter", idVirtualDatacenter); query.setInteger("idRack", idRack); query.setParameter("state", MachineState.MANAGED); query.setParameterList("reserveds", reserveds); query.setInteger("enterpriseId", enterprise.getId()); query.setInteger("originalHypervisorId", originalHypervisorId); machines = query.list(); if (machines == null || machines.size() == 0) { whyNotCandidateMachines(idRack, idVirtualDatacenter, 0l, enterprise, reserveds); } return machines; } else { final String msg = String.format( "Enterprise works in restricted reserved machines mode but no machine is reserved. Current enterprise: %s", enterprise.getName()); throw new PersistenceException(msg); } }
From source file:icom.jpa.bdk.dao.SimpleContentDAO.java
public void copyObjectState(ManagedObjectProxy obj, Object bdkObject, Projection proj) { super.copyObjectState(obj, bdkObject, proj); if (bdkObject instanceof IdentifiableSimpleContent) { IdentifiableSimpleContent bdkSimpleContent = (IdentifiableSimpleContent) bdkObject; Object pojoObject = obj.getPojoObject(); //if (isBetweenProjections((ManagedDependentProxy) obj, SimpleContentInfo.Attributes.contentLanguage.name(), lastLoadedProjection, proj)) { if (isPartOfProjection(SimpleContentInfo.Attributes.contentLanguage.name(), proj)) { try { assignAttributeValue(pojoObject, SimpleContentInfo.Attributes.contentLanguage.name(), bdkSimpleContent.getContentLanguage()); } catch (Exception ex) { // ignore }/*from w w w . java 2 s . c o m*/ } //if (isBetweenProjections((ManagedDependentProxy) obj, SimpleContentInfo.Attributes.characterEncoding.name(), lastLoadedProjection, proj)) { if (isPartOfProjection(SimpleContentInfo.Attributes.characterEncoding.name(), proj)) { try { assignAttributeValue(pojoObject, SimpleContentInfo.Attributes.characterEncoding.name(), bdkSimpleContent.getCharacterEncoding()); } catch (Exception ex) { // ignore } } //if (isBetweenProjections((ManagedDependentProxy) obj, SimpleContentInfo.Attributes.contentEncoding.name(), lastLoadedProjection, proj)) { if (isPartOfProjection(SimpleContentInfo.Attributes.contentEncoding.name(), proj)) { try { assignAttributeValue(pojoObject, SimpleContentInfo.Attributes.contentEncoding.name(), bdkSimpleContent.getContentEncoding().name()); } catch (Exception ex) { // ignore } } //if (isBetweenProjections((ManagedDependentProxy) obj, SimpleContentInfo.Attributes.data.name(), lastLoadedProjection, proj)) { if (isPartOfProjection(SimpleContentInfo.Attributes.contentBody.name(), proj)) { try { ContentStreamTrait streamHelper = (ContentStreamTrait) BeanHandler .instantiatePojoObject(SimpleContentInfo.ContentStreamClassName); OutputStream outputStream = streamHelper.getFileOutputStream(); PersistenceContext context = obj.getPersistenceContext(); BdkUserContextImpl userContext = (BdkUserContextImpl) context.getUserContext(); String resource = "adoc/content"; ManagedIdentifiableProxy parentObj = (ManagedIdentifiableProxy) ((ManagedDependentProxy) obj) .getParent(); String collabId = parentObj.getObjectId().toString(); GetMethod method = prepareGetMethod(resource, collabId); try { bdkHttpUtil.execute(outputStream, method, userContext.httpClient); } catch (Exception ex) { // ignore } assignAttributeValue(pojoObject, SimpleContentInfo.Attributes.contentBody.name(), streamHelper); } catch (Exception ex) { // ignore } } } else { SimpleContent bdkSimpleContent = (SimpleContent) bdkObject; Object pojoObject = obj.getPojoObject(); /* if (isBetweenProjections((ManagedDependentProxy) obj, SimpleContentInfo.Attributes.name.name(), lastLoadedProjection, proj)) { try { String name = bdkSimpleContent.getName().convertToString(); assignAttributeValue(pojoObject, SimpleContentInfo.Attributes.name.name(), name); } catch (CsiRuntimeException ex) { // ignore } catch (UnsupportedEncodingException ex) { // TODO } } */ //if (isBetweenProjections((ManagedDependentProxy) obj, SimpleContentInfo.Attributes.contentLanguage.name(), lastLoadedProjection, proj)) { if (isPartOfProjection(SimpleContentInfo.Attributes.contentLanguage.name(), proj)) { try { assignAttributeValue(pojoObject, SimpleContentInfo.Attributes.contentLanguage.name(), bdkSimpleContent.getContentLanguage()); } catch (Exception ex) { // ignore } } //if (isBetweenProjections((ManagedDependentProxy) obj, SimpleContentInfo.Attributes.characterEncoding.name(), lastLoadedProjection, proj)) { if (isPartOfProjection(SimpleContentInfo.Attributes.characterEncoding.name(), proj)) { try { assignAttributeValue(pojoObject, SimpleContentInfo.Attributes.characterEncoding.name(), bdkSimpleContent.getCharacterEncoding()); } catch (Exception ex) { // ignore } } //if (isBetweenProjections((ManagedDependentProxy) obj, SimpleContentInfo.Attributes.contentEncoding.name(), lastLoadedProjection, proj)) { if (isPartOfProjection(SimpleContentInfo.Attributes.contentEncoding.name(), proj)) { try { assignAttributeValue(pojoObject, SimpleContentInfo.Attributes.contentEncoding.name(), bdkSimpleContent.getContentEncoding().name()); } catch (Exception ex) { // ignore } } //if (isBetweenProjections((ManagedDependentProxy) obj, SimpleContentInfo.Attributes.data.name(), lastLoadedProjection, proj)) { if (isPartOfProjection(SimpleContentInfo.Attributes.contentBody.name(), proj)) { try { String partIdentifierString = bdkSimpleContent.getPartIdentifier(); if (partIdentifierString != null) { byte[] partIdentifier = partIdentifierString.getBytes(); assignAttributeValue(pojoObject, SimpleContentInfo.TransientAttributes.partIdentifier.name(), partIdentifier); byte[] contentBytes = bdkSimpleContent.getContentBytes(); if (contentBytes == null) { PersistenceContext context = obj.getPersistenceContext(); BdkUserContextImpl userContext = (BdkUserContextImpl) context.getUserContext(); String resourceType = EmailMessageDAO.getInstance().getResourceType(); resourceType += "/content"; ManagedIdentifiableProxy messageObj = getManagedEntityProxy( (ManagedDependentProxy) obj); BeeId id = getBeeId(messageObj.getObjectId().toString()); String partIdentifierStr = new String(partIdentifier); partIdentifierStr = URLEncoder.encode(partIdentifierStr); String params = "partid=" + partIdentifierStr; // TODO GetMethod method = BdkAbstractDAO.prepareGetMethod(resourceType, id.getId(), null, params); ContentStreamTrait streamHelper = (ContentStreamTrait) BeanHandler .instantiatePojoObject(SimpleContentInfo.ContentStreamClassName); OutputStream outputStream = streamHelper.getFileOutputStream(); BdkHttpUtil.getInstance().execute(outputStream, method, userContext.httpClient); outputStream.flush(); outputStream.close(); assignAttributeValue(pojoObject, SimpleContentInfo.Attributes.contentBody.name(), streamHelper); } else { ContentStreamTrait streamHelper = (ContentStreamTrait) BeanHandler .instantiatePojoObject(SimpleContentInfo.ContentStreamClassName); OutputStream outputStream = streamHelper.getFileOutputStream(); outputStream.write(contentBytes); outputStream.flush(); outputStream.close(); assignAttributeValue(pojoObject, SimpleContentInfo.Attributes.contentBody.name(), streamHelper); } } else { // if partIdentifierString is null, we assume that the artifact is a wiki page assignAttributeValue(pojoObject, SimpleContentInfo.TransientAttributes.partIdentifier.name(), null); } } catch (Exception ex) { throw new PersistenceException(ex); } } } }
From source file:icom.jpa.bdk.dao.LabelApplicationDAO.java
public LabelApplication concludeCreateObject(ManagedIdentifiableProxy obj, DAOContext context, Projection proj) {// w w w . j av a 2 s. co m LabelApplicationUpdater updater = (LabelApplicationUpdater) context.getUpdater(); try { 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(); Persistent tag = (Persistent) getAttributeValue(pojoTagApp, TagApplicationInfo.Attributes.tag.name()); BeeId tagId = getBeeId( ((ManagedIdentifiableProxy) tag.getManagedObjectProxy()).getObjectId().toString()); String labelId = tagId.getId(); String params = "labelid=" + labelId; String tagApplicationTypeName = getEnumName(pojoTagApp, BeehiveTagApplicationInfo.Attributes.type.name()); if (tagApplicationTypeName != null) { LabelApplicationType labelAppType = LabelApplicationType.valueOf(tagApplicationTypeName); params += "&type=" + labelAppType.name(); } else { params += "&type=" + LabelApplicationType.PUBLIC.name(); } PostMethod postMethod = preparePostMethod(resourceType + "/label/apply", entityId.getId(), userContext.antiCSRF, Projection.EMPTY, params); LabelApplication bdkLabelApplication = (LabelApplication) bdkHttpUtil.execute(LabelApplication.class, postMethod, updater, userContext.httpClient); return bdkLabelApplication; } catch (Exception ex) { throw new PersistenceException(ex); } }
From source file:com.openmeap.model.ModelManagerImpl.java
private void authorize(ModelEntity entity, Authorizer.Action action) { if (!getAuthorizer().may(action, entity)) { throw new PersistenceException( new AuthorizationException("The user logged in does not have permissions to " + action.toString() + " the " + entity.getClass().getSimpleName())); }//from w ww. j a va2 s . com }