List of usage examples for org.hibernate SQLQuery addEntity
SQLQuery<T> addEntity(String tableAlias, Class entityType);
From source file:de.innovationgate.webgate.api.jdbc.WGDatabaseImpl.java
License:Open Source License
private WGResultSetCore executeSQLQuery(String fullQuery, Map queryOptions) throws WGAPIException { try {/*from ww w . jav a2s. c o m*/ queryOptions.put(WGDatabase.QUERYOPTION_RETURNQUERY, fullQuery); SQLQuery hibQuery = getSession().createSQLQuery(fullQuery); if (fullQuery.contains("{")) { hibQuery.addEntity("content", Content.class); } Map queryParams = (Map) queryOptions.get(WGDatabase.QUERYOPTION_QUERY_PARAMETERS); HibernateResultSet.injectQueryParams(hibQuery, queryParams); return new WGSQLResultSet(this, hibQuery, queryParams, queryOptions); } catch (SQLGrammarException e) { throw new WGQueryException(fullQuery, e.getMessage(), e); } catch (HibernateException e) { throw new WGBackendException("Error executing SQL query", e); } }
From source file:edu.pitt.sis.exp.colfusion.dal.dao.SourceInfoDAOImpl.java
@Override public List<ColfusionSourceinfo> findOneSidsTrue() throws HibernateException { List<ColfusionSourceinfo> returnList = new ArrayList<ColfusionSourceinfo>(); String sql = "select {cs.*} from Colfusion_sourceinfo cs where Status<>'draft' and cs.sid not in (Select sid1 from Colfusion_relationships union Select sid2 from Colfusion_relationships)"; logger.info(String.format("Starting processing findOneSidsTrue ")); SQLQuery query = null; try {// w ww . j ava2 s. c o m HibernateUtil.beginTransaction(); query = this.getSession().createSQLQuery(sql); query.addEntity("cs", ColfusionSourceinfo.class); returnList = findMany(query); HibernateUtil.commitTransaction(); } catch (Exception e) { logger.error(String.format("findOneSidsTrue failed on HibernateUtil.getSession().createQuery(sql)"), e); throw e; } logger.info(String.format("Finish processing findOneSidsTrue")); return returnList; }
From source file:edu.wustl.cab2b.server.user.UserOperations.java
License:BSD License
/** * This method returns user from database with given user name * @param name user name/*from w w w .jav a 2 s .c o m*/ * @return User */ public UserInterface getUserByName(String value) { List<UserInterface> userList = null; final String queryStr = "Select {User.*} from cab2b_user User where name COLLATE latin1_bin=?"; try { SQLQuery sqlQuery = DBUtil.currentSession().createSQLQuery(queryStr); sqlQuery.setString(0, value); userList = sqlQuery.addEntity("User", edu.wustl.cab2b.common.user.User.class).list(); } catch (HibernateException hbe) { logger.error(hbe.getMessage(), hbe); throw new RuntimeException("Error occurred while fetching User", ErrorCodeConstants.UR_0003); } finally { DBUtil.closeSession(); } UserInterface user = null; if (userList != null && !userList.isEmpty()) { user = userList.get(0); } return user; }
From source file:gov.nih.nci.caarray.dao.AuditLogDaoImpl.java
License:BSD License
/** * {@inheritDoc}/*from w ww . j a v a2 s .co m*/ */ public List<AuditLogRecord> getRecords(AuditLogSearchCriteria criteria, PageSortParams<AuditLogRecord> sort) { StringBuffer sb = new StringBuffer(); buildSql(criteria, sb, "distinct r.*"); sb.append(" order by "); if (sort.getSortCriteria().isEmpty()) { sb.append("created_date asc, r.id desc"); } else { String direction = sort.isDesc() ? " desc" : " asc"; String comma = ""; for (SortCriterion<AuditLogRecord> s : sort.getSortCriteria()) { sb.append(comma); sb.append("r.").append(s.getOrderField()).append(direction); comma = ", "; } sb.append(comma).append("r.id").append(direction); } SQLQuery q = buildQuery(criteria, sb); q.addEntity("r", AuditLogRecord.class); q.setMaxResults(sort.getPageSize()); q.setFirstResult(sort.getIndex()); @SuppressWarnings("unchecked") List<AuditLogRecord> records = q.list(); return records; }
From source file:net.chrisrichardson.foodToGo.domain.hibernate.HibernateOrderRepositoryImpl.java
License:Apache License
private SQLQuery makeSqlQuery(Session session) { SQLQuery query = session.createSQLQuery("SELECT {o.*},{r.*} " + " FROM FTGO_PLACED_ORDER o, FTGO_RESTAURANT r " + " WHERE r.restaurant_id = o.restaurant_id " + "AND o.delivery_city = :name " + " ORDER BY DELIVERY_TIME desc"); query.addEntity("o", Order.class); query.addJoin("r", "o.restaurant"); query.setParameter("name", "Oakland"); return query; }
From source file:net.sf.sail.webapp.dao.workgroup.impl.HibernateWorkgroupDao.java
License:LGPL
/** * @see net.sf.sail.webapp.dao.workgroup.WorkgroupDao#getListByOfferingAndUser(net.sf.sail.webapp.domain.Offering, * net.sf.sail.webapp.domain.User)//from w w w. j a va 2 s . c o m */ @SuppressWarnings("unchecked") public List<Workgroup> getListByOfferingAndUser(Offering offering, User user) { Session session = this.getSession(); SQLQuery sqlQuery = session.createSQLQuery( "SELECT w.*, g.* FROM workgroups as w, groups as g, " + "groups_related_to_users as g_r_u " + "WHERE w.group_fk = g.id " + "AND g_r_u.group_fk = w.group_fk " + "AND g_r_u.user_fk = :user_param " + "AND w.offering_fk = :offering_param"); sqlQuery.addEntity("workgroup", WorkgroupImpl.class); sqlQuery.setParameter("offering_param", offering.getId(), Hibernate.LONG); sqlQuery.setParameter("user_param", user.getId(), Hibernate.LONG); return sqlQuery.list(); }
From source file:net.sf.sail.webapp.dao.workgroup.impl.HibernateWorkgroupDao.java
License:LGPL
/** * @see net.sf.sail.webapp.dao.workgroup.WorkgroupDao#getListByUser(net.sf.sail.webapp.domain.User) *//*from w w w .j a v a 2s .c om*/ @SuppressWarnings("unchecked") public List<Workgroup> getListByUser(User user) { Session session = this.getSession(); SQLQuery sqlQuery = session.createSQLQuery("SELECT w.*, g.* FROM workgroups as w, groups as g, " + "groups_related_to_users as g_r_u " + "WHERE w.group_fk = g.id " + "AND g_r_u.group_fk = w.group_fk " + "AND g_r_u.user_fk = :user_param "); sqlQuery.addEntity("workgroup", WorkgroupImpl.class); sqlQuery.setParameter("user_param", user.getId(), Hibernate.LONG); return sqlQuery.list(); }
From source file:org.anyframe.hibernate.impl.DynamicHibernateServiceImpl.java
License:Apache License
private void addEntity(SQLQuery query, List<ReturnInfo> returnList) { if (!returnList.isEmpty()) for (int i = 0; i < returnList.size(); i++) { ReturnInfo info = returnList.get(i); String alias = info.getAlias(); Class<?> clazz = info.getClazz(); String entityName = info.getEntityName(); if (alias != null) { if (clazz != null) query.addEntity(alias, clazz); if (entityName != null) query.addEntity(alias, entityName); } else { if (clazz != null) query.addEntity(clazz); if (entityName != null) query.addEntity(entityName); }// w ww. j a va 2s.c o m } }
From source file:org.bedework.carddav.server.dirHandlers.db.HibSessionImpl.java
License:Apache License
/** Create a sql query ready for parameter replacement or execution. * * @param s String hibernate query * @param returnAlias/*from ww w . j a va 2 s .c o m*/ * @param returnClass * @throws WebdavException */ public void createSQLQuery(final String s, final String returnAlias, final Class returnClass) throws WebdavException { if (exc != null) { // Didn't hear me last time? throw new WebdavException(exc); } try { SQLQuery sq = sess.createSQLQuery(s); sq.addEntity(returnAlias, returnClass); q = sq; crit = null; } catch (Throwable t) { handleException(t); } }
From source file:org.bedework.dumprestore.HibSession.java
License:Apache License
/** Create a sql query ready for parameter replacement or execution. * * @param s String hibernate query * @param returnAlias/*www .j ava 2 s.com*/ * @param returnClass * @throws CalFacadeException */ public void createSQLQuery(String s, String returnAlias, Class returnClass) throws CalFacadeException { if (exc != null) { // Didn't hear me last time? throw new CalFacadeException(exc); } try { SQLQuery sq = sess.createSQLQuery(s); sq.addEntity(returnAlias, returnClass); q = sq; crit = null; } catch (Throwable t) { handleException(t); } }