Example usage for org.hibernate SQLQuery uniqueResult

List of usage examples for org.hibernate SQLQuery uniqueResult

Introduction

In this page you can find the example usage for org.hibernate SQLQuery uniqueResult.

Prototype

R uniqueResult();

Source Link

Document

Convenience method to return a single instance that matches the query, or null if the query returns no results.

Usage

From source file:com.gp.cong.logisoft.hibernate.dao.lcl.LclBookingHotCodeDAO.java

public boolean isHotCodeExistForThreeDigit(String fileId, String type, String Code) throws Exception { // type is not but exists method will affected
    SQLQuery query = getCurrentSession()
            .createSQLQuery("select if(count(*)<1,true,false) as result from lcl_booking_hot_code "
                    + " where SUBSTRING_INDEX(code,'/',1)=:code and file_number_id=:fileId");
    query.setParameter("fileId", fileId);
    query.setParameter("code", Code);
    query.addScalar("result", BooleanType.INSTANCE);
    return (Boolean) query.uniqueResult();
}

From source file:com.gp.cong.logisoft.hibernate.dao.lcl.LclBookingHotCodeDAO.java

public boolean isHotCodeValidate(Long fileId, String code) throws Exception { // type is not but exists method will affected
    SQLQuery query = getCurrentSession()
            .createSQLQuery("select if(count(*)>0,true,false) as result from lcl_booking_hot_code "
                    + " where SUBSTRING_INDEX(code,'/',1)=:code and file_number_id=:fileId");
    query.setParameter("fileId", fileId);
    query.setParameter("code", code);
    query.addScalar("result", BooleanType.INSTANCE);
    return (Boolean) query.uniqueResult();
}

From source file:com.gp.cong.logisoft.hibernate.dao.lcl.LclBookingHotCodeDAO.java

public Boolean isHazmatHotCodeExist(String fileId) throws Exception {
    StringBuilder queryStr = new StringBuilder();
    queryStr.append("SELECT if((SELECT hazrds FROM ").append(dataBaseName).append(
            ".ldgins WHERE loadcd = SUBSTRING_INDEX(lp.code,'/',1))='y',true,false)  as result  FROM lcl_booking_hot_code lp JOIN genericcode_dup gd ");
    queryStr.append("ON gd.code = SUBSTRING_INDEX(lp.code,'/',1) and ");
    queryStr.append("gd.Codetypeid= (SELECT codetypeid FROM codetype WHERE description='Hot Codes') ");
    queryStr.append("AND gd.Field1='Y' WHERE lp.file_number_id =:fileId limit 1");
    SQLQuery query = getCurrentSession().createSQLQuery(queryStr.toString());
    query.setParameter("fileId", fileId);
    query.addScalar("result", BooleanType.INSTANCE);
    return (Boolean) (query.uniqueResult() != null ? query.uniqueResult() : Boolean.FALSE);
}

From source file:com.gp.cong.logisoft.hibernate.dao.lcl.LclBookingHotCodeDAO.java

public boolean qtHazmatCodeExit(String fileId) throws Exception {
    StringBuilder sb = new StringBuilder();
    sb.append("SELECT ");
    sb.append("  IF(");
    sb.append("    (SELECT ");
    sb.append("      hazrds ");
    sb.append("    FROM ");
    sb.append(dataBaseName).append(".ldgins");
    sb.append("    WHERE loadcd = SUBSTRING_INDEX(lq.code, '/', 1)) = 'y',");
    sb.append("    TRUE,");
    sb.append("    FALSE");
    sb.append("  ) AS hazStatus ");
    sb.append(" FROM");
    sb.append("  lcl_quote_hot_code lq ");
    sb.append("  JOIN genericcode_dup gd ");
    sb.append("    ON gd.code = SUBSTRING_INDEX(lq.code, '/', 1) ");
    sb.append("    AND gd.Codetypeid = ");
    sb.append("    (SELECT ");
    sb.append("      codetypeid ");
    sb.append("    FROM");
    sb.append("      codetype ");
    sb.append("    WHERE description = 'Hot Codes') ");
    sb.append("    AND gd.Field1 = 'Y' ");
    sb.append(" WHERE lq.file_number_id = :fileId");
    SQLQuery queryObject = getCurrentSession().createSQLQuery(sb.toString());
    queryObject.setParameter("fileId", fileId);
    queryObject.addScalar("hazStatus", BooleanType.INSTANCE);
    return (Boolean) (queryObject.uniqueResult() != null ? queryObject.uniqueResult() : Boolean.FALSE);
}

From source file:com.gp.cong.logisoft.hibernate.dao.lcl.LclQuoteHotCodeDAO.java

public boolean isHotCodeExist(String Code, String fileId) throws Exception {
    SQLQuery query = getCurrentSession()
            .createSQLQuery("select if(count(*)<1,true,false) as result from lcl_quote_hot_code "
                    + " where code=:code and file_number_id=:fileId");
    query.setParameter("fileId", fileId);
    query.setParameter("code", Code);
    query.addScalar("result", BooleanType.INSTANCE);
    return (Boolean) query.uniqueResult();
}

From source file:com.hrms.manager.QuarterManager.java

public int count(Quarterdto emp) throws SQLException {
    int count = 0;
    int empId = emp.getEmpId();
    List list = null;//  w  w  w . ja v a  2s.  c  o m
    Session s = HibernateUtil.getSessionFactory().openSession();
    try {
        String sql = "select count(d.dep_name) from dependents_information d where d.family_head_id=:empId";
        SQLQuery query = s.createSQLQuery(sql);
        query.setParameter("empId", empId);
        BigInteger count1 = (BigInteger) query.uniqueResult();
        count = count1.intValue();
        //            Criteria c=s.createCriteria(DependentsInformation.class);
        //          
        //            c.add(Restrictions.eq("familyIdentity.employeeProfile",empId)).uniqueResult();  
        //             c.setProjection(Projections.rowCount());
        //             BigInteger count1= (BigInteger)c.uniqueResult(); 
        //             count=count1.intValue();
        //             list=c.list();
        //             System.out.println("list is"+list);
        //List l=query.list();
    } catch (HibernateException h) {
        System.out.println("HibernateException during Edit:" + h);
    }
    //   System.out.println(count);
    return count;
}

From source file:com.hrms.manager.QuarterManager.java

public int count1(Quarterdto emp) throws SQLException {
    int count = 0;
    int empId = emp.getEmpId();
    Session s = HibernateUtil.getSessionFactory().openSession();
    try {/*from   w w  w  .j  ava  2 s .c o m*/
        String sql = "select count(d.dep_name) from dependents_information d where d.family_head_id=:empId and dep_status='yes'";
        SQLQuery query = s.createSQLQuery(sql);
        query.setParameter("empId", empId);
        BigInteger count1 = (BigInteger) query.uniqueResult();
        count = count1.intValue();
        //List l=query.list();
    } catch (HibernateException h) {
        System.out.println("HibernateException during Edit:" + h);
    }
    //  System.out.println(count);
    return count;
}

From source file:com.ignou.aadhar.dao.hibernate.GenericDaoHibernate.java

License:Open Source License

/**
 * Fetches the Enum values for the provided column in the specified table.
 * @param tableName Table name in the database
 * @param columnName Column in the table.
 * @return Returns the ENUM values specified for the column in the table. It
 * does not format the ENUM values and they are available in the following
 * format.<br/>//  www.  j ava  2 s .  c  o m
 * <code>('ENUMVAL1','ENUMVAL2')</code>
 */
@Override
public Map<String, String> getEnum(String tableName, String columnName) {

    /* Generalized query for fetching the ENUM data for the column in the
     * required table specified.
     */
    String strSqlQuery = "SELECT SUBSTRING(COLUMN_TYPE,5) EnumData " + "FROM INFORMATION_SCHEMA.COLUMNS "
            + "WHERE TABLE_SCHEMA = 'aadhar' " + "AND TABLE_NAME = '" + tableName + "' " + "AND COLUMN_NAME = '"
            + columnName + "';";

    /* Get the Hibernate Session instance to perform db operation */
    Session session = getSessionFactory().getCurrentSession();
    SQLQuery sqlQuery = session.createSQLQuery(strSqlQuery).addScalar("EnumData", Hibernate.STRING);

    /* Execute the query and fetch the enum data as string */
    String enumData = (String) sqlQuery.uniqueResult();

    /* Remove the surrounding braces and quotes and return back */
    enumData = enumData.replaceAll("['()]", "");

    /* Lets split the enum data csv and make a map.
     * For example, for ENUM data - ACTIVE,PENDING, the corresponding map
     * would be { "ACTIVE" : "Active", "PENDING" : "Pending" }
     */
    List<String> enums = Arrays.asList(enumData.split(","));
    Map<String, String> enumMap = new HashMap<String, String>();

    /* The the enum values in the Map now */
    for (String enumEl : enums) {
        String enumElTitleCase = enumEl.charAt(0) + enumEl.substring(1).toLowerCase();
        enumMap.put(enumEl, enumElTitleCase.replaceAll("[^A-Za-z]", " "));
    }

    return enumMap;
}

From source file:com.iluwatar.cqrs.queries.QueryServiceImpl.java

License:Open Source License

@Override
public BigInteger getAuthorBooksCount(String username) {
    BigInteger bookcount = null;/*from   w ww .  j  a  va 2 s  . co  m*/
    try (Session session = sessionFactory.openSession()) {
        SQLQuery sqlQuery = session.createSQLQuery("SELECT count(b.title)"
                + " FROM  Book b, Author a where b.author_id = a.id and a.username=:username");
        sqlQuery.setParameter("username", username);
        bookcount = (BigInteger) sqlQuery.uniqueResult();
    }
    return bookcount;
}

From source file:com.iluwatar.cqrs.queries.QueryServiceImpl.java

License:Open Source License

@Override
public BigInteger getAuthorsCount() {
    BigInteger authorcount = null;
    try (Session session = sessionFactory.openSession()) {
        SQLQuery sqlQuery = session.createSQLQuery("SELECT count(id) from Author");
        authorcount = (BigInteger) sqlQuery.uniqueResult();
    }/*from www.  ja  va 2s .c om*/
    return authorcount;
}