List of usage examples for org.hibernate Session getNamedQuery
org.hibernate.Query getNamedQuery(String queryName);
From source file:com.ibm.tap.misld.report.PriceReportDelegate.java
/** * @param priceReportCycle// ww w . j av a 2s . c om * @return * @throws NamingException * @throws HibernateException */ private static List getPriceReportArchiveList(PriceReportCycle priceReportCycle) throws HibernateException, NamingException { List priceReportArchiveList = null; Session session = getHibernateSession(); priceReportArchiveList = session.getNamedQuery("getPriceReportArchive") .setEntity("priceReportCycle", priceReportCycle).list(); session.close(); return priceReportArchiveList; }
From source file:com.ibm.tap.misld.report.PriceReportDelegate.java
/** * @param unlockCustomers/*from w w w . ja v a 2 s. com*/ * @throws NamingException * @throws HibernateException */ public static void InactivatePriceReportCycle(ArrayList unlockCustomers) throws HibernateException, NamingException { Session session = getHibernateSession(); Transaction tx = session.beginTransaction(); session.getNamedQuery("inactivatePriceReportCycle").setParameterList("customers", unlockCustomers) .executeUpdate(); tx.commit(); session.close(); }
From source file:com.ibm.tap.misld.report.PriceReportDelegate.java
/** * @param poForm//from w w w . j a v a 2s . co m * @throws NamingException * @throws HibernateException * @throws SQLException */ public static void acceptSplaMoet(String usageDate) throws NamingException, HibernateException { Session session = getHibernateSession(); Transaction tx = session.beginTransaction(); session.getNamedQuery("acceptSplaMoet").setString("usageDate", usageDate).executeUpdate(); tx.commit(); session.close(); }
From source file:com.ibm.tap.misld.report.PriceReportDelegate.java
/** * @return/*from w w w .ja va 2s . co m*/ * @throws NamingException * @throws HibernateException */ private static List getPriceReportNotificationReport() throws HibernateException, NamingException { List notificationList = null; Vector returnList = new Vector(); Session session = getHibernateSession(); notificationList = session.getNamedQuery("getPriceReportNotificationReport").list(); session.close(); Iterator i = notificationList.iterator(); while (i.hasNext()) { Object[] pair = (Object[]) i.next(); String podName = (String) pair[0]; String status = (String) pair[1]; Integer count = (Integer) pair[2]; PriceReportNotificationReport prnr = new PriceReportNotificationReport(podName, status, count.longValue()); returnList.add(prnr); } return returnList; }
From source file:com.ibm.tap.misld.report.PriceReportDelegate.java
/** * @param customer/*from ww w. j av a2 s.c o m*/ * @return * @throws NamingException * @throws HibernateException */ public static List getPriceReportCycles(Customer customer) throws HibernateException, NamingException { List priceReportCycles = null; Session session = getHibernateSession(); priceReportCycles = session.getNamedQuery("getPriceReportCycles").setEntity("customer", customer).list(); session.close(); Iterator i = priceReportCycles.iterator(); Vector returnVector = new Vector(); while (i.hasNext()) { Object[] pair = (Object[]) i.next(); Long priceReportCycleId = (Long) pair[0]; Date recordTime = (Date) pair[1]; PriceReportCycle priceReportCycle = new PriceReportCycle(); priceReportCycle.setPriceReportCycleId(priceReportCycleId); priceReportCycle.setCustomer(customer); priceReportCycle.setRecordTime(recordTime); returnVector.add(priceReportCycle); } return returnVector; }
From source file:com.ibm.tap.misld.report.PriceReportDelegate.java
/** * @param priceReportCycleId//w ww . j a va 2 s . c o m * @return * @throws NamingException * @throws HibernateException */ public static PriceReportCycle getPriceReportCycle(Long priceReportCycleId) throws HibernateException, NamingException { PriceReportCycle priceReportCycle = null; Session session = getHibernateSession(); priceReportCycle = (PriceReportCycle) session.getNamedQuery("getPriceReportCycle") .setLong("priceReportCycleId", priceReportCycleId.longValue()).uniqueResult(); session.close(); return priceReportCycle; }
From source file:com.imos.sample.model.PersonDAO.java
public PersonDAO setNamedQuery(Session session, String namedPersonDAO) { query = session.getNamedQuery(namedPersonDAO); return this; }
From source file:com.ipn.dao.UsuarioDAO.java
public Usuario login(String username, String password) throws HibernateException { Session session = HibernateUtil.getSessionFactory().getCurrentSession(); Transaction transaction = session.getTransaction(); Usuario u = null;//w w w . j ava2 s . co m try { transaction.begin(); Query q = session.getNamedQuery("userLoginU"); q.setParameter("username", username); q.setParameter("pass", password); // Obtener el usuario que ha ingresado su sesion u = (Usuario) q.uniqueResult(); transaction.commit(); } catch (HibernateException e) { if (transaction != null && transaction.isActive()) transaction.rollback(); } return u; }
From source file:com.jaspersoft.jasperserver.api.metadata.common.service.impl.hibernate.HibernateRepositoryServiceImpl.java
License:Open Source License
@Transactional(propagation = Propagation.REQUIRED) public List<ResourceLookup> getDependentResources(ExecutionContext context, String uri, SearchCriteriaFactory searchCriteriaFactory, int current, int max) { final Resource resource = getResource(context, uri); if (resource == null) { throw new JSException("jsexception.resource.does.not.exist"); }//from www . j ava2s.com if (resource instanceof ReportDataSource) { //ReportDataSource can have dependent ReportUnit items final ReportDataSource dataSource = (ReportDataSource) resource; RepoResource repoDS = findByURI(RepoResource.class, uri, true); Session session = getHibernateTemplate().getSessionFactory().getCurrentSession(); //TODO GetDependentResourcesIds query can be updated to handle ReportUnit objects too org.hibernate.Query query = session.getNamedQuery("GetDependentResourcesIds"); query.setEntity("dependency", repoDS).setFirstResult(current); if (max > 0) { query.setMaxResults(max); } List<Long> depRes = query.list(); List<ResourceLookup> depResLookup = getResourcesByIdList(depRes); return depResLookup; //TODO delete if code above proves to work fine // SearchFilter filter = new SearchFilter() { // public void applyRestrictions(String type, ExecutionContext context, SearchCriteria criteria) { // DetachedCriteria dsCriteria = criteria.createCriteria("dataSource", "ds"); // dsCriteria.add(Restrictions.eq("ds.name", dataSource.getName())); // // DetachedCriteria dsParent = dsCriteria.createCriteria("parent", "dsParent"); // dsParent.add(Restrictions.eq("dsParent.URI", dataSource.getParentFolder())); // // // will use it later on for sorting // DetachedCriteria folderCriteria = criteria.createCriteria("parent", "f"); // } // }; // // SearchSorter sorter = new SearchSorter() { // public void applyOrder(String type, ExecutionContext context, SearchCriteria criteria) { // criteria.addOrder(Order.asc("f.URI")); // criteria.addOrder(Order.asc("name")); // // by default we retrieving only id's and to be able sort we had to add property to select clause // criteria.addProjection(Projections.property("f.URI")); // criteria.addProjection(Projections.property("name")); // } // }; // SearchCriteriaFactory criteriaFactory = searchCriteriaFactory.newFactory(ReportUnit.class.getName()); // List<ResourceLookup> resources = getResources( // context, // criteriaFactory, // Arrays.asList(filter), // sorter, // new BasicTransformerFactory(), // current, max); // // return resources; //TODO: replace 'exist' with right solution, it's hardcoded fix for CE version } else if (resource instanceof ReportUnit && exist("com.jaspersoft.ji.adhoc.DashboardResource")) { //ReportUnit can have dependent DashboardResource items final RepoResource repoResource = getRepoResource(resource); SearchFilter filter = new SearchFilter() { public void applyRestrictions(String type, ExecutionContext context, SearchCriteria criteria) { DetachedCriteria resourcesCriteria = criteria.createCriteria("resources", "res"); resourcesCriteria.add(Restrictions.eq("res.id", repoResource.getId())); } }; SearchSorter sorter = new SearchSorter() { @Override protected void addOrder(String type, ExecutionContext context, SearchCriteria criteria) { criteria.addOrder(Order.asc("name")).addOrder(Order.asc("id")); } @Override protected void addProjection(String type, ExecutionContext context, SearchCriteria criteria) { } }; SearchCriteriaFactory criteriaFactory = searchCriteriaFactory .newFactory("com.jaspersoft.ji.adhoc.DashboardResource"); List<ResourceLookup> resources = getResources(context, criteriaFactory, Arrays.asList(filter), sorter, new BasicTransformerFactory(), current, max); return resources; } else { return null; //unsupported resource } }
From source file:com.jaspersoft.jasperserver.api.metadata.common.service.impl.hibernate.HibernateRepositoryServiceImpl.java
License:Open Source License
@Transactional(propagation = Propagation.REQUIRED, readOnly = false) public void replaceFileResourceData(final String uri, DataContainer data) { final long resourceId = findResourceId(uri, FileResource.class); if (log.isDebugEnabled()) { log.debug("replacing file resource data at " + uri); }/*from w ww . jav a 2 s.c o m*/ final byte[] dataBytes = data.getData(); // we're using a batch update so that the version does not get incremented. getHibernateTemplate().execute(new HibernateCallback<Void>() { public Void doInHibernate(Session session) throws HibernateException, SQLException { int count = session.getNamedQuery("FileResourceReplaceDataById").setLong("id", resourceId) .setBinary("data", dataBytes).executeUpdate(); if (log.isDebugEnabled()) { log.debug("update " + count + " records for resource " + uri); } if (count == 0) { throw new JSException( "Failed to update file resource data at " + uri + " with id " + resourceId); } if (count > 1) { // should not get here, but protect against any accidents throw new RuntimeException( "Replacing file resource data at " + uri + " updated " + count + " records"); } return null; } }); }