/** * Tests fix for BUG#54095 - Unnecessary call in newSetTimestampInternal. * * This bug was fixed as a consequence of the patch for Bug#71084. * * @throws Exception * if the test fails. */ public void testBug54095() throws Exception { Connection testConn = getConnectionWithProps("useLegacyDatetimeCode=false"); Calendar testCal = Calendar.getInstance(); java.util.Date origDate = testCal.getTime(); PreparedStatement testPstmt = testConn.prepareStatement("SELECT ?"); testPstmt.setTimestamp(1, new Timestamp(0), testCal); assertEquals("Calendar object shouldn't have changed after PreparedStatement.setTimestamp().", origDate, testCal.getTime()); ResultSet testRs = testPstmt.executeQuery(); testRs.next(); assertEquals("Calendar object shouldn't have changed after PreparedStatement.executeQuery().", origDate, testCal.getTime()); testRs.getTimestamp(1, testCal); assertEquals("Calendar object shouldn't have changed after ResultSet.getTimestamp().", origDate, testCal.getTime()); testRs.close(); testPstmt.close(); testConn.close(); }
private void PreparedStmtSetValue(CallableStatement cStmt, int idx, Object obj) throws SQLException{ if (obj instanceof String) { pStmt.setString(idx, (String) obj); } else if(obj instanceof Integer){ pStmt.setInt(idx, (Integer) obj); } else if(obj instanceof BigDecimal){ pStmt.setBigDecimal(idx, (BigDecimal) obj); } else if(obj instanceof Double){ pStmt.setDouble(idx, (Double) obj); } else if(obj instanceof Date){ pStmt.setDate(idx, (Date) obj); } else if(obj instanceof byte[]){ pStmt.setBytes(idx, (byte[]) obj); } else{ pStmt.setObject(idx, obj); } }
public void testDateTypesToBigInt() throws Exception { final int TOTAL_RECORDS = 1 * 10; long offset = TimeZone.getDefault().getRawOffset(); String table = getTableName().toUpperCase(); ColumnGenerator[] cols = new ColumnGenerator[] { HCatalogTestUtils.colGenerator(HCatalogTestUtils.forIdx(0), "date", Types.DATE, HCatFieldSchema.Type.BIGINT, 0, 0, 0 - offset, new Date(70, 0, 1), KeyType.NOT_A_KEY), HCatalogTestUtils.colGenerator(HCatalogTestUtils.forIdx(1), "time", Types.TIME, HCatFieldSchema.Type.BIGINT, 0, 0, 36672000L - offset, new Time(10, 11, 12), KeyType.NOT_A_KEY), HCatalogTestUtils.colGenerator(HCatalogTestUtils.forIdx(2), "timestamp", Types.TIMESTAMP, HCatFieldSchema.Type.BIGINT, 0, 0, 36672000L - offset, new Timestamp(70, 0, 1, 10, 11, 12, 0), KeyType.NOT_A_KEY), }; List<String> addlArgsArray = new ArrayList<String>(); addlArgsArray.add("--map-column-hive"); addlArgsArray.add("COL0=bigint,COL1=bigint,COL2=bigint"); runHCatExport(addlArgsArray, TOTAL_RECORDS, table, cols); }
@Test public void testLogin() { Pet Pet = new Pet(11, 9527, "肥仔", 1, 60, 40, new Date(2017-1-1), "宝贝"); Scanner sc = new Scanner(System.in); System.out.println("请输入登陆名:"); String username = sc.next(); System.out.println("请输入密码:"); String password = sc.next(); Master master = new Master(username, password); Connection conn = DBHelper.getInstance().getConnection(); MasterDao dao = new MasterServiceImpl(conn); MasterService service = new MasterServiceImpl(dao); service.login(master); DBHelper.closeConnection(conn); }
@Test public void testGetTaskCountByWorkbasketAndDaysInPastAndState() { final long daysInPast = 10L; List<TaskState> taskStates = Arrays.asList(TaskState.CLAIMED, TaskState.COMPLETED); List<DueWorkbasketCounter> expectedResult = new ArrayList<>(); doReturn(expectedResult).when(taskMonitorMapperMock).getTaskCountByWorkbasketIdAndDaysInPastAndState( any(Date.class), any()); List<DueWorkbasketCounter> actualResult = cut.getTaskCountByWorkbasketAndDaysInPastAndState(daysInPast, taskStates); verify(taskanaEngineImpl, times(1)).openConnection(); verify(taskMonitorMapperMock, times(1)).getTaskCountByWorkbasketIdAndDaysInPastAndState(any(Date.class), any()); verify(taskanaEngineImpl, times(1)).returnConnection(); verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl, taskMonitorMapperMock, objectReferenceMapperMock, workbasketServiceMock); assertThat(actualResult, equalTo(expectedResult)); }
private String generateTestDataFileForPartitionInput() throws Exception { final File file = getTempFile(); PrintWriter printWriter = new PrintWriter(file); String partValues[] = {"1", "2", "null"}; for(int c = 0; c < partValues.length; c++) { for(int d = 0; d < partValues.length; d++) { for(int e = 0; e < partValues.length; e++) { for (int i = 1; i <= 5; i++) { Date date = new Date(System.currentTimeMillis()); Timestamp ts = new Timestamp(System.currentTimeMillis()); printWriter.printf("%s,%s,%s,%s,%s", date.toString(), ts.toString(), partValues[c], partValues[d], partValues[e]); printWriter.println(); } } } } printWriter.close(); return file.getPath(); }
private static Object date2Obj(Object value, String type, String format) { String fromType = "Date"; java.util.Date dte = (java.util.Date) value; if ("String".equalsIgnoreCase(type) || DataType.STRING.equalsIgnoreCase(type)) { if (format == null || format.length() == 0) { return dte.toString(); } else { SimpleDateFormat sdf = new SimpleDateFormat(format); return sdf.format(dte); } } else if ("Date".equalsIgnoreCase(type) || DataType.DATE.equalsIgnoreCase(type)) { return value; } else if ("java.sql.Date".equalsIgnoreCase(type)) { return new Date(dte.getTime()); } else if ("Time".equalsIgnoreCase(type) || DataType.TIME.equalsIgnoreCase(type)) { return new Time(dte.getTime()); } else if ("Timestamp".equalsIgnoreCase(type) || DataType.TIMESTAMP.equalsIgnoreCase(type)) { return new Timestamp(dte.getTime()); } else { throw new DataParseException(String.format(support, fromType, type)); } }
public void setParam(PreparedStatement ps, int parameterIndex, Object object) throws SQLException { if (object instanceof Timestamp) { ps.setTimestamp(parameterIndex, (Timestamp) object); } else if (object instanceof Date) { ps.setDate(parameterIndex, (Date) object); } else if (object instanceof String) { ps.setString(parameterIndex, (String) object); } else if (object instanceof Integer) { ps.setInt(parameterIndex, ((Integer) object).intValue()); } else if (object instanceof Long) { ps.setLong(parameterIndex, ((Long) object).longValue()); } else if (object instanceof Boolean) { ps.setBoolean(parameterIndex, ((Boolean) object).booleanValue()); } else { ps.setObject(parameterIndex, object); } }
public void setDate(String parameterName, Date x) throws SQLException { try { if (this.wrappedStmt != null) { ((CallableStatement) this.wrappedStmt).setDate(parameterName, x); } else { throw SQLError.createSQLException("No operations allowed after statement closed", SQLError.SQL_STATE_GENERAL_ERROR, this.exceptionInterceptor); } } catch (SQLException sqlEx) { checkAndFireConnectionError(sqlEx); } }
public static Timestamp getNormalisedTimestamp(Date d) { synchronized (tempCalDefault) { setTimeInMillis(tempCalDefault, d.getTime()); resetToDate(tempCalDefault); long value = getTimeInMillis(tempCalDefault); return new Timestamp(value); } }
@Override public void appendLog(StringBuilder builder, Date parameter, DatabaseDialect dialect) { // if (DatabaseDialect.MYSQL == dialect) { // builder.append('\''); // builder.append((null != parameter) ? new SimpleDateFormat("yyyy-MM-dd").format(parameter) : null); // builder.append('\''); // } builder.append('\''); builder.append((null != parameter) ? new SimpleDateFormat("yyyy-MM-dd").format(parameter) : null); builder.append('\''); }
public void setDate(String parameterName, Date x, Calendar cal) throws SQLException { try { if (this.wrappedStmt != null) { ((CallableStatement) this.wrappedStmt).setDate(parameterName, x, cal); } else { throw SQLError.createSQLException("No operations allowed after statement closed", SQLError.SQL_STATE_GENERAL_ERROR, this.exceptionInterceptor); } } catch (SQLException sqlEx) { checkAndFireConnectionError(sqlEx); } }
/** * Test for Date values. * * @param constant the constant value to be tested * @param op the operation to be used for testing/condition against constant value * @param arg1 the value to be compared against the constant value * @param check boolean indicating the result of predicate test for above */ @Test(dataProvider = "getDateData") public void testGetPredicateForDate(final Object constant, final TypePredicateOp op, final Date arg1, boolean check) { System.out.printf("PredicateHelperTest.testGetPredicateForDate :: %s -- %s -- %s -- %s\n", constant, op, arg1, check); assertUsingSerDeForType(BasicTypes.DATE, constant, op, arg1, check); }
public static Date getNormalisedDate(Date d) { synchronized (tempCalDefault) { setTimeInMillis(tempCalDefault, d.getTime()); resetToDate(tempCalDefault); long value = getTimeInMillis(tempCalDefault); return new Date(value); } }
public static String getDateString(java.util.Date x, Calendar cal) { synchronized (sdfd) { sdfd.setCalendar(cal == null ? tempCalDefault : cal); return sdfd.format(x); } }
public JYComment(int seq, String id, String content, int boardseq, Date wdate, int likecount, int hatecount, String ip, int seqReply, int ref, int delflag) { super(); this.seq = seq; this.id = id; this.content = content; this.boardseq = boardseq; this.wdate = wdate; this.likecount = likecount; this.hatecount = hatecount; this.ip = ip; this.seqReply = seqReply; this.ref = ref; this.delflag = delflag; }
/** * Tests that binary dates/times are encoded/decoded correctly. * * @throws Exception * if the test fails. * * @deprecated because we need to use this particular constructor for the * date class, as Calendar-constructed dates don't pass the * .equals() test :( */ @Deprecated public void testServerPrepStmtAndDate() throws Exception { createTable("testServerPrepStmtAndDate", "(`P_ID` int(10) NOT NULL default '0', `R_Date` date default NULL, UNIQUE KEY `P_ID` (`P_ID`), KEY `R_Date` (`R_Date`))"); Date dt = new java.sql.Date(102, 1, 2); // Note, this represents the date 2002-02-02 PreparedStatement pStmt2 = this.conn.prepareStatement("INSERT INTO testServerPrepStmtAndDate (P_ID, R_Date) VALUES (171576, ?)"); pStmt2.setDate(1, dt); pStmt2.executeUpdate(); pStmt2.close(); this.rs = this.stmt.executeQuery("SELECT R_Date FROM testServerPrepStmtAndDate"); this.rs.next(); System.out.println("Date that was stored (as String) " + this.rs.getString(1)); // comes back as 2002-02-02 PreparedStatement pStmt = this.conn.prepareStatement("Select P_ID,R_Date from testServerPrepStmtAndDate Where R_Date = ? and P_ID = 171576"); pStmt.setDate(1, dt); this.rs = pStmt.executeQuery(); assertTrue(this.rs.next()); assertEquals("171576", this.rs.getString(1)); assertEquals(dt, this.rs.getDate(2)); }
/** * Internal value converter. Similar to its counterpart in JDBCResultSet <p> * * All trivially successful getXXX methods eventually go through this * method, converting if necessary from the source type to the * requested type. <p> * * Conversion to the JDBC representation, if different, is handled by the * calling methods. * * @param columnIndex of the column value for which to perform the * conversion * @param targetType the org.hsqldb.types.Type object for targetType * @return an Object of the requested targetType, representing the value of the * specified column * @throws SQLException when there is no rowData, the column index is * invalid, or the conversion cannot be performed */ private Object getColumnInType(int columnIndex, Type targetType) throws SQLException { checkGetParameterIndex(columnIndex); Type sourceType; Object value; sourceType = parameterTypes[--columnIndex]; value = parameterValues[columnIndex]; if (trackNull(value)) { return null; } if (sourceType.typeCode != targetType.typeCode) { try { value = targetType.convertToTypeJDBC(session, value, sourceType); } catch (HsqlException e) { String stringValue = (value instanceof Number || value instanceof String || value instanceof java.util.Date) ? value.toString() : "instance of " + value.getClass().getName(); String msg = "from SQL type " + sourceType.getNameString() + " to " + targetType.getJDBCClassName() + ", value: " + stringValue; HsqlException err = Error.error(ErrorCode.X_42561, msg); throw JDBCUtil.sqlException(err, e); } } return value; }
/** * * @return */ private Manifest createManifest() { Manifest manifest = new Manifest(); Attributes main = manifest.getMainAttributes(); main.putValue("Manifest-Version", "1.0"); main.putValue("Created-By", "1.0 (JarPatch)"); main.putValue("Created-Time", new Date(System.currentTimeMillis()).toGMTString()); return manifest; }
final static Time fastTimeCreate(Calendar cal, int hour, int minute, int second, ExceptionInterceptor exceptionInterceptor) throws SQLException { if (hour < 0 || hour > 24) { throw SQLError.createSQLException( "Illegal hour value '" + hour + "' for java.sql.Time type in value '" + timeFormattedString(hour, minute, second) + ".", SQLError.SQL_STATE_ILLEGAL_ARGUMENT, exceptionInterceptor); } if (minute < 0 || minute > 59) { throw SQLError.createSQLException( "Illegal minute value '" + minute + "' for java.sql.Time type in value '" + timeFormattedString(hour, minute, second) + ".", SQLError.SQL_STATE_ILLEGAL_ARGUMENT, exceptionInterceptor); } if (second < 0 || second > 59) { throw SQLError.createSQLException( "Illegal minute value '" + second + "' for java.sql.Time type in value '" + timeFormattedString(hour, minute, second) + ".", SQLError.SQL_STATE_ILLEGAL_ARGUMENT, exceptionInterceptor); } synchronized (cal) { java.util.Date origCalDate = cal.getTime(); try { cal.clear(); // Set 'date' to epoch of Jan 1, 1970 cal.set(1970, 0, 1, hour, minute, second); long timeAsMillis = cal.getTimeInMillis(); return new Time(timeAsMillis); } finally { cal.setTime(origCalDate); } } }
/** * */ public void test_requestBugsFromBugzillaCanHandleEmptyProductVersion() throws Exception { final Date fromDate = stringToDate("2003-02-21 21:03:14"); final Date toDate = stringToDate("2003-05-15 23:07:06"); // empty string as a version Collection result = bugzillaDatabaseConnector. requestBugsFromBugzilla(TEST_PRODUCT_NAME, "", fromDate, toDate); assertEquals(7, result.size()); assertEquals("Number of errors", 0, em.errorCount()); // null string as a version result = bugzillaDatabaseConnector. requestBugsFromBugzilla(TEST_PRODUCT_NAME, null, fromDate, toDate); assertEquals(7, result.size()); assertEquals("Number of errors", 0, em.errorCount()); }
/** * @deprecated because we use deprecated methods */ @Deprecated public void testBug34913() throws Exception { Timestamp ts = new Timestamp(new Date(109, 5, 1).getTime()); this.pstmt = ((com.mysql.jdbc.Connection) this.conn).serverPrepareStatement("SELECT 'abcdefghij', ?"); this.pstmt.setTimestamp(1, ts); this.rs = this.pstmt.executeQuery(); this.rs.next(); assertTrue(this.rs.getTimestamp(2).getMonth() == 5); assertTrue(this.rs.getTimestamp(2).getDate() == 1); }
/** * {@inheritDoc} */ @Override public v3_AuthorRecord values(Integer value1, String value2, String value3, Date value4, Integer value5, String value6, Integer value7) { value1(value1); value2(value2); value3(value3); value4(value4); value5(value5); value6(value6); value7(value7); return this; }
@RequestMapping(path = "/day", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) public RestResponse getMovieOnShowByDay( @RequestParam("movieId") Integer movieId, @RequestParam("cinemaId") Integer cinemaId, @RequestParam("showDate") Date showDate, HttpServletRequest request, HttpServletResponse response) { LogUtil.logReq(Log, request); List<Integer> idsList = movieOnShowService.getMovieOnShowByDate(movieId, showDate, cinemaId); return new CollectionResponse(idsList); }
public Date getFechaInsercion() { return fechaInsercion; }
public Date getFechaActualizacion() { return fechaActualizacion; }
public void resolveTable(Map<String, Object> message) { if (message == null || message.isEmpty() || message.get(key) == null) return; DefaultFormattingConversionService cs = new DefaultFormattingConversionService(true); message.put(key, cs.convert(message.get(key), Long.class)); logger.info("start to resolve message"); String[] baseTableColumn = tDataBase.split(","); String[] extraTableColumn = tDataExtra.split(","); String[] customTableColumn = tDataCustom.split(","); Map<String, Object> baseTable = new HashMap<>(); Map<String, Object> extraTable = new HashMap<>(); Map<String, Object> customTable = new HashMap<>(); long uuid = CustomUUID.get().nextId(); baseTable.put(index, uuid); extraTable.put(index, uuid); baseTable.put(attr, new Date((long) message.get(key))); extraTable.put(attr, new Date((long) message.get(key))); Arrays.asList(baseTableColumn).stream().forEach(e -> { baseTable.put(e, message.get(e)); }); Arrays.asList(extraTableColumn).stream().forEach(e -> { extraTable.put(e, message.get(e)); }); Arrays.asList(customTableColumn).stream().forEach(e -> { if (message.get(e) == null || "".equals(((String) message.get(e)).trim())) { return; } customTable.put(e, message.get(e)); }); logger.info("start to insert DB"); baseDataReportMapper.insertReportData(baseTable); extraDataReportMapper.insertReportData(extraTable); if (customTable.size() > 0) { customTable.put(index, uuid); customTable.put(attr, new Date((long) message.get(key))); Arrays.asList(customTableColumn).stream().forEach(e -> { if (customTable.get(e) == null || "".equals(((String) customTable.get(e)).trim())) customTable.put(e, Constants.TABLE_COLUMN_TYPE.get(e)); }); customDataReportMapper.insertReportData(customTable); } logger.info("message insert DB successed"); }
public void setFechaActualizacion(Date fechaActualizacion) { this.fechaActualizacion = fechaActualizacion; }
public String formatDate(Date dateObject) { SimpleDateFormat dateFormat = new SimpleDateFormat("LLL dd, yyyy"); String carl = dateFormat.format(dateObject); return carl; }
@Test public void test11() { Date d = Date.valueOf("1961-08-30"); Date d2 = new Date(System.currentTimeMillis()); assertTrue(d.compareTo(d2) == -1, "Error d.compareTo(d2) != -1"); }
@Override public Date getDate(int parameterIndex, Calendar cal) throws SQLException { // TODO Auto-generated method stub return null; }
@Test(expectedExceptions = NullPointerException.class) public void test15() throws Exception { LocalDate ld = null; Date.valueOf(ld); }
public void setDate(int parameterIndex, Date x) throws SQLException { ps.setDate(parameterIndex, x); }
public Date getHiredate() { return this.hiredate; }
public void setDate(int parameterIndex, Date x, Calendar cal) throws SQLException { throw new SQLException("Not Implemented: setDate(int parameterIndex, Date x, Calendar cal)"); }