Example usage for java.sql Date getTime

List of usage examples for java.sql Date getTime

Introduction

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

Prototype

public long getTime() 

Source Link

Document

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

Usage

From source file:adalid.commons.util.TimeUtils.java

public static String defaultTemporalString(Object object) {
    java.util.Date date = object instanceof java.util.Date ? (java.util.Date) object : null;
    if (date == null) {
        return null;
    }//from   w w  w .j  a  v  a2s  .c  om
    Calendar c = Calendar.getInstance();
    c.setTimeInMillis(date.getTime());
    int dd = c.get(Calendar.YEAR);
    int MM = c.get(Calendar.MONTH);
    int yy = c.get(Calendar.DAY_OF_MONTH);
    int hh = c.get(Calendar.HOUR_OF_DAY);
    int mm = c.get(Calendar.MINUTE);
    int ss = c.get(Calendar.SECOND);
    int ms = c.get(Calendar.MILLISECOND);
    boolean dateless = dd == 1 && MM == Calendar.JANUARY && yy == 1970;
    boolean timeless = hh + mm + ss + ms == 0;
    return timeless ? defaultDateString(date)
            : dateless ? defaultTimeString(date) : defaultTimestampString(date);
}

From source file:adalid.commons.util.TimeUtils.java

public static java.util.Date parse(String pdq) {
    if (StringUtils.isBlank(pdq)) {
        return null;
    }//from  w  w  w  . j av  a2s  .  c om
    String string = pdq.trim();
    ParsePosition position = new ParsePosition(0);
    java.util.Date util = timestampFormatter().parse(string, position);
    int i = position.getIndex();
    int l = string.length();
    if (util != null && i == l) {
        return new Timestamp(util.getTime());
    }
    position.setIndex(0);
    util = dateFormatter().parse(string, position);
    i = position.getIndex();
    if (util != null) {
        if (i == l) {
            return new Date(util.getTime());
        }
        java.util.Date time = timeFormatter().parse(string, position);
        i = position.getIndex();
        if (time != null && i == l) {
            return merge(util, time);
        }
    }
    position.setIndex(0);
    util = timeFormatter().parse(string, position);
    i = position.getIndex();
    if (util != null && i == l) {
        return new Time(util.getTime());
    }
    return null;
}

From source file:org.rti.zcore.dar.transfer.access.ImportMshData.java

/**
 * Creates Initial Health Record./*w w w. j a va  2s.c  o  m*/
 * Uses mshPatientMaster.getDateTherapyStarted() for datevisit.
 * @param conn
 * @param siteId
 * @param mshPatientMaster
 * @return
 * @throws NumberFormatException
 * @throws Exception
 */
private static EncounterData createInitialHealthRecord(Connection conn, Long siteId,
        MshPatientMaster mshPatientMaster) throws NumberFormatException, Exception {
    Form formDef = null;
    Long formId = (Long) DynaSiteObjects.getFormNameMap().get("PatientCondition");
    formDef = (Form) DynaSiteObjects.getForms().get(new Long(formId));
    PatientCondition formData = new PatientCondition();
    formData.setSiteId(siteId);
    formData.setCreatedBy("zepadmin");
    formData.setFlowId(formDef.getFlowId());
    formData.setFormId(formId);
    formData.setPatientId(mshPatientMaster.getPatientId());
    formData.setSessionPatient(mshPatientMaster.getSessionPatient());
    formData.setEvent(mshPatientMaster.getEvent());
    formData.setEventId(mshPatientMaster.getEventId());
    formData.setEventUuid(mshPatientMaster.getEventUuid());

    Date dateVisit = DateUtils.toDateSql(mshPatientMaster.getDateTherapyStarted());
    formData.setDateVisit(dateVisit);
    formData.setWeight(mshPatientMaster.getWeightOnStart());
    formData.setHeight(mshPatientMaster.getStartHeight());
    if (dateVisit != null) {
        Timestamp ts = new Timestamp(dateVisit.getTime());
        formData.setCreated(ts);
        formData.setLastModified(ts);
    }
    /*StringBuffer sbuf = new StringBuffer();
    formData.setOi_indications(sbuf.toString());*/

    EncounterData enc = FormDAO.create(conn, formData, formData.getCreatedBy(), formData.getSiteId(), formDef,
            formData.getFlowId(), null);
    return enc;
}

From source file:adalid.commons.util.TimeUtils.java

public static java.util.Date getSqlExtension(java.util.Date util) {
    if (util == null) {
        return null;
    } else if (util instanceof Date || util instanceof Time || util instanceof Timestamp) {
        return util;
    } else {//w w w .j  ava2  s. co  m
        long milliseconds = util.getTime();
        Date date = newDate(util);
        if (date.getTime() == milliseconds) {
            return date;
        }
        Time time = newTime(util);
        if (time.getTime() == milliseconds) {
            return time;
        }
        return new Timestamp(milliseconds);
    }
}

From source file:org.rti.zcore.dar.report.DailyActivityReport.java

/**
 * You must first populate the stockReportMap and itemMap. 
 * Provides regimenReportMap (amounts for each regimen) and a list of patients, which can be used to populate a registry.
 * Populates a patientArvMap while looping through the PatientDispensaryEncounter by using the getPatientArtRegimen method
 * Populates totalDispensed in stockReportMap
 * //w w  w . ja va 2 s  . c o  m
 * Also populates other fields in the ARTRegimenReport including TotalAdultsDispensed
 * @param conn
 * @param beginDate
 * @param endDate
 * @param siteId
 * @param stockReportMap
 * @param itemMap
 * @return
 * @throws ServletException
 * @throws ObjectNotFoundException
 * @throws IOException
 */
public static ARTReport assembleArtRegimenReport(Connection conn, Date beginDate, Date endDate, int siteId,
        LinkedHashMap<String, StockReport> stockReportMap, LinkedHashMap<Long, Item> itemMap)
        throws ServletException, ObjectNotFoundException, IOException, SQLException {

    Form encounterForm = ((Form) DynaSiteObjects.getForms().get(new Long(132)));
    String className = "org.rti.zcore.dar.gen." + StringManipulation.fixClassname(encounterForm.getName());
    Class clazz = null;
    try {
        clazz = Class.forName(className);
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }
    // For each patient, load the report class and add this patient to the list
    // also increment the total dispensed values
    // totalDispensed = new ARTAdultPatient();
    ARTReport artRegimenReport = new ARTReport();
    HashMap<Long, String> patientArvMap = new HashMap<Long, String>();
    HashMap<String, Integer> regimenReportMap = new HashMap<String, Integer>();
    SortedSet<ARTPatient> adults = new TreeSet<ARTPatient>(new CreatedComparator());
    SortedSet<ARTPatient> children = new TreeSet<ARTPatient>(new CreatedComparator());

    ResultSet rs = null;
    try {
        System.out.println("headed to getPatientDispensaryEncounters");
        ids = getPatientEncounterIdsForPeriod(conn, siteId, beginDate, endDate);
        //'rs = InventoryUtils.getPatientDispensaryEncounters(conn, siteId, beginDate, endDate);
        System.out.println("out of getPatientDispensaryEncounters");
    } catch (Exception e) {
        e.printStackTrace();
    }

    int i = 0;
    while (i < ids.size()) {

        rs = getTheRestOfDetails(conn, siteId, beginDate, endDate, ids.get(i));
        rs.next();
        try {
            Long encounterId = (Long) ids.get(i);
            Long patientId = rs.getLong("patient_id");
            String districtPatientId = rs.getString("district_patient_id");
            String firstName = rs.getString("first_name");
            String surname = rs.getString("surname");
            Date dateVisit = rs.getDate("date_visit");
            //Integer age = rs.getInt("age_at_first_visit");
            Integer ageCategory = rs.getInt("age_category");
            int currentSiteId = rs.getInt("site_id");
            String createdBy = rs.getString("created_by");
            Timestamp created = rs.getTimestamp("created");
            int sex = rs.getInt("sex");

            ARTPatient patient = new ARTPatient();

            patient.setEncounterId(encounterId);
            patient.setPatientId(patientId);
            patient.setClientId(districtPatientId);
            patient.setFirstName(firstName);
            patient.setSurname(surname);
            patient.setDateVisit(dateVisit);
            patient.setSiteId(currentSiteId);
            patient.setPharmacist(createdBy);
            patient.setCreated(created);
            patient.setSex(sex);

            switch (ageCategory) {
            case 3283:
                patient.setChildOrAdult("A");
                break;
            case 3284:
                patient.setChildOrAdult("C");
                break;
            default:
                patient.setChildOrAdult("A");
                break;
            }
            System.out.println("out of PatientItemDAO.getEncounterRawValues");
            EncounterData encounter = (EncounterData) PatientItemDAO.getEncounterRawValues(conn, encounterForm,
                    "132", encounterId, clazz);
            System.out.println("out of PatientItemDAO.getEncounterRawValues");
            Map encMap = encounter.getEncounterMap();
            Set encSet = encMap.entrySet();
            boolean includePatientInReport = false;

            HashMap<String, Integer> patientDispensed = new HashMap<String, Integer>();

            for (Iterator iterator = encSet.iterator(); iterator.hasNext();) {
                Map.Entry entry = (Map.Entry) iterator.next();
                Long key = (Long) entry.getKey();
                Integer value = (Integer) entry.getValue();
                // Someone might have forgotten to enter the value
                if (value == null) {
                    value = 0;
                }
                if (key != null) {
                    int n = 0;
                    Item item = itemMap.get(key);
                    //log.debug("item " + key + " dispensed to " + patient.getSurname());
                    if (item != null) {
                        String code = item.getCode().trim().replace(" ", "_");
                        patientDispensed.put("item" + code, value);
                        //log.debug("item " + code + " amount: " + value + " dispensed to " + patient.getSurname());
                        StockReport stockReport = stockReportMap.get("item" + code);
                        Integer itemDispensed = stockReport.getTotalDispensed();
                        if (itemDispensed != null) {
                            n = itemDispensed + value;
                        } else {
                            n = value;
                        }
                        //totalDispensed.setStavudine_LamivudineFDCTabs_30_150mg(n);
                        //patientDispensed.put("item" + code, n);
                        //stockReport.setTotalDispensed(n);
                        includePatientInReport = true;
                        //log.debug("item " + code + " dispensed to " + patient.getSurname());
                    }
                }
            }

            patient.setTotalStockDispensed(patientDispensed);

            if (patientArvMap.get(patientId) == null) {
                //if (includePatientInReport == true) {
                try {
                    System.out.println("out of ZEPRSUtils.getPatientArtRegimen");
                    ResultSet artRs = ZEPRSUtils.getPatientArtRegimen(conn, patientId, beginDate, endDate);
                    System.out.println("out of ZEPRSUtils.getPatientArtRegimen");
                    //int totalAdultsDispensed = 0;
                    while (artRs.next()) {
                        String code = artRs.getString("code");
                        patient.setArvRegimenCode(code);
                        //if (patientArvMap.get(patientId) == null) {
                        patientArvMap.put(patientId, code);
                        if (patient.getChildOrAdult().equals("A")) {
                            int n = artRegimenReport.getTotalAdultsDispensed();
                            n++;
                            artRegimenReport.setTotalAdultsDispensed(n);
                        } else if (patient.getChildOrAdult().equals("C")) {
                            int n = artRegimenReport.getTotalChildrenDispensed();
                            n++;
                            artRegimenReport.setTotalChildrenDispensed(n);
                        }
                        // check if this is the first visit - there might be multiples ones for this encounter
                        Date firstVisit = EncountersDAO.getFirstVisit(conn, patientId);
                        if (firstVisit.getTime() == dateVisit.getTime()) {
                            patient.setRevisit(false);
                            switch (sex) {
                            case 1:
                                int n = artRegimenReport.getTotalFemalesNew();
                                n++;
                                artRegimenReport.setTotalFemalesNew(n);
                            case 2:
                                n = artRegimenReport.getTotalMalesNew();
                                n++;
                                artRegimenReport.setTotalMalesNew(n);
                            }
                            if (patient.getChildOrAdult().equals("A")) {
                                int n = artRegimenReport.getTotalAdultsNew();
                                n++;
                                artRegimenReport.setTotalAdultsNew(n);
                            } else if (patient.getChildOrAdult().equals("C")) {
                                int n = artRegimenReport.getTotalChildrenNew();
                                n++;
                                artRegimenReport.setTotalChildrenNew(n);
                            }
                        } else {
                            patient.setRevisit(true);
                            switch (sex) {
                            case 1:
                                int n = artRegimenReport.getTotalFemalesRevisit();
                                n++;
                                artRegimenReport.setTotalFemalesRevisit(n);
                            case 2:
                                n = artRegimenReport.getTotalMalesRevisit();
                                n++;
                                artRegimenReport.setTotalMalesRevisit(n);
                            }
                            if (patient.getChildOrAdult().equals("A")) {
                                int n = artRegimenReport.getTotalAdultsRevisit();
                                n++;
                                artRegimenReport.setTotalAdultsRevisit(n);
                            } else if (patient.getChildOrAdult().equals("C")) {
                                int n = artRegimenReport.getTotalChildrenRevisit();
                                n++;
                                artRegimenReport.setTotalChildrenRevisit(n);
                            }
                        }
                        String key = "regimen" + code.trim().replace(" ", "_");
                        int amount = 0;
                        if (regimenReportMap.get(key) != null) {
                            amount = regimenReportMap.get(key);
                        }
                        amount++;
                        regimenReportMap.put(key, amount);
                    }
                    artRs.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            patient.setEncounter(encounter);
            if (includePatientInReport == true) {
                if (patient.getChildOrAdult().equals("A")) {
                    adults.add(patient);
                } else if (patient.getChildOrAdult().equals("C")) {
                    children.add(patient);
                }
            }
        } catch (SQLException e) {
            log.error(e);
        }
        i++;
    }

    artRegimenReport.setRegimenReportMap(regimenReportMap);
    artRegimenReport.setAdults(adults);
    artRegimenReport.setChildren(children);
    return artRegimenReport;
}

From source file:com.sap.dirigible.repository.db.dao.DBMapper.java

/**
 * ResultSet current row to DB Repository transformation
 * //from w  w  w  . j  av a2  s . com
 * @param repository
 * @param resultSet
 * @return
 * @throws SQLException
 * @throws DBBaseException
 */
static DBObject dbToObject(DBRepository repository, ResultSet resultSet) throws SQLException, DBBaseException {

    String name = resultSet.getString(FILE_NAME);
    String path = resultSet.getString(FILE_PATH);
    int type = resultSet.getInt(FILE_TYPE);
    String content = resultSet.getString(FILE_CONTENT_TYPE);
    String createdBy = resultSet.getString(FILE_CREATED_BY);
    Date createdAt = new Date(resultSet.getTimestamp(FILE_CREATED_AT).getTime());
    String modifiedBy = resultSet.getString(FILE_MODIFIED_BY);
    Date modifiedAt = new Date(resultSet.getTimestamp(FILE_MODIFIED_AT).getTime());

    DBObject dbObject = null;
    if (type == OBJECT_TYPE_FOLDER) {
        dbObject = new DBFolder(repository);
    } else if (type == OBJECT_TYPE_DOCUMENT) {
        dbObject = new DBFile(repository, false, content);
    } else if (type == OBJECT_TYPE_BINARY) {
        dbObject = new DBFile(repository, true, content);
    } else {
        throw new DBBaseException(Messages.getString("DBMapper.THE_OBJECT_IS_UNKNOWN")); //$NON-NLS-1$
    }

    dbObject.setName(name);
    dbObject.setPath(path);
    dbObject.setCreatedBy(createdBy);
    dbObject.setCreatedAt(new java.util.Date(createdAt.getTime()));
    dbObject.setModifiedBy(modifiedBy);
    dbObject.setModifiedAt(new java.util.Date(modifiedAt.getTime()));

    return dbObject;
}

From source file:org.apache.hive.storage.jdbc.spitter.DateIntervalSplitter.java

@Override
public List<MutablePair<String, String>> getIntervals(String lowerBound, String upperBound, int numPartitions,
        TypeInfo typeInfo) {//from   w  w  w.j  av a 2 s  .  c o m
    List<MutablePair<String, String>> intervals = new ArrayList<>();
    Date dateLower = Date.valueOf(lowerBound);
    Date dateUpper = Date.valueOf(upperBound);
    double dateInterval = (dateUpper.getTime() - dateLower.getTime()) / (double) numPartitions;
    Date splitDateLower, splitDateUpper;
    for (int i = 0; i < numPartitions; i++) {
        splitDateLower = new Date(Math.round(dateLower.getTime() + dateInterval * i));
        splitDateUpper = new Date(Math.round(dateLower.getTime() + dateInterval * (i + 1)));
        if (splitDateLower.compareTo(splitDateUpper) < 0) {
            intervals
                    .add(new MutablePair<String, String>(splitDateLower.toString(), splitDateUpper.toString()));
        }
    }
    return intervals;
}

From source file:m.dekmak.Database.java

private static java.sql.Date getCurrentDate() {
    java.util.Date today = new java.util.Date();
    return new java.sql.Date(today.getTime());
}

From source file:de.interseroh.report.formatters.DateFormatter.java

@Override
public Date parse(String text, Locale locale) throws ParseException {
    java.util.Date parsed = getDateFormat(locale).parse(text);
    return new Date(parsed.getTime());
}

From source file:com.fusesource.examples.horo.db.typehandler.DateTimeTypeHandler.java

@Override
public DateTime getNullableResult(ResultSet rs, int i) throws SQLException {
    Date date = rs.getDate(i);
    return (date == null) ? null : new DateTime(date.getTime());
}