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.cassandra.pelops.PelopsClient.java
/** * Find.// w ww .ja v a 2 s . c o m * * @param ixClause * the ix clause * @param m * the m * @param isRelation * the is relation * @param relations * the relations * @return the list */ public List find(List<IndexClause> ixClause, EntityMetadata m, boolean isRelation, List<String> relations, int maxResult) { // ixClause can be 0,1 or more! Selector selector = Pelops.createSelector(PelopsUtils.generatePoolName(getPersistenceUnit())); SlicePredicate slicePredicate = Selector.newColumnsPredicateAll(false, Integer.MAX_VALUE); List<Object> entities = null; if (ixClause.isEmpty()) { if (m.isCounterColumnType()) { IThriftPool thrift = Pelops.getDbConnPool(PelopsUtils.generatePoolName(getPersistenceUnit())); // thrift.get IPooledConnection connection = thrift.getConnection(); org.apache.cassandra.thrift.Cassandra.Client thriftClient = connection.getAPI(); try { List<KeySlice> ks = thriftClient.get_range_slices(new ColumnParent(m.getTableName()), slicePredicate, selector.newKeyRange("", "", maxResult), consistencyLevel); if (m.getType().isSuperColumnFamilyMetadata()) { Map<Bytes, List<CounterSuperColumn>> qCounterSuperColumnResults = ColumnOrSuperColumnHelper .transformKeySlices(ks, ColumnOrSuperColumnHelper.COUNTER_SUPER_COLUMN); entities = new ArrayList<Object>(qCounterSuperColumnResults.size()); populateDataForSuperCounter(m, qCounterSuperColumnResults, entities, isRelation, relations); } else { Map<Bytes, List<CounterColumn>> qCounterColumnResults = ColumnOrSuperColumnHelper .transformKeySlices(ks, ColumnOrSuperColumnHelper.COUNTER_COLUMN); entities = new ArrayList<Object>(qCounterColumnResults.size()); populateDataForCounter(m, qCounterColumnResults, entities, isRelation, relations); } } catch (InvalidRequestException irex) { log.error("Error during executing find, Caused by :" + irex.getMessage()); throw new PersistenceException(irex); } catch (UnavailableException uex) { log.error("Error during executing find, Caused by :" + uex.getMessage()); throw new PersistenceException(uex); } catch (TimedOutException tex) { log.error("Error during executing find, Caused by :" + tex.getMessage()); throw new PersistenceException(tex); } catch (TException tex) { log.error("Error during executing find, Caused by :" + tex.getMessage()); throw new PersistenceException(tex); } } else { Map<Bytes, List<Column>> qResults = selector.getColumnsFromRows(m.getTableName(), selector.newKeyRange("", "", maxResult), slicePredicate, consistencyLevel); // selector.getCounterColumnsFromRows(m.getTableName(), // selector.newKeyRange("", "", maxResult), slicePredicate, // consistencyLevel); // selector.getCounterColumnsFromRows entities = new ArrayList<Object>(qResults.size()); populateData(m, qResults, entities, isRelation, relations); } } else { entities = new ArrayList<Object>(); for (IndexClause ix : ixClause) { Map<Bytes, List<Column>> qResults = selector.getIndexedColumns(m.getTableName(), ix, slicePredicate, consistencyLevel); // iterate through complete map and populateData(m, qResults, entities, isRelation, relations); } } return entities; }
From source file:icom.jpa.bdk.dao.EntityDAO.java
public AccessControlFields loadAccessControlFields(ManagedIdentifiableProxy obj) { BeeId id = getBeeId(obj.getObjectId().toString()); String collabId = id.getId(); String resourceType = id.getResourceType(); GetMethod method = prepareGetMethod(resourceType + "/ac", collabId, null); PersistenceContext context = obj.getPersistenceContext(); try {//from w ww .j av a 2 s . c o m BdkUserContextImpl userContext = (BdkUserContextImpl) context.getUserContext(); AccessControlFields bdkAccessControlFields = (AccessControlFields) bdkHttpUtil .execute(AccessControlFields.class, method, userContext.httpClient); return bdkAccessControlFields; } catch (Exception ex) { throw new PersistenceException(ex); } }
From source file:icom.jpa.bdk.dao.VersionSeriesToDocumentDAO.java
public void cancelCheckout(ManagedIdentifiableProxy representativeCopyOfVersionableObj) { PersistenceContext context = representativeCopyOfVersionableObj.getPersistenceContext(); try {//from ww w . jav a 2 s. co m String resource = "adoc/checkout/cancel"; BeeId representativeCopyOfVersionableId = getBeeId( representativeCopyOfVersionableObj.getObjectId().toString()); String collabId = representativeCopyOfVersionableId.getId(); String 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, userContext.httpClient); // version series is updated through representativeCopyOfVersionableObj representativeCopyOfVersionableObj.checkReadyAndSetPooled(); representativeCopyOfVersionableObj.getProviderProxy() .copyLoadedProjection(representativeCopyOfVersionableObj, bdkDocumentFamily, proj); } catch (Exception ex) { throw new PersistenceException(ex); } }
From source file:com.impetus.client.rdbms.query.RDBMSEntityReader.java
@Override public EnhanceEntity findById(Object primaryKey, EntityMetadata m, Client client) { List<String> relationNames = m.getRelationNames(); if (relationNames != null && !relationNames.isEmpty()) { Set<String> keys = new HashSet<String>(1); keys.add(primaryKey.toString()); String query = getSqlQueryFromJPA(m, relationNames, keys); List<EnhanceEntity> results = populateEnhanceEntities(m, relationNames, client, query); return results != null && !results.isEmpty() ? results.get(0) : null; } else {/*from ww w. ja v a 2 s.c om*/ Object o; try { o = client.find(m.getEntityClazz(), primaryKey); } catch (Exception e) { throw new PersistenceException(e); } return o != null ? new EnhanceEntity(o, getId(o, m), null) : null; } // return super.findById(primaryKey, m, client); }
From source file:icom.jpa.bdk.dao.EntityDAO.java
public void copyAccessControlFields(ManagedObjectProxy obj, AccessControlFields bdkAccessControlFields) { PersistenceContext context = obj.getPersistenceContext(); Persistent pojoEntity = obj.getPojoObject(); try {/*from w w w. j a v a 2 s .c om*/ BeeId accessorId = bdkAccessControlFields.getOwner(); if (accessorId != null) { String collabId = accessorId.getId(); String resourceType = accessorId.getResourceType(); BdkUserContextImpl userContext = (BdkUserContextImpl) context.getUserContext(); GetMethod method = prepareGetMethod(resourceType, collabId, Projection.EMPTY); Accessor bdkAccessor = (Accessor) bdkHttpUtil.execute(Accessor.class, method, userContext.httpClient); ManagedIdentifiableProxy ownerObj = getEntityProxy(context, bdkAccessor); Persistent pojoOwner = ownerObj.getPojoIdentifiable(); assignAttributeValue(pojoEntity, EntityInfo.Attributes.owner.name(), pojoOwner); } } catch (Exception ex) { throw new PersistenceException(ex); } try { List<Ace> aceSet = bdkAccessControlFields.getLocalACLs(); if (aceSet != null) { ManagedObjectProxy accessControlListObj = getNonIdentifiableDependentProxy(context, IcomBeanEnumeration.AccessControlList.name(), obj, EntityInfo.Attributes.accessControlList.name()); accessControlListObj.getProviderProxy().copyLoadedProjection(accessControlListObj, aceSet, Projection.SECURITY); Persistent pojoAccessControlList = accessControlListObj.getPojoObject(); assignAttributeValue(pojoEntity, EntityInfo.Attributes.accessControlList.name(), pojoAccessControlList); } } catch (Exception ex) { throw new PersistenceException(ex); } }
From source file:icom.jpa.bdk.dao.SimpleContentDAO.java
void updateObjectStateForDiscussionMessage(ManagedObjectProxy obj, DAOContext context) { SimpleContentUpdater updater = (SimpleContentUpdater) context.getUpdater(); Persistent pojoIdentifiable = obj.getPojoObject(); String characterEncoding = (String) getAttributeValue(pojoIdentifiable, SimpleContentInfo.Attributes.characterEncoding.name()); if ((obj.isNew() && characterEncoding != null) || isChanged(obj, SimpleContentInfo.Attributes.characterEncoding.name())) { updater.setCharacterEncoding(characterEncoding); }/*from www . j a va2 s . co m*/ Locale contentLanguage = (Locale) getAttributeValue(pojoIdentifiable, SimpleContentInfo.Attributes.contentLanguage.name()); if ((obj.isNew() && contentLanguage != null) || isChanged(obj, SimpleContentInfo.Attributes.contentLanguage.name())) { updater.setContentLanguage(contentLanguage.getDisplayName()); } String contentEncoding = (String) getAttributeValue(pojoIdentifiable, SimpleContentInfo.Attributes.contentEncoding.name()); if ((obj.isNew() && contentEncoding != null) || isChanged(obj, SimpleContentInfo.Attributes.contentEncoding.name())) { //updater.setContentEncoding(ContentEncodingType.EIGHT_BIT); //TODO } if (obj.isNew() || isChanged(obj, SimpleContentInfo.Attributes.contentBody.name())) { updater.setPiecewiseUpdate(false); try { ContentStreamTrait cos = (ContentStreamTrait) getAttributeValue(pojoIdentifiable, SimpleContentInfo.Attributes.contentBody.name()); InputStream fis = null; if (cos != null) { fis = cos.getFileInputStream(); } if (fis != null) { try { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); byte[] data = new byte[ContentStreamTrait.dataSize]; int num = 0; do { num = fis.read(data); if (num != -1) { buffer.write(data, 0, num); } } while (num != -1); byte[] alldata = buffer.toByteArray(); updater.setContentBytes(alldata); } finally { fis.close(); } } } catch (IOException ex) { throw new PersistenceException(ex); } } }
From source file:icom.jpa.bdk.dao.VersionSeriesToDocumentDAO.java
public Entity checkoutPrivate(ManagedIdentifiableProxy representativeCopyOfVersionableObj, String checkoutComments) { PersistenceContext context = representativeCopyOfVersionableObj.getPersistenceContext(); try {//w w w. j a va2s . c o m String resource = "adoc/checkout"; BeeId representativeCopyOfVersionableId = getBeeId( representativeCopyOfVersionableObj.getObjectId().toString()); String collabId = representativeCopyOfVersionableId.getId(); String params = "checkout_comments="; params += URLEncoder.encode(checkoutComments, "UTF-8"); Object changeToken = representativeCopyOfVersionableObj.getChangeToken(); if (changeToken != null) { params += "&snapshotid="; String sid = changeToken.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, 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:org.appverse.web.framework.backend.persistence.services.integration.impl.live.JPAPersistenceService.java
@SuppressWarnings("unchecked") private Class<T> getClassP() throws PersistenceException { Class<T> classP = null; final Type type = this.getClass().getGenericSuperclass(); if (type instanceof ParameterizedType) { final ParameterizedType pType = (ParameterizedType) type; if (pType.getActualTypeArguments()[0] instanceof Class) { classP = (Class<T>) pType.getActualTypeArguments()[0]; } else { logger.error(PersistenceMessageBundle.MSG_DAO_RETRIEVEBY_ERROR_PARAMETERTYPE, this.getClass()); throw new PersistenceException(this.getClass().getSimpleName() + PersistenceMessageBundle.MSG_DAO_RETRIEVEBY_ERROR_PARAMETERTYPE); }/*from ww w . j a v a2 s. c om*/ } else { logger.error(PersistenceMessageBundle.MSG_DAO_RETRIEVEBY_ERROR_PARAMETERPATTERN, this.getClass()); throw new PersistenceException( this.getClass() + PersistenceMessageBundle.MSG_DAO_RETRIEVEBY_ERROR_PARAMETERPATTERN); } return classP; }
From source file:com.impetus.kundera.utils.KunderaCoreUtils.java
/** * @param clazz// www . java 2 s .c om * @return */ public static Object createNewInstance(Class clazz) { Object target = null; try { Constructor[] constructors = clazz.getDeclaredConstructors(); for (Constructor constructor : constructors) { if ((Modifier.isProtected(constructor.getModifiers()) || Modifier.isPublic(constructor.getModifiers())) && constructor.getParameterTypes().length == 0) { constructor.setAccessible(true); target = constructor.newInstance(); constructor.setAccessible(false); break; } } return target; } catch (InstantiationException iex) { logger.error("Error while creating an instance of {} .", clazz); throw new PersistenceException(iex); } catch (IllegalAccessException iaex) { logger.error("Illegal Access while reading data from {}, Caused by: .", clazz, iaex); throw new PersistenceException(iaex); } catch (Exception e) { logger.error("Error while creating an instance of {}, Caused by: .", clazz, e); throw new PersistenceException(e); } }
From source file:com.impetus.client.cassandra.CassandraClientBase.java
/** * Deletes record for given primary key from counter column family. * /* ww w.j a va 2 s .co m*/ * @param pKey * the key * @param tableName * the table name * @param metadata * the metadata * @param consistencyLevel * the consistency level */ protected void deleteRecordFromCounterColumnFamily(Object pKey, String tableName, EntityMetadata metadata, ConsistencyLevel consistencyLevel) { ColumnPath path = new ColumnPath(tableName); Cassandra.Client conn = null; Object pooledConnection = null; try { pooledConnection = getConnection(); conn = (org.apache.cassandra.thrift.Cassandra.Client) getConnection(pooledConnection); if (log.isInfoEnabled()) { log.info("Removing data for counter column family {}.", tableName); } conn.remove_counter((CassandraUtilities.toBytes(pKey, metadata.getIdAttribute().getJavaType())), path, consistencyLevel); } catch (Exception e) { log.error("Error during executing delete, Caused by: .", e); throw new PersistenceException(e); } finally { releaseConnection(pooledConnection); } }