Example usage for org.hibernate.type StandardBasicTypes INTEGER

List of usage examples for org.hibernate.type StandardBasicTypes INTEGER

Introduction

In this page you can find the example usage for org.hibernate.type StandardBasicTypes INTEGER.

Prototype

IntegerType INTEGER

To view the source code for org.hibernate.type StandardBasicTypes INTEGER.

Click Source Link

Document

The standard Hibernate type for mapping Integer to JDBC java.sql.Types#INTEGER INTEGER .

Usage

From source file:com.agroservices.hibernate.Dialect.java

public Dialect() {
    super();//from   w  w w  .  j  a v  a2  s .c  o  m
    registerFunction("date_add_interval",
            new SQLFunctionTemplate(StandardBasicTypes.DATE, "DATE_ADD(?1, INTERVAL ?2 ?3)"));
    registerFunction("date_diff", new SQLFunctionTemplate(StandardBasicTypes.INTEGER, "DATEDIFF(?1, ?2)"));
    registerFunction("cast_new", new SQLFunctionTemplate(StandardBasicTypes.FLOAT, "CAST(?1 as DECIMAL)"));
}

From source file:com.basic.dao.EnterpriseDao.java

/**?
 * @param keyword ???????//from  w w  w . ja v a 2 s . c o  m
 * @param offset
 * @param limit
 * @return ?ID??logo????????????
 * */
public BootTablePageDto<Enterprise> search(Long province, Long city, Long county, Long town,
        Integer[] costumeCodes, String processType, Integer staffNumber, String keyword, int offset, int limit,
        Long total) {
    StringBuffer countSql = new StringBuffer("select count(1)");
    StringBuffer subSql = new StringBuffer(
            " from basic_enterprise where (enterprise_name like :keyword or description like :keyword) ");
    List<String> params = new ArrayList<String>();
    List<Object> values = new ArrayList<Object>();
    //???????
    params.add("keyword");
    values.add("%" + keyword + "%");

    //?
    if (province != null) {
        subSql.append(" and province =:province");
        params.add("province");
        values.add(province);
    }
    if (city != null) {
        subSql.append(" and city =:city");
        params.add("city");
        values.add(city);
    }
    if (county != null) {
        subSql.append(" and county =:county");
        params.add("county");
        values.add(county);
    }
    if (town != null) {
        subSql.append(" and town =:town");
        params.add("town");
        values.add(town);
    }
    //
    if (processType != null) {
        subSql.append(" and process_type like :processType");
        params.add("processType");
        values.add("%" + processType + "%");
    }
    //?
    if (costumeCodes != null && costumeCodes.length > 0) {
        subSql.append(
                " and id in (select distinct enterprise_id from basic_enterprise_costume_rela where costume_code in (:costumeCodes))");
        params.add("costumeCodes");
        values.add(costumeCodes);
    }
    //?
    if (staffNumber != null) {
        switch (staffNumber) {
        case 1:
            subSql.append(" and staff_number < 50");
            break;
        case 2:
            subSql.append(" and staff_number between 50 and 100");
            break;
        case 3:
            subSql.append(" and staff_number between 101 and 200");
            break;
        case 4:
            subSql.append(" and staff_number between 201 and 500");
            break;
        case 5:
            subSql.append(" and staff_number between 501 and 1000");
            break;
        case 6:
            subSql.append(" and staff_number > 1000");
            break;
        }
    }
    //total??total
    if (total == null) {
        countSql.append(subSql);
        BigInteger bigInt = (BigInteger) super.findByNativeSql(countSql.toString(), params, values).get(0);
        total = bigInt.longValue();
    }

    StringBuffer sql = new StringBuffer(
            "select id, enterprise_name as enterpriseName, process_type as processType, staff_number as staffNumber, left(description,150) as description, province, city, county, town, logo");
    sql.append(subSql);
    List<Object[]> scalars = new ArrayList<Object[]>();
    scalars.add(new Object[] { "id", StandardBasicTypes.INTEGER });
    scalars.add(new Object[] { "enterpriseName", StandardBasicTypes.STRING });
    scalars.add(new Object[] { "processType", StandardBasicTypes.STRING });
    scalars.add(new Object[] { "staffNumber", StandardBasicTypes.INTEGER });
    scalars.add(new Object[] { "description", StandardBasicTypes.STRING });
    scalars.add(new Object[] { "province", StandardBasicTypes.LONG });
    scalars.add(new Object[] { "city", StandardBasicTypes.LONG });
    scalars.add(new Object[] { "county", StandardBasicTypes.LONG });
    scalars.add(new Object[] { "town", StandardBasicTypes.LONG });
    scalars.add(new Object[] { "logo", StandardBasicTypes.STRING });
    List<Enterprise> enterprises = super.findByNativeSql(sql.toString(), params, values, scalars, offset,
            limit);
    return new BootTablePageDto<Enterprise>(total, enterprises);
}

From source file:com.consult.app.dao.impl.CargoMessageDaoImpl.java

/**
 * Common Search cargo, used by 274 Version!
 * This supports multiple truck length/*w  ww  . j a  va 2 s .  com*/
 * 
 */
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 ww .j ava  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//w ww  .  java 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;
        }
    }
    //      }
}

From source file:com.consult.app.dao.impl.CargoMessageDaoImpl.java

@Override
public List<Object> getTodaySuspiciousCargoer() {
    Session session = null;/*  www .  j ava 2s  .  c  o 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) {
    /**//from   w ww. j  ava2  s  .  c o  m
     * 
     */
    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;/*from  w  w w .  j ava  2s  . 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;/*from  ww w  .  j ava 2 s  .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.enigmabridge.hibernate.dialect.SQLiteDialect.java

License:unlicense.org

public SQLiteDialect() {
    registerColumnType(Types.BIT, "boolean");
    registerColumnType(Types.TINYINT, "tinyint");
    registerColumnType(Types.SMALLINT, "smallint");
    registerColumnType(Types.INTEGER, "integer");
    registerColumnType(Types.BIGINT, "bigint");
    registerColumnType(Types.FLOAT, "float");
    registerColumnType(Types.REAL, "real");
    registerColumnType(Types.DOUBLE, "double");
    registerColumnType(Types.NUMERIC, "numeric($p, $s)");
    registerColumnType(Types.DECIMAL, "decimal");
    registerColumnType(Types.CHAR, "char");
    registerColumnType(Types.VARCHAR, "varchar($l)");
    registerColumnType(Types.LONGVARCHAR, "longvarchar");
    registerColumnType(Types.DATE, "date");
    registerColumnType(Types.TIME, "time");
    registerColumnType(Types.TIMESTAMP, "datetime");
    registerColumnType(Types.BINARY, "blob");
    registerColumnType(Types.VARBINARY, "blob");
    registerColumnType(Types.LONGVARBINARY, "blob");
    registerColumnType(Types.BLOB, "blob");
    registerColumnType(Types.CLOB, "clob");
    registerColumnType(Types.BOOLEAN, "boolean");

    registerFunction("concat", new VarArgsSQLFunction(StandardBasicTypes.STRING, "", "||", ""));
    registerFunction("mod", new SQLFunctionTemplate(StandardBasicTypes.INTEGER, "?1 % ?2"));
    registerFunction("quote", new StandardSQLFunction("quote", StandardBasicTypes.STRING));
    registerFunction("random", new NoArgSQLFunction("random", StandardBasicTypes.INTEGER));
    registerFunction("round", new StandardSQLFunction("round"));
    registerFunction("substr", new StandardSQLFunction("substr", StandardBasicTypes.STRING));
    registerFunction("trim", new AbstractAnsiTrimEmulationFunction() {
        protected SQLFunction resolveBothSpaceTrimFunction() {
            return new SQLFunctionTemplate(StandardBasicTypes.STRING, "trim(?1)");
        }// w ww.j a  va 2s.  co m

        protected SQLFunction resolveBothSpaceTrimFromFunction() {
            return new SQLFunctionTemplate(StandardBasicTypes.STRING, "trim(?2)");
        }

        protected SQLFunction resolveLeadingSpaceTrimFunction() {
            return new SQLFunctionTemplate(StandardBasicTypes.STRING, "ltrim(?1)");
        }

        protected SQLFunction resolveTrailingSpaceTrimFunction() {
            return new SQLFunctionTemplate(StandardBasicTypes.STRING, "rtrim(?1)");
        }

        protected SQLFunction resolveBothTrimFunction() {
            return new SQLFunctionTemplate(StandardBasicTypes.STRING, "trim(?1, ?2)");
        }

        protected SQLFunction resolveLeadingTrimFunction() {
            return new SQLFunctionTemplate(StandardBasicTypes.STRING, "ltrim(?1, ?2)");
        }

        protected SQLFunction resolveTrailingTrimFunction() {
            return new SQLFunctionTemplate(StandardBasicTypes.STRING, "rtrim(?1, ?2)");
        }
    });
    uniqueDelegate = new SQLiteUniqueDelegate(this);
}