List of usage examples for org.hibernate Query setLong
@Deprecated @SuppressWarnings("unchecked") default Query<R> setLong(String name, long val)
From source file:de.unisb.cs.st.javalanche.mutation.testsuite.DeleteTest.java
License:Open Source License
private void checkLinkTablesFailing(Long resultID) { Session session = HibernateUtil.getSessionFactory().openSession(); Transaction tx = session.beginTransaction(); Query q = session .createSQLQuery(" SELECT * FROM MutationTestResult_TestMessage S WHERE MutationTestResult_id=:id") .addEntity(MutationTestResult.class); q.setLong("id", resultID); int resultSize = q.list().size(); tx.commit();/*from www. ja v a2 s. c om*/ session.close(); Assert.assertEquals("Expecting result to be deleted", 0, resultSize); }
From source file:de.unisb.cs.st.javalanche.mutation.testsuite.DeleteTest.java
License:Open Source License
private void checkLinkTablesPassing(Long resultID) { Session session = HibernateUtil.getSessionFactory().openSession(); Transaction tx = session.beginTransaction(); Query q = session .createSQLQuery("SELECT * FROM MutationTestResult_Passing S WHERE MutationTestResult_id=:id") .addEntity(MutationTestResult.class); q.setLong("id", resultID); int resultSize = q.list().size(); tx.commit();/* w ww . j a v a 2 s.com*/ session.close(); Assert.assertEquals("Expecting result to be deleted", 0, resultSize); }
From source file:de.unisb.cs.st.javalanche.mutation.util.ShowMutation.java
License:Open Source License
/** * Fetches one a mutation from the database an prints it to the console. * //w w w .j a va 2 s . c om * @param id * the id of the mutation to print */ @SuppressWarnings("unchecked") private static void showMutation(long id) { SessionFactory sessionFactory = HibernateServerUtil.getSessionFactory(HibernateServerUtil.Server.HOBEL); QueryManager.setSessionFactory(sessionFactory); Session session = sessionFactory.openSession(); Transaction tx = session.beginTransaction(); Query query = session.createQuery("FROM Mutation WHERE id = :id"); query.setLong("id", id); @SuppressWarnings("unchecked") List<Mutation> mutations = query.list(); int count = 0; for (Mutation mutation : mutations) { System.out.println((count++) + " " + mutation); System.out.println("TestCases for mutation: " + MutationCoverageFile.getCoverageData(mutation).size()); boolean coveredMutation = QueryManager.isCoveredMutation(mutation); System.out.println("Is covered: " + coveredMutation); } tx.commit(); session.close(); }
From source file:de.xirp.db.ChartDatabaseUtil.java
License:Open Source License
/** * Returns all {@link de.xirp.db.Observed} for the * given record, key name and time interval. * //from w w w.j a va 2s. c om * @param record * The record to look in. * @param keyname * The name of the observed key. * @param startTime * The start time of the time interval. * @param stopTime * the stop tine of the time interval. * @return A list with all <code>Observed</code> for the record, * key and time interval. * @see de.xirp.db.Observed */ @SuppressWarnings("unchecked") public static List<Observed> getObservedList(Record record, String keyname, long startTime, long stopTime) { Session session = DatabaseManager.getCurrentHibernateSession(); session.getTransaction().begin(); Query query = session.createQuery( "FROM Observed as obs WHERE obs.record = ? and obs.observedKey = ? and obs.timestamp >= ? and obs.timestamp <= ?"); //$NON-NLS-1$ query.setEntity(0, record); query.setString(1, keyname); query.setLong(2, startTime); query.setLong(3, stopTime); List<Observed> obs = query.list(); session.close(); return Collections.unmodifiableList(obs); }
From source file:de.xirp.db.ChartDatabaseUtil.java
License:Open Source License
/** * Returns all key names for a given record id. * /* www . ja va 2 s .co m*/ * @param id * The record id. * @return A list with the available keys for this record. */ @SuppressWarnings("unchecked") public static List<String> getObservedKeysForRecordID(long id) { Session session = DatabaseManager.getCurrentHibernateSession(); session.getTransaction().begin(); Query query = session .createQuery("SELECT DISTINCT obs.observedKey FROM Observed as obs WHERE obs.record = ?"); //$NON-NLS-1$ query.setLong(0, new Long(id)); List<String> keys = query.list(); session.close(); return Collections.unmodifiableList(keys); }
From source file:de.xirp.db.ChartDatabaseUtil.java
License:Open Source License
/** * Returns all {@link de.xirp.db.Observed} for the * given record id.//from ww w . j a v a 2 s. co m * * @param id * The record id. * @return A list with all <code>Observed</code> for the record. * @see de.xirp.db.Observed */ @SuppressWarnings("unchecked") public static List<Observed> getObservedListForRecordID(long id) { Session session = DatabaseManager.getCurrentHibernateSession(); session.getTransaction().begin(); Query query = session.createQuery("FROM Observed as obs WHERE obs.record = ?"); //$NON-NLS-1$ query.setLong(0, new Long(id)); List<Observed> keys = query.list(); session.close(); return Collections.unmodifiableList(keys); }
From source file:de.xirp.db.ReportDatabaseUtil.java
License:Open Source License
/** * Returns a {@link de.xirp.report.ReportDescriptor} * for the given id./*from w w w. ja v a 2 s .co m*/ * * @param id * The report id. * @return The report descriptor. * @see de.xirp.report.ReportDescriptor */ public static ReportDescriptor getReport(long id) { Session session = DatabaseManager.getCurrentHibernateSession(); session.getTransaction().begin(); Query query = session.createQuery("FROM ReportDescriptor as report WHERE report.id = ?"); //$NON-NLS-1$ query.setLong(0, id); ReportDescriptor rd = (ReportDescriptor) query.uniqueResult(); session.close(); return rd; }
From source file:de.xirp.db.ReportDatabaseUtil.java
License:Open Source License
/** * Starts a search in the database and returns all report * descriptors fitting the search parameters. The parameters are * the given start and stop time and the robot name. If the robot * name is <code>null</code> or empty the method will return the * reports found in the specified time interval for all existing * robots.//w w w . j a v a 2 s .c o m * * @param start * The start time of the search interval. * @param stop * the stop time of the search interval. * @param robotName * The robot name to search reports for. * @return A list of report descriptors. * @see de.xirp.report.ReportDescriptor */ @SuppressWarnings("unchecked") public static List<ReportDescriptor> searchForReports(Date start, Date stop, String robotName) { Session session = DatabaseManager.getCurrentHibernateSession(); session.getTransaction().begin(); Query query; if (!Util.isEmpty(robotName)) { query = session.createQuery( "FROM ReportDescriptor as report WHERE report.creationTime > ? AND report.creationTime < ? AND report.robotName = ?"); //$NON-NLS-1$ query.setLong(0, start.getTime()); query.setLong(1, stop.getTime()); query.setString(2, robotName); } else { query = session.createQuery( "FROM ReportDescriptor as report WHERE report.creationTime > ? AND report.creationTime < ?"); //$NON-NLS-1$ query.setLong(0, start.getTime()); query.setLong(1, stop.getTime()); } List<ReportDescriptor> names = query.list(); session.close(); return Collections.unmodifiableList(names); }
From source file:edu.common.dynamicextensions.entitymanager.EntityManager.java
License:BSD License
/** * This method substitues the parameters from substitutionParameterMap into the input query. * @param substitutionParameterMap// ww w . j a v a2s . c om * @throws HibernateException */ private Query substitutionParameterForQuery(Session session, String queryName, Map substitutionParameterMap) throws HibernateException { Query q = session.getNamedQuery(queryName); for (int counter = 0; counter < substitutionParameterMap.size(); counter++) { HQLPlaceHolderObject hPlaceHolderObject = (HQLPlaceHolderObject) substitutionParameterMap .get(counter + ""); String objectType = hPlaceHolderObject.getType(); if (objectType.equals("string")) { q.setString(counter, hPlaceHolderObject.getValue() + ""); } else if (objectType.equals("integer")) { q.setInteger(counter, Integer.parseInt(hPlaceHolderObject.getValue() + "")); } else if (objectType.equals("long")) { q.setLong(counter, Long.parseLong(hPlaceHolderObject.getValue() + "")); } else if (objectType.equals("boolean")) { q.setBoolean(counter, Boolean.parseBoolean(hPlaceHolderObject.getValue() + "")); } } return q; }
From source file:edu.depaul.armada.dao.ContainerDaoHibernate.java
License:Open Source License
/** * Returns a List<Container> of a limited number of Containers with a specific id. * @param id long/*from w w w .j av a 2 s. c o m*/ * @param int count * @return List<Container> */ @Override public List<Container> get(long id, int count) { Query query = sessionFactory.getCurrentSession().createQuery("from Container where id > :id"); query.setLong("id", id); query.setMaxResults(count); return query.list(); }