Example usage for javax.persistence TemporalType DATE

List of usage examples for javax.persistence TemporalType DATE

Introduction

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

Prototype

TemporalType DATE

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

Click Source Link

Document

Map as java.sql.Date

Usage

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  ww .j  a  v  a 2 s.co m*/
 */
@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.hive.enterprisemanage.entity.EEnterpriseinfomodifytemp.java

@Temporal(TemporalType.DATE)
@Column(name = "DCREATETIME", nullable = false, length = 7)
@JsonSerialize(using = JsonDateSerializer.class)
public Date getDcreatetime() {
    return this.dcreatetime;
}

From source file:com.hive.enterprisemanage.entity.EEnterpriseinfo.java

@Temporal(TemporalType.DATE)
@Column(name = "DCREATETIME", nullable = true, length = 7)
@JsonSerialize(using = JsonDateSerializer.class)
public Date getDcreatetime() {
    return this.dcreatetime;
}

From source file:com.hive.enterprisemanage.entity.EEnterpriseinfo.java

@Temporal(TemporalType.DATE)
@Column(name = "DMODIFYTIME", length = 7)
@JsonSerialize(using = JsonDateTimeSerializer.class)
public Date getDmodifytime() {
    return this.dmodifytime;
}

From source file:com.hive.enterprisemanage.entity.EEnterpriseinfo.java

@Temporal(TemporalType.DATE)
@Column(name = "DAUDITTIME", length = 7)
@JsonSerialize(using = JsonDateTimeSerializer.class)
public Date getDaudittime() {
    return this.daudittime;
}

From source file:org.apache.openjpa.persistence.jdbc.AnnotationPersistenceMappingSerializer.java

/**
 * Return field's temporal type./* w  ww  .  ja  va 2 s  .  co m*/
 */
private TemporalType getTemporal(FieldMapping field) {
    if (field.getDeclaredTypeCode() != JavaTypes.DATE && field.getDeclaredTypeCode() != JavaTypes.CALENDAR)
        return null;

    DBDictionary dict = ((JDBCConfiguration) getConfiguration()).getDBDictionaryInstance();
    int def = dict.getJDBCType(field.getTypeCode(), false);
    for (Column col : (List<Column>) field.getValueInfo().getColumns()) {
        if (col.getType() == def)
            continue;
        switch (col.getType()) {
        case Types.DATE:
            return TemporalType.DATE;
        case Types.TIME:
            return TemporalType.TIME;
        case Types.TIMESTAMP:
            return TemporalType.TIMESTAMP;
        }
    }
    return null;
}

From source file:org.somespc.webservices.rest.SoMeSPCResource.java

@Path("Medicao/Total")
@GET//from  w w  w  .  j  ava  2  s.c  o  m
@Consumes(MediaType.APPLICATION_JSON + ";charset=utf-8")
@Produces(MediaType.APPLICATION_JSON + ";charset=utf-8")
public Response obterTotalMedicoes(@QueryParam("medida") String nomeMedida,
        @QueryParam("entidade") int idEntidade, @QueryParam("dataInicio") String dtInicio,
        @QueryParam("dataFim") String dtFim) throws ParseException {
    Response response;

    Date dataInicio = fmt.parse(dtInicio);
    Date dataFim = fmt.parse(dtFim);

    EntityManager manager = XPersistence.createManager();

    Query queryTotal = manager.createQuery("SELECT COUNT(*) FROM Medicao m "
            + "WHERE m.medidaPlanoDeMedicao.medida.nome = :nomeMedida "
            + "AND m.entidadeMensuravel.id = :idEntidade AND cast(m.data as date) BETWEEN :dataInicio AND :dataFim")
            .setParameter("nomeMedida", nomeMedida).setParameter("idEntidade", idEntidade)
            .setParameter("dataInicio", dataInicio, TemporalType.DATE)
            .setParameter("dataFim", dataFim, TemporalType.DATE);

    Long total = (Long) queryTotal.getSingleResult();

    manager.close();

    response = Response.status(Status.OK).entity(total).build();
    return response;
}

From source file:com.encens.khipus.service.production.RawMaterialPayRollServiceBean.java

public DiscountProducer findDiscountProducerByDate(Date date) {
    List<DiscountProducer> discountProducers = new ArrayList<DiscountProducer>();
    try {//from  w  ww.  ja  va2 s . c o m
        discountProducers = (List<DiscountProducer>) getEntityManager()
                .createQuery(" SELECT discountProducer from DiscountProducer discountProducer "
                        + " where discountProducer.startDate <= :date "
                        + " and discountProducer.endDate >= :date " + " and discountProducer.state = 'ENABLE'")
                .setParameter("date", date, TemporalType.DATE).getResultList();
    } catch (NoResultException e) {
        return null;
    }
    if (discountProducers.size() == 0)
        return null;

    return discountProducers.get(0);
}

From source file:edu.ku.brc.specify.datamodel.CollectionObject.java

/**
 *
 *//*from  w  w w  .  j av a2  s.com*/
@Temporal(TemporalType.DATE)
@Column(name = "CatalogedDate", unique = false, nullable = true, insertable = true, updatable = true)
public Calendar getCatalogedDate() {
    return this.catalogedDate;
}

From source file:com.newline.view.company.entity.NlCompanyEntity.java

/**
 * : ?java.util.Date/*from w  w  w . jav a2 s.  co  m*/
 * 
 * @return: java.util.Date ?
 */
@Column(name = "ESTABLISHTIME", nullable = true)
@Temporal(TemporalType.DATE)
@JSONField(format = "yyyy-MM-dd")
@DateTimeFormat(pattern = "yyyy-MM-dd")
public java.util.Date getEstablishtime() {
    return this.establishtime;
}