Java Code Examples for org.hibernate.criterion.Expression#eq()

The following examples show how to use org.hibernate.criterion.Expression#eq() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SbiMetaSourceDAOHibImpl.java    From Knowage-Server with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public SbiMetaSource loadSourceByName(Session session, String name) throws EMFUserError {
	logger.debug("IN");

	SbiMetaSource toReturn = null;
	Session tmpSession = session;

	try {

		Criterion labelCriterrion = Expression.eq("name", name);
		Criteria criteria = tmpSession.createCriteria(SbiMetaSource.class);
		criteria.add(labelCriterrion);
		toReturn = (SbiMetaSource) criteria.uniqueResult();
		if (toReturn == null)
			return null;

	} catch (HibernateException he) {
		logException(he);
		throw new EMFUserError(EMFErrorSeverity.ERROR, 100);
	} finally {
		logger.debug("OUT");
	}

	return toReturn;
}
 
Example 2
Source File: SbiMetaBcDAOHibImpl.java    From Knowage-Server with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Load source by the unique name.
 *
 * @param session
 *            the session
 *
 * @param name
 *            the unique name
 *
 * @return the meta bc
 *
 * @throws EMFUserError
 *             the EMF user error
 *
 * @see it.eng.spagobi.metadata.dao.ISbiMetaBcDAOHibImpl#loadBcByUniqueName(session, string)
 */
@Override
public SbiMetaBc loadBcByUniqueName(Session session, String uniqueName) throws EMFUserError {
	logger.debug("IN");

	SbiMetaBc toReturn = null;

	try {
		Criterion labelCriterrion = Expression.eq("uniqueName", uniqueName);
		Criteria criteria = session.createCriteria(SbiMetaBc.class);
		criteria.add(labelCriterrion);
		toReturn = (SbiMetaBc) criteria.uniqueResult();
	} catch (HibernateException he) {
		logException(he);
		throw new HibernateException(he);
	} finally {
		logger.debug("OUT");
	}
	return toReturn;
}
 
Example 3
Source File: SbiMetaJobDAOHibImpl.java    From Knowage-Server with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public SbiMetaJob loadJobByName(Session session, String name) throws EMFUserError {
	logger.debug("IN");

	SbiMetaJob toReturn = null;
	Session tmpSession = session;

	try {
		Criterion labelCriterrion = Expression.eq("name", name);
		Criteria criteria = tmpSession.createCriteria(SbiMetaJob.class);
		criteria.add(labelCriterrion);
		toReturn = (SbiMetaJob) criteria.uniqueResult();
		if (toReturn == null)
			return null;

	} catch (HibernateException he) {
		logException(he);
		throw new EMFUserError(EMFErrorSeverity.ERROR, 100);
	} finally {
		logger.debug("OUT");
	}

	return toReturn;
}
 
Example 4
Source File: SbiMetaTableColumnDAOHibImpl.java    From Knowage-Server with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public SbiMetaTableColumn loadTableColumnByName(Session session, String name) throws EMFUserError {
	logger.debug("IN");

	SbiMetaTableColumn toReturn = null;
	Session tmpSession = session;
	try {
		Criterion labelCriterrion = Expression.eq("name", name);
		Criteria criteria = tmpSession.createCriteria(SbiMetaTableColumn.class);
		criteria.add(labelCriterrion);
		toReturn = (SbiMetaTableColumn) criteria.uniqueResult();
		if (toReturn == null)
			return null;
	} catch (HibernateException he) {
		logException(he);
		throw new HibernateException(he);
	} finally {
		logger.debug("OUT");
	}
	return toReturn;
}
 
Example 5
Source File: DistributionListDaoImpl.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public DistributionList loadDistributionListByName(String name) throws EMFUserError {
	logger.debug("IN");
	DistributionList biDL = null;
	Session tmpSession = null;
	Transaction tx = null;
	try {
		tmpSession = getSession();
		tx = tmpSession.beginTransaction();
		Criterion nameCriterrion = Expression.eq("name", name);
		Criteria criteria = tmpSession.createCriteria(SbiDistributionList.class);
		criteria.add(nameCriterrion);
		SbiDistributionList hibDL = (SbiDistributionList) criteria.uniqueResult();
		if (hibDL == null)
			return null;
		biDL = toDistributionList(hibDL);
		tx.commit();
	} catch (HibernateException he) {
		logger.error("Error while loading the Distribution List with name " + name, he);
		if (tx != null)
			tx.rollback();
		throw new EMFUserError(EMFErrorSeverity.ERROR, 9104);
	} finally {
		if (tmpSession != null) {
			if (tmpSession.isOpen())
				tmpSession.close();
		}
	}
	logger.debug("OUT");
	return biDL;
}
 
Example 6
Source File: SbiMetaBcAttributeDAOHibImpl.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public List<SbiMetaBcAttribute> loadAllBCAttributeFromTableColumn(int columnId) throws EMFUserError {
	logger.debug("IN");

	List toReturn = null;
	Session tmpSession = null;
	Transaction tx = null;

	try {
		tmpSession = getSession();
		tx = tmpSession.beginTransaction();

		Criterion labelCriterrion = Expression.eq("columnId", columnId);
		Criteria criteria = tmpSession.createCriteria(SbiMetaTableColumn.class);
		criteria.add(labelCriterrion);

		toReturn = criteria.list();
		if (toReturn == null)
			return null;
		tx.commit();

	} catch (HibernateException he) {
		logException(he);
		if (tx != null)
			tx.rollback();
		throw new EMFUserError(EMFErrorSeverity.ERROR, 100);
	} finally {
		if (tmpSession != null) {
			if (tmpSession.isOpen())
				tmpSession.close();
		}
	}

	logger.debug("OUT");
	return toReturn;
}
 
Example 7
Source File: DataSourceDAOHibImpl.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
private SbiDataSource loadSbiDataSourceWriteDefault(Session aSession) {
	Criterion labelCriterrion = Expression.eq("writeDefault", true);
	Criteria criteria = aSession.createCriteria(SbiDataSource.class);
	criteria.add(labelCriterrion);
	SbiDataSource hibDataSource = (SbiDataSource) criteria.uniqueResult();
	logger.debug("Hibernate datasource write default found in session: " + hibDataSource);
	return hibDataSource;
}
 
Example 8
Source File: BIObjectParameterDAOHibImpl.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public BIObjectParameter loadBiObjParameterByObjIdAndLabel(Integer objId, String label) throws EMFUserError {
	BIObjectParameter objPar = null;
	Session aSession = null;
	Transaction tx = null;
	try {
		aSession = getSession();
		tx = aSession.beginTransaction();

		Criterion idCriterrion = Expression.eq("sbiObject.biobjId", objId);
		Criterion labelCriterrion = Expression.eq("label", label);
		Criteria criteria = aSession.createCriteria(SbiObjPar.class);
		criteria.add(idCriterrion);
		criteria.add(labelCriterrion);

		SbiObjPar hibObjPar = (SbiObjPar) criteria.uniqueResult();
		if (hibObjPar != null)
			objPar = toBIObjectParameter(hibObjPar);

		tx.commit();
	} catch (HibernateException he) {
		logException(he);
		if (tx != null)
			tx.rollback();
		throw new EMFUserError(EMFErrorSeverity.ERROR, 100);
	} finally {
		if (aSession != null) {
			if (aSession.isOpen())
				aSession.close();
		}
	}
	return objPar;
}
 
Example 9
Source File: SbiMetaTableDAOHibImpl.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public List<SbiMetaTable> loadTablesFromSource(int sourceId) throws EMFUserError {
	logger.debug("IN");

	List toReturn = null;
	Session tmpSession = null;
	Transaction tx = null;

	try {
		tmpSession = getSession();
		tx = tmpSession.beginTransaction();

		Criterion labelCriterrion = Expression.eq("sourceid", sourceId);
		Criteria criteria = tmpSession.createCriteria(SbiMetaTable.class);
		criteria.add(labelCriterrion);

		toReturn = criteria.list();
		if (toReturn == null)
			return null;
		tx.commit();

	} catch (HibernateException he) {
		logException(he);
		if (tx != null)
			tx.rollback();
		throw new EMFUserError(EMFErrorSeverity.ERROR, 100);
	} finally {
		if (tmpSession != null) {
			if (tmpSession.isOpen())
				tmpSession.close();
		}
	}

	logger.debug("OUT");
	return toReturn;
}
 
Example 10
Source File: SbiMetaTableColumnDAOHibImpl.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void modifyTableColumn(Session session, SbiMetaTableColumn aMetaTableColumn) throws EMFUserError {
	logger.debug("IN");

	Session tmpSession = session;

	try {
		SbiMetaTableColumn hibMeta = (SbiMetaTableColumn) tmpSession.load(SbiMetaTableColumn.class, aMetaTableColumn.getColumnId());

		hibMeta.setName(aMetaTableColumn.getName());
		hibMeta.setType(aMetaTableColumn.getType());
		hibMeta.setDeleted(aMetaTableColumn.isDeleted());

		SbiMetaTable metaTable = null;
		if (aMetaTableColumn.getSbiMetaTable().getTableId() < 0) {
			Criterion aCriterion = Expression.eq("valueId", aMetaTableColumn.getSbiMetaTable().getTableId());
			Criteria criteria = tmpSession.createCriteria(SbiMetaSource.class);
			criteria.add(aCriterion);
			metaTable = (SbiMetaTable) criteria.uniqueResult();
			if (metaTable == null) {
				throw new SpagoBIDAOException("The SbiMetaTable with id= " + aMetaTableColumn.getSbiMetaTable().getTableId() + " does not exist");
			}
			hibMeta.setSbiMetaTable(metaTable);
		}

		updateSbiCommonInfo4Update(hibMeta);

	} catch (HibernateException he) {
		logException(he);
		throw new HibernateException(he);
	} finally {
		logger.debug("OUT");
	}
}
 
Example 11
Source File: MenuDAOImpl.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Load menu by id.
 *
 * @param menuID the menu id
 * @param roleId the user's role id
 *
 * @return the menu
 *
 * @throws EMFUserError the EMF user error
 *
 * @see it.eng.spagobi.wapp.dao.IMenuDAO#loadMenuByID(integer)
 */
@Override
public Menu loadMenuByID(Integer menuID, Integer roleID) throws EMFUserError {
	Menu toReturn = null;
	Session tmpSession = null;
	Transaction tx = null;

	try {
		tmpSession = getSession();
		tx = tmpSession.beginTransaction();

		Criterion domainCdCriterrion = Expression.eq("menuId", menuID);
		Criteria criteria = tmpSession.createCriteria(SbiMenu.class);
		criteria.add(domainCdCriterrion);
		SbiMenu hibMenu = (SbiMenu) criteria.uniqueResult();
		if (hibMenu == null)
			return null;

		// SbiMenu hibMenu = (SbiMenu)tmpSession.load(SbiMenu.class,
		// menuID);
		toReturn = toMenu(hibMenu, roleID);

	} catch (HibernateException he) {
		logException(he);

		if (tx != null)
			tx.rollback();

		throw new EMFUserError(EMFErrorSeverity.ERROR, 100);

	} finally {
		if (tmpSession != null) {
			if (tmpSession.isOpen())
				tmpSession.close();

		}
	}
	return toReturn;
}
 
Example 12
Source File: SbiMetaBcDAOHibImpl.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public List<SbiMetaBc> loadAllBCFromTable(int tableId) throws EMFUserError {
	logger.debug("IN");

	List toReturn = null;
	Session tmpSession = null;
	Transaction tx = null;

	try {
		tmpSession = getSession();
		tx = tmpSession.beginTransaction();

		Criterion labelCriterrion = Expression.eq("tableId", tableId);
		Criteria criteria = tmpSession.createCriteria(SbiMetaTable.class);
		criteria.add(labelCriterrion);

		toReturn = criteria.list();
		if (toReturn == null)
			return null;
		tx.commit();

	} catch (HibernateException he) {
		logException(he);
		if (tx != null)
			tx.rollback();
		throw new EMFUserError(EMFErrorSeverity.ERROR, 100);
	} finally {
		if (tmpSession != null) {
			if (tmpSession.isOpen())
				tmpSession.close();
		}
	}

	logger.debug("OUT");
	return toReturn;
}
 
Example 13
Source File: MenuDAOImpl.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public SbiMenu loadSbiMenubyName(String name) {
	Session tmpSession = null;
	Transaction tx = null;

	try {
		tmpSession = getSession();
		tx = tmpSession.beginTransaction();

		Criterion domainCdCriterrion = Expression.eq("name", name);
		Criteria criteria = tmpSession.createCriteria(SbiMenu.class);
		criteria.add(domainCdCriterrion);
		SbiMenu hibMenu = (SbiMenu) criteria.uniqueResult();

		return hibMenu;
	} catch (HibernateException he) {
		logException(he);
		if (tx != null)
			tx.rollback();

	} finally {
		if (tmpSession != null) {
			if (tmpSession.isOpen())
				tmpSession.close();
		}
	}
	return null;
}
 
Example 14
Source File: SbiMetaBcAttributeDAOHibImpl.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public List<SbiMetaBcAttribute> loadAllBCAttributeFromBC(int bcId) throws EMFUserError {
	logger.debug("IN");

	List toReturn = null;
	Session tmpSession = null;
	Transaction tx = null;

	try {
		tmpSession = getSession();
		tx = tmpSession.beginTransaction();

		Criterion labelCriterrion = Expression.eq("bcId", bcId);
		Criteria criteria = tmpSession.createCriteria(SbiMetaBcAttribute.class);
		criteria.add(labelCriterrion);

		toReturn = criteria.list();
		if (toReturn == null)
			return null;
		tx.commit();

	} catch (HibernateException he) {
		logException(he);
		if (tx != null)
			tx.rollback();
		throw new EMFUserError(EMFErrorSeverity.ERROR, 100);
	} finally {
		if (tmpSession != null) {
			if (tmpSession.isOpen())
				tmpSession.close();
		}
	}

	logger.debug("OUT");
	return toReturn;
}
 
Example 15
Source File: SbiGeoLayersDAOHibImpl.java    From Knowage-Server with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * Load layer by name.
 *
 * @param name
 *            the name
 *
 * @return the geo layer
 *
 * @throws EMFUserError
 *             the EMF user error
 *
 * @see it.eng.spagobi.mapcatalogue.dao.geo.bo.dao.ISbiGeoLayersDAO#loadLayerByName(string)
 */
@Override
public GeoLayer loadLayerByLabel(String label) throws EMFUserError {
	GeoLayer biLayer = null;
	Session tmpSession = null;
	// Transaction tx = null;

	try {
		tmpSession = getSession();
		// tx = tmpSession.beginTransaction();
		Criterion labelCriterrion = Expression.eq("label", label);
		Criteria criteria = tmpSession.createCriteria(SbiGeoLayers.class);
		criteria.add(labelCriterrion);
		SbiGeoLayers hibLayer = (SbiGeoLayers) criteria.uniqueResult();
		if (hibLayer == null)
			return null;
		biLayer = hibLayer.toGeoLayer();

		String resourcePath = SpagoBIUtilities.getResourcePath();
		if (biLayer.getPathFile() != null) {
			if (biLayer.getPathFile().startsWith(resourcePath)) {
				// biLayer.setPathFile(biLayer.getPathFile());
			} else {
				biLayer.setPathFile(resourcePath + File.separator + biLayer.getPathFile());
			}
		}

		// tx.commit();
	} catch (HibernateException he) {
		logException(he);
		// if (tx != null)
		// tx.rollback();
		throw new EMFUserError(EMFErrorSeverity.ERROR, 100);
	} finally {

		if (tmpSession != null) {
			if (tmpSession.isOpen())
				tmpSession.close();
		}

	}
	return biLayer;
}
 
Example 16
Source File: AssessmentGradingFacadeQueries.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
public Map<Long, List<ItemGradingData>> getItemScores(final Long itemId, List<AssessmentGradingData> scores, boolean loadItemGradingAttachment) {
    try {
        HashMap<Long, List<ItemGradingData>> map = new HashMap<>();

        HibernateCallback<List<ItemGradingData>> hcb = session -> {
            Criteria criteria = session.createCriteria(ItemGradingData.class);
            Disjunction disjunction = Expression.disjunction();

            /** make list from AssessmentGradingData ids */
            List<Long> gradingIdList = scores.stream()
                    .map(AssessmentGradingData::getAssessmentGradingId)
                    .collect(Collectors.toList());

            /** create or disjunctive expression for (in clauses) */
            List tempList;
            for (int i = 0; i < gradingIdList.size(); i += 50) {
                if (i + 50 > gradingIdList.size()) {
                    tempList = gradingIdList.subList(i, gradingIdList.size());
                    disjunction.add(Expression.in("assessmentGradingId", tempList));
                } else {
                    tempList = gradingIdList.subList(i, i + 50);
                    disjunction.add(Expression.in("assessmentGradingId", tempList));
                }
            }

            if (itemId.equals(Long.valueOf(0))) {
                criteria.add(disjunction);
                //criteria.add(Expression.isNotNull("submittedDate"));
            } else {

                /** create logical and between the pubCriterion and the disjunction criterion */
                //Criterion pubCriterion = Expression.eq("publishedItem.itemId", itemId);
                Criterion pubCriterion = Expression.eq("publishedItemId", itemId);
                criteria.add(Expression.and(pubCriterion, disjunction));
                //criteria.add(Expression.isNotNull("submittedDate"));
            }
            criteria.addOrder(Order.asc("agentId"));
            criteria.addOrder(Order.desc("submittedDate"));
            return criteria.list();
            //large list cause out of memory error (java heap space)
            //return criteria.setMaxResults(10000).list();
        };
        List<ItemGradingData> temp = getHibernateTemplate().execute(hcb);

        Map<Long, Set<ItemGradingAttachment>> attachmentMap = new HashMap<>();
        if (loadItemGradingAttachment) {
            attachmentMap = getItemGradingAttachmentMap(itemId);
        }
        for (ItemGradingData data : temp) {
            if (loadItemGradingAttachment) {
                if (attachmentMap.get(data.getItemGradingId()) != null) {
                    data.setItemGradingAttachmentSet(attachmentMap.get(data.getItemGradingId()));
                } else {
                    data.setItemGradingAttachmentSet(new HashSet<>());
                }
            }
            List<ItemGradingData> thisone = map.get(data.getPublishedItemId());
            if (thisone == null) {
                thisone = new ArrayList<>();
            }
            thisone.add(data);
            map.put(data.getPublishedItemId(), thisone);
        }
        return map;
    } catch (Exception e) {
        log.warn(e.getMessage(), e);
        return new HashMap<>();
    }
}
 
Example 17
Source File: SbiMetaTableDAOHibImpl.java    From Knowage-Server with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * Insert a metatable.
 *
 * @param aMetaSource
 *            the sbimetatable to insert
 *
 * @throws EMFUserError
 *             the EMF user error
 *
 * @see it.eng.spagobi.metadata.dao.ISbiMetaTableDAOHibImpl#insertSource(SbiMetaTable)
 */
@Override
public Integer insertTable(SbiMetaTable aMetaTable) throws EMFUserError {
	logger.debug("IN");

	Session tmpSession = null;
	Transaction tx = null;
	Integer idToReturn = null;

	try {
		tmpSession = getSession();
		tx = tmpSession.beginTransaction();

		SbiMetaTable hibMeta = new SbiMetaTable();
		hibMeta.setName(aMetaTable.getName());
		hibMeta.setDeleted(aMetaTable.isDeleted());

		SbiMetaSource metaSource = null;
		if (aMetaTable.getSbiMetaSource() != null) {
			Criterion aCriterion = Expression.eq("sourceId", aMetaTable.getSbiMetaSource().getSourceId());
			Criteria criteria = tmpSession.createCriteria(SbiMetaSource.class);
			criteria.add(aCriterion);
			metaSource = (SbiMetaSource) criteria.uniqueResult();
			if (metaSource == null) {
				throw new SpagoBIDAOException("The Domain with value_id= " + aMetaTable.getSbiMetaSource().getSourceId() + " does not exist");
			}
			hibMeta.setSbiMetaSource(metaSource);
		}

		updateSbiCommonInfo4Insert(hibMeta);
		idToReturn = (Integer) tmpSession.save(hibMeta);
		tx.commit();

	} catch (HibernateException he) {
		logException(he);

		if (tx != null)
			tx.rollback();

		throw new EMFUserError(EMFErrorSeverity.ERROR, 100);

	} finally {

		if (tmpSession != null) {
			if (tmpSession.isOpen())
				tmpSession.close();
		}

	}
	logger.debug("OUT");
	return idToReturn;
}
 
Example 18
Source File: ObjMetacontentDAOHibImpl.java    From Knowage-Server with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * Insert object's metadata content.
 *
 * @param aObjMetacontent
 *            the metadata content
 *
 * @throws EMFUserError
 *             the EMF user error
 *
 * @see it.eng.spagobi.tools.objmetadata.dao.IObjMetadataDAO#insertObjMetacontent(it.eng.spagobi.tools.objmetadata.bo.ObjMetacontent)
 */
@Override
public void insertObjMetacontent(ObjMetacontent aObjMetacontent) throws EMFUserError {

	logger.debug("IN");
	Session aSession = null;
	Transaction tx = null;
	Criterion aCriterion = null;
	Criteria criteria = null;
	try {
		aSession = getSession();
		tx = aSession.beginTransaction();

		SbiObjMetacontents hibContents = new SbiObjMetacontents();

		// get biobject reference
		aCriterion = Expression.eq("biobjId", aObjMetacontent.getBiobjId());
		criteria = aSession.createCriteria(SbiObjects.class);
		criteria.add(aCriterion);
		SbiObjects biobj = (SbiObjects) criteria.uniqueResult();
		hibContents.setSbiObjects(biobj);

		// get subobject reference
		if (aObjMetacontent.getSubobjId() == null) {
			hibContents.setSbiSubObjects(null);
		} else {
			aCriterion = Expression.eq("subObjId", aObjMetacontent.getSubobjId());
			criteria = aSession.createCriteria(SbiSubObjects.class);
			criteria.add(aCriterion);
			SbiSubObjects subobj = (SbiSubObjects) criteria.uniqueResult();
			hibContents.setSbiSubObjects(subobj);
		}

		SbiBinContents binaryContent = new SbiBinContents();
		binaryContent.setContent(aObjMetacontent.getContent());
		updateSbiCommonInfo4Insert(binaryContent);
		aSession.save(binaryContent);
		hibContents.setSbiBinContents(binaryContent);

		hibContents.setObjmetaId(aObjMetacontent.getObjmetaId());

		hibContents.setCreationDate(aObjMetacontent.getCreationDate());

		hibContents.setLastChangeDate(aObjMetacontent.getLastChangeDate());

		hibContents.setAdditionalInfo(aObjMetacontent.getAdditionalInfo());

		updateSbiCommonInfo4Insert(hibContents);
		aSession.save(hibContents);
		tx.commit();
	} catch (HibernateException he) {
		logger.error(
				"Error while inserting the metadata content with id "
						+ ((aObjMetacontent == null) ? "" : String.valueOf(aObjMetacontent.getObjMetacontentId())), he);

		if (tx != null)
			tx.rollback();

		throw new EMFUserError(EMFErrorSeverity.ERROR, 100);

	} finally {
		if (aSession != null) {
			if (aSession.isOpen())
				aSession.close();
			logger.debug("OUT");
		}
	}

}
 
Example 19
Source File: SbiMetaTableDAOHibImpl.java    From Knowage-Server with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * Modify a metatable.
 *
 * @param aMetaTable
 *            the sbimetatable changed
 *
 * @throws EMFUserError
 *             the EMF user error
 *
 * @see it.eng.spagobi.metadata.dao.ISbiMetaTableDAOHibImpl#modifyTable(SbiMetaTable)
 */
@Override
public void modifyTable(SbiMetaTable aMetaTable) throws EMFUserError {
	logger.debug("IN");

	Session tmpSession = null;
	Transaction tx = null;

	try {
		tmpSession = getSession();
		tx = tmpSession.beginTransaction();

		SbiMetaTable hibMeta = (SbiMetaTable) tmpSession.load(SbiMetaTable.class, aMetaTable.getTableId());

		hibMeta.setName(aMetaTable.getName());
		hibMeta.setDeleted(aMetaTable.isDeleted());

		SbiMetaSource metaSource = null;
		if (aMetaTable.getSbiMetaSource().getSourceId() < 0) {
			Criterion aCriterion = Expression.eq("valueId", aMetaTable.getSbiMetaSource().getSourceId());
			Criteria criteria = tmpSession.createCriteria(SbiMetaSource.class);
			criteria.add(aCriterion);
			metaSource = (SbiMetaSource) criteria.uniqueResult();
			if (metaSource == null) {
				throw new SpagoBIDAOException("The Domain with value_id= " + aMetaTable.getSbiMetaSource().getSourceId() + " does not exist");
			}
			hibMeta.setSbiMetaSource(metaSource);
		}

		updateSbiCommonInfo4Update(hibMeta);
		tx.commit();

	} catch (HibernateException he) {
		logException(he);

		if (tx != null)
			tx.rollback();

		throw new EMFUserError(EMFErrorSeverity.ERROR, 100);

	} finally {
		if (tmpSession != null) {
			if (tmpSession.isOpen())
				tmpSession.close();
		}
	}
	logger.debug("OUT");

}
 
Example 20
Source File: LowFunctionalityDAOHibImpl.java    From Knowage-Server with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * Load sub low functionalities.
 *
 * @param initialPath
 *            the initial path
 * @param recoverBIObjects
 *            the recover bi objects
 *
 * @return the list
 *
 * @throws EMFUserError
 *             the EMF user error
 *
 * @see it.eng.spagobi.analiticalmodel.functionalitytree.dao.ILowFunctionalityDAO#loadSubLowFunctionalities(java.lang.String, boolean)
 */
@Override
public List loadSubLowFunctionalities(String initialPath, boolean recoverBIObjects) throws EMFUserError {
	logger.debug("IN");
	Session aSession = null;
	Transaction tx = null;
	List realResult = new ArrayList();
	try {
		aSession = getSession();
		tx = aSession.beginTransaction();

		// loads folder corresponding to initial path
		Criterion domainCdCriterrion = Expression.eq("path", initialPath);
		Criteria criteria = aSession.createCriteria(SbiFunctions.class);
		criteria.add(domainCdCriterrion);
		SbiFunctions hibFunct = (SbiFunctions) criteria.uniqueResult();
		if (hibFunct == null) {
			return null;
		}
		LowFunctionality funct = toLowFunctionality(hibFunct, recoverBIObjects);
		putIntoCache(String.valueOf(funct.getId()), funct);
		realResult.add(funct);

		// loads sub functionalities

		/* ********* start luca changes *************** */
		// Query hibQuery =
		// aSession.createQuery(" from SbiFunctions s where s.path like '" +
		// initialPath + "/%' order by s.parentFunct.functId, s.prog");
		Query hibQuery = aSession.createQuery(" from SbiFunctions s where s.path like ? order by s.parentFunct.functId, s.prog");
		// Query hibQuery =
		// aSession.createQuery(" from SbiFunctions s where s.functTypeCd = 'LOW_FUNCT' and s.path like '"
		// + initialPath +
		// "/%' order by s.parentFunct.functId, s.prog");
		/* ********* end luca changes ***************** */
		hibQuery.setString(0, initialPath + "/%");
		List hibList = hibQuery.list();
		Iterator it = hibList.iterator();
		while (it.hasNext()) {
			funct = toLowFunctionality((SbiFunctions) it.next(), recoverBIObjects);
			putIntoCache(String.valueOf(funct.getId()), funct);
			realResult.add(funct);
		}
		tx.commit();
	} catch (HibernateException he) {
		logger.error("HibernateException", he);

		if (tx != null)
			tx.rollback();

		throw new EMFUserError(EMFErrorSeverity.ERROR, 100);

	} finally {
		if (aSession != null) {
			if (aSession.isOpen())
				aSession.close();
		}
	}
	logger.debug("OUT");
	return realResult;
}