List of usage examples for org.hibernate Query setInteger
@Deprecated @SuppressWarnings("unchecked") default Query<R> setInteger(String name, int val)
From source file:com.candy.db.FundamentalDataProc.java
/** * delete UnProcessed Q data//from www .j a va 2 s . c o m * @param symbol * @param year * @param quarter * @param type */ public boolean deleteQData(String symbol, int year, int oldQtr, int type) { Session session = getSession(); try { begin(); Query q = session.createQuery( "delete from Fundamentaldata where symbol = :symbol and year = :year and quarter =:quarter and type = :type"); q.setString("symbol", symbol); q.setInteger("year", year); q.setInteger("quarter", oldQtr); q.setInteger("type", type); int rowCount = q.executeUpdate(); commit(); return (rowCount == 1); } catch (HibernateException e) { e.printStackTrace(); return false; } }
From source file:com.cantor.ipplan.server.ProfileServiceImpl.java
License:Open Source License
private void deleteMessage(Session session, int messageId) { Query q = session.createQuery("delete from Messages where messagesId=:messagesId"); q.setInteger("messagesId", messageId); q.executeUpdate();/*from ww w.j a v a2s .c om*/ }
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);/*from w w w. ja v a 2s . c o m*/ query.setString(1, brand); 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);/* w w w .jav a 2 s.com*/ query.setString(1, brand); 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 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);/* w w w.ja v a2s.co m*/ query.setInteger(1, seat); 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.cimmyt.model.dao.impl.SampleDetailDAOImpl.java
License:Apache License
public List<SampleDetail> getSamplesByShipmentSet(final ShipmentSet shipmentSet) { final String queryString = "select sd from SampleDetail as sd " + "inner join sd.imsShipmentdetailCollection as shd " + "where shd.stShipmentSet.idShipmentSet = :id"; List<SampleDetail> sampleDetails = null; sampleDetails = (List<SampleDetail>) getHibernateTemplate().execute(new HibernateCallback() { @Override/* w w w .ja va 2 s.com*/ public Object doInHibernate(Session session) throws HibernateException, SQLException { List<SampleDetail> samplesDetailResult = null; Query query = session.createQuery(queryString); query.setInteger("id", shipmentSet.getIdShipmentSet()); samplesDetailResult = query.list(); return samplesDetailResult; } }); return sampleDetails; }
From source file:com.cimmyt.model.dao.impl.SampleDetailDAOImpl.java
License:Apache License
public List<String> getPlatesInShipmentSet(final ShipmentSet shipSet) { final String queryString = "select distinct sd.platename from SampleDetail as sd " + "inner join sd.imsShipmentdetailCollection as shd " + "where shd.stShipmentSet.idShipmentSet = :id"; List<String> sampleDetails = null; sampleDetails = (List<String>) getHibernateTemplate().execute(new HibernateCallback<List<String>>() { public List<String> doInHibernate(Session session) throws HibernateException, SQLException { Query query = session.createQuery(queryString); query.setInteger("id", shipSet.getIdShipmentSet()); @SuppressWarnings("unchecked") List<String> samplesDetailResult = query.list(); return samplesDetailResult; }/*from w w w . ja v a2 s . c o m*/ }); return sampleDetails; }
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 www . j a v a 2 s . com*/ 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.consult.app.dao.impl.CargoMessageDaoImpl.java
/** * ???//w w w.j a v a 2s.c o m * */ public CargoMessageItem selectById(Long id) { Session session = null; CargoMessageItem message = null; try { CargoMessageInterceptor inter = new CargoMessageInterceptor(); long triggerTime = System.currentTimeMillis(); inter.setShardCriteria(triggerTime); session = sessionFactory.openSession(inter); Query query = session.createQuery( "select new com.consult.app.response.cargo.CargoMessageItem(message.messageId, message.type, message.weight, message.capacity, message.truckType, message.contact, message.telephone, message.start, message.end, message.description, message.updateTime, message.truckLength, message.companyName, message.companyAddress, message.landlines, message.picture, message.avatarAuthenticate, message.userId, message.licenseAuthenticate, message.charges, message.cargoType, message.score, message.orderCount, message.messageCount, message.truckLengthSet) from CargoMessage message where message.messageId=? and message.updateTime>? and message.type>0 and message.type<?"); query.setLong(0, id); query.setLong(1, TimeUtils.getStartOfDay(triggerTime)); query.setInteger(2, Constant.TYPE_ORDERED); message = (CargoMessageItem) query.uniqueResult(); if (message != null) { return message; } if (inter.isFinishSearch(0)) { return null; } triggerTime = inter.getTriggerTime(); return message; } catch (Exception e) { e.printStackTrace(); return null; } finally { if (session != null) { session.close(); session = null; } } }
From source file:com.consult.app.dao.impl.CargoMessageDaoImpl.java
/** * Common Search cargo, used by 274 Version! * This supports multiple truck length//from www. ja va 2 s . c o m * */ private List<Object> getMultipleTruckLengthSearch(SearchCargoRequest req, City endCity) { Long today = TimeUtils.getStartOfDay(System.currentTimeMillis()); StringBuilder sb = new StringBuilder(String.format(Constant.CARGO_SEARCH_MULTIPLE_TRUCKLENGTH, today)); if (Double.valueOf(req.getTruckLength()) >= 0) { sb.append(" and find_in_set(").append(req.getTruckLength()).append(",message.truck_length_set)"); } if (req.getTruckType() >= 0) { sb.append(" and message.truck_type=").append(req.getTruckType()); } if (req.getWeightRange() > 0) { sb.append(" and message.cargo_weight_range=").append(req.getWeightRange()); } sb.append(" and (message.start=").append(req.getStart()).append(" or message.start_father=") .append(req.getStart()).append(" or message.start_grand=").append(req.getStart()) .append(") and (message.end=").append(endCity.getId()).append(" or message.end_father=") .append(endCity.getId()).append(" or message.end_grand=").append(endCity.getId()).append(" or 0=") .append(endCity.getId()).append(")"); sb.append(" and message.type>=? and message.type<4 order by message.update_time desc"); Long triggerTime = req.getAfter(); if (triggerTime.equals(Long.MAX_VALUE)) { triggerTime = System.currentTimeMillis(); } CargoMessageInterceptor inter = new CargoMessageInterceptor(); int count = req.getCount(); // for(int i = 0; i < Constant.SEARCH_TABLE_COUNT; i++) { Session session = null; try { // Long messageId, int type, // double weight, double capacity, int truckType, // String contact, String telephone, int start, int end, // String description, long updateTime, double truckLength, // String companyName, String companyAddress, String landlines, // String picture, int avatarAuthenticate, Long userId inter.setShardCriteria(System.currentTimeMillis()); session = sessionFactory.openSession(inter); Query query = session.createSQLQuery(sb.toString()).addScalar("messageId", StandardBasicTypes.LONG) .addScalar("type", StandardBasicTypes.INTEGER).addScalar("weight", StandardBasicTypes.DOUBLE) .addScalar("capacity", StandardBasicTypes.DOUBLE) .addScalar("truckType", StandardBasicTypes.INTEGER) .addScalar("contact", StandardBasicTypes.STRING) .addScalar("telephone", StandardBasicTypes.STRING) .addScalar("start", StandardBasicTypes.INTEGER).addScalar("end", StandardBasicTypes.INTEGER) .addScalar("description", StandardBasicTypes.STRING) .addScalar("updateTime", StandardBasicTypes.LONG) .addScalar("truckLength", StandardBasicTypes.DOUBLE) .addScalar("companyName", StandardBasicTypes.STRING) .addScalar("companyAddress", StandardBasicTypes.STRING) .addScalar("landlines", StandardBasicTypes.STRING) .addScalar("picture", StandardBasicTypes.STRING) .addScalar("avatarAuthenticate", StandardBasicTypes.INTEGER) .addScalar("userId", StandardBasicTypes.LONG) .addScalar("licenseAuthenticate", StandardBasicTypes.INTEGER) .addScalar("cargoType", StandardBasicTypes.INTEGER) .addScalar("score", StandardBasicTypes.DOUBLE) .addScalar("orderCount", StandardBasicTypes.INTEGER) .addScalar("charges", StandardBasicTypes.INTEGER) .addScalar("messageCount", StandardBasicTypes.LONG) .addScalar("truckLengthSet", StandardBasicTypes.STRING).setResultTransformer( Transformers.aliasToBean(com.consult.app.response.cargo.CargoMessageItem.class)); query.setLong(0, req.getBefore()); query.setLong(1, triggerTime); query.setInteger(2, Constant.TYPE_NORMAL); query.setFirstResult(0); query.setMaxResults(count); @SuppressWarnings("unchecked") List<Object> tmpList = query.list(); // if(tmpList != null && tmpList.size() > 0) { // list.addAll(tmpList); // if(tmpList.size() >= count) { // tx.commit(); // return list; // } // count -= tmpList.size(); //// min = metaList.get(metaList.size() - 1).getUpdateTime(); // } // if(inter.isFinishSearch(req.getBefore())) { // tx.commit(); // return list; // } // triggerTime = inter.getTriggerTime(); return tmpList; } catch (Exception e) { e.printStackTrace(); return null; } finally { if (session != null) { session.close(); session = null; } } }