Java Code Examples for org.hibernate.Query#setInteger()

The following examples show how to use org.hibernate.Query#setInteger() . 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: SpagoBIInitializer.java    From Knowage-Server with GNU Affero General Public License v3.0 6 votes vote down vote up
protected void deleteAuthorization(Session hibernateSession, SbiAuthorizations sbiAuthorization) {
	logger.debug("IN");
	try {
		// Doesn't work check hibernate mapping to use this code
		// Set<SbiAuthorizationsRoles> sbiAuthorizationsRoles = sbiAuthorization.getSbiAuthorizationsRoleses();
		// for (SbiAuthorizationsRoles authRole : sbiAuthorizationsRoles) {
		// deleteAuthorizationsRoles(hibernateSession, authRole);
		// }

		Integer authorizationId = sbiAuthorization.getId();

		String hql = "delete from SbiAuthorizationsRoles a where a.id.authorizationId = :authorizationId";
		Query query = hibernateSession.createQuery(hql);
		query.setInteger("authorizationId", authorizationId);
		query.executeUpdate();

		hibernateSession.delete(sbiAuthorization);
	} catch (Throwable t) {
		throw new SpagoBIRuntimeException(
				"An error occured while deletion of Authorizations " + sbiAuthorization.getId() + " in synchronization with Configuraion file", t);
	} finally {
		logger.debug("OUT");
	}
}
 
Example 2
Source File: SbiMetaTableColumnDAOHibImpl.java    From Knowage-Server with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public SbiMetaTableColumn loadTableColumnByNameAndTable(Session session, String name, Integer tableId) throws EMFUserError {
	logger.debug("IN");

	SbiMetaTableColumn toReturn = null;
	Session tmpSession = session;

	try {
		String hql = " from SbiMetaTableColumn c where c.name = ? and c.sbiMetaTable.tableId = ? ";
		Query aQuery = tmpSession.createQuery(hql);
		aQuery.setString(0, name);
		aQuery.setInteger(1, tableId);
		toReturn = (SbiMetaTableColumn) aQuery.uniqueResult();

		if (toReturn == null)
			return null;
	} catch (HibernateException he) {
		logException(he);
		throw new HibernateException(he);
	} finally {
		logger.debug("OUT");
	}
	return toReturn;
}
 
Example 3
Source File: SbiMetaTableDAOHibImpl.java    From Knowage-Server with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public SbiMetaTable loadTableByNameAndSource(Session session, String name, Integer sourceId) throws EMFUserError {
	logger.debug("IN");

	SbiMetaTable toReturn = null;
	Session tmpSession = session;

	try {
		// Criterion labelCriterrion = Expression.eq("name", name);
		// Criteria criteria = tmpSession.createCriteria(SbiMetaTable.class);
		// criteria.add(labelCriterrion);
		// toReturn = (SbiMetaTable) criteria.uniqueResult();

		String hql = " from SbiMetaTable c where c.name = ? and c.sbiMetaSource.sourceId = ? ";
		Query aQuery = tmpSession.createQuery(hql);
		aQuery.setString(0, name);
		aQuery.setInteger(1, sourceId);
		toReturn = (SbiMetaTable) aQuery.uniqueResult();
	} catch (HibernateException he) {
		logException(he);
		throw new HibernateException(he);
	} finally {
		logger.debug("OUT");
	}
	return toReturn;
}
 
Example 4
Source File: DBQueryUtil.java    From kardio with Apache License 2.0 6 votes vote down vote up
/**
 * Update the k8s_pods_containers table with number of Pods&Containers
 * @param envId
 * @param compName
 * @param numOfPods
 * @param parentCompName
 * @param numOfCont
 */
public static void updatePodsAndContainers(final int envId, String compName, int numOfPods, String parentCompName, int numOfCont){
	final java.sql.Date todayDate = new java.sql.Date(Calendar.getInstance().getTimeInMillis());;
	final int compId = getComponentId(compName, parentCompName);
	if(compId == 0){
		logger.info("Component Name = " + compName + "; Parent Component Name = " + parentCompName + "; is not available in the DB");
		return;
	}
	Session session = HibernateConfig.getSessionFactory().getCurrentSession();
	Transaction txn = session.beginTransaction();
	Query query = session.createQuery(HQLConstants.UPDATE_K8S_PODS_CONT_DETAILS);
	query.setInteger("totalPods", numOfPods);
	query.setInteger("totalContainers", numOfCont);
	query.setLong("compId", compId);
	query.setLong("environmentId", envId);
	query.setDate("stsDate", todayDate);
	query.executeUpdate();
	txn.commit();
}
 
Example 5
Source File: I18NMessagesDAOHibImpl.java    From Knowage-Server with GNU Affero General Public License v3.0 6 votes vote down vote up
private List<SbiI18NMessages> getSbiI18NMessagesByLabel(SbiI18NMessages message, String tenant, Session curSession) {
	logger.debug("IN");
	List<SbiI18NMessages> toReturn = new ArrayList<SbiI18NMessages>();
	try {
		String hql = "from SbiI18NMessages m where m.label = :label and m.commonInfo.organization = :organization and m.languageCd != :languageCd";
		Query query = curSession.createQuery(hql);
		query.setString("label", message.getLabel());
		query.setString("organization", tenant);
		query.setInteger("languageCd", message.getLanguageCd());
		toReturn = query.list();
	} catch (HibernateException e) {
		logException(e);
		throw new RuntimeException();
	}
	logger.debug("OUT");
	return toReturn;
}
 
Example 6
Source File: SbiUserDAOHibImpl.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public ArrayList<SbiUserAttributes> loadSbiUserAttributesById(Integer id) {
	logger.debug("IN");

	Session aSession = null;
	Transaction tx = null;
	try {
		aSession = getSession();
		tx = aSession.beginTransaction();
		String q = "select us.sbiUserAttributeses from SbiUser us where us.id = :id";

		Query query = aSession.createQuery(q);
		query.setInteger("id", id);

		ArrayList<SbiUserAttributes> result = (ArrayList<SbiUserAttributes>) query.list();

		Hibernate.initialize(result);
		for (SbiUserAttributes current : result) {
			Hibernate.initialize(current.getSbiAttribute());
		}
		return result;

	} catch (HibernateException he) {
		if (tx != null)
			tx.rollback();
		throw new SpagoBIDAOException("Error while loading user attribute with id " + id, he);
	} finally {
		logger.debug("OUT");
		if (aSession != null) {
			if (aSession.isOpen())
				aSession.close();
		}
	}
}
 
Example 7
Source File: ObjNoteDAOHibImpl.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
@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;
}
 
Example 8
Source File: SubObjectDAOHibImpl.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public List getAccessibleSubObjects(Integer idBIObj, IEngUserProfile profile) throws EMFUserError {
	List subs = new ArrayList();
	Session aSession = null;
	Transaction tx = null;
	try {
		aSession = getSession();
		tx = aSession.beginTransaction();
		// String hql = "from SbiSubObjects sso where sso.sbiObject.biobjId="+idBIObj + " " +
		// "and (isPublic = true or owner = '"+((UserProfile)profile).getUserId().toString()+"')";

		String hql = "from SbiSubObjects sso where sso.sbiObject.biobjId= ? " + "and (isPublic = true or owner = ? )";

		Query query = aSession.createQuery(hql);
		query.setInteger(0, idBIObj.intValue());
		query.setString(1, ((UserProfile) profile).getUserId().toString());

		List result = query.list();
		Iterator it = result.iterator();
		while (it.hasNext()) {
			subs.add(toSubobject((SbiSubObjects) it.next()));
		}
		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();
		}
	}
	return subs;
}
 
Example 9
Source File: Frequency.java    From core with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns List of Frequency objects for the specified database revision.
 * 
 * @param session
 * @param configRev
 * @return
 * @throws HibernateException
 */
@SuppressWarnings("unchecked")
public static List<Frequency> getFrequencies(Session session, int configRev) 
		throws HibernateException {
	String hql = "FROM Frequency " +
			"    WHERE configRev = :configRev";
	Query query = session.createQuery(hql);
	query.setInteger("configRev", configRev);
	return query.list();
}
 
Example 10
Source File: SbiObjDsDAOHibImpl.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public SbiMetaObjDs loadDsObjByKey(SbiMetaObjDsId objDsId) throws EMFUserError {
	logger.debug("IN");

	Session aSession = null;
	Transaction tx = null;
	SbiMetaObjDs toReturn = null;
	Query hqlQuery = null;

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

		hqlQuery = aSession
				.createQuery(" from SbiMetaObjDs as db where db.id.objId = ? and db.id.dsId = ? and db.id.versionNum = ? and db.id.organization = ?");
		hqlQuery.setInteger(0, objDsId.getObjId());
		hqlQuery.setInteger(1, objDsId.getDsId());
		hqlQuery.setInteger(2, objDsId.getVersionNum());
		hqlQuery.setString(3, objDsId.getOrganization());
		toReturn = (SbiMetaObjDs) hqlQuery.uniqueResult();

		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;
}
 
Example 11
Source File: ViewpointDAOHimpl.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Load viewpoint by name and document identifier.
 *
 * @param name
 *            the name of the viewpoint
 * @param name
 *            The id of the document
 *
 * @return the viewpoint
 *
 * @throws EMFUserError
 *             the EMF user error
 *
 * @see it.eng.spagobi.analiticalmodel.document.dao.IViewpointDAO#loadViewpointByName(java.lang.String)
 */
@Override
public Viewpoint loadViewpointByNameAndBIObjectId(String name, Integer biobjectId) throws EMFUserError {
	Viewpoint toReturn = null;
	Session aSession = null;
	Transaction tx = null;

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

		String hql = "from SbiViewpoints vp where vp.sbiObject.biobjId = ? and vp.vpName = ?";
		Query hqlQuery = aSession.createQuery(hql);
		hqlQuery.setInteger(0, biobjectId.intValue());
		hqlQuery.setString(1, name);

		SbiViewpoints hibViewpoint = (SbiViewpoints) hqlQuery.uniqueResult();
		if (hibViewpoint == null)
			return null;
		toReturn = toViewpoint(hibViewpoint);
		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 toReturn;
}
 
Example 12
Source File: MetaModelParuseDAOHibImpl.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Load obj paruse.
 *
 * @param objParId
 *            the obj par id
 * @param paruseId
 *            the paruse id
 *
 * @return the list
 *
 * @throws EMFUserError
 *             the EMF user error
 *
 * @see it.eng.spagobi.behaviouralmodel.analyticaldriver.dao.IObjParuseDAO#loadObjParuse(java.lang.Integer, java.lang.Integer)
 */
@Override
public List loadMetaModelParuse(Integer metaModelParId, Integer paruseId) throws HibernateException {
	List metaModelParuses = new ArrayList();
	MetaModelParuse toReturn = null;
	Session aSession = null;
	Transaction tx = null;
	try {
		aSession = getSession();
		tx = aSession.beginTransaction();

		String hql = "from SbiMetamodelParuse s where s.sbiMetaModelPar.metaModelParId=? " + " and s.sbiParuse.useId=? " + " order by s.prog";

		Query query = aSession.createQuery(hql);
		query.setInteger(0, metaModelParId.intValue());
		query.setInteger(1, paruseId.intValue());

		List sbiMetaModelParuses = query.list();
		if (sbiMetaModelParuses == null)
			return metaModelParuses;
		Iterator itersbiOP = sbiMetaModelParuses.iterator();
		while (itersbiOP.hasNext()) {
			SbiMetamodelParuse sbiop = (SbiMetamodelParuse) itersbiOP.next();
			MetaModelParuse op = toMetaModelParuse(sbiop);
			metaModelParuses.add(op);
		}
		tx.commit();
	} catch (HibernateException he) {
		logException(he);
		if (tx != null)
			tx.rollback();
		throw new HibernateException(he.getLocalizedMessage(), he);
	} finally {
		if (aSession != null) {
			if (aSession.isOpen())
				aSession.close();
		}
	}
	return metaModelParuses;
}
 
Example 13
Source File: ProgressThreadDAOImpl.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void setErrorProgressThread(Integer progressThreadId) throws EMFUserError {
	// logger.debug("IN");
	ProgressThread toReturn = null;

	Session aSession = null;
	Transaction tx = null;

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

		Query hibPT = aSession.createQuery("from SbiProgressThread h where h.progressThreadId = ? ");
		hibPT.setInteger(0, progressThreadId);
		SbiProgressThread sbiProgressThread = (SbiProgressThread) hibPT.uniqueResult();
		sbiProgressThread.setStatus("ERROR");
		tx.commit();

	} catch (HibernateException he) {
		logger.error("Error while loading Progress Thread with progressThreadId = " + progressThreadId, he);
		if (tx != null)
			tx.rollback();
		throw new EMFUserError(EMFErrorSeverity.ERROR, 100);
	} finally {
		if (aSession != null) {
			if (aSession.isOpen())
				aSession.close();
			// logger.debug("OUT");
		}
	}
	// logger.debug("OUT");

}
 
Example 14
Source File: I18NMessagesDAOHibImpl.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void deleteI18NMessage(Integer id) {
	logger.debug("IN");
	Session session = null;
	Transaction tx = null;
	SbiI18NMessages toDelete = new SbiI18NMessages();
	try {
		session = getSession();
		tx = session.beginTransaction();

		String hql = "from SbiI18NMessages mess where mess.id = :id";
		Query query = session.createQuery(hql);
		query.setInteger("id", id);
		toDelete = (SbiI18NMessages) query.uniqueResult();

		session.delete(toDelete);
		tx.commit();
		session.flush();
	} 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");
}
 
Example 15
Source File: ProgressThreadDAOImpl.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public ProgressThread loadProgressThreadById(Integer progressThreadId) throws EMFUserError {
	logger.debug("IN");
	ProgressThread toReturn = null;

	Session aSession = null;
	Transaction tx = null;

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

		Query hibPT = aSession.createQuery("from SbiProgressThread h where h.progressThreadId = ?");
		hibPT.setInteger(0, progressThreadId);
		SbiProgressThread sbiProgressThread = (SbiProgressThread) hibPT.uniqueResult();
		if (sbiProgressThread != null) {
			toReturn = toProgressThread(sbiProgressThread);
		}
		tx.commit();

	} catch (HibernateException he) {
		logger.error("Error while loading Progress Thread with progresThreadId", he);
		if (tx != null)
			tx.rollback();
		throw new EMFUserError(EMFErrorSeverity.ERROR, 100);
	} finally {
		if (aSession != null) {
			if (aSession.isOpen())
				aSession.close();
			// logger.debug("OUT");
		}
	}
	// logger.debug("OUT");
	return toReturn;
}
 
Example 16
Source File: DataSetDAOImpl.java    From Knowage-Server with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * Restore an Older Version of the dataset
 *
 * @param dsId      the a data set ID
 * @param dsVersion the a data set Version
 * @throws EMFUserError the EMF user error
 */
@Override
public IDataSet restoreOlderDataSetVersion(Integer dsId, Integer dsVersion) {
	logger.debug("IN");
	Session session = null;
	Transaction transaction = null;
	IDataSet toReturn = null;
	IDataSet oldDataSet = null;
	try {
		session = getSession();
		transaction = session.beginTransaction();
		if (dsId != null && dsVersion != null) {

			Query hibQuery = session.createQuery("from SbiDataSet h where h.active = ? and h.id.dsId = ?");
			hibQuery.setBoolean(0, true);
			hibQuery.setInteger(1, dsId);
			SbiDataSet dsActiveDetail = (SbiDataSet) hibQuery.uniqueResult();
			oldDataSet = DataSetFactory.toDataSet(dsActiveDetail, this.getUserProfile());
			dsActiveDetail.setActive(false);

			Query hibernateQuery = session.createQuery("from SbiDataSet h where h.id.versionNum = ? and h.id.dsId = ?");
			hibernateQuery.setInteger(0, dsVersion);
			hibernateQuery.setInteger(1, dsId);
			SbiDataSet dsDetail = (SbiDataSet) hibernateQuery.uniqueResult();
			dsDetail.setActive(true);

			session.update(dsActiveDetail);
			session.update(dsDetail);
			transaction.commit();
			// toReturn = DataSetFactory.toGuiDataSet(dsDetail);
			toReturn = DataSetFactory.toDataSet(dsDetail);

			DataSetEventManager.getInstance().notifyRestoreVersion(oldDataSet, toReturn);

		}
	} catch (Throwable t) {
		if (transaction != null && transaction.isActive()) {
			transaction.rollback();
		}
		throw new SpagoBIDAOException("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;
}
 
Example 17
Source File: MenuRolesDAOImpl.java    From Knowage-Server with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * Load menu by role id.
 *
 * @param roleId
 *            the role id
 *
 * @return the list
 *
 * @throws EMFUserError
 *             the EMF user error
 *
 * @see it.eng.spagobi.wapp.dao.IMenuRolesDAO#loadMenuByRoleId(java.lang.Integer)
 */
@Override
public List loadMenuByRoleId(Integer roleId) throws EMFUserError {
	logger.debug("IN");
	if (roleId != null)
		logger.debug("roleId=" + roleId.toString());
	Session aSession = null;
	Transaction tx = null;
	List realResult = new ArrayList();
	String hql = null;
	Query hqlQuery = null;

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

		hql = " select mf.id.menuId, mf.id.extRoleId from SbiMenuRole as mf, SbiMenu m " + " where mf.id.menuId = m.menuId " + " and mf.id.extRoleId = ? "
				+ " order by m.parentId, m.prog";

		hqlQuery = aSession.createQuery(hql);
		hqlQuery.setInteger(0, roleId.intValue());
		List hibList = hqlQuery.list();

		Iterator it = hibList.iterator();
		IMenuDAO menuDAO = DAOFactory.getMenuDAO();
		Menu tmpMenu = null;
		while (it.hasNext()) {
			Object[] tmpLst = (Object[]) it.next();
			Integer menuId = (Integer) tmpLst[0];
			tmpMenu = menuDAO.loadMenuByID(menuId, roleId);
			if (tmpMenu != null) {
				logger.debug("Add Menu:" + tmpMenu.getName());
				realResult.add(tmpMenu);
			}
		}
		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;
}
 
Example 18
Source File: MetaModelsDAOImpl.java    From Knowage-Server with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public MetaModel loadMetaModelForExecutionByIdAndRole(Integer id, String role) {
	logger.debug("IN");
	Session aSession = null;
	Transaction tx = null;
	MetaModel businessModel = null;
	try {
		aSession = getSession();
		tx = aSession.beginTransaction();
		businessModel = loadMetaModelForDetail(id);
		// String hql = "from SbiObjPar s where s.sbiObject.biobjId = " +
		// biObject.getId() + " order by s.priority asc";
		String hql = "from SbiMetaModelParameter s where s.sbiMetaModel.id = ? order by s.priority asc";
		Query hqlQuery = aSession.createQuery(hql);
		hqlQuery.setInteger(0, businessModel.getId().intValue());
		List hibMetaModelPars = hqlQuery.list();
		SbiMetaModelParameter hibMetaModelPar = null;
		Iterator it = hibMetaModelPars.iterator();
		BIMetaModelParameter tmpBIMetaModelParameter = null;
		BIMetaModelParameterDAOHibImpl aBIMetaModelParameterDAOHibImpl = new BIMetaModelParameterDAOHibImpl();
		IParameterDAO aParameterDAO = DAOFactory.getParameterDAO();
		List metamodelParameters = new ArrayList();
		Parameter aParameter = null;
		int count = 1;
		while (it.hasNext()) {
			hibMetaModelPar = (SbiMetaModelParameter) it.next();
			tmpBIMetaModelParameter = aBIMetaModelParameterDAOHibImpl.toBIMetaModelParameter(hibMetaModelPar);

			// *****************************************************************
			// **************** START PRIORITY RECALCULATION
			// *******************
			// *****************************************************************
			Integer priority = tmpBIMetaModelParameter.getPriority();
			if (priority == null || priority.intValue() != count) {
				logger.warn("The priorities of the biparameters for the business model with id = " + businessModel.getId()
						+ " are not sorted. Priority recalculation starts.");
				aBIMetaModelParameterDAOHibImpl.recalculateBiParametersPriority(businessModel.getId(), aSession);
				tmpBIMetaModelParameter.setPriority(new Integer(count));
			}
			count++;
			// *****************************************************************
			// **************** END PRIORITY RECALCULATION
			// *******************
			// *****************************************************************

			aParameter = aParameterDAO.loadForExecutionByParameterIDandRoleName(tmpBIMetaModelParameter.getParID(), role);
			tmpBIMetaModelParameter.setParID(aParameter.getId());
			tmpBIMetaModelParameter.setParameter(aParameter);
			metamodelParameters.add(tmpBIMetaModelParameter);
		}
		businessModel.setDrivers(metamodelParameters);
		tx.commit();
	} catch (Exception e) {
		logger.error(e);
		if (tx != null)
			tx.rollback();
		throw new SpagoBIDAOException("An unexpected error occured while loading model with id [" + id + "]", e);
	} finally {
		if (aSession != null) {
			if (aSession.isOpen())
				aSession.close();
		}
	}
	logger.debug("OUT");
	return businessModel;
}
 
Example 19
Source File: BaseDAO.java    From bamboobsc with Apache License 2.0 4 votes vote down vote up
/**
 * for public QueryResult getList... doInHibernate
 * @param query		 JPA-Style : from TB_ACCOUNT where account = ?0 
 * @param position   JPA-Style : "0", "1" .....
 * @param params
 */
@SuppressWarnings("rawtypes")
private void setQueryParams(Query query, String position, Object params) {
	if (params instanceof java.lang.String ) {
		query.setString(position, (java.lang.String)params);
		return;
	}
	if (params instanceof java.lang.Character) {
		query.setCharacter(position, (java.lang.Character)params);
		return;
	}
	if (params instanceof java.lang.Double ) {
		query.setDouble(position, (java.lang.Double)params);	
		return;
	}							
	if (params instanceof java.lang.Byte ) {
		query.setByte(position, (java.lang.Byte)params);
		return;
	}														
	if (params instanceof java.lang.Integer ) {
		query.setInteger(position, (java.lang.Integer)params);
		return;
	}
	if (params instanceof java.lang.Long ) {
		query.setLong(position, (java.lang.Long)params);
		return;
	}							
	if (params instanceof java.lang.Boolean ) {
		query.setBoolean(position, (java.lang.Boolean)params);
		return;
	}
	if (params instanceof java.math.BigDecimal ) {
		query.setBigDecimal(position, (java.math.BigDecimal)params);
		return;
	}							
	if (params instanceof java.util.Date ) {
		query.setDate(position, (java.util.Date)params);
		return;
	}		
	if (params instanceof java.util.List ) {
		List listParams=(List)params;
		this.setQueryParamsOfList(query, position, listParams);
		return;
	}
}
 
Example 20
Source File: I18NMessagesDAOHibImpl.java    From Knowage-Server with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public Map<String, String> getAllI18NMessages(Locale locale) throws EMFUserError {
	logger.debug("IN");

	Map<String, String> toReturn = new HashMap<String, String>();

	Session aSession = null;
	Transaction tx = null;

	if (locale == null) {
		logger.error("No I18n conversion because locale passed as parameter is null");
		throw new EMFUserError(EMFErrorSeverity.ERROR, 100);
	}

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

		String qDom = "from SbiDomains dom where dom.valueCd = :valueCd AND dom.domainCd = 'LANG'";
		Query queryDom = aSession.createQuery(qDom);

		String localeId = null;

		try {
			localeId = locale.getISO3Language().toUpperCase();
		} catch (Exception e) {
			logger.warn("No iso code found for locale, set manually");
		}
		if (localeId == null) {
			if (locale.getLanguage().toUpperCase().equals("US"))
				localeId = "ENG";
			else if (locale.getLanguage().toUpperCase().equals("IT"))
				localeId = "ITA";
			else if (locale.getLanguage().toUpperCase().equals("FR"))
				localeId = "FRA";
			else if (locale.getLanguage().toUpperCase().equals("ES"))
				localeId = "ESP";
		}

		logger.debug("localeId=" + localeId);
		queryDom.setString("valueCd", localeId);
		Object objDom = queryDom.uniqueResult();
		if (objDom == null) {
			logger.error("Could not find domain for locale " + locale.getISO3Language());
			throw new EMFUserError(EMFErrorSeverity.ERROR, 100);
		}

		Integer domId = ((SbiDomains) objDom).getValueId();

		String q = "from SbiI18NMessages att where att.id.languageCd = :languageCd";
		Query query = aSession.createQuery(q);

		query.setInteger("languageCd", domId);

		List objList = query.list();
		if (objList != null && objList.size() > 0) {
			for (Iterator iterator = objList.iterator(); iterator.hasNext();) {
				SbiI18NMessages i18NMess = (SbiI18NMessages) iterator.next();
				toReturn.put(i18NMess.getLabel(), i18NMess.getMessage());
			}
		}

	} catch (HibernateException he) {
		logger.error(he.getMessage(), he);
		if (tx != null)
			tx.rollback();
		throw new EMFUserError(EMFErrorSeverity.ERROR, 100);
	} finally {
		if (aSession != null) {
			if (aSession.isOpen())
				aSession.close();
		}
	}
	logger.debug("OUT.toReturn=" + toReturn);
	return toReturn;

}