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.psystems.dicom.browser.server.stat.StatDailyLoadChartServlet2.java

/**
 * @param connection/* w  w w .  j  av  a  2  s .  c  om*/
 * @param series
 * @param metrica
 * @param timeBegin
 * @param timeEnd
 * @param dataset
 * @throws SQLException
 */
private void getMetrics(Connection connection, String series, String metrica, Calendar calendarBegin,
        Calendar calendarEnd, DefaultCategoryDataset dataset) throws SQLException {

    PreparedStatement stmt = null;
    try {

        SimpleDateFormat format = new SimpleDateFormat("dd.MM.yyyy");

        Calendar calendar1 = (Calendar) calendarBegin.clone();
        String dateStr = format.format(calendar1.getTime());
        dataset.addValue(0, series, dateStr);
        for (int i = 0; i < 6; i++) {
            calendar1.add(Calendar.DAY_OF_MONTH, 1);
            dateStr = format.format(calendar1.getTime());
            dataset.addValue(0, series, dateStr);
        }

        stmt = connection.prepareStatement("SELECT METRIC_VALUE_LONG, METRIC_DATE"
                + " FROM WEBDICOM.DAYSTAT WHERE METRIC_NAME = ? and " + " METRIC_DATE BETWEEN ? AND ? ");

        stmt.setString(1, metrica);
        stmt.setDate(2, new java.sql.Date(calendarBegin.getTimeInMillis()));
        stmt.setDate(3, new java.sql.Date(calendarEnd.getTimeInMillis()));
        ResultSet rs = stmt.executeQuery();

        while (rs.next()) {
            long value = rs.getLong("METRIC_VALUE_LONG") / 1000;
            Date date = rs.getDate("METRIC_DATE");
            dateStr = format.format(date.getTime());
            String category = dateStr;
            dataset.addValue(value, series, category);
            //            System.out.println(value + " = " + series + " = "+ category);
        }
        rs.close();

    } finally {
        if (stmt != null)
            stmt.close();
    }
}

From source file:org.wso2.carbon.dataservices.core.DBUtils.java

/**
 * Create a Date object from the given date string.
 *///from  w  w  w .jav  a 2 s.  com
public static Date getDate(String value) throws DataServiceFault {
    /* if something goes wrong with converting the value to a date,
       * try with dateTime and get the date out it, this is because,
       * some service clients send a full date-time string for a date */
    try {
        java.util.Date date = ConverterUtil.convertToDate(value);
        if (null == date) {
            throw new DataServiceFault("Empty string or null value was found as date.");
        } else {
            return new Date(date.getTime());
        }
    } catch (Exception e) {
        java.util.Calendar calendarDate = ConverterUtil.convertToDateTime(value);
        if (null == calendarDate) {
            throw new DataServiceFault("Empty string or null value was found as date.");
        } else {
            return new Date(calendarDate.getTimeInMillis());
        }
    }
}

From source file:com.ar.hotwiredautorepairshop.controller.ServiceOrderController.java

@RequestMapping(value = "/serviceOrders/register/new", method = RequestMethod.POST)
public ServiceOrder registerServiceOrder(@RequestParam(value = "customerSSN") String customerSSN,
        @RequestParam(value = "licensePlate") String licensePlate,
        @RequestParam(value = "mechanicSSN") String mechanicSSN,
        @RequestParam(value = "serviceDate") String serviceDate,
        @RequestParam(value = "pickupDate") String pickupDate,
        @RequestParam(value = "workTypeIds") List<String> workTypeIds,
        @RequestParam(value = "complaintId") Integer complaintId) {
    ServiceOrder newServiceOrder = new ServiceOrder();
    java.util.Date utilDate = new java.util.Date();
    Date registrationDate = new Date(utilDate.getTime());
    newServiceOrder.setRegistrationDate(registrationDate);

    Customer customer = customerRepository.findOne(customerSSN);
    Mechanic mechanic = mechanicRepository.findOne(mechanicSSN);
    Car car = carRepository.findOne(licensePlate);

    if (!mechanic.getCarsInProgress().contains(car)) {
        mechanic.getCarsInProgress().add(car);
    }/*from w w  w.  ja v a 2 s  . c o  m*/

    if (complaintId != null) {
        newServiceOrder.setComplaint(complaintRepository.findOne(complaintId));
    }

    newServiceOrder.setCustomer(customer);
    newServiceOrder.setCar(car);

    newServiceOrder.setMechanic(mechanic);
    newServiceOrder.setServiceDate(Date.valueOf(serviceDate));
    newServiceOrder.setPickupDate(Date.valueOf(pickupDate));
    int totalPrice = 0;

    for (String workTypeId : workTypeIds) {
        WorkType workType = workTypeRepository.findOne(Integer.parseInt(workTypeId));
        newServiceOrder.getWorkTypes().add(workType);
        totalPrice += workType.getPrice();
    }
    newServiceOrder.setTotalPrice(totalPrice);
    newServiceOrder.setActive(true);
    serviceOrderRepository.save(newServiceOrder);

    return newServiceOrder;
}

From source file:org.kuali.kfs.pdp.dataaccess.impl.PaymentDetailDaoOjb.java

/**
 * @see org.kuali.kfs.pdp.dataaccess.PaymentDetailDao#getDisbursementNumberRanges(java.lang.String)
 *///from w  w w  .j  ava  2 s  . c o  m
@Override
public List<DisbursementNumberRange> getDisbursementNumberRanges(String campus) {
    LOG.debug("getDisbursementNumberRanges() started");

    java.util.Date now = new java.util.Date();
    Timestamp nowTs = new Timestamp(now.getTime());

    Criteria criteria = new Criteria();
    criteria.addLessOrEqualThan(PdpPropertyConstants.DISBURSEMENT_NUMBER_RANGE_START_DATE, nowTs);
    criteria.addEqualTo(PdpPropertyConstants.PHYS_CAMPUS_PROC_CODE, campus);
    criteria.addEqualTo(KFSPropertyConstants.ACTIVE, true);

    QueryByCriteria qbc = new QueryByCriteria(DisbursementNumberRange.class, criteria);
    qbc.addOrderBy(KFSPropertyConstants.BANK_CODE, true);

    return (List<DisbursementNumberRange>) getPersistenceBrokerTemplate().getCollectionByQuery(qbc);
}

From source file:com.ar.hotwiredautorepairshop.controller.ServiceOrderController.java

@RequestMapping(value = "/serviceOrders/register/newFromComplaint", method = RequestMethod.POST)
public ServiceOrder registerServiceOrderFromComplaint(
        @RequestParam(value = "serviceOrderId") Integer serviceOrderId,
        @RequestParam(value = "complaintId") Integer complaintId) {
    ServiceOrder oldServiceOrder = serviceOrderRepository.findOne(serviceOrderId);
    ServiceOrder newServiceOrder = new ServiceOrder();

    java.util.Date utilDate = new java.util.Date();
    Date registrationDate = new Date(utilDate.getTime());
    newServiceOrder.setRegistrationDate(registrationDate);

    String customerSSN = oldServiceOrder.getCustomer().getSocialSecurityNumber();
    String mechanicSSN = oldServiceOrder.getMechanic().getSocialSecurityNumber();
    String licensePlate = oldServiceOrder.getCar().getLicensePlate();
    Customer customer = customerRepository.findOne(customerSSN);
    Mechanic mechanic = mechanicRepository.findOne(mechanicSSN);
    Car car = carRepository.findOne(licensePlate);

    if (!mechanic.getCarsInProgress().contains(car)) {
        mechanic.getCarsInProgress().add(car);
    }/*  ww  w  .j  ava 2s  .com*/

    Complaint complaint = complaintRepository.findOne(complaintId);
    complaint.setActive(false);
    newServiceOrder.setComplaint(complaint);

    newServiceOrder.setCustomer(customer);
    newServiceOrder.setCar(car);
    newServiceOrder.setMechanic(mechanic);

    Calendar calendar = Calendar.getInstance();
    calendar.setTime(registrationDate);
    calendar.add(Calendar.DATE, 7);

    Date serviceDate = new Date(calendar.getTimeInMillis());

    calendar.setTime(serviceDate);
    calendar.add(Calendar.DATE, 7);

    Date pickUpDate = new Date(calendar.getTimeInMillis());

    newServiceOrder.setServiceDate(serviceDate);
    newServiceOrder.setPickupDate(pickUpDate);
    int totalPrice = 0;

    for (WorkType workType : complaint.getWorkTypes()) {
        newServiceOrder.getWorkTypes().add(workType);
        totalPrice += workType.getPrice();
    }
    newServiceOrder.setTotalPrice(totalPrice);
    newServiceOrder.setActive(true);
    serviceOrderRepository.save(newServiceOrder);

    return newServiceOrder;
}

From source file:com.ar.hotwiredautorepairshop.controller.CustomerController.java

private Integer calculateAge(String socialSecurityNumber) {

    socialSecurityNumber = socialSecurityNumber.substring(0, 8);
    java.util.Date dateParsed = new java.util.Date();
    try {/* ww  w  .j  a va 2 s.  c o  m*/
        dateParsed = new SimpleDateFormat("yyyyMMdd").parse(socialSecurityNumber);
    } catch (ParseException e) {
    }
    Date customerDate = new Date(dateParsed.getTime());

    Calendar dateOfBirth = Calendar.getInstance();
    dateOfBirth.setTime(customerDate);
    Calendar today = Calendar.getInstance();
    int age = today.get(Calendar.YEAR) - dateOfBirth.get(Calendar.YEAR);

    if (today.get(Calendar.MONTH) < dateOfBirth.get(Calendar.MONTH)) {
        age--;
    } else if (today.get(Calendar.MONTH) == dateOfBirth.get(Calendar.MONTH)
            && today.get(Calendar.DAY_OF_MONTH) < dateOfBirth.get(Calendar.DAY_OF_MONTH)) {
        age--;
    }
    return age;
}

From source file:org.kuali.kfs.coa.businessobject.AccountDelegateGlobalDetail.java

public AccountDelegateGlobalDetail(AccountDelegateModelDetail model) {
    accountDelegatePrimaryRoutingIndicator = model.getAccountDelegatePrimaryRoutingIndicator();
    // KFSCNTRB-1403: don't populate the account delegate with the start date inherited from the model, just put today's date there
    //accountDelegateStartDate = model.getAccountDelegateStartDate();
    java.util.Date utilDate = new java.util.Date(); // default C'Tor for java.util.Date populates the date with the current date
    accountDelegateStartDate = new java.sql.Date(utilDate.getTime()); // now populate accountDelegateStartDate
    accountDelegateUniversalId = model.getAccountDelegateUniversalId();
    approvalFromThisAmount = model.getApprovalFromThisAmount();
    approvalToThisAmount = model.getApprovalToThisAmount();
    financialDocumentTypeCode = model.getFinancialDocumentTypeCode();
}

From source file:data.DefaultExchanger.java

protected Long date(Date date) {
    if (date != null) {
        return date.getTime();
    } else {/*w w  w  . j ava 2  s . c  o  m*/
        return null;
    }
}

From source file:com.cemeterylistingsweb.services.impl.ViewListingByGraveNumberServiceImpl.java

@Override
public List<PublishedDeceasedListing> findListingByGraveNumber(String number, Long SubId) {
    List<PublishedDeceasedListing> lists = publishRepo.findAll();
    Subscriber sub = subRepo.findOne(SubId);

    List<PublishedDeceasedListing> list = new ArrayList();
    for (PublishedDeceasedListing pubListing : lists) {

        SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy");
        Date parsed = null;
        try {/*from  w ww.j  a  v a 2 s . co  m*/
            parsed = (Date) format.parse(pubListing.getDateOfDeath());
        } catch (ParseException ex) {
            Logger.getLogger(ViewListingBySubscriberServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
        }
        java.sql.Date dod = new java.sql.Date(parsed.getTime());

        if (pubListing.getGraveNumber().equals(number) && dod.after(sub.getSubscriptionDate())
                && dod.before(sub.getValidUntil()))
            list.add(pubListing);
    }

    return list;
}

From source file:com.cemeterylistingsweb.services.impl.ViewListingByCemeteryImpl.java

@Override
public List<PublishedDeceasedListing> findListingByCemetery(Long cemId, Long subId) {
    ///*  w ww  .ja  v  a  2 s.  co m*/
    List<PublishedDeceasedListing> deceasedList = deadRepo.findAll();
    List<PublishedDeceasedListing> Listings = new ArrayList();
    Subscriber sub = subRepo.findOne(subId);

    for (PublishedDeceasedListing listing : deceasedList) {

        SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy");
        Date parsed = null;
        try {
            parsed = (Date) format.parse(listing.getDateOfDeath());
        } catch (ParseException ex) {
            Logger.getLogger(ViewListingBySubscriberServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
        }
        java.sql.Date dod = new java.sql.Date(parsed.getTime());

        if (listing.getCemeteryID().equals(cemId) && dod.after(sub.getSubscriptionDate())
                && dod.before(sub.getLastContributionYear())) {
            //add to list
            Listings.add(listing);
        }
    }
    return Listings;
}