Java Code Examples for org.hibernate.Query.setTimestamp()

The following are Jave code examples for showing how to use setTimestamp() of the org.hibernate.Query class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: sjk   File: AppHistory4IndexDaoImpl.java   View Source Code Vote up 11 votes
/**
 * 更新 状态到数据库,仅针对 appStatus 为 1(add) 2(update) 更新索引 ,
 */
@Override
public int updateAppHistory4indeToIndexed(List<Integer> appIds) {
    String hql = "update AppHistory4Index set indexStatus=1,lastIndexTime=:lastIndexTime where (appStatus=1 or appStatus=2) and appId in (:appIds)";

    Session session = null;
    try {
        session = this.sessions.openSession();
        Query query = session.createQuery(hql);
        query.setParameterList("appIds", appIds);
        query.setTimestamp("lastIndexTime", new Date());

        return query.executeUpdate();
    } catch (Exception e) {
        logger.error("error:", e);
        return 0;
    } finally {
        if (session != null && session.isOpen()) {
            session.flush();
            session.clear();
            session.close();
        }
    }

}
 
Example 2
Project: ImageClassify   File: MarkService.java   View Source Code Vote up 6 votes
@Override
public boolean updateMarkAll(Mark mark) {
	 Session session = HibernateUtils.getSession();
	 Transaction tx = session.beginTransaction();
	 boolean b = false;
	 try {
		Query query = session.createQuery("update Mark m set m.mark_accuracy =?,m.mark_time =?,m.option_mark_name =?,"
				+ "m.manual_mark_name=? where m.user_id = ? and m.img_id = ?");  
	    query.setString(0, mark.getMark_accuracy());
	    query.setTimestamp(1, mark.getMark_time());
	    query.setString(2,mark.getOption_mark_name());
	    query.setString(3, mark.getManual_mark_name()); 
	    query.setInteger(4, mark.getUser_id());
	    query.setInteger(5, mark.getImg_id()); 
		query.executeUpdate();  
		tx.commit();
		b = true;
	} catch (Exception e) {
		 e.printStackTrace();
		 tx.rollback(); 
	}finally {
		HibernateUtils.closeSession();
	} 
	 return b;
}
 
Example 3
Project: sjk   File: AppHistory4IndexDaoImpl.java   View Source Code Vote up 6 votes
@Override
public int delAppHistory4index(List<Integer> appIds) {

    // String hql =
    // "delete  AppHistory4Index  where appStatus=3 and indexStatus=-1 and appId in (:appIds)";
    // 删除前一天生成索引的数据,避免数据过多
    String hql = "delete  AppHistory4Index  where (indexStatus=-1 and appId in (:appIds) ) or lastIndexTime<:lastIndexTime";
    Session session = null;
    try {
        session = this.sessions.openSession();
        Query query = session.createQuery(hql);
        query.setParameterList("appIds", appIds);
        query.setTimestamp("lastIndexTime", DateUtils.addDays(new Date(), -1));// 删除前一天索引后的数据

        return query.executeUpdate();
    } catch (Exception e) {
        logger.error("error:", e);
        return 0;
    } finally {
        if (session != null && session.isOpen()) {
            session.flush();
            session.clear();
            session.close();
        }
    }

}
 
Example 4
Project: sjk   File: AppHistory4IndexDaoImpl.java   View Source Code Vote up 6 votes
/**
 * 设置appStatus 状态 为可删除 状态 3,索引状态 indexStatus为 -1
 */
@Override
public int updateAppStatus2Del(List<Integer> ids) {
    Session session = null;

    try {
        session = this.sessions.openSession();

        String hql = "update AppHistory4Index set appStatus=3,indexStatus=-1,lastOpTime=:lastOpTime where appId in (:appIds)";
        Query query = session.createQuery(hql);
        query.setParameterList("appIds", ids);
        query.setTimestamp("lastOpTime", new Date());

        return query.executeUpdate();

    } catch (Exception e) {
        logger.error("error:", e);
        return 0;
    } finally {
        if (session != null && session.isOpen()) {
            session.flush();
            session.clear();
            session.close();
        }
    }

}
 
Example 5
Project: sjk   File: AppHistory4IndexDaoImpl.java   View Source Code Vote up 6 votes
@Override
public int updateAppStatus2Del(Integer id) {
    Session session = null;

    try {
        session = this.sessions.openSession();
        //
        String hql = "update AppHistory4Index set appStatus=3,indexStatus=-1,lastOpTime=:lastOpTime where appId =:appId";
        Query query = session.createQuery(hql);
        query.setInteger("appId", id);
        query.setTimestamp("lastOpTime", new Date());

        return query.executeUpdate();

    } catch (Exception e) {
        logger.error("error:", e);
        return 0;
    } finally {
        if (session != null && session.isOpen()) {
            session.flush();
            session.clear();
            session.close();
        }
    }
}
 
Example 6
Project: sjk   File: AppHistory4IndexDaoImpl.java   View Source Code Vote up 6 votes
@Override
public int update(List<Integer> ids) {
    Session session = null;
    try {
        session = this.sessions.openSession();
        // 设置状态 为更新
        // 需要重新索引
        String hql = "update AppHistory4Index set appStatus=2,indexStatus=0,lastOpTime=:lastOpTime where appId in (:appIds)";
        Query query = session.createQuery(hql);
        query.setParameterList("appIds", ids);
        query.setTimestamp("lastOpTime", new Date());

        return query.executeUpdate();

    } catch (Exception e) {
        logger.error("error:", e);
        return 0;
    } finally {
        if (session != null && session.isOpen()) {
            session.flush();
            session.clear();
            session.close();
        }
    }
}
 
Example 7
Project: Restaurant   File: OrderDaoImpl.java   View Source Code Vote up 5 votes
public List<Order> showOrdersForToday() {
	
	String sql = "from Order where date>=:startDate and date<=:endDate";
	Date date = new Date(new Date().getTime()-24*3600*1000);
	Session session = sessionFactory.openSession();
	Query query = session.createQuery(sql);
	query.setTimestamp("startDate", new Timestamp(date.getTime()));
	query.setTimestamp("endDate", new Timestamp(System.currentTimeMillis()));
	List<Order> orders = query.list();
	session.close();
	return orders;
	
}
 
Example 8
Project: SandBoxNGSB   File: QuoteDAOImpl.java   View Source Code Vote up 5 votes
@Override
public QuotePE getFromDate(Date dateStartStep, Date dateEndStep){
	Session session = getSession();
	String requete = "FROM QuotePE "
			+ "WHERE creationDateTime <= :dateMin "
			+ "AND creationDateTime > :dateMax "
			+ "ORDER BY creationDateTime ASC ";
	
	Query query = session.createQuery(requete);
	
	query.setTimestamp("dateMin", dateStartStep);
	query.setTimestamp("dateMax", dateEndStep);
	query.setFirstResult(0);
	query.setMaxResults(1);
	query.uniqueResult();
	
	List<QuotePE> lpe = (List<QuotePE>) query.list();
	

	session.close();
	
	if(lpe.isEmpty())
		return null;
	else 
		return lpe.get(0);
	
	
}
 
Example 9
Project: sjk   File: AppHistory4IndexDaoImpl.java   View Source Code Vote up 5 votes
/**
 * 设置appStatus 状态 为可删除 状态 3,索引状态 indexStatus为 -1
 */
@Override
public int updateAppStatus2Del(List<Integer> ids) {
    String hql = "update AppHistory4Index set appStatus=3,indexStatus=-1,lastOpTime=:lastOpTime where appId in (:appIds)";
    Query query = this.getSession().createQuery(hql);
    query.setParameterList("appIds", ids);
    query.setTimestamp("lastOpTime", new Date());

    return query.executeUpdate();

}
 
Example 10
Project: ctsms   File: QueryParameterValue.java   View Source Code Vote up 4 votes
public void set(Query query, int pos, HashMap<NamedParameterValues, Object> namedParameterValuesCache) throws Exception {
	switch (type) {
		case CRITERION_VALUE:
			QueryUtil.setQueryParameterFromCriterion(propertyName, query, valueType, pos, criterion);
			break;
		case FILTER_VALUE:
			QueryUtil.setQueryParameterFromString(query, propertyClass, pos, value);
			break;
		case STATIC_TERM_VALUE:
			QueryUtil.setQueryParameterFromCriterion(null, query, valueType, pos, criterion);
			break;
		case TODAY:
			query.setDate(pos, getCachedTime(namedParameterValuesCache));
			break;
		case NOW:
			query.setTimestamp(pos, CommonUtil.dateToTimestamp(getCachedTime(namedParameterValuesCache)));
			break;
		case TODAY_PLUS_VARIABLE_PERIOD:
			if (VariablePeriod.EXPLICIT.equals(period)) {
				throw new IllegalArgumentException(L10nUtil.getMessage(MessageCodes.NAMED_PARAMETER_EXPLICIT_VARIABLE_PERIOD,
						DefaultMessages.NAMED_PARAMETER_EXPLICIT_VARIABLE_PERIOD));
			}
			query.setDate(pos, DateCalc.addInterval(getCachedTime(namedParameterValuesCache), period, null));
			break;
		case TODAY_MINUS_VARIABLE_PERIOD:
			if (VariablePeriod.EXPLICIT.equals(period)) {
				throw new IllegalArgumentException(L10nUtil.getMessage(MessageCodes.NAMED_PARAMETER_EXPLICIT_VARIABLE_PERIOD,
						DefaultMessages.NAMED_PARAMETER_EXPLICIT_VARIABLE_PERIOD));
			}
			query.setDate(pos, DateCalc.subInterval(getCachedTime(namedParameterValuesCache), period, null));
			break;
		case NOW_PLUS_VARIABLE_PERIOD:
			if (VariablePeriod.EXPLICIT.equals(period)) {
				throw new IllegalArgumentException(L10nUtil.getMessage(MessageCodes.NAMED_PARAMETER_EXPLICIT_VARIABLE_PERIOD,
						DefaultMessages.NAMED_PARAMETER_EXPLICIT_VARIABLE_PERIOD));
			}
			query.setTimestamp(pos, CommonUtil.dateToTimestamp(DateCalc.addInterval(getCachedTime(namedParameterValuesCache), period, null)));
			break;
		case NOW_MINUS_VARIABLE_PERIOD:
			if (VariablePeriod.EXPLICIT.equals(period)) {
				throw new IllegalArgumentException(L10nUtil.getMessage(MessageCodes.NAMED_PARAMETER_EXPLICIT_VARIABLE_PERIOD,
						DefaultMessages.NAMED_PARAMETER_EXPLICIT_VARIABLE_PERIOD));
			}
			query.setTimestamp(pos, CommonUtil.dateToTimestamp(DateCalc.subInterval(getCachedTime(namedParameterValuesCache), period, null)));
			break;
		case CONTEXT_USER_ID:
			query.setBigInteger(pos, new BigInteger(getCachedUser(namedParameterValuesCache).getId().toString()));
			break;
		case CONTEXT_USER_DEPARTMENT_ID:
			query.setBigInteger(pos, new BigInteger(getCachedUserDepartment(namedParameterValuesCache).getId().toString()));
			break;
		case CONTEXT_IDENTITY_ID:
			query.setBigInteger(pos, new BigInteger(getCachedIdentity(namedParameterValuesCache).getId().toString()));
			break;
		case CONTEXT_IDENTITY_DEPARTMENT_ID:
			query.setBigInteger(pos, new BigInteger(getCachedIdentityDepartment(namedParameterValuesCache).getId().toString()));
			break;
		default:
	}
}
 
Example 11
Project: ctsms   File: QueryUtil.java   View Source Code Vote up 4 votes
public static void setQueryParameterFromCriterion(String propertyName, Query query, CriterionValueType valueType, int pos, CriterionInstantVO value) throws Exception {
	switch (valueType) {
		case BOOLEAN:
			query.setBoolean(pos, value.getBooleanValue());
			break;
		case BOOLEAN_HASH:
			query.setBinary(pos, CryptoUtil.hashForSearch(value.getBooleanValue()));
			break;
		case DATE:
			query.setDate(pos, value.getDateValue());
			break;
		case DATE_HASH:
			query.setBinary(pos, CryptoUtil.hashForSearch(value.getDateValue()));
			break;
		case TIME:
			query.setTime(pos, value.getTimeValue());
			break;
		case TIME_HASH:
			query.setBinary(pos, CryptoUtil.hashForSearch(value.getTimeValue()));
			break;
		case FLOAT:
			query.setFloat(pos, value.getFloatValue().floatValue());
			break;
		case FLOAT_HASH:
			query.setBinary(pos, CryptoUtil.hashForSearch(value.getFloatValue()));
			break;
		case LONG:
			query.setBigInteger(pos, new BigInteger(value.getLongValue().toString()));
			break;
		case LONG_HASH:
			query.setBinary(pos, CryptoUtil.hashForSearch(value.getLongValue()));
			break;
		case STRING:
			query.setString(pos, value.getStringValue());
			break;
		case STRING_HASH:
			query.setBinary(pos, CryptoUtil.hashForSearch(value.getStringValue()));
			break;
		case TIMESTAMP:
			query.setTimestamp(pos, value.getTimestampValue());
			break;
		case TIMESTAMP_HASH:
			query.setBinary(pos, CryptoUtil.hashForSearch(value.getTimestampValue()));
			break;
		case NONE:
			break;
		default:
			// datatype unimplemented
			throw new IllegalArgumentException(MessageFormat.format(CommonUtil.UNSUPPORTED_CRITERION_VALUE_TYPE, valueType.toString()));
	}
}
 
Example 12
Project: ctsms   File: QueryUtil.java   View Source Code Vote up 4 votes
public static void setQueryParameterFromString(Query query, Class propertyClass, int pos, String value) throws Exception {
	if (propertyClass.equals(String.class)) {
		query.setString(pos, value);
	} else if (propertyClass.equals(Long.class)) {
		query.setBigInteger(pos, new BigInteger(value));
	} else if (propertyClass.equals(java.lang.Long.TYPE)) {
		query.setBigInteger(pos, new BigInteger(value));
	} else if (propertyClass.equals(Integer.class)) {
		query.setInteger(pos, new Integer(value));
	} else if (propertyClass.equals(java.lang.Integer.TYPE)) {
		query.setInteger(pos, new Integer(value));
	} else if (propertyClass.equals(Boolean.class)) {
		query.setBoolean(pos, new Boolean(value));
	} else if (propertyClass.equals(java.lang.Boolean.TYPE)) {
		query.setBoolean(pos, new Boolean(value));
	} else if (propertyClass.equals(Float.class)) {
		query.setFloat(pos, new Float(value));
	} else if (propertyClass.equals(java.lang.Float.TYPE)) {
		query.setFloat(pos, new Float(value));
	} else if (propertyClass.equals(Double.class)) {
		query.setDouble(pos, new Double(value));
	} else if (propertyClass.equals(java.lang.Double.TYPE)) {
		query.setDouble(pos, new Double(value));
	} else if (propertyClass.equals(Date.class)) {
		query.setDate(pos, CommonUtil.parseDate(value, CommonUtil.INPUT_DATE_PATTERN));
	} else if (propertyClass.equals(Timestamp.class)) {
		query.setTimestamp(pos, CommonUtil.dateToTimestamp(CommonUtil.parseDate(value, CommonUtil.INPUT_DATETIME_PATTERN)));
	} else if (propertyClass.equals(VariablePeriod.class)) {
		query.setString(pos, VariablePeriod.fromString(value).name());
	} else if (propertyClass.equals(AuthenticationType.class)) {
		query.setString(pos, AuthenticationType.fromString(value).name());
	} else if (propertyClass.equals(Sex.class)) {
		query.setString(pos, Sex.fromString(value).name());
	} else if (propertyClass.equals(DBModule.class)) {
		query.setString(pos, DBModule.fromString(value).name());
	} else if (propertyClass.equals(HyperlinkModule.class)) {
		query.setString(pos, HyperlinkModule.fromString(value).name());
	} else if (propertyClass.equals(JournalModule.class)) {
		query.setString(pos, JournalModule.fromString(value).name());
	} else if (propertyClass.equals(FileModule.class)) {
		query.setString(pos, FileModule.fromString(value).name());
	} else if (propertyClass.equals(Color.class)) {
		query.setString(pos, Color.fromString(value).name());
	} else if (propertyClass.equals(InputFieldType.class)) {
		query.setString(pos, InputFieldType.fromString(value).name());
	} else if (propertyClass.equals(EventImportance.class)) {
		query.setString(pos, EventImportance.fromString(value).name());
	} else if (propertyClass.equals(ExportStatus.class)) {
		query.setString(pos, ExportStatus.fromString(value).name());
	} else if (propertyClass.isArray() && propertyClass.getComponentType().equals(java.lang.Byte.TYPE)) { // only string hashes supported, no boolean, float, etc...
		query.setBinary(pos, CryptoUtil.hashForSearch(value));
	} else {
		// illegal type...
		throw new IllegalArgumentException(MessageFormat.format(CommonUtil.INPUT_TYPE_NOT_SUPPORTED, propertyClass.toString()));
	}
}