List of usage examples for java.sql Timestamp valueOf
@SuppressWarnings("deprecation") public static Timestamp valueOf(LocalDateTime dateTime)
From source file:org.apache.ddlutils.io.TestChangeColumn.java
/** * Tests adding a default value to a primary key column. *//*from w ww . ja va 2 s . c o m*/ public void testPKColumnAddDefault() throws ParseException { final String model1Xml = "<?xml version='1.0' encoding='ISO-8859-1'?>\n" + "<database xmlns='" + DatabaseIO.DDLUTILS_NAMESPACE + "' name='roundtriptest'>\n" + " <table name='roundtrip'>\n" + " <column name='pk' type='TIMESTAMP' primaryKey='true' required='true'/>\n" + " <column name='avalue' type='INTEGER'/>\n" + " </table>\n" + "</database>"; final String model2Xml = "<?xml version='1.0' encoding='ISO-8859-1'?>\n" + "<database xmlns='" + DatabaseIO.DDLUTILS_NAMESPACE + "' name='roundtriptest'>\n" + " <table name='roundtrip'>\n" + " <column name='pk' type='TIMESTAMP' primaryKey='true' required='true' default='2000-01-01 00:00:00'/>\n" + " <column name='avalue' type='INTEGER'/>\n" + " </table>\n" + "</database>"; createDatabase(model1Xml); Timestamp time = new Timestamp(new Date().getTime()); // some databases (such as MySql) don't store micro-/nanoseconds time.setNanos(0); insertRow("roundtrip", new Object[] { time, new Integer(1) }); alterDatabase(model2Xml); assertEquals(getAdjustedModel(), readModelFromDatabase("roundtriptest")); insertRow("roundtrip", new Object[] { null, new Integer(2) }); List beans = getRows("roundtrip", "avalue"); Timestamp defaultTime = Timestamp.valueOf("2000-01-01 00:00:00"); assertEquals(time, beans.get(0), "pk"); assertEquals(new Integer(1), beans.get(0), "avalue"); assertEquals(defaultTime, beans.get(1), "pk"); assertEquals(new Integer(2), beans.get(1), "avalue"); }
From source file:org.wso2.carbon.apimgt.core.dao.impl.ApiDAOImpl.java
/** * Update an existing API workflow state * * @param apiID The {@link String} of the API that needs to be updated * @param workflowStatus workflow status * @throws APIMgtDAOException if error occurs while accessing data layer */// w w w .java 2s . c om @Override public void updateAPIWorkflowStatus(String apiID, APILCWorkflowStatus workflowStatus) throws APIMgtDAOException { final String query = "UPDATE AM_API SET LAST_UPDATED_TIME = ?, LC_WORKFLOW_STATUS=? WHERE UUID = ?"; try (Connection connection = DAOUtil.getConnection(); PreparedStatement statement = connection.prepareStatement(query)) { try { connection.setAutoCommit(false); statement.setTimestamp(1, Timestamp.valueOf(LocalDateTime.now())); statement.setString(2, workflowStatus.toString()); statement.setString(3, apiID); statement.execute(); connection.commit(); } catch (SQLException e) { connection.rollback(); throw new APIMgtDAOException(e); } finally { connection.setAutoCommit(DAOUtil.isAutoCommit()); } } catch (SQLException e) { String errorMessage = "SQL exception while updating api workflow status for :" + apiID; log.error(errorMessage, e); throw new APIMgtDAOException(e); } }
From source file:org.apache.ddlutils.io.TestChangeColumn.java
/** * Tests adding a default value to an indexed column. *//*from www.j a v a 2s . com*/ public void testUniqueIndexColumnAddDefault() { if (!getPlatformInfo().isIndicesSupported()) { return; } final String model1Xml = "<?xml version='1.0' encoding='ISO-8859-1'?>\n" + "<database xmlns='" + DatabaseIO.DDLUTILS_NAMESPACE + "' name='roundtriptest'>\n" + " <table name='roundtrip'>\n" + " <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n" + " <column name='avalue1' type='INTEGER'/>\n" + " <column name='avalue2' type='TIMESTAMP'/>\n" + " <unique name='testindex'>\n" + " <unique-column name='avalue1'/>\n" + " <unique-column name='avalue2'/>\n" + " </unique>\n" + " </table>\n" + "</database>"; final String model2Xml = "<?xml version='1.0' encoding='ISO-8859-1'?>\n" + "<database xmlns='" + DatabaseIO.DDLUTILS_NAMESPACE + "' name='roundtriptest'>\n" + " <table name='roundtrip'>\n" + " <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n" + " <column name='avalue1' type='INTEGER'/>\n" + " <column name='avalue2' type='TIMESTAMP' default='2000-01-01 00:00:00'/>\n" + " <unique name='testindex'>\n" + " <unique-column name='avalue1'/>\n" + " <unique-column name='avalue2'/>\n" + " </unique>\n" + " </table>\n" + "</database>"; createDatabase(model1Xml); Timestamp time = new Timestamp(new Date().getTime()); // some databases (such as MySql) don't store micro-/nanoseconds time.setNanos(0); insertRow("roundtrip", new Object[] { new Integer(1), new Integer(2), time }); alterDatabase(model2Xml); assertEquals(getAdjustedModel(), readModelFromDatabase("roundtriptest")); insertRow("roundtrip", new Object[] { new Integer(2), new Integer(3) }); List beans = getRows("roundtrip"); Timestamp defaultTime = Timestamp.valueOf("2000-01-01 00:00:00"); assertEquals(new Integer(1), beans.get(0), "pk"); assertEquals(new Integer(2), beans.get(0), "avalue1"); assertEquals(time, beans.get(0), "avalue2"); assertEquals(new Integer(2), beans.get(1), "pk"); assertEquals(new Integer(3), beans.get(1), "avalue1"); assertEquals(defaultTime, beans.get(1), "avalue2"); }
From source file:org.ofbiz.order.order.OrderServices.java
public static Map<String, Object> updateApprovedOrderItems(DispatchContext dctx, Map<String, ? extends Object> context) { LocalDispatcher dispatcher = dctx.getDispatcher(); Delegator delegator = dctx.getDelegator(); GenericValue userLogin = (GenericValue) context.get("userLogin"); Locale locale = (Locale) context.get("locale"); String orderId = (String) context.get("orderId"); Map<String, String> overridePriceMap = UtilGenerics.checkMap(context.get("overridePriceMap")); Map<String, String> itemDescriptionMap = UtilGenerics.checkMap(context.get("itemDescriptionMap")); Map<String, String> itemPriceMap = UtilGenerics.checkMap(context.get("itemPriceMap")); Map<String, String> itemQtyMap = UtilGenerics.checkMap(context.get("itemQtyMap")); Map<String, String> itemReasonMap = UtilGenerics.checkMap(context.get("itemReasonMap")); Map<String, String> itemCommentMap = UtilGenerics.checkMap(context.get("itemCommentMap")); Map<String, String> itemAttributesMap = UtilGenerics.checkMap(context.get("itemAttributesMap")); Map<String, String> itemEstimatedShipDateMap = UtilGenerics.checkMap(context.get("itemShipDateMap")); Map<String, String> itemEstimatedDeliveryDateMap = UtilGenerics .checkMap(context.get("itemDeliveryDateMap")); Boolean calcTax = (Boolean) context.get("calcTax"); if (calcTax == null) { calcTax = Boolean.TRUE;// w ww . j av a 2s .c o m } // obtain a shopping cart object for updating ShoppingCart cart = null; try { cart = loadCartForUpdate(dispatcher, delegator, userLogin, orderId); } catch (GeneralException e) { return ServiceUtil.returnError(e.getMessage()); } if (cart == null) { return ServiceUtil.returnError(UtilProperties.getMessage(resource, "OrderShoppingCartEmpty", locale)); } // go through the item attributes map once to get a list of key names Set<String> attributeNames = FastSet.newInstance(); Set<String> keys = itemAttributesMap.keySet(); for (String key : keys) { String[] attributeInfo = key.split(":"); attributeNames.add(attributeInfo[0]); } // go through the item map and obtain the totals per item Map<String, BigDecimal> itemTotals = new HashMap<String, BigDecimal>(); Iterator<String> i = itemQtyMap.keySet().iterator(); while (i.hasNext()) { String key = i.next(); String quantityStr = itemQtyMap.get(key); BigDecimal groupQty = BigDecimal.ZERO; try { groupQty = new BigDecimal(quantityStr); } catch (NumberFormatException e) { Debug.logError(e, module); return ServiceUtil.returnError(e.getMessage()); } if (groupQty.compareTo(BigDecimal.ZERO) == 0) { return ServiceUtil .returnError(UtilProperties.getMessage(resource, "OrderItemQtyMustBePositive", locale)); } String[] itemInfo = key.split(":"); BigDecimal tally = itemTotals.get(itemInfo[0]); if (tally == null) { tally = groupQty; } else { tally = tally.add(groupQty); } itemTotals.put(itemInfo[0], tally); } // set the items amount/price Iterator<String> iai = itemTotals.keySet().iterator(); while (iai.hasNext()) { String itemSeqId = iai.next(); ShoppingCartItem cartItem = cart.findCartItem(itemSeqId); if (cartItem != null) { BigDecimal qty = itemTotals.get(itemSeqId); BigDecimal priceSave = cartItem.getBasePrice(); // set quantity try { cartItem.setQuantity(qty, dispatcher, cart, false, false); // trigger external ops, don't reset ship groups (and update prices for both PO and SO items) } catch (CartItemModifyException e) { Debug.logError(e, module); return ServiceUtil.returnError(e.getMessage()); } Debug.log("Set item quantity: [" + itemSeqId + "] " + qty, module); if (cartItem.getIsModifiedPrice()) // set price cartItem.setBasePrice(priceSave); if (overridePriceMap.containsKey(itemSeqId)) { String priceStr = itemPriceMap.get(itemSeqId); if (UtilValidate.isNotEmpty(priceStr)) { BigDecimal price = new BigDecimal("-1"); price = new BigDecimal(priceStr).setScale(orderDecimals, orderRounding); cartItem.setBasePrice(price); cartItem.setIsModifiedPrice(true); Debug.log("Set item price: [" + itemSeqId + "] " + price, module); } } // Update the item description if (itemDescriptionMap != null && itemDescriptionMap.containsKey(itemSeqId)) { String description = itemDescriptionMap.get(itemSeqId); if (UtilValidate.isNotEmpty(description)) { cartItem.setName(description); Debug.log("Set item description: [" + itemSeqId + "] " + description, module); } else { return ServiceUtil.returnError( UtilProperties.getMessage(resource, "OrderItemDescriptionCannotBeEmpty", locale)); } } // update the order item attributes if (itemAttributesMap != null) { String attrValue = null; for (String attrName : attributeNames) { attrValue = itemAttributesMap.get(attrName + ":" + itemSeqId); if (UtilValidate.isNotEmpty(attrName)) { cartItem.setOrderItemAttribute(attrName, attrValue); Debug.log("Set item attribute Name: [" + itemSeqId + "] " + attrName + " , Value:" + attrValue, module); } } } } else { Debug.logInfo("Unable to locate shopping cart item for seqId #" + itemSeqId, module); } } // Create Estimated Delivery dates for (Map.Entry<String, String> entry : itemEstimatedDeliveryDateMap.entrySet()) { String itemSeqId = entry.getKey(); String estimatedDeliveryDate = entry.getValue(); if (UtilValidate.isNotEmpty(estimatedDeliveryDate)) { Timestamp deliveryDate = Timestamp.valueOf(estimatedDeliveryDate); ShoppingCartItem cartItem = cart.findCartItem(itemSeqId); cartItem.setDesiredDeliveryDate(deliveryDate); } } // Create Estimated ship dates for (Map.Entry<String, String> entry : itemEstimatedShipDateMap.entrySet()) { String itemSeqId = entry.getKey(); String estimatedShipDate = entry.getValue(); if (UtilValidate.isNotEmpty(estimatedShipDate)) { Timestamp shipDate = Timestamp.valueOf(estimatedShipDate); ShoppingCartItem cartItem = cart.findCartItem(itemSeqId); cartItem.setEstimatedShipDate(shipDate); } } // update the group amounts Iterator<String> gai = itemQtyMap.keySet().iterator(); while (gai.hasNext()) { String key = gai.next(); String quantityStr = itemQtyMap.get(key); BigDecimal groupQty = BigDecimal.ZERO; try { groupQty = new BigDecimal(quantityStr); } catch (NumberFormatException e) { Debug.logError(e, module); return ServiceUtil.returnError(e.getMessage()); } String[] itemInfo = key.split(":"); int groupIdx = -1; try { groupIdx = Integer.parseInt(itemInfo[1]); } catch (NumberFormatException e) { Debug.logError(e, module); return ServiceUtil.returnError(e.getMessage()); } // set the group qty ShoppingCartItem cartItem = cart.findCartItem(itemInfo[0]); if (cartItem != null) { Debug.log("Shipping info (before) for group #" + (groupIdx - 1) + " [" + cart.getShipmentMethodTypeId(groupIdx - 1) + " / " + cart.getCarrierPartyId(groupIdx - 1) + "]", module); cart.setItemShipGroupQty(cartItem, groupQty, groupIdx - 1); Debug.log("Set ship group qty: [" + itemInfo[0] + " / " + itemInfo[1] + " (" + (groupIdx - 1) + ")] " + groupQty, module); Debug.log("Shipping info (after) for group #" + (groupIdx - 1) + " [" + cart.getShipmentMethodTypeId(groupIdx - 1) + " / " + cart.getCarrierPartyId(groupIdx - 1) + "]", module); } } // save all the updated information try { saveUpdatedCartToOrder(dispatcher, delegator, cart, locale, userLogin, orderId, UtilMisc .<String, Object>toMap("itemReasonMap", itemReasonMap, "itemCommentMap", itemCommentMap), calcTax, false); } catch (GeneralException e) { return ServiceUtil.returnError(e.getMessage()); } // run promotions to handle all changes in the cart ProductPromoWorker.doPromotions(cart, dispatcher); // log an order note try { dispatcher.runSync("createOrderNote", UtilMisc.<String, Object>toMap("orderId", orderId, "note", "Updated order.", "internalNote", "Y", "userLogin", userLogin)); } catch (GenericServiceException e) { Debug.logError(e, module); } Map<String, Object> result = ServiceUtil.returnSuccess(); result.put("shoppingCart", cart); result.put("orderId", orderId); return result; }