List of usage examples for java.sql Timestamp valueOf
@SuppressWarnings("deprecation") public static Timestamp valueOf(LocalDateTime dateTime)
From source file:org.apache.hadoop.hive.ql.session.SessionState.java
/** * Initialize current timestamp, other necessary query initialization. *//* w w w .j av a 2 s. c o m*/ public void setupQueryCurrentTimestamp() { queryCurrentTimestamp = new Timestamp(System.currentTimeMillis()); // Provide a facility to set current timestamp during tests if (sessionConf.getBoolVar(ConfVars.HIVE_IN_TEST)) { String overrideTimestampString = HiveConf.getVar(sessionConf, HiveConf.ConfVars.HIVETESTCURRENTTIMESTAMP, (String) null); if (overrideTimestampString != null && overrideTimestampString.length() > 0) { queryCurrentTimestamp = Timestamp.valueOf(overrideTimestampString); } } }
From source file:org.ofbiz.order.shoppingcart.ShoppingCartEvents.java
/** * Add an order term *//from www . j a v a2 s. c om */ public static String addOrderTerm(HttpServletRequest request, HttpServletResponse response) { ShoppingCart cart = getCartObject(request); Locale locale = UtilHttp.getLocale(request); String termTypeId = request.getParameter("termTypeId"); String termValueStr = request.getParameter("termValue"); String termDaysStr = request.getParameter("termDays"); String textValue = request.getParameter("textValue"); String termDateStr = request.getParameter("termDate"); String termSecStr = request.getParameter("termSec"); GenericValue termType = null; Delegator delegator = (Delegator) request.getAttribute("delegator"); BigDecimal termValue = null; Long termDays = null; Long termSec = null; Timestamp termDate = null; termDateStr = termDateStr + " 00:00:00"; Debug.logInfo(".........CODIGOLINUX........ Fecha: " + termDateStr, module); if (UtilValidate.isEmpty(termTypeId)) { request.setAttribute("_ERROR_MESSAGE_", UtilProperties.getMessage(resource_error, "OrderOrderTermTypeIsRequired", locale)); return "error"; } try { termType = delegator.findOne("TermType", UtilMisc.toMap("termTypeId", termTypeId), false); } catch (GenericEntityException gee) { request.setAttribute("_ERROR_MESSAGE_", gee.getMessage()); return "error"; } if (("FIN_PAYMENT_TERM".equals(termTypeId) && UtilValidate.isEmpty(termDaysStr)) || (UtilValidate.isNotEmpty(termType) && "FIN_PAYMENT_TERM".equals(termType.get("parentTypeId")) && UtilValidate.isEmpty(termDaysStr))) { request.setAttribute("_ERROR_MESSAGE_", UtilProperties.getMessage(resource_error, "OrderOrderTermDaysIsRequired", locale)); return "error"; } if (UtilValidate.isNotEmpty(termValueStr)) { try { termValue = new BigDecimal(termValueStr); } catch (NumberFormatException e) { request.setAttribute("_ERROR_MESSAGE_", UtilProperties.getMessage(resource_error, "OrderOrderTermValueError", UtilMisc.toMap("orderTermValue", termValueStr), locale)); return "error"; } } if (UtilValidate.isNotEmpty(termDaysStr)) { try { termDays = Long.valueOf(termDaysStr); } catch (NumberFormatException e) { request.setAttribute("_ERROR_MESSAGE_", UtilProperties.getMessage(resource_error, "OrderOrderTermDaysError", UtilMisc.toMap("orderTermDays", termDaysStr), locale)); return "error"; } } if (UtilValidate.isNotEmpty(termSecStr)) { try { termSec = Long.valueOf(termSecStr); } catch (NumberFormatException e) { request.setAttribute("_ERROR_MESSAGE_", UtilProperties.getMessage(resource_error, "OrderOrdertermSecError", UtilMisc.toMap("termSec", termSec), locale)); return "error"; } } else termSec = Long.valueOf(0); if (UtilValidate.isNotEmpty(termDateStr)) { try { termDate = Timestamp.valueOf(termDateStr); } catch (NumberFormatException e) { request.setAttribute("_ERROR_MESSAGE_", UtilProperties.getMessage(resource_error, "OrderOrderTermDateError", UtilMisc.toMap("orderTermDate", termDate), locale)); return "error"; } } removeOrderTerm(request, response); cart.addOrderTerm(termTypeId, termValue, termDays, textValue, termDate, termSec); return "success"; }
From source file:org.wso2.carbon.apimgt.core.dao.impl.ApiDAOImpl.java
@Override public void updateRating(String apiId, String ratingId, Rating rating) throws APIMgtDAOException { final String updateRatingQuery = "UPDATE AM_API_RATINGS SET RATING = ? , UPDATED_BY = ? , LAST_UPDATED_TIME = ?" + " WHERE API_ID = ? AND UUID = ?"; try (Connection connection = DAOUtil.getConnection(); PreparedStatement statement = connection.prepareStatement(updateRatingQuery)) { try {/*from w ww .java2 s .co m*/ connection.setAutoCommit(false); statement.setInt(1, rating.getRating()); statement.setString(2, rating.getUsername()); statement.setTimestamp(3, Timestamp.valueOf(LocalDateTime.now())); statement.setString(4, apiId); statement.setString(5, ratingId); statement.execute(); connection.commit(); } catch (SQLException e) { connection.rollback(); String errorMessage = "Error while updating comment for api id: " + apiId + " and comment id: " + rating.getUuid(); log.error(errorMessage, e); throw new APIMgtDAOException(e); } finally { connection.setAutoCommit(DAOUtil.isAutoCommit()); } } catch (SQLException e) { log.error("Error while creating database connection/prepared-statement", e); throw new APIMgtDAOException(e); } }
From source file:com.krawler.workflow.module.dao.ModuleBuilderDaoImpl.java
public String createModule(HttpServletRequest request) throws ServiceException { String result = "{'success':false}"; HashMap<String, String> arrParam = new HashMap<String, String>(); ArrayList<FileItem> fi = new ArrayList<FileItem>(); boolean fileUpload = false; parseRequest(request, arrParam, fi, fileUpload); try {//from ww w . j a v a 2s . c o m String companyId = sessionHandlerDao.getCompanyid(); String query = "select max(mb_modules.reportkey) as count from com.krawler.esp.hibernate.impl.mb_reportlist as mb_modules"; List list = executeQuery(query); Iterator ite = list.iterator(); String mkey = "1"; if (ite.hasNext()) { Object cnt = (Object) ite.next(); if (cnt == null) { mkey = "1"; } else { mkey = Integer.toString(Integer.parseInt(cnt.toString()) + 1); } } mkey = reportDao.toLZ(Integer.parseInt(mkey), 3); java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(ModuleBuilderController.USER_DATEPREF); java.sql.Timestamp timestamp1 = Timestamp.valueOf(sdf.format(new java.util.Date())); // String moduelname = request.getParameter("name").replace(" ",""); String moduelname = arrParam.get("name").replace(" ", "").toLowerCase(); String tableName = "mb_" + mkey + "_" + moduelname; mb_reportlist module = new com.krawler.esp.hibernate.impl.mb_reportlist(); // module.setReportname(request.getParameter("name")); module.setReportname(arrParam.get("name")); module.setTablename(tableName); module.setReportkey(Integer.parseInt(mkey)); module.setCompanyid(companyId); // module.setReportlabel(request.getParameter("label")); module.setCreateddate(timestamp1); module.setCreatedby(sessionHandlerDao.getUserid()); module.setModifieddate(timestamp1); module.setDisplayconf(Integer.parseInt(arrParam.get("displayconfig"))); save(module); String formid = UUID.randomUUID().toString(); String defaultdata = "{" + "xtype:'form'," + "border:false," + "autoHeight:true," + "cls:'quickInsFrmPnl'," + "items:[{layout:'column'," + "id:'1_" + formid + "'," + "border:false," + "items:[" + "{columnWidth:0.5,id:'2_" + formid + "',border:false," + "bodyStyle:'border : 0pt solid'," + "items:[{xtype:'fieldset',id:'3_" + formid + "'," + "bodyStyle:'border : 0pt solid'," + "autoHeight:true}" + "]}," + "{columnWidth:0.5,id:'5_" + formid + "',border:false," + "items:[{xtype:'fieldset',id:'6_" + formid + "'," + "border:false,autoHeight:true" + "}]" + "}," + "{columnWidth:1,id:'7_" + formid + "',border:false," + "items:[{xtype:'fieldset',id:'UserFieldsFS'," + "border:false,autoHeight:true,bodyStyle:'width:500px'" + "}]" + "}" + "]}]}"; com.krawler.esp.hibernate.impl.mb_forms form = new com.krawler.esp.hibernate.impl.mb_forms(); form.setData(defaultdata); form.setFormid(formid); form.setModuleid(module); form.setCompanyid(companyId); String abstractInd = arrParam.get("abstractInd"); form.setAbstractInd("on".equals(abstractInd) ? true : false); form.setName(arrParam.get("name")); // form.setName(request.getParameter("name")); save(form); //moduleBuilderGenerateTable.createModuleConfigTable(session,module.getModuleid()); result = "{'success':true}"; // String actionType = "Add Module"; // String details = arrParam.get("name")+" Module Added"; // long actionId = AuditTrialHandler.getActionId(session, actionType); if (fi.size() > 0) { com.krawler.esp.handlers.genericFileUpload uploader = new com.krawler.esp.handlers.genericFileUpload(); String destinationdir = PropsValues.STORE_PATH; uploader.uploadFile(fi.get(0), destinationdir, module.getReportid()); if (!uploader.ErrorMsg.equals("")) { result = "{'success':true,error:'" + uploader.ErrorMsg + "'}"; } } //Add access right permissions com.krawler.esp.hibernate.impl.mb_permmaster permmaster = null; mb_permgrmaster permgrmaster = new mb_permgrmaster(); // accessRight.addPermGrp(session, permgrmaster, modObj, taskObj); String grname = module.getReportname() + " Permissions (" + "mb_" + module.getReportkey() + "_" + module.getReportname() + ")"; permgrmaster.setPermgrname(grname); permgrmaster.setDescription(grname); permgrmaster.setReportid(module); // permgrmaster.setTaskid(taskObj); permgrmaster.setTaskflag(1); save(permgrmaster); for (int i = 2; i < 10; i++) { // if (i < 5 || ((i == 5 || i == 6) && commentFlag) || ((i == 7 || i == 8) && docFlag)) { permmaster = new com.krawler.esp.hibernate.impl.mb_permmaster(); mb_permactions permaction = (mb_permactions) get(mb_permactions.class, i); permmaster.setPermaction(permaction); permmaster.setPermname(permaction.getName()); permmaster.setDescription(permaction.getName()); permmaster.setPermgrid(permgrmaster); permmaster.setPermid(accessRightDao.getMaxPermid(permgrmaster.getPermgrid())); save(permmaster); // } } // com.krawler.esp.hibernate.impl.mb_permmaster permmaster = null; // mb_permgrmaster permgrmaster = new mb_permgrmaster(); // accessRight.addPermGrp(session,permgrmaster,module); // for(int i=2;i<9;i++) { // permmaster = new com.krawler.esp.hibernate.impl.mb_permmaster(); // mb_permactions permaction = (mb_permactions) session.load(mb_permactions.class,i); // permmaster.setPermaction(permaction); // permmaster.setPermname(permaction.getName()); // permmaster.setDescription(permaction.getName()); // permmaster.setPermgrid(permgrmaster); // permmaster.setPermid(accessRight.getMaxPermid(session,permgrmaster.getPermgrid())); // session.save(permmaster); // } //Done by sm/anup JSONObject jobj = new JSONObject(); JSONObject jtemp2 = new JSONObject(); jtemp2.put("modulename", module.getReportname()); jtemp2.put("moduleid", module.getReportid()); jtemp2.put("tablename", module.getTablename()); jtemp2.put("reportkey", module.getReportkey()); jtemp2.put("dateval", module.getCreateddate()); jtemp2.put("id", "module_" + module.getReportid()); jtemp2.put("formid", form.getFormid()); jobj.append("data", jtemp2.toString()); jobj.put("success", "true"); result = jobj.toString(); // AuditTrialHandler.insertAuditLog(session, actionId, details, request); } catch (Exception e) { logger.warn(e.getMessage(), e); result = "{'success':false}"; throw ServiceException.FAILURE("FormServlet.createModule", e); } finally { return result; } }
From source file:jp.zippyzip.impl.GeneratorServiceImpl.java
String toJsonCities(ParentChild data) throws JSONException { boolean start = true; JSONObject pref = new JSONObject(data.getParents().getFirst()); StringBuilder ret = new StringBuilder("{\"pref\":"); pref.remove("yomi"); ret.append(pref.toString());/*www . ja v a 2 s . c o m*/ ret.append(",\"cities\":["); for (String json : data.getChildren()) { if (start) { start = false; } else { ret.append(","); } JSONObject jo = new JSONObject(json); if (Timestamp.valueOf(jo.getString("expiration")).getTime() < new Date().getTime()) { jo.put("note", ""); } jo.remove("yomi"); jo.remove("expiration"); ret.append(jo.toString()); } return ret.append("]}").toString(); }
From source file:org.kawanfw.sql.jdbc.ResultSetHttp.java
/** * Because ORACLE always format Date as Timestamp, we must test the length * of the string return a java.sql.Date formated from a Timestamp.toString() * or java.sql.Date.toString() input//from w ww . j ava 2 s.c o m * * @param s * the Timestamp.toString() or java.sql.Date.toString() input * @return the java.sql.Date corresponding to the Timestamp.toString() or * java.sql.Date.toString() input */ private java.sql.Date timestampOrDateValueOf(String s) { // Because ORACLE always format Date as Timestamp, we must test the // length of the string if (s.length() > "yyyy-mm-dd".length()) { Timestamp ts = Timestamp.valueOf(s); java.sql.Date date = new java.sql.Date(ts.getTime()); return date; } else { return java.sql.Date.valueOf(s); } }
From source file:adalid.core.AbstractDataArtifact.java
private Timestamp someTimestampValue(Field field, String string) { if (StringUtils.isBlank(string)) { return null; }//from w w w. j a v a 2 s . c o m Timestamp someRelativeTimestamp = someRelativeTimestampValue(string); if (someRelativeTimestamp != null) { return someRelativeTimestamp; } try { return Timestamp.valueOf(string); } catch (Exception e) { logInvalidDataExpression(field, "timestamp", e); } return null; }
From source file:org.wso2.carbon.apimgt.core.dao.impl.ApiDAOImpl.java
/** * Change the lifecycle status of a given API * * @param apiID The UUID of the respective API * @param status The lifecycle status that the API must be set to * @throws APIMgtDAOException if error occurs while accessing data layer *///from w w w .j ava2 s . c om @Override public void changeLifeCycleStatus(String apiID, String status) throws APIMgtDAOException { final String query = "UPDATE AM_API SET CURRENT_LC_STATUS = ?, LAST_UPDATED_TIME = ? WHERE UUID = ?"; try (Connection connection = DAOUtil.getConnection(); PreparedStatement statement = connection.prepareStatement(query)) { try { connection.setAutoCommit(false); statement.setString(1, status); statement.setTimestamp(2, Timestamp.valueOf(LocalDateTime.now())); 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) { throw new APIMgtDAOException(e); } }
From source file:org.wso2.carbon.apimgt.core.dao.impl.PolicyDAOImpl.java
/** * updates an existing Application Policy * * @param applicationPolicy {@link Policy} instance * @param connection DB Connection instance * @throws SQLException if an error occurs while updating the API policy * @throws APIMgtDAOException if the uuid of the policy is not available */// w ww .j a v a2 s.c o m private void updateApplicationPolicy(Policy applicationPolicy, Connection connection) throws APIMgtDAOException, SQLException { final String query = "UPDATE AM_APPLICATION_POLICY SET NAME = ?, DISPLAY_NAME = ?, DESCRIPTION = ?, " + "QUOTA_TYPE = ?, UNIT_TIME = ?, QUOTA = ?, QUOTA_UNIT = ?, TIME_UNIT = ?, LAST_UPDATED_TIME = ? " + "WHERE UUID = ?"; if (applicationPolicy.getUuid() == null || applicationPolicy.getUuid().isEmpty()) { String errorMsg = "Policy uuid is not found, unable to update policy: " + applicationPolicy.getPolicyName(); throw new APIMgtDAOException(errorMsg); } Limit limit = applicationPolicy.getDefaultQuotaPolicy().getLimit(); try (PreparedStatement statement = connection.prepareStatement(query)) { statement.setString(1, applicationPolicy.getPolicyName()); statement.setString(2, applicationPolicy.getDisplayName()); statement.setString(3, applicationPolicy.getDescription()); statement.setString(4, applicationPolicy.getDefaultQuotaPolicy().getType()); statement.setInt(5, applicationPolicy.getDefaultQuotaPolicy().getLimit().getUnitTime()); setDefaultThrottlePolicyDetailsPreparedStmt(limit, statement); statement.setString(8, applicationPolicy.getDefaultQuotaPolicy().getLimit().getTimeUnit()); statement.setTimestamp(9, Timestamp.valueOf(LocalDateTime.now())); statement.setString(10, applicationPolicy.getUuid()); statement.execute(); } }
From source file:org.wso2.carbon.apimgt.core.dao.impl.PolicyDAOImpl.java
/** * updates an existing Subscription Policy * * @param subscriptionPolicy {@link Policy} instance * @param connection DB Connection instance * @throws APIMgtDAOException if an error occurs while updating the Subscription policy *///from w w w.j a v a2 s . c o m private void updateSubscriptionPolicy(Policy subscriptionPolicy, Connection connection) throws APIMgtDAOException, SQLException { final String query = "UPDATE AM_SUBSCRIPTION_POLICY SET NAME = ?, DISPLAY_NAME = ?, DESCRIPTION = ?, QUOTA_TYPE = ?, " + "UNIT_TIME = ?, QUOTA = ?, QUOTA_UNIT = ?, TIME_UNIT = ?, RATE_LIMIT_COUNT = ?, " + "RATE_LIMIT_TIME_UNIT = ?, CUSTOM_ATTRIBUTES = ?, STOP_ON_QUOTA_REACH = ?, " + "BILLING_PLAN = ?, IS_DEPLOYED = ?, LAST_UPDATED_TIME = ? WHERE UUID = ?"; if (subscriptionPolicy.getUuid() == null || subscriptionPolicy.getUuid().isEmpty()) { String errorMsg = "Policy uuid is not found, unable to update policy: " + subscriptionPolicy.getPolicyName(); throw new APIMgtDAOException(errorMsg); } Limit limit = subscriptionPolicy.getDefaultQuotaPolicy().getLimit(); try (PreparedStatement statement = connection.prepareStatement(query)) { statement.setString(1, subscriptionPolicy.getPolicyName()); statement.setString(2, subscriptionPolicy.getDisplayName()); statement.setString(3, subscriptionPolicy.getDescription()); statement.setString(4, subscriptionPolicy.getDefaultQuotaPolicy().getType()); statement.setInt(5, subscriptionPolicy.getDefaultQuotaPolicy().getLimit().getUnitTime()); setDefaultThrottlePolicyDetailsPreparedStmt(limit, statement); statement.setString(8, subscriptionPolicy.getDefaultQuotaPolicy().getLimit().getTimeUnit()); subscriptionPolicy.populateDataInPreparedStatement(statement); statement.setBoolean(14, subscriptionPolicy.isDeployed()); statement.setTimestamp(15, Timestamp.valueOf(LocalDateTime.now())); statement.setString(16, subscriptionPolicy.getUuid()); statement.execute(); } }