List of usage examples for org.hibernate Query setString
@Deprecated @SuppressWarnings("unchecked") default Query<R> setString(String name, String val)
From source file:com.carmanage.dao.impl.BusDaoImpl.java
public List<Car> groupSearch(Car bus, PageController pc) { String plate = bus.getPlate(); String brand = bus.getBrand(); int seat = bus.getSeat(); String register_date = bus.getRegister_date(); String insurance_date = bus.getInsurance_date(); Session session = sessionFactory.openSession(); Query query = session .createQuery("from Car e where e.plate=? and e.brand=? and " + "e.seat=? and e.register_date=? and e.insurance_date=?") .setFirstResult(pc.getPageStartRow()).setMaxResults(pc.getPageSize()); query.setString(0, plate); query.setString(1, brand);/*ww w .jav a 2 s . c om*/ query.setInteger(2, seat); query.setString(3, register_date); query.setString(4, insurance_date); List<Car> buses = query.list(); session.close(); return buses; }
From source file:com.carmanage.dao.impl.BusDaoImpl.java
public int getGroupTotalRows(Car bus) { String plate = bus.getPlate(); String brand = bus.getBrand(); int seat = bus.getSeat(); String register_date = bus.getRegister_date(); String insurance_date = bus.getInsurance_date(); int totalRow = 0; Session session = sessionFactory.openSession(); Query query = session.createQuery("select count(e) from Car e where e.plate=? and e.brand=? and " + "e.seat=? and e.register_date=? and e.insurance_date=?"); query.setString(0, plate); query.setString(1, brand);//from w w w. j a v a 2 s.co m query.setInteger(2, seat); query.setString(3, register_date); query.setString(4, insurance_date); Object oj = query.list().get(0); Number num = (Number) oj; totalRow = num.intValue(); session.close(); return totalRow; }
From source file:com.carmanage.dao.impl.BusDaoImpl.java
public Car showModifyData(String modifyBusPlate) { Session session = sessionFactory.openSession(); Query query = session.createQuery("select e from Car e where e.plate=?"); query.setString(0, modifyBusPlate); Car car = (Car) query.uniqueResult(); session.close();//ww w. java 2s. c om return car; }
From source file:com.carmanage.dao.impl.BusDaoImpl.java
public void modiCar(Car car) { String plate = car.getPlate(); String brand = car.getBrand(); int seat = car.getSeat(); String register_date = car.getRegister_date(); String insurance_date = car.getInsurance_date(); String driver_license = car.getDriver_license(); String driving_license = car.getDriving_license(); Session session = sessionFactory.openSession(); String hql = "Update Car e set e.brand=?,e.seat=?,e.register_date=?,e.insurance_date=?,e.driver_license=?,e.driving_license=? where e.plate=?"; Query query = session.createQuery(hql); query.setString(0, brand); query.setInteger(1, seat);//from w w w. j a v a 2s .c o m query.setString(2, register_date); query.setString(3, insurance_date); query.setString(4, driver_license); query.setString(5, driving_license); query.setString(6, plate); query.executeUpdate(); session.flush(); session.close(); }
From source file:com.cis.paseaproduccionweb.dao.HistorialesDao.java
public Integer getLastVersion(String nombre, BigDecimal sistemaId) { Session session = HibernateUtil.getSessionFactory().openSession(); Transaction tx = null;/* w ww . ja v a2s . c o m*/ Object resultado; try { tx = session.getTransaction(); tx.begin(); Query q = session.getNamedQuery("SP_ULTIMA_VERSION_HISTORIAL"); q.setString(0, nombre); q.setBigDecimal(1, sistemaId); resultado = q.uniqueResult(); tx.commit(); return (Integer) resultado; } catch (Exception e) { if (tx != null) tx.rollback(); ErroresDao dError = new ErroresDao(); PpErrores error = new PpErrores(); Date date = new Date(); error.setStacktrace(e.toString()); error.setFecha(date); dError.insertarError(error); } finally { session.close(); } return 0; }
From source file:com.cloud.bridge.util.QueryHelper.java
License:Open Source License
public static void bindParameters(Query query, Object[] params) { int pos = 0;//from w w w .j a v a 2s . co m if (params != null && params.length > 0) { for (Object param : params) { if (param instanceof Byte) query.setByte(pos++, ((Byte) param).byteValue()); else if (param instanceof Short) query.setShort(pos++, ((Short) param).shortValue()); else if (param instanceof Integer) query.setInteger(pos++, ((Integer) param).intValue()); else if (param instanceof Long) query.setLong(pos++, ((Long) param).longValue()); else if (param instanceof Float) query.setFloat(pos++, ((Float) param).floatValue()); else if (param instanceof Double) query.setDouble(pos++, ((Double) param).doubleValue()); else if (param instanceof Boolean) query.setBoolean(pos++, ((Boolean) param).booleanValue()); else if (param instanceof Character) query.setCharacter(pos++, ((Character) param).charValue()); else if (param instanceof Date) query.setDate(pos++, (Date) param); else if (param instanceof Calendar) query.setCalendar(pos++, (Calendar) param); else if (param instanceof CalendarDateParam) query.setCalendarDate(pos++, ((CalendarDateParam) param).dateValue()); else if (param instanceof TimestampParam) query.setTimestamp(pos++, ((TimestampParam) param).timestampValue()); else if (param instanceof TimeParam) query.setTime(pos++, ((TimeParam) param).timeValue()); else if (param instanceof String) query.setString(pos++, (String) param); else if (param instanceof TextParam) query.setText(pos++, ((TextParam) param).textValue()); else if (param instanceof byte[]) query.setBinary(pos++, (byte[]) param); else if (param instanceof BigDecimal) query.setBigDecimal(pos++, (BigDecimal) param); else if (param instanceof BigInteger) query.setBigInteger(pos++, (BigInteger) param); else if (param instanceof Locale) query.setLocale(pos++, (Locale) param); else if (param instanceof EntityParam) query.setEntity(pos++, ((EntityParam) param).entityValue()); else if (param instanceof Serializable) query.setSerializable(pos++, (Serializable) param); else query.setEntity(pos++, param); } } }
From source file:com.connexience.server.model.datasets.DatasetsUtils.java
License:Open Source License
/** Remove all multiple value data items from a dataset */ public static void removeAllMultipleValueData(Session session, Dataset ds) throws ConnexienceException { // Get all of the data items Query q = session.createQuery("from MultipleValueItem as mv where mv.datasetId=:datasetid"); q.setString("datasetid", ds.getId()); List results = q.list();//from ww w . ja va 2 s.com // Remove all of the associated data MultipleValueItem item; for (int i = 0; i < results.size(); i++) { item = (MultipleValueItem) results.get(i); removeMultipleValueData(session, item); } }
From source file:com.consult.app.dao.impl.CargoMessageDaoImpl.java
@Override public List<Object> searchCargoByClerk(TelephoneRequest req) { Session session = null;/* ww w .ja v a2s. com*/ long startOfDay = TimeUtils.getStartOfDay(System.currentTimeMillis()) + 1; try { CargoMessageInterceptor inter = new CargoMessageInterceptor(startOfDay + 1); session = sessionFactory.openSession(inter); String hql = "select new com.consult.app.response.admin.ClerkMessageItem(message) " + "from CargoMessage message " + "where message.telephone=? and message.updateTime>? and (message.type=1 or message.type=-1 or message.type=2 or message.type=-2)"; Query query = session.createQuery(hql); query.setString(0, req.getTelephone()); query.setLong(1, startOfDay); query.setFirstResult(0); query.setMaxResults(100); List<Object> list = query.list(); return list; } catch (Exception e) { e.printStackTrace(); } finally { if (session != null) { session.close(); session = null; } } return null; }
From source file:com.consult.app.dao.impl.CargoMessageDaoImpl.java
@Override public List<Object> searchAllCargoByAdmin(TelephoneBeforeAfterCountRequest req) { Session session = null;// www . ja v a2 s . c o m List<Object> list = null; // long startOfDay = TimeUtils.getStartOfDay(System.currentTimeMillis()) + 1; try { CargoMessageInterceptor interBefore = new CargoMessageInterceptor(req.getBefore()); int beforeIndex = interBefore.getTableIndex(); CargoMessageInterceptor interAfter = new CargoMessageInterceptor(req.getAfter()); int afterIndex = interAfter.getTableIndex(); if (beforeIndex != afterIndex) { LogUtil.i("searchAllCargoByAdmin", " beforeIndex != afterIndex "); return list; } session = sessionFactory.openSession(interBefore); String hql = "select new com.consult.app.response.admin.ClerkMessageItem(message) " + "from CargoMessage message " + "where message.telephone=? and message.createTime>? and message.createTime<? order by " + " message.createTime desc"; Query query = session.createQuery(hql); query.setString(0, String.valueOf(req.getTelephone())); query.setLong(1, req.getBefore()); query.setLong(2, req.getAfter()); query.setMaxResults(req.getCount()); list = query.list(); return list; } catch (Exception e) { e.printStackTrace(); } finally { if (session != null) { session.close(); session = null; } } return list; }
From source file:com.consult.app.dao.impl.UserDaoImpl.java
@Override public int changePassword(long userId, String newPassword) { try {/*from w w w . j av a 2s. co m*/ String hql = "update User user set user.password=? where user.userId=?"; Query query = sessionFactory.getCurrentSession().createQuery(hql); query.setString(0, newPassword); query.setLong(1, userId); query.executeUpdate(); JUserCache.getInstance().removeUser(userId); return Cookie.RESPONSE_SUCCESS; } catch (Exception e) { e.printStackTrace(); return Cookie.RESPONSE_SERVER_QUERY_ERROR; } }