org.hibernate.Session#isOpen ( )源码实例Demo

下面列出了org.hibernate.Session#isOpen ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: Knowage-Server   文件: DataSourceDAOHibImpl.java
@Override
public IDataSource loadDataSourceWriteDefault() throws EMFUserError {
	logger.debug("IN");
	IDataSource toReturn = null;
	Session tmpSession = null;
	Transaction tx = null;
	try {
		tmpSession = getSession();
		tx = tmpSession.beginTransaction();
		toReturn = loadDataSourceWriteDefault(tmpSession);
		logger.debug("Datasource write default found : " + toReturn);
		tx.commit();
	} catch (HibernateException he) {
		logger.error("Error while loading the data source with write default = true: check there are no more than one (incorrect situation)", 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;
}
 
源代码2 项目: Knowage-Server   文件: ObjNoteDAOHibImpl.java
@Override
public ObjNote getExecutionNotes(Integer biobjId, String execIdentif) throws Exception {
	ObjNote objNote = null;
	Session aSession = null;
	Transaction tx = null;
	try {
		aSession = getSession();
		tx = aSession.beginTransaction();
		// String hql = "from SbiObjNotes son where son.sbiObject.biobjId = " + biobjId +
		// " and son.execReq = '"+execIdentif+"'";

		String hql = "from SbiObjNotes son where son.sbiObject.biobjId = ?" + " and son.execReq = ?";
		Query query = aSession.createQuery(hql);
		query.setInteger(0, biobjId.intValue());
		query.setString(1, execIdentif);

		SbiObjNotes hibObjNote = null;
		List l = query.list();
		if (l != null && !l.isEmpty()) {
			hibObjNote = (SbiObjNotes) l.get(0);
		}
		if (hibObjNote != null) {
			objNote = toObjNote(hibObjNote);
		}
	} 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 objNote;
}
 
源代码3 项目: Knowage-Server   文件: SbiMetaBcDAOHibImpl.java
/**
 * Load all BCs.
 *
 * @return List of meta bc
 *
 * @throws EMFUserError
 *             the EMF user error
 *
 * @see it.eng.spagobi.metadata.dao.ISbiMetaBcDAOHibImpl#loadAllBCs()
 */
@Override
public List<SbiMetaBc> loadAllBCs() throws EMFUserError {
	logger.debug("IN");

	Session tmpSession = null;
	Transaction tx = null;
	List<SbiMetaBc> toReturn = new ArrayList();
	try {
		tmpSession = getSession();
		tx = tmpSession.beginTransaction();

		Query hibQuery = tmpSession.createQuery(" from SbiMetaBc");

		List hibList = hibQuery.list();
		Iterator it = hibList.iterator();
		while (it.hasNext()) {
			SbiMetaBc hibMeta = (SbiMetaBc) it.next();
			toReturn.add(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 toReturn;
}
 
源代码4 项目: Knowage-Server   文件: I18NMessagesDAOHibImpl.java
@Override
public void deleteNonDefaultI18NMessages(SbiI18NMessages message) {
	logger.debug("IN");
	Session session = null;
	Transaction tx = null;
	try {
		session = getSession();
		tx = session.beginTransaction();
		String tenant = getTenant();
		List<SbiI18NMessages> nonDefaultMessages = getSbiI18NMessagesByLabel(message, tenant, session);
		Iterator<SbiI18NMessages> it = nonDefaultMessages.iterator();
		while (it.hasNext()) {
			SbiI18NMessages toDelete = it.next();
			session.delete(toDelete);
			session.flush();
		}
		tx.commit();
	} catch (HibernateException e) {
		logException(e);
		if (tx != null)
			tx.rollback();
		throw new RuntimeException();
	} finally {
		if (session != null) {
			if (session.isOpen())
				session.close();
		}
	}
	logger.debug("OUT");
}
 
/**
 * Load all BCAttributes.
 *
 * @return List of meta bcAttributes
 *
 * @throws EMFUserError
 *             the EMF user error
 *
 * @see it.eng.spagobi.metadata.dao.ISbiMetaBcAttributeDAOHibImpl#loadAllBCAttributes()
 */
@Override
public List<SbiMetaBcAttribute> loadAllBCAttributes() throws EMFUserError {
	logger.debug("IN");

	Session tmpSession = null;
	Transaction tx = null;
	List<SbiMetaBcAttribute> toReturn = new ArrayList();
	try {
		tmpSession = getSession();
		tx = tmpSession.beginTransaction();

		Query hibQuery = tmpSession.createQuery(" from SbiMetaBcAttribute");

		List hibList = hibQuery.list();
		Iterator it = hibList.iterator();
		while (it.hasNext()) {
			SbiMetaBcAttribute hibMeta = (SbiMetaBcAttribute) it.next();
			toReturn.add(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 toReturn;
}
 
源代码6 项目: Knowage-Server   文件: SbiGeoFeaturesDAOHibImpl.java
/**
 * Checks for maps associated.
 * 
 * @param featureId the feature id
 * 
 * @return true, if checks for maps associated
 * 
 * @throws EMFUserError the EMF user error
 * 
 * @see it.eng.spagobi.mapcatalogue.dao.geo.bo.dao.ISbiGeoMapsDAO#hasFeaturesAssociated(java.lang.String)
 */
public boolean hasMapsAssociated (String featureId) throws EMFUserError{
	boolean bool = false; 
	
	
	Session tmpSession = null;
	Transaction tx = null;
	try {
		tmpSession = getSession();
		tx = tmpSession.beginTransaction();
		Integer mapIdInt = Integer.valueOf(featureId);
		
		//String hql = " from SbiGeoMapFeatures s where s.id.featureId = "+ mapIdInt;
		String hql = " from SbiGeoMapFeatures s where s.id.featureId = ?";
		Query aQuery = tmpSession.createQuery(hql);
		aQuery.setInteger(0, mapIdInt.intValue());
		
		List biFeaturesAssocitedWithMap = aQuery.list();
		if (biFeaturesAssocitedWithMap.size() > 0)
			bool = true;
		else
			bool = false;
		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 bool;
	
}
 
源代码7 项目: Knowage-Server   文件: EngineDAOHibImpl.java
/**
 * Load all engines for bi object type.
 *
 * @param biobjectType
 *            the biobject type
 *
 * @return the list
 *
 * @throws EMFUserError
 *             the EMF user error
 *
 * @see it.eng.spagobi.engines.config.dao.IEngineDAO#loadAllEnginesForBIObjectType(java.lang.String)
 */
@Override
public List<Engine> loadAllEnginesForBIObjectType(String biobjectType) throws EMFUserError {
	logger.debug("IN");
	Session aSession = null;
	Transaction tx = null;

	logger.debug("BiObject Type is " + biobjectType);
	List<Engine> realResult = new ArrayList<Engine>();
	try {
		aSession = getSession();
		tx = aSession.beginTransaction();

		Query hibQuery = aSession.createQuery(" from SbiEngines engines where engines.biobjType.valueCd = ?");
		hibQuery.setString(0, biobjectType);
		List hibList = hibQuery.list();
		Iterator it = hibList.iterator();

		while (it.hasNext()) {
			realResult.add(toEngine((SbiEngines) it.next()));
		}
	} catch (HibernateException he) {
		logger.debug("Error in loading ecgines for biObject Type " + biobjectType, he);
		logException(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;
}
 
源代码8 项目: Knowage-Server   文件: SbiMetaTableDAOHibImpl.java
/**
 * Checks for BC associated.
 *
 * @param bcId
 *            the BC id
 *
 * @return true, if checks for BC associated
 *
 * @throws EMFUserError
 *             the EMF user error
 *
 * @see it.eng.spagobi.metadata.dao.ISbiMetaSourceDAOHibImpl#hasBcAssociated(int)
 */
@Override
public boolean hasBcAssociated(Integer id) throws EMFUserError {
	boolean bool = false;

	Session tmpSession = null;
	Transaction tx = null;
	try {
		tmpSession = getSession();
		tx = tmpSession.beginTransaction();

		String hql = " from SbiMetaTableBc s where s.id.tableId = ?";
		Query aQuery = tmpSession.createQuery(hql);
		aQuery.setInteger(0, id);

		List bcAssociated = aQuery.list();
		if (bcAssociated.size() > 0)
			bool = true;
		else
			bool = false;
		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 bool;

}
 
源代码9 项目: Knowage-Server   文件: SbiJobSourceDAOHibImpl.java
@Override
public void modifyJobSource(SbiMetaJobSource aMetaJobSource) throws EMFUserError {
	logger.debug("IN");

	Session aSession = null;
	Transaction tx = null;
	try {
		aSession = getSession();
		tx = aSession.beginTransaction();
		SbiMetaJobSourceId hibId = new SbiMetaJobSourceId();
		hibId.setJobId(aMetaJobSource.getId().getJobId());
		hibId.setSourceId(aMetaJobSource.getId().getSourceId());

		updateSbiCommonInfo4Update(hibId);
		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();
		}

	}
	logger.debug("OUT");
}
 
/**
 * Exist by code.
 *
 * @param code
 *            the code
 *
 * @return the integer
 *
 * @throws EMFUserError
 *             the EMF user error
 *
 * @see it.eng.spagobi.analiticalmodel.functionalitytree.dao.ILowFunctionalityDAO#existByCode(java.lang.String)
 */
@Override
public Integer existByCode(String code) throws EMFUserError {
	Integer id = null;
	Session aSession = null;
	Transaction tx = null;
	try {
		aSession = getSession();
		tx = aSession.beginTransaction();
		Criterion domainCdCriterrion = Expression.eq("code", code);
		Criteria criteria = aSession.createCriteria(SbiFunctions.class);
		criteria.add(domainCdCriterrion);
		SbiFunctions func = (SbiFunctions) criteria.uniqueResult();
		if (func != null) {
			id = func.getFunctId();
		}
		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();
		}
	}
	return id;
}
 
/**
 * Load maps by feature id.
 * 
 * @param featureId the feature id
 * 
 * @return the list
 * 
 * @throws EMFUserError the EMF user error
 * 
 * @see it.eng.spagobi.mapcatalogue.dao.bo.dao.ISbiGeoMapFeaturesDAO#loadMapsByFeatureId(java.lang.Integer)
 */	
public List loadMapsByFeatureId(Integer featureId) throws EMFUserError {
	Session aSession = null;
	Transaction tx = null;
	List realResult = new ArrayList();
	String hql = null;
	Query hqlQuery = null;
	
	try {
		aSession = getSession();
		tx = aSession.beginTransaction();

		/*hql = " from SbiGeoMapFeatures as mf " + 
         "where mf.id.featureId = " + featureId.toString();*/
		
		hql = " from SbiGeoMapFeatures as mf " + 
         "where mf.id.featureId = ?" ;
		
		hqlQuery = aSession.createQuery(hql);
		hqlQuery.setInteger(0, featureId.intValue());
		List hibList = hqlQuery.list();
		
		Iterator it = hibList.iterator();
		ISbiGeoMapsDAO mapDAO = DAOFactory.getSbiGeoMapsDAO();
		SbiGeoMapFeatures tmpMapFeature = null;
		GeoMap tmpMap = null;
		while (it.hasNext()) {				
			tmpMapFeature = (SbiGeoMapFeatures) it.next();
			SbiGeoMapFeaturesId tmpMapFeatureId = tmpMapFeature.getId();				
			tmpMap = mapDAO.loadMapByID(new Integer(tmpMapFeatureId.getMapId()));
			if (tmpMap != null)
				realResult.add((GeoMap)tmpMap);
		}
		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 realResult;
}
 
源代码12 项目: Knowage-Server   文件: EventLogDAOHibImpl.java
/**
 * Insert event log.
 *
 * @param eventLog
 *            the event log
 *
 * @return the integer
 *
 * @throws EMFUserError
 *             the EMF user error
 *
 * @see it.eng.spagobi.events.dao.IEventLogDAO#insertEventLog(it.eng.spagobi.events.bo.EventLog)
 */
@Override
public Integer insertEventLog(EventLog eventLog) throws EMFUserError {
	logger.debug("IN");
	Session session = null;
	Transaction tx = null;
	try {
		session = getSession();
		tx = session.beginTransaction();

		SbiEventsLog hibEventLog = new SbiEventsLog();
		hibEventLog.setUser(eventLog.getUser());
		hibEventLog.setDate(eventLog.getDate());
		hibEventLog.setDesc(eventLog.getDesc());
		hibEventLog.setParams(eventLog.getParams());
		hibEventLog.setEventType(eventLog.getType());
		this.updateSbiCommonInfo4Insert(hibEventLog);
		Set hibEventRoles = new HashSet();
		List roles = eventLog.getRoles();
		Iterator rolesIt = roles.iterator();
		while (rolesIt.hasNext()) {
			String roleName = (String) rolesIt.next();
			String hql = "from SbiExtRoles as roles where roles.name = ?";

			Query hqlQuery = session.createQuery(hql);
			hqlQuery.setString(0, roleName);
			SbiExtRoles aHibRole = (SbiExtRoles) hqlQuery.uniqueResult();
			if (aHibRole == null) {
				logger.error("Role with name = '" + roleName + "' does not exist!!");
				continue;
			}
			hibEventRoles.add(aHibRole);
		}
		hibEventLog.setRoles(hibEventRoles);
		session.save(hibEventLog);
		tx.commit();
		return hibEventLog.getId();
	} catch (HibernateException he) {
		logException(he);

		throw new EMFUserError(EMFErrorSeverity.ERROR, 100);

	} finally {
		if (session != null) {
			if (session.isOpen())
				session.close();
		}
		logger.debug("OUT");
	}
}
 
@Override
public Integer insertCommunityFunctionality(LowFunctionality aLowFunctionality) throws EMFUserError {
	logger.debug("IN");
	Session aSession = null;
	Transaction tx = null;
	Integer result = null;
	try {
		aSession = getSession();
		tx = aSession.beginTransaction();
		SbiFunctions hibFunct = new SbiFunctions();

		// recover sbidomain of the user functionality
		Criterion vcdEQusfunct = Expression.eq("valueCd", "COMMUNITY_FUNCT");
		Criteria criteria = aSession.createCriteria(SbiDomains.class);
		criteria.add(vcdEQusfunct);
		SbiDomains functTypeDomain = (SbiDomains) criteria.uniqueResult();

		hibFunct.setFunctType(functTypeDomain);
		hibFunct.setCode(aLowFunctionality.getCode());
		hibFunct.setFunctTypeCd(functTypeDomain.getValueCd());
		hibFunct.setDescr(aLowFunctionality.getDescription());
		hibFunct.setName(aLowFunctionality.getName());
		hibFunct.setPath(aLowFunctionality.getPath());

		Integer parentId = aLowFunctionality.getParentId();
		SbiFunctions hibParentFunct = null;
		if (parentId != null) {
			// if it is not the root controls if the parent functionality
			// exists
			Criteria parentCriteria = aSession.createCriteria(SbiFunctions.class);
			Criterion parentCriterion = Expression.eq("functId", parentId);
			parentCriteria.add(parentCriterion);
			hibParentFunct = (SbiFunctions) parentCriteria.uniqueResult();
			if (hibParentFunct == null) {
				logger.error("The parent Functionality with id = " + parentId + " does not exist.");
				throw new EMFUserError(EMFErrorSeverity.ERROR, 1038);
			}
		}
		// if it is the root the parent functionality is null
		hibFunct.setParentFunct(hibParentFunct);

		// manages prog column that determines the folders order
		if (hibParentFunct == null)
			hibFunct.setProg(new Integer(1));
		else {
			// loads sub functionalities

			Query hibQuery = aSession.createQuery("select max(s.prog) from SbiFunctions s where s.parentFunct.functId = ? and s.functTypeCd = ?");
			hibQuery.setInteger(0, parentId.intValue());
			hibQuery.setString(1, "COMMUNITY_FUNCT");
			Integer maxProg = (Integer) hibQuery.uniqueResult();
			if (maxProg != null)
				hibFunct.setProg(new Integer(maxProg.intValue() + 1));
			else
				hibFunct.setProg(new Integer(1));
		}

		updateSbiCommonInfo4Insert(hibFunct, true);

		result = (Integer) aSession.save(hibFunct);

		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("The [insertCommunityFunctionality] occurs. LowFunctionality cache will be cleaned.");
				this.clearCache();
			}
			logger.debug("OUT");
		}
	}
	return result;
}
 
源代码14 项目: Knowage-Server   文件: ObjMetacontentDAOHibImpl.java
/**
 * Loads all metacontent for one object or for one subobject, if biObjId is not null load all metacontents for object, if subObjId is not null load all
 * metacontents for subobject
 *
 * @param biObjId
 *            The biObjId for the object to load
 * @param subObjId
 *            The subObjId for the subObject to load
 *
 * @return A list containing all metadata objects
 *
 * @throws EMFUserError
 *             If an Exception occurred
 */

@Override
public List loadObjOrSubObjMetacontents(Integer biObjId, Integer subObjId) throws EMFUserError {

	logger.debug("IN");
	List realResult = new ArrayList();
	Session session = null;
	Transaction tx = null;
	Integer id = null;
	try {
		session = getSession();
		tx = session.beginTransaction();
		String hql = "";

		if (subObjId != null) {
			logger.debug("laod metacontents associated to subbiobj " + subObjId);
			hql = " from SbiObjMetacontents c where c.sbiSubObjects.subObjId = ?";
			id = subObjId;
		} else if (biObjId != null) {
			logger.debug("laod metacontents associated to biobj " + biObjId);
			hql = " from SbiObjMetacontents c where c.sbiObjects.biobjId = ? AND c.sbiSubObjects.subObjId is null";
			id = biObjId;
		}

		Query aQuery = session.createQuery(hql);
		aQuery.setInteger(0, id.intValue());
		List hibList = aQuery.list();
		if (hibList != null && !hibList.isEmpty()) {
			Iterator it = hibList.iterator();
			while (it.hasNext()) {
				realResult.add(toObjMetacontent((SbiObjMetacontents) it.next()));
			}
		}
		tx.rollback();
	} catch (HibernateException he) {
		logger.error("Error while loading the metadata content referring to object or subobject (check log before) with id = " + id, he);
		if (tx != null)
			tx.rollback();
		throw new EMFUserError(EMFErrorSeverity.ERROR, 100);
	} finally {
		if (session != null) {
			if (session.isOpen())
				session.close();
		}
	}
	logger.debug("OUT");
	return realResult;

}
 
源代码15 项目: Knowage-Server   文件: ObjMetadataDAOHibImpl.java
/**
 * Insert object's metadata.
 *
 * @param aObjMetadata the metadata
 *
 * @throws EMFUserError the EMF user error
 *
 * @see it.eng.spagobi.tools.objmetadata.dao.IObjMetadataDAO#insertObjMetadata(it.eng.spagobi.tools.objmetadata.bo.ObjMetadata)
 */
@Override
public void insertObjMetadata(ObjMetadata aObjMetadata) throws EMFUserError {

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

		Criterion aCriterion = Expression.eq("valueId", aObjMetadata.getDataType());
		Criteria criteria = aSession.createCriteria(SbiDomains.class);
		criteria.add(aCriterion);

		SbiDomains dataType = (SbiDomains) criteria.uniqueResult();

		if (dataType == null) {
			logger.error("The Domain with value_id= " + aObjMetadata.getDataType() + " does not exist.");
			throw new EMFUserError(EMFErrorSeverity.ERROR, 1035);
		}
		Date now = new Date();
		// store the object note
		SbiObjMetadata hibMeta = new SbiObjMetadata();
		hibMeta.setLabel(aObjMetadata.getLabel());
		hibMeta.setName(aObjMetadata.getName());
		hibMeta.setDescription(aObjMetadata.getDescription());
		hibMeta.setDataType(dataType);
		hibMeta.setCreationDate(now);
		updateSbiCommonInfo4Insert(hibMeta);
		aSession.save(hibMeta);
		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();
		}
		logger.debug("OUT");
	}
}
 
源代码16 项目: Knowage-Server   文件: SbiDsBcDAOHibImpl.java
@Override
public List<SbiMetaBc> loadBcByDsId(Integer dsId) throws EMFUserError {
	logger.debug("IN");

	Session aSession = null;
	Transaction tx = null;
	List<SbiMetaBc> toReturn = new ArrayList();
	Query hqlQuery = null;

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

		hqlQuery = aSession.createQuery(" from SbiMetaDsBc as db where db.id.dsId = ? ");
		hqlQuery.setInteger(0, dsId);
		List hibList = hqlQuery.list();

		Iterator it = hibList.iterator();
		while (it.hasNext()) {
			SbiMetaDsBc tmpRel = (SbiMetaDsBc) it.next();
			SbiMetaBc tmpBC = DAOFactory.getSbiMetaBCDAO().loadBcByID(new Integer(tmpRel.getId().getBcId()));

			if (tmpBC != null)
				toReturn.add(tmpBC);
		}
		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();
		}
	}
	logger.debug("OUT");
	return toReturn;
}
 
源代码17 项目: Knowage-Server   文件: SbiObjDsDAOHibImpl.java
@Override
public void deleteObjDsbyObjId(Integer objId) throws EMFUserError {
	logger.debug("IN");

	Session aSession = null;
	Transaction tx = null;
	try {
		List<SbiMetaObjDs> lstRel = loadDsByObjId(objId);

		if (lstRel == null)
			return;

		aSession = getSession();
		tx = aSession.beginTransaction();

		for (SbiMetaObjDs r : lstRel) {
			SbiMetaObjDsId hibId = new SbiMetaObjDsId();
			hibId.setObjId(r.getId().getObjId());
			hibId.setDsId(r.getId().getDsId());
			hibId.setOrganization(r.getId().getOrganization());
			hibId.setVersionNum(r.getId().getVersionNum());

			SbiMetaObjDs hib = (SbiMetaObjDs) aSession.load(SbiMetaObjDs.class, hibId);

			aSession.delete(hib);
		}
		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();
		}
	}
	logger.debug("OUT");
}
 
源代码18 项目: Knowage-Server   文件: BIObjectDAOHibImpl.java
@Override
public String changeLockStatus(String documentLabel, boolean isUserAdmin) throws EMFUserError {
	logger.debug("IN");
	BIObject biObject = null;
	Session aSession = null;
	Transaction tx = null;
	String toReturn = null;
	try {
		aSession = getSession();
		tx = aSession.beginTransaction();
		Criterion labelCriterrion = Expression.eq("label", documentLabel);
		Criteria criteria = aSession.createCriteria(SbiObjects.class);
		criteria.add(labelCriterrion);

		SbiObjects hibObject = (SbiObjects) criteria.uniqueResult();
		if (hibObject == null)
			return null;

		String currentUser = (String) ((UserProfile) getUserProfile()).getUserId();

		boolean isLocked = false;
		if (hibObject.getLockedByUser() != null && !hibObject.getLockedByUser().equals(""))
			isLocked = true;

		if (isLocked == true && hibObject.getLockedByUser().equals(currentUser)) {
			hibObject.setLockedByUser(null);
			aSession.save(hibObject);
			tx.commit();
			toReturn = hibObject.getLockedByUser();
		} else if (isLocked == false) {
			// if its not lcked change
			hibObject.setLockedByUser(currentUser);
			aSession.save(hibObject);
			tx.commit();
			toReturn = hibObject.getLockedByUser();
		} else if (isLocked == true && !hibObject.getLockedByUser().equals(currentUser) && isUserAdmin == true) {
			hibObject.setLockedByUser(null);
			aSession.save(hibObject);
			tx.commit();
			toReturn = hibObject.getLockedByUser();
		} else {
			toReturn = null;
		}

	} catch (HibernateException he) {
		logger.error(he);
		he.printStackTrace();
		if (tx != null)
			tx.rollback();
		throw new EMFUserError(EMFErrorSeverity.ERROR, 100);
	} finally {
		if (aSession != null) {
			if (aSession.isOpen())
				aSession.close();
		}
	}
	logger.debug("OUT");
	return toReturn;
}
 
源代码19 项目: Knowage-Server   文件: DbAuditImpl.java
@Override
public List getMyRecentlyUsed(String userId, int limit) throws EMFUserError {
	logger.debug("IN");
	Session aSession = null;
	Transaction tx = null;
	List toReturn = new ArrayList();
	if (userId == null || userId.trim().equals("")) {
		logger.warn("The user id in input is null or empty.");
		return toReturn;
	}
	try {
		aSession = getSession();
		tx = aSession.beginTransaction();
		StringBuffer hql = new StringBuffer();
		hql.append("select ");
		hql.append("		max(a.requestTime), ");
		hql.append("		a.sbiObject.biobjId, ");
		hql.append("		a.sbiObject.label, ");
		hql.append("		a.sbiObject.name, ");
		hql.append("		a.sbiObject.descr, ");
		hql.append("		a.sbiObject.objectTypeCode, ");
		hql.append("		a.subObjId, ");
		hql.append("		a.subObjName, ");
		hql.append("		coalesce(str(a.documentParameters), 'No parameters'), ");
		hql.append("		a.sbiEngine.name, ");
		hql.append("		a.sbiObject.previewFile ");
		hql.append("from ");
		hql.append("		SbiAudit a ");
		hql.append("where 	");
		hql.append("		a.sbiObject is not null and ");
		hql.append("		a.sbiEngine is not null and ");
		hql.append("		a.sbiObject.label not like 'SBI_%' and ");
		hql.append("		a.userName = ? and ");
		hql.append("		(a.sbiSubObject is null or a.sbiSubObject.subObjId = a.subObjId) ");
		hql.append("group by 	a.sbiObject.biobjId, ");
		hql.append("			a.sbiObject.label, ");
		hql.append("			a.sbiObject.name, ");
		hql.append("			a.sbiObject.descr, ");
		hql.append("			a.sbiObject.objectTypeCode, ");
		hql.append("			a.subObjId, ");
		hql.append("			a.subObjName, ");
		hql.append("			coalesce(str(a.documentParameters), 'No parameters'), ");
		hql.append("			a.sbiEngine.name, ");
		hql.append("		a.sbiObject.previewFile ");
		hql.append("order by max(a.requestTime) desc ");
		Query hqlQuery = aSession.createQuery(hql.toString());
		hqlQuery.setString(0, userId);
		hqlQuery.setMaxResults(limit);
		List result = hqlQuery.list();
		Iterator resultIt = result.iterator();
		while (resultIt.hasNext()) {
			Object[] row = (Object[]) resultIt.next();
			toReturn.add(toHotLink(row));
		}
	} catch (Exception ex) {
		logger.error(ex);
		if (tx != null)
			tx.rollback();
		throw new EMFUserError(EMFErrorSeverity.ERROR, 100);
	} finally {
		if (aSession != null) {
			if (aSession.isOpen())
				aSession.close();
		}
		logger.debug("OUT");
	}
	return toReturn;
}
 
源代码20 项目: Knowage-Server   文件: DbAuditImpl.java
@Override
public SbiAudit loadAuditByID(Integer id) throws EMFUserError {
	logger.debug("IN");
	Session aSession = null;
	Transaction tx = null;
	SbiAudit aSbiAudit = null;
	try {
		aSession = getSession();
		tx = aSession.beginTransaction();
		aSbiAudit = (SbiAudit) aSession.load(SbiAudit.class, id);
		aSbiAudit.getSbiObject();
		aSbiAudit.getDocumentLabel();
		aSbiAudit.getDocumentId();
		aSbiAudit.getDocumentName();
		aSbiAudit.getDocumentParameters();
		aSbiAudit.getDocumentState();
		aSbiAudit.getDocumentType();
		aSbiAudit.getSbiSubObject();
		aSbiAudit.getSubObjId();
		aSbiAudit.getSubObjName();
		aSbiAudit.getSubObjOwner();
		aSbiAudit.getSubObjIsPublic();
		aSbiAudit.getSbiEngine();
		aSbiAudit.getEngineClass();
		aSbiAudit.getEngineDriver();
		aSbiAudit.getEngineId();
		aSbiAudit.getEngineLabel();
		aSbiAudit.getEngineName();
		aSbiAudit.getEngineType();
		aSbiAudit.getEngineUrl();
		aSbiAudit.getExecutionModality();
		aSbiAudit.getRequestTime();
		aSbiAudit.getId();
		aSbiAudit.getUserName();
		aSbiAudit.getUserGroup();
		aSbiAudit.getExecutionStartTime();
		aSbiAudit.getExecutionEndTime();
		aSbiAudit.getExecutionTime();
		aSbiAudit.getExecutionState();
		aSbiAudit.getError();
		aSbiAudit.getErrorMessage();
		aSbiAudit.getErrorCode();
		tx.commit();
	} catch (HibernateException he) {
		logger.error(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 aSbiAudit;
}