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:myorg.relex.One2OneTest.java
/** * This test demonstrates use of cascades in a one-to-one * bi-directional relationship where all cascades come * from the inverse/parent side of the relationship. *//*w w w. j ava2s .c om*/ @Test public void testOne2OneCascadeFromInverse() { log.info("*** testOne2OneCascadeFromInverse ***"); Ticket ticket = new Ticket(); ticket.setDate(new GregorianCalendar(2013, Calendar.MARCH, 16).getTime()); Passenger passenger = new Passenger(ticket, "Fred"); //set inverse side ticket.setPassenger(passenger); //set the owning side em.persist(ticket); //persist from inverse side em.flush(); assertTrue("ticket not managed", em.contains(ticket)); assertTrue("passenger not managed", em.contains(passenger)); log.debug("detach both instances from the persistence context"); em.detach(ticket); assertFalse("ticket managed", em.contains(ticket)); assertFalse("passenger managed", em.contains(passenger)); log.debug("perform a bulk update to both objects"); ticket = em.find(Ticket.class, ticket.getId()); Date newDate = new GregorianCalendar(2013, Calendar.APRIL, 1).getTime(); String newName = "Frederick"; em.createQuery("update Ticket t set t.date=:date").setParameter("date", newDate, TemporalType.DATE) .executeUpdate(); em.createQuery("update Passenger p set p.name=:name where p.name='Fred'").setParameter("name", newName) .executeUpdate(); assertFalse("unexpected date", newDate.equals(ticket.getDate())); assertFalse("unexpected name", newName.equals(ticket.getPassenger().getName())); em.refresh(ticket); assertTrue("date not refreshed", newDate.equals(ticket.getDate())); assertTrue("name not refreshed", newName.equals(ticket.getPassenger().getName())); log.debug("merging changes from inverse side"); Ticket ticket2 = new Ticket(ticket.getId()); ticket2.setDate(new GregorianCalendar(2014, Calendar.APRIL, 1).getTime()); Passenger passenger2 = new Passenger(passenger.getId()); passenger2.setName("Rick"); ticket2.setPassenger(passenger2); passenger2.setTicket(ticket2); assertFalse("unexpected date", ticket2.getDate().equals(ticket.getDate())); assertFalse("unexpected name", ticket2.getPassenger().getName().equals(ticket.getPassenger().getName())); ticket = em.merge(ticket2); em.flush(); assertTrue("date not merged", ticket2.getDate().equals(ticket.getDate())); assertTrue("name not merged", ticket2.getPassenger().getName().equals(ticket.getPassenger().getName())); log.debug("delete the entities from the inverse side"); assertNotNull("ticket not found", em.find(Ticket.class, ticket.getId())); assertNotNull("passenger not found", em.find(Passenger.class, ticket.getPassenger().getId())); em.remove(ticket); em.flush(); assertNull("ticket not removed", em.find(Ticket.class, ticket.getId())); assertNull("passenger not removed", em.find(Passenger.class, ticket.getPassenger().getId())); }
From source file:com.encens.khipus.service.production.RawMaterialPayRollServiceBean.java
public List<DiscountProducer> findDiscountsProducerByDate(Date date) { List<DiscountProducer> discountProducers = new ArrayList<DiscountProducer>(); try {/*from w ww. j a v a 2s .com*/ 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 discountProducers; } if (discountProducers.size() == 0) return discountProducers; return discountProducers; }
From source file:com.encens.khipus.service.production.RawMaterialPayRollServiceBean.java
public Discounts getDiscounts(Date dateIni, Date dateEnd, ProductiveZone zone, MetaProduct metaProduct) { Discounts discounts = new Discounts(); List<Object[]> datas = getEntityManager().createNamedQuery("RawMaterialPayRoll.getDiscounts") .setParameter("startDate", dateIni, TemporalType.DATE) .setParameter("endDate", dateEnd, TemporalType.DATE) //.setParameter("productiveZone", zone) .setParameter("metaProduct", metaProduct).getResultList(); if (datas.size() > 0) { discounts.mount = ((Double) datas.get(0)[0] != null) ? ((Double) datas.get(0)[0]).doubleValue() : 0.0; discounts.collected = ((Double) datas.get(0)[1] != null) ? ((Double) datas.get(0)[1]).doubleValue() : 0.0;// w w w . j a va2 s .c o m discounts.alcohol = ((Double) datas.get(0)[2] != null) ? ((Double) datas.get(0)[2]).doubleValue() : 0.0; discounts.concentrated = ((Double) datas.get(0)[3] != null) ? ((Double) datas.get(0)[3]).doubleValue() : 0.0; discounts.yogurt = ((Double) datas.get(0)[4] != null) ? ((Double) datas.get(0)[4]).doubleValue() : 0.0; discounts.recip = ((Double) datas.get(0)[5] != null) ? ((Double) datas.get(0)[5]).doubleValue() : 0.0; discounts.retention = ((Double) datas.get(0)[6] != null) ? ((Double) datas.get(0)[6]).doubleValue() : 0.0; discounts.veterinary = ((Double) datas.get(0)[7] != null) ? ((Double) datas.get(0)[7]).doubleValue() : 0.0; discounts.credit = ((Double) datas.get(0)[8] != null) ? ((Double) datas.get(0)[8]).doubleValue() : 0.0; discounts.discount = ((Double) datas.get(0)[9] != null) ? ((Double) datas.get(0)[9]).doubleValue() : 0.0; discounts.liquid = ((Double) datas.get(0)[10] != null) ? ((Double) datas.get(0)[10]).doubleValue() : 0.0; discounts.otherDiscount = ((Double) datas.get(0)[11] != null) ? ((Double) datas.get(0)[11]).doubleValue() : 0.0; discounts.otherIncome = ((Double) datas.get(0)[12] != null) ? ((Double) datas.get(0)[12]).doubleValue() : 0.0; discounts.adjustment = ((Double) datas.get(0)[13] != null) ? ((Double) datas.get(0)[13]).doubleValue() : 0.0; discounts.unitPrice = ((Double) datas.get(0)[14] != null) ? ((Double) datas.get(0)[14]).doubleValue() : 0.0; } else { discounts.mount = 0.0; discounts.collected = 0.0; discounts.alcohol = 0.0; discounts.concentrated = 0.0; discounts.yogurt = 0.0; discounts.recip = 0.0; discounts.retention = 0.0; discounts.veterinary = 0.0; discounts.credit = 0.0; discounts.discount = 0.0; discounts.liquid = 0.0; discounts.otherDiscount = 0.0; discounts.otherIncome = 0.0; discounts.adjustment = 0.0; discounts.unitPrice = 0.0; } return discounts; }
From source file:com.mmnaseri.dragonfly.metadata.impl.AnnotationTableMetadataResolver.java
private static int getColumnType(Class<?> javaType, Method method, ColumnMetadata foreignReference) { final int dimensions = ReflectionUtils.getArrayDimensions(javaType); javaType = ReflectionUtils.mapType(ReflectionUtils.getComponentType(javaType)); if (dimensions > 1) { throw new UnsupportedColumnTypeError("Arrays of dimension > 1 are not supported"); }/*from ww w. j av a2s .c om*/ if (Byte.class.equals(javaType) && dimensions == 0) { return Types.TINYINT; } else if (Short.class.equals(javaType)) { return Types.SMALLINT; } else if (Integer.class.equals(javaType)) { return Types.INTEGER; } else if (Long.class.equals(javaType)) { return Types.BIGINT; } else if (Float.class.equals(javaType)) { return Types.FLOAT; } else if (Double.class.equals(javaType)) { return Types.DOUBLE; } else if (BigDecimal.class.equals(javaType)) { return Types.DECIMAL; } else if (BigInteger.class.equals(javaType)) { return Types.NUMERIC; } else if (Character.class.equals(javaType)) { return Types.CHAR; } else if (String.class.equals(javaType) || Class.class.equals(javaType)) { if (method != null && method.isAnnotationPresent(Column.class) && method.getAnnotation(Column.class).length() > 0) { return Types.VARCHAR; } else { return Types.LONGVARCHAR; } } else if (Date.class.isAssignableFrom(javaType)) { if (javaType.equals(java.sql.Date.class)) { return Types.DATE; } else if (javaType.equals(Time.class)) { return Types.TIME; } else if (javaType.equals(java.sql.Timestamp.class)) { return Types.TIMESTAMP; } final TemporalType temporalType = method != null && method.isAnnotationPresent(Temporal.class) ? method.getAnnotation(Temporal.class).value() : null; return (temporalType == null || temporalType.equals(TemporalType.TIMESTAMP)) ? Types.TIMESTAMP : (temporalType.equals(TemporalType.DATE) ? Types.DATE : Types.TIME); } else if (Byte.class.equals(javaType) && dimensions > 0) { return Types.VARBINARY; } else if (Enum.class.isAssignableFrom(javaType)) { return Types.VARCHAR; } else if (Boolean.class.equals(javaType)) { return Types.BOOLEAN; } else if (Collection.class.isAssignableFrom(javaType) && method.isAnnotationPresent(BasicCollection.class)) { return Types.LONGVARCHAR; } if (foreignReference != null) { return Integer.MIN_VALUE; } return Types.LONGVARCHAR; }
From source file:com.encens.khipus.service.production.RawMaterialPayRollServiceBean.java
public SummaryTotal getSumaryTotal(Date dateIni, Date dateEnd, ProductiveZone zone, MetaProduct metaProduct) { SummaryTotal summaryTotal = new SummaryTotal(); List<Object[]> datas = getEntityManager().createNamedQuery("RawMaterialPayRoll.getSumaryTotal") .setParameter("startDate", dateIni, TemporalType.DATE) .setParameter("endDate", dateEnd, TemporalType.DATE) //.setParameter("productiveZone", zone) .setParameter("metaProduct", metaProduct).getResultList(); //summaryTotal.differencesTotal = ((Double)datas.get(0)[0] !=null) ? (Double)datas.get(0)[0] : 0.0 ; /*summaryTotal.balanceWeightTotal = ((Double) datas.get(0)[0] != null) ? (Double) datas.get(0)[0] : 0.0; summaryTotal.collectedTotal = ((Double) datas.get(0)[1] != null) ? (Double) datas.get(0)[1] : 0.0;*/ //Change to MYSQL: summaryTotal.balanceWeightTotal = (datas.get(0)[0] != null) ? (Integer) datas.get(0)[0] : 0.0; summaryTotal.collectedTotal = (datas.get(0)[1] != null) ? (Integer) datas.get(0)[1] : 0.0; return summaryTotal; }
From source file:com.encens.khipus.service.production.RawMaterialPayRollServiceBean.java
private List<Object[]> findWeights(String namedQuery, Date startDate, Date endDate, MetaProduct metaProduct) { List<Object[]> result = null; try {//from w w w .ja v a 2 s . c om result = getEntityManager().createNamedQuery(namedQuery) .setParameter("startDate", startDate, TemporalType.DATE) .setParameter("endDate", endDate, TemporalType.DATE) //.setParameter("productiveZone", rawMaterialPayRoll.getProductiveZone()) .setParameter("metaProduct", metaProduct).getResultList(); } catch (Exception e) { } return result; }
From source file:gov.opm.scrd.batchprocessing.jobs.BatchProcessingJob.java
/** * Process import record: R or C line./*from ww w . java 2 s. c o m*/ * * @param mainFrame The MainframeImport record. * @param importStatus The import status. * @return The record type result. * @throws BatchProcessingException If major error occurred. */ private MainframeRecordType processImportRecord(MainframeImport mainFrame, ImportStatus importStatus) throws BatchProcessingException { String recordString = mainFrame.getRecordString(); // Parse the record text rFile.parseFileLine(recordString); rFile.setAchPaymentFlag( rFile.getPaymentType() == LockboxPaymentType.ACH || mainFrame.getAchFlag() == Boolean.TRUE); String errorText = null; MainframeRecordType returnType = MainframeRecordType.NOT_A_RECORD; if (rFile.getValidFileRecord() == Boolean.TRUE) { if (rFile.getTransactionCode().equals("R")) { importStatus.setTransactionsTotal(importStatus.getTransactionsTotal().add(rFile.getAmount())); try { StoredProcedureQuery sp = entityManager .createNamedStoredProcedureQuery("BatchInputBankPayments"); sp.setParameter("pPayTransBatchNumber", rFile.getCdNumber()); sp.setParameter("pPayTransBlockNumber", rFile.getBlockNumber()); sp.setParameter("pPayTransSequenceNumber", rFile.getSequenceNumber()); sp.setParameter("pSCMClaimNumber", rFile.getClaimNumber()); sp.setParameter("pSCMDateOfBirth", rFile.getDateOfBirth(), TemporalType.DATE); sp.setParameter("pPayTransPaymentAmount", rFile.getAmount()); sp.setParameter("pPayTransTransactionDate", rFile.getCdDate(), TemporalType.DATE); sp.setParameter("pACHPaymentFlag", rFile.getAchPaymentFlag()); sp.setParameter("pNetworkId", batchProcessUser.getNetworkId()); sp.execute(); String returnCode = (String) sp.getOutputParameterValue("pReturn"); Long paymentTransactionKey = (Long) sp.getOutputParameterValue("pPayTransactionKey"); if ("0".equals(returnCode)) { mainFrame.setPaymentTransactionId(paymentTransactionKey); returnType = MainframeRecordType.VALID_R_TRANSACTION; } else if ("17".equals(returnCode)) { returnType = MainframeRecordType.DUPLICATE_RECORD; errorText = "Duplicate payment record based on year, batch, block, sequence, amount and date: " + recordString; } else { returnType = MainframeRecordType.BAD_R_TRANSACTION; errorText = "Unknown R Transaction error (" + returnCode + "): " + recordString; } } catch (PersistenceException pe) { // Fill import status for logging fillImportStatus(importStatus, MainframeRecordType.BAD_R_TRANSACTION); errorText = "Database Error while inserting payment transaction record: " + recordString; throw new BatchProcessingException(errorText, pe); } } else { try { StoredProcedureQuery sp = entityManager .createNamedStoredProcedureQuery("BatchPerformBankChanges"); sp.setParameter("pSCMClaimnumber", rFile.getClaimNumber()); sp.setParameter("pSCMDateOfBirth", rFile.getDateOfBirth(), TemporalType.DATE); sp.setParameter("pFieldNumber", rFile.getIndexOfAccountFieldToCorrect()); sp.setParameter("pDataElement", rFile.getCorrectedData()); String[] address = captureChanges(true, rFile.getCorrectedData()); String[] name = captureChanges(false, rFile.getCorrectedData()); sp.setParameter("pSCMCity", address[0]); sp.setParameter("pSCMState", address[1]); sp.setParameter("pSCMZipcode", address[2]); sp.setParameter("pSCMFName", name[0]); sp.setParameter("pSCMMInitial", name[1]); sp.setParameter("pSCMLastname", name[2]); sp.setParameter("pSCMSuffix", name[3]); sp.execute(); Integer updatedCount = (Integer) sp.getOutputParameterValue("pUpdateCount"); String returnCode = (String) sp.getOutputParameterValue("pErrorCode"); if ("0".equals(returnCode)) { if (updatedCount <= 0) { returnType = MainframeRecordType.NOT_MATCH_C_TRANSACTION; logger.warn("Change command did not update database for CSD #" + rFile.getClaimNumber() + " Birthdate " + rFile.getDateOfBirth() + ": " + recordString); } else { returnType = MainframeRecordType.VALID_C_TRANSACTION; } } else if ("-97".equals(returnCode)) { returnType = MainframeRecordType.BAD_C_TRANSACTION; errorText = "Invalid field number. The program does not accept changes to field # " + rFile.getIndexOfAccountFieldToCorrect() + ": " + recordString; } else { returnType = MainframeRecordType.BAD_C_TRANSACTION; errorText = "Unknown C Transaction error (" + returnCode + "): " + recordString; } } catch (PersistenceException pe) { // Fill import status for logging fillImportStatus(importStatus, MainframeRecordType.BAD_C_TRANSACTION); errorText = "Database Error while changing the applicant record: " + recordString; throw new BatchProcessingException(errorText, pe); } } } else { if ("C".equals(rFile.getTransactionCode())) { returnType = MainframeRecordType.BAD_C_TRANSACTION; } else if ("R".equals(rFile.getTransactionCode())) { returnType = MainframeRecordType.BAD_R_TRANSACTION; } else { returnType = MainframeRecordType.NOT_A_RECORD; } errorText = "Text Line is not a valid Transaction Format [" + rFile.getRecordImportError() + "]: " + recordString; } if (errorText != null) { logger.error("Error importing the record from the MainframeImport table in" + " processImportRecord module: " + returnType + ". " + errorText); } return returnType; }
From source file:com.encens.khipus.service.production.RawMaterialPayRollServiceBean.java
public List<DiscountProducer> findDiscountProducerByDate(Date startDate, Date endDate) { List<DiscountProducer> discountProducers = new ArrayList<DiscountProducer>(); try {//from w ww . jav a2 s. co m discountProducers = (List<DiscountProducer>) getEntityManager() .createQuery(" SELECT discountProducer from DiscountProducer discountProducer " + " where discountProducer.startDate = :startDate " + " and discountProducer.endDate = :endDate " + " and discountProducer.state = 'ENABLE'") .setParameter("startDate", startDate, TemporalType.DATE) .setParameter("endDate", endDate, TemporalType.DATE).getResultList(); } catch (NoResultException e) { return null; } return discountProducers; }
From source file:com.encens.khipus.service.production.RawMaterialPayRollServiceBean.java
public RawMaterialPayRoll getTotalsRawMaterialPayRoll(Date dateIni, Date dateEnd, ProductiveZone productiveZone, MetaProduct metaProduct) {/*from www. j a v a2s. c o m*/ String query = createQuery(productiveZone, metaProduct); RawMaterialPayRoll rawMaterialPayRoll = new RawMaterialPayRoll(); Query queryObj = getEntityManager().createQuery(query).setParameter("startDate", dateIni, TemporalType.DATE) .setParameter("endDate", dateEnd, TemporalType.DATE); if (productiveZone != null) queryObj.setParameter("productiveZone", productiveZone); if (metaProduct != null) queryObj.setParameter("metaProduct", metaProduct); try { /*List<Object[]> datas = getEntityManager().createNamedQuery("RawMaterialPayRoll.getTotalsRawMaterialPayRoll") .setParameter("startDate", dateIni) .setParameter("endDate", dateEnd) .setParameter("productiveZone", productiveZone) //.setParameter("metaProduct",metaProduct) .getResultList();*/ List<Object[]> datas = queryObj.getResultList(); rawMaterialPayRoll.setTotalCollectedByGAB((Double) (datas.get(0)[0])); rawMaterialPayRoll.setTotalMountCollectdByGAB((Double) (datas.get(0)[1])); rawMaterialPayRoll.setTotalRetentionGAB((Double) (datas.get(0)[2])); rawMaterialPayRoll.setTotalCreditByGAB((Double) (datas.get(0)[3])); rawMaterialPayRoll.setTotalVeterinaryByGAB((Double) (datas.get(0)[4])); rawMaterialPayRoll.setTotalAlcoholByGAB((Double) (datas.get(0)[5])); rawMaterialPayRoll.setTotalConcentratedByGAB((Double) (datas.get(0)[6])); rawMaterialPayRoll.setTotalYogourdByGAB((Double) (datas.get(0)[7])); rawMaterialPayRoll.setTotalRecipByGAB((Double) (datas.get(0)[8])); rawMaterialPayRoll.setTotalDiscountByGAB((Double) (datas.get(0)[9])); rawMaterialPayRoll.setTotalAdjustmentByGAB((Double) (datas.get(0)[10])); rawMaterialPayRoll.setTotalOtherIncomeByGAB((Double) (datas.get(0)[11])); rawMaterialPayRoll.setTotalLiquidByGAB((Double) (datas.get(0)[12])); //rawMaterialPayRoll.setProductiveZone((ProductiveZone) (datas.get(0)[13])); rawMaterialPayRoll.setUnitPrice((Double) (datas.get(0)[14])); rawMaterialPayRoll.setTotalReserveDicount((Double) (datas.get(0)[15])); rawMaterialPayRoll.setIue((Double) (datas.get(0)[16])); rawMaterialPayRoll.setIt((Double) (datas.get(0)[17])); rawMaterialPayRoll.setTaxRate((Double) (datas.get(0)[18])); rawMaterialPayRoll.setTotalGA((Double) (datas.get(0)[19])); } catch (Exception e) { log.debug("Not found totals RawMaterialPayRoll...." + e); } return rawMaterialPayRoll; }
From source file:com.encens.khipus.service.production.RawMaterialPayRollServiceBean.java
@Override public List<RawMaterialPayRoll> findAll(Date startDate, Date endDate, MetaProduct metaProduct) { List<RawMaterialPayRoll> rawMaterialPayRolls = getEntityManager() .createNamedQuery("RawMaterialPayRoll.getMaterialPayRollInDates") .setParameter("startDate", startDate, TemporalType.DATE) .setParameter("endDate", endDate, TemporalType.DATE).setParameter("metaProduct", metaProduct) .getResultList();//ww w.ja va 2s . com return rawMaterialPayRolls; }