List of usage examples for javax.persistence PersistenceException PersistenceException
public PersistenceException(Throwable cause)
PersistenceException
exception with the specified cause. From source file:gov.ca.cwds.data.persistence.cms.Client.java
/** * Constructor. Construct from counterpart domain class. * * @param id primary key//from w w w . j a va 2s . c o m * @param client The domain object to construct this object from * @param lastUpdatedId the id of the last person to update this object * @param lastUpdatedTime the time when this object is last updated */ public Client(String id, gov.ca.cwds.rest.api.domain.cms.Client client, String lastUpdatedId, Date lastUpdatedTime) { super(lastUpdatedId, lastUpdatedTime); try { this.id = id; this.adjudicatedDelinquentIndicator = cookBoolean(client.getAdjudicatedDelinquentIndicator()); this.adoptionStatusCode = client.getAdoptionStatusCode(); this.alienRegistrationNumber = client.getAlienRegistrationNumber(); this.birthCity = client.getBirthCity(); this.birthCountryCodeType = client.getBirthCountryCodeType(); this.birthDate = uncookDateString(client.getBirthDate()); this.birthFacilityName = client.getBirthFacilityName(); this.birthStateCodeType = client.getBirthStateCodeType(); this.birthplaceVerifiedIndicator = cookBoolean(client.getBirthplaceVerifiedIndicator()); this.childClientIndicatorVar = cookBoolean(client.getChildClientIndicatorVar()); this.clientIndexNumber = client.getClientIndexNumber(); this.commentDescription = client.getCommentDescription(); this.commonFirstName = client.getCommonFirstName(); this.commonMiddleName = StringUtils.isBlank(client.getCommonMiddleName()) ? "" : client.getCommonMiddleName(); this.commonLastName = client.getCommonLastName(); this.confidentialityActionDate = uncookDateString(client.getConfidentialityActionDate()); this.confidentialityInEffectIndicator = cookBoolean(client.getConfidentialityInEffectIndicator()); this.creationDate = uncookDateString(client.getCreationDate()); this.currCaChildrenServIndicator = cookBoolean(client.getCurrCaChildrenServIndicator()); this.currentlyOtherDescription = client.getCurrentlyOtherDescription(); this.currentlyRegionalCenterIndicator = cookBoolean(client.getCurrentlyRegionalCenterIndicator()); this.deathDate = DomainChef.uncookDateString(client.getDeathDate()); this.deathDateVerifiedIndicator = cookBoolean(client.getDeathDateVerifiedIndicator()); this.deathPlace = client.getDeathPlace(); this.deathReasonText = client.getDeathReasonText(); this.driverLicenseNumber = client.getDriverLicenseNumber(); this.driverLicenseStateCodeType = client.getDriverLicenseStateCodeType(); this.emailAddress = client.getEmailAddress(); this.estimatedDobCode = client.getEstimatedDobCode(); this.ethUnableToDetReasonCode = StringUtils.isBlank(client.getEthUnableToDetReasonCode()) ? null : client.getEthUnableToDetReasonCode(); this.fatherParentalRightTermDate = uncookDateString(client.getFatherParentalRightTermDate()); this.genderCode = client.getGenderCode(); this.genderIdentityType = client.getGenderIdentityType(); this.giNotListedDescription = client.getGiNotListedDescription(); this.genderExpressionType = client.getGenderExpressionType(); this.healthSummaryText = client.getHealthSummaryText(); this.hispUnableToDetReasonCode = StringUtils.isBlank(client.getHispUnableToDetReasonCode()) ? null : client.getHispUnableToDetReasonCode(); this.hispanicOriginCode = StringUtils.isBlank(client.getHispanicOriginCode()) ? "" : client.getHispanicOriginCode(); this.immigrationCountryCodeType = client.getImmigrationCountryCodeType(); this.immigrationStatusType = client.getImmigrationStatusType(); this.incapacitatedParentCode = client.getIncapacitatedParentCode(); this.individualHealthCarePlanIndicator = cookBoolean(client.getIndividualHealthCarePlanIndicator()); this.limitationOnScpHealthIndicator = cookBoolean(client.getLimitationOnScpHealthIndicator()); this.literateCode = client.getLiterateCode(); this.maritalCohabitatnHstryIndicatorVar = cookBoolean(client.getMaritalCohabitatnHstryIndicatorVar()); this.maritalStatusType = client.getMaritalStatusType(); this.militaryStatusCode = client.getMilitaryStatusCode(); this.motherParentalRightTermDate = uncookDateString(client.getMotherParentalRightTermDate()); this.namePrefixDescription = client.getNamePrefixDescription(); this.nameType = client.getNameType(); this.outstandingWarrantIndicator = cookBoolean(client.getOutstandingWarrantIndicator()); this.prevCaChildrenServIndicator = cookBoolean(client.getPrevCaChildrenServIndicator()); this.prevOtherDescription = client.getPrevOtherDescription(); this.prevRegionalCenterIndicator = cookBoolean(client.getPrevRegionalCenterIndicator()); this.primaryEthnicityType = client.getPrimaryEthnicityType(); this.primaryLanguageType = client.getPrimaryLanguage(); this.religionType = client.getReligionType(); this.secondaryLanguageType = client.getSecondaryLanguage(); this.sensitiveHlthInfoOnFileIndicator = cookBoolean(client.getSensitiveHlthInfoOnFileIndicator()); this.sensitivityIndicator = client.getSensitivityIndicator(); this.sexualOrientationType = client.getSexualOrientationType(); this.soUnableToDetermineCode = client.getSoUnableToDetermineCode(); this.soNotListedDescrption = client.getSoNotListedDescrption(); this.soc158PlacementCode = client.getSoc158PlacementCode(); this.soc158SealedClientIndicator = cookBoolean(client.getSoc158SealedClientIndicator()); this.socialSecurityNumChangedCode = client.getSocialSecurityNumChangedCode(); this.socialSecurityNumber = StringUtils.isBlank(client.getSocialSecurityNumber()) ? "" : client.getSocialSecurityNumber(); this.suffixTitleDescription = client.getSuffixTitleDescription() == null ? "" : client.getSuffixTitleDescription(); this.tribalAncestryClientIndicatorVar = cookBoolean(client.getTribalAncestryClientIndicatorVar()); this.tribalMembrshpVerifctnIndicatorVar = cookBoolean(client.getTribalMembrshpVerifctnIndicatorVar()); this.unemployedParentCode = client.getUnemployedParentCode(); this.zippyCreatedIndicator = cookBoolean(client.getZippyCreatedIndicator()); } catch (ApiException e) { throw new PersistenceException(e); } }
From source file:org.appverse.web.framework.backend.persistence.services.integration.impl.live.JPAPersistenceService.java
@Override public long persist(final T bean) throws Exception { logger.trace(PersistenceMessageBundle.MSG_DAO_PERSIST); long beanId = -1; try {//from www . j a va2s . c o m beanId = (Long) PropertyUtils.getProperty(bean, this.BEAN_PK_NAME); } catch (final Exception ex) { logger.error(PersistenceMessageBundle.MSG_DAO_PERSIST_IDNOTFOUND, getClass().getName()); throw new PersistenceException(PersistenceMessageBundle.MSG_DAO_PERSIST_IDNOTFOUND); } if (beanId == 0) { // new em.persist(bean); beanId = (Long) PropertyUtils.getProperty(bean, this.BEAN_PK_NAME); } else { Object jpaProviderDelegate = em.getDelegate(); /* The following treatment is specific for Hibernate. * There is no problem with detached objects but at the moment that a JPA entity is attached to the * hibernate session, the version is cached. Does not matter that we override the cached version value * with the one coming from the business layer (the one kept in an object passed from a front end, * for instance, to check if the bean is stale or not) that the version kept when Hibernate generates the * update query is the one from the cache. * This implies that the version id's always match and so no OptimisticLockException is thrown. * EclipseLink handles this properly. Hibernate and JPA doc says that the application should not modify * the @Version annotated fields but in practice is quite common to retrieve an entity from the session * (it will be attached) and then override only the data that has been changed in the front end before * saving. * Even though detaching the object might have a small impact in performance we prefer to ensure that persist * method support properly JPA optimistic locking when JPA Provider is Hibernate. * The reason why we don't use "instance of" here is because depending on the Appverse Web persistence * module you are using (Hibernate or EclipseLink) you will have one classes or another but never both at * the same time, so using "instance of" is not a solution. * Another improvement that has been considered is to check if the annotation @Version is present * in one field or method of the class but this would imply using reflexion and visit every method * to see if the annotation is present or not. We think depending on the case this can affect performance * even more than detaching directly the object always before saving with Hibernate. */ if (jpaProviderDelegate.getClass().getName().contains("hibernate")) { em.detach(bean); } // update em.merge(bean); } PropertyUtils.setProperty(bean, this.BEAN_PK_NAME, beanId); return beanId; }
From source file:jef.database.DbUtils.java
/** * /* www.java 2 s.c o m*/ * * @param data * * @param pk * ?Map? */ public static void setPrimaryKeyValue(IQueryableEntity data, Object pk) throws PersistenceException { List<ColumnMapping> fields = MetaHolder.getMeta(data).getPKFields(); if (fields.isEmpty()) return; Assert.notNull(pk); // if (pk instanceof Map) { // Map<String, Object> pkMap = (Map<String, Object>) pk; // BeanWrapper wrapper = BeanWrapper.wrap(data, BeanWrapper.FAST); // for (Field f : fields) { // if (wrapper.isWritableProperty(f.name())) { // wrapper.setPropertyValue(f.name(), pkMap.get(f.name())); // } // } // } else if (pk.getClass().isArray()) { int length = Array.getLength(pk); int n = 0; Assert.isTrue(length == fields.size()); for (ColumnMapping f : fields) { f.getFieldAccessor().set(data, Array.get(pk, n++)); } } else { if (fields.size() != 1) { throw new PersistenceException("No Proper PK fields!"); } fields.get(0).getFieldAccessor().set(data, pk); } }
From source file:com.impetus.client.cassandra.CassandraClientBase.java
/** * Creates secondary indexes on columns if not already created. * //from www .j a va 2 s.c o m * @param m * the m * @param tableName * Column family name * @param columns * List of columns * @param columnType * the column type */ protected void createIndexesOnColumns(EntityMetadata m, String tableName, List<Column> columns, Class columnType) { Object pooledConnection = null; try { Cassandra.Client api = null; pooledConnection = getConnection(); api = (org.apache.cassandra.thrift.Cassandra.Client) getConnection(pooledConnection); KsDef ksDef = api.describe_keyspace(m.getSchema()); List<CfDef> cfDefs = ksDef.getCf_defs(); // Column family definition on which secondary index creation is // required CfDef columnFamilyDefToUpdate = null; boolean isUpdatable = false; for (CfDef cfDef : cfDefs) { if (cfDef.getName().equals(tableName)) { columnFamilyDefToUpdate = cfDef; break; } } if (columnFamilyDefToUpdate == null) { log.error("Join table {} not available.", tableName); throw new PersistenceException("table" + tableName + " not found!"); } // create a column family, in case it is not already available. // Get list of indexes already created List<ColumnDef> columnMetadataList = columnFamilyDefToUpdate.getColumn_metadata(); List<String> indexList = new ArrayList<String>(); if (columnMetadataList != null) { for (ColumnDef columnDef : columnMetadataList) { indexList.add(new StringAccessor().fromBytes(String.class, columnDef.getName())); } // need to set them to null else it is giving problem on update // column family and trying to add again existing indexes. // columnFamilyDefToUpdate.column_metadata = null; } // Iterate over all columns for creating secondary index on them for (Column column : columns) { ColumnDef columnDef = new ColumnDef(); columnDef.setName(column.getName()); columnDef.setValidation_class(CassandraValidationClassMapper.getValidationClass(columnType, false)); columnDef.setIndex_type(IndexType.KEYS); // Add secondary index only if it's not already created // (if already created, it would be there in column family // definition) if (!indexList.contains(new StringAccessor().fromBytes(String.class, column.getName()))) { isUpdatable = true; columnFamilyDefToUpdate.addToColumn_metadata(columnDef); } } // Finally, update column family with modified column family // definition if (isUpdatable) { columnFamilyDefToUpdate.setKey_validation_class(CassandraValidationClassMapper .getValidationClass(m.getIdAttribute().getJavaType(), isCql3Enabled(m))); api.system_update_column_family(columnFamilyDefToUpdate); } } catch (Exception e) { log.warn("Could not create secondary index on column family {}, Caused by: . ", tableName, e); } finally { releaseConnection(pooledConnection); } }
From source file:icom.jpa.bdk.dao.VersionSeriesToDocumentDAO.java
private Entity checkinPrivate(ManagedIdentifiableProxy representativeCopyOfVersionableObj, String versionName, VersionUpdater versionUpdater) { PersistenceContext context = representativeCopyOfVersionableObj.getPersistenceContext(); try {/*w w w. j av a 2 s . co m*/ String resource = "adoc/checkin"; BeeId representativeCopyOfVersionableId = getBeeId( representativeCopyOfVersionableObj.getObjectId().toString()); String collabId = representativeCopyOfVersionableId.getId(); String params = "version_name="; params += URLEncoder.encode(versionName, "UTF-8"); params += "&snapshotid="; String sid = representativeCopyOfVersionableObj.getChangeToken().toString(); params += sid; BdkUserContextImpl userContext = (BdkUserContextImpl) context.getUserContext(); Projection proj = Projection.FULL; PostMethod postMethod = preparePostMethod(resource, collabId, userContext.antiCSRF, proj, params); Entity bdkDocumentFamily = (Entity) bdkHttpUtil.execute(getBdkClass(representativeCopyOfVersionableObj), postMethod, versionUpdater, userContext.httpClient); ManagedIdentifiableProxy versionableObj = VersionDAO.getInstance().getEntityProxy(context, bdkDocumentFamily); assert (versionableObj == representativeCopyOfVersionableObj); // version series is updated through representativeCopyOfVersionableObj representativeCopyOfVersionableObj.checkReadyAndSetPooled(); representativeCopyOfVersionableObj.getProviderProxy() .copyLoadedProjection(representativeCopyOfVersionableObj, bdkDocumentFamily, proj); return bdkDocumentFamily; } catch (Exception ex) { throw new PersistenceException(ex); } }
From source file:icom.jpa.bdk.dao.EntityDAO.java
public void concludeUpdateAccessControlFields(ManagedIdentifiableProxy obj, DAOContext context) { try {/*www . j av a 2 s.com*/ BdkUserContextImpl userContext = (BdkUserContextImpl) obj.getPersistenceContext().getUserContext(); BeeId id = getBeeId(obj.getObjectId().toString()); String collabId = id.getId(); String resourceType = id.getResourceType(); PutMethod putMethod = preparePutMethod(resourceType + "/ac", collabId, userContext.antiCSRF, Projection.EMPTY); AccessControlFieldsUpdater updater = (AccessControlFieldsUpdater) context.getUpdater(); bdkHttpUtil.execute(AccessControlFields.class, putMethod, updater, userContext.httpClient); } catch (Exception ex) { throw new PersistenceException(ex); } }
From source file:icom.jpa.bdk.dao.EmailMessageDAO.java
public Entity concludeUpdateObject(ManagedIdentifiableProxy obj, DAOContext context, Projection proj) { EntityUpdater updater = (EntityUpdater) context.getUpdater(); try {/*from ww w. ja va2 s . co m*/ BdkUserContextImpl userContext = (BdkUserContextImpl) obj.getPersistenceContext().getUserContext(); BeeId id = getBeeId(obj.getObjectId().toString()); String resourceType = id.getResourceType(); PutMethod putMethod = null; if (updater instanceof EmailMessageUpdater) { String collabId = id.getId(); Object changeToken = obj.getChangeToken(); String snapshotId = changeToken.toString(); String params = "snapshotid=" + snapshotId; putMethod = preparePutMethod(resourceType, collabId, userContext.antiCSRF, proj, params); } else if (updater instanceof EmailDraftUpdater) { // Not supported } 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); } }
From source file:icom.jpa.bdk.dao.EmailMessageDAO.java
public Entity concludeCreateObject(ManagedIdentifiableProxy obj, DAOContext context, Projection proj) { EmailDraftUpdater emailDraftUpdater = (EmailDraftUpdater) context.getUpdater(); try {//from w w w. jav a2 s .c o m BdkUserContextImpl userContext = (BdkUserContextImpl) obj.getPersistenceContext().getUserContext(); BeeId id = getBeeId(obj.getObjectId().toString()); String resourceType = id.getResourceType(); resourceType += "/append"; Persistent pojoUnifiedMessage = obj.getPojoIdentifiable(); Persistent pojoParentFolder = getParent(pojoUnifiedMessage); if (pojoParentFolder == null) { throw new PersistenceException("Must specify parent folder for draft message"); } BeeId folderId = getBeeId(((ManagedIdentifiableProxy) (pojoParentFolder.getManagedObjectProxy())) .getObjectId().toString()); String params = "folder=" + folderId; Date receivedDate = (Date) getAttributeValue(pojoUnifiedMessage, MessageInfo.Attributes.deliveredTime.name()); if (receivedDate != null) { SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); String formatedDate = format.format(receivedDate); params += "&received_date=" + formatedDate; } String uploadScopeId = context.getUploadScopeId(); if (uploadScopeId != null) { params += "&uploadscope=scope" + uploadScopeId; } PostMethod postMethod = preparePostMethod(resourceType, userContext.antiCSRF, proj, params); Entity bdkEntity = (Entity) bdkHttpUtil.execute(getBdkClass(obj), postMethod, emailDraftUpdater, userContext.httpClient); String objectId = bdkEntity.getCollabId().getId(); obj.setObjectId(objectId); assignObjectId(obj.getPojoIdentifiable(), objectId); if (proj != Projection.EMPTY) { String changeToken = bdkEntity.getSnapshotId(); assignChangeToken(obj.getPojoIdentifiable(), changeToken); } assignEnumConstant(obj.getPojoObject(), UnifiedMessageInfo.Attributes.editMode.name(), BeanHandler.getBeanPackageName(), IcomBeanEnumeration.UnifiedMessageEditModeEnum.name(), MessageMode.DraftCopy.name()); // re-cache the object with the server assigned id // the server may assign a new object id rather than use the client assigned id obj.getPersistenceContext().recacheIdentifiableDependent(obj); return bdkEntity; } catch (Exception ex) { throw new PersistenceException(ex); } }
From source file:com.impetus.client.oraclenosql.OracleNoSQLClient.java
/** * Find by relational column name and value. * /*from w ww . j a v a2 s.c om*/ * @param colName * the col name * @param colValue * the col value * @param entityClazz * the entity clazz * @return the list */ @Override public List<Object> findByRelation(String colName, Object colValue, Class entityClazz) { // find by relational value ! EntityMetadata entityMetadata = KunderaMetadataManager.getEntityMetadata(kunderaMetadata, entityClazz); MetamodelImpl metamodel = (MetamodelImpl) KunderaMetadataManager.getMetamodel(kunderaMetadata, entityMetadata.getPersistenceUnit()); EntityType entityType = metamodel.entity(entityMetadata.getEntityClazz()); Table schemaTable = tableAPI.getTable(entityMetadata.getTableName()); Iterator<Row> rowsIter = null; if (schemaTable.getPrimaryKey().contains(colName)) { PrimaryKey rowKey = schemaTable.createPrimaryKey(); NoSqlDBUtils.add(schemaTable.getField(colName), rowKey, colValue, colName); rowsIter = tableAPI.tableIterator(rowKey, null, null); } else { Index index = schemaTable.getIndex(colName); IndexKey indexKey = index.createIndexKey(); NoSqlDBUtils.add(schemaTable.getField(colName), indexKey, colValue, colName); rowsIter = tableAPI.tableIterator(indexKey, null, null); } try { Map<String, Object> relationMap = initialize(entityMetadata); return scrollAndPopulate(null, entityMetadata, metamodel, schemaTable, rowsIter, relationMap, null); } catch (Exception e) { log.error("Error while finding data for Key " + colName + ", Caused By :" + e + "."); throw new PersistenceException(e); } }
From source file:org.appverse.web.framework.backend.persistence.services.integration.impl.live.JPAPersistenceService.java
@Override public T retrieve(final long pk) throws Exception { final Class<T> classP = getClassP(); logger.trace(PersistenceMessageBundle.MSG_DAO_RETRIEVEBYPK, new Object[] { classP, this.BEAN_PK_NAME }); try {//from w w w. j a va 2 s.c om return em.find(classP, pk); } catch (final Exception e) { logger.error(PersistenceMessageBundle.MSG_DAO_RETRIEVEBYPK_ERROR, new Object[] { classP, this.BEAN_PK_NAME }); logger.error(PersistenceMessageBundle.MSG_DAO_RETRIEVEBYPK_ERROR, e); throw new PersistenceException(PersistenceMessageBundle.MSG_DAO_RETRIEVEBYPK_ERROR + this.BEAN_PK_NAME); } }