List of usage examples for org.hibernate Query setString
@Deprecated @SuppressWarnings("unchecked") default Query<R> setString(String name, String val)
From source file:com.enonic.cms.store.dao.GroupEntityDao.java
License:Open Source License
public List<GroupEntity> findBySpecification(GroupSpecification spec) { String hqlQuery = createHqlQuery(spec); Query compiled = getHibernateTemplate().getSessionFactory().getCurrentSession().createQuery(hqlQuery); compiled.setCacheable(true);/*from w w w . j av a2s . c o m*/ if (spec.getKey() != null) { compiled.setString("key", spec.getKey().toString()); } if (spec.getName() != null) { compiled.setString("name", spec.getName()); } if (spec.getSyncValue() != null) { compiled.setString("syncValue", spec.getSyncValue()); } if (spec.getUserStoreKey() != null) { compiled.setInteger("userStoreKey", spec.getUserStoreKey().toInt()); } if (spec.getType() != null) { compiled.setInteger("type", spec.getType().toInteger()); } return compiled.list(); }
From source file:com.enonic.cms.store.dao.UserEntityDao.java
License:Open Source License
public List<UserEntity> findBySpecification(final UserSpecification spec) { String hqlQuery = createHqlQuery(spec); Query compiled = getHibernateTemplate().getSessionFactory().getCurrentSession().createQuery(hqlQuery); compiled.setCacheable(true);//from w w w . j a va 2 s .c om if (spec.getKey() != null) { compiled.setParameter("key", spec.getKey()); } if (spec.getName() != null) { compiled.setString("name", spec.getName().toLowerCase()); } if (spec.getSyncValue() != null) { compiled.setString("syncValue", spec.getSyncValue()); } if (spec.getUserStoreKey() != null) { compiled.setInteger("userStoreKey", spec.getUserStoreKey().toInt()); } if (spec.getType() != null) { compiled.setInteger("type", spec.getType().getKey()); } if (spec.getUserGroupKey() != null) { compiled.setString("userGroupKey", spec.getUserGroupKey().toString()); } if (spec.getEmail() != null) { compiled.setString("email", spec.getEmail().toLowerCase()); } return compiled.list(); }
From source file:com.enonic.vertical.engine.handlers.KeyHandler.java
License:Open Source License
private boolean updateNextKey(final String tableName) { final Query query = getSession().createSQLQuery(KEY_UPDATE); query.setString("table", tableName.toLowerCase()); return query.executeUpdate() > 0; }
From source file:com.enonic.vertical.engine.handlers.KeyHandler.java
License:Open Source License
private int selectCurrentKey(final String tableName) { final Query query = getSession().createSQLQuery(KEY_SELECT); query.setString("table", tableName.toLowerCase()); return ((Number) query.uniqueResult()).intValue(); }
From source file:com.enonic.vertical.engine.handlers.KeyHandler.java
License:Open Source License
private int insertCurrentKey(final String tableName, final int key) { final Query query = getSession().createSQLQuery(KEY_INSERT); query.setString("table", tableName.toLowerCase()); query.setInteger("key", key); query.executeUpdate();//from w ww.j av a 2s . c o m return key; }
From source file:com.env.dao.impl.EffectAppraiseAndLicenseDAOImpl.java
public List<EffectAppraiseAndLicense> getAllEffectAppraiseAndLicense(String entUserId) { String hql = "From EffectAppraiseAndLicense e where e.entUserId=?"; Query query = sessionFactory.getCurrentSession().createQuery(hql); query.setString(0, entUserId); return query.list(); }
From source file:com.env.dao.impl.EffectAppraiseAndLicenseDAOImpl.java
public boolean delEffectAppraiseAndLicense(String effectLicenseId) { String hql = "delete EffectAppraiseAndLicense e where e.effectLicenseId=?"; Query query = sessionFactory.getCurrentSession().createQuery(hql); query.setString(0, effectLicenseId); return (query.executeUpdate() > 0); }
From source file:com.env.dao.impl.EffectAppraiseAndLicenseDAOImpl.java
public EffectAppraiseAndLicense getEffectAppraiseAndLicense(String effectLicenseId) { String hql = "from EffectAppraiseAndLicense e where e.effectLicenseId=?"; Query query = sessionFactory.getCurrentSession().createQuery(hql); query.setString(0, effectLicenseId); return (EffectAppraiseAndLicense) query.uniqueResult(); }
From source file:com.esteban.cmms.maven.model.Ciudades_Model.java
/** * @param ciudad Necesita el nombre de la ciudad que desea buscar * @param pais Cdigo del pas que corresponde a la ciudad * @return si la ciudad y el cdigo del pas corresponden retorna todos los * datos de la ciudad solicitada/*from w ww . j ava 2s.c o m*/ */ public Ciudades getCiudad(String ciudad, String pais) { Ciudades obj = null; Transaction trns = null; Session session = HibernateUtil.getSessionFactory().openSession(); try { trns = session.beginTransaction(); Query query = session.createQuery("from Ciudades as ci " + "left join fetch ci.paises " + "where ci.ciudad = :ciudad " + "and ci.paises.codigo = :pais"); query.setString("ciudad", ciudad); query.setString("pais", pais); obj = (Ciudades) query.uniqueResult(); } catch (RuntimeException e) { e.printStackTrace(); } finally { session.flush(); session.close(); } return obj; }
From source file:com.esteban.cmms.maven.model.Imagenes_Model.java
/** * /* w w w. j a v a2s . com*/ * @param estado El estado al que se desea actualizar el registro, estos para * este sistema pueden se 'Activo' o 'Inactivo' * @param id El id del registro que desea cambiar de estado, lo pasa como un * entero (int) * @param user Informacin del usuario que realiza la operacin. */ public void estadoImagen(String estado, int id, String user) { Transaction trns = null; Session session = HibernateUtil.getSessionFactory().openSession(); try { trns = session.beginTransaction(); Query query = session.createQuery( "UPDATE Imagenes SET " + "Estado = :estado, " + "UserAction = :user " + "WHERE Id = :id"); query.setString("estado", estado); query.setString("user", user); query.setInteger("id", id); query.executeUpdate(); System.out.println("Cambia de estado..."); session.getTransaction().commit(); } catch (RuntimeException e) { if (trns != null) { trns.rollback(); } e.printStackTrace(); } finally { session.flush(); session.close(); } }