List of usage examples for javax.persistence EntityManager createQuery
public Query createQuery(CriteriaDelete deleteQuery);
Query
for executing a criteria delete query. From source file:es.uvigo.ei.sing.rubioseq.gui.util.DBInitializer.java
@SuppressWarnings("unchecked") private static List<User> getAdminUsers(EntityManager em) { List<User> toret = new LinkedList<User>(); for (User u : (List<User>) em.createQuery("SELECT u FROM User u").getResultList()) { if (u.isAdmin()) { toret.add(u);/*from ww w. ja v a2 s . c om*/ } } return toret; }
From source file:org.apache.cxf.fediz.service.idp.service.jpa.ApplicationDAOJPAImpl.java
static ApplicationEntity getApplicationEntity(String realm, EntityManager em) { Query query = null;// w w w . j a va 2s. c o m query = em.createQuery("select a from Application a where a.realm=:realm"); query.setParameter("realm", realm); //@SuppressWarnings("rawtypes") return (ApplicationEntity) query.getSingleResult(); }
From source file:com.enioka.jqm.test.helpers.TestHelpers.java
public static void setNodesLogLevel(String level, EntityManager em) { em.getTransaction().begin();/*from w ww .ja v a 2 s .c o m*/ em.createQuery("UPDATE Node n set n.rootLogLevel = :l").setParameter("l", level).executeUpdate(); em.getTransaction().commit(); }
From source file:com.enioka.jqm.test.helpers.TestHelpers.java
public static void cleanup(EntityManager em) { em.getTransaction().begin();//from w w w .ja v a2s . c o m em.createQuery("DELETE GlobalParameter WHERE 1=1").executeUpdate(); em.createQuery("DELETE Deliverable WHERE 1=1").executeUpdate(); em.createQuery("DELETE DeploymentParameter WHERE 1=1").executeUpdate(); em.createQuery("DELETE Message WHERE 1=1").executeUpdate(); em.createQuery("DELETE History WHERE 1=1").executeUpdate(); em.createQuery("DELETE JobDefParameter WHERE 1=1").executeUpdate(); em.createQuery("DELETE RuntimeParameter WHERE 1=1").executeUpdate(); em.createQuery("DELETE JobInstance WHERE 1=1").executeUpdate(); em.createQuery("DELETE Node WHERE 1=1").executeUpdate(); em.createQuery("DELETE JobDef WHERE 1=1").executeUpdate(); em.createQuery("DELETE Queue WHERE 1=1").executeUpdate(); em.createQuery("DELETE JndiObjectResourceParameter WHERE 1=1").executeUpdate(); em.createQuery("DELETE JndiObjectResource WHERE 1=1").executeUpdate(); em.createQuery("DELETE PKI WHERE 1=1").executeUpdate(); em.createQuery("DELETE RPermission WHERE 1=1").executeUpdate(); em.createQuery("DELETE RRole WHERE 1=1").executeUpdate(); em.createQuery("DELETE RUser WHERE 1=1").executeUpdate(); em.getTransaction().commit(); try { // Conf dir may contain certificates and certificate stores if ((new File("./conf")).isDirectory()) { FileUtils.deleteDirectory(new File("./conf")); } // All logs if ((new File("./logs")).isDirectory()) { FileUtils.deleteDirectory(new File("./logs")); } // The war... if ((new File("./webapp")).isDirectory()) { FileUtils.deleteDirectory(new File("./webapp")); } // Where files created by payloads are stored File f = TestHelpers.node == null ? null : new File(TestHelpers.node.getDlRepo()); if (f != null && f.isDirectory()) { FileUtils.cleanDirectory(new File(TestHelpers.node.getDlRepo())); } // Temp dir where files downloaded by the API are stored (supposed to be self-destructible file but anyway) if ((new File(System.getProperty("java.io.tmpdir") + "/jqm")).isDirectory()) { FileUtils.cleanDirectory(new File(System.getProperty("java.io.tmpdir") + "/jqm")); } } catch (IOException e) { // Nothing to do } }
From source file:ro.allevo.fintpws.security.RolesUtils.java
public static boolean hasReadAuthorityOnQueue(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"); query.setParameter("userid", loggedUser.getUserid()); query.setParameter("queueid", queueEntity.getGuid()); List roles = query.getResultList(); if (roles.isEmpty()) { return false; }// w w w . ja v a2 s. co m return true; }
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 .co m*/ return true; }
From source file:org.apache.cxf.fediz.service.idp.service.jpa.IdpDAOJPAImpl.java
static IdpEntity getIdpEntity(String realm, EntityManager em) { Query query = null;// w w w . j a v a 2 s . c o m query = em.createQuery("select i from IDP i where i.realm=:realm"); query.setParameter("realm", realm); //@SuppressWarnings("rawtypes") return (IdpEntity) query.getSingleResult(); }
From source file:com.siberhus.ngai.core.CrudHelper.java
public final static Query createQueryObject(EntityManager em, String queryString, List<Object> paramList) { if (em == null) { throw new IllegalArgumentException("EntityManager is null"); }//from w ww . ja va 2s .c o m Query query = em.createQuery(queryString); for (int i = 0; i < paramList.size(); i++) { Object param = paramList.get(i); if (param instanceof TemporalObject) { TemporalObject tempParam = ((TemporalObject) param); query.setParameter(i + 1, tempParam.getTemporalObject(), tempParam.getTemporalType()); } else { query.setParameter(i + 1, param); } } return query; }
From source file:models.RememberMeInfo.java
/** * ?<br>/*w ww .j av a 2 s .com*/ * ?? ?cookie??<br> * ??? */ public static void rememberMeAutoLogin(Request request, final Response response, final Session session) { String path = request.path(); // ?tell/poll??, forgetMe?? if (StringUtils.isNotBlank(path) && (isMsgTellPollUrl(path) || path.startsWith("/forgetMe"))) { return; } // ?? ?cookie?? if (!UserAuthService.isLogin(session)) { Cookie cookie = request.cookie(Constants.COOKIE_REMEMBER_ME); if (null != cookie && StringUtils.isNotBlank(cookie.value())) { final String cookieValue = cookie.value(); JPAUtil.indieTransaction(new IndieTransactionCall() { @Override public void call(EntityManager em) { @SuppressWarnings("unchecked") List<RememberMeInfo> entityList = em.createQuery( "from RememberMeInfo rm left join fetch rm.user where rm.cookieValue = :cookieValue ") .setParameter("cookieValue", cookieValue).getResultList(); if (CollectionUtils.isNotEmpty(entityList)) { RememberMeInfo entity = entityList.get(0); User user = entity.user; Calendar expires = Calendar.getInstance(); expires.add(Calendar.SECOND, -REMEMBER_ME_EXPIRES); // ? if (entity.beginTime.before(expires.getTime())) { em.remove(entity); response.discardCookie(Constants.COOKIE_REMEMBER_ME); } else if (user.lastRMLoginTime != null && user.lastRMLoginTime.getTime() + AUTO_LOGIN_INTERVAL * 1000 > System.currentTimeMillis()) { // ? em.remove(entity); response.discardCookie(Constants.COOKIE_REMEMBER_ME); } else { // ObjectNodeResult loginObjectNodeResult = null; try { loginObjectNodeResult = User.loginByEncryptedPassword(user.getEmail(), user.getEncryptedPassword(), false, UsernameType.EMAIL); } catch (Exception e) { LOGGER.error("fail to loginByEncryptedPassword.", e); } if (null == loginObjectNodeResult || !loginObjectNodeResult.isSuccess()) { em.remove(entity); response.discardCookie(Constants.COOKIE_REMEMBER_ME); } else { User.refreshCurrentLastRMLoginTime(session); } } } else { response.discardCookie(Constants.COOKIE_REMEMBER_ME); } } }); } } }
From source file:com.enioka.jqm.tools.Main.java
private static void importJobDef(String xmlpath) { try {/* w ww . java 2 s . co m*/ EntityManager em = Helpers.getNewEm(); if (em.createQuery("SELECT q FROM Queue q WHERE q.defaultQueue = true").getResultList().size() != 1) { jqmlogger.fatal( "Cannot import a Job Definition when there are no queues defined. Create at least an engine first to create one"); em.close(); return; } String[] pathes = xmlpath.split(","); for (String path : pathes) { XmlJobDefParser.parse(path, em); } em.close(); } catch (Exception e) { throw new JqmRuntimeException("Could not import file", e); } }