Example usage for javax.persistence TemporalType TIME

List of usage examples for javax.persistence TemporalType TIME

Introduction

In this page you can find the example usage for javax.persistence TemporalType TIME.

Prototype

TemporalType TIME

To view the source code for javax.persistence TemporalType TIME.

Click Source Link

Document

Map as java.sql.Time

Usage

From source file:org.lightadmin.core.persistence.metamodel.PersistentPropertyType.java

private static boolean isOfTimeType(PersistentProperty persistentProperty) {
    Class attrType = persistentProperty.getType();

    if (java.sql.Time.class.equals(attrType)) {
        return true;
    }/*from  w w w  .  j  a v  a 2s  .  c  o  m*/

    if (LocalTime.class.equals(attrType)) {
        return true;
    }

    if (Date.class.equals(attrType) || Calendar.class.equals(attrType)) {
        return hasTemporalType(persistentProperty, TemporalType.TIME);
    }

    return false;
}

From source file:com.testing26thjuly_.db123testing.NewTypesUser.java

@Temporal(TemporalType.TIME)
@Column(name = "`Time Col`", nullable = true)
public Date getTimeCol() {
    return this.timeCol;
}

From source file:com.testing26thjuly_.db123testing.AllTypes.java

@Temporal(TemporalType.TIME)
@Column(name = "`TIME COL`", nullable = false)
public Date getTimeCol() {
    return this.timeCol;
}

From source file:com.haulmont.chile.jpa.loader.JPAAnnotationsLoader.java

@Override
protected Class getTypeOverride(AnnotatedElement element) {
    Temporal temporal = element.getAnnotation(Temporal.class);
    if (temporal != null && temporal.value().equals(TemporalType.DATE))
        return java.sql.Date.class;
    else if (temporal != null && temporal.value().equals(TemporalType.TIME))
        return java.sql.Time.class;
    else/*from  w w w . j  av  a2 s. co  m*/
        return null;
}

From source file:com.testing26thjuly_.db123testing.V1.java

@Id
@Temporal(TemporalType.TIME)
@Column(name = "`Time Col`", nullable = true)
public Date getTimeCol() {
    return this.timeCol;
}

From source file:com.p5solutions.core.jpa.orm.ConversionUtilityImpl.java

/**
 * Convert timestamp.//  w  w  w  .  ja va2 s.c  o  m
 * 
 * @param pb
 *          the pb
 * @param timestamp
 *          the timestamp
 * @param targetType
 *          the target type
 * @return the object
 */
public Object convertTimestamp(ParameterBinder pb, Timestamp timestamp, Class<?> targetType) {
    // TODO probably needs further checking based on JPA annotations, some
    // timezone issues???
    if (ReflectionUtility.isDate(targetType)) {
        // Check for Temporal
        if (pb != null) {
            Temporal temporal = pb.getTemporal();
            if (temporal != null) {
                Date converted = timestamp;
                if (TemporalType.DATE.equals(temporal.value())) {
                    java.sql.Date dt = new java.sql.Date(timestamp.getTime());
                    return dt;
                } else if (TemporalType.TIME.equals(temporal.value())) {
                    java.sql.Time tm = new java.sql.Time(timestamp.getTime());
                    return tm;
                } else if (TemporalType.TIMESTAMP.equals(temporal.value())) {

                }

                return converted;
            }
        }

        Date test = new Date(timestamp.getTime());
        return test;

        // return (Date) timestamp;
    } else if (ReflectionUtility.isStringClass(targetType)) {
        // TODO needs to be formatted based on the Format defined by the
        // 'custom?'
        // Format annotation ????
        return timestamp.toLocaleString();
    } else if (ReflectionUtility.isLongClass(targetType)) {

    }
    return timestamp;
}

From source file:myorg.relex.One2OneTest.java

/**
 * This test provides a demonstration of creating a one-to-one, uni-directional
 * relationship to a parent class that uses a composite primary key mapped thru an @IdClass
 *//*from ww  w . j av a2  s  .c om*/
@Test
public void testOne2OneUniIdClass() {
    log.info("*** testOne2OneUniIdClass ***");
    Date showDate = new GregorianCalendar(1975 + new Random().nextInt(100), Calendar.JANUARY, 1).getTime();
    Date showTime = new GregorianCalendar(0, 0, 0, 0, 0, 0).getTime();
    ShowEvent show = new ShowEvent(showDate, showTime);
    show.setName("Rocky Horror");
    ShowTickets tickets = new ShowTickets(show); //parent already has natural PK by this point
    tickets.setTicketsLeft(300);
    em.persist(show);
    em.persist(tickets);

    //flush commands to database, clear cache, and pull back new instance
    em.flush();
    em.clear();
    ShowTickets tickets2 = em.find(ShowTickets.class, new ShowEventPK(tickets.getDate(), tickets.getTime()));
    log.info("calling parent...");
    assertEquals("unexpected name", tickets.getShow().getName(), tickets2.getShow().getName());

    //verify the contents of the database tables, columns, and relationships
    Object[] cols = (Object[]) em.createNativeQuery("select show.date show_date, show.time show_time, "
            + "tickets.ticket_date ticket_date, tickets.ticket_time ticket_time, tickets.tickets "
            + "from RELATIONEX_SHOWEVENT show "
            + "join RELATIONEX_SHOWTICKETS tickets on show.date = tickets.ticket_date and show.time = tickets.ticket_time "
            + "where tickets.ticket_date = ?1 and tickets.ticket_time = ?2")
            .setParameter(1, tickets.getShow().getDate(), TemporalType.DATE)
            .setParameter(2, tickets.getShow().getTime(), TemporalType.TIME).getSingleResult();
    log.info("row=" + Arrays.toString(cols));
    assertEquals("unexpected show_date", tickets2.getShow().getDate(), (Date) cols[0]);
    assertEquals("unexpected show_time", tickets2.getShow().getTime(), (Date) cols[1]);
    assertEquals("unexpected ticket_date", tickets2.getDate(), (Date) cols[2]);
    assertEquals("unexpected ticket_time", tickets2.getTime(), (Date) cols[3]);
    assertEquals("unexpected ticketsLeft", tickets2.getTicketsLeft(), ((Number) cols[4]).intValue());

    //remove the objects and flush commands to the database
    em.remove(tickets2);
    em.remove(tickets2.getShow());
    em.flush();
    assertNull("tickets not deleted",
            em.find(ShowEvent.class, new ShowEventPK(show.getDate(), show.getTime())));
    assertNull("show not deleted",
            em.find(ShowTickets.class, new ShowEventPK(tickets.getDate(), tickets.getTime())));
}

From source file:myorg.relex.One2OneTest.java

/**
 * This test provides a demonstration of creating a one-to-one, uni-directional
 * relationship to a parent class that uses a composite primary key mapped thru and 
 * @EmbeddedId/*w  w w . ja v  a2 s .  com*/
 */
@Test
public void testOne2OneUniEmbeddedId() {
    log.info("*** testOne2OneUniEmbedded ***");
    Date showDate = new GregorianCalendar(1975 + new Random().nextInt(100), Calendar.JANUARY, 1).getTime();
    Date showTime = new GregorianCalendar(0, 0, 0, 0, 0, 0).getTime();
    ShowEvent show = new ShowEvent(showDate, showTime);
    show.setName("Rocky Horror");
    BoxOffice boxOffice = new BoxOffice(show);
    boxOffice.setTicketsLeft(500);
    em.persist(show);
    em.persist(boxOffice); //provider auto propagates parent.cid to dependent.FK mapped to dependent.cid 

    //flush commands to database, clear cache, and pull back new instance
    em.flush();
    em.clear();
    BoxOffice boxOffice2 = em.find(BoxOffice.class, new ShowEventPK(boxOffice.getDate(), boxOffice.getTime()));
    log.info("calling parent...");
    assertEquals("unexpected name", boxOffice.getShow().getName(), boxOffice2.getShow().getName());

    //verify the contents of the database tables, columns, and relationships
    Object[] cols = (Object[]) em.createNativeQuery("select show.date show_date, show.time show_time, "
            + "tickets.show_date ticket_date, tickets.show_time ticket_time, tickets.tickets "
            + "from RELATIONEX_SHOWEVENT show "
            + "join RELATIONEX_BOXOFFICE tickets on show.date = tickets.show_date and show.time = tickets.show_time "
            + "where tickets.show_date = ?1 and tickets.show_time = ?2")
            .setParameter(1, boxOffice.getShow().getDate(), TemporalType.DATE)
            .setParameter(2, boxOffice.getShow().getTime(), TemporalType.TIME).getSingleResult();
    log.info("row=" + Arrays.toString(cols));
    assertEquals("unexpected show_date", boxOffice2.getShow().getDate(), (Date) cols[0]);
    assertEquals("unexpected show_time", boxOffice2.getShow().getTime(), (Date) cols[1]);
    assertEquals("unexpected ticket_date", boxOffice2.getDate(), (Date) cols[2]);
    assertEquals("unexpected ticket_time", boxOffice2.getTime(), (Date) cols[3]);
    assertEquals("unexpected ticketsLeft", boxOffice2.getTicketsLeft(), ((Number) cols[4]).intValue());

    //remove the objects and flush commands to the database
    em.remove(boxOffice2);
    em.remove(boxOffice2.getShow());
    em.flush();
    assertNull("tickets not deleted",
            em.find(ShowEvent.class, new ShowEventPK(show.getDate(), show.getTime())));
    assertNull("show not deleted",
            em.find(BoxOffice.class, new ShowEventPK(boxOffice.getDate(), boxOffice.getTime())));
}

From source file:com.haulmont.cuba.core.sys.MetaModelLoader.java

protected Class getTypeOverride(AnnotatedElement element) {
    Temporal temporal = element.getAnnotation(Temporal.class);
    if (temporal != null && temporal.value().equals(TemporalType.DATE))
        return java.sql.Date.class;
    else if (temporal != null && temporal.value().equals(TemporalType.TIME))
        return java.sql.Time.class;
    else/*from   ww w. ja v a2  s .co m*/
        return null;
}

From source file:org.apache.camel.bam.model.ActivityState.java

@Temporal(TemporalType.TIME)
public Date getTimeExpected() {
    return timeExpected;
}