List of usage examples for org.hibernate Session getFlushMode
@Override FlushModeType getFlushMode();
From source file:org.jboss.dashboard.security.PermissionManager.java
License:Apache License
/** * Find the permission descriptor for given principal and permission *//*from w w w . j av a2 s. c o 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 */// www . j a va2 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; }
From source file:org.jboss.dashboard.security.PermissionManager.java
License:Apache License
/** * Recover Permissions for the given permission class and resource name, including or excluding the ones marked as readonly *///from www. j a v a 2 s . co m public List<PermissionDescriptor> find(final String permissionClass, final String permissionResource, final Boolean includeReadOnly) { final List<PermissionDescriptor> results = new ArrayList<PermissionDescriptor>(10); HibernateTxFragment txFragment = new HibernateTxFragment() { protected void txFragment(Session session) throws Exception { StringBuffer buf = new StringBuffer( " from " + PermissionDescriptor.class.getName() + " as item where item.dbid is not null "); buf.append( "and item.permissionClass = :permissionClass and item.permissionResource = :permissionResource"); if (!includeReadOnly) buf.append(" and item.readonly = :readonly"); Query query = session.createQuery(buf.toString()); query.setString("permissionClass", permissionClass); query.setString("permissionResource", permissionResource); if (!includeReadOnly) query.setBoolean("readonly", includeReadOnly); query.setCacheable(true); FlushMode oldFlushMode = session.getFlushMode(); session.setFlushMode(FlushMode.NEVER); results.addAll(query.list()); session.setFlushMode(oldFlushMode); } }; try { txFragment.execute(); } catch (Exception e) { log.error("Error retrieving PermissionDescriptors for permission class " + permissionClass + " and resource " + permissionResource, e); } return results; }
From source file:org.jboss.dashboard.security.PermissionManager.java
License:Apache License
/** * Recover a Permission by its Id// ww w . j a va 2s.c om */ public PermissionDescriptor findPermissionDescriptorById(final Long idPermission) { final List<PermissionDescriptor> result = new ArrayList<PermissionDescriptor>(1); try { new HibernateTxFragment() { protected void txFragment(Session session) throws Exception { String sql = " from " + PermissionDescriptor.class.getName() + " as item where item.dbid = :dbid"; Query query = session.createQuery(sql); query.setLong("dbid", idPermission); FlushMode oldFlushMode = session.getFlushMode(); session.setFlushMode(FlushMode.NEVER); result.add((PermissionDescriptor) query.uniqueResult()); session.setFlushMode(oldFlushMode); } }.execute(); } catch (Exception e) { log.error("PermissionDescriptor with id " + idPermission + " not found!", e); } return result.get(0); }
From source file:org.jboss.dashboard.security.PermissionManager.java
License:Apache License
/** * Recover the Permissions by the Ids indicated in the List parameter *//*from ww w . j a v a 2 s. c o m*/ public List<PermissionDescriptor> find(final List<Long> permissionIds) { final List<PermissionDescriptor> results = new ArrayList<PermissionDescriptor>(10); if (permissionIds != null) { final StringBuilder idString = new StringBuilder( " from " + PermissionDescriptor.class.getName() + " as item where item.dbid in ("); for (int i = 0; i < permissionIds.size(); i++) { idString.append(permissionIds.get(i)); if (i != permissionIds.size() - 1) idString.append(","); } idString.append(")"); HibernateTxFragment txFragment = new HibernateTxFragment() { protected void txFragment(Session session) throws Exception { Query query = session.createQuery(idString.toString()); FlushMode oldFlushMode = session.getFlushMode(); session.setFlushMode(FlushMode.NEVER); results.addAll(query.list()); session.setFlushMode(oldFlushMode); } }; try { txFragment.execute(); } catch (Exception e) { log.error("Error deleting PermissionDescriptors with dbids in (" + idString + ")", e); } } return results; }
From source file:org.jboss.dashboard.ui.panel.advancedHTML.HTMLDriver.java
License:Apache License
public HTMLText load(final PanelInstance instance) { final List<HTMLText> results = new ArrayList<HTMLText>(); try {//from ww w .j av a2 s . co m new HibernateTxFragment() { protected void txFragment(Session session) throws Exception { FlushMode oldFlushMode = session.getFlushMode(); session.setFlushMode(FlushMode.NEVER); Query query = session.createQuery( " from " + HTMLText.class.getName() + " as text where text.panelInstance = :instance"); query.setParameter("instance", instance); query.setCacheable(true); results.addAll(query.list()); session.setFlushMode(oldFlushMode); } }.execute(); HTMLText text = null; if (results.size() > 0) text = results.get(0); else log.debug("Does not exist a html_text for HTML panel"); return text; } catch (Exception e) { log.error("Can't retrive a data for HTML panel ", e); return null; } }
From source file:org.jboss.dashboard.ui.panel.advancedHTML.HTMLDriver.java
License:Apache License
/** * Replicates panel data.//from ww w . j av a 2s.c o m * * @param src Source PanelInstance * @param dest Destinaton PanelInstance */ public void replicateData(final PanelInstance src, PanelInstance dest) throws Exception { super.replicateData(src, dest); log.debug( "HTMLDriver replicating Data from PanelInstance " + src.getDbid() + " to " + dest.getDbid() + ")."); if (src.equals(dest)) { log.debug("Ignoring replication, panel instance is the same."); return; } final HTMLText[] textArray = new HTMLText[1]; try { new HibernateTxFragment() { protected void txFragment(Session session) throws Exception { log.debug("Getting text to duplicate for instance " + src.getDbid()); FlushMode oldMode = session.getFlushMode(); session.setFlushMode(FlushMode.COMMIT);//Avoids flushing, as we know the text was not modified in this transaction. textArray[0] = load(src); session.setFlushMode(oldMode); log.debug("Got text to duplicate for instance " + src.getDbid()); } }.execute(); } catch (Exception e) { log.error("Error loading text for instance. ", e); } HTMLText text = textArray[0]; if (text == null) { log.debug("Nothing to replicate from PanelInstance " + src.getDbid() + " to " + dest.getDbid()); return; } Map<String, String> htmlSrc = text.getText(); log.debug("htmlCode to replicate = " + htmlSrc); HTMLText htmlDest = new HTMLText(); htmlDest.setPanelInstance(dest.getInstance()); for (String lang : htmlSrc.keySet()) { String val = htmlSrc.get(lang); htmlDest.setText(lang, val); } try { log.debug("Updating HTMLText: IDText " + htmlDest.getDbid() + " Text " + htmlDest.getText()); htmlDest.save(); } catch (Exception e) { log.error("Replicating panel data", e); } }
From source file:org.jboss.dashboard.ui.panel.dataSourceManagement.DataSourceTableManager.java
License:Apache License
public List<DataSourceTableEntry> getSelectedTablesEntries(final String datasource) throws Exception { final List<DataSourceTableEntry> existingEntries = new ArrayList<DataSourceTableEntry>(); new HibernateTxFragment() { protected void txFragment(Session session) throws Exception { Query query = session.createQuery(" from " + DataSourceTableEntry.class.getName() + " entry where entry.datasource = :datasource"); query.setString("datasource", datasource); query.setCacheable(true);//from www . j a va2 s. c om FlushMode oldFlushMode = session.getFlushMode(); session.setFlushMode(FlushMode.COMMIT); existingEntries.addAll(query.list()); session.setFlushMode(oldFlushMode); } }.execute(); return existingEntries; }
From source file:org.jboss.dashboard.ui.panel.dataSourceManagement.DataSourceTableManager.java
License:Apache License
public List<DataSourceColumnEntry> getSelectedColumnsEntries(final String datasource, final String tableName) throws Exception { final List<DataSourceColumnEntry> existingEntries = new ArrayList<DataSourceColumnEntry>(); new HibernateTxFragment() { protected void txFragment(Session session) throws Exception { Query query = session.createQuery(" from " + DataSourceColumnEntry.class.getName() + " entry where entry.datasource = :datasource and entry.tableName = :tableName"); query.setString("datasource", datasource); query.setString("tableName", tableName); FlushMode oldFlushMode = session.getFlushMode(); session.setFlushMode(FlushMode.NEVER); query.setCacheable(true);//from www.j av a2s . co m existingEntries.addAll(query.list()); session.setFlushMode(oldFlushMode); } }.execute(); return existingEntries; }
From source file:org.jboss.dashboard.workspace.GraphicElementManagerImpl.java
License:Apache License
/** * Take all elements in DB, and load them *///from w ww . ja va2s. c o m protected void loadDbElements() throws Exception { elements = new Vector(); HibernateTxFragment txFragment = new HibernateTxFragment() { protected void txFragment(Session session) throws Exception { FlushMode oldFlushMode = session.getFlushMode(); session.setFlushMode(FlushMode.NEVER); List dbItems = session.createQuery("from " + classToHandle.getName() + " as element").list(); for (int i = 0; i < dbItems.size(); i++) { GraphicElement element = (GraphicElement) dbItems.get(i); //element.deploy(); log.debug("Loaded db item " + element.getId()); elements.add(element); } session.setFlushMode(oldFlushMode); } }; txFragment.execute(); Collections.sort(elements); }