Package org.hibernate

Examples of org.hibernate.Query


  public CategoryIF createCategory(CategoryIF parent, String title) {
    return createCategory(parent, title, null);
  }
 
  public CategoryIF createCategory(CategoryIF parent, String title, String domain) {
    Query query = session.createQuery("from Category as cat where cat.title = ? and cat.domain = ? ");
    query.setString(0, title);
    query.setString(1, domain);
    CategoryIF cat = (CategoryIF) query.uniqueResult();
    if (cat == null) {
      cat = new Category(title);
      cat.setDomain(domain);
      if (parent != null) {
        parent.addChild(cat);
View Full Code Here


  }

  @SuppressWarnings("unchecked")
  public List<PrintTemplate> findAll() throws IOException {
    try {
      Query q = sessionFactory.getCurrentSession().createQuery("from PrintTemplate");
      return q.list();
    } catch (HibernateException e) {
      throw new IOException("find all print template names failed", e);
    }
  }
View Full Code Here

      boolean doLog = Tracing.isDebugEnabled(DBManager.class);
      long start = 0;
      if (doLog) start = System.currentTimeMillis();

      // old: li = this.getSession().find(query, value, type);
      Query qu = this.getSession().createQuery(query);
      qu.setParameter(0, value, type);
      li = qu.list();
     
      if (doLog) {
        long time = (System.currentTimeMillis() - start);
        logQuery("find (time "+time+", res " +(li == null? "null": ""+li.size())+")(trans "+trx.hashCode()+")", new Object[] {value}, new Type[] {type}, query)
      }
View Full Code Here

    try {
      boolean doLog = Tracing.isDebugEnabled(DBManager.class);
      long start = 0;
      if (doLog) start = System.currentTimeMillis();
      // old: li = getSession().find(query, values, types);
      Query qu = this.getSession().createQuery(query);
      qu.setParameters(values, types);
      li = qu.list();
     
     
      if (doLog) {
        long time = (System.currentTimeMillis() - start);
        logQuery("find (time "+time+", res " +(li == null? "null": ""+li.size())+")(trans "+trx.hashCode()+")", values, types, query)
View Full Code Here

    try {
      boolean doLog = Tracing.isDebugEnabled(DBManager.class);
      long start = 0;
      if (doLog) start = System.currentTimeMillis();
      // old: li = getSession().find(query);
      Query qu = this.getSession().createQuery(query);
      li = qu.list();

      if (doLog) {
        long time = (System.currentTimeMillis() - start);
        logQuery("find (time "+time+", res " +(li == null? "null": ""+li.size())+")(trans "+trx.hashCode()+")", null, null, query)
      }
View Full Code Here

  /**
   * @param query
   * @return Hibernate Query object.
   */
  DBQuery createQuery(String query) {
    Query q = null;
    DBQuery dbq = null;
    try {
      q = this.getSession().createQuery(query);
      dbq = new DBQueryImpl(q);
    } catch (HibernateException he) {
View Full Code Here

  int delete(String query, Object value, Type type) {
    int deleted = 0;
    try {
      // old: deleted = getSession().delete(query, value, type);
      Session si = getSession();
      Query qu = si.createQuery(query);
      qu.setParameter(0, value, type);
      List foundToDel = qu.list();
      int deletionCount = foundToDel.size();
      for (int i = 0; i < deletionCount; i++ ) {
        si.delete( foundToDel.get(i) );
      }
      ////
View Full Code Here

    }
    try {
      //old: deleted = getSession().delete(query, value, type);
     
      Session si = getSession();
      Query qu = si.createQuery(query);
      qu.setParameter(0, value, type);
      List foundToDel = qu.list();
      int deletionCount = foundToDel.size();
      for (int i = 0; i < deletionCount; i++ ) {
        si.delete( foundToDel.get(i) );
      }
     
View Full Code Here

      throw new DBRuntimeException("cannot delete in a transaction that is rolledback or committed " + values);
    }
    try {
      //old: deleted = getSession().delete(query, values, types);
      Session si = getSession();
      Query qu = si.createQuery(query);
      qu.setParameters(values, types);
      List foundToDel = qu.list();
      int deletionCount = foundToDel.size();
      for (int i = 0; i < deletionCount; i++ ) {
        si.delete( foundToDel.get(i) );
      }
     
View Full Code Here

  public synchronized TableModel queryData(final String query, final DataRow parameters)
      throws ReportDataFactoryException
  {
    try
    {
      final Query pstmt = getSession().createQuery(query);
      final String[] params = pstmt.getNamedParameters();
      for (int i = 0; i < params.length; i++)
      {
        final String param = params[i];
        final Object pvalue = parameters.get(param);
        if (pvalue == null)
        {
          // this should work, but some driver are known to die here.
          // they should be fed with setNull(..) instead; something
          // we cant do as JDK1.2's JDBC does not define it.
          pstmt.setParameter(param, null);
        }
        else
        {
          pstmt.setParameter(param, pvalue);
        }
      }
      final Object queryLimit = parameters.get(DataFactory.QUERY_LIMIT);
      if (queryLimit instanceof Number)
      {
        final Number i = (Number) queryLimit;
        if (i.intValue() >= 0)
        {
          pstmt.setMaxResults(i.intValue());
        }
      }
      final Object queryTimeout = parameters.get(DataFactory.QUERY_TIMEOUT);
      if (queryTimeout instanceof Number)
      {
        final Number i = (Number) queryLimit;
        if (i.intValue() >= 0)
        {
          pstmt.setTimeout(i.intValue());
        }
      }
      final ScrollableResults res = pstmt.scroll(ScrollMode.FORWARD_ONLY);
      return generateDefaultTableModel(res, pstmt.getReturnAliases());
    }
    catch (Exception e)
    {
      throw new ReportDataFactoryException("Failed at query: " + query, e);
    }
View Full Code Here

TOP

Related Classes of org.hibernate.Query

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.