List of usage examples for java.sql Date getTime
public long getTime()
From source file:org.pentaho.di.core.jdbc.ThinResultSet.java
@Override public Timestamp getTimestamp(int index) throws SQLException { java.util.Date date = getDate(index); if (date == null) { return null; }//from www . jav a2s .c om return new Timestamp(date.getTime()); }
From source file:fr.paris.lutece.plugins.calendar.business.CalendarDAO.java
/** * Return 1 if the day contains an event 0 otherwise * @param calendar The day//from w ww . jav a 2 s . co m * @param plugin The plugin * @return 1 if the day contains an event 0 otherwise */ public boolean hasOccurenceEvent(Calendar calendar, Plugin plugin) { DAOUtil daoUtil = new DAOUtil(SQL_QUERY_HAS_EVENT, plugin); boolean isOccurrence = false; String date = Utils.getDate(calendar); java.util.Date dateEvent = Utils.getDate(date); daoUtil.setDate(1, new java.sql.Date(dateEvent.getTime())); daoUtil.executeQuery(); while (daoUtil.next()) { isOccurrence = true; } daoUtil.free(); return isOccurrence; }
From source file:org.pasta.apps.form.InvoiceReturn.java
public Vector<Vector<Object>> getData(int orgId, String invoiceFrom, String invoiceTo, java.util.Date invoiceDateFrom, java.util.Date invoiceDateTo, int invoiceDocType, int customerId, String invoiceSent) {/*from w ww. ja v a 2 s .com*/ Vector<Vector<Object>> dataL = new Vector<Vector<Object>>(); List<Object> params = new ArrayList<Object>(); StringBuffer sql = new StringBuffer( "SELECT iv.IsSent , iv.DocumentNo , bp.Name as CustomerName , iv.DateInvoiced , iv.GrandTotal , iv.InvoiceStatusNote , iv.C_Invoice_ID\n"); sql.append("FROM C_Invoice iv INNER JOIN C_BPartner bp ON iv.C_BPartner_ID = bp.C_BPartner_ID ").append( "WHERE iv.IsSOTrx = 'Y' AND iv.DocStatus ='CO' AND iv.AD_Client_ID = ? AND iv.AD_Org_Id = ? \n"); params.add(Env.getAD_Client_ID(getCtx())); params.add(orgId); if (!StringUtils.isEmpty(invoiceFrom)) { sql.append("AND iv.DocumentNo >= ? "); params.add(invoiceFrom); } if (!StringUtils.isEmpty(invoiceTo)) { sql.append("AND iv.DocumentNo <= ? "); params.add(invoiceTo); } if (invoiceDateFrom != null) { sql.append("AND iv.DateInvoiced >= ? "); java.sql.Date dateFrom = new java.sql.Date(invoiceDateFrom.getTime()); params.add(dateFrom); } if (invoiceDateTo != null) { sql.append("AND iv.DateInvoiced <= ? "); java.sql.Date dateTo = new java.sql.Date(invoiceDateTo.getTime()); params.add(dateTo); } if (invoiceDocType > 0) { sql.append("AND iv.C_DocType_ID = ? "); params.add(invoiceDocType); } if (customerId > 0) { sql.append("AND iv.C_BPartner_ID = ? "); params.add(customerId); } if (!StringUtils.isEmpty(invoiceSent)) { sql.append("AND COALESCE(iv.IsSent,'N') = ? "); params.add(invoiceSent); } sql.append("ORDER BY iv.DocumentNo Desc , iv.DateInvoiced "); PreparedStatement pstmt = DB.prepareStatement(sql.toString(), null); try { int prmIdx = 1; for (Object param : params) { pstmt.setObject(prmIdx++, param); } ResultSet rs = pstmt.executeQuery(); while (rs.next()) { ids.put(rs.getString("DocumentNo"), rs.getInt("C_Invoice_ID")); Vector<Object> line = new Vector<Object>(7); line.add(new Boolean(false)); KeyNamePair pp = new KeyNamePair(rs.getInt("C_Invoice_ID"), rs.getString("DocumentNo")); line.add(pp); line.add(rs.getString("CustomerName")); line.add(rs.getTimestamp("DateInvoiced")); line.add(rs.getBigDecimal("GrandTotal")); line.add(StringUtils.defaultIfEmpty(rs.getString("InvoiceStatusNote"), "")); line.add(new Boolean("Y".equals(rs.getString("IsSent")))); dataL.add(line); } rs.close(); pstmt.close(); } catch (Exception ex) { log.log(Level.SEVERE, sql.toString(), ex); } return dataL; }
From source file:org.kuali.kfs.module.tem.document.service.TravelDocumentServiceTest.java
/** * * This method creates a list of per diems. * @return/*from w w w .j ava 2 s. c om*/ */ private List<PerDiemExpense> createAListOfPerDiems() { PerDiemExpense perDiemExpense = new PerDiemExpense() { @Override public MileageRate getMileageRate(java.sql.Date effectiveDate) { MileageRate rate = new MileageRate(); rate.setRate(new BigDecimal(0.45)); rate.setExpenseTypeCode("MP"); return rate; } }; Date today = dateTimeService.getCurrentSqlDateMidnight(); Calendar cal = Calendar.getInstance(); cal.setTime(today); perDiemExpense.setMiles(20); final PerDiem perDiem = findSomePerDiem(new java.sql.Date(cal.getTimeInMillis())); List<PerDiemExpense> perDiemExpenses = new ArrayList<PerDiemExpense>(); if (perDiem != null) { perDiemExpense.setPrimaryDestinationId(perDiem.getPrimaryDestinationId()); perDiemExpense.setLodging(perDiem.getLodging()); perDiemExpense.setMileageDate(new Timestamp(today.getTime())); perDiemExpense.setBreakfast(true); perDiemExpense.setLunch(true); perDiemExpense.setDinner(true); PerDiemExpense perDiemExpense2 = this.copyPerDiem(perDiemExpense); cal.add(Calendar.DATE, 1); perDiemExpense2.setMileageDate(new Timestamp(cal.getTimeInMillis())); perDiemExpense2.setPrimaryDestinationId(perDiem.getPrimaryDestinationId()); perDiemExpense2.setMiles(30); perDiemExpense2.setLodging(perDiem.getLodging()); perDiemExpense2.setBreakfast(true); perDiemExpense2.setLunch(true); perDiemExpense2.setDinner(true); PerDiemExpense perDiemExpense3 = this.copyPerDiem(perDiemExpense2); cal.add(Calendar.DATE, 1); perDiemExpense3.setMileageDate(new Timestamp(cal.getTimeInMillis())); perDiemExpense3.setPrimaryDestinationId(perDiem.getPrimaryDestinationId()); perDiemExpense3.setMiles(40); perDiemExpense3.setLodging(perDiem.getLodging()); perDiemExpense3.setBreakfast(true); perDiemExpense3.setLunch(true); perDiemExpense3.setDinner(true); perDiemExpenses.add(perDiemExpense); perDiemExpenses.add(perDiemExpense2); perDiemExpenses.add(perDiemExpense3); } return perDiemExpenses; }
From source file:com.mobiaware.auction.data.impl.MySqlDataServiceImpl.java
@Override public Auction getAuction(final int uid) { Auction obj = null;/*w w w .ja v a 2 s. co m*/ Connection conn = null; CallableStatement stmt = null; ResultSet rs = null; try { conn = _dataSource.getConnection(); stmt = conn.prepareCall("{call SP_GETAUCTION (?)}"); stmt.setInt(1, uid); rs = stmt.executeQuery(); if (rs.next()) { AuctionBuilder builder = Auction.newBuilder().setUid(rs.getInt("UID")) .setName(rs.getString("NAME")); Date startdate = rs.getDate("STARTDATE"); if (startdate != null) { builder.setStartDate(startdate.getTime()); } Date enddate = rs.getDate("ENDDATE"); if (enddate != null) { builder.setEndDate(enddate.getTime()); } builder.setLogoUrl(rs.getString("LOGOURL")); builder.setColor(rs.getString("COLOR")); obj = builder.build(); } } catch (SQLException e) { LOG.error(Throwables.getStackTraceAsString(e)); } finally { DbUtils.closeQuietly(conn, stmt, rs); } if (LOG.isDebugEnabled()) { LOG.debug("AUCTION [method:{} result:{}]", new Object[] { "get", obj != null ? obj.toString() : "[error]" }); } return obj; }
From source file:com.mobiaware.auction.data.impl.MySqlDataServiceImpl.java
@Override public List<Auction> getAuctions(final int start, final int length, final String sort, final String dir) { List<Auction> objs = Lists.newArrayList(); Connection conn = null;/*w ww . java 2s . com*/ CallableStatement stmt = null; ResultSet rs = null; try { conn = _dataSource.getConnection(); stmt = conn.prepareCall("{call SP_GETAUCTIONS (?,?,?,?)}"); stmt.setInt(1, start); stmt.setInt(2, length); stmt.setString(3, sort); stmt.setString(4, dir); rs = stmt.executeQuery(); while (rs.next()) { AuctionBuilder builder = Auction.newBuilder().setUid(rs.getInt("UID")) .setName(rs.getString("NAME")); Date startdate = rs.getDate("STARTDATE"); if (startdate != null) { builder.setStartDate(startdate.getTime()); } Date enddate = rs.getDate("ENDDATE"); if (enddate != null) { builder.setEndDate(enddate.getTime()); } builder.setLogoUrl(rs.getString("LOGOURL")); builder.setColor(rs.getString("COLOR")); objs.add(builder.build()); } } catch (SQLException e) { LOG.error(Throwables.getStackTraceAsString(e)); } finally { DbUtils.closeQuietly(conn, stmt, rs); } if (LOG.isDebugEnabled()) { LOG.debug("AUCTION [method:{} result:{}]", new Object[] { "get", objs.size() }); } return ImmutableList.copyOf(objs); }
From source file:pt.fct.di.benchmarks.TPCW_Riak.database.TPCW_Riak_Executor.java
public void updateIndex(String subject, java.util.Date date, int item_id, String title, int author_key) throws Exception { Author author = (Author) GSON/* www. j a v a 2 s . c o m*/ .fromJson(getBucket("author").fetch(author_key + "").execute().getValueAsString(), Author.class); AuthorIndex authorIndex = new AuthorIndex(author.getA_FNAME(), author.getA_LNAME(), title); Date d = new Date(System.currentTimeMillis()); Long new_time_stamp = Long.MAX_VALUE - d.getTime(); String new_index_key = new_time_stamp + "." + item_id; getBucket(subject + "_item_subject_index").store(new_index_key, GSON.toJson(authorIndex)).execute(); // index(new_index_key, subject+"_item_subject_index", new_index_key, // authorIndex); // TODO: Isto no deve estar a funcionar, parece estranho Long old_time_stamp = Long.MAX_VALUE - date.getTime(); String old_index_key = old_time_stamp + "." + item_id; remove(old_index_key, subject + "_item_subject_index", null); }
From source file:com.continuent.tungsten.common.mysql.MySQLPacket.java
/** * Puts a {@link Date} to the buffer as:<br> * two bytes year one byte month one byte day * /*from w w w . j a v a2s. co m*/ * @param d jdbc date to write * @return the rounded date as milliseconds actually put (without hh mm ss * ms information) */ public long putDate(Date d) { Calendar fullDate = new GregorianCalendar(); fullDate.clear(); fullDate.setTimeInMillis(d.getTime()); // MYO-100: We need to return the remaining millis for the date only, // not for its HHMMSSMS Calendar yymmddOnly = new GregorianCalendar(fullDate.get(Calendar.YEAR), fullDate.get(Calendar.MONTH), fullDate.get(Calendar.DAY_OF_MONTH)); // Note: Supported range for MySQL date is '1000-01-01' to '9999-12-31'. // So we don't care about era field (BC/AD) putInt16(yymmddOnly.get(Calendar.YEAR)); // 1-based (ie. 1 for January) putByte((byte) (1 + yymmddOnly.get(Calendar.MONTH))); // 1-based (ie. 1 for 1st of the month) putByte((byte) yymmddOnly.get(Calendar.DAY_OF_MONTH)); return yymmddOnly.getTimeInMillis(); }
From source file:org.kuali.kfs.module.tem.service.impl.TravelEncumbranceServiceImpl.java
/** * Returns the first accounting period of the given fiscal year * @param fiscalYear the fiscal year to find the first accounting period for * @return the first accounting period of the given fiscal year *//* w w w. j a va2 s. c om*/ protected AccountingPeriod getFirstAccountingPeriodOfFiscalYear(Integer fiscalYear) { final java.util.Date firstDateOfFiscalYear = getUniversityDateService() .getFirstDateOfFiscalYear(fiscalYear); final AccountingPeriod firstAccountingPeriodOfFiscalYear = getAccountingPeriodService() .getByDate(new java.sql.Date(firstDateOfFiscalYear.getTime())); return firstAccountingPeriodOfFiscalYear; }
From source file:org.pentaho.di.core.jdbc.ThinResultSet.java
@Override public Date getDate(int index) throws SQLException { try {/*from w w w . j a v a 2 s. c om*/ java.util.Date date = rowMeta.getDate(currentRow, index - 1); if (date == null) { lastNull = true; return null; } lastNull = false; return new Date(date.getTime()); } catch (Exception e) { throw new SQLException(e); } }