List of usage examples for org.hibernate SQLQuery addEntity
SQLQuery<T> addEntity(String tableAlias, Class entityType);
From source file:org.telscenter.sail.webapp.dao.workgroup.impl.HibernateWISEWorkgroupDao.java
License:LGPL
/** * @see net.sf.sail.webapp.dao.workgroup.WorkgroupDao#getListByUser(net.sf.sail.webapp.domain.User) *//*from w w w . ja v a 2s . c o m*/ @SuppressWarnings("unchecked") public List<WISEWorkgroup> getListByUser(User user) { Session session = this.getSession(); SQLQuery sqlQuery = session.createSQLQuery("SELECT w.*, g.*, ww.* FROM workgroups as w, groups as g, " + "groups_related_to_users as g_r_u, wiseworkgroups as ww " + "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.id = ww.id"); sqlQuery.addEntity("wiseworkgroup", WISEWorkgroupImpl.class); sqlQuery.setParameter("user_param", user.getId(), Hibernate.LONG); return sqlQuery.list(); }
From source file:org.theospi.portfolio.presentation.model.impl.PresentationManagerImpl.java
License:Educational Community License
public List getPresentationComments(Id presentationId, Agent viewer) { Session session = getSession();/*from ww w . j a v a 2 s.c o m*/ SQLQuery query = session.createSQLQuery("SELECT {osp_presentation_comment.*} " + " FROM osp_presentation_comment {osp_presentation_comment}, osp_presentation p " + " WHERE {osp_presentation_comment}.presentation_id = p.id and p.id = :presentationId and" + " (visibility = " + PresentationComment.VISABILITY_PUBLIC + " or " + " (visibility = " + PresentationComment.VISABILITY_SHARED + " and " + " p.owner_id = :viewerId) or " + " creator_id = :viewerId)" + " ORDER BY {osp_presentation_comment}.created"); query.addEntity("osp_presentation_comment", PresentationComment.class); query.setString("presentationId", presentationId.getValue()); query.setString("viewerId", viewer.getId().getValue()); try { return query.list(); } catch (HibernateException e) { logger.error("", e); throw new OspException(e); } }
From source file:org.theospi.portfolio.presentation.model.impl.PresentationManagerImpl.java
License:Educational Community License
public List getOwnerComments(Agent owner, CommentSortBy sortBy, boolean excludeOwner) { String orderBy = sortBy.getSortByColumn(); if (orderBy.startsWith("owner_id") || orderBy.startsWith("name")) { orderBy = "p." + orderBy; } else {//from w w w . j a v a2s. com orderBy = "{osp_presentation_comment}." + orderBy; } Session session = getSession(); String includeOwnerCondition = ""; if (!excludeOwner) { includeOwnerCondition = " or creator_id = :ownerId ) "; } else { includeOwnerCondition = " ) and ( creator_id != :ownerId )"; } SQLQuery query = session.createSQLQuery("SELECT {osp_presentation_comment.*} " + " FROM osp_presentation_comment {osp_presentation_comment}, osp_presentation p " + " WHERE {osp_presentation_comment}.presentation_id = p.id and " + " (visibility = " + PresentationComment.VISABILITY_PUBLIC + " or " + " visibility = " + PresentationComment.VISABILITY_SHARED + includeOwnerCondition + " and " + " p.owner_id = :ownerId " + " ORDER BY " + orderBy + " " + sortBy.getDirection()); query.addEntity("osp_presentation_comment", PresentationComment.class); query.setString("ownerId", owner.getId().getValue()); try { return query.list(); } catch (HibernateException e) { logger.error("", e); throw new OspException(e); } }
From source file:org.theospi.portfolio.presentation.model.impl.PresentationManagerImpl.java
License:Educational Community License
public List getOwnerComments(Agent owner, String toolId, CommentSortBy sortBy, boolean excludeOwner) { String orderBy = sortBy.getSortByColumn(); if (orderBy.startsWith("owner_id") || orderBy.startsWith("name")) { orderBy = "p." + orderBy; } else {/*from w w w.j a va 2s . c o m*/ orderBy = "{osp_presentation_comment}." + orderBy; } Session session = getSession(); String includeOwnerCondition = ""; if (!excludeOwner) { includeOwnerCondition = " or creator_id = :ownerId ) "; } else { includeOwnerCondition = " ) and ( creator_id != :ownerId )"; } StringBuilder queryBuf = new StringBuilder("SELECT {osp_presentation_comment.*} " + " FROM osp_presentation_comment {osp_presentation_comment}, osp_presentation p " + " WHERE {osp_presentation_comment}.presentation_id = p.id and "); if (!isOnWorkspaceTab()) { queryBuf.append(" p.tool_id = :toolId and "); } queryBuf.append(" (visibility = " + PresentationComment.VISABILITY_PUBLIC + " or "); queryBuf.append(" visibility = " + PresentationComment.VISABILITY_SHARED); queryBuf.append(includeOwnerCondition + " and "); queryBuf.append(" p.owner_id = :ownerId "); queryBuf.append(" ORDER BY " + orderBy + " " + sortBy.getDirection()); SQLQuery query = session.createSQLQuery(queryBuf.toString()); query.addEntity("osp_presentation_comment", PresentationComment.class); if (!isOnWorkspaceTab()) { query.setString("toolId", toolId); } query.setString("ownerId", owner.getId().getValue()); try { return query.list(); } catch (HibernateException e) { logger.error("", e); throw new OspException(e); } }
From source file:org.theospi.portfolio.presentation.model.impl.PresentationManagerImpl.java
License:Educational Community License
public List getCreatorComments(Agent creator, CommentSortBy sortBy) { String orderBy = sortBy.getSortByColumn(); if (orderBy.startsWith("owner_id") || orderBy.startsWith("name")) { orderBy = "p." + orderBy; } else {/*from www. j av a2 s .c o m*/ orderBy = "{osp_presentation_comment}." + orderBy; } String queryString = "SELECT {osp_presentation_comment.*} " + " FROM osp_presentation_comment {osp_presentation_comment}, osp_presentation p " + " WHERE {osp_presentation_comment}.presentation_id = p.id and " + " creator_id = :creatorId" + " ORDER BY " + orderBy + " " + sortBy.getDirection(); Session session = getSession(); SQLQuery query = session.createSQLQuery(queryString); query.addEntity("osp_presentation_comment", PresentationComment.class); query.setString("creatorId", creator.getId().getValue()); try { return query.list(); } catch (HibernateException e) { logger.error("", e); throw new OspException(e); } }
From source file:org.theospi.portfolio.presentation.model.impl.PresentationManagerImpl.java
License:Educational Community License
public List getCreatorComments(Agent creator, String toolId, CommentSortBy sortBy) { String orderBy = sortBy.getSortByColumn(); if (orderBy.startsWith("owner_id") || orderBy.startsWith("name")) { orderBy = "p." + orderBy; } else {// www . j a v a 2 s. c o m orderBy = "{osp_presentation_comment}." + orderBy; } StringBuilder queryBuf = new StringBuilder("SELECT {osp_presentation_comment.*} " + " FROM osp_presentation_comment {osp_presentation_comment}, osp_presentation p " + " WHERE {osp_presentation_comment}.presentation_id = p.id and "); if (!isOnWorkspaceTab()) { queryBuf.append(" tool_id = :toolId and"); } queryBuf.append(" creator_id = :creatorId"); queryBuf.append(" ORDER BY " + orderBy + " " + sortBy.getDirection()); Session session = getSession(); SQLQuery query = session.createSQLQuery(queryBuf.toString()); query.addEntity("osp_presentation_comment", PresentationComment.class); if (!isOnWorkspaceTab()) { query.setString("toolId", toolId); } query.setString("creatorId", creator.getId().getValue()); try { return query.list(); } catch (HibernateException e) { logger.error("", e); throw new OspException(e); } }
From source file:org.theospi.portfolio.presentation.model.impl.PresentationManagerImpl.java
License:Educational Community License
public Collection getPresentationItems(Id artifactId) { Session session = getSession();// w w w. j a va 2s.c om SQLQuery query = session.createSQLQuery("SELECT {osp_presentation.*} " + " FROM osp_presentation {osp_presentation}, osp_presentation_item pi " + " WHERE {osp_presentation}.id = pi.presentation_id and pi.artifact_id = :artifactId"); query.addEntity("osp_presentation", Presentation.class); query.setString("artifactId", artifactId.getValue()); try { return query.list(); } catch (HibernateException e) { logger.error("", e); throw new OspException(e); } }
From source file:org.theospi.portfolio.presentation.model.impl.PresentationManagerImpl.java
License:Educational Community License
public Collection getPresentationsBasedOnTemplateFileRef(Id artifactId) { Session session = getSession();/*from www.ja va2 s . c o m*/ try { SQLQuery query = session.createSQLQuery("SELECT {osp_presentation.*} " + " FROM osp_presentation {osp_presentation}, osp_template_file_ref tfr" + " WHERE {osp_presentation}.template_id = tfr.template_id and tfr.file_id = :artifactId"); query.addEntity("osp_presentation", Presentation.class); query.setString("artifactId", artifactId.getValue()); Collection tfr = query.list(); query = session.createSQLQuery("SELECT {osp_presentation.*} " + " FROM osp_presentation {osp_presentation}, osp_presentation_template templ " + " WHERE {osp_presentation}.template_id = templ.id and (templ.renderer = :artifactId " + " or templ.propertyPage = :artifactId)"); query.addEntity("osp_presentation", Presentation.class); query.setString("artifactId", artifactId.getValue()); tfr.addAll(query.list()); return tfr; } catch (HibernateException e) { logger.error("", e); throw new OspException(e); } }
From source file:org.wise.portal.dao.workgroup.impl.HibernateWorkgroupDao.java
License:Open Source License
/** * @param offering/* ww w . j a v a 2 s . c om*/ * @param user * @return */ @SuppressWarnings("unchecked") public List<Workgroup> getListByOfferingAndUser(Offering offering, User user) { Session session = this.getHibernateTemplate().getSessionFactory().getCurrentSession(); SQLQuery sqlQuery = session.createSQLQuery("SELECT w.*, g.*, ww.* FROM workgroups as w, groups as g, " + "groups_related_to_users as g_r_u, wiseworkgroups as ww " + "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 " + "AND w.id = ww.id"); sqlQuery.addEntity("wiseworkgroup", WISEWorkgroupImpl.class); sqlQuery.setParameter("offering_param", offering.getId()); sqlQuery.setParameter("user_param", user.getId()); return sqlQuery.list(); }
From source file:org.wise.portal.dao.workgroup.impl.HibernateWorkgroupDao.java
License:Open Source License
/** * @param user/*from w ww. j a va 2 s . c o m*/ * @return */ @SuppressWarnings("unchecked") public List<Workgroup> getListByUser(User user) { Session session = this.getHibernateTemplate().getSessionFactory().getCurrentSession(); SQLQuery sqlQuery = session.createSQLQuery("SELECT w.*, g.*, ww.* FROM workgroups as w, groups as g, " + "groups_related_to_users as g_r_u, wiseworkgroups as ww " + "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.id = ww.id"); sqlQuery.addEntity("wiseworkgroup", WISEWorkgroupImpl.class); sqlQuery.setParameter("user_param", user.getId()); return sqlQuery.list(); }