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:org.kuali.coeus.common.budget.impl.summary.BudgetSummaryServiceImpl.java

protected Date add(Date date, int days) {
    Calendar c1 = Calendar.getInstance();
    c1.setTime(new java.util.Date(date.getTime()));
    c1.add(Calendar.DATE, days);//w ww.j  a va2  s .co m
    return new java.sql.Date(c1.getTime().getTime());

}

From source file:fr.certu.chouette.exchange.gtfs.importer.NeptuneConverter.java

private Date cloneDateAfterMidnight(Date source) {
    return new Date(source.getTime() + dayOffest);
}

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

/**
 *
 * @param beginDate//from  www  . j a  v  a2s.co m
 * @param endDate
 * @param siteId
 */
public void getPatientRegister(Date beginDate, Date endDate, int siteId) {

    PreparedStatement ps = null;
    ResultSet rs = null;
    String sql = null;
    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();
    }

    Connection conn = null;

    try {
        conn = DatabaseUtils.getZEPRSConnection(org.rti.zcore.Constants.DATABASE_ADMIN_USERNAME);

        ReportCreator reportCreator = this.getReportCreator();
        String username = reportCreator.getUsernameR();
        UserInfoReport userInfo = (UserInfoReport) EncountersDAO.getOneReportById(conn, username,
                "SQL_RETRIEVE_REPORT_ID_ADMIN170", UserInfoReport.class);
        reportCreator.setEmailR(userInfo.getEmailR()); // email
        reportCreator.setFirstnameR(userInfo.getForenamesR()); // firstname
        reportCreator.setLastnameR(userInfo.getLastnameR()); // lastname
        reportCreator.setMobileR(userInfo.getMobileR()); // mobile
        reportCreator.setPhoneR(userInfo.getPhoneR()); // phone

        regimenList = new ArrayList<RegimenReport>();
        HashMap<String, RegimenReport> regimenSpecMap = new HashMap<String, RegimenReport>();

        // Now get stats for ART regimens
        artRegimenReport = new ARTReport();
        newEstimatedArtPatients = new ARTReport();
        totalEstimatedArtPatients = new ARTReport();

        try {
            rs = getArtRegimens(conn, siteId, beginDate, endDate, "ASC");
            while (rs.next()) {

                Integer age = rs.getInt("age");
                Integer regimenGroup = rs.getInt("regimen_group_id");
                String code = rs.getString("code");
                String name = rs.getString("name");
                Long patientId = rs.getLong("patient_id");
                Date dateVisit = rs.getDate("date_visit");
                int sex = rs.getInt("sex");
                Integer ageCategory = rs.getInt("age_category");

                /*Long encounterId = rs.getLong("id");
                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");
                int currentSiteId = rs.getInt("site_id");
                String createdBy = rs.getString("created_by");
                Timestamp created = rs.getTimestamp("created");*/

                ARTPatient patient = new ARTPatient();

                switch (ageCategory) {
                case 3283:
                    patient.setChildOrAdult("A");
                    break;
                case 3284:
                    patient.setChildOrAdult("C");
                    break;
                default:
                    patient.setChildOrAdult("A");
                    break;
                }

                /*if (this.getDynamicReport() != null && this.getDynamicReport() == true) {
                   RegimenReport regimenReport = regimenSpecMap.get(code);
                   if (regimenReport == null) {
                      regimenReport = new RegimenReport();
                      regimenReport.setCode(code);
                      regimenReport.setName(name);
                      regimenReport.setRegimenGroup(regimenGroup);
                      regimenSpecMap.put(code, regimenReport);
                   }
                   int countInt = regimenReport.getCountInt();
                   countInt ++;
                   regimenReport.setCountInt(countInt);
                } else {*/
                // increment the totals
                /*if (age != null && age > 14) {
                   int n = artRegimenReport.getTotalAdults();
                   n++;
                   artRegimenReport.setTotalAdults(n);
                }
                if (age != null && age <= 14) {
                   int n = artRegimenReport.getTotalChildren();
                   n++;
                   artRegimenReport.setTotalChildren(n);
                }*/

                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()) {
                    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);

                //log.debug("new regimen: " + code);
                RegimenReport regimenReport = regimenSpecMap.get(code);
                if (regimenReport == null) {
                    regimenReport = new RegimenReport();
                    regimenReport.setCode(code);
                    regimenReport.setName(name);
                    regimenReport.setRegimenGroup(regimenGroup);
                    regimenSpecMap.put(code, regimenReport);
                }
                int countInt = regimenReport.getCountInt();
                countInt++;
                regimenReport.setCountInt(countInt);
                //}

                /*if (patient != null) {
                // 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);
                } else {
                   patient.setRevisit(true);
                }
                this.addPatient(patient);
                if (patientMap.get(patient.getPatientId()) != null) {
                       ARTAdultPatient encounter = (ARTAdultPatient) patientMap.get(patient.getPatientId());
                        encounters.add(patient);
                    } else {
                       patientMap.put(patient.getPatientId(), patient);
                    }
                }*/
                //}
            }

            artRegimenReport.setRegimenReportMap(regimenReportMap);
            /*
                        //if (this.getDynamicReport() != null && this.getDynamicReport() == true) {
                        Set<Entry<String,RegimenReport>> set = map.entrySet();
                        for (Entry<String, RegimenReport> entry : set) {
                           RegimenReport report = entry.getValue();
                           regimenList.add(report);
                        }
                        Collections.sort(regimenList, new SiteStatisticsDAO().new CodeComparator());
                        //}
            */
            // Sort out the view spec
            regimenMap = InventoryUtils.populateRegimenMap(conn);
            ArrayList<ReportDisplay> reportDisplayList = new ArrayList<ReportDisplay>();
            String filename = org.rti.zcore.Constants.getPathToCatalinaHome() + "databases" + File.separator
                    + "regimens.txt";
            for (String line : new TextFile(filename)) {
                //System.out.println(line);
                String[] lineArray = line.split("\\|");
                if (lineArray[0].startsWith("regimen")) {
                    String title = null;
                    String regimenCode = null;
                    Integer value = null;
                    Integer newEstimatedArtPatientsValue = null;
                    Integer totalEstimatedArtPatientsValue = null;
                    String alternateCode = null;
                    String rowNum = lineArray[1];
                    Integer rowInt = Integer.valueOf(rowNum) - 1;
                    String cellNumStr = lineArray[2];
                    int cellNum = Integer.valueOf(cellNumStr) - 1;
                    if (lineArray.length > 3) {
                        regimenCode = lineArray[3];
                        value = regimenReportMap.get("regimen" + regimenCode);
                        //value = regimenReportMap.get(regimenCode);
                        newEstimatedArtPatientsValue = newEstimatedArtPatients.getRegimenReportMap()
                                .get(regimenCode);
                        totalEstimatedArtPatientsValue = totalEstimatedArtPatients.getRegimenReportMap()
                                .get(regimenCode);
                    }
                    if (lineArray.length > 4) {
                        alternateCode = lineArray[4];
                    }
                    RegimenReport regimenReport = regimenSpecMap.get(regimenCode);
                    if (regimenReport != null) {
                        title = regimenReport.getName();
                    } else {
                        Regimen regimen = regimenMap.get(regimenCode);
                        if (regimen != null) {
                            title = regimen.getName();
                        }
                    }
                    ReportDisplay reportDisplay = new ReportDisplay("regimen", title, value, regimenCode, null,
                            newEstimatedArtPatientsValue, totalEstimatedArtPatientsValue, alternateCode);
                    reportDisplayList.add(reportDisplay);
                } else if (lineArray[0].equals("header") || lineArray[0].equals("subheader")) {
                    String rowNum = lineArray[1];
                    Integer rowInt = Integer.valueOf(rowNum) - 1;
                    String cellNumStr = lineArray[2];
                    int cellNum = Integer.valueOf(cellNumStr) - 1;
                    String title = lineArray[3];
                    String title2 = null;
                    if (lineArray.length > 4) {
                        if (lineArray[4] != null) {
                            title2 = lineArray[4];
                        }
                    }
                    ReportDisplay reportDisplay = new ReportDisplay("header", title, null, null, title2, null,
                            null, null);
                    reportDisplayList.add(reportDisplay);
                }
            }

            this.setReportDisplayList(reportDisplayList);

        } catch (Exception e) {
            e.printStackTrace();
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        try {
            conn.close();
        } catch (SQLException e) {
            log.error(e);
        }

    }
}

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

/**
 * getAgeAtVisit()/* w w  w. j a  va2  s .  com*/
 *
 * @param dateVisit
 * @param birthDate
 * @return The age of the patient on the visit date
 */
public static int getAgeAtVisit(Date dateVisit, Date birthDate) {

    long difference = dateVisit.getTime() - birthDate.getTime();

    // return (int) (difference / (60 * 60 * 24 * 365 * 1000));
    return (int) (difference / 1471228928);
}

From source file:de.axelfaust.alfresco.nashorn.repo.loaders.AbstractNodeScriptFile.java

/**
 * {@inheritDoc}/* w ww  .ja v a  2s  .co m*/
 */
@Override
public long getLastModified(final boolean force) {
    final Date modified = this.retryingTransactionHelper
            .doInTransaction(new RetryingTransactionCallback<Date>() {

                /**
                 * {@inheritDoc}
                 */
                @Override
                public Date execute() {
                    final Serializable value = AbstractNodeScriptFile.this.nodeService
                            .getProperty(AbstractNodeScriptFile.this.nodeRef, ContentModel.PROP_MODIFIED);
                    final Date modified = DefaultTypeConverter.INSTANCE.convert(Date.class, value);
                    return modified;
                }
            });

    final long lastModified = modified != null ? modified.getTime() : System.currentTimeMillis();

    if (this.cacheLastModified != -1 && lastModified > this.cacheLastModified) {
        synchronized (this) {
            this.size = -1;
            this.cacheFile.delete();
        }
    }

    return lastModified;
}

From source file:org.kuali.coeus.common.committee.impl.bo.CommitteeScheduleBase.java

public Timestamp getStartTime() {
    if (startTime == null || startTime.getTime() == 0) {
        java.util.Date dt = new java.util.Date(0);
        dt = DateUtils.round(dt, Calendar.DAY_OF_MONTH);
        if (viewStartTime != null) {
            dt = DateUtils.addMinutes(dt, viewStartTime.findMinutes());
            // dt = DateUtils.addMinutes(dt, getViewTime().findMinutes());
        }/*from   w  w  w  .  j a  v a 2 s . co  m*/
        this.startTime = new Timestamp(dt.getTime());
    }

    return startTime;
}

From source file:net.sf.jasperreports.engine.JRResultSetDataSource.java

protected Object readDate(Integer columnIndex, JRField field) throws SQLException {
    Calendar calendar = getFieldCalendar(field);
    java.sql.Date objValue = calendar == null ? resultSet.getDate(columnIndex)
            : resultSet.getDate(columnIndex, calendar);
    if (resultSet.wasNull()) {
        objValue = null;/*w w w.j av a  2s . c  o  m*/
    }
    if (log.isDebugEnabled()) {
        log.debug("date field " + field.getName() + " is "
                + (objValue == null ? "null" : (objValue + " (" + objValue.getTime() + ")")));
    }
    return objValue;
}

From source file:nl.ordina.bag.etl.dao.AbstractBAGMutatiesDAO.java

@Override
public long insertMutatiesFile(final java.util.Date dateFrom, final java.util.Date dateTo, final byte[] content)
        throws DAOException {
    try {/* ww  w. ja  v a2s  . c o  m*/
        KeyHolder keyHolder = new GeneratedKeyHolder();
        jdbcTemplate.update(new PreparedStatementCreator() {
            @Override
            public PreparedStatement createPreparedStatement(Connection connection) throws SQLException {
                PreparedStatement ps = connection.prepareStatement("insert into bag_mutaties_file (" + " id,"
                        + " date_from," + " date_to," + " content"
                        + ") values ((select nvl(max(id),0) + 1 from bag_mutaties_file),trunc(?),trunc(?),?)",
                        new int[] { 1 });
                ps.setDate(1, new Date(dateFrom.getTime()));
                ps.setDate(2, new Date(dateTo.getTime()));
                ps.setBytes(3, content);
                return ps;
            }
        }, keyHolder);
        return keyHolder.getKey().longValue();
    } catch (DataAccessException e) {
        throw new DAOException(e);
    }
}

From source file:org.kuali.coeus.common.committee.impl.bo.CommitteeScheduleBase.java

public Timestamp getEndTime() {
    if (endTime == null || endTime.getTime() == 0) {
        java.util.Date dt = new java.util.Date(0); // set to 1969/12/31 19:00 ?
        dt = DateUtils.round(dt, Calendar.DAY_OF_MONTH); // force it to 1970-01-01
        if (viewEndTime != null) {
            dt = DateUtils.addMinutes(dt, viewEndTime.findMinutes());
            // dt = DateUtils.addMinutes(dt, getViewTime().findMinutes());
        }/*from w w  w  .j  a  va  2  s. c o m*/
        this.endTime = new Timestamp(dt.getTime());
    }
    return endTime;
}

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

public static int getCurrentAge(Date birthDate) {

    Calendar cal = new GregorianCalendar();
    long now = cal.getTimeInMillis();

    long ageInMillis = now - birthDate.getTime();

    // for some strange reason, dividing by the number of millis
    // in a year directly does not produce the proper result, so
    // instead I divide by the number of millis in a day, then
    // divide again by the number of days in a year
    Long age = new Long((ageInMillis / (1000 * 60 * 60 * 24)) / 365);

    return age.intValue();
}