List of usage examples for java.sql Timestamp getTime
public long getTime()
From source file:au.edu.jcu.fascinator.plugin.harvester.directory.DerbyCache.java
private long getLastModified(String oid) { try {/*from w w w . j a v a 2 s. c o m*/ PreparedStatement sql = connection() .prepareStatement("SELECT lastModified FROM " + BASIC_TABLE + " WHERE oid = ? AND cacheId = ?"); // Prepare and execute sql.setString(1, oid); sql.setString(2, cacheId); ResultSet result = sql.executeQuery(); // Build response Timestamp ts = null; if (result.next()) { ts = result.getTimestamp("lastModified"); } close(result); close(sql); if (ts == null) { return -1; } else { return ts.getTime(); } } catch (SQLException ex) { log.error("Error querying last modified date: ", ex); return -1; } }
From source file:com.ichi2.anki.PreferenceContext.java
/** * Code which is run when a SharedPreference change has been detected * @param prefs instance of SharedPreferences * @param key key in prefs which is being updated * @param listener PreferenceActivity of PreferenceFragment which is hosting the preference *///from w ww . java 2 s. c o m private void updatePreference(SharedPreferences prefs, String key, PreferenceContext listener) { try { PreferenceScreen screen = listener.getPreferenceScreen(); Preference pref = screen.findPreference(key); // Handle special cases switch (key) { case "timeoutAnswer": { CheckBoxPreference keepScreenOn = (CheckBoxPreference) screen.findPreference("keepScreenOn"); keepScreenOn.setChecked(((CheckBoxPreference) pref).isChecked()); break; } case LANGUAGE: closePreferences(); break; case "convertFenText": if (((CheckBoxPreference) pref).isChecked()) { ChessFilter.install(Hooks.getInstance(getApplicationContext())); } else { ChessFilter.uninstall(Hooks.getInstance(getApplicationContext())); } break; case "fixHebrewText": if (((CheckBoxPreference) pref).isChecked()) { HebrewFixFilter.install(Hooks.getInstance(getApplicationContext())); showDialog(DIALOG_HEBREW_FONT); } else { HebrewFixFilter.uninstall(Hooks.getInstance(getApplicationContext())); } break; case "showProgress": getCol().getConf().put("dueCounts", ((CheckBoxPreference) pref).isChecked()); getCol().setMod(); break; case "showEstimates": getCol().getConf().put("estTimes", ((CheckBoxPreference) pref).isChecked()); getCol().setMod(); break; case "newSpread": getCol().getConf().put("newSpread", Integer.parseInt(((ListPreference) pref).getValue())); getCol().setMod(); break; case "timeLimit": getCol().getConf().put("timeLim", ((NumberRangePreference) pref).getValue() * 60); getCol().setMod(); break; case "learnCutoff": getCol().getConf().put("collapseTime", ((NumberRangePreference) pref).getValue() * 60); getCol().setMod(); break; case "useCurrent": getCol().getConf().put("addToCur", ((ListPreference) pref).getValue().equals("0")); getCol().setMod(); break; case "dayOffset": { int hours = ((SeekBarPreference) pref).getValue(); Timestamp crtTime = new Timestamp(getCol().getCrt() * 1000); Calendar date = GregorianCalendar.getInstance(); date.setTimeInMillis(crtTime.getTime()); date.set(Calendar.HOUR_OF_DAY, hours); getCol().setCrt(date.getTimeInMillis() / 1000); getCol().setMod(); break; } case "minimumCardsDueForNotification": { ListPreference listpref = (ListPreference) screen.findPreference("minimumCardsDueForNotification"); if (listpref != null) { updateNotificationPreference(listpref); } break; } case "reportErrorMode": { String value = prefs.getString("reportErrorMode", ""); AnkiDroidApp.getInstance().setAcraReportingMode(value); break; } case "syncAccount": { SharedPreferences preferences = AnkiDroidApp.getSharedPrefs(getBaseContext()); String username = preferences.getString("username", ""); Preference syncAccount = screen.findPreference("syncAccount"); if (syncAccount != null) { if (TextUtils.isEmpty(username)) { syncAccount.setSummary(R.string.sync_account_summ_logged_out); } else { syncAccount.setSummary(getString(R.string.sync_account_summ_logged_in, username)); } } break; } case "providerEnabled": { ComponentName providerName = new ComponentName(this, "com.ichi2.anki.provider.CardContentProvider"); PackageManager pm = getPackageManager(); int state; if (((CheckBoxPreference) pref).isChecked()) { state = PackageManager.COMPONENT_ENABLED_STATE_ENABLED; Timber.i("AnkiDroid ContentProvider enabled by user"); } else { state = PackageManager.COMPONENT_ENABLED_STATE_DISABLED; Timber.i("AnkiDroid ContentProvider disabled by user"); } pm.setComponentEnabledSetting(providerName, state, PackageManager.DONT_KILL_APP); break; } } // Update the summary text to reflect new value updateSummary(pref); } catch (BadTokenException e) { Timber.e(e, "Preferences: BadTokenException on showDialog"); } catch (NumberFormatException | JSONException e) { throw new RuntimeException(); } }
From source file:com.cnd.greencube.server.dao.jdbc.JdbcDAO.java
@SuppressWarnings("rawtypes") private Object getColumnValue(ResultSet rs, ResultSetMetaData meta, int index, Class clazz) throws Exception { Object value = null;/*from w ww.ja v a 2s .c o m*/ int type = meta.getColumnType(index); if (clazz == String.class) { value = rs.getString(index); } else if (clazz == Integer.class) { value = rs.getInt(index); } else if (clazz == Boolean.class) { value = rs.getBoolean(index); } else if (clazz == byte[].class) { if (type == Types.BLOB) value = rs.getBlob(index); else value = rs.getBytes(index); } else if (clazz == Long.class) { value = rs.getLong(index); } else if (clazz == BigInteger.class) { value = rs.getBigDecimal(index); } else if (clazz == Float.class) { value = rs.getFloat(index); } else if (clazz == Double.class) { value = rs.getDouble(index); } else if (clazz == java.util.Date.class) { Timestamp time = rs.getTimestamp(index); if (time == null) value = null; else { value = new java.util.Date(time.getTime()); } } else if (clazz == java.sql.Date.class) { value = rs.getDate(index); } else if (clazz == java.sql.Time.class) { value = rs.getTime(index); } else if (clazz == java.sql.Timestamp.class) { value = rs.getTimestamp(index); } else { throw new Exception("Cannote determin this column type:" + meta.getColumnName(index)); } return value; }
From source file:fr.paris.lutece.portal.service.admin.AdminUserService.java
/** * Update the user expiration date with new values, and notify him with an email if his account was close to expire. * @param user The user to update/*from w w w.j a v a 2s . c o m*/ */ @SuppressWarnings("deprecation") public static void updateUserExpirationDate(AdminUser user) { if (user == null) { return; } Timestamp newExpirationDate = getAccountMaxValidDate(); Timestamp maxValidDate = user.getAccountMaxValidDate(); // We update the user account AdminUserHome.updateUserExpirationDate(user.getUserId(), newExpirationDate); // We notify the user String strUserMail = user.getEmail(); int nbDaysBeforeFirstAlert = AdminUserService .getIntegerSecurityParameter(PARAMETER_TIME_BEFORE_ALERT_ACCOUNT); if (maxValidDate != null) { Timestamp firstAlertMaxDate = new Timestamp( maxValidDate.getTime() - DateUtil.convertDaysInMiliseconds(nbDaysBeforeFirstAlert)); Timestamp currentTimestamp = new Timestamp(new java.util.Date().getTime()); if ((currentTimestamp.getTime() > firstAlertMaxDate.getTime()) && StringUtils.isNotBlank(strUserMail)) { AdminUser completeUser = AdminUserHome.findByPrimaryKey(user.getUserId()); String strBody = DatabaseTemplateService .getTemplateFromKey(PARAMETER_ACCOUNT_REACTIVATED_MAIL_BODY); DefaultUserParameter defaultUserParameter = DefaultUserParameterHome .findByKey(PARAMETER_ACCOUNT_REACTIVATED_MAIL_SENDER); String strSender = (defaultUserParameter == null) ? StringUtils.EMPTY : defaultUserParameter.getParameterValue(); defaultUserParameter = DefaultUserParameterHome .findByKey(PARAMETER_ACCOUNT_REACTIVATED_MAIL_SUBJECT); String strSubject = (defaultUserParameter == null) ? StringUtils.EMPTY : defaultUserParameter.getParameterValue(); Map<String, String> model = new HashMap<String, String>(); DateFormat dateFormat = SimpleDateFormat.getDateInstance(DateFormat.SHORT, Locale.getDefault()); String accountMaxValidDate = dateFormat.format(new Date(newExpirationDate.getTime())); model.put(MARK_DATE_VALID, accountMaxValidDate); model.put(MARK_NAME, completeUser.getLastName()); model.put(MARK_FIRST_NAME, completeUser.getFirstName()); HtmlTemplate template = AppTemplateService.getTemplateFromStringFtl(strBody, Locale.getDefault(), model); MailService.sendMailHtml(strUserMail, strSender, strSender, strSubject, template.getHtml()); } } }
From source file:ome.services.SearchBean.java
@Transactional @RolesAllowed("user") public void onlyCreatedBetween(Timestamp start, Timestamp stop) { synchronized (values) { values.createdStart = SearchValues.copyTimestamp(start); values.createdStop = SearchValues.copyTimestamp(stop); if (start != null && stop != null) { if (stop.getTime() < start.getTime()) { log.warn("FullText search created with " + "creation stop before start"); }/*from ww w . ja v a2s . com*/ } } }
From source file:jp.co.acroquest.endosnipe.report.converter.compressor.SamplingCompressor.java
/** * ??????/*from w w w.j a v a 2 s. c o m*/ * ??????????????? * * @param samplingList measureTimeField?????????????? * @param startTime ? * @param endTime ? * @param measureTimeField ???? * @param operation ?? * @param clazz ?Class * @return ??? * @throws IllegalAccessException ????????? * @throws InvocationTargetException ?????? * @throws NoSuchMethodException ?????? * @throws NoSuchFieldException * @throws InstantiationException * @throws SecurityException */ public List compressSamplingList(List samplingList, Timestamp startTime, Timestamp endTime, String measureTimeField, List<CompressOperation> operation, Class clazz) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, SecurityException, InstantiationException, NoSuchFieldException { // ?1???? // ??????????????????? long samplingTerm = (endTime.getTime() - startTime.getTime()) / this.samplingMax_; if (samplingTerm < this.minLimitSamplingTerm_) { samplingTerm = this.minLimitSamplingTerm_; } long nowStartTime = startTime.getTime(); int sampleIndex = 0; List compressedList = new ArrayList(); while (nowStartTime < endTime.getTime()) { // ????? List samplingGroup = new ArrayList(); for (int cnt = sampleIndex; cnt < samplingList.size(); cnt++) { Object sampleData = samplingList.get(cnt); Date measureTime = (Date) PropertyUtils.getProperty(sampleData, measureTimeField); if (nowStartTime > measureTime.getTime()) { sampleIndex++; continue; } if (nowStartTime + samplingTerm <= measureTime.getTime()) { sampleIndex = cnt; break; } samplingGroup.add(sampleData); } // ?? Object compressedData = createCompressedSample(samplingGroup, nowStartTime, nowStartTime + samplingTerm, measureTimeField, operation, clazz); compressedList.add(compressedData); nowStartTime += samplingTerm; } return compressedList; }
From source file:ome.services.SearchBean.java
@Transactional @RolesAllowed("user") public void onlyModifiedBetween(Timestamp start, Timestamp stop) { synchronized (values) { values.modifiedStart = SearchValues.copyTimestamp(start); values.modifiedStop = SearchValues.copyTimestamp(stop); if (start != null && stop != null) { if (stop.getTime() < start.getTime()) { log.warn("FullText search created " + "with modification stop before start"); }/*ww w .ja v a 2 s . co m*/ } } }
From source file:com.funambol.LDAP.engine.source.AbstractLDAPSyncSource.java
/** * Returns a timestamp aligned to UTC/*from w w w . ja va2 s . co m*/ */ private Timestamp normalizeTimestamp(Timestamp t) { return new Timestamp(t.getTime() - getServerTimeZone().getOffset(t.getTime())); }
From source file:edu.umd.cs.marmoset.modelClasses.Project.java
public static Project importProject(InputStream in, Course course, StudentRegistration canonicalStudentRegistration, Connection conn) throws SQLException, IOException, ClassNotFoundException { Project project = new Project(); ZipInputStream zipIn = new ZipInputStream(in); // Start transaction conn.setAutoCommit(false);/*from www . j a v a2s . c o m*/ conn.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE); byte[] canonicalBytes = null; byte[] testSetupBytes = null; byte[] projectStarterFileBytes = null; while (true) { ZipEntry entry = zipIn.getNextEntry(); if (entry == null) break; if (entry.getName().contains("project.out")) { // Found the serialized project! ObjectInputStream objectInputStream = new ObjectInputStream(zipIn); project = (Project) objectInputStream.readObject(); // Set the PKs to null, the values that get serialized are actually from // a different database with a different set of keys project.setProjectPK(0); project.setTestSetupPK(0); project.setArchivePK(null); project.setVisibleToStudents(false); // These two PKs need to be passed in when we import/create the project project.setCoursePK(course.getCoursePK()); project.setCanonicalStudentRegistrationPK(canonicalStudentRegistration.getStudentRegistrationPK()); // Insert the project so that we have a projectPK for other methods project.insert(conn); } else if (entry.getName().contains("canonical")) { // Found the canonical submission... ByteArrayOutputStream baos = new ByteArrayOutputStream(); CopyUtils.copy(zipIn, baos); canonicalBytes = baos.toByteArray(); } else if (entry.getName().contains("test-setup")) { // Found the test-setup! ByteArrayOutputStream baos = new ByteArrayOutputStream(); CopyUtils.copy(zipIn, baos); testSetupBytes = baos.toByteArray(); } else if (entry.getName().contains("project-starter-files")) { // Found project starter files ByteArrayOutputStream baos = new ByteArrayOutputStream(); CopyUtils.copy(zipIn, baos); projectStarterFileBytes = baos.toByteArray(); } } Timestamp submissionTimestamp = new Timestamp(System.currentTimeMillis()); // Now "upload" bytes as an archive for the project starter files, if it exists if (projectStarterFileBytes != null) { project.setArchiveForUpload(projectStarterFileBytes); project.uploadCachedArchive(conn); } // Now "submit" these bytes as a canonical submission // TODO read the submissionTimestamp from the serialized project in the archive Submission submission = Submission.submit(canonicalBytes, canonicalStudentRegistration, project, "t" + submissionTimestamp.getTime(), "ProjectImportTool, serialMinorVersion", Integer.toString(serialMinorVersion, 100), submissionTimestamp, conn); // Now "upload" the test-setup bytes as an archive String comment = "Project Import Tool uploaded at " + submissionTimestamp; TestSetup testSetup = TestSetup.submit(testSetupBytes, project, comment, conn); project.setTestSetupPK(testSetup.getTestSetupPK()); testSetup.setTestRunPK(submission.getCurrentTestRunPK()); testSetup.update(conn); return project; }
From source file:org.kuali.kra.coi.service.impl.CoiMessagesServiceImpl.java
/** * @ Check COI to see if annual disclosure is coming due */// w ww . j a v a2 s. com public List<String> getMessages() { List<String> results = new ArrayList<String>(); UserSession session = GlobalVariables.getUserSession(); if (session != null && StringUtils.isNotEmpty(GlobalVariables.getUserSession().getPrincipalId())) { String personId = GlobalVariables.getUserSession().getPrincipalId(); String renewalDateString = getParameterService().getParameterValueAsString( Constants.MODULE_NAMESPACE_COIDISCLOSURE, ParameterConstants.DOCUMENT_COMPONENT, "ANNUAL_DISCLOSURE_RENEWAL_DATE"); LOG.debug("renewalDateString=" + renewalDateString); if (StringUtils.isNotEmpty(renewalDateString)) { Date renewalDue = null; try { renewalDue = new Date(new SimpleDateFormat("MM/dd/yyyy").parse(renewalDateString).getTime()); } catch (Exception e) { LOG.error( "***** no valid Annual Disclosure Certification renewal date found. Defaulting to anniversary of last Annual"); } String advanceNoticeString = getParameterService().getParameterValueAsString( Constants.MODULE_NAMESPACE_COIDISCLOSURE, ParameterConstants.DOCUMENT_COMPONENT, "ANNUAL_DISCLOSURE_ADVANCE_NOTICE"); int advanceDays = -1; try { advanceDays = Integer.parseInt(advanceNoticeString); } catch (Exception e) { LOG.error( "***** no valid Annual Disclosure Certification advance notice parameter found. Defaulting to 30 days."); advanceDays = 30; } LOG.debug("advanceDays=" + advanceDays); // find latest existing annual review Map<String, Object> fieldValues = new HashMap<String, Object>(); fieldValues.put("personId", personId); fieldValues.put("eventTypeCode", CoiDisclosureEventType.ANNUAL); List<CoiDisclosure> annualDisclosures = (List<CoiDisclosure>) businessObjectService .findMatching(CoiDisclosure.class, fieldValues); Timestamp lastAnnualDate = null; for (CoiDisclosure disclosure : annualDisclosures) { final Timestamp disclosureCertificationTimestamp = disclosure.getCertificationTimestamp(); if (disclosureCertificationTimestamp != null) { if (lastAnnualDate == null || lastAnnualDate.before(disclosureCertificationTimestamp)) { lastAnnualDate = disclosureCertificationTimestamp; } } } Calendar lastAnnualCalendar = null; if (lastAnnualDate != null) { lastAnnualCalendar = Calendar.getInstance(); lastAnnualCalendar.setTimeInMillis(lastAnnualDate.getTime()); } final Calendar currentTime = Calendar.getInstance(); boolean sendErrorWithDate = false; boolean sendError = false; LOG.debug("renewalDue=" + renewalDue); if (renewalDue != null) { final Calendar reminderDate = Calendar.getInstance(); reminderDate.setTimeInMillis(renewalDue.getTime()); reminderDate.add(Calendar.DATE, -advanceDays); if (currentTime.after(reminderDate) && ((lastAnnualCalendar == null) || currentTime.after(lastAnnualCalendar))) { sendErrorWithDate = true; } } else { final Calendar dueCalendarDate = Calendar.getInstance(); if (lastAnnualDate == null) { sendError = true; } else { dueCalendarDate.setTimeInMillis(lastAnnualDate.getTime()); dueCalendarDate.add(Calendar.YEAR, 1); dueCalendarDate.add(Calendar.DATE, -1); renewalDue = new Date(dueCalendarDate.getTimeInMillis()); final Calendar reminderDate = Calendar.getInstance(); reminderDate.setTimeInMillis(renewalDue.getTime()); reminderDate.add(Calendar.DATE, -advanceDays); if (currentTime.after(reminderDate)) { sendErrorWithDate = true; } } } if (sendError) { String msg = getConfigurationService() .getPropertyValueAsString("annual.disclosure.due.message"); if (!StringUtils.isEmpty(msg)) { results.add(msg); } } if (sendErrorWithDate) { String msg = getConfigurationService() .getPropertyValueAsString("annual.disclosure.due.message.with.date"); if (!StringUtils.isEmpty(msg)) { results.add(msg.replace("{0}", new SimpleDateFormat("MM/dd/yyyy").format(renewalDue))); } } } } return results; }