Example usage for org.hibernate CacheMode GET

List of usage examples for org.hibernate CacheMode GET

Introduction

In this page you can find the example usage for org.hibernate CacheMode GET.

Prototype

CacheMode GET

To view the source code for org.hibernate CacheMode GET.

Click Source Link

Document

The session may read items from the cache, but will not add items, except to invalidate items when updates occur.

Usage

From source file:com.heliosapm.aa4h.parser.XMLQueryParser.java

License:Apache License

/**
 * Initializes a Criteria Query./*  w  w w .  j a v a  2 s. c o  m*/
 * Mandatory Attributes:<ul>
 * <li><b>name</b>: The unqualified class name driving the criteria query.</li>
 * </ul>
 * Optional Attributes:<ul>
 * <li><b>prefix</b>: The package name of the class driving the criteria query. If null, no package is assumed.</li>
 * <li><b>maxSize</b>: The maximum number of rows to return from the database.</li>
 * <li><b>fetchSize</b>: The number of rows to fetch when rows are requested. Usually not useful for AA4H.</li>
 * <li><b>cacheEnabled</b>: Enables or disables caching for the queried objects.</li>
 * <li><b>cacheMode</b>: The cache options for the queried objects.</li>
 * <li><b>flushMode</b>: The session flush options.</li>
 * <li><b>fetchMode</b>: The collection fetch options for the query.</li>
 * <li><b>lockMode</b>: The row lock options for the queried rows.</li>
 * <li><b>timeOut</b>: The query timeout option.</li>
 * <li><b>rowCountOnly</b>: Returns a count of the query rows only.</li>
 * </ul>
 * @param attrs The attributes of the processed node.
 * @return An appended or new CriteriaSpecification
 * @throws SAXException
 */
protected CriteriaSpecification processCriteria(Attributes attrs) throws SAXException {
    if (inDetached) {
        return criteriaStack.peek();
    }
    String name = attrs.getValue("name");
    String prefix = attrs.getValue("prefix");
    if (prefix != null) {
        className = prefix + "." + name;
    } else {
        className = name;
    }
    String maxSize = attrs.getValue("maxSize");
    String fetchSize = attrs.getValue("fetchSize");
    String firstResult = attrs.getValue("firstResult");
    String cacheEnabled = attrs.getValue("cacheEnabled");
    String cacheMode = attrs.getValue("cacheMode");
    String flushMode = attrs.getValue("flushMode");
    String fetchMode = attrs.getValue("fetchMode");
    String lockMode = attrs.getValue("lockMode");
    String timeOut = attrs.getValue("timeOut");
    String rowCountOnly = attrs.getValue("rowCountOnly");
    Criteria newCriteria = null;
    try {
        if (criteriaStack.size() == 0) {
            newCriteria = session.createCriteria(className);
        } else {
            newCriteria = ((Criteria) criteriaStack.peek()).createCriteria(className);
        }
        criteriaStack.push(newCriteria);
        if ("true".equalsIgnoreCase(rowCountOnly)) {
            newCriteria.setProjection(Projections.projectionList().add(Projections.rowCount())

            );
            setRowCountOnly(true);
        }
        if (maxSize != null && isRowCountOnly() == false) {
            newCriteria.setMaxResults(Integer.parseInt(maxSize));
        }
        if (fetchSize != null && isRowCountOnly() == false) {
            newCriteria.setFetchSize(Integer.parseInt(fetchSize));
        }
        if (firstResult != null && isRowCountOnly() == false) {
            newCriteria.setFirstResult(Integer.parseInt(firstResult));
        }
        if (timeOut != null) {
            newCriteria.setTimeout(Integer.parseInt(timeOut));
        }

        if ("true".equalsIgnoreCase(cacheEnabled)) {
            newCriteria.setCacheable(true);
        } else if ("false".equalsIgnoreCase(cacheEnabled)) {
            newCriteria.setCacheable(false);
        }
        if (fetchMode != null && fetchMode.length() > 0) {
            if ("JOIN".equalsIgnoreCase(fetchMode)) {
                newCriteria.setFetchMode(name, FetchMode.JOIN);
            } else if ("SELECT".equalsIgnoreCase(fetchMode)) {
                newCriteria.setFetchMode(name, FetchMode.SELECT);
            } else {
                newCriteria.setFetchMode(name, FetchMode.DEFAULT);
            }
        } else {
            newCriteria.setFetchMode(name, FetchMode.DEFAULT);
        }
        if (cacheMode != null && cacheMode.length() > 0) {
            if ("GET".equalsIgnoreCase(cacheMode)) {
                newCriteria.setCacheMode(CacheMode.GET);
            } else if ("IGNORE".equalsIgnoreCase(cacheMode)) {
                newCriteria.setCacheMode(CacheMode.IGNORE);
            } else if ("NORMAL".equalsIgnoreCase(cacheMode)) {
                newCriteria.setCacheMode(CacheMode.NORMAL);
            } else if ("PUT".equalsIgnoreCase(cacheMode)) {
                newCriteria.setCacheMode(CacheMode.PUT);
            } else if ("REFRESH".equalsIgnoreCase(cacheMode)) {
                newCriteria.setCacheMode(CacheMode.REFRESH);
            } else {
                newCriteria.setCacheMode(CacheMode.NORMAL);
            }
        }
        if (lockMode != null && lockMode.length() > 0) {
            if ("NONE".equalsIgnoreCase(lockMode)) {
                newCriteria.setLockMode(LockMode.NONE);
            } else if ("READ".equalsIgnoreCase(lockMode)) {
                newCriteria.setLockMode(LockMode.READ);
            } else if ("UPGRADE".equalsIgnoreCase(lockMode)) {
                newCriteria.setLockMode(LockMode.UPGRADE);
            } else if ("UPGRADE_NOWAIT".equalsIgnoreCase(lockMode)) {
                newCriteria.setLockMode(LockMode.UPGRADE_NOWAIT);
            } else if ("WRITE".equalsIgnoreCase(lockMode)) {
                newCriteria.setLockMode(LockMode.WRITE);
            } else {
                throw new SAXException("lockMode[" + lockMode + "] Not Recognized");
            }
        }
        if (flushMode != null && flushMode.length() > 0) {
            if ("ALWAYS".equalsIgnoreCase(flushMode)) {
                newCriteria.setFlushMode(FlushMode.ALWAYS);
            } else if ("AUTO".equalsIgnoreCase(flushMode)) {
                newCriteria.setFlushMode(FlushMode.AUTO);
            } else if ("COMMIT".equalsIgnoreCase(flushMode)) {
                newCriteria.setFlushMode(FlushMode.COMMIT);
            } else if ("NEVER".equalsIgnoreCase(flushMode)) {
                // NEVER is deprecated, so we won't throw an exception but we'll ignore it.
            } else {
                throw new SAXException("flushMode[" + flushMode + "] Not Recognized");
            }
        }
        return newCriteria;

    } catch (Exception e) {
        throw new SAXException("Unable to configure class " + className, e);
    }
}

From source file:com.sap.data.db.dao.BapiDD03LDao.java

public List<BapiDD03LPojo> select() throws NotFoundException {
    List<BapiDD03LPojo> list = null;
    Session session = null;//from   w w w  .ja v a 2s.  c  o  m
    try {
        session = HibernateUtil.getSession();
        session.setCacheMode(CacheMode.GET);
        list = session.createCriteria("BapiDD03LPojo").addOrder(Order.asc("id.TABNAME"))
                .addOrder(Order.asc("id.FIELDNAME")).addOrder(Order.asc("id.AS4LOCAL"))
                .addOrder(Order.asc("id.AS4VERS")).addOrder(Order.asc("id.POSITION")).list();
    } catch (HibernateException ex) {
        Logger.getLogger(BapiDD03LDao.class.getName()).log(Level.SEVERE, null, ex);
        throw new NotFoundException(ex.getMessage());
    } finally {
        HibernateUtil.close(session);
    }
    return list;
}

From source file:com.sap.data.db.dao.BapiDD03LDao.java

public List<BapiDD03LPojo> selectTabFields(String tabName) throws NotFoundException {
    List<BapiDD03LPojo> list = null;
    Session session = null;/*from w  w w  . j  a v  a2s  .c  om*/
    try {
        session = HibernateUtil.getSession();
        session.setCacheMode(CacheMode.GET);
        list = session.createCriteria("BapiDD03LPojo").add(Restrictions.eq("id.TABNAME", tabName))
                .addOrder(Order.asc("id.POSITION")).list();
    } catch (HibernateException ex) {
        Logger.getLogger(BapiDD03LDao.class.getName()).log(Level.SEVERE, null, ex);
        throw new NotFoundException(ex.getMessage());
    } finally {
        HibernateUtil.close(session);
    }
    return list;
}

From source file:com.sap.data.db.dao.BapiDD03LDMDao.java

public List<BapiDD03LDMPojo> selectKeyFields(String tabName) throws NotFoundException {
    List<BapiDD03LDMPojo> list = null;
    Session session = null;//from   w  w w.ja v  a2  s . co m
    try {
        session = HibernateUtil.getSession();
        session.setCacheMode(CacheMode.GET);
        list = session.createCriteria("BapiDD03LDMPojo").add(Restrictions.eq("id.TABNAME", tabName))
                .add(Restrictions.eq("DM_KEYFLAG", "X")).list();
    } catch (HibernateException ex) {
        Logger.getLogger(BapiDD03LDao.class.getName()).log(Level.SEVERE, null, ex);
        throw new NotFoundException(ex.getMessage());
    } finally {
        HibernateUtil.close(session);
    }
    return list;
}

From source file:com.sap.data.db.dao.BapiFUPARAREFDao.java

public List<BapiFUPARAREFPojo> select() throws NotFoundException {
    List<BapiFUPARAREFPojo> list = null;
    Session session = null;// w w  w  .ja  va2  s  .  c om
    try {
        session = HibernateUtil.getSession();
        session.setCacheMode(CacheMode.GET);
        list = session.createCriteria("BapiFUPARAREFPojo").addOrder(Order.asc("id.FUNCNAME"))
                .addOrder(Order.asc("id.R3STATE")).addOrder(Order.asc("id.PARAMETER"))
                .addOrder(Order.asc("id.PARAMTYPE")).addOrder(Order.asc("PPOSITION")).list();
    } catch (HibernateException ex) {
        Logger.getLogger(BapiFUPARAREFDao.class.getName()).log(Level.SEVERE, null, ex);
        throw new NotFoundException(ex.getMessage());
    } finally {
        HibernateUtil.close(session);
    }
    return list;
}

From source file:com.sap.data.db.dao.BapiFUPARAREFDao.java

public String selectParameterStructure(String funcName, String parameter) throws NotFoundException {
    String structure = null;/*ww w . j  a v a  2s  . c o  m*/
    Session session = null;
    try {
        String sql = "select distinct(rbp.STRUCTURE) from BapiFUPARAREFPojo rbp where rbp.id.FUNCNAME =:FUNCNAME and rbp.id.PARAMETER =:PARAMETER";
        session = HibernateUtil.getSession();
        session.setCacheMode(CacheMode.GET);
        Query query = session.createQuery(sql);
        query.setString("FUNCNAME", funcName);
        query.setString("PARAMETER", parameter);
        structure = (String) query.uniqueResult();
    } catch (HibernateException ex) {
        Logger.getLogger(BapiDD03LDao.class.getName()).log(Level.SEVERE, null, ex);
        throw new NotFoundException(ex.getMessage());
    } finally {
        HibernateUtil.close(session);
    }
    return structure;
}

From source file:com.sap.data.db.dao.BapiFUPARAREFDao.java

public List<BapiFUPARAREFPojo> selectInputParameters(String funcName) throws NotFoundException {
    List<BapiFUPARAREFPojo> list = null;
    Session session = null;/*w ww . ja  va2 s.  c  o m*/
    try {
        session = HibernateUtil.getSession();
        session.setCacheMode(CacheMode.GET);
        list = session.createCriteria("BapiFUPARAREFPojo").add(Restrictions.eq("id.FUNCNAME", funcName))
                .add(Restrictions.eq("id.PARAMTYPE", "I")).addOrder(Order.asc("id.FUNCNAME"))
                .addOrder(Order.asc("id.R3STATE")).addOrder(Order.asc("id.PARAMETER"))
                .addOrder(Order.asc("id.PARAMTYPE")).addOrder(Order.asc("PPOSITION")).list();
    } catch (HibernateException ex) {
        Logger.getLogger(BapiFUPARAREFDao.class.getName()).log(Level.SEVERE, null, ex);
        throw new NotFoundException(ex.getMessage());
    } finally {
        HibernateUtil.close(session);
    }
    return list;
}

From source file:com.sap.data.db.dao.BapiFUPARAREFDao.java

public List<BapiFUPARAREFPojo> selectTabParameters(String funcName) throws NotFoundException {
    List<BapiFUPARAREFPojo> list = null;
    Session session = null;/*from   ww  w . j av a 2 s.com*/
    try {
        session = HibernateUtil.getSession();
        session.setCacheMode(CacheMode.GET);
        list = session.createCriteria("BapiFUPARAREFPojo").add(Restrictions.eq("id.FUNCNAME", funcName))
                .add(Restrictions.eq("id.PARAMTYPE", "T")).addOrder(Order.asc("id.FUNCNAME"))
                .addOrder(Order.asc("id.R3STATE")).addOrder(Order.asc("id.PARAMETER"))
                .addOrder(Order.asc("id.PARAMTYPE")).addOrder(Order.asc("PPOSITION")).list();
    } catch (HibernateException ex) {
        Logger.getLogger(BapiFUPARAREFDao.class.getName()).log(Level.SEVERE, null, ex);
        throw new NotFoundException(ex.getMessage());
    } finally {
        HibernateUtil.close(session);
    }
    return list;
}

From source file:com.sap.data.db.dao.BapiFUPARAREFDao.java

public List<BapiFUPARAREFPojo> selectParameters(String funcName) throws NotFoundException {
    List<BapiFUPARAREFPojo> list = null;
    Session session = null;//w  w  w.j  a  v a  2  s. co  m
    try {
        session = HibernateUtil.getSession();
        session.setCacheMode(CacheMode.GET);
        list = session.createCriteria("BapiFUPARAREFPojo").add(Restrictions.eq("id.FUNCNAME", funcName))
                .addOrder(Order.asc("id.FUNCNAME")).addOrder(Order.asc("id.R3STATE"))
                .addOrder(Order.asc("id.PARAMETER")).addOrder(Order.asc("id.PARAMTYPE"))
                .addOrder(Order.asc("PPOSITION")).list();
    } catch (HibernateException ex) {
        Logger.getLogger(BapiFUPARAREFDao.class.getName()).log(Level.SEVERE, null, ex);
        throw new NotFoundException(ex.getMessage());
    } finally {
        HibernateUtil.close(session);
    }
    return list;
}

From source file:com.sap.data.db.dao.BapiFUPARAREFDao.java

public List<BapiFUPARAREFPojo> selectETParameters(String funcName) throws NotFoundException {
    List<BapiFUPARAREFPojo> list = null;
    Session session = null;//from   ww  w .j  a  v a2  s  . c  o m
    try {
        session = HibernateUtil.getSession();
        session.setCacheMode(CacheMode.GET);
        list = session.createCriteria("BapiFUPARAREFPojo").add(Restrictions.eq("id.FUNCNAME", funcName))
                .add(Restrictions.in("id.PARAMTYPE", new Object[] { "E", "T" }))
                .add(Restrictions.sqlRestriction("STRUCTURE not like('%-%')"))
                .addOrder(Order.asc("id.FUNCNAME")).addOrder(Order.asc("id.R3STATE"))
                .addOrder(Order.asc("id.PARAMETER")).addOrder(Order.asc("id.PARAMTYPE"))
                .addOrder(Order.asc("PPOSITION")).list();
    } catch (HibernateException ex) {
        Logger.getLogger(BapiFUPARAREFDao.class.getName()).log(Level.SEVERE, null, ex);
        throw new NotFoundException(ex.getMessage());
    } finally {
        HibernateUtil.close(session);
    }
    return list;
}