List of usage examples for org.hibernate.transform Transformers aliasToBean
public static ResultTransformer aliasToBean(Class target)
From source file:com.consult.app.dao.impl.CargoMessageDaoImpl.java
/** * Search Nearby cargoMessages/* w w w. j av a2s . co 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; } } // } }
From source file:com.consult.app.dao.impl.CargoMessageDaoImpl.java
@Override public List<Object> getTodaySuspiciousCargoer() { Session session = null;/*from www .j a v a 2 s . co m*/ String sql = "select u.install_place as city, u.telephone as telephone, p.user_name as userName, count(m.message_id) as cnt from cargo_message_00 m, users u, profiles p where m.user_id=u.user_id and m.user_id=p.user_id and (m.type=1 or m.type=-1 or m.type=4) and m.update_time>? group by m.user_id having cnt>=20 order by cnt desc;"; long startOfDay = TimeUtils.getStartOfDay(System.currentTimeMillis()); try { CargoMessageInterceptor inter = new CargoMessageInterceptor(startOfDay + 1); session = sessionFactory.openSession(inter); Query query = session.createSQLQuery(sql).addScalar("city", StandardBasicTypes.INTEGER) .addScalar("telephone", StandardBasicTypes.LONG) .addScalar("userName", StandardBasicTypes.STRING).addScalar("cnt", StandardBasicTypes.INTEGER) .setResultTransformer(Transformers.aliasToBean(com.consult.app.response.cargo.CargoItem.class)); query.setLong(0, startOfDay); List list = query.list(); return list; } catch (Exception e) { e.printStackTrace(); return null; } finally { if (session != null) { session.close(); session = null; } } }
From source file:com.consult.app.dao.impl.UserDaoImpl.java
public List<Object> searchDriverList(SearchDriverRequest req) { /**/* w w w . j a v a 2 s . com*/ * */ long possitionTime = System.currentTimeMillis() - TimeUtils.DAY * 14; Query query = null; StringBuffer querysql = new StringBuffer(""); String truckLengthCondition = req.getTruckLength() <= 0d ? "" : "and p.truck_length=:truckLength"; String sqlTem = "(select u.user_id as userId,p.picture as picture,p.user_name as userName,u.telephone as telephone,p.truck_length as truckLength,p.truck_load as truckLoad,p.truck_type as truckType,p.number as number,u.is_authenticate as isAuthenticate,u.create_time as updateTime,p.order_count as orderCount,u.city as cityId,abs(u.city-:start) as sortFlag from users u, profiles p, %s sub, search_conditions sc where sub.user_id=u.user_id and u.user_id=p.user_id and p.user_type=1 and sub.search_id=sc.search_id and u.telephone>13000000000 " + truckLengthCondition + " and sub.push_subscribe=1 and u.push_subscribe=1 and u.type=1 and sub.type>0 and (sc.end=:end or sc.end=:endFather) and (sc.start=:start or sc.start=:startFather) and u.update_time>:before and u.update_time<:after and u.update_time>:possitionTime)"; for (int i = 0; i < Constant.SHARD_TABLE_SUBSCRIBE.length; i++) { if (i == 0) { querysql.append("select t.* from (" + String.format(sqlTem, Constant.SHARD_TABLE_SUBSCRIBE[i]) + " union all "); } else if (i == Constant.SHARD_TABLE_SUBSCRIBE.length - 1) { querysql.append(String.format(sqlTem, Constant.SHARD_TABLE_SUBSCRIBE[i]) + ") t group by t.userId order by t.sortFlag asc,t.updateTime desc");//,t.orderCount desc } else { querysql.append(String.format(sqlTem, Constant.SHARD_TABLE_SUBSCRIBE[i]) + " union all "); } } query = sessionFactory.getCurrentSession().createSQLQuery(querysql.toString()) .addScalar("userId", StandardBasicTypes.LONG).addScalar("picture", StandardBasicTypes.STRING) .addScalar("userName", StandardBasicTypes.STRING).addScalar("telephone", StandardBasicTypes.STRING) .addScalar("truckLength", StandardBasicTypes.DOUBLE) .addScalar("truckLoad", StandardBasicTypes.DOUBLE) .addScalar("truckType", StandardBasicTypes.INTEGER).addScalar("number", StandardBasicTypes.STRING) .addScalar("isAuthenticate", StandardBasicTypes.INTEGER) .addScalar("updateTime", StandardBasicTypes.LONG) .addScalar("orderCount", StandardBasicTypes.INTEGER).addScalar("cityId", StandardBasicTypes.INTEGER) .setResultTransformer(Transformers.aliasToBean(com.consult.app.response.truck.DriverInfo.class)); if (req.getTruckLength() > 0) { query.setDouble("truckLength", req.getTruckLength()); } query.setInteger("end", req.getEnd()).setInteger("endFather", req.getEndFather()) .setInteger("start", req.getStart()).setInteger("startFather", req.getStartFather()) .setLong("before", req.getBefore()).setLong("after", req.getAfter()) .setLong("possitionTime", possitionTime); query.setMaxResults(req.getCount()); @SuppressWarnings("unchecked") List<Object> all = query.list(); return all; }
From source file:com.consult.app.dao.impl.UserDaoImpl.java
public Object findDriverByTelephone(Long telephone) { Object obj = null;/* w w w. ja v a2 s .c om*/ try { String sql = "select '1'as userType,u.user_id as userId,p.picture as picture,p.user_name as userName,u.telephone as telephone,p.truck_length as truckLength,p.truck_load as truckLoad,p.truck_type as truckType,p.number as number,u.is_authenticate as isAuthenticate from users u, profiles p where u.user_id=p.user_id and p.user_type=1 and u.telephone=? "; Query query = null; query = sessionFactory.getCurrentSession().createSQLQuery(sql) .addScalar("userType", StandardBasicTypes.INTEGER).addScalar("userId", StandardBasicTypes.LONG) .addScalar("picture", StandardBasicTypes.STRING) .addScalar("userName", StandardBasicTypes.STRING) .addScalar("telephone", StandardBasicTypes.STRING) .addScalar("truckLength", StandardBasicTypes.DOUBLE) .addScalar("truckLoad", StandardBasicTypes.DOUBLE) .addScalar("truckType", StandardBasicTypes.INTEGER) .addScalar("number", StandardBasicTypes.STRING) .addScalar("isAuthenticate", StandardBasicTypes.INTEGER) .setResultTransformer(Transformers.aliasToBean(com.consult.app.response.truck.DriverInfo.class)) .setLong(0, telephone); obj = query.uniqueResult(); if (obj == null) { sql = "select '0' as userType, u.user_id as userId,'' as picture,u.user_name as userName,u.telephone as telephone,u.truck_length as truckLength,u.truck_load as truckLoad,u.truck_type as truckType,u.truck_number as number,0 as isAuthenticate from unregister_user u where u.type=2 and u.telephone=?"; query = sessionFactory.getCurrentSession().createSQLQuery(sql) .addScalar("userType", StandardBasicTypes.INTEGER) .addScalar("userId", StandardBasicTypes.LONG) .addScalar("picture", StandardBasicTypes.STRING) .addScalar("userName", StandardBasicTypes.STRING) .addScalar("telephone", StandardBasicTypes.STRING) .addScalar("truckLength", StandardBasicTypes.DOUBLE) .addScalar("truckLoad", StandardBasicTypes.DOUBLE) .addScalar("truckType", StandardBasicTypes.INTEGER) .addScalar("number", StandardBasicTypes.STRING) .addScalar("isAuthenticate", StandardBasicTypes.INTEGER) .setResultTransformer( Transformers.aliasToBean(com.consult.app.response.truck.DriverInfo.class)) .setLong(0, telephone); obj = query.uniqueResult(); } } catch (Exception e) { e.printStackTrace(); } return obj; }
From source file:com.consult.app.dao.impl.UserDaoImpl.java
public Object findDriverByUserId(Long id) { Object obj = null;/* ww w .j a va2s . c o m*/ try { String sql = "select '1'as userType,u.user_id as userId,p.picture as picture,p.user_name as userName,u.telephone as telephone,p.truck_length as truckLength,p.truck_load as truckLoad,p.truck_type as truckType,p.number as number,u.is_authenticate as isAuthenticate from users u, profiles p where u.user_id=p.user_id and p.user_type=1 and u.user_id=? "; Query query = null; query = sessionFactory.getCurrentSession().createSQLQuery(sql) .addScalar("userType", StandardBasicTypes.INTEGER).addScalar("userId", StandardBasicTypes.LONG) .addScalar("picture", StandardBasicTypes.STRING) .addScalar("userName", StandardBasicTypes.STRING) .addScalar("telephone", StandardBasicTypes.STRING) .addScalar("truckLength", StandardBasicTypes.DOUBLE) .addScalar("truckLoad", StandardBasicTypes.DOUBLE) .addScalar("truckType", StandardBasicTypes.INTEGER) .addScalar("number", StandardBasicTypes.STRING) .addScalar("isAuthenticate", StandardBasicTypes.INTEGER) .setResultTransformer(Transformers.aliasToBean(com.consult.app.response.truck.DriverInfo.class)) .setLong(0, id); obj = query.uniqueResult(); if (obj == null) { sql = "select '0' as userType, u.user_id as userId,'' as picture,u.user_name as userName,u.telephone as telephone,u.truck_length as truckLength,u.truck_load as truckLoad,u.truck_type as truckType,u.truck_number as number,0 as isAuthenticate from unregister_user u where u.type=2 and u.user_id=?"; query = sessionFactory.getCurrentSession().createSQLQuery(sql) .addScalar("userType", StandardBasicTypes.INTEGER) .addScalar("userId", StandardBasicTypes.LONG) .addScalar("picture", StandardBasicTypes.STRING) .addScalar("userName", StandardBasicTypes.STRING) .addScalar("telephone", StandardBasicTypes.STRING) .addScalar("truckLength", StandardBasicTypes.DOUBLE) .addScalar("truckLoad", StandardBasicTypes.DOUBLE) .addScalar("truckType", StandardBasicTypes.INTEGER) .addScalar("number", StandardBasicTypes.STRING) .addScalar("isAuthenticate", StandardBasicTypes.INTEGER) .setResultTransformer( Transformers.aliasToBean(com.consult.app.response.truck.DriverInfo.class)) .setLong(0, id); obj = query.uniqueResult(); } } catch (Exception e) { e.printStackTrace(); } return obj; }
From source file:com.court.controller.AssignNewLoanFxmlController.java
private ObservableList<Loan> getAllLoans() { Session session = HibernateUtil.getSessionFactory().openSession(); Criteria c = session.createCriteria(Loan.class); c.add(Restrictions.eq("status", true)); c.setProjection(Projections.projectionList().add(Projections.property("loanId"), "loanId") .add(Projections.property("loanName"), "loanName")); c.setResultTransformer(Transformers.aliasToBean(Loan.class)); List<Loan> lList = c.list(); ObservableList<Loan> loans = FXCollections.observableArrayList(lList); session.close();/*from www . j a va2s .c o m*/ return loans; }
From source file:com.court.controller.AssignNewLoanFxmlController.java
private Set<Member> getAvailableGuarantors() { Session session = HibernateUtil.getSessionFactory().openSession(); Criteria c1 = session.createCriteria(MemberLoan.class); c1.setProjection(Projections.projectionList().add(Projections.property("isComplete"), "isComplete") .add(Projections.property("guarantors"), "guarantors") .add(Projections.property("member"), "member")); c1.setResultTransformer(Transformers.aliasToBean(MemberLoan.class)); List<MemberLoan> ml = c1.list(); //GET ALL GUARANTORS OF ONGOING LOANS List<String> guarantors = ml.stream().filter(p -> !p.isIsComplete()) .map(m -> m.getGuarantors() + "-" + m.getMember().getMemberId()).collect(Collectors.toList()); Set<String> lkm = new HashSet<>(guarantors); List<String> guarantor_filtered = lkm.stream().map(r -> r = r.split("-")[0]).collect(Collectors.toList()); //GET ALREADY GUARANTED MEMBERS OF THE GARNTOR List<String> alreadyGurantedMembers = ml.stream().filter(p -> !p.isIsComplete()) .filter(p -> p.getMember().getMemberId().equalsIgnoreCase(getMember().getMemberId())) .map(MemberLoan::getGuarantors).collect(Collectors.toList()); //======================== Set<Member> set = new HashSet<>(); //======================== //GET ALL MEMBERS EXCEPT THE LOAN GRANTOR Criteria c2 = session.createCriteria(Member.class); c2.add(Restrictions.ne("memberId", getMember().getMemberId())); c2.add(Restrictions.eq("status", true)); c2.setProjection(Projections.projectionList().add(Projections.property("memberId"), "memberId") .add(Projections.property("fullName"), "fullName")); c2.setResultTransformer(Transformers.aliasToBean(Member.class)); //IF NO GURANTORS FOUND THEN ALL MEMBERS CAN GUARANT FOR THE LOAN EXCEPT THE LOAN GRANTOR if (getUniqueGuarantors(guarantor_filtered, UNIQUE_GUR_FRQUENCY).isEmpty()) { List<Member> list = c2.list(); set.addAll(list);//from w w w . ja v a 2 s . co m // } else { List<Member> list = c2.add(Restrictions .not(Restrictions.in("memberId", getUniqueGuarantors(guarantor_filtered, UNIQUE_GUR_FRQUENCY)))) .list(); set.addAll(list); } //IF NO GUARANTORS AVAILABLE THEY CAN GURANT THE GRANTOR ULTIMATELY UNTIL ALL GUARANTED LOANS END if (!alreadyGurantedMembers.isEmpty()) { Set<Member> arlm = getAlreadyGurantedMembers(alreadyGurantedMembers, session); set.addAll(arlm); } session.close(); return set; }
From source file:com.court.controller.AssignNewLoanFxmlController.java
private Set<Member> getAlreadyGurantedMembers(List<String> agm, Session s) { Set<String> ug = new HashSet<>(); for (String string : agm) { Type type = new TypeToken<List<String>>() { }.getType();/*from w ww . j a v a 2s . com*/ List<String> yourList = new Gson().fromJson(string, type); for (String yl : yourList) { ug.add(yl); } } Criteria cc2 = s.createCriteria(Member.class); cc2.add(Restrictions.in("memberId", ug)); cc2.setProjection(Projections.projectionList().add(Projections.property("memberId"), "memberId") .add(Projections.property("fullName"), "fullName")); cc2.setResultTransformer(Transformers.aliasToBean(Member.class)); List<Member> list = cc2.list(); Set<Member> mbrs = new HashSet(list); return mbrs; }
From source file:com.court.controller.HomeFXMLController.java
private Map<String, Number> getLoanReleasedData() { LocalDate now = LocalDate.now(); Map<String, Number> map = new HashMap<>(); Session s = HibernateUtil.getSessionFactory().openSession(); Criteria c = s.createCriteria(MemberLoan.class); ProjectionList pList = Projections.projectionList(); ClassMetadata lpMeta = s.getSessionFactory().getClassMetadata(MemberLoan.class); pList.add(Projections.property(lpMeta.getIdentifierPropertyName())); for (String prop : lpMeta.getPropertyNames()) { pList.add(Projections.property(prop), prop); }/*from ww w.ja v a 2 s . com*/ c.add(Restrictions.eq("status", true)); c.add(Restrictions.between("grantedDate", FxUtilsHandler.getDateFrom(now.with(firstDayOfYear())), FxUtilsHandler.getDateFrom(now.with(lastDayOfYear())))); c.setProjection(pList .add(Projections.sqlGroupProjection("DATE_FORMAT(granted_date, '%Y-%m-01') AS groupPro", "groupPro", new String[] { "groupPro" }, new Type[] { StringType.INSTANCE })) .add(Projections.sqlProjection("SUM(loan_amount) AS lSum", new String[] { "lSum" }, new Type[] { DoubleType.INSTANCE }))); c.addOrder(Order.asc("grantedDate")); c.setResultTransformer(Transformers.aliasToBean(MemberLoan.class)); List<MemberLoan> list = (List<MemberLoan>) c.list(); for (MemberLoan ml : list) { map.put(ml.getGroupPro(), ml.getlSum()); } s.close(); return map; }
From source file:com.court.controller.HomeFXMLController.java
private Map<String, Number> getLoanCollectionData() { LocalDate now = LocalDate.now(); Map<String, Number> map = new HashMap<>(); Session s = HibernateUtil.getSessionFactory().openSession(); Criteria c = s.createCriteria(LoanPayment.class); ProjectionList pList = Projections.projectionList(); ClassMetadata lpMeta = s.getSessionFactory().getClassMetadata(LoanPayment.class); pList.add(Projections.property(lpMeta.getIdentifierPropertyName())); for (String prop : lpMeta.getPropertyNames()) { pList.add(Projections.property(prop), prop); }//from ww w . j a va2s . c om c.add(Restrictions.between("paymentDate", FxUtilsHandler.getDateFrom(now.with(firstDayOfYear())), FxUtilsHandler.getDateFrom(now.with(lastDayOfYear())))); c.setProjection(pList .add(Projections.sqlGroupProjection("DATE_FORMAT(payment_date, '%Y-%m-01') AS groupPro", "groupPro", new String[] { "groupPro" }, new Type[] { StringType.INSTANCE })) .add(Projections.sqlProjection("SUM(paid_amt) AS lSum", new String[] { "lSum" }, new Type[] { DoubleType.INSTANCE }))); c.addOrder(Order.asc("paymentDate")); c.setResultTransformer(Transformers.aliasToBean(LoanPayment.class)); List<LoanPayment> list = (List<LoanPayment>) c.list(); for (LoanPayment lp : list) { map.put(lp.getGroupPro(), lp.getlSum()); } s.close(); return map; }