List of usage examples for javax.persistence TemporalType DATE
TemporalType DATE
To view the source code for javax.persistence TemporalType DATE.
Click Source Link
java.sql.Date
From source file:com.haulmont.cuba.core.global.MessageTools.java
/** * @param temporalType a temporal type/*from w ww .j a va 2 s .co m*/ * @return default date format string for passed temporal type */ public String getDefaultDateFormat(TemporalType temporalType) { return temporalType == TemporalType.DATE ? messages.getMainMessage("dateFormat") : messages.getMainMessage("dateTimeFormat"); }
From source file:com.encens.khipus.service.production.RawMaterialPayRollServiceBean.java
public List<BoletaPagoProductor> findBoletaDePago(Date fechaIni, Date fechaFin, RawMaterialProducer rawMaterialProducer, ProductiveZone productiveZone, MetaProduct metaProduct) { List<Object[]> datos = new ArrayList<Object[]>(); List<BoletaPagoProductor> boletaPagoProductors = new ArrayList<BoletaPagoProductor>(); if (rawMaterialProducer != null && productiveZone != null) datos = getEntityManager().createQuery(consultaBoletaDePago(rawMaterialProducer, productiveZone)) .setParameter("fechaIni", fechaIni, TemporalType.DATE) .setParameter("fechaFin", fechaFin, TemporalType.DATE) .setParameter("rawMaterialProducer", rawMaterialProducer) .setParameter("productiveZone", productiveZone).setParameter("metaProduct", metaProduct) .getResultList();//from w w w . j a va2s .c o m else { if (rawMaterialProducer != null) datos = getEntityManager().createQuery(consultaBoletaDePago(rawMaterialProducer, productiveZone)) .setParameter("fechaIni", fechaIni, TemporalType.DATE) .setParameter("fechaFin", fechaFin, TemporalType.DATE) .setParameter("rawMaterialProducer", rawMaterialProducer) .setParameter("metaProduct", metaProduct).getResultList(); if (productiveZone != null) datos = getEntityManager().createQuery(consultaBoletaDePago(rawMaterialProducer, productiveZone)) .setParameter("fechaIni", fechaIni, TemporalType.DATE) .setParameter("fechaFin", fechaFin, TemporalType.DATE) .setParameter("productiveZone", productiveZone).setParameter("metaProduct", metaProduct) .getResultList(); if (rawMaterialProducer == null && productiveZone == null) datos = getEntityManager().createQuery(consultaBoletaDePago(rawMaterialProducer, productiveZone)) .setParameter("fechaIni", fechaIni, TemporalType.DATE) .setParameter("fechaFin", fechaFin, TemporalType.DATE) .setParameter("metaProduct", metaProduct).getResultList(); } for (Object[] dato : datos) { BoletaPagoProductor boletaPagoProductor = new BoletaPagoProductor(); boletaPagoProductor .setNombrecompletoProductor((String) dato[1] + " " + (String) dato[2] + " " + (String) dato[3]); boletaPagoProductor.setNombreGAB((String) dato[18]); boletaPagoProductor.setTotalLitrosLeche((Double) dato[4]); boletaPagoProductor.setPrecioLeche((Double) dato[5]); boletaPagoProductor.setTotalBrutoBs((Double) dato[6]); boletaPagoProductor.setRetencion((Double) dato[7]); boletaPagoProductor.setReserva((Double) dato[19]); boletaPagoProductor.setAlcohol((Double) dato[8]); boletaPagoProductor.setConcentrados((Double) dato[9]); boletaPagoProductor.setCredito((Double) dato[10]); boletaPagoProductor.setVeterinario((Double) dato[11]); boletaPagoProductor.setYogurt((Double) dato[12]); boletaPagoProductor.setTachos((Double) dato[13]); boletaPagoProductor.setAjustes((Double) dato[15]); boletaPagoProductor.setOtrosDescuentos((Double) dato[14]); boletaPagoProductor.setOtrosIngresos((Double) dato[16]); boletaPagoProductor.setLiquidoPagable((Double) dato[17]); boletaPagoProductor.setCi((String) dato[20]); boletaPagoProductor.setDescuentoGA((Double) dato[21]); boletaPagoProductors.add(boletaPagoProductor); } return boletaPagoProductors; }
From source file:org.somespc.webservices.rest.SoMeSPCResource.java
/** * Obtem as medicoes./*from ww w. j a v a2s . co m*/ * * @return * @throws Exception */ @Path("Medicao") @GET @Consumes(MediaType.APPLICATION_JSON + ";charset=utf-8") @Produces(MediaType.APPLICATION_JSON + ";charset=utf-8") public Response obterMedicoes(@QueryParam("medida") String nomeMedida, @QueryParam("entidade") int idEntidade, @QueryParam("indiceAtual") int indiceAtual, @QueryParam("tamanhoPagina") int tamanhoPagina, @QueryParam("dataInicio") String dtInicio, @QueryParam("dataFim") String dtFim) throws Exception { Response response; if (nomeMedida == null || nomeMedida.isEmpty() || dtInicio == null || dtInicio.isEmpty() || dtFim == null || dtFim.isEmpty() || idEntidade == 0) { response = Response.status(Status.BAD_REQUEST).build(); } else { EntityManager manager = XPersistence.createManager(); Date dataInicio = fmt.parse(dtInicio); Date dataFim = fmt.parse(dtFim); TypedQuery<Medicao> query = manager.createQuery("Select m FROM Medicao m " + "WHERE m.medidaPlanoDeMedicao.medida.nome = :nomeMedida " + "AND m.entidadeMensuravel.id = :idEntidade AND cast(m.data as date) BETWEEN :dataInicio AND :dataFim ORDER BY m.data ASC", Medicao.class).setParameter("nomeMedida", nomeMedida).setParameter("idEntidade", idEntidade) .setParameter("dataInicio", dataInicio, TemporalType.DATE) .setParameter("dataFim", dataFim, TemporalType.DATE) .setFirstResult((indiceAtual * tamanhoPagina) - tamanhoPagina).setMaxResults(tamanhoPagina); List<Medicao> result = query.getResultList(); if (result == null) response = Response.status(Status.NOT_FOUND).build(); else { List<MedicaoDTO> listaDto = new ArrayList<MedicaoDTO>(); for (Medicao medicao : result) { MedicaoDTO dto = new MedicaoDTO(); dto.setId(medicao.getId()); dto.setData(medicao.getData()); dto.setValorMedido(medicao.getValorMedido().getValorMedido()); listaDto.add(dto); } response = Response.status(Status.OK).entity(listaDto).build(); } manager.close(); } return response; }
From source file:com.haulmont.cuba.gui.components.filter.Param.java
protected Component createDateField(Class javaClass, final ValueProperty valueProperty) { UserSession userSession = userSessionSource.getUserSession(); boolean supportTimezones = false; boolean dateOnly = false; if (property != null) { TemporalType tt = (TemporalType) property.getAnnotations().get(MetadataTools.TEMPORAL_ANN_NAME); dateOnly = (tt == TemporalType.DATE); Object ignoreUserTimeZone = metadataTools.getMetaAnnotationValue(property, IgnoreUserTimeZone.class); supportTimezones = !dateOnly && !Boolean.TRUE.equals(ignoreUserTimeZone); } else if (javaClass.equals(java.sql.Date.class)) { dateOnly = true;//from w w w . ja v a 2 s . c om if (useUserTimeZone) { supportTimezones = true; } } else { supportTimezones = true; } if (inExpr) { ListEditor listEditor = componentsFactory.createComponent(ListEditor.class); ListEditor.ItemType itemType = dateOnly ? ListEditor.ItemType.DATE : ListEditor.ItemType.DATETIME; listEditor.setItemType(itemType); if (userSession.getTimeZone() != null && supportTimezones) { listEditor.setTimeZone(userSession.getTimeZone()); } initListEditor(listEditor, valueProperty); return listEditor; } DateField dateField = componentsFactory.createComponent(DateField.class); DateField.Resolution resolution; String formatStr; Messages messages = AppBeans.get(Messages.NAME); if (dateOnly) { resolution = com.haulmont.cuba.gui.components.DateField.Resolution.DAY; formatStr = messages.getMainMessage("dateFormat"); } else { resolution = com.haulmont.cuba.gui.components.DateField.Resolution.MIN; formatStr = messages.getMainMessage("dateTimeFormat"); } dateField.setResolution(resolution); dateField.setDateFormat(formatStr); if (userSession.getTimeZone() != null && supportTimezones) { dateField.setTimeZone(userSession.getTimeZone()); } dateField.addValueChangeListener(e -> _setValue(e.getValue(), valueProperty)); dateField.setValue(_getValue(valueProperty)); return dateField; }
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 w w w . ja v a 2 s .co m*/ return null; }
From source file:edu.ku.brc.specify.datamodel.CollectionObject.java
/** * @return the inventoryDate/*from w w w . j a va2 s.c o m*/ */ @Temporal(TemporalType.DATE) @Column(name = "InventoryDate", unique = false, nullable = true, insertable = true, updatable = true) public Calendar getInventoryDate() { return inventoryDate; }
From source file:org.openhie.openempi.model.Person.java
@Temporal(TemporalType.DATE) @Column(name = "death_time", length = 8) @XmlElement public Date getDeathTime() { return this.deathTime; }
From source file:com.encens.khipus.service.production.RawMaterialPayRollServiceBean.java
public List<BoletaPagoProductor> findBoletaDePagoGA(Date fechaIni, Date fechaFin, RawMaterialProducer rawMaterialProducer, ProductiveZone productiveZone, MetaProduct metaProduct) { List<Object[]> datos = new ArrayList<Object[]>(); List<BoletaPagoProductor> boletaPagoProductors = new ArrayList<BoletaPagoProductor>(); if (rawMaterialProducer != null && productiveZone != null) { datos = getEntityManager().createQuery(consultaBoletaDePagoGA(rawMaterialProducer, productiveZone)) .setParameter("fechaIni", fechaIni, TemporalType.DATE) .setParameter("fechaFin", fechaFin, TemporalType.DATE) .setParameter("rawMaterialProducer", rawMaterialProducer) .setParameter("productiveZone", productiveZone).setParameter("metaProduct", metaProduct) .getResultList();//from w w w . j a v a2 s .co m } else { if (rawMaterialProducer != null) datos = getEntityManager().createQuery(consultaBoletaDePagoGA(rawMaterialProducer, productiveZone)) .setParameter("fechaIni", fechaIni, TemporalType.DATE) .setParameter("fechaFin", fechaFin, TemporalType.DATE) .setParameter("rawMaterialProducer", rawMaterialProducer) .setParameter("metaProduct", metaProduct).getResultList(); if (productiveZone != null) datos = getEntityManager().createQuery(consultaBoletaDePagoGA(rawMaterialProducer, productiveZone)) .setParameter("fechaIni", fechaIni, TemporalType.DATE) .setParameter("fechaFin", fechaFin, TemporalType.DATE) .setParameter("productiveZone", productiveZone).setParameter("metaProduct", metaProduct) .getResultList(); if (rawMaterialProducer == null && productiveZone == null) datos = getEntityManager().createQuery(consultaBoletaDePagoGA(rawMaterialProducer, productiveZone)) .setParameter("fechaIni", fechaIni, TemporalType.DATE) .setParameter("fechaFin", fechaFin, TemporalType.DATE) .setParameter("metaProduct", metaProduct).getResultList(); } for (Object[] dato : datos) { BoletaPagoProductor boletaPagoProductor = new BoletaPagoProductor(); boletaPagoProductor .setNombrecompletoProductor((String) dato[1] + " " + (String) dato[2] + " " + (String) dato[3]); boletaPagoProductor.setNombreGAB((String) dato[18]); boletaPagoProductor.setTotalLitrosLeche((Double) dato[4]); boletaPagoProductor.setPrecioLeche((Double) dato[5]); boletaPagoProductor.setTotalBrutoBs((Double) dato[6]); boletaPagoProductor.setRetencion((Double) dato[7]); boletaPagoProductor.setReserva((Double) dato[19]); boletaPagoProductor.setAlcohol((Double) dato[8]); boletaPagoProductor.setConcentrados((Double) dato[9]); boletaPagoProductor.setCredito((Double) dato[10]); boletaPagoProductor.setVeterinario((Double) dato[11]); boletaPagoProductor.setYogurt((Double) dato[12]); boletaPagoProductor.setTachos((Double) dato[13]); boletaPagoProductor.setAjustes((Double) dato[15]); boletaPagoProductor.setOtrosDescuentos((Double) dato[14]); boletaPagoProductor.setOtrosIngresos((Double) dato[16]); boletaPagoProductor.setLiquidoPagable((Double) dato[17]); boletaPagoProductor.setCi((String) dato[20]); boletaPagoProductor.setDescuentoGA((Double) dato[21]); boletaPagoProductors.add(boletaPagoProductor); } return boletaPagoProductors; }
From source file:gov.opm.scrd.batchprocessing.jobs.BatchProcessingJob.java
/** * Checks whether the current day is a holiday. * * @param now The current day.// w w w .j a va 2 s. c o m * @return True if the current date is a holiday, false otherwise. * @throws BatchProcessingException If major error occurred. */ protected boolean isNowHoliday(Date now) throws BatchProcessingException { Calendar calendar = Calendar.getInstance(); calendar.setTime(now); int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK); if (dayOfWeek == Calendar.SUNDAY || dayOfWeek == Calendar.SATURDAY) { return true; // Sunday for 0 and Saturday for 6 are holidays } try { startTransaction(); StoredProcedureQuery sp = entityManager.createNamedStoredProcedureQuery("IsThisHoliday"); sp.setParameter("pDate2Test", now, TemporalType.DATE); Boolean result = (Boolean) sp.getSingleResult(); commitTransaction(); return result; } catch (PersistenceException pe) { throw new BatchProcessingException("Database error checking holiday.", pe); } }
From source file:myorg.relex.One2OneTest.java
/** * This test demonstrates use of cascades in a one-to-one * uni-directional relationship or one where all cascades come * from the owning/dependent side./*from ww w .ja va2 s . c om*/ */ @Test public void testOne2OneCascadeFromOwner() { log.info("*** testOne2OneCascadeFromOwner ***"); License license = new License(); license.setRenewal(new GregorianCalendar(2012, 1, 1).getTime()); LicenseApplication licapp = new LicenseApplication(license); licapp.setUpdated(new Date()); em.persist(licapp); em.flush(); //detach the current instances and obtain new instances assertTrue("licapp was not managed???", em.contains(licapp)); assertTrue("license was not managed???", em.contains(license)); em.detach(licapp); assertFalse("licapp still managed", em.contains(licapp)); assertFalse("license still managed", em.contains(license)); licapp = em.find(LicenseApplication.class, licapp.getId()); license = licapp.getLicense(); //perform a bulk update and refresh on the entities to synchronize state Date newDate = new GregorianCalendar(2014, 1, 1).getTime(); Date newUpdate = new Date(licapp.getUpdated().getTime() + 1); assertEquals("unexpected update count", 1, em.createQuery("update License lic set lic.renewal=:renewal where lic.id=:id") .setParameter("renewal", newDate, TemporalType.DATE).setParameter("id", license.getId()) .executeUpdate()); assertEquals("unexpected update count", 1, em.createQuery("update LicenseApplication licapp set licapp.updated=:updated where licapp.id=:id") .setParameter("updated", newUpdate, TemporalType.TIMESTAMP) .setParameter("id", licapp.getId()).executeUpdate()); assertFalse("unexpected updated value prior to refresh", licapp.getUpdated().getTime() == newUpdate.getTime()); assertFalse("unexpected renewal value prior to refresh", license.getRenewal().getTime() == newDate.getTime()); log.info("database updated"); em.refresh(licapp); log.info("entities refreshed"); DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSSZ"); assertTrue(String.format("licapp not refreshed, exp=%s, act=%s", df.format(newUpdate), df.format(licapp.getUpdated())), licapp.getUpdated().getTime() == newUpdate.getTime()); assertTrue(String.format("license not refreshed, exp=%s, act=%s", df.format(newDate), df.format(license.getRenewal())), license.getRenewal().getTime() == newDate.getTime()); //detach, change, and merge changes from the detached entities em.detach(licapp); newDate = new GregorianCalendar(2016, 1, 1).getTime(); newUpdate = new Date(licapp.getUpdated().getTime() + 1); assertFalse("licapp still managed", em.contains(licapp)); assertFalse("license still managed", em.contains(licapp.getLicense())); licapp.setUpdated(newUpdate); licapp.getLicense().setRenewal(newDate); log.info("merging changes to detached entities"); licapp = em.merge(licapp); em.flush(); log.info("merging complete"); assertTrue("merged licapp not managed", em.contains(licapp)); assertTrue("merged licapp.license not managed", em.contains(licapp.getLicense())); assertTrue(String.format("licapp not merged, exp=%s, act=%s", df.format(newUpdate), df.format(licapp.getUpdated())), licapp.getUpdated().getTime() == newUpdate.getTime()); assertTrue( String.format("license not merged, exp=%s, act=%s", df.format(newDate), df.format(license.getRenewal())), licapp.getLicense().getRenewal().getTime() == newDate.getTime()); //delete remaining objects em.remove(licapp); em.flush(); assertNull("licapp not deleted", em.find(LicenseApplication.class, licapp.getId())); assertNull("licapp.license not deleted", em.find(License.class, licapp.getLicense().getId())); }