Here are the examples of the java api org.hibernate.Query.setString() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
210 Examples
19
Source : TermDaoImpl.java
with Apache License 2.0
from openequella
with Apache License 2.0
from openequella
private void updateFullValues(final Taxonomy taxonomy) {
getHibernateTemplate().execute(session -> {
boolean foundInvalid = false;
do {
Query ru = session.createQuery("UPDATE Term" + " SET fullValue = value" + " WHERE parent IS NULL AND fullValue IS NULL" + " AND taxonomy = :taxonomy");
ru.setParameter("taxonomy", taxonomy);
ru.executeUpdate();
Query q = session.createQuery("SELECT DISTINCT(parent.id), parent.fullValue" + " FROM Term WHERE fullValue IS NULL AND parent.fullValue IS NOT NULL" + " AND taxonomy = :taxonomy");
q.setParameter("taxonomy", taxonomy);
final List<Object[]> parents = q.list();
foundInvalid = !Check.isEmpty(parents);
for (Object[] parent : parents) {
Query u = session.createQuery("UPDATE Term" + " SET fullValue = :parentFullValue || :termSeparator || value" + " WHERE parent.id = :parentId AND fullValue IS NULL");
u.setString("termSeparator", TaxonomyConstants.TERM_SEPARATOR);
u.setString("parentFullValue", (String) parent[1]);
u.setLong("parentId", (Long) parent[0]);
u.executeUpdate();
}
} while (foundInvalid);
return null;
});
}
18
Source : AbstractDAOImpl.java
with MIT License
from ria-ee
with MIT License
from ria-ee
static void setString(Query q, String name, String value) {
if (value != null) {
q.setString(name, value);
}
}
18
Source : AbstractOrgClosureTest.java
with Apache License 2.0
from Pardus-Engerek
with Apache License 2.0
from Pardus-Engerek
private List<String> getOrgChildren(String oid) {
Query childrenQuery = getSession().createQuery("select distinct parentRef.ownerOid from RObjectReference as parentRef" + " join parentRef.owner as owner where parentRef.targetOid=:oid and parentRef.referenceType=0" + " and owner.objectTypeClreplaced = :orgType");
// TODO eliminate use of parameter here
childrenQuery.setParameter("orgType", RObjectType.ORG);
childrenQuery.setString("oid", oid);
return childrenQuery.list();
}
18
Source : AbstractOrgClosureTest.java
with Apache License 2.0
from Pardus-Engerek
with Apache License 2.0
from Pardus-Engerek
private List<ROrgClosure> getOrgClosureByDescendant(String descendantOid) {
Query query = getSession().createQuery("from ROrgClosure where descendantOid=:oid");
query.setString("oid", descendantOid);
return query.list();
}
18
Source : AbstractOrgClosureTest.java
with Apache License 2.0
from Pardus-Engerek
with Apache License 2.0
from Pardus-Engerek
protected List<String> getChildren(String oid) {
Query childrenQuery = getSession().createQuery("select distinct ownerOid from RObjectReference where targetOid=:oid and referenceType=0");
childrenQuery.setString("oid", oid);
return childrenQuery.list();
}
18
Source : AbstractOrgClosureTest.java
with Apache License 2.0
from Pardus-Engerek
with Apache License 2.0
from Pardus-Engerek
private List<ROrgClosure> getOrgClosureByAncestor(String ancestorOid) {
Query query = getSession().createQuery("from ROrgClosure where ancestorOid=:oid");
query.setString("oid", ancestorOid);
return query.list();
}
18
Source : TermDaoImpl.java
with Apache License 2.0
from openequella
with Apache License 2.0
from openequella
private void shift(Session session, final Taxonomy taxonomy, final Term term, final int amount) {
if (session != null) {
Query q = session.getNamedQuery("shiftByPath");
q.setInteger("amount", amount);
q.setString("fullValue", term.getFullValue());
q.setString("fullValueWild", term.getFullValue() + "\\%");
q.setParameter("taxonomy", taxonomy);
q.executeUpdate();
} else {
getHibernateTemplate().execute(newSession -> {
shift(newSession, taxonomy, term, amount);
return null;
});
}
}
18
Source : SbiMetaTableColumnDAOHibImpl.java
with GNU Affero General Public License v3.0
from KnowageLabs
with GNU Affero General Public License v3.0
from KnowageLabs
@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;
}
18
Source : SbiMetaBcAttributeDAOHibImpl.java
with GNU Affero General Public License v3.0
from KnowageLabs
with GNU Affero General Public License v3.0
from KnowageLabs
@Override
public SbiMetaBcAttribute loadBcAttributeByNameAndBc(Session session, String name, Integer bcId) throws EMFUserError {
logger.debug("IN");
SbiMetaBcAttribute toReturn = null;
try {
Query hqlQuery = session.createQuery(" from SbiMetaBcAttribute as db where db.name = ? and db.sbiMetaBc.bcId = ? ");
hqlQuery.setString(0, name);
hqlQuery.setInteger(1, bcId);
toReturn = (SbiMetaBcAttribute) hqlQuery.uniqueResult();
} catch (HibernateException he) {
logException(he);
throw new HibernateException(he);
} finally {
logger.debug("OUT");
}
return toReturn;
}
18
Source : SbiDsBcDAOHibImpl.java
with GNU Affero General Public License v3.0
from KnowageLabs
with GNU Affero General Public License v3.0
from KnowageLabs
@Override
public List<SbiMetaDsBc> loadBcByDsIdAndTenant(Integer dsId, String organization) throws EMFUserError {
logger.debug("IN");
Session aSession = null;
Transaction tx = null;
List<SbiMetaDsBc> toReturn = new ArrayList();
Query hqlQuery = null;
try {
aSession = getSession();
tx = aSession.beginTransaction();
hqlQuery = aSession.createQuery(" from SbiMetaDsBc as db where db.id.dsId = ? and db.id.organization = ? ");
hqlQuery.setInteger(0, dsId);
hqlQuery.setString(1, organization);
toReturn = hqlQuery.list();
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;
}
18
Source : I18NMessagesDAOHibImpl.java
with GNU Affero General Public License v3.0
from KnowageLabs
with GNU Affero General Public License v3.0
from KnowageLabs
@Override
public String getI18NMessages(Locale locale, String code) throws EMFUserError {
logger.debug("IN. code=" + code);
String toReturn = null;
Session aSession = null;
Transaction tx = null;
if (locale == null) {
logger.warn("No I18n conversion because locale preplaceded as parameter is null");
return code;
}
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 = locale.getISO3Language().toUpperCase();
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());
return code;
}
Integer domId = ((SbiDomains) objDom).getValueId();
String q = "from SbiI18NMessages att where att.id.languageCd = :languageCd AND att.id.label = :label";
Query query = aSession.createQuery(q);
query.setInteger("languageCd", domId);
query.setString("label", code);
Object obj = query.uniqueResult();
if (obj != null) {
SbiI18NMessages SbiI18NMessages = (SbiI18NMessages) obj;
toReturn = SbiI18NMessages.getMessage();
}
tx.commit();
} 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;
}
18
Source : I18NMessagesDAOHibImpl.java
with GNU Affero General Public License v3.0
from KnowageLabs
with GNU Affero General Public License v3.0
from KnowageLabs
@Override
public List<SbiI18NMessages> getI18NMessages(String languageName) {
logger.debug("IN");
List<SbiI18NMessages> toReturn = null;
Session aSession = null;
Transaction tx = null;
try {
aSession = getSession();
tx = aSession.beginTransaction();
Integer domainId = getSbiDomainId(languageName, aSession);
String tenant = getTenant();
String hql = "from SbiI18NMessages m where m.languageCd = :languageCd and m.commonInfo.organization = :organization";
Query query = aSession.createQuery(hql);
query.setInteger("languageCd", domainId);
query.setString("organization", tenant);
toReturn = query.list();
} catch (HibernateException he) {
logger.error(he.getMessage(), he);
if (tx != null)
tx.rollback();
throw new RuntimeException();
} finally {
if (aSession != null) {
if (aSession.isOpen())
aSession.close();
}
}
logger.debug("OUT.toReturn=" + toReturn);
return toReturn;
}
18
Source : I18NMessagesDAOHibImpl.java
with GNU Affero General Public License v3.0
from KnowageLabs
with GNU Affero General Public License v3.0
from KnowageLabs
private Integer getSbiDomainId(String langName, Session curSession) {
logger.debug("IN");
Integer domainId = null;
SbiDomains domain = null;
String DOMAIN_CD = "LANG";
try {
String hql = "from SbiDomains d where d.domainCd = :domainCd and d.valueCd = :valueCd";
Query query = curSession.createQuery(hql);
query.setString("domainCd", DOMAIN_CD);
query.setString("valueCd", langName.toUpperCase());
domain = (SbiDomains) query.uniqueResult();
domainId = domain.getValueId();
} catch (HibernateException e) {
logException(e);
throw new RuntimeException();
}
logger.debug("OUT");
return domainId;
}
18
Source : SbiFederationDefinitionDAOHibImpl.java
with GNU Affero General Public License v3.0
from KnowageLabs
with GNU Affero General Public License v3.0
from KnowageLabs
public SbiFederationDefinition saveSbiFederationDefinition(FederationDefinition dataset, boolean duplicated, Session session, Transaction transaction) {
LogMF.debug(logger, "IN: model = [{0}]", dataset);
UserProfile userProfile = null;
String userID = null;
if (dataset == null) {
throw new IllegalArgumentException("Input parameter [dataset] cannot be null");
}
if (!duplicated) {
logger.debug("Checking if the federation already exists");
Query hibQuery = session.createQuery(" from SbiFederationDefinition fd where fd.label = ? ");
hibQuery.setString(0, dataset.getLabel());
SbiFederationDefinition sbiResult = (SbiFederationDefinition) hibQuery.uniqueResult();
if (sbiResult != null) {
logger.debug("The federation already exisists and the id is " + sbiResult.getFederation_id());
dataset.setFederation_id(sbiResult.getFederation_id());
return sbiResult;
}
logger.debug("The federation doesn't exist");
}
userProfile = UserProfileManager.getProfile();
userID = (String) userProfile.getUserId();
dataset.setOwner(userID);
SbiFederationDefinition hibFederatedDataset = new SbiFederationDefinition();
SbiFederationUtils.toSbiFederationDefinition(hibFederatedDataset, dataset);
updateSbiCommonInfo4Insert(hibFederatedDataset);
session.save(hibFederatedDataset);
return hibFederatedDataset;
}
18
Source : EventDAOHibImpl.java
with GNU Affero General Public License v3.0
from KnowageLabs
with GNU Affero General Public License v3.0
from KnowageLabs
/*
* (non-Javadoc)
*
* @see it.eng.spagobi.events.dao.IEventDAO#unregisterEvents(java.lang.String)
*/
@Override
public void unregisterEvents(String user) throws EMFUserError {
Session aSession = null;
Transaction tx = null;
String hql = null;
Query hqlQuery = null;
List events = null;
try {
aSession = getSession();
tx = aSession.beginTransaction();
/*
* hql = "from SbiEvents as event " + "where event.user = '" + user + "'";
*/
hql = "from SbiEvents as event where event.user = ?";
hqlQuery = aSession.createQuery(hql);
hqlQuery.setString(0, user);
events = hqlQuery.list();
Iterator it = events.iterator();
while (it.hasNext()) {
aSession.delete(it.next());
}
tx.commit();
} catch (HibernateException he) {
logException(he);
if (tx != null)
tx.rollback();
throw new EMFUserError(EMFErrorSeverity.ERROR, 100);
} catch (Exception ex) {
logException(ex);
if (tx != null)
tx.rollback();
throw new EMFUserError(EMFErrorSeverity.ERROR, 100);
} finally {
if (aSession != null) {
if (aSession.isOpen())
aSession.close();
}
}
}
18
Source : EventDAOHibImpl.java
with GNU Affero General Public License v3.0
from KnowageLabs
with GNU Affero General Public License v3.0
from KnowageLabs
/*
* (non-Javadoc)
*
* @see it.eng.spagobi.events.dao.IEventDAO#loadEvents(java.lang.String)
*/
@Override
public List loadEvents(String user) 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 SbiEvents as event " + "where event.user = '" + user + "'";
*/
hql = "from SbiEvents as event where event.user = ?";
hqlQuery = aSession.createQuery(hql);
hqlQuery.setString(0, user);
List hibList = hqlQuery.list();
Iterator it = hibList.iterator();
while (it.hasNext()) {
realResult.add(toEvent((SbiEvents) it.next()));
}
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;
}
18
Source : SbiCommunityDAOImpl.java
with GNU Affero General Public License v3.0
from KnowageLabs
with GNU Affero General Public License v3.0
from KnowageLabs
@Override
public void deleteMemberFromCommunity(String userID, Integer communityId) throws EMFUserError {
logger.debug("IN");
Session aSession = null;
Transaction tx = null;
try {
aSession = getSession();
tx = aSession.beginTransaction();
String q = "from SbiCommunityUsers cu where cu.id.userId = ? and cu.id.communityId = ? ";
Query query = aSession.createQuery(q);
query.setString(0, userID);
query.setInteger(1, communityId);
List<SbiCommunityUsers> result = query.list();
if (result != null && !result.isEmpty()) {
for (int i = 0; i < result.size(); i++) {
aSession.delete(result.get(i));
}
}
tx.commit();
} catch (HibernateException he) {
logger.error(he.getMessage(), he);
if (tx != null)
tx.rollback();
throw new EMFUserError(EMFErrorSeverity.ERROR, 100);
} finally {
logger.debug("OUT");
if (aSession != null) {
if (aSession.isOpen())
aSession.close();
}
}
}
18
Source : SbiCommunityDAOImpl.java
with GNU Affero General Public License v3.0
from KnowageLabs
with GNU Affero General Public License v3.0
from KnowageLabs
@Override
public List<SbiCommunity> loadSbiCommunityByOwner(String owner) throws EMFUserError {
logger.debug("IN");
Session aSession = null;
List<SbiCommunity> result = null;
Transaction tx = null;
try {
aSession = getSession();
tx = aSession.beginTransaction();
String q = "from SbiCommunity c where c.owner = :userId";
Query query = aSession.createQuery(q);
query.setString("userId", owner);
result = query.list();
return result;
} catch (HibernateException he) {
logger.error(he.getMessage(), he);
if (tx != null)
tx.rollback();
throw new EMFUserError(EMFErrorSeverity.ERROR, 100);
} finally {
logger.debug("OUT");
if (aSession != null) {
if (aSession.isOpen())
aSession.close();
}
}
}
18
Source : SbiCommunityDAOImpl.java
with GNU Affero General Public License v3.0
from KnowageLabs
with GNU Affero General Public License v3.0
from KnowageLabs
@Override
public List<SbiCommunity> loadSbiCommunityByUser(String userId) throws EMFUserError {
logger.debug("IN");
Session aSession = null;
List<SbiCommunity> result = null;
Transaction tx = null;
try {
aSession = getSession();
tx = aSession.beginTransaction();
String q = "select cu.sbiCommunity from SbiCommunityUsers cu where cu.id.userId = :userId";
Query query = aSession.createQuery(q);
query.setString("userId", userId);
result = query.list();
return result;
} catch (HibernateException he) {
logger.error(he.getMessage(), he);
if (tx != null)
tx.rollback();
throw new EMFUserError(EMFErrorSeverity.ERROR, 100);
} finally {
logger.debug("OUT");
if (aSession != null) {
if (aSession.isOpen())
aSession.close();
}
}
}
18
Source : SbiCommunityDAOImpl.java
with GNU Affero General Public License v3.0
from KnowageLabs
with GNU Affero General Public License v3.0
from KnowageLabs
@Override
public void deleteCommunityMembership(String userID) throws EMFUserError {
logger.debug("IN");
Session aSession = null;
Transaction tx = null;
try {
aSession = getSession();
tx = aSession.beginTransaction();
String q = "from SbiCommunityUsers cu where cu.id.userId = ?";
Query query = aSession.createQuery(q);
query.setString(0, userID);
List<SbiCommunityUsers> result = query.list();
if (result != null && !result.isEmpty()) {
for (int i = 0; i < result.size(); i++) {
aSession.delete(result.get(i));
}
}
tx.commit();
} catch (HibernateException he) {
logger.error(he.getMessage(), he);
if (tx != null)
tx.rollback();
throw new EMFUserError(EMFErrorSeverity.ERROR, 100);
} finally {
logger.debug("OUT");
if (aSession != null) {
if (aSession.isOpen())
aSession.close();
}
}
}
18
Source : SbiCommunityDAOImpl.java
with GNU Affero General Public License v3.0
from KnowageLabs
with GNU Affero General Public License v3.0
from KnowageLabs
@Override
public SbiCommunity loadSbiCommunityByName(String name) throws EMFUserError {
logger.debug("IN");
Session aSession = null;
Transaction tx = null;
SbiCommunity result = null;
try {
aSession = getSession();
tx = aSession.beginTransaction();
String q = "from SbiCommunity c where c.name = :name";
Query query = aSession.createQuery(q);
query.setString("name", name);
result = (SbiCommunity) query.uniqueResult();
return result;
} catch (HibernateException he) {
logger.error(he.getMessage(), he);
if (tx != null)
tx.rollback();
throw new EMFUserError(EMFErrorSeverity.ERROR, 100);
} finally {
logger.debug("OUT");
if (aSession != null) {
if (aSession.isOpen())
aSession.close();
}
}
}
18
Source : BIObjectRatingDAOHibImpl.java
with GNU Affero General Public License v3.0
from KnowageLabs
with GNU Affero General Public License v3.0
from KnowageLabs
private SbiObjectsRating loadBIObjectRatingById(BIObject obj, String userid) throws EMFUserError {
SbiObjectsRating hibBIObjectsRating = new SbiObjectsRating();
Session aSession = null;
Transaction tx = null;
try {
aSession = getSession();
tx = aSession.beginTransaction();
// String hql = " from SbiObjectsRating s where " +
// " s.id.objId = "+ obj.getId()+ " and s.id.userId = '"+ userid +"'";
String hql = " from SbiObjectsRating s where " + " s.id.objId = ? and s.id.userId = ?";
Query hqlQuery = aSession.createQuery(hql);
hqlQuery.setInteger(0, obj.getId().intValue());
hqlQuery.setString(1, userid);
hibBIObjectsRating = (SbiObjectsRating) hqlQuery.uniqueResult();
tx.commit();
return hibBIObjectsRating;
} 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();
}
}
}
18
Source : SpagoBIInitializer.java
with GNU Affero General Public License v3.0
from KnowageLabs
with GNU Affero General Public License v3.0
from KnowageLabs
protected SbiOrganizationProductType findOrganizationProductType(Session aSession, String tenant, String productType) {
logger.debug("IN");
String hql = "from SbiOrganizationProductType p where p.sbiOrganizations.name = :tenantName and p.sbiProductType.label = :productLabel";
Query hibQuery = aSession.createQuery(hql);
hibQuery.setString("tenantName", tenant);
hibQuery.setString("productLabel", productType);
SbiOrganizationProductType result = (SbiOrganizationProductType) hibQuery.uniqueResult();
logger.debug("OUT");
return result;
}
18
Source : SpagoBIInitializer.java
with GNU Affero General Public License v3.0
from KnowageLabs
with GNU Affero General Public License v3.0
from KnowageLabs
protected SbiProductTypeEngine findProductEngineType(Session aSession, String engine, String productType) {
logger.debug("IN");
String hql = "from SbiProductTypeEngine p where p.sbiEngines.label = :engine and p.sbiProductType.label = :productLabel";
Query hibQuery = aSession.createQuery(hql);
hibQuery.setString("engine", engine);
hibQuery.setString("productLabel", productType);
SbiProductTypeEngine result = (SbiProductTypeEngine) hibQuery.uniqueResult();
logger.debug("OUT");
return result;
}
18
Source : LdapDBService.java
with European Union Public License 1.1
from EUSurvey
with European Union Public License 1.1
from EUSurvey
@Transactional(readOnly = true)
public List<EcasUser> getECASUsers(String name, String department, String email, String domain, int page, int rowsPerPage) {
Session session = sessionFactory.getCurrentSession();
String hql = "SELECT DISTINCT u FROM EcasUser as u WHERE (u.deactivated IS NULL OR u.deactivated = false)";
if (name != null && name.length() > 0) {
hql += " AND CONCAT(u.givenName,' ', u.surname) LIKE :name";
}
if (email != null && email.length() > 0) {
hql += " AND u.email LIKE :email";
}
if (department != null && department.length() > 0 && !department.equalsIgnoreCase("undefined")) {
hql += " AND u.departmentNumber LIKE :department";
}
if (domain != null && domain.length() > 0) {
hql += " AND u.organisation LIKE :domain";
}
hql += " ORDER BY u.id ASC";
Query query = session.createQuery(hql);
if (name != null && name.length() > 0) {
query.setString("name", "%" + name + "%");
}
if (email != null && email.length() > 0) {
query.setString(Constants.EMAIL, "%" + email + "%");
}
if (department != null && department.length() > 0 && !department.equalsIgnoreCase("undefined")) {
query.setString("department", "%" + department + "%");
}
if (domain != null && domain.length() > 0) {
query.setString("domain", domain);
}
@SuppressWarnings("unchecked")
List<EcasUser> res = query.setFirstResult((page - 1) * rowsPerPage).setMaxResults(rowsPerPage).list();
return res;
}
18
Source : ArchiveService.java
with European Union Public License 1.1
from EUSurvey
with European Union Public License 1.1
from EUSurvey
@Transactional
public String getSurveyUIDForArchivedSurveyShortname(String shortname) {
Session session = sessionFactory.getCurrentSession();
Query query = session.createQuery("SELECT a.surveyUID FROM Archive a WHERE a.surveyShortname = :shortname");
query.setString(Constants.SHORTNAME, shortname);
return (String) query.uniqueResult();
}
18
Source : AdministrationService.java
with European Union Public License 1.1
from EUSurvey
with European Union Public License 1.1
from EUSurvey
@Transactional(readOnly = true)
public User getUserForLogin(String login, boolean ecas) throws MessageException {
logger.debug("getUserForLogin".toUpperCase() + " START CHECK USER " + login + " IS ECAS " + ecas);
Session session = sessionFactory.getCurrentSession();
String hql = "FROM User u where u.login = :login AND u.type = :type";
Query query = session.createQuery(hql).setString("login", login);
if (ecas) {
query.setString("type", User.ECAS);
} else {
query.setString("type", User.SYSTEM);
}
logger.debug("getUserForLogin".toUpperCase() + " START CHECK USER LAUNCH QUERY ");
@SuppressWarnings("unchecked")
List<User> list = query.list();
logger.debug("getUserForLogin".toUpperCase() + " START CHECK USER QUERY EXECUTED WITH RESULT SIZE " + list.size());
if (list.isEmpty())
throw new MessageException("No user found for login " + login);
if (list.size() > 1)
throw new MessageException("Multiple users found for login " + login);
return list.get(0);
}
18
Source : AdministrationService.java
with European Union Public License 1.1
from EUSurvey
with European Union Public License 1.1
from EUSurvey
@Transactional(readOnly = true)
public int getNumberOfUsers(UserFilter filter) {
Session session = sessionFactory.getCurrentSession();
HashMap<String, Object> parameters = new HashMap<>();
Query query = session.createQuery(getHql(filter, parameters));
for (Entry<String, Object> entry : parameters.entrySet()) {
Object value = entry.getValue();
if (value instanceof String) {
query.setString(entry.getKey(), (String) value);
} else if (value instanceof Integer) {
query.setInteger(entry.getKey(), (Integer) value);
} else if (value instanceof Date) {
query.setDate(entry.getKey(), (Date) value);
}
}
return query.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENreplacedY).list().size();
}
17
Source : ServiceDAOImpl.java
with MIT License
from ria-ee
with MIT License
from ria-ee
private ServiceType find(Session session, ServiceId id) {
StringBuilder qb = new StringBuilder();
qb.append("select s from ServiceType s");
qb.append(" inner join fetch s.wsdl w");
qb.append(" inner join fetch w.client c");
qb.append(" where s.serviceCode = :serviceCode");
qb.append(" and s.serviceVersion " + nullOrName(id.getServiceVersion(), "serviceVersion"));
qb.append(" and c.identifier.xRoadInstance = :clientInstance");
qb.append(" and c.identifier.memberClreplaced = :clientClreplaced");
qb.append(" and c.identifier.memberCode = :clientCode");
qb.append(" and c.identifier.subsystemCode " + nullOrName(id.getClientId().getSubsystemCode(), "clientSubsystemCode"));
Query q = session.createQuery(qb.toString());
q.setString("serviceCode", id.getServiceCode());
setString(q, "serviceVersion", id.getServiceVersion());
q.setString("clientInstance", id.getClientId().getXRoadInstance());
q.setString("clientClreplaced", id.getClientId().getMemberClreplaced());
q.setString("clientCode", id.getClientId().getMemberCode());
setString(q, "clientSubsystemCode", id.getClientId().getSubsystemCode());
return findOne(q);
}
17
Source : CronTabDAO.java
with GNU General Public License v2.0
from openkm
with GNU General Public License v2.0
from openkm
/**
* Find by filename
*/
public static CronTab findByName(String name) throws DatabaseException {
log.debug("findByName({})", name);
String qs = "from CronTab ct where ct.name=:name";
Session session = null;
try {
session = HibernateUtil.getSessionFactory().openSession();
Query q = session.createQuery(qs);
q.setString("name", name);
CronTab ret = (CronTab) q.setMaxResults(1).uniqueResult();
log.debug("findByName: {}", ret);
return ret;
} catch (HibernateException e) {
throw new DatabaseException(e.getMessage(), e);
} finally {
HibernateUtil.close(session);
}
}
17
Source : ActivityDAO.java
with GNU General Public License v2.0
from openkm
with GNU General Public License v2.0
from openkm
/**
* Get activity date
*/
public static Calendar getActivityDate(String user, String action, String item) throws DatabaseException {
log.debug("getActivityDate({}, {}, {})", new Object[] { user, action, item });
String qsAct = "select max(a.date) from Activity a " + "where a.user=:user and a.action=:action and a.item=:item";
String qsNoAct = "select max(a.date) from Activity a " + "where (a.action='CREATE_DOreplacedENT' or a.action='CHECKIN_DOreplacedENT') and a.item=:item";
Session session = null;
try {
session = HibernateUtil.getSessionFactory().openSession();
Query q = null;
if (action != null) {
q = session.createQuery(qsAct);
q.setString("user", user);
q.setString("action", action);
q.setString("item", item);
} else {
q = session.createQuery(qsNoAct);
q.setString("item", item);
}
Calendar ret = (Calendar) q.setMaxResults(1).uniqueResult();
if (ret == null) {
// May be the doreplacedent has been moved or renamed?
ret = Calendar.getInstance();
}
log.debug("getActivityDate: {}", ret);
return ret;
} catch (HibernateException e) {
throw new DatabaseException(e.getMessage(), e);
} finally {
HibernateUtil.close(session);
}
}
17
Source : SbiTagDAOImpl.java
with GNU Affero General Public License v3.0
from KnowageLabs
with GNU Affero General Public License v3.0
from KnowageLabs
/**
* Returns SbiTag object or null
*/
@Override
public SbiTag loadTagByName(String name) {
logger.debug("IN");
SbiTag toReturn = null;
Session session = null;
try {
session = getSession();
Query query = session.createQuery("from SbiTag t where t.name = :name");
query.setString("name", name);
toReturn = (SbiTag) query.uniqueResult();
} catch (HibernateException e) {
logException(e);
throw new RuntimeException(e);
} finally {
if (session != null && session.isOpen())
session.close();
}
logger.debug("OUT");
return toReturn;
}
17
Source : SbiAttributeDAOHibImpl.java
with GNU Affero General Public License v3.0
from KnowageLabs
with GNU Affero General Public License v3.0
from KnowageLabs
@Override
public SbiAttribute loadSbiAttributeByName(String name) throws EMFUserError {
logger.debug("IN");
SbiAttribute toReturn = null;
Session aSession = null;
Transaction tx = null;
try {
aSession = getSession();
tx = aSession.beginTransaction();
String q = "from SbiAttribute att where att.attributeName = :name";
Query query = aSession.createQuery(q);
query.setString("name", name);
toReturn = (SbiAttribute) query.uniqueResult();
tx.commit();
} 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");
return toReturn;
}
17
Source : SbiDsBcDAOHibImpl.java
with GNU Affero General Public License v3.0
from KnowageLabs
with GNU Affero General Public License v3.0
from KnowageLabs
@Override
public List<SbiMetaDsBc> loadDsBcByKey(SbiMetaDsBcId dsBcId) throws EMFUserError {
logger.debug("IN");
Session aSession = null;
Transaction tx = null;
List<SbiMetaDsBc> toReturn = null;
Query hqlQuery = null;
try {
aSession = getSession();
tx = aSession.beginTransaction();
hqlQuery = aSession.createQuery(" from SbiMetaDsBc as db where db.id.dsId = ? and db.id.bcId = ? and db.id.organization = ?");
hqlQuery.setInteger(0, dsBcId.getDsId());
hqlQuery.setInteger(1, dsBcId.getBcId());
hqlQuery.setString(2, dsBcId.getOrganization());
toReturn = hqlQuery.list();
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
Source : I18NMessagesDAOHibImpl.java
with GNU Affero General Public License v3.0
from KnowageLabs
with GNU Affero General Public License v3.0
from KnowageLabs
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;
}
17
Source : I18NMessagesDAOHibImpl.java
with GNU Affero General Public License v3.0
from KnowageLabs
with GNU Affero General Public License v3.0
from KnowageLabs
@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 preplaceded 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;
}
17
Source : SbiCommunityDAOImpl.java
with GNU Affero General Public License v3.0
from KnowageLabs
with GNU Affero General Public License v3.0
from KnowageLabs
@Override
public List<SbiCommunityUsers> loadCommunitieMembersByName(SbiCommunity community, SbiUser owner) throws EMFUserError {
logger.debug("IN");
List<SbiCommunityUsers> result = null;
Session aSession = null;
Transaction tx = null;
try {
aSession = getSession();
tx = aSession.beginTransaction();
Integer id = community.getCommunityId();
String q = "from SbiCommunityUsers cu where cu.id.communityId = ? and cu.id.userId != ? order by creationDate desc";
Query query = aSession.createQuery(q);
query.setInteger(0, id);
query.setString(1, owner.getUserId());
result = query.list();
return result;
} catch (HibernateException he) {
logger.error(he.getMessage(), he);
if (tx != null)
tx.rollback();
throw new EMFUserError(EMFErrorSeverity.ERROR, 100);
} finally {
logger.debug("OUT");
if (aSession != null) {
if (aSession.isOpen())
aSession.close();
}
}
}
17
Source : LovsInitializer.java
with GNU Affero General Public License v3.0
from KnowageLabs
with GNU Affero General Public License v3.0
from KnowageLabs
public void init(SourceBean config, Session hibernateSession, SbiTenant tenant) {
logger.debug("IN");
try {
String hql = "from SbiLov l where l.commonInfo.organization = :organization";
Query hqlQuery = hibernateSession.createQuery(hql);
hqlQuery.setString("organization", tenant.getName());
List lovs = hqlQuery.list();
if (lovs.isEmpty()) {
logger.info("No LOVs for tenant " + tenant.getName() + ". Starting populating predefined LOVs...");
writeLovs(hibernateSession, tenant);
} else {
logger.debug("Lovs table is already populated for tenant " + tenant.getName());
}
} catch (Throwable t) {
throw new SpagoBIRuntimeException("Ab unexpected error occured while initializeng LOVs", t);
} finally {
logger.debug("OUT");
}
}
17
Source : ChecksInitializer.java
with GNU Affero General Public License v3.0
from KnowageLabs
with GNU Affero General Public License v3.0
from KnowageLabs
public void init(SourceBean config, Session hibernateSession, SbiTenant tenant) {
logger.debug("IN");
try {
String hql = "from SbiChecks c where c.commonInfo.organization = :organization";
Query hqlQuery = hibernateSession.createQuery(hql);
hqlQuery.setString("organization", tenant.getName());
List checks = hqlQuery.list();
if (checks.isEmpty()) {
logger.info("No checks for tenant " + tenant.getName() + ". Starting populating predefined checks...");
writeChecks(hibernateSession, tenant);
} else {
logger.debug("Checks table is already populated for tenant " + tenant.getName());
}
} catch (Throwable t) {
throw new SpagoBIRuntimeException("Ab unexpected error occured while initializeng Checks", t);
} finally {
logger.debug("OUT");
}
}
17
Source : DatabaseServiceStorage.java
with Apache License 2.0
from exactpro
with Apache License 2.0
from exactpro
private long getFirstServiceEventID(Session session, String serviceID) {
String hql = "select event.id from StoredServiceEvent event";
if (serviceID != null) {
hql += " where event.serviceId = :serviceID";
}
Query query = session.createQuery(hql + " order by event.id asc");
if (serviceID != null) {
query.setString("serviceID", serviceID);
}
return (long) ObjectUtils.defaultIfNull(query.setMaxResults(1).uniqueResult(), -1L);
}
17
Source : DatabaseMessageStorage.java
with Apache License 2.0
from exactpro
with Apache License 2.0
from exactpro
private long getFirstMessageID(Session session, String serviceID) {
String hql = "select msg.id from StoredMessage msg";
if (serviceID != null) {
hql += " where msg.serviceId = :serviceID";
}
Query query = session.createQuery(hql + " order by msg.id asc");
if (serviceID != null) {
query.setString("serviceID", serviceID);
}
return (long) ObjectUtils.defaultIfNull(query.setMaxResults(1).uniqueResult(), -1L);
}
17
Source : LdapDBService.java
with European Union Public License 1.1
from EUSurvey
with European Union Public License 1.1
from EUSurvey
@Transactional(timeout = 3000)
public void reloadDomains(Map<String, String> ldapDomains) {
Session session = sessionFactory.getCurrentSession();
logger.info("reload Domains started");
Query query = session.createQuery("FROM Domain d");
@SuppressWarnings("unchecked")
List<Domain> dbDomains = query.list();
Map<String, Domain> dbDomainCodes = new HashMap<>();
for (Domain domain : dbDomains) {
dbDomainCodes.put(domain.getCode(), domain);
}
// create new departments
for (Entry<String, String> ldapDomain : ldapDomains.entrySet()) {
if (!dbDomainCodes.containsKey(ldapDomain.getKey())) {
session.save(new Domain(ldapDomain.getKey(), ldapDomain.getValue()));
} else if (!dbDomainCodes.get(ldapDomain.getKey()).getDescription().equals(ldapDomain.getValue())) {
Domain domain = dbDomainCodes.get(ldapDomain.getKey());
domain.setDescription(ldapDomain.getValue());
session.saveOrUpdate(domain);
}
}
logger.info("new domains saved");
// remove domains that don't exist anymore
for (String domain : dbDomainCodes.keySet()) {
if (!ldapDomains.containsKey(domain)) {
query = session.createQuery("delete from Domain d where d.code = :code");
query.setString("code", domain);
query.executeUpdate();
}
}
logger.info("old domains deleted");
}
17
Source : LdapDBService.java
with European Union Public License 1.1
from EUSurvey
with European Union Public License 1.1
from EUSurvey
@Transactional(timeout = 3000)
public void reload(Set<Departmenreplacedem> departments) {
Session session = sessionFactory.getCurrentSession();
logger.info("reload started");
SQLQuery query = session.createSQLQuery("SELECT DISTINCT DOMAIN_CODE domainCode, NAME name FROM DEPARTMENTS");
@SuppressWarnings("unchecked")
List<Departmenreplacedem> existingDepartments = query.setResultTransformer(Transformers.aliasToBean(Departmenreplacedem.clreplaced)).list();
logger.debug("departments retrieved");
// create new departments
for (Departmenreplacedem department : departments) {
if (!existingDepartments.contains(department)) {
session.save(new Department(department.getName(), department.getDomainCode()));
}
}
logger.debug("new departments saved");
Query deleteQuery = session.createQuery("delete from Department d where d.domainCode = :domainCode and d.name = :department");
// remove departments that don't exist anymore
for (Departmenreplacedem department : existingDepartments) {
if (!departments.contains(department)) {
deleteQuery.setString("department", department.getName());
deleteQuery.setString("domainCode", department.getDomainCode());
deleteQuery.executeUpdate();
}
}
logger.debug("old departments deleted");
}
16
Source : UserDaoImpl.java
with MIT License
from zhangjikai
with MIT License
from zhangjikai
@Override
public User getUserByName$Pw(String username, String preplacedword) {
String sql = "from User where username=:username and preplacedword=:preplacedword";
Session session = sessionFactory.getCurrentSession();
Query query = session.createQuery(sql);
query.setString("username", username);
query.setString("preplacedword", preplacedword);
List<User> users = query.list();
if (users.size() == 0) {
return null;
}
return users.get(0);
}
16
Source : UserDaoImpl.java
with MIT License
from zhangjikai
with MIT License
from zhangjikai
@Override
public User getUserByName(String username) {
String sql = "from User where username=:username";
Session session = sessionFactory.getCurrentSession();
Query query = session.createQuery(sql);
query.setString("username", username);
List<User> users = query.list();
if (users.size() == 0) {
return null;
} else {
return users.get(0);
}
}
16
Source : UserDaoImpl.java
with MIT License
from zhangjikai
with MIT License
from zhangjikai
@Override
public User getUserByEmail(String email) {
String sql = "from User where email=:email";
// String sql = "select id from User where email=:email";
Session session = sessionFactory.getCurrentSession();
Query query = session.createQuery(sql);
query.setString("email", email);
List<User> users = query.list();
if (users.size() == 0) {
return null;
} else {
return users.get(0);
}
}
16
Source : OrgStructTest.java
with Apache License 2.0
from Pardus-Engerek
with Apache License 2.0
from Pardus-Engerek
private List<ROrgClosure> getOrgClosureByDescendant(String descendantOid, Session session) {
Query query = session.createQuery("from ROrgClosure where descendantOid=:oid");
query.setString("oid", descendantOid);
return query.list();
}
16
Source : OrgStructTest.java
with Apache License 2.0
from Pardus-Engerek
with Apache License 2.0
from Pardus-Engerek
private List<ROrgClosure> getOrgClosure(String ancestorOid, String descendantOid, Session session) {
Query query = session.createQuery("from ROrgClosure where ancestorOid=:aOid and descendantOid=:dOid");
query.setString("aOid", ancestorOid);
query.setString("dOid", descendantOid);
return query.list();
}
16
Source : LookupTableHelper.java
with Apache License 2.0
from Pardus-Engerek
with Apache License 2.0
from Pardus-Engerek
private void deleteRowByKey(Session session, String tableOid, String key) {
Query query = session.getNamedQuery("delete.lookupTableDataRowByKey");
query.setString("oid", tableOid);
query.setString("key", key);
query.executeUpdate();
}
16
Source : GeneralHelper.java
with Apache License 2.0
from Pardus-Engerek
with Apache License 2.0
from Pardus-Engerek
public int findLastIdInRepo(Session session, String tableOid, String queryName) {
Query query = session.getNamedQuery(queryName);
query.setString("oid", tableOid);
Integer lastId = (Integer) query.uniqueResult();
if (lastId == null) {
lastId = 0;
}
return lastId;
}
See More Examples