List of usage examples for org.hibernate Query setBoolean
@Deprecated @SuppressWarnings("unchecked") default Query<R> setBoolean(String name, boolean val)
From source file:fr.mael.microrss.dao.impl.UserArticleDaoImpl.java
License:Open Source License
@Override public Long labelUnread(User user, UserLabel label) { StringBuffer query = new StringBuffer("select count(ua) from UserArticle ua "); query.append("inner join ua.userLabels ul "); query.append("where ua.user = :user "); query.append("and ua.read = :read "); query.append("and ul = :label "); Query q = getSession().createQuery(query.toString()); q.setEntity("user", user); q.setBoolean("read", false); q.setEntity("label", label); return (Long) q.uniqueResult(); }
From source file:it.eng.spagobi.tools.dataset.dao.DataSetDAOImpl.java
License:Mozilla Public License
public List<IDataSet> loadAllActiveDataSets() { List<IDataSet> toReturn; Session session;/*from w ww .jav a2 s . c o m*/ Transaction transaction; logger.debug("IN"); toReturn = null; session = null; transaction = null; try { toReturn = new ArrayList<IDataSet>(); try { session = getSession(); Assert.assertNotNull(session, "session cannot be null"); transaction = session.beginTransaction(); Assert.assertNotNull(transaction, "transaction cannot be null"); } catch (Throwable t) { throw new SpagoBIDOAException("An error occured while creating the new transaction", t); } Query query = session.createQuery("from SbiDataSetHistory h where h.active = ? "); query.setBoolean(0, true); List<SbiDataSetHistory> sbiDataSetHistoryList = query.list(); for (SbiDataSetHistory sbiDataSetHistory : sbiDataSetHistoryList) { if (sbiDataSetHistory != null) { toReturn.add(DataSetFactory.toDataSet(sbiDataSetHistory)); } } } catch (Throwable t) { if (transaction != null && transaction.isActive()) { transaction.rollback(); } throw new SpagoBIDOAException("An unexpected error occured while loading datasets", t); } finally { if (session != null && session.isOpen()) { session.close(); } logger.debug("OUT"); } return toReturn; }
From source file:it.eng.spagobi.tools.dataset.dao.DataSetDAOImpl.java
License:Mozilla Public License
/** * Load data set by label.//from www . j a v a2s. c o m * @param label the label * @return the data set * @see it.eng.spagobi.tools.dataset.dao.IDataSetDAO#loadDataSetByLabel(string) */ public IDataSet loadActiveDataSetByLabel(String label) { IDataSet toReturn; Session session; Transaction transaction; logger.debug("IN"); toReturn = null; session = null; transaction = null; try { if (label == null) { throw new IllegalArgumentException("Input parameter [label] cannot be null"); } try { session = getSession(); Assert.assertNotNull(session, "session cannot be null"); transaction = session.beginTransaction(); Assert.assertNotNull(transaction, "transaction cannot be null"); } catch (Throwable t) { throw new SpagoBIDOAException("An error occured while creating the new transaction", t); } Criterion labelCriterrion = Expression.eq("label", label); Criteria criteria = session.createCriteria(SbiDataSetConfig.class); criteria.add(labelCriterrion); SbiDataSetConfig hibDS = (SbiDataSetConfig) criteria.uniqueResult(); if (hibDS == null) return null; Integer dsId = hibDS.getDsId(); Query hibQuery = session .createQuery("from SbiDataSetHistory h where h.active = ? and h.sbiDsConfig = ?"); hibQuery.setBoolean(0, true); hibQuery.setInteger(1, dsId); SbiDataSetHistory dsActiveDetail = (SbiDataSetHistory) hibQuery.uniqueResult(); if (dsActiveDetail != null) { toReturn = DataSetFactory.toDataSet(dsActiveDetail); } transaction.commit(); } catch (Throwable t) { if (transaction != null && transaction.isActive()) { transaction.rollback(); } throw new SpagoBIDOAException( "An unexpected error occured while loading dataset whose label is equal to [" + label + "]", t); } finally { if (session != null && session.isOpen()) { session.close(); } logger.debug("OUT"); } return toReturn; }
From source file:it.eng.spagobi.tools.dataset.dao.DataSetDAOImpl.java
License:Mozilla Public License
public IDataSet loadActiveIDataSetByID(Integer id) { IDataSet toReturn;// w w w. j ava2 s .c om Session session; Transaction transaction; logger.debug("IN"); toReturn = null; session = null; transaction = null; try { if (id == null) { throw new IllegalArgumentException("Input parameter [id] cannot be null"); } try { session = getSession(); Assert.assertNotNull(session, "session cannot be null"); transaction = session.beginTransaction(); Assert.assertNotNull(transaction, "transaction cannot be null"); } catch (Throwable t) { throw new SpagoBIDOAException("An error occured while creating the new transaction", t); } Query hibQuery = session .createQuery("from SbiDataSetHistory h where h.active = ? and h.sbiDsConfig = ?"); hibQuery.setBoolean(0, true); hibQuery.setInteger(1, id); SbiDataSetHistory dsActiveDetail = (SbiDataSetHistory) hibQuery.uniqueResult(); if (dsActiveDetail != null) { toReturn = DataSetFactory.toDataSet(dsActiveDetail); } transaction.commit(); } catch (Throwable t) { if (transaction != null && transaction.isActive()) { transaction.rollback(); } throw new SpagoBIDOAException( "An unexpected error occured while loading dataset whose id is equal to [" + id + "]", t); } finally { if (session != null && session.isOpen()) { session.close(); } logger.debug("OUT"); } return toReturn; }
From source file:it.eng.spagobi.tools.dataset.dao.DataSetDAOImpl.java
License:Mozilla Public License
public List<GuiGenericDataSet> loadFilteredDatasetList(String hsql, Integer offset, Integer fetchSize) { List<GuiGenericDataSet> toReturn; Session session;//from w w w . j a v a 2 s . c o m Transaction transaction; logger.debug("IN"); toReturn = null; session = null; transaction = null; try { toReturn = new ArrayList<GuiGenericDataSet>(); if (offset == null) { logger.warn("Input parameter [offset] is null. It will be set to [0]"); offset = new Integer(0); } if (fetchSize == null) { logger.warn("Input parameter [offset] is null. It will be set to [" + Integer.MAX_VALUE + "]"); fetchSize = Integer.MAX_VALUE; } try { session = getSession(); Assert.assertNotNull(session, "session cannot be null"); transaction = session.beginTransaction(); Assert.assertNotNull(transaction, "transaction cannot be null"); } catch (Throwable t) { throw new SpagoBIDOAException("An error occured while creating the new transaction", t); } Query countQuery = session.createQuery("select count(*) " + hsql); Long temp = (Long) countQuery.uniqueResult(); Integer resultNumber = new Integer(temp.intValue()); offset = offset < 0 ? 0 : offset; if (resultNumber > 0) { fetchSize = (fetchSize > 0) ? Math.min(fetchSize, resultNumber) : resultNumber; } Query listQuery = session.createQuery(hsql); listQuery.setFirstResult(offset); if (fetchSize > 0) listQuery.setMaxResults(fetchSize); List<SbiDataSetHistory> sbiDatasetVersions = listQuery.list(); if (sbiDatasetVersions != null && sbiDatasetVersions.isEmpty() == false) { for (SbiDataSetHistory sbiDatasetVersion : sbiDatasetVersions) { GuiGenericDataSet guiGenericDataSet = DataSetFactory.toGuiGenericDataSet(sbiDatasetVersion); List<GuiDataSetDetail> oldDsVersion = new ArrayList(); if (sbiDatasetVersion.getSbiDsConfig() != null) { Integer dsId = sbiDatasetVersion.getSbiDsConfig().getDsId(); Query hibQuery = session .createQuery("from SbiDataSetHistory h where h.active = ? and h.sbiDsConfig = ?"); hibQuery.setBoolean(0, false); hibQuery.setInteger(1, dsId); List<SbiDataSetHistory> olderTemplates = hibQuery.list(); if (olderTemplates != null && !olderTemplates.isEmpty()) { Iterator it2 = olderTemplates.iterator(); while (it2.hasNext()) { SbiDataSetHistory hibOldDataSet = (SbiDataSetHistory) it2.next(); if (hibOldDataSet != null && !hibOldDataSet.isActive()) { GuiDataSetDetail dsD = DataSetFactory.toGuiDataSetDetail(hibOldDataSet); oldDsVersion.add(dsD); } } } } guiGenericDataSet.setNonActiveDetails(oldDsVersion); toReturn.add(guiGenericDataSet); } } } catch (Throwable t) { if (transaction != null && transaction.isActive()) { transaction.rollback(); } throw new SpagoBIDOAException("An unexpected error occured while loading dataset versions", t); } finally { if (session != null && session.isOpen()) { session.close(); } logger.debug("OUT"); } return toReturn; }
From source file:it.eng.spagobi.tools.dataset.dao.DataSetDAOImpl.java
License:Mozilla Public License
/** * Returns List of all existent IDataSets with current active version * @param offset starting element//from w w w . ja va 2 s.co m * @param fetchSize number of elements to retrieve * @return List of all existent IDataSets with current active version * @throws EMFUserError the EMF user error */ public List<GuiGenericDataSet> loadPagedDatasetList(Integer offset, Integer fetchSize) { List<GuiGenericDataSet> toReturn; Session session; Transaction transaction; logger.debug("IN"); toReturn = null; session = null; transaction = null; try { toReturn = new ArrayList<GuiGenericDataSet>(); if (offset == null) { logger.warn("Input parameter [offset] is null. It will be set to [0]"); offset = new Integer(0); } if (fetchSize == null) { logger.warn("Input parameter [offset] is null. It will be set to [" + Integer.MAX_VALUE + "]"); fetchSize = Integer.MAX_VALUE; } try { session = getSession(); Assert.assertNotNull(session, "session cannot be null"); transaction = session.beginTransaction(); Assert.assertNotNull(transaction, "transaction cannot be null"); } catch (Throwable t) { throw new SpagoBIDOAException("An error occured while creating the new transaction", t); } Query countQuery = session.createQuery("select count(*) from SbiDataSetConfig"); Long resultNumber = (Long) countQuery.uniqueResult(); offset = offset < 0 ? 0 : offset; if (resultNumber > 0) { fetchSize = (fetchSize > 0) ? Math.min(fetchSize, resultNumber.intValue()) : resultNumber.intValue(); } Query listQuery = session .createQuery("from SbiDataSetHistory h where h.active = ? order by h.sbiDsConfig.name "); listQuery.setBoolean(0, true); listQuery.setFirstResult(offset); if (fetchSize > 0) listQuery.setMaxResults(fetchSize); List sbiActiveDatasetsList = listQuery.list(); if (sbiActiveDatasetsList != null && !sbiActiveDatasetsList.isEmpty()) { Iterator it = sbiActiveDatasetsList.iterator(); while (it.hasNext()) { SbiDataSetHistory hibDataSet = (SbiDataSetHistory) it.next(); GuiGenericDataSet ds = DataSetFactory.toGuiGenericDataSet(hibDataSet); List<GuiDataSetDetail> oldDsVersion = new ArrayList(); if (hibDataSet.getSbiDsConfig() != null) { Integer dsId = hibDataSet.getSbiDsConfig().getDsId(); Query hibQuery = session .createQuery("from SbiDataSetHistory h where h.active = ? and h.sbiDsConfig = ?"); hibQuery.setBoolean(0, false); hibQuery.setInteger(1, dsId); List<SbiDataSetHistory> olderTemplates = hibQuery.list(); if (olderTemplates != null && !olderTemplates.isEmpty()) { Iterator it2 = olderTemplates.iterator(); while (it2.hasNext()) { SbiDataSetHistory hibOldDataSet = (SbiDataSetHistory) it2.next(); if (hibOldDataSet != null && !hibOldDataSet.isActive()) { GuiDataSetDetail dsD = DataSetFactory.toGuiDataSetDetail(hibOldDataSet); oldDsVersion.add(dsD); } } } } ds.setNonActiveDetails(oldDsVersion); toReturn.add(ds); } } } catch (Throwable t) { if (transaction != null && transaction.isActive()) { transaction.rollback(); } throw new SpagoBIDOAException("An unexpected error occured while loading datasets", t); } finally { if (session != null && session.isOpen()) { session.close(); } logger.debug("OUT"); } return toReturn; }
From source file:it.eng.spagobi.tools.dataset.dao.DataSetDAOImpl.java
License:Mozilla Public License
/** * Load data set by id./*from w w w.j a v a 2 s .co m*/ * @param dsID the ds id * @return the data set as genericGuiDataset * @throws EMFUserError the EMF user error */ public GuiGenericDataSet loadDataSetById(Integer id) { GuiGenericDataSet toReturn; Session session; Transaction transaction; logger.debug("IN"); toReturn = null; session = null; transaction = null; try { if (id == null) { throw new IllegalArgumentException("Input parameter [id] cannot be null"); } try { session = getSession(); Assert.assertNotNull(session, "session cannot be null"); transaction = session.beginTransaction(); Assert.assertNotNull(transaction, "transaction cannot be null"); } catch (Throwable t) { throw new SpagoBIDOAException("An error occured while creating the new transaction", t); } Query hibQueryHistory = session .createQuery("from SbiDataSetHistory h where h.active = ? and h.sbiDsConfig = ?"); hibQueryHistory.setBoolean(0, true); hibQueryHistory.setInteger(1, id); SbiDataSetHistory sbiDataSetHistory = (SbiDataSetHistory) hibQueryHistory.uniqueResult(); if (sbiDataSetHistory != null) { toReturn = DataSetFactory.toGuiGenericDataSet(sbiDataSetHistory); } transaction.commit(); } catch (Throwable t) { if (transaction != null && transaction.isActive()) { transaction.rollback(); } throw new SpagoBIDOAException( "An unexpected error occured while loading dataset whose id is equal to [" + id + "]", t); } finally { if (session != null && session.isOpen()) { session.close(); } logger.debug("OUT"); } return toReturn; }
From source file:it.eng.spagobi.tools.dataset.dao.DataSetDAOImpl.java
License:Mozilla Public License
/** * Load data set by id.//from w w w. j av a 2 s.c o m * @param label the ds label * @return the data set as genericGuiDataset * @throws EMFUserError the EMF user error */ public GuiGenericDataSet loadDataSetByLabel(String label) { GuiGenericDataSet toReturn; Session session; Transaction transaction; logger.debug("IN"); toReturn = null; session = null; transaction = null; try { if (label == null) { throw new IllegalArgumentException("Input parameter [label] cannot be null"); } try { session = getSession(); Assert.assertNotNull(session, "session cannot be null"); transaction = session.beginTransaction(); Assert.assertNotNull(transaction, "transaction cannot be null"); } catch (Throwable t) { throw new SpagoBIDOAException("An error occured while creating the new transaction", t); } Query hibQueryHistory = session .createQuery("from SbiDataSetHistory h where h.active = ? and h.sbiDsConfig.label = ? "); hibQueryHistory.setBoolean(0, true); hibQueryHistory.setString(1, label); SbiDataSetHistory sbiDataSetHistory = (SbiDataSetHistory) hibQueryHistory.uniqueResult(); if (sbiDataSetHistory != null) { GuiDataSetDetail detail = DataSetFactory.toGuiDataSetDetail(sbiDataSetHistory); toReturn = DataSetFactory.toGuiGenericDataSet(sbiDataSetHistory); } transaction.commit(); } catch (Throwable t) { if (transaction != null && transaction.isActive()) { transaction.rollback(); } throw new SpagoBIDOAException( "An unexpected error occured while loading dataset whose label is equal to [" + label + "]", t); } finally { if (session != null && session.isOpen()) { session.close(); } logger.debug("OUT"); } return toReturn; }
From source file:it.eng.spagobi.tools.dataset.dao.DataSetDAOImpl.java
License:Mozilla Public License
/** * Modify data set.//from ww w . j ava2s. c o m * @param aDataSet the a data set * @throws EMFUserError the EMF user error * @see it.eng.spagobi.tools.dataset.dao.IDataSetDAO#modifyDataSet(it.eng.spagobi.tools.dataset.bo.AbstractDataSet) */ public void modifyDataSet(GuiGenericDataSet dataSet) { Session session; Transaction transaction; logger.debug("IN"); session = null; transaction = null; try { try { session = getSession(); Assert.assertNotNull(session, "session cannot be null"); transaction = session.beginTransaction(); Assert.assertNotNull(transaction, "transaction cannot be null"); } catch (Throwable t) { throw new SpagoBIDOAException("An error occured while creating the new transaction", t); } SbiDataSetHistory hibDataSet = null; if (dataSet != null) { Integer dsId = dataSet.getDsId(); GuiDataSetDetail dsActiveDetailToSet = dataSet.getActiveDetail(); if (dsActiveDetailToSet instanceof FileDataSetDetail) { hibDataSet = new SbiFileDataSet(); if (((FileDataSetDetail) dsActiveDetailToSet).getFileName() != null) { ((SbiFileDataSet) hibDataSet) .setFileName(((FileDataSetDetail) dsActiveDetailToSet).getFileName()); } } else if (dsActiveDetailToSet instanceof QueryDataSetDetail) { hibDataSet = new SbiQueryDataSet(); if (((QueryDataSetDetail) dsActiveDetailToSet).getQuery() != null) { ((SbiQueryDataSet) hibDataSet) .setQuery(((QueryDataSetDetail) dsActiveDetailToSet).getQuery()); } if (((QueryDataSetDetail) dsActiveDetailToSet).getQueryScript() != null) { ((SbiQueryDataSet) hibDataSet) .setQueryScript(((QueryDataSetDetail) dsActiveDetailToSet).getQueryScript()); } if (((QueryDataSetDetail) dsActiveDetailToSet).getQueryScriptLanguage() != null) { ((SbiQueryDataSet) hibDataSet).setQueryScriptLanguage( ((QueryDataSetDetail) dsActiveDetailToSet).getQueryScriptLanguage()); } if (((QueryDataSetDetail) dsActiveDetailToSet).getDataSourceLabel() != null) { SbiDataSource hibDataSource = null; String dataSourceLabel = ((QueryDataSetDetail) dsActiveDetailToSet).getDataSourceLabel(); Criterion labelCriterrion = Expression.eq("label", dataSourceLabel); Criteria criteria = session.createCriteria(SbiDataSource.class); criteria.add(labelCriterrion); hibDataSource = (SbiDataSource) criteria.uniqueResult(); ((SbiQueryDataSet) hibDataSet).setDataSource(hibDataSource); } } else if (dsActiveDetailToSet instanceof QbeDataSetDetail) { hibDataSet = new SbiQbeDataSet(); SbiQbeDataSet hibQbeDataSet = (SbiQbeDataSet) hibDataSet; QbeDataSetDetail qbeDataSet = (QbeDataSetDetail) dsActiveDetailToSet; hibQbeDataSet.setSqlQuery(qbeDataSet.getSqlQuery()); hibQbeDataSet.setJsonQuery(qbeDataSet.getJsonQuery()); hibQbeDataSet.setDatamarts(qbeDataSet.getDatamarts()); String dataSourceLabel = qbeDataSet.getDataSourceLabel(); Criterion labelCriterrion = Expression.eq("label", dataSourceLabel); Criteria criteria = session.createCriteria(SbiDataSource.class); criteria.add(labelCriterrion); SbiDataSource hibDataSource = (SbiDataSource) criteria.uniqueResult(); hibQbeDataSet.setDataSource(hibDataSource); } else if (dsActiveDetailToSet instanceof WSDataSetDetail) { hibDataSet = new SbiWSDataSet(); if (((WSDataSetDetail) dsActiveDetailToSet).getAddress() != null) { ((SbiWSDataSet) hibDataSet).setAdress(((WSDataSetDetail) dsActiveDetailToSet).getAddress()); } if (((WSDataSetDetail) dsActiveDetailToSet).getOperation() != null) { ((SbiWSDataSet) hibDataSet) .setOperation(((WSDataSetDetail) dsActiveDetailToSet).getOperation()); } } else if (dsActiveDetailToSet instanceof JClassDataSetDetail) { hibDataSet = new SbiJClassDataSet(); if (((JClassDataSetDetail) dsActiveDetailToSet).getJavaClassName() != null) { ((SbiJClassDataSet) hibDataSet) .setJavaClassName(((JClassDataSetDetail) dsActiveDetailToSet).getJavaClassName()); } } else if (dsActiveDetailToSet instanceof CustomDataSetDetail) { hibDataSet = new SbiCustomDataSet(); if (((CustomDataSetDetail) dsActiveDetailToSet).getCustomData() != null) { ((SbiCustomDataSet) hibDataSet) .setCustomData(((CustomDataSetDetail) dsActiveDetailToSet).getCustomData()); } if (((CustomDataSetDetail) dsActiveDetailToSet).getJavaClassName() != null) { ((SbiCustomDataSet) hibDataSet) .setJavaClassName(((CustomDataSetDetail) dsActiveDetailToSet).getJavaClassName()); } } else if (dsActiveDetailToSet instanceof ScriptDataSetDetail) { hibDataSet = new SbiScriptDataSet(); if (((ScriptDataSetDetail) dsActiveDetailToSet).getScript() != null) { ((SbiScriptDataSet) hibDataSet) .setScript(((ScriptDataSetDetail) dsActiveDetailToSet).getScript()); } if (((ScriptDataSetDetail) dsActiveDetailToSet).getLanguageScript() != null) { ((SbiScriptDataSet) hibDataSet) .setLanguageScript(((ScriptDataSetDetail) dsActiveDetailToSet).getLanguageScript()); } } SbiDomains transformer = null; if (dsActiveDetailToSet.getTransformerId() != null) { Criterion aCriterion = Expression.eq("valueId", dsActiveDetailToSet.getTransformerId()); Criteria criteria = session.createCriteria(SbiDomains.class); criteria.add(aCriterion); transformer = (SbiDomains) criteria.uniqueResult(); if (transformer == null) { throw new SpagoBIDOAException("The Domain with value_id= " + dsActiveDetailToSet.getTransformerId() + " does not exist"); } } SbiDomains category = null; if (dsActiveDetailToSet.getCategoryId() != null) { Criterion aCriterion = Expression.eq("valueId", dsActiveDetailToSet.getCategoryId()); Criteria criteria = session.createCriteria(SbiDomains.class); criteria.add(aCriterion); category = (SbiDomains) criteria.uniqueResult(); if (category == null) { throw new SpagoBIDOAException("The Domain with value_id= " + dsActiveDetailToSet.getCategoryId() + " does not exist"); } } Date currentTStamp = new Date(); hibDataSet.setTimeIn(currentTStamp); hibDataSet.setActive(true); hibDataSet.setTransformer(transformer); hibDataSet.setPivotColumnName(dsActiveDetailToSet.getPivotColumnName()); hibDataSet.setPivotRowName(dsActiveDetailToSet.getPivotRowName()); hibDataSet.setPivotColumnValue(dsActiveDetailToSet.getPivotColumnValue()); hibDataSet.setNumRows(dsActiveDetailToSet.isNumRows()); hibDataSet.setCategory(category); hibDataSet.setParameters(dsActiveDetailToSet.getParameters()); hibDataSet.setDsMetadata(dsActiveDetailToSet.getDsMetadata()); SbiDataSetConfig hibGenericDataSet = (SbiDataSetConfig) session.load(SbiDataSetConfig.class, dsId); hibGenericDataSet.setLabel(dataSet.getLabel()); hibGenericDataSet.setDescription(dataSet.getDescription()); hibGenericDataSet.setName(dataSet.getName()); updateSbiCommonInfo4Update(hibGenericDataSet); String userUp = hibGenericDataSet.getCommonInfo().getUserUp(); String sbiVersionUp = hibGenericDataSet.getCommonInfo().getSbiVersionUp(); hibDataSet.setUserIn(userUp); hibDataSet.setSbiVersionIn(sbiVersionUp); hibDataSet.setTimeIn(currentTStamp); hibDataSet.setOrganization(hibGenericDataSet.getCommonInfo().getOrganization()); Integer currenthigherVersion = getHigherVersionNumForDS(dsId); Integer newVersion = currenthigherVersion + 1; hibDataSet.setVersionNum(newVersion); Query hibQuery = session .createQuery("from SbiDataSetHistory h where h.active = ? and h.sbiDsConfig = ?"); hibQuery.setBoolean(0, true); hibQuery.setInteger(1, dsId); SbiDataSetHistory dsActiveDetail = (SbiDataSetHistory) hibQuery.uniqueResult(); dsActiveDetail.setActive(false); session.update(dsActiveDetail); session.update(hibGenericDataSet); hibDataSet.setSbiDsConfig(hibGenericDataSet); session.save(hibDataSet); transaction.commit(); } } catch (Throwable t) { if (transaction != null && transaction.isActive()) { transaction.rollback(); } throw new SpagoBIDOAException("Error while modifing the data Set with id " + ((dataSet == null) ? "" : String.valueOf(dataSet.getDsId())), t); } finally { if (session != null && session.isOpen()) { session.close(); } logger.debug("OUT"); } }
From source file:it.eng.spagobi.tools.dataset.dao.DataSetDAOImpl.java
License:Mozilla Public License
/** * Restore an Older Version of the dataset * @param dsId the a data set ID// ww w. j a v a 2s . co m * @param dsVersion the a data set Version * @throws EMFUserError the EMF user error */ public GuiGenericDataSet restoreOlderDataSetVersion(Integer dsId, Integer dsVersion) { logger.debug("IN"); Session session = null; Transaction transaction = null; GuiGenericDataSet toReturn = null; try { session = getSession(); transaction = session.beginTransaction(); if (dsId != null && dsVersion != null) { Query hibQuery = session .createQuery("from SbiDataSetHistory h where h.active = ? and h.sbiDsConfig = ?"); hibQuery.setBoolean(0, true); hibQuery.setInteger(1, dsId); SbiDataSetHistory dsActiveDetail = (SbiDataSetHistory) hibQuery.uniqueResult(); dsActiveDetail.setActive(false); Query hibernateQuery = session .createQuery("from SbiDataSetHistory h where h.versionNum = ? and h.sbiDsConfig = ?"); hibernateQuery.setInteger(0, dsVersion); hibernateQuery.setInteger(1, dsId); SbiDataSetHistory dsDetail = (SbiDataSetHistory) hibernateQuery.uniqueResult(); dsDetail.setActive(true); if (dsActiveDetail.getSbiDsConfig() != null) { SbiDataSetConfig hibDs = dsActiveDetail.getSbiDsConfig(); updateSbiCommonInfo4Update(hibDs); session.update(hibDs); } if (dsDetail.getSbiDsConfig() != null) { SbiDataSetConfig hibDs = dsDetail.getSbiDsConfig(); updateSbiCommonInfo4Update(hibDs); session.update(hibDs); } session.update(dsActiveDetail); session.update(dsDetail); transaction.commit(); toReturn = DataSetFactory.toGuiGenericDataSet(dsDetail); } } catch (Throwable t) { if (transaction != null && transaction.isActive()) { transaction.rollback(); } throw new SpagoBIDOAException( "Error while modifing the data Set with id " + ((dsId == null) ? "" : String.valueOf(dsId)), t); } finally { if (session != null && session.isOpen()) { session.close(); } logger.debug("OUT"); } return toReturn; }