List of usage examples for org.hibernate Query setCacheable
Query<R> setCacheable(boolean cacheable);
From source file:org.jboss.dashboard.database.DataSourceManager.java
License:Apache License
/** * Get all registered datasource entries *//*from w w w .ja va 2s . c o m*/ public List<DataSourceEntry> getDataSourceEntries() { final List result = new ArrayList(); try { new HibernateTxFragment() { protected void txFragment(Session session) throws Exception { Query query = session.createQuery(" from " + DataSourceEntry.class.getName()); FlushMode oldFlushMode = session.getFlushMode(); session.setFlushMode(FlushMode.COMMIT); query.setCacheable(true); result.addAll(query.list()); session.setFlushMode(oldFlushMode); } }.execute(); } catch (Exception e) { log.error("Error: ", e); } return result; }
From source file:org.jboss.dashboard.database.DataSourceManager.java
License:Apache License
public DataSourceEntry getDataSourceEntry(final String name) throws Exception { if (name == null) return null; final List results = new ArrayList(); new HibernateTxFragment() { protected void txFragment(Session session) throws Exception { FlushMode flushMode = session.getFlushMode(); session.setFlushMode(FlushMode.COMMIT); StringBuffer sql = new StringBuffer(); sql.append("select dse "); sql.append("from ").append(DataSourceEntry.class.getName()).append(" as dse "); sql.append("where dse.name = :name"); Query query = session.createQuery(sql.toString()); query.setString("name", name); query.setCacheable(true); results.addAll(query.list()); session.setFlushMode(flushMode); }/*w ww . ja v a2 s . c om*/ }.execute(); if (results.size() > 0) { if (results.size() > 1) log.error("There are " + results.size() + " data sources with name=" + name); return (DataSourceEntry) results.get(0); } else { log.debug("Does not exists data source with name: " + name); return null; } }
From source file:org.jboss.dashboard.kpi.KPIManagerImpl.java
License:Apache License
public Set<KPI> getAllKPIs() throws Exception { final Set<KPI> results = new HashSet<KPI>(); new HibernateTxFragment() { protected void txFragment(Session session) throws Exception { FlushMode flushMode = session.getFlushMode(); session.setFlushMode(FlushMode.COMMIT); Query query = session.createQuery("from " + KPIImpl.class.getName() + " order by id"); query.setCacheable(true); results.addAll(query.list()); session.setFlushMode(flushMode); }// ww w.j a v a 2s. com }.execute(); return results; }
From source file:org.jboss.dashboard.kpi.KPIManagerImpl.java
License:Apache License
public KPI getKPIById(final Long id) throws Exception { final List<KPI> results = new ArrayList<KPI>(); new HibernateTxFragment() { protected void txFragment(Session session) throws Exception { FlushMode flushMode = session.getFlushMode(); session.setFlushMode(FlushMode.COMMIT); StringBuffer sql = new StringBuffer(); sql.append("from ").append(KPIImpl.class.getName()).append(" as instance "); sql.append("where instance.id = :id"); Query query = session.createQuery(sql.toString()); if (id != null) query.setLong("id", id.longValue()); query.setCacheable(true); results.addAll(query.list()); session.setFlushMode(flushMode); }/*from ww w. j a v a 2 s.c om*/ }.execute(); if (results.size() > 0) return (KPIImpl) results.get(0); else log.debug("KPI with id =" + id + " does not exist."); return null; }
From source file:org.jboss.dashboard.kpi.KPIManagerImpl.java
License:Apache License
public KPI getKPIByCode(final String code) throws Exception { final List<KPI> results = new ArrayList<KPI>(); new HibernateTxFragment() { protected void txFragment(Session session) throws Exception { FlushMode flushMode = session.getFlushMode(); session.setFlushMode(FlushMode.COMMIT); StringBuffer sql = new StringBuffer(); sql.append("from ").append(KPIImpl.class.getName()).append(" as instance "); sql.append("where instance.code = :code"); Query query = session.createQuery(sql.toString()); if (code != null) query.setString("code", code); query.setCacheable(true); results.addAll(query.list()); session.setFlushMode(flushMode); }/*from w w w. j a v a2 s . com*/ }.execute(); if (results.size() > 0) return (KPIImpl) results.get(0); else log.debug("KPI with code=" + code + " does not exist."); return null; }
From source file:org.jboss.dashboard.provider.DataProviderManagerImpl.java
License:Apache License
public Set<DataProvider> getAllDataProviders() throws Exception { final Set<DataProvider> results = new HashSet<DataProvider>(); new HibernateTxFragment() { protected void txFragment(Session session) throws Exception { FlushMode flushMode = session.getFlushMode(); session.setFlushMode(FlushMode.COMMIT); Query query = session.createQuery("from " + DataProviderImpl.class.getName() + " order by id"); query.setCacheable(true); results.addAll(query.list()); session.setFlushMode(flushMode); }//from ww w . j a v a 2 s . co m }.execute(); return results; }
From source file:org.jboss.dashboard.provider.DataProviderManagerImpl.java
License:Apache License
public DataProvider getDataProviderById(final Long id) throws Exception { final List<DataProvider> results = new ArrayList<DataProvider>(); new HibernateTxFragment() { protected void txFragment(Session session) throws Exception { FlushMode flushMode = session.getFlushMode(); session.setFlushMode(FlushMode.COMMIT); StringBuffer sql = new StringBuffer(); sql.append("from ").append(DataProviderImpl.class.getName()).append(" as instance "); sql.append("where instance.id = :id"); Query query = session.createQuery(sql.toString()); if (id != null) query.setLong("id", id.longValue()); query.setCacheable(true); results.addAll(query.list()); session.setFlushMode(flushMode); }/*from ww w . jav a 2s . c o m*/ }.execute(); if (results.size() > 0) return (DataProviderImpl) results.get(0); else log.debug("Data provider with id =" + id + " does not exist."); return null; }
From source file:org.jboss.dashboard.provider.DataProviderManagerImpl.java
License:Apache License
public DataProvider getDataProviderByCode(final String code) throws Exception { final List<DataProvider> results = new ArrayList<DataProvider>(); new HibernateTxFragment() { protected void txFragment(Session session) throws Exception { FlushMode flushMode = session.getFlushMode(); session.setFlushMode(FlushMode.COMMIT); StringBuffer sql = new StringBuffer(); sql.append("from ").append(DataProviderImpl.class.getName()).append(" as instance "); sql.append("where instance.code = :code"); Query query = session.createQuery(sql.toString()); if (code != null) query.setString("code", code); query.setCacheable(true); results.addAll(query.list()); session.setFlushMode(flushMode); }/* w w w . j a v a 2 s . c o m*/ }.execute(); if (results.size() > 0) return (DataProviderImpl) results.get(0); else log.debug("Data provider with code=" + code + " does not exist."); return null; }
From source file:org.jboss.dashboard.security.PermissionManager.java
License:Apache License
/** * Find the permission descriptor for given principal and permission *//* w w w. j a va2 s .co m*/ public PermissionDescriptor find(final Principal prpal, final Permission perm) { final List<PermissionDescriptor> results = new ArrayList<PermissionDescriptor>(1); HibernateTxFragment txFragment = new HibernateTxFragment() { protected void txFragment(Session session) throws Exception { StringBuffer buf = new StringBuffer(); buf.append( " from " + PermissionDescriptor.class.getName() + " as item where item.dbid is not null "); if (prpal != null) { buf.append(" and item.principalClass = :principalClass "); buf.append(" and item.principalName = :principalName "); } buf.append( "and item.permissionClass = :permissionClass and item.permissionResource = :permissionResource"); Query query = session.createQuery(buf.toString()); if (prpal != null) { query.setString("principalClass", prpal.getClass().getName()); query.setString("principalName", prpal.getName()); } query.setString("permissionClass", perm.getClass().getName()); query.setString("permissionResource", perm.getName()); query.setCacheable(true); FlushMode oldFlushMode = session.getFlushMode(); session.setFlushMode(FlushMode.NEVER); results.addAll(query.list()); session.setFlushMode(oldFlushMode); } }; try { txFragment.execute(); if (!results.isEmpty()) return results.get(0); else return null; } catch (Exception e) { log.error("Error retrieving PermissionDescriptor", e); return null; } }
From source file:org.jboss.dashboard.security.PermissionManager.java
License:Apache License
/** * Recover the Permissions for the given permission resource name *//* ww w.j a v a 2 s.co m*/ public List<PermissionDescriptor> find(final String resourceName) throws Exception { final List<PermissionDescriptor> results = new ArrayList<PermissionDescriptor>(); new HibernateTxFragment() { protected void txFragment(Session session) throws Exception { StringBuffer buf = new StringBuffer(); buf.append( " from " + PermissionDescriptor.class.getName() + " as item where item.dbid is not null "); if (!StringUtils.isBlank(resourceName)) buf.append(" and item.permissionResource = :res1 or item.permissionResource = :res2"); Query query = session.createQuery(buf.toString()); if (!StringUtils.isBlank(resourceName)) { query.setString("res1", resourceName); query.setString("res2", resourceName + ".*"); } query.setCacheable(true); FlushMode oldFlushMode = session.getFlushMode(); session.setFlushMode(FlushMode.NEVER); results.addAll(query.list()); session.setFlushMode(oldFlushMode); } }.execute(); return results; }