List of usage examples for org.hibernate HibernateException HibernateException
public HibernateException(Throwable cause)
From source file:org.alfresco.repo.workflow.jbpm.JbpmTimerTest.java
License:Open Source License
public static void throwException() throws HibernateException { throw new HibernateException("My Timer Exception"); }
From source file:org.ambraproject.admin.service.impl.AdminRolesServiceImpl.java
License:Apache License
/** * Get all the roles associated with a user * * @param userProfileID/*from ww w .j ava 2 s. c o m*/ * @return */ public Set<UserRoleView> getUserRoles(final Long userProfileID) { UserProfile up = (UserProfile) hibernateTemplate.load(UserProfile.class, userProfileID); if (up == null) { throw new HibernateException("Can not find user with ID: " + userProfileID); } Set<UserRoleView> results = new HashSet<UserRoleView>(); for (UserRole ur : up.getRoles()) { results.add(new UserRoleView(ur.getID(), ur.getRoleName(), true)); } return results; }
From source file:org.ambraproject.admin.service.impl.AdminRolesServiceImpl.java
License:Apache License
/** * Revoke all the roles from the passed in userProfileID * * @param userProfileID//from w w w .j a va 2 s. c om */ @SuppressWarnings("unchecked") public void revokeAllRoles(final Long userProfileID) { List<UserProfile> userProfiles = (List<UserProfile>) hibernateTemplate.findByCriteria(DetachedCriteria .forClass(UserProfile.class).add(Restrictions.eq("ID", userProfileID)) .setFetchMode("userRole", FetchMode.JOIN).setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY)); if (userProfiles.size() == 0) { throw new HibernateException("Can not find user with ID: " + userProfileID); } UserProfile up = userProfiles.get(0); //Set roles to an empty collection up.setRoles(new HashSet<UserRole>()); hibernateTemplate.update(up); }
From source file:org.ambraproject.hibernate.OTMBlobType.java
License:Apache License
public int hashCode(Object o) throws HibernateException { if (o instanceof Blob) { return ((Blob) o).hashCode(); } else {//w w w. java 2 s .c o m throw new HibernateException("Not of type blob"); } }
From source file:org.ambraproject.hibernate.OTMBlobType.java
License:Apache License
public void nullSafeSet(PreparedStatement statement, java.lang.Object value, int index) throws HibernateException, SQLException { if (value == null) { statement.setNull(index, Types.BLOB); } else {/*w w w .j a v a 2 s .c o m*/ if (value instanceof org.topazproject.otm.Blob) { //TODO: I don't think the following line works statement.setBlob(index, ((org.topazproject.otm.Blob) value).getInputStream()); } else { throw new HibernateException("Object not of correct type: " + value.getClass().getName()); } } }
From source file:org.ambraproject.rating.service.RatingsServiceImpl.java
License:Apache License
/** * Delete the Rating identified by ratingId and update the RatingSummary. * * @param ratingID the identifier of the Rating object to be deleted * @throws org.ambraproject.ApplicationException on an error *///from w ww.j av a 2s . com @SuppressWarnings("unchecked") @Transactional(rollbackFor = { Throwable.class }) public void deleteRating(final Long ratingID, String authId) throws ApplicationException { permissionsService.checkRole(PermissionsService.ADMIN_ROLE, authId); final Rating articleRating = (Rating) hibernateTemplate.get(Rating.class, ratingID); if (articleRating == null) { throw new HibernateException("Failed to get Rating to delete: " + ratingID); } final long articleID = articleRating.getArticleID(); final RatingSummary ratingSummary = getRatingSummary(articleID); if (ratingSummary == null) { throw new HibernateException("No RatingSummary object found for articleID: " + articleID); } ratingSummary.removeRating(articleRating); hibernateTemplate.update(ratingSummary); hibernateTemplate.delete(articleRating); }
From source file:org.anyframe.hibernate.impl.DynamicHibernateServiceImpl.java
License:Apache License
/** * implements callback method using hibernateTemplate.execute(). * /* w w w . ja v a 2 s . c o m*/ * @param context * velocity context * @param queryName * executable dynamic HQL's identifier * @return being specified query execution results * * @throws DataAccessException * if there is any problem executing the query */ @SuppressWarnings("unchecked") private <T> T execute(final Context context, final String queryName) throws DataAccessException { return this.hibernateTemplate.execute(new HibernateCallback<T>() { public T doInHibernate(Session session) throws DataAccessException { try { Query query = findInternal(session, queryName, context); return (T) query.uniqueResult(); } catch (Exception e) { throw new HibernateException(e.getMessage()); } } }); }
From source file:org.anyframe.hibernate.impl.DynamicHibernateServiceImpl.java
License:Apache License
/** * implements callback method using hibernateTemplate.executeFind(). * /*from w w w. j a v a 2 s.co m*/ * @param context * velocity context * @param queryName * executable dynamic HQL's identifier * @param pageIndex * page number (greater than equal to one) * @param pageSize * the number of data for showing in the selected page (greater * than equal to one) * @return being specified query execution results * * @throws DataAccessException * if there is any problem executing the query */ @SuppressWarnings("unchecked") private <T> List<T> executeFind(final Context context, final String queryName, final int pageIndex, final int pageSize) throws DataAccessException { List<Object> tempResult = this.hibernateTemplate.executeFind(new HibernateCallback<List>() { public List doInHibernate(Session session) throws DataAccessException { try { Query query = findInternal(session, queryName, context); if (pageIndex > 0 && pageSize > 0) { query.setFirstResult((pageIndex - 1) * pageSize); query.setMaxResults(pageSize); } return query.list(); } catch (IOException e) { throw new HibernateException(e.getMessage()); } } }); List<T> finalResult = new ArrayList(); for (Object entity : tempResult) { finalResult.add((T) entity); } return finalResult; }
From source file:org.anyframe.hibernate.impl.DynamicHibernateServiceImpl.java
License:Apache License
private String getRunnableSQL(String sql, Context context) { StringBuffer tempStatement = new StringBuffer(sql); SortedMap<Integer, String> replacementPositions = findTextReplacements(tempStatement); Iterator<Entry<Integer, String>> properties = replacementPositions.entrySet().iterator(); int valueLengths = 0; while (properties.hasNext()) { Map.Entry<Integer, String> entry = properties.next(); Integer pos = entry.getKey(); String key = entry.getValue(); Object replaceValue = context.get(key); if (replaceValue == null) { throw new HibernateException( "DynamicHibernate Service : Text replacement [" + entry.getValue() + "] has not been set."); }//w w w .java 2s. c om String value = replaceValue.toString(); tempStatement.insert(pos.intValue() + valueLengths, value); valueLengths += value.length(); } return tempStatement.toString(); }
From source file:org.apache.ode.dao.jpa.hibernate.DataSourceConnectionProvider.java
License:Apache License
public Connection getConnection() throws SQLException { if (!available) { throw new HibernateException("Provider is closed!"); }//from w ww.ja va 2 s .co m Connection c = HibernateUtil.getConnection(_props); DbIsolation.setIsolationLevel(c); return c; }