Java Code Examples for org.hibernate.Query#setEntity()
The following examples show how to use
org.hibernate.Query#setEntity() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UserConfigDAO.java From document-management-system with GNU General Public License v2.0 | 6 votes |
/** * Update user config profile */ public static void updateProfile(String ucUser, int upId) throws DatabaseException { log.debug("updateProfile({}, {})", ucUser, upId); String qs = "update UserConfig uc set uc.profile=:profile where uc.user=:user"; Session session = null; Transaction tx = null; try { session = HibernateUtil.getSessionFactory().openSession(); tx = session.beginTransaction(); Query q = session.createQuery(qs); q.setEntity("profile", ProfileDAO.findByPk(upId)); q.setString("user", ucUser); q.executeUpdate(); HibernateUtil.commit(tx); } catch (HibernateException e) { HibernateUtil.rollback(tx); throw new DatabaseException(e.getMessage(), e); } finally { HibernateUtil.close(session); } log.debug("updateProfile: void"); }
Example 2
Source File: KickstartFactory.java From spacewalk with GNU General Public License v2.0 | 6 votes |
/** * 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 * @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); }
Example 3
Source File: ActionManagerTest.java From spacewalk with GNU General Public License v2.0 | 5 votes |
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(); int initialSize = results.size(); assertEquals(expected, initialSize); }
Example 4
Source File: ActionManagerTest.java From spacewalk with GNU General Public License v2.0 | 5 votes |
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(); int initialSize = results.size(); assertEquals(expected, initialSize); }
Example 5
Source File: ActionManagerTest.java From spacewalk with GNU General Public License v2.0 | 5 votes |
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(); int initialSize = results.size(); assertEquals(expected, initialSize); }
Example 6
Source File: ActionManagerTest.java From spacewalk with GNU General Public License v2.0 | 5 votes |
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); 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()); }
Example 7
Source File: ConfigurationFactory.java From spacewalk with GNU General Public License v2.0 | 5 votes |
/** * 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. */ 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(); }
Example 8
Source File: ConfigurationFactory.java From spacewalk with GNU General Public License v2.0 | 5 votes |
/** * Finds configuration revisions for a given configuration file * @param cf The ConfigFile to look for. * @return List of configuration revisions for given configuration file. */ public static List lookupConfigRevisions(ConfigFile cf) { Session session = HibernateFactory.getSession(); Query q = session.getNamedQuery("ConfigRevision.findByConfigFile"); q.setEntity("cf", cf); return q.list(); }
Example 9
Source File: DbManager.java From megatron-java with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") public List<MailJob> searchMailJobs(Job job) throws DbException { try { Query query = session.createQuery("from MailJob where Job = ?"); query.setEntity(0, job); return query.list(); } catch (Exception e) { throw handleException(e.getClass().getSimpleName() + " exception in searchMailJobs", e); } }