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.kfs.module.ar.document.service.impl.InvoiceRecurrenceDocumentServiceImpl.java

/**
 * @see org.kuali.kfs.module.ar.document.service.InvoiceRecurrenceService#isValidRecurrenceEndDate(Date)
 *//*from  ww w. java  2  s . co m*/
@Override
public boolean isValidRecurrenceEndDate(Date beginDate, Date endDate) {
    boolean isSuccess = true;
    if (ObjectUtils.isNull(beginDate) || ObjectUtils.isNull(endDate)) {
        return isSuccess;
    }
    Timestamp beginDateTimestamp = new Timestamp(beginDate.getTime());
    Timestamp endDateTimestamp = new Timestamp(endDate.getTime());
    if ((ObjectUtils.isNotNull(endDateTimestamp))
            && (endDateTimestamp.before(beginDateTimestamp) || endDateTimestamp.equals(beginDateTimestamp))) {
        return false;
    }
    return isSuccess;
}

From source file:org.wso2.ws.dataservice.DBUtils.java

/**
 * @param value - String value to be converted to time.Should be either in format "hh:mm:ss"
 * @param paramName - name given to parameter in data service configuration file
 * @return Time object containing passed value
 *//*ww  w  .  j  a va 2 s.  c  o m*/

private static Time getTime(String value, String paramName) throws AxisFault {
    java.sql.Time time;
    try {
        SimpleDateFormat sdf = new SimpleDateFormat("hh:mm:ss");
        java.util.Date date = sdf.parse(value);
        time = new java.sql.Time(date.getTime());
    } catch (ParseException e) {
        log.error(
                "Incorrect Time format for parameter : " + paramName + ".Time should be in the format hh:mm:ss",
                e);
        throw new AxisFault(
                "Incorrect Time format for parameter : " + paramName + ".Time should be in the format hh:mm:ss",
                e);
    }
    return time;
}

From source file:com.photon.phresco.eshop.service.EShopService.java

public Review getReviews(final int productId) throws EShopException {
    @SuppressWarnings("unchecked")
    Review review = (Review) template.execute(new HibernateCallback() {
        public Object doInHibernate(Session session) throws HibernateException, SQLException {
            Review review = new Review();
            review.setProductId(productId);
            review.setUserId(1);//from w w  w .j a v  a2  s.  com
            List<KeyValue> ratings = new ArrayList<KeyValue>(5);
            Rating rating = new Rating();
            int total = 0;

            for (int i = 1; i <= 5; i++) {
                List<Integer> count = session.createCriteria(ReviewHBM.class)
                        .setProjection(Projections.rowCount()).add(Restrictions.eq("ratings", i))
                        .add(Restrictions.eq("productId", productId)).list();
                System.out.println("count = " + count);
                int totalRating = (int) count.get(0);
                total += totalRating;
                System.out.println("Total Rating = " + totalRating);
                // reviewHBM.setTotalRating(totalRating);
                KeyValue keyvalue = new KeyValue(i, totalRating);
                ratings.add(keyvalue);
                rating.setRating(ratings);
                // reviews.add(reviewHBM);
            }

            Criteria crit = session.createCriteria(ReviewHBM.class)
                    .add(Restrictions.eq("productId", productId));
            ProjectionList p1 = Projections.projectionList();
            p1.add(Projections.property("comment"));
            p1.add(Projections.property("ratings"));
            p1.add(Projections.property("commentDate"));
            p1.add(Projections.property("userId"));

            crit.setProjection(p1);

            List<Comment> list = crit.list();

            Iterator iter = list.iterator();
            List<Comment> comments = new ArrayList<Comment>();
            while (iter.hasNext()) {
                Object[] obj = (Object[]) iter.next();
                Comment comment = null;
                for (int i = 0; i < obj.length; i++) {
                    comment = new Comment();
                    comment.setComment(obj[0].toString());
                    comment.setRatings((Integer) obj[1]);
                    java.sql.Date sqlDate = (java.sql.Date) obj[2];
                    java.util.Date utilDate = new java.util.Date(sqlDate.getTime());
                    comment.setCommentDate(utilDate);
                    comment.setUserid((Integer) obj[3]);
                    comments.add(comment);
                    Criteria criteria = session.createCriteria(UserHBM.class)
                            .add(Restrictions.eq("userId", (Integer) obj[3]));
                    ProjectionList p2 = Projections.projectionList();
                    p2.add(Projections.property("userName"));
                    criteria.setProjection(p2);

                    List listusername = criteria.list();
                    Iterator iter1 = listusername.iterator();
                    while (iter1.hasNext()) {
                        Object[] obj1 = (Object[]) iter.next();
                        for (int j = 0; j < obj1.length; j++) {
                            System.out.println("obj{j] value ---> " + obj1[j]);
                            comment.setUser((String) obj1[j]);
                        }
                    }
                }

            }

            int averateRating = ServiceUtil.getRating(total);
            review.setAverage(averateRating);
            review.setRatings(rating);
            review.setComments(comments);

            return review;
        }
    });

    return review;
}

From source file:de.tuttas.restful.AnwesenheitsManager.java

/**
 * Liste der Fehltage fr einen Schler ber einen Bereich
 *
 * @param httpHeaders auth_key zur Verifikation
 * @param sid ID des Schlers//w  w  w. j  av a  2s .  c om
 * @param from Bereich von
 * @param to Bereich bis
 * @return Liste von Anwesenheitsobjekten
 */
@GET
@Path("schueler/{sid}/{from}/{to}")
public List<AnwesenheitObjekt> getAnwesenheit(@PathParam("sid") int sid, @PathParam("from") Date from,
        @PathParam("to") Date to) {
    to = new Date(to.getTime() + 24 * 60 * 60 * 1000);
    Log.d("Webservice Anwesenheit GET from=" + from + " to=" + to);
    TypedQuery<AnwesenheitEintrag> query = em.createNamedQuery("findAnwesenheitbySchueler",
            AnwesenheitEintrag.class);
    query.setParameter("paramIdSchueler", sid);
    query.setParameter("paramFromDate", from);
    query.setParameter("paramToDate", to);
    List<AnwesenheitEintrag> anwesenheit = query.getResultList();

    Query qb = em.createNamedQuery("findBemerkungbyDate");
    qb.setParameter("paramFromDate", from);
    qb.setParameter("paramToDate", to);
    List<String> ids = new ArrayList<>();
    ids.add("" + sid);
    qb.setParameter("idList", ids);
    List<Bemerkung> bem = qb.getResultList();
    Log.d("Bemerkungen=" + bem);
    return getDataf(anwesenheit, bem);
}

From source file:de.tuttas.restful.AnwesenheitsManager.java

/**
 * Liste der Anwesenheit einer Klasse ber einen Bereich Adresse
 * /api/v1/anwesenheit/{Name der Klasse}/{von Datum}/{bis Datum}
 *
 * @param kl Name der Klasse/* www.j  a v a 2s  . com*/
 * @param from Startdatum (inclusiv)
 * @param to EndDatum (inclusiv)
 * @return Liste der Anwesenheitsobjekte
 */
@GET
@Path("/{klasse}/{from}/{to}")
public List<AnwesenheitObjekt> getAnwesenheit(@PathParam("klasse") String kl, @PathParam("from") Date from,
        @PathParam("to") Date to) {
    to = new Date(to.getTime() + 24 * 60 * 60 * 1000);
    Log.d("Webservice Anwesenheit GET from=" + from + " to=" + to);
    TypedQuery<AnwesenheitEintrag> query = em.createNamedQuery("findAnwesenheitbyKlasse",
            AnwesenheitEintrag.class);
    query.setParameter("paramKName", kl);
    query.setParameter("paramFromDate", from);
    query.setParameter("paramToDate", to);

    List<AnwesenheitEintrag> anwesenheit = query.getResultList();

    Query qb = em.createNamedQuery("findBemerkungbyDate");
    qb.setParameter("paramFromDate", from);
    qb.setParameter("paramToDate", to);

    List<String> ids = new ArrayList<>();
    for (AnwesenheitEintrag ae : anwesenheit) {
        ids.add("" + ae.getID_SCHUELER());
    }
    List<Bemerkung> bemerkungen = null;
    qb.setParameter("idList", ids);
    if (ids.size() > 0) {
        bemerkungen = qb.getResultList();
        Log.d("Result List Bemerkunken:" + bemerkungen);
    }
    return getData(anwesenheit, bemerkungen);
}

From source file:org.apache.nifi.csv.TestCSVRecordReader.java

@Test
public void testDate() throws IOException, MalformedRecordException {
    final String text = "date\n11/30/1983";

    final List<RecordField> fields = new ArrayList<>();
    fields.add(new RecordField("date", RecordFieldType.DATE.getDataType()));
    final RecordSchema schema = new SimpleRecordSchema(fields);

    try (final InputStream bais = new ByteArrayInputStream(text.getBytes());
            final CSVRecordReader reader = new CSVRecordReader(bais, Mockito.mock(ComponentLog.class), schema,
                    format, true, false, "MM/dd/yyyy", RecordFieldType.TIME.getDefaultFormat(),
                    RecordFieldType.TIMESTAMP.getDefaultFormat(), "UTF-8")) {

        final Record record = reader.nextRecord();
        final java.sql.Date date = (Date) record.getValue("date");
        final Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("gmt"));
        calendar.setTimeInMillis(date.getTime());

        assertEquals(1983, calendar.get(Calendar.YEAR));
        assertEquals(10, calendar.get(Calendar.MONTH));
        assertEquals(30, calendar.get(Calendar.DAY_OF_MONTH));
    }/* www .j  a  v a 2  s  . c  om*/
}

From source file:org.apache.nifi.csv.TestJacksonCSVRecordReader.java

@Test
public void testDate() throws IOException, MalformedRecordException {
    final String text = "date\n11/30/1983";

    final List<RecordField> fields = new ArrayList<>();
    fields.add(new RecordField("date", RecordFieldType.DATE.getDataType()));
    final RecordSchema schema = new SimpleRecordSchema(fields);

    try (final InputStream bais = new ByteArrayInputStream(text.getBytes());
            final JacksonCSVRecordReader reader = new JacksonCSVRecordReader(bais,
                    Mockito.mock(ComponentLog.class), schema, format, true, false, "MM/dd/yyyy",
                    RecordFieldType.TIME.getDefaultFormat(), RecordFieldType.TIMESTAMP.getDefaultFormat(),
                    "UTF-8")) {

        final Record record = reader.nextRecord();
        final Date date = (Date) record.getValue("date");
        final Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("gmt"));
        calendar.setTimeInMillis(date.getTime());

        assertEquals(1983, calendar.get(Calendar.YEAR));
        assertEquals(10, calendar.get(Calendar.MONTH));
        assertEquals(30, calendar.get(Calendar.DAY_OF_MONTH));
    }//from   ww  w. java  2 s .  c  o m
}

From source file:org.kuali.kfs.module.ar.document.service.impl.InvoiceRecurrenceDocumentServiceImpl.java

/**
 * @see org.kuali.kfs.module.ar.document.service.InvoiceRecurrenceService#isValidRecurrenceBeginDate(Date)
 *///from  w  ww.ja v  a 2s . c  o m
@Override
public boolean isValidRecurrenceBeginDate(Date beginDate) {
    boolean isSuccess = true;
    if (ObjectUtils.isNull(beginDate)) {
        return isSuccess;
    }
    Timestamp currentDate = new Timestamp(dateTimeService.getCurrentDate().getTime());
    Timestamp beginDateTimestamp = new Timestamp(beginDate.getTime());
    if (beginDateTimestamp.before(currentDate) || beginDateTimestamp.equals(currentDate)) {
        return false;
    }
    return isSuccess;
}

From source file:org.wso2.ws.dataservice.DBUtils.java

/**
 * @param value - String value to be converted to timestamp.
 * Should be either in format "yyyy-MM-dd hh:mm:ss" or "yyyy-MM-dd hh:mm:ss.SSSSSS"
 * @param paramName - name given to parameter in data service configuration file
 * @return Timestamp object containing passed value
 *//*from  ww  w.  ja  v a 2  s  .  c  o  m*/
private static Timestamp getTimestamp(String value, String paramName) throws AxisFault {
    java.sql.Timestamp timestamp = null;
    SimpleDateFormat sdf;
    try {
        sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss.SSSSSS");
        java.util.Date date = sdf.parse(value);
        timestamp = new java.sql.Timestamp(date.getTime());
    } catch (ParseException e) {
        try {
            sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
            java.util.Date date = sdf.parse(value);
            timestamp = new java.sql.Timestamp(date.getTime());
        } catch (ParseException e1) {
            sdf = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss.sss'Z'");
            try {
                java.util.Date date = sdf.parse(value);
                timestamp = new java.sql.Timestamp(date.getTime());
            } catch (ParseException e2) {
                try {
                    sdf = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss.sss'+'hh:mm");
                    java.util.Date date = sdf.parse(value);
                    timestamp = new java.sql.Timestamp(date.getTime());
                } catch (ParseException e3) {
                    try {
                        sdf = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss.sss'-'hh:mm");
                        java.util.Date date = sdf.parse(value);
                        timestamp = new java.sql.Timestamp(date.getTime());
                    } catch (ParseException e4) {
                        try {
                            sdf = new SimpleDateFormat("yyyy-MM-dd");
                            java.util.Date date = sdf.parse(value);
                            timestamp = new java.sql.Timestamp(date.getTime());
                        } catch (ParseException e5) {
                            log.error("Incorrect Timestamp format for parameter : " + paramName
                                    + ".Timestamp should be in one of following formats "
                                    + "yyyy-MM-dd'T'hh:mm:ss.sss'+'hh:mm, "
                                    + "yyyy-MM-dd'T'hh:mm:ss.sss'-'hh:mm, " + "yyyy-MM-dd'T'hh:mm:ss.sss'Z', "
                                    + "yyyy-MM-dd hh:mm:ss.SSSSSS or " + "yyyy-MM-dd hh:mm:ss", e5);
                            throw new AxisFault("Incorrect Timestamp format for parameter : " + paramName
                                    + ".Timestamp should be in one of following formats "
                                    + "yyyy-MM-dd'T'hh:mm:ss.sss'+'hh:mm, "
                                    + "yyyy-MM-dd'T'hh:mm:ss.sss'-'hh:mm, " + "yyyy-MM-dd'T'hh:mm:ss.sss'Z', "
                                    + "yyyy-MM-dd hh:mm:ss.SSSSSS or " + "yyyy-MM-dd hh:mm:ss", e5);
                        }
                    }
                }
            }
        }
    }
    return timestamp;
}

From source file:org.apache.sqoop.mapreduce.hcat.SqoopHCatExportHelper.java

private Object convertStringTypes(Object val, String javaColType) {
    String valStr = val.toString();
    if (javaColType.equals(BIG_DECIMAL_TYPE)) {
        return new BigDecimal(valStr);
    } else if (javaColType.equals(DATE_TYPE) || javaColType.equals(TIME_TYPE)
            || javaColType.equals(TIMESTAMP_TYPE)) {
        // Oracle expects timestamps for Date also by default based on version
        // Just allow all date types to be assignment compatible
        if (valStr.length() == 10 && valStr.matches("^\\d{4}-\\d{2}-\\d{2}$")) {
            // Date in yyyy-mm-dd format
            Date d = Date.valueOf(valStr);
            if (javaColType.equals(DATE_TYPE)) {
                return d;
            } else if (javaColType.equals(TIME_TYPE)) {
                return new Time(d.getTime());
            } else if (javaColType.equals(TIMESTAMP_TYPE)) {
                return new Timestamp(d.getTime());
            }//from  www .  j a v a 2 s  .c o  m
        } else if (valStr.length() == 8 && valStr.matches("^\\d{2}:\\d{2}:\\d{2}$")) {
            // time in hh:mm:ss
            Time t = Time.valueOf(valStr);
            if (javaColType.equals(DATE_TYPE)) {
                return new Date(t.getTime());
            } else if (javaColType.equals(TIME_TYPE)) {
                return t;
            } else if (javaColType.equals(TIMESTAMP_TYPE)) {
                return new Timestamp(t.getTime());
            }
        } else if (valStr.length() >= 19 && valStr.length() <= 26
                && valStr.matches("^\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}(.\\d+)?$")) {
            // timestamp in yyyy-mm-dd hh:mm:ss
            Timestamp ts = Timestamp.valueOf(valStr);
            if (javaColType.equals(DATE_TYPE)) {
                return new Date(ts.getTime());
            } else if (javaColType.equals(TIME_TYPE)) {
                return new Time(ts.getTime());
            } else if (javaColType.equals(TIMESTAMP_TYPE)) {
                return ts;
            }
        } else {
            return null;
        }
    } else if (javaColType.equals(STRING_TYPE)) {
        return valStr;
    } else if (javaColType.equals(BOOLEAN_TYPE)) {
        return Boolean.valueOf(valStr);
    } else if (javaColType.equals(BYTE_TYPE)) {
        return Byte.parseByte(valStr);
    } else if (javaColType.equals(SHORT_TYPE)) {
        return Short.parseShort(valStr);
    } else if (javaColType.equals(INTEGER_TYPE)) {
        return Integer.parseInt(valStr);
    } else if (javaColType.equals(LONG_TYPE)) {
        return Long.parseLong(valStr);
    } else if (javaColType.equals(FLOAT_TYPE)) {
        return Float.parseFloat(valStr);
    } else if (javaColType.equals(DOUBLE_TYPE)) {
        return Double.parseDouble(valStr);
    }
    return null;
}