Example usage for java.sql Timestamp equals

List of usage examples for java.sql Timestamp equals

Introduction

In this page you can find the example usage for java.sql Timestamp equals.

Prototype

public boolean equals(java.lang.Object ts) 

Source Link

Document

Tests to see if this Timestamp object is equal to the given object.

Usage

From source file:org.n52.ifgicopter.spf.input.LastDataPostgisInputPlugin.java

@Override
public boolean hasNewData() {
    if (!this.running)
        return false;

    // ensure minimum time between requests
    long diff = System.currentTimeMillis() - this.lastNewDataRequest;
    if (diff < this.minimumMillisBetweenRequests) {
        return false;
    }//from  w ww. j  a v a 2s . co m
    this.lastNewDataRequest = System.currentTimeMillis();

    if (log.isDebugEnabled() && this.extensiveLog)
        log.debug("Checking database for new data: " + this.host);

    String query = getLatestRecordQuery();
    Statement statement;
    try {
        statement = getConnection().createStatement();
    } catch (SQLException e) {
        log.error(e);
        return false;
    }

    ResultSet resultSet;
    try {
        resultSet = statement.executeQuery(query);
    } catch (SQLException e) {
        log.error(e);
        return false;
    }

    Timestamp t;
    try {
        // no lines returned
        if (!resultSet.next())
            return false;

        t = resultSet.getTimestamp(this.timeColumnName);

        if (log.isDebugEnabled() && this.extensiveLog)
            log.debug("Got newest data for " + t + ", last data was " + this.lastDataTimestamp);
    } catch (SQLException e) {
        log.error(e);
        return false;
    }

    if (t.equals(this.lastDataTimestamp))
        return false;

    return true;
}

From source file:org.ofbiz.order.order.OrderServices.java

@SuppressWarnings("unchecked")
public static Map<String, Object> cancelFlaggedSalesOrders(DispatchContext dctx,
        Map<String, ? extends Object> context) {
    Delegator delegator = dctx.getDelegator();
    LocalDispatcher dispatcher = dctx.getDispatcher();
    GenericValue userLogin = (GenericValue) context.get("userLogin");
    //Locale locale = (Locale) context.get("locale");

    List<GenericValue> ordersToCheck = null;

    // create the query expressions
    List<EntityExpr> exprs = UtilMisc.toList(
            EntityCondition.makeCondition("orderTypeId", EntityOperator.EQUALS, "SALES_ORDER"),
            EntityCondition.makeCondition("statusId", EntityOperator.NOT_EQUAL, "ORDER_COMPLETED"),
            EntityCondition.makeCondition("statusId", EntityOperator.NOT_EQUAL, "ORDER_CANCELLED"),
            EntityCondition.makeCondition("statusId", EntityOperator.NOT_EQUAL, "ORDER_REJECTED"));
    EntityConditionList<EntityExpr> ecl = EntityCondition.makeCondition(exprs, EntityOperator.AND);

    // get the orders
    try {//  ww w .j a  v  a 2 s .co m
        ordersToCheck = delegator.findList("OrderHeader", ecl, null, UtilMisc.toList("orderDate"), null, false);
    } catch (GenericEntityException e) {
        Debug.logError(e, "Problem getting order headers", module);
    }

    if (UtilValidate.isEmpty(ordersToCheck)) {
        Debug.logInfo("No orders to check, finished", module);
        return ServiceUtil.returnSuccess();
    }

    Timestamp nowTimestamp = UtilDateTime.nowTimestamp();
    Iterator<GenericValue> i = ordersToCheck.iterator();
    while (i.hasNext()) {
        GenericValue orderHeader = i.next();
        String orderId = orderHeader.getString("orderId");
        String orderStatus = orderHeader.getString("statusId");

        if (orderStatus.equals("ORDER_CREATED")) {
            // first check for un-paid orders
            Timestamp orderDate = orderHeader.getTimestamp("entryDate");

            // need the store for the order
            GenericValue productStore = null;
            try {
                productStore = orderHeader.getRelatedOne("ProductStore");
            } catch (GenericEntityException e) {
                Debug.logError(e, "Unable to get ProductStore from OrderHeader", module);
            }

            // default days to cancel
            int daysTillCancel = 30;

            // get the value from the store
            if (productStore != null && productStore.get("daysToCancelNonPay") != null) {
                daysTillCancel = productStore.getLong("daysToCancelNonPay").intValue();
            }

            if (daysTillCancel > 0) {
                // 0 days means do not auto-cancel
                Calendar cal = Calendar.getInstance();
                cal.setTimeInMillis(orderDate.getTime());
                cal.add(Calendar.DAY_OF_YEAR, daysTillCancel);
                Date cancelDate = cal.getTime();
                Date nowDate = new Date();
                //Debug.log("Cancel Date : " + cancelDate, module);
                //Debug.log("Current Date : " + nowDate, module);
                if (cancelDate.equals(nowDate) || nowDate.after(cancelDate)) {
                    // cancel the order item(s)
                    Map<String, Object> svcCtx = UtilMisc.<String, Object>toMap("orderId", orderId, "statusId",
                            "ITEM_CANCELLED", "userLogin", userLogin);
                    try {
                        // TODO: looks like result is ignored here, but we should be looking for errors
                        dispatcher.runSync("changeOrderItemStatus", svcCtx);
                    } catch (GenericServiceException e) {
                        Debug.logError(e, "Problem calling change item status service : " + svcCtx, module);
                    }
                }
            }
        } else {
            // check for auto-cancel items
            List itemsExprs = new ArrayList();

            // create the query expressions
            itemsExprs.add(EntityCondition.makeCondition("orderId", EntityOperator.EQUALS, orderId));
            itemsExprs.add(EntityCondition.makeCondition(
                    UtilMisc.toList(
                            EntityCondition.makeCondition("statusId", EntityOperator.EQUALS, "ITEM_CREATED"),
                            EntityCondition.makeCondition("statusId", EntityOperator.EQUALS, "ITEM_APPROVED")),
                    EntityOperator.OR));
            itemsExprs.add(EntityCondition.makeCondition("dontCancelSetUserLogin", EntityOperator.EQUALS,
                    GenericEntity.NULL_FIELD));
            itemsExprs.add(EntityCondition.makeCondition("dontCancelSetDate", EntityOperator.EQUALS,
                    GenericEntity.NULL_FIELD));
            itemsExprs.add(EntityCondition.makeCondition("autoCancelDate", EntityOperator.NOT_EQUAL,
                    GenericEntity.NULL_FIELD));

            ecl = EntityCondition.makeCondition(itemsExprs);

            List<GenericValue> orderItems = null;
            try {
                orderItems = delegator.findList("OrderItem", ecl, null, null, null, false);
            } catch (GenericEntityException e) {
                Debug.logError(e, "Problem getting order item records", module);
            }
            if (UtilValidate.isNotEmpty(orderItems)) {
                Iterator<GenericValue> oii = orderItems.iterator();
                while (oii.hasNext()) {
                    GenericValue orderItem = oii.next();
                    String orderItemSeqId = orderItem.getString("orderItemSeqId");
                    Timestamp autoCancelDate = orderItem.getTimestamp("autoCancelDate");

                    if (autoCancelDate != null) {
                        if (nowTimestamp.equals(autoCancelDate) || nowTimestamp.after(autoCancelDate)) {
                            // cancel the order item
                            Map<String, Object> svcCtx = UtilMisc.<String, Object>toMap("orderId", orderId,
                                    "orderItemSeqId", orderItemSeqId, "statusId", "ITEM_CANCELLED", "userLogin",
                                    userLogin);
                            try {
                                // TODO: check service result for an error return
                                dispatcher.runSync("changeOrderItemStatus", svcCtx);
                            } catch (GenericServiceException e) {
                                Debug.logError(e, "Problem calling change item status service : " + svcCtx,
                                        module);
                            }
                        }
                    }
                }
            }
        }
    }
    return ServiceUtil.returnSuccess();
}