List of usage examples for org.hibernate Session setFlushMode
@Deprecated
void setFlushMode(FlushMode flushMode);
From source file:org.jboss.dashboard.security.PermissionManager.java
License:Apache License
/** * Recover a Permission by its Id// w ww . j av a2s . 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 w w w .j ava 2s. com 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 w w w . ja v a2s . com*/ 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 w ww.j a v a2 s . c om * * @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 w w w. j av a 2 s.com 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 w w w . j a v a 2 s . c o 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 */// w w w . j a v a 2 s . c om 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); }
From source file:org.jboss.dashboard.workspace.PanelsManagerImpl.java
License:Apache License
public Panel getPanelByDbId(final Long panelId) throws Exception { if (panelId != null) { final List<Panel> results = new ArrayList<Panel>(); new HibernateTxFragment() { protected void txFragment(Session session) throws Exception { FlushMode flushMode = session.getFlushMode(); session.setFlushMode(FlushMode.COMMIT); StringBuffer sql = new StringBuffer(); sql.append("select p "); sql.append("from ").append(Panel.class.getName()).append(" as p "); sql.append("where p.dbid = :dbid"); Query query = session.createQuery(sql.toString()); query.setLong("dbid", panelId); query.setCacheable(true); results.addAll(query.list()); session.setFlushMode(flushMode); }//from ww w . java 2 s. c o m }.execute(); if (results.size() > 0) return results.get(0); else log.debug("Does not exists panel with DB id: " + panelId); } return null; }
From source file:org.jboss.dashboard.workspace.PanelsManagerImpl.java
License:Apache License
public Panel getPanelById(final Long panelId) throws Exception { final List<Panel> results = new ArrayList<Panel>(); new HibernateTxFragment() { protected void txFragment(Session session) throws Exception { FlushMode flushMode = session.getFlushMode(); session.setFlushMode(FlushMode.COMMIT); StringBuffer sql = new StringBuffer(); sql.append("select p "); sql.append("from ").append(Panel.class.getName()).append(" as p "); sql.append("where p.panelId = :panelId"); Query query = session.createQuery(sql.toString()); query.setLong("panelId", panelId); query.setCacheable(true);//from w ww.j a v a 2 s. co m results.addAll(query.list()); session.setFlushMode(flushMode); } }.execute(); if (results.size() > 0) return results.get(0); else log.debug("Does not exists panel with id: " + panelId); return null; }
From source file:org.jboss.dashboard.workspace.PanelsManagerImpl.java
License:Apache License
/** * Retrieves the panel instances with the given paramId as a panelParameter. *//* w w w.j a va 2s. c o m*/ public Set<PanelInstance> getPanelsByParameter(final String paramId, final String value) throws Exception { final Set<PanelInstance> results = new HashSet<PanelInstance>(); if (value == null || paramId == null) return results; new HibernateTxFragment() { protected void txFragment(Session session) throws Exception { FlushMode flushMode = session.getFlushMode(); session.setFlushMode(FlushMode.COMMIT); StringBuffer sql = new StringBuffer(); sql.append("select p "); sql.append("from ").append(PanelInstance.class.getName()) .append(" as p join p.panelParams as param "); sql.append("where param.idParameter = :paramId "); Query query = session.createQuery(sql.toString()); query.setString("paramId", paramId); query.setCacheable(true); results.addAll(query.list()); session.setFlushMode(flushMode); } }.execute(); Set<PanelInstance> matchPanel = new HashSet<PanelInstance>(); for (PanelInstance panelInstance : results) { Set<PanelParameter> panelParams = panelInstance.getPanelParams(); for (PanelParameter panelParameter : panelParams) { if (paramId.equals(panelParameter.getIdParameter()) && value.equals(panelParameter.getValue())) { matchPanel.add(panelInstance); } } } return matchPanel; }