List of usage examples for org.hibernate Query setEntity
@Deprecated @SuppressWarnings("unchecked") Query<R> setEntity(String name, Object val);
From source file:dao.TimeDao.java
public List<Time> listarTimesPorJogo(Jogo jogo) { try {//from w w w . ja v a 2s . c o m if (jogo == null) { return null; } Session sessao = Hibernate4Util.getSessionFactory(); Transaction transacao = sessao.beginTransaction(); Query consulta = sessao .createQuery("SELECT ti1 " + " FROM Jogo jo" + " JOIN jo.time1 ti1" + " WHERE (jo = ?)"); consulta.setEntity(0, jogo); List<Time> resultado = consulta.list(); consulta = sessao .createQuery("SELECT ti1 " + " FROM Jogo jo" + " JOIN jo.time2 ti2" + " WHERE (jo = ?)"); consulta.setEntity(0, jogo); resultado.addAll(consulta.list()); transacao.commit(); return resultado; } catch (HibernateException e) { System.out.println("No foi possvel selecionar apostadores. Erro: " + e.getMessage()); throw new HibernateException(e); } }
From source file:de.csw.expertfinder.persistence.PersistenceStoreFacade.java
License:Open Source License
/** * Retrieves all topics the given author has contributed to. * /*w w w. j a va 2 s . c o m*/ * @param author * @return */ @SuppressWarnings("unchecked") public List<Concept> getContributedTopics(Author author) { Session session = sessionFactory.getCurrentSession(); Query query = session.createQuery("select distinct c from Concept c, Word w, Revision rc " + "where w.concept = c " + "and w.revisionCreated = rc " + "and rc.author = :author "); query.setEntity("author", author); return query.list(); }
From source file:de.csw.expertfinder.persistence.PersistenceStoreFacade.java
License:Open Source License
/** * Retrieves all topics the given author has contributed to. * /*from ww w. j a v a2 s . co m*/ * @param author * @return */ @SuppressWarnings("unchecked") public List<Concept> getIndirectContributedTopics(Author author) { Session session = sessionFactory.getCurrentSession(); Query query = session.createQuery( "select distinct c " + "from Concept c, Word w, Revision rc, Section s, SectionConcept sc " + "where rc.author = :author " + "and w.revisionCreated = rc " + "and sc.section = w.section " + "and sc.concept = c "); query.setEntity("author", author); return query.list(); }
From source file:de.csw.expertfinder.persistence.PersistenceStoreFacade.java
License:Open Source License
/** * Retrieves all authors that have directly contributed to the given * topic./*ww w .j ava 2s .c o m*/ * * @param topic * @return */ @SuppressWarnings("unchecked") public List<Author> getAuthorsWhoContributedToTopic(Concept topic) { Session session = sessionFactory.getCurrentSession(); Query query = session.createQuery("select distinct a from Author a, Word w, Revision rc " + "where w.concept = :topic " + "and w.revisionCreated = rc " + "and rc.author = a "); query.setEntity("topic", topic); return query.list(); }
From source file:de.csw.expertfinder.persistence.PersistenceStoreFacade.java
License:Open Source License
/** * Gets cached author contributions by author. * @param author// w w w .j a va 2 s. c om * @return */ @SuppressWarnings("unchecked") public List<AuthorContribution> getCachedAuthorContributions(Author author) { Session session = sessionFactory.getCurrentSession(); Query query = session.createQuery("from AuthorContribution ac where ac.author = :author"); query.setEntity("author", author); return query.list(); }
From source file:de.csw.expertfinder.persistence.PersistenceStoreFacade.java
License:Open Source License
/** * Gets cached author contributions by topic. * @param topic/*from w w w . j ava2 s . com*/ * @return */ @SuppressWarnings("unchecked") public List<AuthorContribution> getCachedAuthorContributions(Concept topic) { Session session = sessionFactory.getCurrentSession(); Query query = session.createQuery("from AuthorContribution ac where ac.concept = :topic"); query.setEntity("topic", topic); return query.list(); }
From source file:de.csw.expertfinder.persistence.PersistenceStoreFacade.java
License:Open Source License
/** * Retrieves all authors that have indirectly contributed to the given * topic./*from w w w . j ava2s.c o m*/ * * @param topic * @return */ @SuppressWarnings("unchecked") public List<Author> getAuthorsWhoIndirectlyContributedToTopic(Concept topic) { Session session = sessionFactory.getCurrentSession(); Query query = session.createQuery( "select distinct a " + "from Author a, Word w, Revision rc, Section s, SectionConcept sc " + "where sc.concept = :topic " + "and w.concept is not null " + "and w.revisionCreated = rc " + "and sc.section = w.section " + "and rc.author = a"); query.setEntity("topic", topic); return query.list(); }
From source file:de.csw.expertfinder.persistence.PersistenceStoreFacade.java
License:Open Source License
public AuthorCredibility getAuthorCredibility(Author author, Concept concept) { Session session = sessionFactory.getCurrentSession(); Query query = session .createQuery("from AuthorCredibility ac where ac.author = :author and ac.concept = :concept"); query.setEntity("author", author); query.setEntity("concept", concept); return (AuthorCredibility) query.uniqueResult(); }
From source file:de.decidr.model.commands.user.ConfirmInvitationCommand.java
License:Apache License
/** * Makes the given user a member of the given tenant. This method has no * effect if the user is already a tenant member or the tenant admin. * //from ww w .ja v a 2 s.c o m * @param user * user who should become member of the given tenant * @param tenant * tenant to which the given user should be added */ private void makeMemberOfTenant(User user, Tenant tenant) { if ((tenant == null) || (user == null)) { throw new IllegalArgumentException("User and tenant must not be null"); } Query q = session.createQuery("select count(*) from UserIsMemberOfTenant a " + "where (a.tenant = :tenant AND a.user = :user) or a.tenant.admin = :user"); q.setEntity("tenant", tenant); q.setEntity("user", user); if (((Number) q.uniqueResult()).intValue() < 1) { // user isn't a tenant member yet, make him a tenant member! UserIsMemberOfTenant relation = new UserIsMemberOfTenant(); relation.setUser(user); relation.setTenant(tenant); session.save(relation); } }
From source file:de.decidr.model.commands.user.ConfirmInvitationCommand.java
License:Apache License
/** * Makes the receiver of the invitation a member of the tenant and allows * him to administrate the workflow model that is specified by the * invitation./*from w ww .ja v a 2 s .c o m*/ * * @throws AccessDeniedException */ private void processWorkflowModelInvitation() throws AccessDeniedException { User user = invitation.getReceiver(); Tenant tenant = invitation.getAdministrateWorkflowModel().getTenant(); makeMemberOfTenant(user, tenant); // only registered users can do this if (user.getUserProfile() == null) { throw new AccessDeniedException("You must be registered to become workflow administrator"); } // add as WorkflowAdmin only if not already a workflow admin Query q = session.createQuery("select count(*) from UserAdministratesWorkflowModel rel " + "where rel.user = :user and rel.workflowModel = :workflowModel"); q.setEntity("user", user).setEntity("workflowModel", invitation.getAdministrateWorkflowModel()); if (((Number) q.uniqueResult()).intValue() < 1) { // the user is currently not administrating the workflow model UserAdministratesWorkflowModel relation = new UserAdministratesWorkflowModel(); relation.setUser(user); relation.setWorkflowModel(invitation.getAdministrateWorkflowModel()); session.save(relation); } }