List of usage examples for org.hibernate FlushMode COMMIT
FlushMode COMMIT
To view the source code for org.hibernate FlushMode COMMIT.
Click Source Link
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);//from w w w . j ava2s .co m results.addAll(query.list()); session.setFlushMode(flushMode); } }.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.ui.panel.advancedHTML.HTMLDriver.java
License:Apache License
/** * Replicates panel data.// 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 ww .j a v a 2 s. c o m FlushMode oldFlushMode = session.getFlushMode(); session.setFlushMode(FlushMode.COMMIT); existingEntries.addAll(query.list()); session.setFlushMode(oldFlushMode); } }.execute(); return existingEntries; }
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 . j a v a2 s.co 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. java2s . 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. *//*from ww w. j a v a 2s . com*/ 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; }
From source file:org.jboss.dashboard.workspace.SectionsManagerImpl.java
License:Apache License
public Section getSectionByDbId(final Long dbid) throws Exception { if (dbid == null) return null; final List<Section> results = new ArrayList<Section>(); new HibernateTxFragment() { protected void txFragment(Session session) throws Exception { FlushMode flushMode = session.getFlushMode(); session.setFlushMode(FlushMode.COMMIT); StringBuffer sql = new StringBuffer(); sql.append("select item "); sql.append("from ").append(Section.class.getName()).append(" as item "); sql.append("where item.dbid = :dbid"); Query query = session.createQuery(sql.toString()); query.setLong("dbid", dbid.longValue()); query.setCacheable(true);//ww w . java 2s .c o m results.addAll(query.list()); session.setFlushMode(flushMode); } }.execute(); if (results.size() > 0) return results.get(0); else log.debug("Does not exists a section with dbid: " + dbid); return null; }
From source file:org.jboss.seam.persistence.hibernate.HibernateManagedSessionProxyHandler.java
License:Open Source License
private void changeFushMode(FlushModeType flushModeType) { switch (flushModeType) { case AUTO:// w w w .j av a 2 s . c o m delegate.setFlushMode(FlushMode.AUTO); break; case MANUAL: delegate.setFlushMode(FlushMode.MANUAL); break; case COMMIT: delegate.setFlushMode(FlushMode.COMMIT); break; default: throw new RuntimeException("Unkown flush mode: " + flushModeType); } }
From source file:org.mifos.application.questionnaire.migration.QuestionnaireMigration.java
License:Open Source License
@Autowired public QuestionnaireMigration(QuestionnaireMigrationMapper questionnaireMigrationMapper, QuestionnaireServiceFacade questionnaireServiceFacade, SessionFactory sessionFactory) { this.questionnaireMigrationMapper = questionnaireMigrationMapper; this.questionnaireServiceFacade = questionnaireServiceFacade; this.sessionFactory = sessionFactory; session = sessionFactory.openSession(); session.setFlushMode(FlushMode.COMMIT); }
From source file:org.mifos.application.questionnaire.migration.QuestionnaireMigration.java
License:Open Source License
public Session getSession() { if (session == null || !session.isOpen() || !session.isConnected()) { session = sessionFactory.openSession(); session.setFlushMode(FlushMode.COMMIT); }/*from ww w.j av a 2 s. c o m*/ return session; }