List of usage examples for org.hibernate Query setEntity
@Deprecated @SuppressWarnings("unchecked") Query<R> setEntity(String name, Object val);
From source file:com.neu.web.phmis.dao.ResourceDao.java
public List<MedicalStaffBean> getStaff(EnterpriseBean enterpriseBean) { List<MedicalStaffBean> staffList = null; try {//from ww w .j a va 2s . com session = HibernateUtil.getSessionFactory().openSession(); Query query = session.createQuery("from MedicalStaffBean where enterpriseBean = :bean"); query.setEntity("bean", enterpriseBean); staffList = query.list(); } catch (HibernateException e) { session.getTransaction().rollback(); surgeryRequestBean = null; e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } finally { session.close(); return staffList; } }
From source file:com.nominanuda.hibernate.AbstractHibernateStructStore.java
License:Apache License
protected void bind(Query q, String k, Object v) { DataType t = struct.getDataType(v);//from ww w .j av a2s . co m switch (t) { case array: q.setParameterList(k, struct.toMapsAndSetLists((DataArray) v)); break; case object: q.setEntity(k, struct.toMapsAndSetLists((DataObject) v)); break; case string: q.setString(k, (String) v); break; case bool: q.setBoolean(k, (Boolean) v); break; case number: Double d = ((Number) v).doubleValue(); if (Maths.isInteger(d)) { q.setLong(k, d.longValue()); } else { q.setDouble(k, d); } break; default: throw new IllegalArgumentException(t.name()); } }
From source file:com.qcadoo.model.internal.search.SearchQueryImpl.java
License:Open Source License
@Override public void addParameters(final Query query) { for (Map.Entry<String, String> parameter : strings.entrySet()) { query.setString(parameter.getKey(), parameter.getValue()); }//from w ww .j av a 2 s . c om for (Map.Entry<String, Boolean> parameter : booleans.entrySet()) { query.setBoolean(parameter.getKey(), parameter.getValue()); } for (Map.Entry<String, Byte> parameter : bytes.entrySet()) { query.setByte(parameter.getKey(), parameter.getValue()); } for (Map.Entry<String, Short> parameter : shorts.entrySet()) { query.setShort(parameter.getKey(), parameter.getValue()); } for (Map.Entry<String, Integer> parameter : integers.entrySet()) { query.setInteger(parameter.getKey(), parameter.getValue()); } for (Map.Entry<String, Long> parameter : longs.entrySet()) { query.setLong(parameter.getKey(), parameter.getValue()); } for (Map.Entry<String, Float> parameter : floats.entrySet()) { query.setFloat(parameter.getKey(), parameter.getValue()); } for (Map.Entry<String, Double> parameter : doubles.entrySet()) { query.setDouble(parameter.getKey(), parameter.getValue()); } for (Map.Entry<String, BigDecimal> parameter : bigDecimals.entrySet()) { query.setBigDecimal(parameter.getKey(), parameter.getValue()); } for (Map.Entry<String, Date> parameter : dates.entrySet()) { query.setDate(parameter.getKey(), parameter.getValue()); } for (Map.Entry<String, Date> parameter : times.entrySet()) { query.setTime(parameter.getKey(), parameter.getValue()); } for (Map.Entry<String, Date> parameter : timestamps.entrySet()) { query.setTimestamp(parameter.getKey(), parameter.getValue()); } for (Map.Entry<String, Object> parameter : parameters.entrySet()) { query.setParameter(parameter.getKey(), parameter.getValue()); } for (Map.Entry<String, Collection<? extends Object>> parametersList : parameterLists.entrySet()) { query.setParameterList(parametersList.getKey(), parametersList.getValue()); } for (Map.Entry<String, Object> parameter : entities.entrySet()) { query.setEntity(parameter.getKey(), parameter.getValue()); } }
From source file:com.redhat.rhn.domain.config.ConfigurationFactory.java
License:Open Source License
/** * Finds a ConfigRevision for a given ConfigFile and given revision id * @param cf The ConfigFile to look for. * @param revId The ConfigFile revision to look for. * @return ConfigRevision The sought for ConfigRevision. *///from w ww . j a v a 2s . c o m public static ConfigRevision lookupConfigRevisionByRevId(ConfigFile cf, Long revId) { Session session = HibernateFactory.getSession(); Query q = session.getNamedQuery("ConfigRevision.findByRevisionAndConfigFile"); q.setLong("rev", revId.longValue()); q.setEntity("cf", cf); return (ConfigRevision) q.uniqueResult(); }
From source file:com.redhat.rhn.domain.config.ConfigurationFactory.java
License:Open Source License
/** * Finds configuration revisions for a given configuration file * @param cf The ConfigFile to look for. * @return List of configuration revisions for given configuration file. *///w w w . ja va2 s. c o m public static List lookupConfigRevisions(ConfigFile cf) { Session session = HibernateFactory.getSession(); Query q = session.getNamedQuery("ConfigRevision.findByConfigFile"); q.setEntity("cf", cf); return q.list(); }
From source file:com.redhat.rhn.domain.kickstart.KickstartFactory.java
License:Open Source License
/** * Set the kickstart session history message. * * Java version of the stored procedure set_ks_session_history_message. This procedure * attempted to iterate all states with the given label, but these are unique and * this method will not attempt to do the same. * * @param ksSession/* ww w .j a v a 2 s. c om*/ * @param stateLabel */ // TODO: Find a better location for this method. private static void setKickstartSessionHistoryMessage(KickstartSession ksSession, KickstartSessionState state, String message) { Session session = HibernateFactory.getSession(); Query q = session.getNamedQuery("KickstartSessionHistory.findByKickstartSessionAndState"); q.setEntity("state", state); q.setEntity("kickstartSession", ksSession); List results = q.list(); Iterator iter = results.iterator(); while (iter.hasNext()) { KickstartSessionHistory history = (KickstartSessionHistory) iter.next(); history.setMessage(message); } ksSession.addHistory(state, message); }
From source file:com.redhat.rhn.manager.action.test.ActionManagerTest.java
License:Open Source License
public void assertServerActionCount(Action parentAction, int expected) { Session session = HibernateFactory.getSession(); Query query = session.createQuery("from ServerAction sa where " + "sa.parentAction = :parent_action"); query.setEntity("parent_action", parentAction); List results = query.list();/* w w w. j a v a 2 s. com*/ int initialSize = results.size(); assertEquals(expected, initialSize); }
From source file:com.redhat.rhn.manager.action.test.ActionManagerTest.java
License:Open Source License
public void assertServerActionCount(User user, int expected) { Session session = HibernateFactory.getSession(); Query query = session.createQuery("from ServerAction sa where " + "sa.parentAction.schedulerUser = :user"); query.setEntity("user", user); List results = query.list();// w w w .j av a2s. c om int initialSize = results.size(); assertEquals(expected, initialSize); }
From source file:com.redhat.rhn.manager.action.test.ActionManagerTest.java
License:Open Source License
public void assertActionsForUser(User user, int expected) throws Exception { Session session = HibernateFactory.getSession(); Query query = session.createQuery("from Action a where a.schedulerUser = :user"); query.setEntity("user", user); List results = query.list();/* w w w . j a va 2s . com*/ int initialSize = results.size(); assertEquals(expected, initialSize); }
From source file:com.redhat.rhn.manager.action.test.ActionManagerTest.java
License:Open Source License
public void testCancelKickstartAction() throws Exception { Session session = HibernateFactory.getSession(); User user = UserTestUtils.findNewUser("testUser", "testOrg" + this.getClass().getSimpleName()); user.addPermanentRole(RoleFactory.ORG_ADMIN); UserFactory.save(user);/*from ww w. j av a 2 s. co m*/ Action parentAction = createActionWithServerActions(user, 1); Server server = parentAction.getServerActions().iterator().next().getServer(); ActionFactory.save(parentAction); KickstartDataTest.setupTestConfiguration(user); KickstartData ksData = KickstartDataTest.createKickstartWithOptions(user.getOrg()); KickstartSession ksSession = KickstartSessionTest.createKickstartSession(server, ksData, user, parentAction); TestUtils.saveAndFlush(ksSession); ksSession = (KickstartSession) reload(ksSession); List actionList = createActionList(user, new Action[] { parentAction }); Query kickstartSessions = session.createQuery("from KickstartSession ks where ks.action = :action"); kickstartSessions.setEntity("action", parentAction); List results = kickstartSessions.list(); assertEquals(1, results.size()); assertEquals(1, ksSession.getHistory().size()); KickstartSessionHistory history = (KickstartSessionHistory) ksSession.getHistory().iterator().next(); assertEquals("created", history.getState().getLabel()); ActionManager.cancelActions(user, actionList); // New history entry should have been created: assertEquals(2, ksSession.getHistory().size()); // Test that the kickstart wasn't deleted but rather marked as failed: assertEquals("failed", ksSession.getState().getLabel()); }