List of usage examples for javax.persistence PersistenceException PersistenceException
public PersistenceException(String message, Throwable cause)
PersistenceException
exception with the specified detail message and cause. From source file:com.netflix.paas.dao.astyanax.AstyanaxDao.java
@Override public Collection<String> listIds() throws PersistenceException { final List<String> ids = Lists.newArrayList(); try {/* w w w . ja v a 2 s .co m*/ new AllRowsReader.Builder<String, String>(keyspace, columnFamily).withIncludeEmptyRows(false) .forEachRow(new Function<Row<String, String>, Boolean>() { @Override public Boolean apply(Row<String, String> row) { ids.add(row.getKey()); return true; } }).build().call(); } catch (Exception e) { throw new PersistenceException("Error trying to fetch row ids", e); } return ids; }
From source file:com.nortal.petit.orm.statement.InsertStatement.java
@Override public void exec() { prepare();//w w w.j av a 2s. co m if (!CollectionUtils.isEmpty(getBeans())) { if (getMapping().id() == null) { execBatchUpdate(); } else { final KeyHolder keyHolder = new GeneratedKeyHolder(); final InterceptorCalls interceptorCalls = new InterceptorCalls(); getJdbcTemplate().execute(new PreparedStatementCreator() { @Override public PreparedStatement createPreparedStatement(Connection con) throws SQLException { return con.prepareStatement(getSql(), Statement.RETURN_GENERATED_KEYS); } }, new PreparedStatementCallback<Object>() { @Override public Object doInPreparedStatement(PreparedStatement ps) throws SQLException, DataAccessException { MappingParamFunction<B> paramFunction = new MappingParamFunction<B>(getMapping()); for (B bean : getBeans()) { paramFunction.setBean(bean); Object[] params = getParams(paramFunction); Object[] queryParams = params.length == 1 && params[0] instanceof Object[] ? (Object[]) params[0] : params; interceptorCalls.setBeanValues(bean, queryParams); ArgPreparedStatementSetter.setValues(ps, queryParams, 1); ps.executeUpdate(); extractKeys(ps); } return null; } /** * @param ps * @throws SQLException */ private void extractKeys(PreparedStatement ps) throws SQLException { ResultSet keys = ps.getGeneratedKeys(); if (keys != null) { try { RowMapperResultSetExtractor<Map<String, Object>> rse = new RowMapperResultSetExtractor<Map<String, Object>>( new ColumnMapRowMapper(), 1); keyHolder.getKeyList().addAll(rse.extractData(keys)); } finally { JdbcUtils.closeResultSet(keys); } } } }); try { Property<B, Object> idProperty = getMapping().id(); for (int i = 0; i < getBeans().size(); i++) { B bean = getBeans().get(i); Object key = keyHolder.getKeyList().get(i).get(idProperty.column()); idProperty.write(bean, key); interceptorCalls.setBeanId(bean, key); } } catch (Exception e) { throw new PersistenceException("InsertStatement.exec: unable to write bean primary key", e); } interceptorCalls.callInterceptor(); } } else { getJdbcTemplate().update(getSql(), getParams(null)); } }
From source file:com.impetus.client.cassandra.query.ResultIterator.java
/** * on check relation event, invokes populate entities and set relational * entities, in case relations are present. *///w w w. j a va 2s .co m private void onCheckRelation() { try { results = populateEntities(entityMetadata, client); if (entityMetadata.isRelationViaJoinTable() || (entityMetadata.getRelationNames() != null && !(entityMetadata.getRelationNames().isEmpty()))) { query.setRelationalEntities(results, client, entityMetadata); } } catch (Exception e) { throw new PersistenceException("Error while scrolling over results, Caused by :.", e); } }
From source file:jef.database.DbUtils.java
/** * ?OrderBy/*ww w . j ava 2 s. c o m*/ * * @param sql * @return * @throws ParseException */ public static OrderBy parseOrderBy(String sql) { StSqlParser parser = new StSqlParser(new StringReader("ORDER BY " + sql)); try { return parser.OrderByElements(); } catch (ParseException e) { throw new PersistenceException(sql, e); } }
From source file:com.impetus.client.oraclenosql.OracleNoSQLClient.java
/** * Execute./* w w w . j a v a2s . c o m*/ * * @param batches * the batches */ private void execute(Map<Key, List<TableOperation>> batches) { if (batches != null && !batches.isEmpty()) { try { for (List<TableOperation> batch : batches.values()) { tableAPI.execute(batch, null); } } catch (DurabilityException e) { log.error("Error while executing operations in OracleNOSQL, Caused by:" + e + "."); throw new PersistenceException("Error while Persisting data using batch", e); } catch (TableOpExecutionException e) { log.error("Error while executing operations in OracleNOSQL, Caused by:" + e + "."); throw new PersistenceException("Error while Persisting data using batch", e); } catch (FaultException e) { log.error("Error while executing operations in OracleNOSQL, Caused by:" + e + "."); throw new PersistenceException("Error while Persisting data using batch", e); } finally { batches.clear(); } } }
From source file:com.impetus.kundera.utils.KunderaCoreUtils.java
/** * Initialize.//from w w w . j av a2 s . c o m * * @param tr * the tr * @param m * the m * @param entity * the entity * @param tr * @return the object * @throws InstantiationException * the instantiation exception * @throws IllegalAccessException * the illegal access exception */ public static Object initialize(EntityMetadata m, Object entity, Object id) { try { if (entity == null) { entity = createNewInstance(m.getEntityClazz()); } if (id != null) { PropertyAccessorHelper.setId(entity, m, id); } return entity; } catch (Exception e) { throw new PersistenceException("Error occured while instantiating entity.", e); } }
From source file:com.impetus.kundera.utils.KunderaCoreUtils.java
/** * Initialize.//from www . j a v a 2 s.c om * * @param tr * the tr * @param m * the m * @param entity * the entity * @param tr * @return the object * @throws InstantiationException * the instantiation exception * @throws IllegalAccessException * the illegal access exception */ public static Object initialize(Class clazz, Object record) { try { if (record == null) { record = createNewInstance(clazz); } return record; } catch (Exception e) { throw new PersistenceException("Error occured while instantiating entity.", e); } }
From source file:org.appverse.web.framework.backend.persistence.services.integration.impl.live.JPAPersistenceService.java
@Override public T retrieve(final IntegrationDataFilter filter) throws Exception { logger.trace(PersistenceMessageBundle.MSG_DAO_RETRIEVEFILTERED, new Object[] { getClassP(), filter }); try {/*from w w w . j a v a 2 s .c o m*/ final StringBuilder queryString = buildQueryString(filter); final QueryJpaCallback<T> query = new QueryJpaCallback<T>(queryString.toString()); if (filter != null) { query.setIndexedParameters(filter.getValues().toArray()); if (filter instanceof IntegrationPaginatedDataFilter) { IntegrationPaginatedDataFilter iFilter = (IntegrationPaginatedDataFilter) filter; query.setFirstResult(iFilter.getOffset()); query.setMaxRecords(iFilter.getLimit()); } } return query.doInJpaSingleResult(em); } catch (final Exception e) { logger.error(PersistenceMessageBundle.MSG_DAO_RETRIEVEFILTERED_ERROR, new Object[] { filter.toString(), getClassP() }); throw new PersistenceException(PersistenceMessageBundle.MSG_DAO_RETRIEVEFILTERED_ERROR_P1 + filter.toString() + PersistenceMessageBundle.MSG_DAO_RETRIEVEFILTERED_ERROR_P2 + getClassP(), e); } }
From source file:com.impetus.client.neo4j.GraphEntityMapper.java
/** * /*from w w w .j a v a 2s. c o m*/ * @param m * @param entity * @param id * @return */ private Object initialize(EntityMetadata m, Object entity) { try { if (entity == null) { entity = KunderaCoreUtils.createNewInstance(m.getEntityClazz()); } return entity; } catch (Exception e) { throw new PersistenceException("Error occured while instantiating entity, Caused by : ", e); } }
From source file:org.appverse.web.framework.backend.persistence.services.integration.impl.live.JPAPersistenceService.java
@Override public List<T> retrieveList(final IntegrationDataFilter filter) throws Exception { logger.trace(PersistenceMessageBundle.MSG_DAO_RETRIEVEFILTERED, new Object[] { getClassP(), filter }); try {//w w w. jav a 2 s .c o m final StringBuilder queryString = buildQueryString(filter); final QueryJpaCallback<T> query = new QueryJpaCallback<T>(queryString.toString()); if (filter != null) { query.setIndexedParameters(filter.getValues().toArray()); if (filter instanceof IntegrationPaginatedDataFilter) { IntegrationPaginatedDataFilter iFilter = (IntegrationPaginatedDataFilter) filter; query.setFirstResult(iFilter.getOffset()); query.setMaxRecords(iFilter.getLimit()); } } return query.doInJpa(em); } catch (final Exception e) { logger.error(PersistenceMessageBundle.MSG_DAO_RETRIEVEFILTERED_ERROR, new Object[] { filter.toString(), getClassP() }); logger.error(PersistenceMessageBundle.MSG_DAO_RETRIEVEFILTERED_ERROR, e); throw new PersistenceException(PersistenceMessageBundle.MSG_DAO_RETRIEVEFILTERED_ERROR_P1 + filter.toString() + PersistenceMessageBundle.MSG_DAO_RETRIEVEFILTERED_ERROR_P2 + getClassP(), e); } }