List of usage examples for java.sql Timestamp Timestamp
public Timestamp(long time)
From source file:edu.ku.brc.specify.datamodel.DataModelObjBase.java
/** * This can be called in order to initialize the fields common to all DataModelObjBase * implementations.//www .j a va 2s. com */ protected void init() { Timestamp now = new Timestamp(System.currentTimeMillis()); timestampCreated = now; timestampModified = now; createdByAgent = AppContextMgr.getInstance() == null ? null : (AppContextMgr.getInstance().hasContext() ? Agent.getUserAgent() : null); modifiedByAgent = null; }
From source file:libepg.epg.util.DateTimeFieldConverterTest.java
/** * Test of BytesToSqlDateTime method, of class DateTimeFieldConverter. * * @throws java.lang.Exception/*w w w. j a va 2 s . c o m*/ */ @Test public void testBytesTOSqlDateTime1() throws Exception { LOG.debug("BytesTOSqlDateTime1"); byte[] source = Hex.decodeHex("C079124500".toCharArray()); Timestamp expResult = new Timestamp( new java.text.SimpleDateFormat("yyyyMMddHHmmss").parse("19931013124500").getTime()); Timestamp result = DateTimeFieldConverter.BytesToSqlDateTime(source); assertEquals(expResult, result); }
From source file:edu.umd.cs.submitServer.servlets.ReportTestOutcomes.java
@Override public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // will be set by MultipartRequestFilter MultipartRequest multipartRequest = (MultipartRequest) request.getAttribute(MULTIPART_REQUEST); Timestamp now = new Timestamp(System.currentTimeMillis()); // Insert test outcomes into database, // create new TestRun // and update submission as having been tested. Connection conn = null;//from w w w. ja v a 2 s. c om boolean transactionSuccess = false; try { // Get submission pk and the submission @Submission.PK int submissionPK = Submission.asPK(multipartRequest.getIntParameter("submissionPK")); String courses = multipartRequest.getStringParameter("courses"); // Get the testSetupPK int testSetupPK = multipartRequest.getIntParameter("testSetupPK"); boolean newTestSetup = multipartRequest.getBooleanParameter("newTestSetup"); boolean isBackgroundRetest = multipartRequest.getBooleanParameter("isBackgroundRetest"); String load = multipartRequest.getOptionalStringParameter("load"); if (load == null) load = "unknown"; String kindString = multipartRequest.getOptionalStringParameter("kind"); Kind kind = Kind.UNKNOWN; if (kindString != null) { try { kind = Kind.valueOf(kindString); } catch (RuntimeException e) { // ignore } } String remoteHost = SubmitServerFilter.getRemoteHost(request); // Get test machine (if specified) String testMachine = multipartRequest.getOptionalStringParameter("hostname"); if (testMachine == null) testMachine = multipartRequest.getOptionalStringParameter("testMachine"); if (testMachine == null) testMachine = "unknown"; CodeMetrics codeMetrics = getCodeMetrics(multipartRequest); int testDurationsMillis = multipartRequest.getIntegerParameter("testDurationsMillis", 0); // Read into TestOutcomeCollection in memory TestOutcomeCollection testOutcomeCollection = TestOutcomeCollection .deserialize(getfileItemDataAndDelete(multipartRequest)); logHotspotErrors(submissionPK, testSetupPK, testMachine, testOutcomeCollection); conn = getConnection(); Submission submission = Submission.lookupBySubmissionPK(submissionPK, conn); if (submission == null) { throw new ServletException( "submissionPK " + submissionPK + " does not refer to a submission in the database"); } StudentRegistration studentRegistration = StudentRegistration .lookupByStudentRegistrationPK(submission.getStudentRegistrationPK(), conn); @Student.PK Integer studentPK = studentRegistration.getStudentPK(); Project project = Project.getByProjectPK(submission.getProjectPK(), conn); TestSetup testSetup = TestSetup.lookupByTestSetupPK(testSetupPK, conn); Integer canonicalTestRunPK = testSetup.getTestRunPK(); if (newTestSetup && (testSetup.getStatus() == TestSetup.Status.TESTED || testSetup.getStatus() == TestSetup.Status.ACTIVE)) { newTestSetup = false; } BuildServer.insertOrUpdateSuccess(conn, testMachine, remoteHost, now, load, submission); // Validate buildserver Collection<Integer> allowedCourses = RequestSubmission.getCourses(conn, courses); if (allowedCourses.isEmpty()) { ServerError.insert(conn, ServerError.Kind.BAD_AUTHENTICATION, studentPK, studentPK, project.getCoursePK(), project.getProjectPK(), submission.getSubmissionPK(), "", "Build server " + testMachine + " reporting outcome but does not provide any valid credentials", "", this.getClass().getSimpleName(), "", "", remoteHost, "", "", null); response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Not authorized"); return; } if (!allowedCourses.contains(project.getCoursePK())) { ServerError.insert(conn, ServerError.Kind.BAD_AUTHENTICATION, studentPK, studentPK, project.getCoursePK(), project.getProjectPK(), submission.getSubmissionPK(), "", "Build server " + testMachine + " reporting outcome for course it is not authorized to do so", "", this.getClass().getSimpleName(), "", "", remoteHost, "", "", null); response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Not authorized"); return; } TestRun canonicalTestRun = TestRun.lookupByTestRunPK(canonicalTestRunPK, conn); if (!newTestSetup) { if (canonicalTestRun == null || canonicalTestRun.getTestSetupPK() != testSetupPK) { ServerError.insert(conn, ServerError.Kind.UNKNOWN, studentPK, studentPK, project.getCoursePK(), project.getProjectPK(), submission.getSubmissionPK(), "", "Discarding stale build server result", "", this.getClass().getSimpleName(), "", "", remoteHost, "", "", null); response.sendError(HttpServletResponse.SC_NOT_ACCEPTABLE, "not current test setup"); return; } // Set point totals TestOutcomeCollection canonicalTestOutcomeCollection = TestOutcomeCollection .lookupByTestRunPK(canonicalTestRun.getTestRunPK(), conn); Map<String, TestOutcome> canonicalTestOutcomeMap = new HashMap<String, TestOutcome>(); for (TestOutcome testOutcome : canonicalTestOutcomeCollection.getAllOutcomes()) { if (testOutcome.isCardinalTestType()) canonicalTestOutcomeMap.put(testOutcome.getTestName(), testOutcome); } for (TestOutcome testOutcome : testOutcomeCollection.getAllOutcomes()) if (testOutcome.isCardinalTestType() && !testOutcome.getOutcome().equals(TestOutcome.COULD_NOT_RUN)) { TestOutcome canonicalTestOutcome = canonicalTestOutcomeMap.get(testOutcome.getTestName()); if (canonicalTestOutcome == null || !canonicalTestOutcome.getTestType().equals(testOutcome.getTestType())) { String message = "Did not find matching canonical test outcome for " + testOutcome.getTestName() + " with outcome " + testOutcome.getOutcome(); ServerError.insert(conn, ServerError.Kind.UNKNOWN, studentPK, studentPK, project.getCoursePK(), project.getProjectPK(), submission.getSubmissionPK(), "", message, "", this.getClass().getSimpleName(), "", "", remoteHost, "", "", null); response.sendError(HttpServletResponse.SC_NOT_ACCEPTABLE, message); return; } testOutcome.setPointValue(canonicalTestOutcome.getPointValue()); } } else { // new test setup // set all point values to 1 for (TestOutcome testOutcome : testOutcomeCollection) { testOutcome.setPointValue(1); } } getSubmitServerServletLog().info("Reporting test outcome for submissionPK = " + submissionPK + ", testSetupPK = " + testSetupPK + " performed by " + testMachine + ", kind = " + kind); // Background Retests: // If this was a background re-test, then we need to take special // steps. // This was a background-retest if: // 1) The BuildServer says that this was a background retest // 2) or the status has been left as "complete" or has been // explicitly marked "background" if (isBackgroundRetest || !newTestSetup && submission.getBuildStatus().equals(Submission.BuildStatus.COMPLETE)) { // Look up current testOutcomeCollection TestOutcomeCollection currentTestOutcomeCollection = TestOutcomeCollection .lookupByTestRunPK(submission.getCurrentTestRunPK(), conn); // Look up the testRun for the current TestOutcomeCollection TestRun currentTestRun = TestRun.lookupByTestRunPK(submission.getCurrentTestRunPK(), conn); if (currentTestRun == null) getSubmitServerServletLog().warn("Unable to find test run " + submission.getCurrentTestRunPK()); if (currentTestRun == null || currentTestRun.getTestSetupPK() != testSetupPK) { // Retest was against a different jarfile than the current // one; // for now just ignore this run. return; } // Compare the cardinal test outcomes from the two // outcomeCollections String differences = compareCardinalOutcomes(currentTestOutcomeCollection, testOutcomeCollection, submissionPK, testSetupPK, testMachine); if (differences == null) { // If the results are the same, great! We have more // confidence that this result is correct. submission.incrementNumSuccessfulBackgroundRetests(); getSuccessfulBackgroundRetestLog().info("Corroborating run for submissionPK = " + submissionPK + ", testSetupPK = " + testSetupPK + " performed by " + testMachine); } else if (differences.equals("skip")) { // There may have been differences but we don't care // We don't re-test "could_not_run" results return; } else { // If the results differ, log which test cases were // different submission.incrementNumFailedBackgroundRetests(); // TODO: RSS feed getFailedBackgroundRetestLog().warn(differences); // XXX Should I insert differing outcomes into the database // as re-tests? if (currentTestOutcomeCollection.getValuePassedOverall() < testOutcomeCollection .getValuePassedOverall()) isBackgroundRetest = false; } submission.update(conn); // If there were no differences, commit what we've done and // exit. if (differences == null) return; } // isBackgroundRetest conn = switchToTransaction(conn); // * Create new TestRun row // * increment numTestOutcomes in submissions table // * set currentTestRunPK in submissions table // * set testRunPK in all the testOutcomes // * write the testoutcomes to the disk // Create new TestRun row. TestRun testRun = createTestRun(submissionPK, testSetupPK, testMachine, testOutcomeCollection, codeMetrics, now, testDurationsMillis); // perform insert testRun.insert(conn); BuildServer.updateLastTestRun(conn, testMachine, testRun); // Insert a new codeMetrics row if we have codeMetrics data to // insert // codeMetrics data is keyed to the testRunPK if (codeMetrics.getCodeSegmentSize() > 0) { codeMetrics.setTestRunPK(testRun.getTestRunPK()); codeMetrics.insert(conn); } // update the testRunPK of the testOutcomes we've been sent from the // BuildServer // with the testRunPK of the row we just inserted testOutcomeCollection.updateTestRunPK(testRun.getTestRunPK()); // increment the number of test outcomes submission.setNumTestRuns(submission.getNumTestRuns() + 1); // Next, insert the test outcomes testOutcomeCollection.insert(conn); // if this was a new project jarfile being tested against the // canonical account if (newTestSetup) { getSubmitServerServletLog().info("Ran new test setup, submissionPK = " + submissionPK + ", testSetupPK = " + testSetupPK + " performed by " + testMachine + ", kind = " + kind); // lookup the pending project testSetup.setValueTotalTests(testOutcomeCollection.getValuePassedOverall()); testSetup.setValuePublicTests(testOutcomeCollection.getValuePublicTests()); testSetup.setValueReleaseTests(testOutcomeCollection.getValueReleaseTests()); testSetup.setValueSecretTests(testOutcomeCollection.getValueSecretTests()); testSetup.setTestRunPK(testRun.getTestRunPK()); if (!testOutcomeCollection.isCompileSuccessful() || testOutcomeCollection.getNumFailedOverall() > 0 || testOutcomeCollection.getCouldNotRunAnyCardinalTests()) { // If any tests have failed, then set status to failed testSetup.setStatus(TestSetup.Status.FAILED); } else { testSetup.setStatus(TestSetup.Status.TESTED); } getSubmitServerServletLog().info("Ran new test setup, submissionPK = " + submissionPK + ", testSetupPK = " + testSetupPK + " performed by " + testMachine + ", kind = " + kind + ", status = " + testSetup.getStatus()); // update pending testSetup to reflect the changes just // made testSetup.update(conn); } // Only change information about the current test_run if this // run used the most recent testSetup if (!isBackgroundRetest && (newTestSetup || testRun.getTestSetupPK() == project.getTestSetupPK())) { // update the pass/fail/warning stats submission.setCurrentTestRunPK(testRun.getTestRunPK()); // Ensure that submission is not release eligible if the // student_submit_status.can_release_test is false StudentSubmitStatus submitStatus = StudentSubmitStatus.lookupByStudentRegistrationPKAndProjectPK( submission.getStudentRegistrationPK(), submission.getProjectPK(), conn); boolean canReleaseTest = (submitStatus == null) || submitStatus.getCanReleaseTest(); submission.setReleaseEligible(testOutcomeCollection.isReleaseEligible() && canReleaseTest); // if project's release policy is anytime, then make it release // eligible if (Project.ANYTIME.equals(project.getReleasePolicy())) submission.setReleaseEligible(canReleaseTest); submission.setValuePassedOverall(testOutcomeCollection.getValuePassedOverall()); submission.setCompileSuccessful(testOutcomeCollection.isCompileSuccessful()); submission.setValuePublicTestsPassed(testOutcomeCollection.getValuePublicTestsPassed()); submission.setValueReleaseTestsPassed(testOutcomeCollection.getValueReleaseTestsPassed()); submission.setValueSecretTestsPassed(testOutcomeCollection.getValueSecretTestsPassed()); submission.setNumFindBugsWarnings(testOutcomeCollection.getNumFindBugsWarnings()); // If we're re-setting the currentTestRunPK, then find any // existing // backgroundRetests and clear them. Background re-tests are // always compared // to the current set of testOutcomes. submission.setNumFailedBackgroundRetests(0); submission.setNumSuccessfulBackgroundRetests(0); submission.setNumPendingBuildRequests(0); } // perform update // Update the status of the submission submission.setBuildStatus(Submission.BuildStatus.COMPLETE); submission.update(conn); getSubmitServerServletLog().info("Completed testing submissionPK = " + submissionPK + ", testSetupPK = " + testSetupPK + " performed by " + testMachine + ", kind = " + kind + ", status = " + testSetup.getStatus()); conn.commit(); transactionSuccess = true; } catch (InvalidRequiredParameterException e) { throw new ServletException(e); } catch (SQLException e) { throw new ServletException(e); } finally { rollbackIfUnsuccessfulAndAlwaysReleaseConnection(transactionSuccess, request, conn); } }
From source file:com.luna.common.repository.UserRepository2ImplForDefaultSearchIT.java
@Test public void testLteAndGteForDate() throws ParseException { int count = 15; String dateStr = "2012-01-15 16:59:00"; String dateStrFrom = "2012-01-15 16:59:00"; String dateStrEnd = "2012-01-15 16:59:00"; DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); for (int i = 0; i < count; i++) { User user = createUser();//from ww w .j a va2 s.c o m user.getBaseInfo().setBirthday(new Timestamp(df.parse(dateStr).getTime())); userRepository2.save(user); } Map<String, Object> searchParams = new HashMap<String, Object>(); searchParams.put("baseInfo.birthday_gte", dateStrFrom); searchParams.put("baseInfo.birthday_lte", dateStrEnd); Searchable search = Searchable.newSearchable(searchParams); assertEquals(count, userRepository2.countAllByDefault(search)); }
From source file:org.spring.data.gemfire.app.dao.provider.JdbcUserDao.java
protected Timestamp convert(final Calendar dateTime) { return (dateTime != null ? new Timestamp(dateTime.getTimeInMillis()) : null); }
From source file:jp.zippyzip.City.java
/** * ??//from w w w. ja va2 s. c o m * * @param expiration ? */ public void setExpiration(Date expiration) { this.expiration = new Timestamp(expiration.getTime()); }
From source file:org.koiroha.jyro.workers.crawler.Crawler.java
/** * * @param job//w w w.ja v a 2 s . co m * @return * @throws WorkerException */ @Distribute(name = "crawl", params = { "url", "referer" }) public void crawl(String url, String referer) throws SQLException, JyroException { List<URI> urls = retrieveLink(url); WorkerContext context = getContext(); Connection con = Transaction.getConnection(); con.setAutoCommit(false); PreparedStatement stmt1 = con.prepareStatement( "INSERT INTO jyro_urls(scheme,host,port,path,retrieved_at,created_at) VALUES(?,?,?,?,?,?)"); PreparedStatement stmt = con.prepareStatement( "SELECT EXISTS(SELECT * FROM jyro_urls WHERE scheme=? AND host=? AND port=? AND path=?)"); for (URI uri : urls) { int port = getPort(uri); if (port < 0) { logger.debug(uri + " is not supported"); continue; } stmt.setString(1, uri.getScheme()); stmt.setString(2, uri.getHost()); stmt.setInt(3, port); stmt.setString(4, uri.getPath()); ResultSet rs = stmt.executeQuery(); rs.next(); boolean exists = rs.getBoolean(1); if (!exists) { Timestamp now = new Timestamp(System.currentTimeMillis()); stmt1.setString(1, uri.getScheme()); stmt1.setString(2, uri.getHost()); stmt1.setInt(3, port); stmt1.setString(4, uri.getPath()); stmt1.setTimestamp(5, now); stmt1.setTimestamp(6, now); stmt1.executeUpdate(); con.commit(); context.call("crawl", uri.toString()); } else { logger.info("URL " + uri + " already retrieved"); } } stmt.close(); stmt1.close(); con.commit(); return; }
From source file:org.cloudfoundry.identity.uaa.codestore.ExpiringCodeStoreTests.java
@Test public void testGenerateCode() throws Exception { String data = "{}"; Timestamp expiresAt = new Timestamp(System.currentTimeMillis() + 60000); ExpiringCode expiringCode = expiringCodeStore.generateCode(data, expiresAt); assertNotNull(expiringCode);/*from w w w. jav a 2s .co m*/ assertNotNull(expiringCode.getCode()); assertTrue(expiringCode.getCode().trim().length() > 0); assertEquals(expiresAt, expiringCode.getExpiresAt()); assertEquals(data, expiringCode.getData()); }
From source file:com.rogchen.common.xml.UtilDateTime.java
public static Timestamp addDaysToTimestamp(Timestamp start, int days) { return new Timestamp(start.getTime() + (24L * 60L * 60L * 1000L * days)); }