Add TimeUtil.nowTs() to create a new Timestamp

Change-Id: I5b2457703a5812c99cd71dc2ad87e45ae5d665e2
This commit is contained in:
Dave Borowitz
2013-10-15 15:55:29 -07:00
parent 46b1ac8f07
commit 1d69c2e8ce
8 changed files with 14 additions and 11 deletions

View File

@@ -462,7 +462,7 @@ public class H2CacheImpl<K, V> extends AbstractLoadingCache<K, V> {
c.touch =c.conn.prepareStatement("UPDATE data SET accessed=? WHERE k=?");
}
try {
c.touch.setTimestamp(1, new Timestamp(TimeUtil.nowMs()));
c.touch.setTimestamp(1, TimeUtil.nowTs());
keyType.set(c.touch, 2, key);
c.touch.executeUpdate();
} finally {
@@ -491,7 +491,7 @@ public class H2CacheImpl<K, V> extends AbstractLoadingCache<K, V> {
keyType.set(c.put, 1, key);
c.put.setObject(2, holder.value);
c.put.setTimestamp(3, new Timestamp(holder.created));
c.put.setTimestamp(4, new Timestamp(TimeUtil.nowMs()));
c.put.setTimestamp(4, TimeUtil.nowTs());
c.put.executeUpdate();
holder.clean = true;
} finally {

View File

@@ -145,7 +145,7 @@ public class ChangeUtil {
}
public static void updated(final Change c) {
c.setLastUpdatedOn(new Timestamp(TimeUtil.nowMs()));
c.setLastUpdatedOn(TimeUtil.nowTs());
computeSortKey(c);
}

View File

@@ -63,7 +63,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.sql.Timestamp;
import java.util.Collections;
import java.util.List;
import java.util.Set;
@@ -332,7 +331,7 @@ public class PatchSetInserter {
if (patchSet == null) {
patchSet = new PatchSet(
ChangeUtil.nextPatchSetId(git, change.currentPatchSetId()));
patchSet.setCreatedOn(new Timestamp(TimeUtil.nowMs()));
patchSet.setCreatedOn(TimeUtil.nowTs());
patchSet.setUploader(change.getOwner());
patchSet.setRevision(new RevId(commit.name()));
}

View File

@@ -179,7 +179,7 @@ public class Submit implements RestModifyView<RevisionResource, Input>,
public Change submit(RevisionResource rsrc, IdentifiedUser caller)
throws OrmException, IOException {
final Timestamp timestamp = new Timestamp(TimeUtil.nowMs());
final Timestamp timestamp = TimeUtil.nowTs();
Change change = rsrc.getChange();
ReviewDb db = dbProvider.get();
db.changes().beginTransaction(change.getId());

View File

@@ -214,7 +214,7 @@ class EncryptedContactStore implements ContactStore {
throws ContactInformationStoreException {
Timestamp on = account.getContactFiledOn();
if (on == null) {
on = new Timestamp(TimeUtil.nowMs());
on = TimeUtil.nowTs();
}
final SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");

View File

@@ -33,7 +33,6 @@ import org.eclipse.jgit.lib.RefUpdate;
import org.eclipse.jgit.revwalk.RevCommit;
import java.io.IOException;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
@@ -160,7 +159,7 @@ public class CherryPick extends SubmitStrategy {
PatchSet.Id id =
ChangeUtil.nextPatchSetId(args.repo, n.change.currentPatchSetId());
final PatchSet ps = new PatchSet(id);
ps.setCreatedOn(new Timestamp(TimeUtil.nowMs()));
ps.setCreatedOn(TimeUtil.nowTs());
ps.setUploader(submitAudit.getAccountId());
ps.setRevision(new RevId(newCommit.getId().getName()));
insertAncestors(args.db, ps.getId(), newCommit);

View File

@@ -137,7 +137,6 @@ import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.io.StringWriter;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -1742,7 +1741,7 @@ public class ReceiveCommits {
PatchSet.Id id =
ChangeUtil.nextPatchSetId(allRefs, change.currentPatchSetId());
newPatchSet = new PatchSet(id);
newPatchSet.setCreatedOn(new Timestamp(TimeUtil.nowMs()));
newPatchSet.setCreatedOn(TimeUtil.nowTs());
newPatchSet.setUploader(currentUser.getAccountId());
newPatchSet.setRevision(toRevId(newCommit));
if (magicBranch != null && magicBranch.isDraft()) {

View File

@@ -16,12 +16,18 @@ package com.google.gerrit.server.util;
import org.joda.time.DateTimeUtils;
import java.sql.Timestamp;
/** Static utility methods for dealing with dates and times. */
public class TimeUtil {
public static long nowMs() {
return DateTimeUtils.currentTimeMillis();
}
public static Timestamp nowTs() {
return new Timestamp(nowMs());
}
private TimeUtil() {
}
}