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:edu.ku.brc.specify.tasks.subpane.JasperReportsCache.java

/**
 * Starts the report creation process// ww  w  . jav  a  2s.  com
 * @param fileName the XML file name of the report definition
 * @param recrdSet the recordset to use to fill the labels
 */
public static ReportCompileInfo checkReport(final File file) {
    File cachePath = getCachePath();
    String fileName = file.getName();
    File compiledPath = getCompiledFile(file);

    AppResourceIFace appRes = AppContextMgr.getInstance().getResource(fileName);

    File reportFileFromCache = new File(cachePath.getAbsoluteFile() + File.separator + fileName);

    // Check to see if it needs to be recompiled, if it doesn't need compiling then
    // call "compileComplete" directly to have it start filling the labels
    // otherswise create the compiler runnable and have it be compiled 
    // asynchronously

    Timestamp apTime = appRes.getTimestampModified() == null ? appRes.getTimestampCreated()
            : appRes.getTimestampModified();
    boolean needsCompiling = apTime == null || !compiledPath.exists()
            || apTime.getTime() > reportFileFromCache.lastModified();

    //log.debug(appRes.getTimestampModified().getTime()+" > "+reportFileFromCache.lastModified() +"  "+(appRes.getTimestampModified().getTime() > reportFileFromCache.lastModified()));
    //log.debug(compiledPath.exists());
    //log.debug("needsCompiling "+needsCompiling);
    return new ReportCompileInfo(reportFileFromCache, compiledPath, needsCompiling);
}

From source file:org.azkfw.datasource.xml.XmlDatasourceFactory.java

private static XmlRecord readData(final int aRowNum, final XmlRecordEntity aRecord,
        final List<XmlField> aFields) throws ParseException {
    Map<String, Object> data = new HashMap<String, Object>();
    for (int i = 0; i < aFields.size(); i++) {
        XmlField field = aFields.get(i);
        XmlRecordDataEntity d = aRecord.data.get(i);

        String value = d.value;/*www.j  a va  2 s. co  m*/

        if ("(NULL)".equals(value)) {
            data.put(field.name, null);
        } else {
            if (FieldType.String == field.type) {
                String obj = value;
                data.put(field.name, obj);
            } else if (FieldType.Boolean == field.type) {
                Boolean obj = Boolean.parseBoolean(value);
                data.put(field.name, obj);
            } else if (FieldType.Integer == field.type) {
                Double obj = Double.parseDouble(value);
                data.put(field.name, Integer.valueOf(obj.intValue()));
            } else if (FieldType.Long == field.type) {
                Double obj = Double.parseDouble(value);
                data.put(field.name, Long.valueOf(obj.longValue()));
            } else if (FieldType.Float == field.type) {
                Float obj = Float.parseFloat(value);
                data.put(field.name, obj);
            } else if (FieldType.Double == field.type) {
                Double obj = Double.parseDouble(value);
                data.put(field.name, obj);
            } else if (FieldType.Timestamp == field.type) {
                Timestamp obj = new Timestamp(
                        new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").parse(value).getTime());
                data.put(field.name, obj);
            } else if (FieldType.Date == field.type) {
                Timestamp ts = new Timestamp(new SimpleDateFormat("yyyy/MM/dd").parse(value).getTime());
                Date obj = new Date(ts.getTime());
                data.put(field.name, obj);
            } else if (FieldType.Time == field.type) {
                Timestamp ts = new Timestamp(new SimpleDateFormat("HH:mm:ss").parse(value).getTime());
                Time obj = new Time(ts.getTime());
                data.put(field.name, obj);
            } else {
                throw new ParseException("Undefined type.[" + field.getType() + "]", aRowNum);
            }
        }
    }

    XmlRecord record = new XmlRecord();
    record.data = data;
    return record;
}

From source file:oculus.memex.rest.PreclusterDetailsResource.java

private static void getMainDetails(HashMap<Integer, HashSet<Pair<String, String>>> adKeywords,
        HashMap<Integer, DataRow> result, HashMap<Integer, String> sources, StringBuffer adstring) {
    MemexHTDB htdb = MemexHTDB.getInstance();
    Connection htconn = htdb.open();

    String sqlStr;//from  w  w  w. ja  v  a  2s  . c o m
    Statement stmt;
    sqlStr = "SELECT id,phone,email,website,sources_id,title,text,url,posttime,first_id FROM ads WHERE id IN "
            + adstring.toString();
    stmt = null;
    try {
        stmt = htconn.createStatement();
        ResultSet rs = stmt.executeQuery(sqlStr);
        while (rs.next()) {
            int adid = rs.getInt("id");
            adAttribute(adid, "mainphone", rs.getString("phone"), result);
            adAttribute(adid, "email", rs.getString("email"), result);
            adAttribute(adid, "websites", rs.getString("website"), result);
            adAttribute(adid, "source", sources.get(rs.getInt("sources_id")), result);
            adAttribute(adid, "title", rs.getString("title"), result);
            adAttribute(adid, "text", rs.getString("text"), result);
            adAttribute(adid, "url", rs.getString("url"), result);
            Timestamp timestamp = rs.getTimestamp("posttime");
            adAttribute(adid, "posttime", "" + (timestamp == null ? 0 : timestamp.getTime()), result);
            adAttribute(adid, "first_id", rs.getString("first_id"), result);
        }
    } catch (Exception e) {
        System.out.println("Failed: " + sqlStr);
        e.printStackTrace();
    } finally {
        try {
            if (stmt != null) {
                stmt.close();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    htdb.close();
}

From source file:com.antsdb.saltedfish.server.mysql.util.BufferUtils.java

public static Date readDate(ByteBuf in) {
    Timestamp ts = readTimestamp(in);
    return new Date(ts.getTime());
}

From source file:net.ymate.platform.module.search.Searchs.java

@SuppressWarnings({ "rawtypes", "unchecked" })
private static void __doProcessDocumentField(Document document, ClassBeanWrapper<?> wrapper, String fieldName,
        IndexField idxField) {/*from w w w  . j a va2s.  c  o m*/
    BlurObject _fieldValue = new BlurObject(wrapper.getValue(fieldName));
    if (_fieldValue.toObjectValue() == null) {
        return;
    }
    Class<?> _fieldType = wrapper.getFieldType(fieldName);
    Field _field = null;
    if (Date.class.equals(_fieldType)) {
        Date _date = (Date) _fieldValue.toObjectValue(Date.class);
        _field = new LongField(fieldName, _date.getTime(), idxField.isStore() ? Store.YES : Store.NO);
    } else if (Timestamp.class.equals(_fieldType)) {
        Timestamp _tstamp = (Timestamp) _fieldValue.toObjectValue(Timestamp.class);
        _field = new LongField(fieldName, _tstamp.getTime(), idxField.isStore() ? Store.YES : Store.NO);
    } else if (List.class.equals(_fieldType) || Set.class.equals(_fieldType)
            || Queue.class.equals(_fieldType)) {
        Collection<?> coll = (Collection<?>) _fieldValue.toObjectValue();
        StringBuilder _sb = new StringBuilder();
        for (Object o : coll) {
            _sb.append(o).append(";");
        }
        _field = new Field(fieldName, _sb.toString(), __doBuildFieldType(idxField));
    } else if (Map.class.equals(_fieldType)) {
        Map map = (Map) _fieldValue.toObjectValue();
        StringBuilder _sb = new StringBuilder();
        Set<Entry> set = map.entrySet();
        for (Entry entry : set) {
            _sb.append(entry.getValue()).append(";");
        }
        _field = new Field(fieldName, _sb.toString(), __doBuildFieldType(idxField));
    } else {
        _field = new Field(fieldName, _fieldValue.toStringValue(), __doBuildFieldType(idxField));
    }
    if (_field != null) {
        if (_field.fieldType().indexed() && _field.fieldType().omitNorms()) {
            _field.setBoost(idxField.boost());
        }
        document.add(_field);
    }
}

From source file:org.mapbuilderfreq.FrequencyMapClient.java

public static Date getSoonestDate() {
    //go through flu score data table
    Date soonest = null;/*from w ww  .j  a  v  a 2  s  .c om*/
    try {
        String sysParamsQuery = "SELECT \"CreatedTime\" FROM public.\"ScoredMsg\" ORDER BY \"CreatedTime\" DESC LIMIT 1;";
        Statement st = db.createStatement();
        ResultSet rs = st.executeQuery(sysParamsQuery);

        while (rs.next()) {
            //Date tempDate = rs.getDate(1);
            //DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
            //soonest = formatter.parse(formatter.format(tempDate));

            Timestamp ts = rs.getTimestamp(1);
            soonest = new Date(ts.getTime());

            break;
        }
    } catch (SQLException ex) {
        System.err.println("Earliest Date loading failed....");
        System.err.println(ex);
        System.exit(0);
    }
    return soonest;
}

From source file:org.easyrec.utils.spring.store.dao.DaoUtils.java

/**
 * get a java.util.Date object from a result set column with sql type TIMESTAMP and given name
 *
 * @param rs//w ww.j a v a 2 s.  com
 * @param columnName
 * @return the value, which may be <code>null</code>
 * @throws SQLException
 */
public static Date getDate(ResultSet rs, String columnName) throws SQLException {
    Timestamp ts = rs.getTimestamp(columnName);
    if (ts == null) {
        return null;
    }
    return new Date(ts.getTime());
}

From source file:com.arm.connector.bridge.core.Utils.java

public static java.util.Date convertDate(java.sql.Timestamp date) {
    java.util.Date java_date = new java.util.Date(date.getTime());
    return java_date;
}

From source file:com.twitter.elephanttwin.util.DateUtil.java

/**
 * Timezones in mysql are wacky, this takes a timestamp
 * and returns a Calendar representation of it in UTC
 *///from ww  w.j a  v  a2  s .  c  om
public static Calendar fromSqlTimestamp(Timestamp t) {
    if (t == null) {
        return null;
    }

    Calendar cal = getCalendarInstance();
    cal.setTimeInMillis(t.getTime());
    return cal;
}

From source file:com.streamsets.pipeline.lib.jdbc.multithread.TableContextUtil.java

public static String getOffsetValueForTimestamp(Timestamp timestamp) {
    return getOffsetValueForTimestampParts(timestamp.getTime(), timestamp.getNanos());
}