List of usage examples for org.hibernate SQLQuery setCacheable
@Override
NativeQuery<T> setCacheable(boolean cacheable);
From source file:com.querydsl.jpa.hibernate.sql.AbstractHibernateSQLQuery.java
License:Apache License
private Query createQuery(boolean forCount) { NativeSQLSerializer serializer = (NativeSQLSerializer) serialize(forCount); String queryString = serializer.toString(); logQuery(queryString, serializer.getConstantToLabel()); org.hibernate.SQLQuery query = session.createSQLQuery(queryString); // set constants HibernateUtil.setConstants(query, serializer.getConstantToLabel(), queryMixin.getMetadata().getParams()); if (!forCount) { ListMultimap<Expression<?>, String> aliases = serializer.getAliases(); Set<String> used = Sets.newHashSet(); // set entity paths Expression<?> projection = queryMixin.getMetadata().getProjection(); if (projection instanceof FactoryExpression) { for (Expression<?> expr : ((FactoryExpression<?>) projection).getArgs()) { if (isEntityExpression(expr)) { query.addEntity(extractEntityExpression(expr).toString(), expr.getType()); } else if (aliases.containsKey(expr)) { for (String scalar : aliases.get(expr)) { if (!used.contains(scalar)) { query.addScalar(scalar); used.add(scalar); break; }/*w ww .ja va 2 s. co m*/ } } } } else if (isEntityExpression(projection)) { query.addEntity(extractEntityExpression(projection).toString(), projection.getType()); } else if (aliases.containsKey(projection)) { for (String scalar : aliases.get(projection)) { if (!used.contains(scalar)) { query.addScalar(scalar); used.add(scalar); break; } } } // set result transformer, if projection is a FactoryExpression instance if (projection instanceof FactoryExpression) { query.setResultTransformer(new FactoryExpressionTransformer((FactoryExpression<?>) projection)); } } if (fetchSize > 0) { query.setFetchSize(fetchSize); } if (timeout > 0) { query.setTimeout(timeout); } if (cacheable != null) { query.setCacheable(cacheable); } if (cacheRegion != null) { query.setCacheRegion(cacheRegion); } if (readOnly != null) { query.setReadOnly(readOnly); } return query; }
From source file:com.zdtx.ifms.specific.service.monitor.IpCamManager.java
/** * Get IP Camera's users//from ww w . java 2 s . c o m * @return CamUserVO */ @SuppressWarnings("unchecked") public CamUserVO getCamUsers() { String sql = "SELECT A.USERNAME AS ADMINNAME, A.USERPASS AS ADMINPASS, " + "B.USERNAME AS OPERATORNAME, B.USERPASS AS OPERATORPASS, " + "C.USERNAME AS VIEWERNAME, C.USERPASS AS VIEWERPASS " + "FROM T_CORE_CAM_USER A, T_CORE_CAM_USER B, T_CORE_CAM_USER C " + "WHERE A.AUTHLEVEL = 0 AND B.AUTHLEVEL = 1 AND C.AUTHLEVEL = 2"; SQLQuery query = dao.getSession().createSQLQuery(sql); query.addScalar("adminName", StringType.INSTANCE); query.addScalar("adminPass", StringType.INSTANCE); query.addScalar("operatorName", StringType.INSTANCE); query.addScalar("operatorPass", StringType.INSTANCE); query.addScalar("viewerName", StringType.INSTANCE); query.addScalar("viewerPass", StringType.INSTANCE); query.setResultTransformer(Transformers.aliasToBean(CamUserVO.class)); query.setCacheable(true); CamUserVO camUserVO = ((List<CamUserVO>) query.list()).get(0); return camUserVO; }
From source file:edu.vt.vbi.patric.dao.DBDisease.java
License:Apache License
public int getVFDBBreadCrumbCount(Map<String, String> key) { String sql = getVFDBSQL(key, "breadcrumb"); Session session = factory.getCurrentSession(); session.beginTransaction();//from ww w . j a v a2s. co m SQLQuery q = session.createSQLQuery(sql).addScalar("cnt", Hibernate.INTEGER); q = bindVFDBSQLValues(q, key); q.setCacheable(true); Object obj = q.uniqueResult(); session.getTransaction().commit(); return Integer.parseInt(obj.toString()); }
From source file:edu.vt.vbi.patric.dao.DBDisease.java
License:Apache License
public int getVFDBFeatureBreadCrumbCount(Map<String, String> key) { String sql = getVFDBFeatureSQL(key, "breadcrumb"); Session session = factory.getCurrentSession(); session.beginTransaction();/*from w ww .j a va 2 s . c o m*/ SQLQuery q = session.createSQLQuery(sql).addScalar("cnt", Hibernate.INTEGER); q = bindVFDBFeatureSQLValues(q, key); q.setCacheable(true); Object obj = q.uniqueResult(); session.getTransaction().commit(); return Integer.parseInt(obj.toString()); }
From source file:edu.vt.vbi.patric.dao.DBDisease.java
License:Apache License
public int getVFDBCount(Map<String, String> key) { String sql = getVFDBSQL(key, "count"); sql += " )";// w ww .jav a2 s. co m Session session = factory.getCurrentSession(); session.beginTransaction(); SQLQuery q = session.createSQLQuery(sql).addScalar("cnt", Hibernate.INTEGER); q = bindVFDBSQLValues(q, key); q.setCacheable(true); Object obj = q.uniqueResult(); session.getTransaction().commit(); return Integer.parseInt(obj.toString()); }
From source file:edu.vt.vbi.patric.dao.DBDisease.java
License:Apache License
public int getVFDBFeatureCount(Map<String, String> key) { String sql = getVFDBFeatureSQL(key, "count"); sql += " )";/* w w w . jav a 2s .c o m*/ Session session = factory.getCurrentSession(); session.beginTransaction(); SQLQuery q = session.createSQLQuery(sql).addScalar("cnt", Hibernate.INTEGER); q = bindVFDBFeatureSQLValues(q, key); q.setCacheable(true); Object obj = q.uniqueResult(); session.getTransaction().commit(); return Integer.parseInt(obj.toString()); }
From source file:edu.vt.vbi.patric.dao.DBDisease.java
License:Apache License
public int getCTDBreadCrumbCount(Map<String, String> key) { String sql = getCTDSQL(key, "breadcrumb"); Session session = factory.getCurrentSession(); session.beginTransaction();//from ww w .ja v a2s . c om SQLQuery q = session.createSQLQuery(sql).addScalar("cnt", Hibernate.INTEGER); q = bindSQLValues(q, key); q.setCacheable(true); Object obj = q.uniqueResult(); session.getTransaction().commit(); return Integer.parseInt(obj.toString()); }
From source file:edu.vt.vbi.patric.dao.DBDisease.java
License:Apache License
public int getCTDCount(Map<String, String> key) { String sql = getCTDSQL(key, "count"); Session session = factory.getCurrentSession(); session.beginTransaction();/*from w w w . j ava 2s. c o m*/ SQLQuery q = session.createSQLQuery(sql).addScalar("cnt", Hibernate.INTEGER); q = bindSQLValues(q, key); q.setCacheable(true); Object obj = q.uniqueResult(); session.getTransaction().commit(); return Integer.parseInt(obj.toString()); }
From source file:edu.vt.vbi.patric.dao.DBDisease.java
License:Apache License
public int getCTDGraphBreadCrumbCount(Map<String, String> key) { String sql = getCTDSQL(key, "graphbreadcrumb"); Session session = factory.getCurrentSession(); session.beginTransaction();/* ww w. j a v a2 s.c om*/ SQLQuery q = session.createSQLQuery(sql).addScalar("cnt", Hibernate.INTEGER); q = bindGraphCTDSQLValues(q, key); q.setCacheable(true); Object obj = q.uniqueResult(); session.getTransaction().commit(); return Integer.parseInt(obj.toString()); }
From source file:edu.vt.vbi.patric.dao.DBDisease.java
License:Apache License
public int getCTDGraphCount(Map<String, String> key) { String sql = getCTDSQL(key, "graphcount"); Session session = factory.getCurrentSession(); session.beginTransaction();/*from w w w.ja v a 2 s.c o m*/ SQLQuery q = session.createSQLQuery(sql).addScalar("cnt", Hibernate.INTEGER); q = bindGraphCTDSQLValues(q, key); q.setCacheable(true); Object obj = q.uniqueResult(); session.getTransaction().commit(); return Integer.parseInt(obj.toString()); }