List of usage examples for javax.persistence Query getResultList
List getResultList();
From source file:eu.trentorise.smartcampus.ac.provider.repository.persistence.AcDaoPersistenceImplTest.java
@SuppressWarnings("unchecked") private static void cleanDb() { emf = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME); em = emf.createEntityManager();/* ww w .j a v a 2 s . c om*/ em.getTransaction().begin(); Query q = em.createQuery("from UserEntity"); List<UserEntity> results = q.getResultList(); for (UserEntity temp : results) { em.remove(temp); } q = em.createQuery("from AuthorityEntity"); List<AuthorityEntity> res = q.getResultList(); for (AuthorityEntity temp : res) { em.remove(temp); } em.getTransaction().commit(); em.close(); emf.close(); }
From source file:ro.allevo.fintpws.security.RolesUtils.java
public static boolean hasWriteAuthorityOnQueue(QueueEntity queueEntity) { EntityManagerFactory configEntityManagerFactory = Persistence.createEntityManagerFactory("fintpCFG"); EntityManager entityManagerConfig = configEntityManagerFactory.createEntityManager(); Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); UserEntity loggedUser = (UserEntity) authentication.getPrincipal(); Query query = entityManagerConfig.createQuery( "SELECT ur.roleid FROM UserRoleEntity ur, QueuesRoleMapEntity qr " + "WHERE ur.roleid = qr.roleid " + "AND ur.userid=:userid " + "AND qr.queueid=:queueid " + "AND qr.actiontype = 'RW'"); query.setParameter("userid", loggedUser.getUserid()); query.setParameter("queueid", queueEntity.getGuid()); List roles = query.getResultList(); if (roles.isEmpty()) { return false; }//from ww w . ja va 2 s. c o m return true; }
From source file:com.siberhus.ngai.core.CrudHelper.java
@SuppressWarnings("unchecked") public final static List<Object> findByQTO(EntityManager em, QTO qto) { Query query = createQueryObject(em, qto.buildQueryString(), qto.getParameterList()); if (qto.getFirstResult() != null) { query.setFirstResult(qto.getFirstResult()); }/* ww w. ja va 2 s. co m*/ if (qto.getMaxResult() != null) { query.setMaxResults(qto.getMaxResult()); } return query.getResultList(); }
From source file:at.gv.egovernment.moa.id.commons.db.ConfigurationDBRead.java
public static UserDatabase getUserWithID(long id) { MiscUtil.assertNotNull(id, "UserID"); Logger.trace("Getting Userinformation with ID " + id + " from database."); List<UserDatabase> result; EntityManager session = ConfigurationDBUtils.getCurrentSession(); javax.persistence.Query query = session.createQuery(QUERIES.get("getUserWithUserID")); query.setParameter("id", id); result = query.getResultList(); Logger.trace("Found entries: " + result.size()); if (result.size() == 0) { Logger.trace("No entries found."); return null; }/*from w w w. j a v a 2s . c o m*/ return (UserDatabase) result.get(0); }
From source file:at.gv.egovernment.moa.id.commons.db.ConfigurationDBRead.java
public static UserDatabase getUsersWithOADBID(long id) { MiscUtil.assertNotNull(id, "OADBID"); Logger.trace("Getting Userinformation with OADBID " + id + " from database."); List<UserDatabase> result; EntityManager session = ConfigurationDBUtils.getCurrentSession(); javax.persistence.Query query = session.createQuery(QUERIES.get("getUsersWithOADBID")); query.setParameter("id", id); result = query.getResultList(); Logger.trace("Found entries: " + result.size()); if (result.size() == 0) { Logger.trace("No entries found."); return null; }//from w w w.j a va 2 s . c o m return (UserDatabase) result.get(0); }
From source file:at.gv.egovernment.moa.id.commons.db.ConfigurationDBRead.java
public static UserDatabase getUserWithUserBPKWBPK(String bpkwbpk) { MiscUtil.assertNotNull(bpkwbpk, "bpk/wbpk"); Logger.trace("Getting Userinformation with ID " + bpkwbpk + " from database."); List<UserDatabase> result; EntityManager session = ConfigurationDBUtils.getCurrentSession(); javax.persistence.Query query = session.createQuery(QUERIES.get("getUserWithUserBPKWBPK")); query.setParameter("bpk", bpkwbpk); result = query.getResultList(); Logger.trace("Found entries: " + result.size()); if (result.size() == 0) { Logger.trace("No entries found."); return null; }//w w w .j a v a2 s . c o m return (UserDatabase) result.get(0); }
From source file:at.gv.egovernment.moa.id.commons.db.ConfigurationDBRead.java
public static UserDatabase getNewUserWithTokken(String tokken) { MiscUtil.assertNotNull(tokken, "bpk/wbpk"); Logger.trace("Getting Userinformation with Tokken " + tokken + " from database."); List<UserDatabase> result; EntityManager session = ConfigurationDBUtils.getCurrentSession(); javax.persistence.Query query = session.createQuery(QUERIES.get("getNewUserWithUserTokken")); query.setParameter("tokken", tokken); result = query.getResultList(); Logger.trace("Found entries: " + result.size()); if (result.size() == 0) { Logger.trace("No entries found."); return null; }/*from ww w . ja v a 2 s. c om*/ return (UserDatabase) result.get(0); }
From source file:at.gv.egovernment.moa.id.commons.db.ConfigurationDBRead.java
public static UserDatabase getUserWithUserName(String username) { MiscUtil.assertNotNull(username, "UserName"); Logger.trace("Getting Userinformation with ID " + username + " from database."); List<UserDatabase> result; EntityManager session = ConfigurationDBUtils.getCurrentSession(); javax.persistence.Query query = session.createQuery(QUERIES.get("getUserWithUserUsername")); query.setParameter("username", username); result = query.getResultList(); Logger.trace("Found entries: " + result.size()); if (result.size() == 0) { Logger.trace("No entries found."); return null; }//from ww w . jav a2s.c o m return (UserDatabase) result.get(0); }
From source file:at.gv.egovernment.moa.id.commons.db.ConfigurationDBRead.java
@SuppressWarnings("rawtypes") public static List<OnlineApplication> searchOnlineApplications(String id) { MiscUtil.assertNotNull(id, "OnlineApplictionID"); Logger.trace("Getting OnlineApplication with ID " + id + " from database."); List<OnlineApplication> result; EntityManager session = ConfigurationDBUtils.getCurrentSession(); javax.persistence.Query query = session.createQuery(QUERIES.get("searchOnlineApplicationsWithID")); query.setParameter("id", "%" + id + "%"); result = query.getResultList(); Logger.trace("Found entries: " + result.size()); if (result.size() == 0) { Logger.trace("No entries found."); return null; }/*from w w w . j ava2 s . c om*/ return result; }
From source file:com.impetus.kvapps.runner.ExecutorService.java
/** * On find by native CQL3 query./* www . j a v a 2 s. com*/ * * @param em entity manager instance. * @param query native cql3 query. */ @SuppressWarnings("unchecked") static void findByNativeQuery(final EntityManager em, final String query) { Query q = em.createNativeQuery(query, Tweets.class); Map<String, Client> clients = (Map<String, Client>) em.getDelegate(); ThriftClient client = (ThriftClient) clients.get("twissandra"); client.setCqlVersion(CassandraConstants.CQL_VERSION_3_0); logger.info("[On Find Tweets by CQL3]"); List<Tweets> tweets = q.getResultList(); System.out.println("#######################START##########################################"); logger.info("\t\t User's total tweets:" + tweets.size()); onPrintTweets(tweets); logger.info("\n"); // logger.info("First tweet:" users.get(0).getTweets().); System.out.println("#######################END############################################"); logger.info("\n"); }