Example usage for java.sql Timestamp getTime

List of usage examples for java.sql Timestamp getTime

Introduction

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

Prototype

public long getTime() 

Source Link

Document

Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by this Timestamp object.

Usage

From source file:uk.org.funcube.fcdw.server.extract.csv.WodCsvExtractor.java

@Transactional(readOnly = false)
public void extractWeekly(long satelliteId) {
    List<SatelliteStatusEntity> satelliteStatuses = satelliteStatusDao.findBySatelliteId(satelliteId);

    if (satelliteStatuses.isEmpty()) {
        LOG.error("No satellite status found for satellite id: " + satelliteId);
        return;//from  w w w . ja  v a 2s . c  o  m
    }

    SatelliteStatusEntity satelliteStatus = satelliteStatuses.get(0);
    final Timestamp lastDumpTime = satelliteStatus.getLastWodDump();
    LOG.debug("Last dump time recorded: " + SDTF.format(new Date(lastDumpTime.getTime())));
    final Date lastDumpDate = new Date(lastDumpTime.getTime() + 1000);
    final Timestamp newDumpTime = new Timestamp(lastDumpTime.getTime() + (7 * 24 * 60 * 60 * 1000));
    LOG.debug("New end dump time calculated: " + SDTF.format(new Date(newDumpTime.getTime())));
    final Date newDumpDate = new Date(newDumpTime.getTime());

    final String fileName = "wod" + SDF.format(newDumpDate) + ".csv";

    String fileSeparator = System.getProperty("file.separator");

    File fileLocation = new File(System.getProperty("wodweekly.dir") + fileSeparator + fileName);

    LOG.debug("Dumping WOD for period : " + SDTF.format(lastDumpDate) + " to " + SDTF.format(newDumpDate) + " "
            + "to file " + fileName);

    List<WholeOrbitDataEntity> wodWeekly = wholeOrbitDataDao
            .getBySatelliteIdAndValidAndCreatedDateBetween(satelliteId, lastDumpDate, newDumpDate);

    LOG.debug("First date in list:" + SDTF.format(wodWeekly.get(0).getCreatedDate()));
    LOG.debug("Last date list:" + SDTF.format(wodWeekly.get(wodWeekly.size() - 1).getCreatedDate()));

    if (!wodWeekly.isEmpty()) {

        writeFile(wodWeekly, fileLocation);

        satelliteStatus.setLastWodDump(newDumpTime);
        satelliteStatusDao.save(satelliteStatus);
    }
}

From source file:org.openmrs.web.taglib.FormatDateTag.java

public int doStartTag() {
    RequestContext requestContext = (RequestContext) this.pageContext
            .getAttribute(RequestContextAwareTag.REQUEST_CONTEXT_PAGE_ATTRIBUTE);

    if (date == null && getPath() != null) {
        try {/*from   ww  w.j a  v a2s.  c o  m*/
            // get the "path" object from the pageContext
            String resolvedPath = getPath();
            String nestedPath = (String) pageContext.getAttribute(NestedPathTag.NESTED_PATH_VARIABLE_NAME,
                    PageContext.REQUEST_SCOPE);
            if (nestedPath != null) {
                resolvedPath = nestedPath + resolvedPath;
            }

            BindStatus status = new BindStatus(requestContext, resolvedPath, false);
            log.debug("status: " + status);

            if (status.getValue() != null) {
                log.debug("status.value: " + status.getValue());
                if (status.getValue().getClass() == Date.class) {
                    // if no editor was registered all will go well here
                    date = (Date) status.getValue();
                } else {
                    // if a "Date" property editor was registerd for the form, the status.getValue()
                    // object will be a java.lang.String.  This is useless.  Try getting the original
                    // value from the troublesome editor
                    log.debug("status.valueType: " + status.getValueType());
                    Timestamp timestamp = (Timestamp) status.getEditor().getValue();
                    date = new Date(timestamp.getTime());
                }
            }
        } catch (Exception e) {
            log.warn("Unable to get a date object from path: " + getPath(), e);
            return SKIP_BODY;
        }
    }

    if (!dateWasSet && date == null) {
        log.warn("Both 'date' and 'path' cannot be null.  Page: " + pageContext.getPage() + " localname:"
                + pageContext.getRequest().getLocalName() + " rd:"
                + pageContext.getRequest().getRequestDispatcher(""));
        return SKIP_BODY;
    }

    if (type == null) {
        type = "";
    }

    DateFormat dateFormat = null;

    if (format != null && format.length() > 0) {
        dateFormat = new SimpleDateFormat(format, Context.getLocale());
    } else if (type.equals("xml")) {
        dateFormat = new SimpleDateFormat("dd-MMM-yyyy", Context.getLocale());
    } else {
        log.debug("context locale: " + Context.getLocale());

        if (type.equals("long")) {
            dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, Context.getLocale());
        } else if (type.equals("medium")) {
            dateFormat = DateFormat.getDateInstance(DateFormat.MEDIUM, Context.getLocale());
        } else {
            dateFormat = Context.getDateFormat();
        }
    }

    if (dateFormat == null) {
        dateFormat = new SimpleDateFormat("MM-dd-yyyy");
    }

    String datestr = "";

    try {
        if (date != null) {
            if (type.equals("milliseconds")) {
                datestr = "" + date.getTime();
            } else {
                if (showTodayOrYesterday && (DateUtils.isSameDay(Calendar.getInstance().getTime(), date)
                        || OpenmrsUtil.isYesterday(date))) {
                    //print only time of day but maintaining the format(24 Vs 12) if any was specified
                    String timeFormatString = (format != null && !format.contains("a")) ? "HH:mm" : "h:mm a";
                    dateFormat = new SimpleDateFormat(timeFormatString);
                    if (DateUtils.isSameDay(Calendar.getInstance().getTime(), date)) {
                        datestr = Context.getMessageSourceService().getMessage("general.today") + " "
                                + dateFormat.format(date);
                    } else {
                        datestr = Context.getMessageSourceService().getMessage("general.yesterday") + " "
                                + dateFormat.format(date);
                    }
                } else {
                    datestr = dateFormat.format(date);
                }
            }
        }
    } catch (IllegalArgumentException e) {
        //format or date is invalid
        log.error("date: " + date);
        log.error("format: " + format);
        log.error(e);
        datestr = date.toString();
    }

    try {
        pageContext.getOut().write(datestr);
    } catch (IOException e) {
        log.error(e);
    }

    // reset the objects to null because taglibs are reused
    release();

    return SKIP_BODY;
}

From source file:org.apache.olingo.fit.proxy.EntityRetrieveTestITCase.java

@Test
public void navigate() {
    final Order order = getContainer().getOrders().getByKey(8).load();
    assertEquals(8, order.getOrderID(), 0);

    final Timestamp date = order.getOrderDate();
    assertNotNull(date);//  w  ww  .  j a  v  a2 s. c om
    final Calendar actual = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
    actual.clear();
    actual.set(2011, 2, 4, 16, 3, 57);
    assertEquals(actual.getTimeInMillis(), date.getTime());

    final Customer customer = getContainer().getCustomers().getByKey(1).load();
    assertNotNull(customer);
    assertEquals(1, customer.getPersonID(), 0);
    final Address address = customer.getHomeAddress();
    assertNotNull(address);
    assertEquals("98052", address.getPostalCode());
}

From source file:org.apache.hadoop.hive.serde2.avro.AvroSerializer.java

private Object serializePrimitive(TypeInfo typeInfo, PrimitiveObjectInspector fieldOI, Object structFieldData,
        Schema schema) throws AvroSerdeException {
    switch (fieldOI.getPrimitiveCategory()) {
    case BINARY:/* w w  w.j av a  2 s. c  o m*/
        if (schema.getType() == Type.BYTES) {
            return AvroSerdeUtils.getBufferFromBytes((byte[]) fieldOI.getPrimitiveJavaObject(structFieldData));
        } else if (schema.getType() == Type.FIXED) {
            Fixed fixed = new GenericData.Fixed(schema,
                    (byte[]) fieldOI.getPrimitiveJavaObject(structFieldData));
            return fixed;
        } else {
            throw new AvroSerdeException("Unexpected Avro schema for Binary TypeInfo: " + schema.getType());
        }
    case DECIMAL:
        HiveDecimal dec = (HiveDecimal) fieldOI.getPrimitiveJavaObject(structFieldData);
        return AvroSerdeUtils.getBufferFromDecimal(dec, ((DecimalTypeInfo) typeInfo).scale());
    case CHAR:
        HiveChar ch = (HiveChar) fieldOI.getPrimitiveJavaObject(structFieldData);
        return ch.getStrippedValue();
    case VARCHAR:
        HiveVarchar vc = (HiveVarchar) fieldOI.getPrimitiveJavaObject(structFieldData);
        return vc.getValue();
    case DATE:
        Date date = ((DateObjectInspector) fieldOI).getPrimitiveJavaObject(structFieldData);
        return DateWritable.dateToDays(date);
    case TIMESTAMP:
        Timestamp timestamp = ((TimestampObjectInspector) fieldOI).getPrimitiveJavaObject(structFieldData);
        return timestamp.getTime();
    case UNKNOWN:
        throw new AvroSerdeException("Received UNKNOWN primitive category.");
    case VOID:
        return null;
    default: // All other primitive types are simple
        return fieldOI.getPrimitiveJavaObject(structFieldData);
    }
}

From source file:data.DefaultExchanger.java

protected Long timestamp(Timestamp timestamp) {
    if (timestamp != null) {
        return timestamp.getTime();
    } else {//  w w  w.  j a  v  a 2s. c  om
        return null;
    }
}

From source file:org.emergent.plumber.StorageServlet.java

private JSONObject readEntry(ResultSet rs) throws JSONException, SQLException {
    JSONObject clientObj = new JSONObject();
    String id = rs.getString("nodeid");
    clientObj.put("id", id);

    Timestamp modified = rs.getTimestamp("modified");
    long mod = modified.getTime();
    double modDouble = MiscUtil.toWeaveTimestampDouble(mod);
    clientObj.put("modified", modDouble);

    String payload = rs.getString("payload");
    clientObj.put("payload", payload);

    int sortindex = rs.getInt("sortindex");
    if (!rs.wasNull())
        clientObj.put("sortindex", sortindex);

    log("returning : " + clientObj.toString());
    return clientObj;
}

From source file:org.kuali.kfs.module.ar.batch.service.impl.LetterOfCreditCreateServiceImpl.java

/**
 * This method created cashcontrol documents and payment application based on the loc creation type and loc value passed.
 *
 * @param contractsGrantsInvoiceDocument
 * @return/*from  w w w. j a  v a  2  s  . c o  m*/
 */
protected CashControlDetail createCashControlDetail(
        ContractsGrantsInvoiceDocument contractsGrantsInvoiceDocument) {
    CashControlDetail cashControlDetail = new CashControlDetail();
    cashControlDetail.setCustomerNumber(
            contractsGrantsInvoiceDocument.getAccountsReceivableDocumentHeader().getCustomerNumber());
    cashControlDetail.setFinancialDocumentLineAmount(contractsGrantsInvoiceDocument.getOpenAmount());
    Timestamp ts = new Timestamp(new java.util.Date().getTime());
    java.sql.Date today = new java.sql.Date(ts.getTime());
    cashControlDetail.setCustomerPaymentDate(today);

    return cashControlDetail;
}

From source file:org.kuali.kfs.module.cab.businessobject.lookup.PurApReportLookupableHelperServiceImpl.java

/**
 * Get the Date instance. Why we need this? Looks OJB returns different type of instance when connect to MySql and Oracle:
 * Oracle returns Date instance while MySql returns TimeStamp instance.
 *
 * @param obj/*from   w ww .  ja va 2 s  .  co  m*/
 * @return
 */
private Date getDate(Object obj) {
    if (obj instanceof Date) {
        return (Date) obj;
    } else if (obj instanceof Timestamp) {
        Timestamp tsp = (Timestamp) obj;
        return new Date(tsp.getTime());
    } else {
        return null;
    }
}

From source file:org.kuali.coeus.propdev.impl.budget.core.ProposalBudgetViewHelperServiceImpl.java

public String getDateFromTimeStamp(Timestamp timestamp) {
    return ObjectUtils.isNull(timestamp) ? ""
            : getDateTimeService().toDateString(new Date(timestamp.getTime()));
}

From source file:org.apache.roller.weblogger.ui.rendering.pagers.CommentsPager.java

/** Get last updated time from items in pager */
public Date getLastUpdated() {
    if (lastUpdated == null) {
        // feeds are sorted by pubtime, so first might not be last updated
        List<WeblogEntryCommentWrapper> items = (List<WeblogEntryCommentWrapper>) getItems();
        if (getItems() != null && getItems().size() > 0) {
            Timestamp newest = ((WeblogEntryCommentWrapper) getItems().get(0)).getPostTime();
            for (WeblogEntryCommentWrapper c : items) {
                if (c.getPostTime().after(newest)) {
                    newest = c.getPostTime();
                }/* w  w w  .  j ava 2  s.co m*/
            }
            lastUpdated = new Date(newest.getTime());
        } else {
            // no update so we assume it's brand new
            lastUpdated = new Date();
        }
    }
    return lastUpdated;
}