List of usage examples for javax.persistence PersistenceException PersistenceException
public PersistenceException(Throwable cause)
PersistenceException
exception with the specified cause. From source file:com.impetus.kundera.client.PelopsClient.java
@Override public final void writeColumns(String keyspace, String columnFamily, String rowId, List<EntityMetadata.Column> columns, EnhancedEntity e) throws Exception { if (!isOpen()) { throw new PersistenceException("PelopsClient is closed."); }/*ww w .jav a 2 s . co m*/ PelopsClient.ThriftRow tf = toThriftRow(e, columns, columnFamily); Mutator mutator = Pelops.createMutator(poolName, keyspace); mutator.writeColumns(tf.getId(), columnFamily, Arrays.asList(tf.getColumns().toArray(new Column[0]))); mutator.execute(ConsistencyLevel.ONE); }
From source file:com.openmeap.model.ModelServiceImpl.java
@Override public <T extends ModelEntity> T saveOrUpdate(T entity) throws PersistenceException { T entityToReturn = entity;/*from w w w . j av a 2 s. c o m*/ try { // if we haven't loaded this object yet, // then attempt to do so if (!entityManager.contains(entity)) { entityToReturn = entityManager.merge(entity); } entityManager.persist(entityToReturn); } catch (PersistenceException pe) { throw new PersistenceException(pe); } return entityToReturn; }
From source file:com.impetus.kundera.ejb.EntityManagerFactoryBuilder.java
/** * Gets the persistence metadata./*from w w w.j a v a 2 s . c o m*/ * * @param persistenceUnitName * the persistence unit name * @return the persistence metadata */ private PersistenceMetadata getPersistenceMetadata(String persistenceUnitName) { log.info("Look up for persistence unit: " + persistenceUnitName); List<PersistenceMetadata> metadatas = findPersistenceMetadatas(); // If there is just ONE persistenceUnit, then use this irrespective of the name if (metadatas.size() == 1) { return metadatas.get(0); } // Since there is more persistenceUnits, you must provide a name to look up if (isEmpty(persistenceUnitName)) { throw new PersistenceException("No name provided and several persistence units found"); } // Look for one that interests us for (PersistenceMetadata metadata : metadatas) { if (metadata.getName().equals(persistenceUnitName)) { return metadata; } } throw new PersistenceException( "Could not find persistence unit in the classpath for name: " + persistenceUnitName); }
From source file:com.nortal.petit.beanmapper.BeanMappingFactoryImpl.java
@Override public <B> BeanMapping<B> create(Class<B> type) { Map<String, Property<B, Object>> props = new LinkedHashMap<String, Property<B, Object>>(); List<Property<B, Object>> idProps = new ArrayList<Property<B, Object>>(); initProps(props, idProps, type);/*ww w. j a va 2s. c o m*/ if (idProps.size() > 1) { throw new PersistenceException("Multiple primary keys @Id defined for model " + type.getSimpleName()); } SimpleBeanMapping<B> m = new SimpleBeanMapping<B>(type, inferTable(type), props); if (idProps.size() == 1) { m.id(idProps.get(0)); } return m; }
From source file:com.impetus.kundera.ejb.EntityManagerImpl.java
@Override public final <E> E find(Class<E> entityClass, Object primaryKey) { if (closed) { throw new PersistenceException("EntityManager already closed."); }//from w ww .ja v a 2s. c om if (primaryKey == null) { throw new IllegalArgumentException("primaryKey value must not be null."); } // Validate metadataManager.validate(entityClass); E e = null; e = session.lookup(entityClass, primaryKey); if (null != e) { log.debug(entityClass.getName() + "_" + primaryKey + " is loaded from cache!"); return e; } return immediateLoadAndCache(entityClass, primaryKey); }
From source file:com.impetus.kundera.client.PelopsClient.java
@Override public void writeColumns(EntityManagerImpl em, EnhancedEntity e, EntityMetadata m) throws Exception { throw new PersistenceException("Not yet implemented"); }
From source file:com.openmeap.model.ModelServiceImpl.java
@Override public <T extends ModelEntity> void refresh(T entity) throws PersistenceException { int numRetries = numberOfRefreshRetries; boolean notSuccessful = false; do {//from www .j av a 2s. com try { if (entity != null) { this._refresh(entity); } } catch (Exception e) { Throwable t = ExceptionUtils.getRootCause(e); if (!(t instanceof SQLException)) { throw new PersistenceException(e); } logger.warn("Unable to refresh model entity, " + numRetries + " left. " + t.getMessage()); numRetries--; notSuccessful = true; try { Thread.sleep(refreshRetryInterval); } catch (InterruptedException e1) { throw new PersistenceException( "Thread sleep interrupted during the refresh retry interval: " + e1.getMessage(), e1); } } } while (notSuccessful && numRetries != 0); if (numRetries == 0) { throw new PersistenceException( "Unable to refresh model entity. " + numberOfRefreshRetries + " retries failed"); } }
From source file:icom.jpa.bdk.dao.PresenceDAO.java
void loadPresenceOnWatchable(ManagedIdentifiableProxy watchableObj, Projection projection, String parentAttributeName) { PersistenceContext context = watchableObj.getPersistenceContext(); BeeId watchableObjId = getBeeId(watchableObj.getObjectId().toString()); String collabId = watchableObjId.getId(); String resourceType = "presence"; Persistent pojoPresence = null;/*from w ww.j a va2 s.com*/ try { BdkUserContextImpl userContext = (BdkUserContextImpl) context.getUserContext(); GetMethod method = prepareGetMethod(resourceType, collabId, projection); Presence bdkPresence = (Presence) bdkHttpUtil.execute(Presence.class, method, userContext.httpClient); ManagedIdentifiableProxy presenceObj = getEntityProxy(context, bdkPresence); pojoPresence = presenceObj.getPojoIdentifiable(); presenceObj.getProviderProxy().copyLoadedProjection(presenceObj, bdkPresence, projection); } catch (Exception ex) { throw new PersistenceException(ex); } watchableObj.getProviderProxy().copyLazyAttribute(watchableObj, parentAttributeName, null, pojoPresence); }
From source file:com.impetus.kundera.utils.KunderaCoreUtils.java
/** * Prepares composite key .//from w w w.j a v a2 s .c o m * * @param m * entity metadata * @param compositeKey * composite key instance * @return redis key */ public static String prepareCompositeKey(final EntityMetadata m, final Object compositeKey) { Field[] fields = m.getIdAttribute().getBindableJavaType().getDeclaredFields(); StringBuilder stringBuilder = new StringBuilder(); for (Field f : fields) { if (!ReflectUtils.isTransientOrStatic(f)) { try { String fieldValue = PropertyAccessorHelper.getString(compositeKey, f); // what if field value is null???? stringBuilder.append(fieldValue); stringBuilder.append(COMPOSITE_KEY_SEPERATOR); } catch (IllegalArgumentException e) { logger.error("Error during prepare composite key, Caused by {}.", e); throw new PersistenceException(e); } } } if (stringBuilder.length() > 0) { stringBuilder.deleteCharAt(stringBuilder.lastIndexOf(COMPOSITE_KEY_SEPERATOR)); } return stringBuilder.toString(); }
From source file:com.impetus.kundera.client.PelopsClient.java
@Override public final void writeSuperColumns(String keyspace, String columnFamily, String rowId, SuperColumn... superColumns) throws Exception { if (!isOpen()) { throw new PersistenceException("PelopsClient is closed."); }/* w ww .j av a 2 s. c om*/ Mutator mutator = Pelops.createMutator(poolName, keyspace); for (SuperColumn sc : superColumns) { mutator.writeSubColumns(rowId, columnFamily, sc.getName(), sc.getColumns()); } mutator.execute(ConsistencyLevel.ONE); }