List of usage examples for org.hibernate Session createSQLQuery
@Override NativeQuery createSQLQuery(String queryString);
From source file:com.cis.paseaproduccionweb.dao.ArchivoPaseDao.java
public void TruncarTabla() { Session session = HibernateUtil.getSessionFactory().openSession(); Transaction tx = null;//from w ww.j a va2s.co m try { tx = session.getTransaction(); tx.begin(); Query q = session.createSQLQuery("delete from PP_ARCHIVOS_PASE"); q.executeUpdate(); tx.commit(); } 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(); } }
From source file:com.cms.utils.BaseFWDAOImpl.java
License:Open Source License
public Long getSequenId(String sequense, Session session) { String sql = "select " + sequense + ".nextval from dual"; Query query = session.createSQLQuery(sql); return ((BigDecimal) query.list().get(0)).longValue(); }
From source file:com.connexience.server.model.datasets.DatasetsUtils.java
License:Open Source License
/** Get the size of a multiple json value item */ public static int getJsonMultipleValueDataSize(Session session, JsonMultipleValueItem item) throws ConnexienceException { SQLQuery q = session.createSQLQuery("select count(id) from datasetjson where itemid=:itemid"); q.setLong("itemid", item.getId()); //q.addEntity(Long.class); return ((Number) q.uniqueResult()).intValue(); }
From source file:com.connexience.server.model.datasets.DatasetsUtils.java
License:Open Source License
/** Remove all values for a JSON multiple value data item */ private static void removeJsonMultipleValueData(Session session, JsonMultipleValueItem item) throws ConnexienceException { Query q = session.createSQLQuery("delete from datasetjson where itemid=:itemid"); q.setLong("itemid", item.getId()); q.executeUpdate();//from w w w. j a v a 2 s .c o m }
From source file:com.connexience.server.model.datasets.DatasetsUtils.java
License:Open Source License
private static void removeMultipleValueDataRow(Session session, JsonMultipleValueItem item, long rowId) throws ConnexienceException { Query q = session.createSQLQuery("delete from datasetjson where id=:rowid"); q.setLong("rowid", rowId); q.executeUpdate();//from w w w . j av a 2 s.c o m }
From source file:com.connexience.server.model.metadata.MetadataQueryBuilder.java
License:Open Source License
/** Create the Hibernate Query */ public SQLQuery createSQLQuery(Session session) throws Exception { // Metadata query String queryText = buildMetaDataSearchQuery(); // Full query String fullQuery = "select * from objectsflat where id in (" + queryText + ")"; SQLQuery q = session.createSQLQuery(fullQuery); Iterator<MetadataQueryItem> items = metadataQuery.items(); MetadataQueryItem i;// w w w. ja v a 2 s. c o m // Set category if needed Object[][] params; int positionCounter = 0; while (items.hasNext()) { i = items.next(); i.setPositionCounter(positionCounter); params = i.getParameters(); for (int j = 0; j < params.length; j++) { q.setParameter((String) params[j][0], params[j][1]); } positionCounter = i.getPositionCounter(); } q.addEntity(ServerObject.class); return q; }
From source file:com.connexience.server.model.metadata.MetadataQueryBuilder.java
License:Open Source License
/** Create a count query */ public SQLQuery createSQLCountQuery(Session session) throws Exception { // Metadata query String queryText = buildMetaDataSearchQuery(); // Full query String fullQuery = "select count(id) from objectsflat where id in (" + queryText + ")"; SQLQuery q = session.createSQLQuery(fullQuery); Iterator<MetadataQueryItem> items = metadataQuery.items(); MetadataQueryItem i;//from w ww. ja va2 s. co m // Set category if needed Object[][] params; int positionCounter = 0; while (items.hasNext()) { i = items.next(); i.setPositionCounter(positionCounter); params = i.getParameters(); for (int j = 0; j < params.length; j++) { q.setParameter((String) params[j][0], params[j][1]); } positionCounter = i.getPositionCounter(); } return q; }
From source file:com.consult.app.dao.impl.CargoMessageDaoImpl.java
/** * Common Search cargo, used by 274 Version! * This supports multiple truck length/*from w w w .j ava2s . co 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; } } }
From source file:com.consult.app.dao.impl.CargoMessageDaoImpl.java
/** * Search Nearby cargoMessages by multiple trucklength * @param req//from w w w .jav a 2 s . c o m * @param endCity * @return */ private List<Object> getNearbyMultipleTruckLengthSearch(SearchCargoRequest req, City endCity) { // List<Object> list = new ArrayList<Object>(); Long today = TimeUtils.getStartOfDay(System.currentTimeMillis()); StringBuilder sb = new StringBuilder( String.format(Constant.NEARBY_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 city.id=").append(req.getStart()).append( " and (find_in_set(message.start, city.near_by) or find_in_set(message.start_father, city.near_by))") .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(triggerTime); session = sessionReadFactory.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; } } // } }
From source file:com.consult.app.dao.impl.CargoMessageDaoImpl.java
/** * Search Nearby cargoMessages/*from w ww . jav a 2 s . c o m*/ * Deprecated! * @param req * @param endCity * @return */ private List<Object> getNearbyMessage(SearchCargoRequest req, City endCity) { // List<Object> list = new ArrayList<Object>(); StringBuilder sb = new StringBuilder(Constant.NEARBY_CARGO_SEARCH); if (req.getTruckLengthRange() > 0) { sb.append(" and message.truck_length_range=").append(req.getTruckLengthRange()); } 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 city.id=").append(req.getStart()).append( " and (find_in_set(message.start, city.near_by) or find_in_set(message.start_father, city.near_by))") .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(triggerTime); 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; } } // } }