Merge branch 'master' into feature/query-cache-1427

This commit is contained in:
rob bygrave committed 2018-06-16 00:09:25 +12:00
commit 5adbebaf6e
6 files changed
+118 -3

No files matched your search

+15 -1
View File
@@ -3,6 +3,7 @@ package io.ebean;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.persistence.NonUniqueResultException;
import java.time.Clock;
import java.util.List;
import java.util.Map;
import java.util.Optional;
@@ -28,6 +29,19 @@ import java.util.function.Predicate;
*/
public interface ExtendedServer {
/**
* Return the NOW time from the Clock.
*/
long clockNow();
/**
* Set the Clock to use for <code>@WhenCreated</code> and <code>@WhenModified</code>.
* <p>
* Note that we only expect to change the Clock for testing purposes.
* </p>
*/
void setClock(Clock clock);
/**
* Return the number of 'top level' or 'root' entities this query should return.
*
@@ -370,7 +384,7 @@ public interface ExtendedServer {
/**
* Execute the update query returning the number of rows updated.
* <p>
* The update query must be created using {@link #update(Class)}.
* The update query must be created using {@link EbeanServer#update(Class)}.
* </p>
*
* @param query the update query to execute
@@ -33,6 +33,7 @@ import io.ebean.util.StringHelper;
import org.avaje.datasource.DataSourceConfig;
import javax.sql.DataSource;
import java.time.Clock;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
@@ -362,6 +363,11 @@ public class ServerConfig {
*/
private String uuidStateFile = "ebean-uuid.state";
/**
* The clock used for setting the timestamps (e.g. @UpdatedTimestamp) on objects.
*/
private Clock clock = Clock.systemUTC();
private List<IdGenerator> idGenerators = new ArrayList<>();
private List<BeanFindController> findControllers = new ArrayList<>();
private List<BeanPersistController> persistControllers = new ArrayList<>();
@@ -507,6 +513,20 @@ public class ServerConfig {
}
/**
* Get the clock used for setting the timestamps (e.g. @UpdatedTimestamp) on objects.
*/
public Clock getClock() {
return clock;
}
/**
* Set the clock used for setting the timestamps (e.g. @UpdatedTimestamp) on objects.
*/
public void setClock(final Clock clock) {
this.clock = clock;
}
/**
* Return the slow query time in millis.
*/
@@ -119,10 +119,10 @@ import javax.persistence.NonUniqueResultException;
import javax.persistence.OptimisticLockException;
import javax.persistence.PersistenceException;
import javax.sql.DataSource;
import java.time.Clock;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
@@ -151,6 +151,11 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
private final DataTimeZone dataTimeZone;
/**
* Clock to use for WhenModified and WhenCreated.
*/
private Clock clock;
private final CallStackFactory callStackFactory;
/**
@@ -278,6 +283,7 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
this.beanLoader = new DefaultBeanLoader(this);
this.jsonContext = config.createJsonContext(this);
this.dataTimeZone = config.getDataTimeZone();
this.clock = config.getServerConfig().getClock();
DocStoreIntegration docStoreComponents = config.createDocStoreIntegration(this);
this.transactionManager = config.createTransactionManager(docStoreComponents.updateProcessor());
@@ -507,6 +513,16 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
return this;
}
@Override
public long clockNow() {
return clock.millis();
}
@Override
public void setClock(Clock clock) {
this.clock = clock;
}
@Override
public BeanState getBeanState(Object bean) {
if (bean instanceof EntityBean) {
@@ -1275,7 +1275,7 @@ public final class PersistRequestBean<T> extends PersistRequest implements BeanP
*/
public long now() {
if (now == 0) {
now = System.currentTimeMillis();
now = ebeanServer.clockNow();
}
return now;
}