Example usage for org.hibernate Query setText

List of usage examples for org.hibernate Query setText

Introduction

In this page you can find the example usage for org.hibernate Query setText.

Prototype

@Deprecated
@SuppressWarnings("unchecked")
default Query<R> setText(String name, String val) 

Source Link

Document

Bind a named String-valued parameter using streaming.

Usage

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  2s. c  om*/
    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.sos.scheduler.db.SchedulerInstancesDBLayer.java

License:Apache License

public int delete() {

    if (session == null) {
        beginTransaction();//from  w  w  w. jav a 2  s . co m
    }

    String hql = "delete from SchedulerInstancesDBItem " + getWhere();

    Query query = session.createQuery(hql);

    if (filter.getHostname() != null && !filter.getHostname().equals("")) {
        query.setText("hostName", filter.getHostname());
    }

    if (filter.getDbName() != null && !filter.getDbName().equals("")) {
        query.setText("dbName", filter.getDbName());
    }

    if (filter.getSchedulerId() != null && !filter.getSchedulerId().equals("")) {
        query.setText("schedulerId", filter.getSchedulerId());
    }

    if (filter.getPort() > 0) {
        query.setInteger("tcpPort", filter.getPort());
    }

    int row = query.executeUpdate();
    return row;
}

From source file:com.sos.scheduler.db.SchedulerInstancesDBLayer.java

License:Apache License

public List<SchedulerInstancesDBItem> getSchedulerInstancesList() {
    initSession();/*from   w ww .j a va 2 s  . c om*/

    Query query = session.createQuery("from SchedulerInstancesDBItem " + getWhere()
            + this.filter.getOrderCriteria() + this.filter.getSortMode());

    if (filter.getHostname() != null && !filter.getHostname().equals("")) {
        query.setText("hostName", filter.getHostname());
    }

    if (filter.getDbName() != null && !filter.getDbName().equals("")) {
        query.setText("dbName", filter.getDbName());
    }

    if (filter.getSchedulerId() != null && !filter.getSchedulerId().equals("")) {
        query.setText("schedulerId", filter.getSchedulerId());
    }

    if (filter.getPort() != null && filter.getPort() > 0) {
        query.setInteger("tcpPort", filter.getPort());
    }

    if (this.getFilter().getLimit() > 0) {
        query.setMaxResults(this.getFilter().getLimit());
    }

    List<SchedulerInstancesDBItem> schedulerInstancesList = query.list();
    return schedulerInstancesList;

}

From source file:com.sos.scheduler.history.db.SchedulerOrderHistoryDBLayer.java

License:Apache License

private List<SchedulerOrderHistoryDBItem> executeQuery(Query query, int limit) {

    if (filter.getExecutedUtcFrom() != null && !filter.getExecutedUtcFrom().equals("")) {
        query.setTimestamp("startTimeFrom", filter.getExecutedUtcFrom());
    }/*from  w ww  . j a v a2 s .  com*/
    if (filter.getExecutedUtcTo() != null && !filter.getExecutedUtcTo().equals("")) {
        query.setTimestamp("startTimeTo", filter.getExecutedUtcTo());
    }

    if (filter.getOrderid() != null && !filter.getOrderid().equals("")) {
        query.setText("orderId", filter.getOrderid());
    }
    if (filter.getJobchain() != null && !filter.getJobchain().equals("")) {
        query.setText("jobChain", filter.getJobchain());
    }
    if (filter.getSchedulerId() != null && !filter.getSchedulerId().equals("")) {
        query.setText("schedulerId", filter.getSchedulerId());
    }

    if (limit > 0) {
        query.setMaxResults(limit);
    }

    List<SchedulerOrderHistoryDBItem> schedulerOrderHistoryList = query.list();
    return schedulerOrderHistoryList;

}

From source file:com.sos.scheduler.history.db.SchedulerOrderHistoryDBLayer.java

License:Apache License

public List<SchedulerOrderHistoryDBItem> getOrderHistoryItems() {
    initSession();/*from  w w w  . ja  v a 2 s. c om*/

    Query query = session.createQuery("from SchedulerOrderHistoryDBItem " + getWhere());

    if (filter.getStartTime() != null && !filter.getStartTime().equals("")) {
        query.setTimestamp("startTime", filter.getStartTime());
    }
    if (filter.getEndTime() != null && !filter.getEndTime().equals("")) {
        query.setTimestamp("endTime", filter.getEndTime());
    }
    if (filter.getOrderid() != null && !filter.getOrderid().equals("")) {
        query.setText("orderId", filter.getOrderid());
    }
    if (filter.getJobchain() != null && !filter.getJobchain().equals("")) {
        query.setText("jobChain", filter.getJobchain());
    }
    if (filter.getSchedulerId() != null && !filter.getSchedulerId().equals("")) {
        query.setText("schedulerId", filter.getSchedulerId());
    }

    query.setMaxResults(filter.getLimit());

    List<SchedulerOrderHistoryDBItem> historyList = query.list();
    return historyList;
}

From source file:com.sos.scheduler.history.db.SchedulerOrderHistoryDBLayer.java

License:Apache License

public SchedulerOrderHistoryDBItem getOrderHistoryItem() {
    initSession();//from  w  w w  .j a v  a2 s .com
    this.filter.setLimit(1);

    Query query = session.createQuery("from SchedulerOrderHistoryDBItem " + getWhere());

    if (filter.getSchedulerOrderHistoryId() != null) {
        query.setLong("schedulerOrderHistoryId", filter.getSchedulerOrderHistoryId());
    } else {

        if (filter.getStartTime() != null && !filter.getStartTime().equals("")) {
            query.setTimestamp("startTime", filter.getStartTime());
        }
        if (filter.getEndTime() != null && !filter.getEndTime().equals("")) {
            query.setTimestamp("endTime", filter.getEndTime());
        }
        if (filter.getOrderid() != null && !filter.getOrderid().equals("")) {
            query.setText("orderId", filter.getOrderid());
        }
        if (filter.getJobchain() != null && !filter.getJobchain().equals("")) {
            query.setText("jobChain", filter.getJobchain());
        }
        if (filter.getSchedulerId() != null && !filter.getSchedulerId().equals("")) {
            query.setText("schedulerId", filter.getSchedulerId());
        }
    }
    query.setMaxResults(filter.getLimit());

    List<SchedulerOrderHistoryDBItem> historyList = query.list();
    if (historyList.size() > 0) {
        return historyList.get(0);

    } else {
        return null;
    }
}

From source file:com.sos.scheduler.history.db.SchedulerTaskHistoryDBLayer.java

License:Apache License

public int delete() {

    if (session == null) {
        beginTransaction();/* w w  w  . ja va2s. com*/
    }

    String hql = "delete from SchedulerTaskHistoryDBItem " + getWhereFromTo();

    Query query = session.createQuery(hql);

    if (filter.getSchedulerId() != null && filter.getSchedulerId() != "") {
        query.setText("schedulerId", filter.getSchedulerId());
    }

    if (filter.getSeverity() != null) {
        query.setInteger("severity", filter.getSeverity().getIntValue());
    }

    if (filter.getJobname() != null && filter.getJobname() != "") {
        query.setText("jobName", filter.getJobname());
    }

    if (filter.getExecutedUtcFrom() != null) {
        query.setTimestamp("startTimeFrom", filter.getExecutedUtcFrom());
    }

    if (filter.getExecutedUtcTo() != null) {
        query.setTimestamp("startTimeTo", filter.getExecutedUtcTo());
    }

    int row = query.executeUpdate();

    return row;
}

From source file:com.sos.scheduler.history.db.SchedulerTaskHistoryDBLayer.java

License:Apache License

private List<SchedulerTaskHistoryDBItem> executeQuery(Query query, int limit) {
    if (filter.getSchedulerId() != null && !filter.getSchedulerId().equals("")) {
        query.setText("schedulerId", filter.getSchedulerId());
    }//from   w w w  . j  a va2  s  .c om

    if (filter.getSeverity() != null) {
        query.setInteger("severity", filter.getSeverity().getIntValue());
    }

    if (filter.getJobname() != null && !filter.getJobname().equals("")) {
        query.setText("jobName", filter.getJobname());
    }

    if (filter.getExecutedUtcFrom() != null) {
        query.setTimestamp("startTimeFrom", filter.getExecutedUtcFrom());
    }
    if (filter.getExecutedUtcTo() != null) {
        query.setTimestamp("startTimeTo", filter.getExecutedUtcTo());
    }

    if (limit > 0) {
        query.setMaxResults(limit);
    }

    List<SchedulerTaskHistoryDBItem> schedulerHistoryList = query.list();
    return schedulerHistoryList;
}

From source file:com.sos.scheduler.history.db.SchedulerTaskHistoryDBLayer.java

License:Apache License

public List<SchedulerTaskHistoryDBItem> getHistoryItems() {
    int limit = this.getFilter().getLimit();
    initSession();/*from ww  w  .  ja  v a 2s  . c om*/

    Query query = session.createQuery("from SchedulerTaskHistoryDBItem " + getWhere()
            + this.filter.getOrderCriteria() + this.filter.getSortMode());

    if (filter.getSchedulerId() != null && filter.getSchedulerId() != "") {
        query.setText("schedulerId", filter.getSchedulerId());
    }

    if (filter.getSeverity() != null) {
        query.setInteger("severity", filter.getSeverity().getIntValue());
    }

    if (filter.getJobname() != null && filter.getJobname() != "") {
        query.setText("jobName", filter.getJobname());
    }

    if (filter.getStartTime() != null) {
        query.setTimestamp("startTime", filter.getStartTime());
    }
    if (filter.getEndTime() != null && !filter.getEndTime().equals("")) {
        query.setTimestamp("endTime", filter.getEndTime());
    }

    if (limit > 0) {
        query.setMaxResults(limit);
    }

    List<SchedulerTaskHistoryDBItem> historyList = query.list();
    return historyList;

}

From source file:com.sos.scheduler.history.db.SchedulerTaskHistoryDBLayer.java

License:Apache License

public SchedulerTaskHistoryDBItem getHistoryItem() {
    this.filter.setLimit(1);
    initSession();//from w ww  . ja  va  2 s .  com

    Query query = session.createQuery("from SchedulerTaskHistoryDBItem " + getWhere()
            + this.filter.getOrderCriteria() + this.filter.getSortMode());

    if (filter.getSchedulerId() != null && filter.getSchedulerId() != "") {
        query.setText("schedulerId", filter.getSchedulerId());
    }

    if (filter.getSeverity() != null) {
        query.setInteger("severity", filter.getSeverity().getIntValue());
    }

    if (filter.getJobname() != null && filter.getJobname() != "") {
        query.setText("jobName", filter.getJobname());
    }

    if (filter.getStartTime() != null) {
        query.setTimestamp("startTime", filter.getStartTime());
    }
    if (filter.getEndTime() != null && !filter.getEndTime().equals("")) {
        query.setTimestamp("endTime", filter.getEndTime());
    }

    if (this.filter.getLimit() > 0) {
        query.setMaxResults(this.filter.getLimit());
    }

    List<SchedulerTaskHistoryDBItem> historyList = query.list();
    if (historyList.size() > 0) {
        return historyList.get(0);
    } else {
        return null;
    }

}