java.sql.Date Java Examples

The following examples show how to use java.sql.Date. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CustomersSecuritiesPortfolioSubqueryStmt.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
private ResultSet getUniqQuery3(Connection conn, int whichQuery,  
    Date since, int tid) {
  boolean[] success = new boolean[1];
  ResultSet rs = null;
  rs = getUniqQuery3(conn, whichQuery, since, tid, success);
  int count=0;
  while (!success[0]) {
    if (SQLHelper.isDerbyConn(conn) || count>=maxNumOfTries) {
      Log.getLogWriter().info("Could not get the resultSet " +
          "abort this operation");
      return rs;
  }
    count++;
    rs = getUniqQuery3(conn, whichQuery, since, tid, success);
  } //retry
  return rs;
}
 
Example #2
Source File: WhereClauseOptimizerTest.java    From phoenix with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
public void testLessThanRound() throws Exception {
    String inst = "a";
    String host = "b";
    Date startDate = DateUtil.parseDate("2012-01-01 01:00:00");
    Date endDate = DateUtil.parseDate("2012-01-02 00:00:00");
    String query = "select * from ptsdb where inst=? and host=? and round(date,'DAY')<?";
    Scan scan = new Scan();
    List<Object> binds = Arrays.<Object>asList(inst,host,startDate);
    compileStatement(query, scan, binds);

    byte[] startRow = ByteUtil.concat(PDataType.VARCHAR.toBytes(inst),QueryConstants.SEPARATOR_BYTE_ARRAY,
            PDataType.VARCHAR.toBytes(host),QueryConstants.SEPARATOR_BYTE_ARRAY);
    assertArrayEquals(startRow, scan.getStartRow());
    byte[] stopRow = ByteUtil.concat(PDataType.VARCHAR.toBytes(inst),QueryConstants.SEPARATOR_BYTE_ARRAY,
            PDataType.VARCHAR.toBytes(host),QueryConstants.SEPARATOR_BYTE_ARRAY,
            PDataType.DATE.toBytes(endDate));
    assertArrayEquals(stopRow, scan.getStopRow());
}
 
Example #3
Source File: OrderService.java    From EasyTransaction with Apache License 2.0 6 votes vote down vote up
private Integer saveOrderRecord(JdbcTemplate jdbcTemplate, final int userId, final long money) {
	
	final String INSERT_SQL = "INSERT INTO `order` (`order_id`, `user_id`, `money`, `create_time`) VALUES (NULL, ?, ?, ?);";
	KeyHolder keyHolder = new GeneratedKeyHolder();
	jdbcTemplate.update(
	    new PreparedStatementCreator() {
	    	@Override
	        public PreparedStatement createPreparedStatement(Connection connection) throws SQLException {
	            PreparedStatement ps =
	                connection.prepareStatement(INSERT_SQL, new String[] {"id"});
	            ps.setInt(1, userId);
	            ps.setLong(2, money);
	            ps.setDate(3, new Date(System.currentTimeMillis()));
	            return ps;
	        }
	    },
	    keyHolder);
	
	return keyHolder.getKey().intValue();
}
 
Example #4
Source File: WhereOptimizerTest.java    From phoenix with Apache License 2.0 6 votes vote down vote up
@Test
public void testGreaterThanRound() throws Exception {
    String inst = "a";
    String host = "b";
    Date startDate = DateUtil.parseDate("2012-01-01 01:00:00");
    Date endDate = DateUtil.parseDate("2012-01-02 00:00:00");
    String query = "select * from ptsdb where inst=? and host=? and round(date,'DAY')>?";
    List<Object> binds = Arrays.<Object>asList(inst,host,startDate);
    Scan scan = compileStatement(query, binds).getScan();
    assertNull(scan.getFilter());

    byte[] startRow = ByteUtil.concat(PVarchar.INSTANCE.toBytes(inst),QueryConstants.SEPARATOR_BYTE_ARRAY,
            PVarchar.INSTANCE.toBytes(host),QueryConstants.SEPARATOR_BYTE_ARRAY,
            PDate.INSTANCE.toBytes(endDate));
    assertArrayEquals(startRow, scan.getStartRow());
    byte[] stopRow = ByteUtil.nextKey(ByteUtil.concat(PVarchar.INSTANCE.toBytes(inst),QueryConstants.SEPARATOR_BYTE_ARRAY,
            PVarchar.INSTANCE.toBytes(host),QueryConstants.SEPARATOR_BYTE_ARRAY));
    assertArrayEquals(stopRow, scan.getStopRow());
}
 
Example #5
Source File: CustomersSecuritiesPortfolioSubqueryStmt.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
private ResultSet getUniqQuery0(Connection conn, int whichQuery,  
    Date since, int tid) {
  boolean[] success = new boolean[1];
  ResultSet rs = null;
  rs = getUniqQuery0(conn, whichQuery, since, tid, success);
  int count=0;
  while (!success[0]) {
    if (SQLHelper.isDerbyConn(conn) || count>=maxNumOfTries) {
      Log.getLogWriter().info("Could not get the resultSet " +
          "abort this operation");
      return rs;
  }
    count++;
    rs = getUniqQuery0(conn, whichQuery, since, tid, success);
  } //retry
  return rs;
}
 
Example #6
Source File: ResultSet.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Transform a String value to a date value
 *
 * @param stringValue
 *            String value
 * @return Corresponding date value
 * @throws OdaException
 */

private Date stringToDate(String stringValue) throws OdaException {
	if (stringValue != null && stringValue.trim().length() > 0) {
		try{
			//return new Date (excelDateToDate(Double.parseDouble(stringValue)).getTime());
			return DateUtil.toSqlDate( stringValue );
		} catch( Exception ex){

			throw new OdaException(Messages.getFormattedString(
					"invalid_date_value", new String[] { stringValue })); //$NON-NLS-1$
		}
	}

	this.wasNull = true;
	return null;
}
 
Example #7
Source File: PDate.java    From phoenix with Apache License 2.0 6 votes vote down vote up
@Override
public int compareTo(Object lhs, Object rhs, PDataType rhsType) {
    if (lhs == rhs) {
        return 0;
    }
    if (lhs == null) {
        return -1;
    }
    if (rhs == null) {
        return 1;
    }
    if (rhsType == PTimestamp.INSTANCE || rhsType == PUnsignedTimestamp.INSTANCE) {
        return -rhsType.compareTo(rhs, lhs, PTime.INSTANCE);
    }
    return ((java.util.Date) lhs).compareTo((java.util.Date) rhs);
}
 
Example #8
Source File: TradeNetworthV1DMLDistTxStmt.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
protected void addUpdateToDerbyTx(long[] cid, long[] c_cid, BigDecimal[] availLoanDelta, 
    BigDecimal[] sec, BigDecimal[] cashDelta, int[] newLoanLimit, Date[] since,
    BigDecimal[] cash, int[] whichUpdate, int[] updateCount, SQLException gfxdse){
  Object[] data = new Object[13];      
  data[0] = DMLDistTxStmtsFactory.TRADE_NETWORTH;
  data[1] = "update";
  data[2] = cid;
  data[3] = c_cid;
  data[4] = availLoanDelta;
  data[5] = sec;
  data[6] = cashDelta;
  data[7] = newLoanLimit;
  data[8] = since;
  data[9] = cash;
  data[10] = whichUpdate;
  data[11] = updateCount;
  data[12] = gfxdse;
   
  ArrayList<Object[]> derbyOps = (ArrayList<Object[]>)SQLDistTxTest.derbyOps.get();
  if (derbyOps == null) derbyOps = new ArrayList<Object[]>();
  derbyOps.add(data);
  SQLDistTxTest.derbyOps.set(derbyOps);
}
 
Example #9
Source File: TaxableRamificationNotificationServiceImpl.java    From kfs with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * @see org.kuali.kfs.module.tem.batch.service.TaxableRamificationNotificationService#sendTaxableRamificationReport(org.kuali.kfs.module.tem.businessobject.TravelAdvance,
 *      java.sql.Date)
 */
@Override
@Transactional
public TaxableRamificationDocument createTaxableRamificationDocument(TravelAdvance travelAdvance, Date taxableRamificationNotificationDate) {
    if (ObjectUtils.isNull(travelAdvance)) {
        throw new RuntimeException("The given travel advance cannot be null.");
    }

    TaxableRamificationDocument taxRamificationDocument = this.getTaxableRamificationDocumentService().createAndBlanketApproveRamificationDocument(travelAdvance);
    if (ObjectUtils.isNotNull(taxRamificationDocument)) {
        travelAdvance.setTaxRamificationNotificationDate(taxableRamificationNotificationDate);
        this.getBusinessObjectService().save(travelAdvance);
    }

    return taxRamificationDocument;
}
 
Example #10
Source File: YearEndFlexibleOffsetTest.java    From kfs with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Initialize defaults for each test.
 * @see org.kuali.kfs.gl.businessobject.OriginEntryTestBase#setUp()
 */
@Override
public void setUp() throws Exception {
    super.setUp();

    this.boService = SpringContext.getBean(BusinessObjectService.class);
    this.fiscalYear = new Integer((SpringContext.getBean(UniversityDateService.class).getCurrentFiscalYear()).intValue() - 1);
    this.transactionDate = new java.sql.Date(new java.util.Date().getTime());
    this.parameterService = SpringContext.getBean(ParameterService.class);
    this.objectTypeService = SpringContext.getBean(ObjectTypeService.class);

    DEFAULT_FLEXIBLE_ENCUMBRANCE_SUB_ACCT_NBR = KFSConstants.getDashSubAccountNumber();
    DEFAULT_NO_FLEXIBLE_ENCUMBRANCE_SUB_ACCT_NBR = KFSConstants.getDashSubAccountNumber();

    createFlexibleOffsetAccounts();
}
 
Example #11
Source File: TaxableRamificationDocumentServiceImpl.java    From kfs with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * @see org.kuali.kfs.module.tem.service.TaxableRamificationDocumentService#getAllQualifiedOutstandingTravelAdvance()
 */
@Override
public List<TravelAdvance> getAllQualifiedOutstandingTravelAdvance() {
    List<TravelAdvance> qualifiedOutstandingTravelAdvance = new ArrayList<TravelAdvance>();

    List<String> customerTypeCodes = this.getTravelerCustomerTypes();
    Integer customerInvoiceAge = this.getNotificationOnDays();

    Date lastTaxableRamificationNotificationDate = this.getLastTaxableRamificationNotificationDate();
    if (ObjectUtils.isNull(lastTaxableRamificationNotificationDate)) {
        lastTaxableRamificationNotificationDate = SpringContext.getBean(DateTimeService.class).getCurrentSqlDate();
    }
    Map<String, KualiDecimal> invoiceOpenAmountMap = this.getAccountsReceivableModuleService().getCustomerInvoiceOpenAmount(customerTypeCodes, customerInvoiceAge, lastTaxableRamificationNotificationDate);
    Set<String> arInvoiceDocNumbers = invoiceOpenAmountMap.keySet();

    if (ObjectUtils.isNotNull(arInvoiceDocNumbers) && !arInvoiceDocNumbers.isEmpty()) {
        qualifiedOutstandingTravelAdvance = this.getTravelDocumentService().getOutstandingTravelAdvanceByInvoice(arInvoiceDocNumbers);
    }

    return qualifiedOutstandingTravelAdvance;
}
 
Example #12
Source File: ObjectCasts.java    From presto with Apache License 2.0 6 votes vote down vote up
public static Date castToDate(Object x, int targetSqlType)
        throws SQLException
{
    if (x instanceof Date) {
        return (Date) x;
    }
    if (x instanceof java.util.Date) {
        return new Date(((java.util.Date) x).getTime());
    }
    if (x instanceof LocalDate) {
        return Date.valueOf((LocalDate) x);
    }
    if (x instanceof LocalDateTime) {
        return Date.valueOf(((LocalDateTime) x).toLocalDate());
    }
    try {
        if (x instanceof String) {
            return Date.valueOf((String) x);
        }
    }
    catch (RuntimeException e) {
        throw invalidConversion(x, targetSqlType, e);
    }
    throw invalidConversion(x, targetSqlType);
}
 
Example #13
Source File: ProductMetricsIT.java    From phoenix with Apache License 2.0 6 votes vote down vote up
@Test
public void testTruncateNotTraversableToFormScanKey() throws Exception {
    long ts = nextTimestamp();
    String tenantId = getOrganizationId();
    String query = "SELECT feature FROM PRODUCT_METRICS WHERE organization_id = ? and TRUNC(date,'DAY') <= ?"; 
    String url = getUrl() + ";" + PhoenixRuntime.CURRENT_SCN_ATTRIB + "=" + (ts + 5); // Run query at timestamp 5
    Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
    Connection conn = DriverManager.getConnection(url, props);
    try {
        Date startDate = toDate("2013-01-01 00:00:00");
        initDateTableValues(tenantId, getSplits(tenantId), ts, startDate, 0.5);
        PreparedStatement statement = conn.prepareStatement(query);
        statement.setString(1, tenantId);
        statement.setDate(2, new Date(startDate.getTime() + (long)(QueryConstants.MILLIS_IN_DAY * 0.25)));
        ResultSet rs = statement.executeQuery();
        assertTrue(rs.next());
        assertEquals("A", rs.getString(1));
        assertTrue(rs.next());
        assertEquals("B", rs.getString(1));
        assertFalse(rs.next());
    } finally {
        conn.close();
    }
}
 
Example #14
Source File: CustomerBillClear.java    From logistics-back with MIT License 6 votes vote down vote up
public CustomerBillClear(String customerCode, String goodsBillCode, double billMoney, double moneyReceivable,
		double receivedMoney, double prepayMoney, double carriageReduceFund, double balance, Date balanceTime,
		double insurance, double payKickback, double carryGoodsFee, String balanceType) {
	super();
	CustomerCode = customerCode;
	this.goodsBillCode = goodsBillCode;
	this.billMoney = billMoney;
	this.moneyReceivable = moneyReceivable;
	this.receivedMoney = receivedMoney;
	this.prepayMoney = prepayMoney;
	this.carriageReduceFund = carriageReduceFund;
	this.balance = balance;
	this.balanceTime = balanceTime;
	this.insurance = insurance;
	this.payKickback = payKickback;
	this.carryGoodsFee = carryGoodsFee;
	this.balanceType = balanceType;
}
 
Example #15
Source File: FieldMetaData.java    From FastDFS_Client with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * 将属性值转换为byte
 *
 * @param charset
 * @return
 * @throws NoSuchMethodException
 * @throws InvocationTargetException
 * @throws IllegalAccessException
 */
public byte[] toByte(Object bean, Charset charset)
        throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
    Object value = this.getFieldValue(bean);
    if (isDynamicField()) {
        return getDynamicFieldByteValue(value, charset);
    } else if (String.class.equals(field.getType())) {
        // 如果是动态属性
        return BytesUtil.objString2Byte((String) value, max, charset);
    } else if (long.class.equals(field.getType())) {
        return BytesUtil.long2buff((long) value);
    } else if (int.class.equals(field.getType())) {
        return BytesUtil.long2buff((int) value);
    } else if (Date.class.equals(field.getType())) {
        throw new FdfsColumnMapException("Date 还不支持");
    } else if (byte.class.equals(field.getType())) {
        byte[] result = new byte[1];
        result[0] = (byte) value;
        return result;
    } else if (boolean.class.equals(field.getType())) {
        throw new FdfsColumnMapException("boolean 还不支持");
    }
    throw new FdfsColumnMapException("将属性值转换为byte时未识别的FdfsColumn类型" + field.getName());
}
 
Example #16
Source File: RoundFloorCeilFunctionsEnd2EndTest.java    From phoenix with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testRoundingUpDate() throws Exception {
    Connection conn = DriverManager.getConnection(getUrl());
    ResultSet rs = conn.createStatement().executeQuery("SELECT ROUND(dt, 'day'), ROUND(dt, 'hour', 1), ROUND(dt, 'minute', 1), ROUND(dt, 'second', 1), ROUND(dt, 'millisecond', 1) FROM ROUND_DATE_TIME_TS_DECIMAL");
    assertTrue(rs.next());
    Date expectedDate = DateUtil.parseDate("2012-01-02 00:00:00");
    assertEquals(expectedDate, rs.getDate(1));
    expectedDate = DateUtil.parseDate("2012-01-01 14:00:00");
    assertEquals(expectedDate, rs.getDate(2));
    expectedDate = DateUtil.parseDate("2012-01-01 14:25:00");
    assertEquals(expectedDate, rs.getDate(3));
    expectedDate = DateUtil.parseDate("2012-01-01 14:25:29");
    assertEquals(expectedDate, rs.getDate(4));
}
 
Example #17
Source File: RoundFloorCeilExpressionsTest.java    From phoenix with Apache License 2.0 5 votes vote down vote up
@Test
public void testRoundDateExpression() throws Exception {
    LiteralExpression dateLiteral = LiteralExpression.newConstant(DateUtil.parseDate("2012-01-01 14:25:28"), PDate.INSTANCE);
    Expression roundDateExpression = RoundDateExpression.create(dateLiteral, TimeUnit.DAY);
    
    ImmutableBytesWritable ptr = new ImmutableBytesWritable();
    roundDateExpression.evaluate(null, ptr);
    Object result = roundDateExpression.getDataType().toObject(ptr);
    
    assertTrue(result instanceof Date);
    Date resultDate = (Date)result;
    assertEquals(DateUtil.parseDate("2012-01-02 00:00:00"), resultDate);
}
 
Example #18
Source File: TradesHdfsDataVerifierV2.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
@Override
public void readFields(DataInput in) throws IOException {
  cid = in.readInt();
  tid=in.readInt();
  eid=in.readInt();
  tradeDate=new Date(in.readLong());
}
 
Example #19
Source File: StandardDialectTest.java    From doma with Apache License 2.0 5 votes vote down vote up
@Test
public void testExpressionFunctions_roundUpTimePart_forDate_endOfYear() throws Exception {
  StandardDialect dialect = new StandardDialect();
  ExpressionFunctions functions = dialect.getExpressionFunctions();
  Calendar calendar = Calendar.getInstance();
  calendar.set(2009, Calendar.DECEMBER, 31, 0, 0, 0);
  Date date = new Date(calendar.getTimeInMillis());
  assertEquals(Date.valueOf("2010-01-01").getTime(), functions.roundUpTimePart(date).getTime());
}
 
Example #20
Source File: SpliceDateFunctions.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Implements the LAST_DAY function
 */
public static Date LAST_DAY(Date source) {
    if (source == null) {
        return null;
    }
    DateTime dt = new DateTime(source).dayOfMonth().withMaximumValue();
    return new Date(dt.getMillis());
}
 
Example #21
Source File: BatchInsertsTest.java    From clickhouse-jdbc with Apache License 2.0 5 votes vote down vote up
@Test
public void testBatchValuesColumn() throws SQLException {
    connection.createStatement().execute("DROP TABLE IF EXISTS test.batch_single_test");
    connection.createStatement().execute(
            "CREATE TABLE test.batch_single_test(date Date, values String) ENGINE = StripeLog"
    );

    PreparedStatement st = connection.prepareStatement("INSERT INTO test.batch_single_test (date, values) VALUES (?, ?)");
    st.setDate(1, new Date(System.currentTimeMillis()));
    st.setString(2, "test");

    st.addBatch();
    st.executeBatch();
}
 
Example #22
Source File: DefaultDatatypeCoder.java    From jaybird with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public Date encodeDate(java.sql.Date d, Calendar cal) {
    if (cal == null) {
        return (d);
    } else {
        cal.setTime(d);
        return new Date(cal.getTime().getTime());
    }
}
 
Example #23
Source File: Plot.java    From PlotMe-Core with GNU General Public License v3.0 5 votes vote down vote up
public Plot(long internalID, String owner, UUID ownerId, IWorld world, String biome, Date expiredDate,
        HashMap<String, AccessLevel> allowed,
        HashSet<String>
                denied,
        HashSet<UUID> likers, PlotId id, double price, boolean forSale, boolean finished, String finishedDate, boolean protect,
        Map<String, Map<String, String>> metadata, int plotLikes, String plotName, Vector topLoc, Vector bottomLoc, String createdDate) {
    this.internalID = internalID;
    this.owner = owner;
    this.ownerId = ownerId;
    this.world = world;
    this.biome = biome;
    this.expiredDate = expiredDate;
    this.finished = finished;
    this.finishedDate = finishedDate;
    this.allowed.putAll(allowed);
    this.id = id;
    this.price = price;
    this.forSale = forSale;
    this.finishedDate = finishedDate;
    this.protect = protect;
    this.likers.addAll(likers);
    this.plotName = plotName;
    this.likes = plotLikes;
    this.denied.addAll(denied);
    this.metadata.putAll(metadata);
    this.plotTopLoc = topLoc;
    this.plotBottomLoc = bottomLoc;
    this.createdDate = createdDate;
}
 
Example #24
Source File: SqlDateSerializer.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public Date deserialize(DataInputView source) throws IOException {
	final long v = source.readLong();
	if (v == Long.MIN_VALUE) {
		return null;
	} else {
		return new Date(v);
	}
}
 
Example #25
Source File: TradeCustomersDMLStmt.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
protected void getDataForUpdate(String[] cust_name,
    Date[] since, String[] addr, int size) {
 
  int data = 1000;
  String temp;
  if (!randomData) {
    //update since using the same date if not random
    for (int i=0; i<size; i++) {
      temp = cust_name[i];
      //Log.getLogWriter().info("temp is " + temp);
      if (temp.indexOf('_') != -1) {
        cust_name[i] = temp.substring(0, temp.indexOf('_')+1) +(Integer.parseInt(temp.substring(temp.indexOf('_')+1))+1);
      } else {
        cust_name[i] += "_1";
      }//update of name
      
      temp = addr[i];
      if (temp.indexOf('_') != -1) {
        addr[i] = temp.substring(0, temp.indexOf('_')+1) + (Integer.parseInt(temp.substring(temp.indexOf('_')+1))+1);
      } else {
        addr[i] += "_1";
      }
    } //update of address
  } else {
    for (int i=0; i<size; i++) {
      cust_name[i] = "name" + rand.nextInt(data);
      addr[i] = "address is " + cust_name[i];    
      since[i] = getSince();  
    }//random data for update
  }    
}
 
Example #26
Source File: ProductMetricsIT.java    From phoenix with Apache License 2.0 5 votes vote down vote up
@Test
public void testRoundAggregation() throws Exception {
    long ts = nextTimestamp();
    String tenantId = getOrganizationId();
    String query = "SELECT round(date,'hour',1) r,count(1) FROM PRODUCT_METRICS WHERE organization_id=? GROUP BY r";
    String url = getUrl() + ";" + PhoenixRuntime.CURRENT_SCN_ATTRIB + "=" + (ts + 5); // Run query at timestamp 5
    Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
    Connection conn = DriverManager.getConnection(url, props);
    try {
        initTableValues(tenantId, getSplits(tenantId), ts);
        PreparedStatement statement = conn.prepareStatement(query);
        statement.setString(1, tenantId);
        Date d;
        int c;
        ResultSet rs = statement.executeQuery();
        
        assertTrue(rs.next());
        d = rs.getDate(1);
        c = rs.getInt(2);
        assertEquals(1 * 60 * 60 * 1000, d.getTime()); // Date bucketed into 1 hr
        assertEquals(2, c);
        
        assertTrue(rs.next());
        d = rs.getDate(1);
        c = rs.getInt(2);
        assertEquals(2 * 60 * 60 * 1000, d.getTime()); // Date bucketed into 2 hr
        assertEquals(3, c);
        
        assertTrue(rs.next());
        d = rs.getDate(1);
        c = rs.getInt(2);
        assertEquals(4 * 60 * 60 * 1000, d.getTime()); // Date bucketed into 4 hr
        assertEquals(1, c);
        
        assertFalse(rs.next());
    } finally {
        conn.close();
    }
}
 
Example #27
Source File: SqlDateSerializer.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public Date copy(Date from) {
	if (from == null) {
		return null;
	}
	return new Date(from.getTime());
}
 
Example #28
Source File: ExerciseGPSStorage.java    From OpenFit with MIT License 5 votes vote down vote up
public void updateExerciseTimestamp(int id, long start, long end) {
    Log.d(LOG_TAG, "UPDATE " + db.EXERCISE_TABLE + ": start =" + new Date(start) + ": end =" + new Date(end) + ": id =" + id);

    ContentValues values = new ContentValues();
    values.put("timestampStart", start);
    values.put("timestampEnd", end);
    SQLiteDatabase wdb = db.getWritableDatabase();
    wdb.update(db.EXERCISE_TABLE, values, "id=" + id, null);
    wdb.close();
}
 
Example #29
Source File: PurapServiceImpl.java    From kfs with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * @see org.kuali.kfs.module.purap.document.service.PurapService#getDateFromOffsetFromToday(int)
 */
@Override
public java.sql.Date getDateFromOffsetFromToday(int offsetDays) {
    Calendar calendar = dateTimeService.getCurrentCalendar();
    calendar.add(Calendar.DATE, offsetDays);
    return new java.sql.Date(calendar.getTimeInMillis());
}
 
Example #30
Source File: AbstractQ6.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
@Override
public int executeQuery() throws SQLException {
  Object[] args = getRandomArgs();
  Date date = (Date)(args[0]);
  Timestamp timestamp = (Timestamp)(args[1]);
  double discount = (Double)(args[2]);
  int quantity = (Integer)(args[3]);
  ResultSet rs = executeQuery(date, timestamp, discount, quantity);
  return readResultSet(rs);
}