mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
no effective change - format only
This commit is contained in:
@@ -151,7 +151,7 @@ public final class BasicTypeConverter implements Serializable {
|
||||
return (Boolean) value;
|
||||
}
|
||||
if (value instanceof Number) {
|
||||
return ((Number)value).intValue() == 1;
|
||||
return ((Number) value).intValue() == 1;
|
||||
}
|
||||
String s = value.toString();
|
||||
return s.equalsIgnoreCase(dbTrueValue);
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package com.avaje.ebeaninternal.server.core;
|
||||
|
||||
import com.avaje.ebean.bean.ObjectGraphNode;
|
||||
import com.avaje.ebean.meta.MetaObjectGraphNodeStats;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
import java.util.concurrent.atomic.LongAdder;
|
||||
|
||||
import com.avaje.ebean.meta.*;
|
||||
import com.avaje.ebean.bean.ObjectGraphNode;
|
||||
|
||||
/**
|
||||
* Helper to collect the query execution statistics for a given node.
|
||||
*/
|
||||
@@ -34,7 +34,7 @@ public class CObjectGraphNodeStatistics {
|
||||
public MetaObjectGraphNodeStats get(boolean reset) {
|
||||
if (reset) {
|
||||
return new Snapshot(node, startTime.getAndSet(System.currentTimeMillis()), count.sumThenReset(),
|
||||
totalTime.sumThenReset(), totalBeans.sumThenReset());
|
||||
totalTime.sumThenReset(), totalBeans.sumThenReset());
|
||||
} else {
|
||||
return new Snapshot(node, startTime.get(), count.sum(), totalTime.sum(), totalBeans.sum());
|
||||
}
|
||||
|
||||
@@ -1,18 +1,28 @@
|
||||
package com.avaje.ebeaninternal.server.core;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DatabaseMetaData;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import javax.persistence.PersistenceException;
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import com.avaje.ebean.config.ServerConfig;
|
||||
import com.avaje.ebean.config.dbplatform.*;
|
||||
import com.avaje.ebean.config.dbplatform.DB2Platform;
|
||||
import com.avaje.ebean.config.dbplatform.DatabasePlatform;
|
||||
import com.avaje.ebean.config.dbplatform.H2Platform;
|
||||
import com.avaje.ebean.config.dbplatform.HsqldbPlatform;
|
||||
import com.avaje.ebean.config.dbplatform.MsSqlServer2000Platform;
|
||||
import com.avaje.ebean.config.dbplatform.MsSqlServer2005Platform;
|
||||
import com.avaje.ebean.config.dbplatform.MySqlPlatform;
|
||||
import com.avaje.ebean.config.dbplatform.OraclePlatform;
|
||||
import com.avaje.ebean.config.dbplatform.Postgres8Platform;
|
||||
import com.avaje.ebean.config.dbplatform.PostgresPlatform;
|
||||
import com.avaje.ebean.config.dbplatform.SQLitePlatform;
|
||||
import com.avaje.ebean.config.dbplatform.SqlAnywherePlatform;
|
||||
import com.avaje.ebean.dbmigration.DbOffline;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.persistence.PersistenceException;
|
||||
import javax.sql.DataSource;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DatabaseMetaData;
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* Create a DatabasePlatform from the configuration.
|
||||
* <p>
|
||||
@@ -135,37 +145,29 @@ public class DatabasePlatformFactory {
|
||||
|
||||
if (dbProductName.contains("oracle")) {
|
||||
return new OraclePlatform();
|
||||
}
|
||||
else if (dbProductName.contains("microsoft")) {
|
||||
} else if (dbProductName.contains("microsoft")) {
|
||||
if (majorVersion > 8) {
|
||||
return new MsSqlServer2005Platform();
|
||||
} else {
|
||||
return new MsSqlServer2000Platform();
|
||||
}
|
||||
}
|
||||
else if (dbProductName.contains("mysql")) {
|
||||
} else if (dbProductName.contains("mysql")) {
|
||||
return new MySqlPlatform();
|
||||
}
|
||||
else if (dbProductName.contains("h2")) {
|
||||
} else if (dbProductName.contains("h2")) {
|
||||
return new H2Platform();
|
||||
}
|
||||
else if (dbProductName.contains("hsql database engine")) {
|
||||
} else if (dbProductName.contains("hsql database engine")) {
|
||||
return new HsqldbPlatform();
|
||||
}
|
||||
else if (dbProductName.contains("postgres")) {
|
||||
} else if (dbProductName.contains("postgres")) {
|
||||
return new PostgresPlatform();
|
||||
}
|
||||
else if (dbProductName.contains("sqlite")) {
|
||||
} else if (dbProductName.contains("sqlite")) {
|
||||
return new SQLitePlatform();
|
||||
}
|
||||
else if (dbProductName.contains("db2")) {
|
||||
} else if (dbProductName.contains("db2")) {
|
||||
return new DB2Platform();
|
||||
}
|
||||
else if (dbProductName.contains("sql anywhere")) {
|
||||
} else if (dbProductName.contains("sql anywhere")) {
|
||||
return new SqlAnywherePlatform();
|
||||
}
|
||||
|
||||
// use the standard one
|
||||
// use the standard one
|
||||
return new DatabasePlatform();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,32 +11,32 @@ import java.util.concurrent.TimeUnit;
|
||||
*/
|
||||
public class DefaultBackgroundExecutor implements SpiBackgroundExecutor {
|
||||
|
||||
private final DaemonScheduleThreadPool schedulePool;
|
||||
private final DaemonScheduleThreadPool schedulePool;
|
||||
|
||||
private final DaemonExecutorService pool;
|
||||
|
||||
/**
|
||||
* Construct the default implementation of BackgroundExecutor.
|
||||
*/
|
||||
public DefaultBackgroundExecutor(int schedulePoolSize, int shutdownWaitSeconds, String namePrefix) {
|
||||
this.pool = new DaemonExecutorService(shutdownWaitSeconds, namePrefix);
|
||||
this.schedulePool = new DaemonScheduleThreadPool(schedulePoolSize, shutdownWaitSeconds, namePrefix+"-periodic-");
|
||||
}
|
||||
public DefaultBackgroundExecutor(int schedulePoolSize, int shutdownWaitSeconds, String namePrefix) {
|
||||
this.pool = new DaemonExecutorService(shutdownWaitSeconds, namePrefix);
|
||||
this.schedulePool = new DaemonScheduleThreadPool(schedulePoolSize, shutdownWaitSeconds, namePrefix + "-periodic-");
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute a Runnable using a background thread.
|
||||
*/
|
||||
public void execute(Runnable r) {
|
||||
pool.execute(r);
|
||||
}
|
||||
/**
|
||||
* Execute a Runnable using a background thread.
|
||||
*/
|
||||
public void execute(Runnable r) {
|
||||
pool.execute(r);
|
||||
}
|
||||
|
||||
public void executePeriodically(Runnable r, long delay, TimeUnit unit) {
|
||||
schedulePool.scheduleWithFixedDelay(r, delay, delay, unit);
|
||||
}
|
||||
public void executePeriodically(Runnable r, long delay, TimeUnit unit) {
|
||||
schedulePool.scheduleWithFixedDelay(r, delay, delay, unit);
|
||||
}
|
||||
|
||||
public void shutdown() {
|
||||
pool.shutdown();
|
||||
schedulePool.shutdown();
|
||||
}
|
||||
|
||||
public void shutdown() {
|
||||
pool.shutdown();
|
||||
schedulePool.shutdown();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
package com.avaje.ebeaninternal.server.core;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.sql.CallableStatement;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import com.avaje.ebean.CallableSql;
|
||||
import com.avaje.ebean.EbeanServer;
|
||||
import com.avaje.ebeaninternal.api.BindParams;
|
||||
@@ -11,6 +7,10 @@ import com.avaje.ebeaninternal.api.BindParams.Param;
|
||||
import com.avaje.ebeaninternal.api.SpiCallableSql;
|
||||
import com.avaje.ebeaninternal.api.TransactionEventTable;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.sql.CallableStatement;
|
||||
import java.sql.SQLException;
|
||||
|
||||
|
||||
public class DefaultCallableSql implements Serializable, SpiCallableSql {
|
||||
|
||||
|
||||
@@ -14,8 +14,8 @@ import com.avaje.ebean.config.dbplatform.DatabasePlatform;
|
||||
import com.avaje.ebean.dbmigration.DbOffline;
|
||||
import com.avaje.ebeaninternal.api.SpiBackgroundExecutor;
|
||||
import com.avaje.ebeaninternal.api.SpiEbeanServer;
|
||||
import com.avaje.ebeaninternal.server.cache.DefaultServerCachePlugin;
|
||||
import com.avaje.ebeaninternal.server.cache.DefaultServerCacheManager;
|
||||
import com.avaje.ebeaninternal.server.cache.DefaultServerCachePlugin;
|
||||
import com.avaje.ebeaninternal.server.cluster.ClusterManager;
|
||||
import com.avaje.ebeaninternal.server.core.bootup.BootupClassPathSearch;
|
||||
import com.avaje.ebeaninternal.server.core.bootup.BootupClasses;
|
||||
@@ -286,7 +286,7 @@ public class DefaultContainer implements SpiContainer {
|
||||
DataSourceFactory factory = config.service(DataSourceFactory.class);
|
||||
if (factory == null) {
|
||||
throw new IllegalStateException("No DataSourceFactory service implementation found in class path."
|
||||
+ " Probably missing dependency to avaje-datasource?");
|
||||
+ " Probably missing dependency to avaje-datasource?");
|
||||
}
|
||||
|
||||
DataSourceAlertFactory alertFactory = config.service(DataSourceAlertFactory.class);
|
||||
@@ -306,7 +306,7 @@ public class DefaultContainer implements SpiContainer {
|
||||
if (dsConfig.getListener() == null) {
|
||||
String poolListener = dsConfig.getPoolListener();
|
||||
if (poolListener != null) {
|
||||
dsConfig.setListener((DataSourcePoolListener)config.getClassLoadConfig().newInstance(poolListener));
|
||||
dsConfig.setListener((DataSourcePoolListener) config.getClassLoadConfig().newInstance(poolListener));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,24 +1,24 @@
|
||||
package com.avaje.ebeaninternal.server.core;
|
||||
|
||||
import com.avaje.ebean.meta.MetaBeanInfo;
|
||||
import com.avaje.ebean.meta.MetaInfoManager;
|
||||
import com.avaje.ebean.meta.MetaObjectGraphNodeStats;
|
||||
import com.avaje.ebean.meta.MetaQueryPlanStatistic;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.avaje.ebean.meta.MetaBeanInfo;
|
||||
import com.avaje.ebean.meta.MetaQueryPlanStatistic;
|
||||
import com.avaje.ebean.meta.MetaInfoManager;
|
||||
import com.avaje.ebean.meta.MetaObjectGraphNodeStats;
|
||||
|
||||
/**
|
||||
* DefaultServer based implementation of MetaInfoManager.
|
||||
*/
|
||||
public class DefaultMetaInfoManager implements MetaInfoManager {
|
||||
|
||||
private final DefaultServer server;
|
||||
|
||||
|
||||
public DefaultMetaInfoManager(DefaultServer server) {
|
||||
this.server = server;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public MetaBeanInfo getMetaBeanInfo(Class<?> beanClass) {
|
||||
return server.getBeanDescriptor(beanClass);
|
||||
@@ -32,16 +32,14 @@ public class DefaultMetaInfoManager implements MetaInfoManager {
|
||||
|
||||
@Override
|
||||
public List<MetaQueryPlanStatistic> collectQueryPlanStatistics(boolean reset) {
|
||||
|
||||
|
||||
List<MetaQueryPlanStatistic> list = new ArrayList<>();
|
||||
|
||||
for (MetaBeanInfo metaBeanInfo : getMetaBeanInfoList()) {
|
||||
list.addAll(metaBeanInfo.collectQueryPlanStatistics(reset));
|
||||
}
|
||||
|
||||
return list;
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
public List<MetaObjectGraphNodeStats> collectNodeStatistics(boolean reset) {
|
||||
|
||||
List<MetaObjectGraphNodeStats> list = new ArrayList<>();
|
||||
@@ -55,5 +53,5 @@ public class DefaultMetaInfoManager implements MetaInfoManager {
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,36 @@
|
||||
package com.avaje.ebeaninternal.server.core;
|
||||
|
||||
import com.avaje.ebean.*;
|
||||
import com.avaje.ebean.AutoTune;
|
||||
import com.avaje.ebean.BackgroundExecutor;
|
||||
import com.avaje.ebean.BeanState;
|
||||
import com.avaje.ebean.CallableSql;
|
||||
import com.avaje.ebean.DocumentStore;
|
||||
import com.avaje.ebean.ExpressionFactory;
|
||||
import com.avaje.ebean.Filter;
|
||||
import com.avaje.ebean.FutureIds;
|
||||
import com.avaje.ebean.FutureList;
|
||||
import com.avaje.ebean.FutureRowCount;
|
||||
import com.avaje.ebean.PagedList;
|
||||
import com.avaje.ebean.PersistenceContextScope;
|
||||
import com.avaje.ebean.Query;
|
||||
import com.avaje.ebean.QueryEachConsumer;
|
||||
import com.avaje.ebean.QueryEachWhileConsumer;
|
||||
import com.avaje.ebean.QueryIterator;
|
||||
import com.avaje.ebean.RawSql;
|
||||
import com.avaje.ebean.SqlQuery;
|
||||
import com.avaje.ebean.SqlRow;
|
||||
import com.avaje.ebean.SqlUpdate;
|
||||
import com.avaje.ebean.Transaction;
|
||||
import com.avaje.ebean.TransactionCallback;
|
||||
import com.avaje.ebean.TxCallable;
|
||||
import com.avaje.ebean.TxIsolation;
|
||||
import com.avaje.ebean.TxRunnable;
|
||||
import com.avaje.ebean.TxScope;
|
||||
import com.avaje.ebean.TxType;
|
||||
import com.avaje.ebean.Update;
|
||||
import com.avaje.ebean.UpdateQuery;
|
||||
import com.avaje.ebean.ValuePair;
|
||||
import com.avaje.ebean.Version;
|
||||
import com.avaje.ebean.bean.BeanCollection;
|
||||
import com.avaje.ebean.bean.CallStack;
|
||||
import com.avaje.ebean.bean.EntityBean;
|
||||
@@ -538,7 +568,7 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
|
||||
* then it will returned that object.
|
||||
* </p>
|
||||
*/
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
public <T> T getReference(Class<T> type, Object id) {
|
||||
|
||||
if (id == null) {
|
||||
@@ -554,13 +584,13 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
|
||||
pc = t.getPersistenceContext();
|
||||
Object existing = desc.contextGet(pc, id);
|
||||
if (existing != null) {
|
||||
return (T)existing;
|
||||
return (T) existing;
|
||||
}
|
||||
}
|
||||
|
||||
InheritInfo inheritInfo = desc.getInheritInfo();
|
||||
if (inheritInfo == null) {
|
||||
return (T)desc.contextRef(pc, null, false, id);
|
||||
return (T) desc.contextRef(pc, null, false, id);
|
||||
}
|
||||
|
||||
BeanProperty idProp = desc.getIdProperty();
|
||||
@@ -652,32 +682,32 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
|
||||
|
||||
TxType type = scope.getType();
|
||||
switch (type) {
|
||||
case REQUIRED:
|
||||
return t == null;
|
||||
case REQUIRED:
|
||||
return t == null;
|
||||
|
||||
case REQUIRES_NEW:
|
||||
return true;
|
||||
case REQUIRES_NEW:
|
||||
return true;
|
||||
|
||||
case MANDATORY:
|
||||
if (t == null) {
|
||||
throw new PersistenceException("Transaction missing when MANDATORY");
|
||||
}
|
||||
return true;
|
||||
case MANDATORY:
|
||||
if (t == null) {
|
||||
throw new PersistenceException("Transaction missing when MANDATORY");
|
||||
}
|
||||
return true;
|
||||
|
||||
case NEVER:
|
||||
if (t != null) {
|
||||
throw new PersistenceException("Transaction exists for Transactional NEVER");
|
||||
}
|
||||
return false;
|
||||
case NEVER:
|
||||
if (t != null) {
|
||||
throw new PersistenceException("Transaction exists for Transactional NEVER");
|
||||
}
|
||||
return false;
|
||||
|
||||
case SUPPORTS:
|
||||
return false;
|
||||
case SUPPORTS:
|
||||
return false;
|
||||
|
||||
case NOT_SUPPORTED:
|
||||
throw new RuntimeException("NOT_SUPPORTED should already be handled?");
|
||||
case NOT_SUPPORTED:
|
||||
throw new RuntimeException("NOT_SUPPORTED should already be handled?");
|
||||
|
||||
default:
|
||||
throw new RuntimeException("Should never get here?");
|
||||
default:
|
||||
throw new RuntimeException("Should never get here?");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -798,7 +828,7 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
|
||||
* </p>
|
||||
* <p>
|
||||
* Code example:<br />
|
||||
*
|
||||
* <p>
|
||||
* <pre>
|
||||
* <code>
|
||||
* Ebean.startTransaction();
|
||||
@@ -814,7 +844,7 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
|
||||
* }
|
||||
* </code>
|
||||
* </pre>
|
||||
*
|
||||
* <p>
|
||||
* </p>
|
||||
*/
|
||||
public void endTransaction() {
|
||||
@@ -862,7 +892,7 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
|
||||
if (beanDescriptor == null) {
|
||||
throw new PersistenceException("BeanDescriptor not found, is [" + query.getBeanType() + "] an entity bean?");
|
||||
}
|
||||
return ((SpiQuery<T>)query).validate(beanDescriptor);
|
||||
return ((SpiQuery<T>) query).validate(beanDescriptor);
|
||||
}
|
||||
|
||||
public <T> Filter<T> filter(Class<T> beanType) {
|
||||
@@ -1056,7 +1086,7 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
|
||||
if (SpiQuery.Mode.NORMAL.equals(spiQuery.getMode()) && !spiQuery.isLoadBeanCache()) {
|
||||
// See if we can skip doing the fetch completely by getting the bean from the
|
||||
// persistence context or the bean cache
|
||||
T bean = findIdCheckPersistenceContextAndCache(t, spiQuery, spiQuery.getId());
|
||||
T bean = findIdCheckPersistenceContextAndCache(t, spiQuery, spiQuery.getId());
|
||||
if (bean != null) {
|
||||
return bean;
|
||||
}
|
||||
@@ -1116,7 +1146,7 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
public <T> Set<T> findSet(Query<T> query, Transaction t) {
|
||||
|
||||
SpiOrmQueryRequest request = createQueryRequest(Type.SET, query, t);
|
||||
@@ -1135,7 +1165,7 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
public <K, T> Map<K, T> findMap(Query<T> query, Transaction t) {
|
||||
|
||||
SpiOrmQueryRequest request = createQueryRequest(Type.MAP, query, t);
|
||||
@@ -1293,7 +1323,7 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
|
||||
@Override
|
||||
public <T> PagedList<T> findPagedList(Query<T> query, Transaction transaction) {
|
||||
|
||||
SpiQuery<T> spiQuery = (SpiQuery<T>)query;
|
||||
SpiQuery<T> spiQuery = (SpiQuery<T>) query;
|
||||
int maxRows = spiQuery.getMaxRows();
|
||||
if (maxRows == 0) {
|
||||
throw new PersistenceException("maxRows must be specified for findPagedList() query");
|
||||
@@ -1445,7 +1475,7 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
|
||||
throw new IllegalArgumentException("This bean is not an EntityBean?");
|
||||
}
|
||||
// mark the bean as dirty (so that an update will not get skipped)
|
||||
((EntityBean)bean)._ebean_getIntercept().setDirty(true);
|
||||
((EntityBean) bean)._ebean_getIntercept().setDirty(true);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1617,9 +1647,9 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
|
||||
throw new IllegalArgumentException(Message.msg("bean.isnull"));
|
||||
}
|
||||
if (!(bean instanceof EntityBean)) {
|
||||
throw new IllegalArgumentException("Was expecting an EntityBean but got a "+bean.getClass());
|
||||
throw new IllegalArgumentException("Was expecting an EntityBean but got a " + bean.getClass());
|
||||
}
|
||||
return (EntityBean)bean;
|
||||
return (EntityBean) bean;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package com.avaje.ebeaninternal.server.core;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.EbeanServer;
|
||||
import com.avaje.ebean.SqlUpdate;
|
||||
@@ -9,6 +7,8 @@ import com.avaje.ebean.Update;
|
||||
import com.avaje.ebeaninternal.api.BindParams;
|
||||
import com.avaje.ebeaninternal.api.SpiSqlUpdate;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* A SQL Update Delete or Insert statement that can be executed. For the times
|
||||
* when you want to use Sql DML rather than a ORM bean approach. Refer to the
|
||||
@@ -21,159 +21,104 @@ import com.avaje.ebeaninternal.api.SpiSqlUpdate;
|
||||
* SqlUpdate is designed for general DML sql and CallableSql is
|
||||
* designed for use with stored procedures.
|
||||
* </p>
|
||||
*
|
||||
* <pre class="code">
|
||||
* // String sql = "update f_topic set post_count = :count where id = :topicId";
|
||||
*
|
||||
* SqlUpdate update = new SqlUpdate(sql);
|
||||
* update.setParameter("count", 1);
|
||||
* update.setParameter("topicId", 50);
|
||||
*
|
||||
* int modifiedCount = Ebean.execute(update);
|
||||
* </pre>
|
||||
*
|
||||
* <p>
|
||||
* Note that when the SqlUpdate is executed via Ebean.execute() the sql is
|
||||
* parsed to determine if it is an update, delete or insert. In addition the
|
||||
* table modified is deduced. If <em>isAutoTableMod()</em> is true, then this
|
||||
* is then added to the TransactionEvent and cache invalidation etc is
|
||||
* maintained. This means you don't need to use the Ebean.externalModification()
|
||||
* method as this has already been done.
|
||||
* </p>
|
||||
* <p>
|
||||
* You can sql.setAutoTableMod(false); to stop the automatic table modification
|
||||
* </p>
|
||||
* <p>
|
||||
* EXAMPLE: Using JDBC batching with SqlUpdate
|
||||
* </p>
|
||||
* <pre class="code">
|
||||
*
|
||||
* String data = "This is a simple test of the batch processing"
|
||||
* + " mode and the transaction execute batch method";
|
||||
*
|
||||
* String[] da = data.split(" ");
|
||||
*
|
||||
* String sql = "insert into junk (word) values (?)";
|
||||
*
|
||||
* SqlUpdate sqlUpdate = Ebean.createSqlUpdate(sql);
|
||||
*
|
||||
* Transaction t = Ebean.beginTransaction();
|
||||
* t.setBatchMode(true);
|
||||
* t.setBatchSize(3);
|
||||
* try {
|
||||
* for (int i = 0; i < da.length; i++) {
|
||||
*
|
||||
* sqlUpdate.setParameter(1, da[i]);
|
||||
* sqlUpdate.execute();
|
||||
* }
|
||||
*
|
||||
* // NB: commit implicitly flushes the batch
|
||||
* Ebean.commitTransaction();
|
||||
*
|
||||
* } finally {
|
||||
* Ebean.endTransaction();
|
||||
* }
|
||||
* </pre>
|
||||
* @see com.avaje.ebean.CallableSql
|
||||
* @see com.avaje.ebean.Ebean#execute(SqlUpdate)
|
||||
*/
|
||||
public final class DefaultSqlUpdate implements Serializable, SpiSqlUpdate {
|
||||
|
||||
private static final long serialVersionUID = -6493829438421253102L;
|
||||
private static final long serialVersionUID = -6493829438421253102L;
|
||||
|
||||
private transient final EbeanServer server;
|
||||
private transient final EbeanServer server;
|
||||
|
||||
/**
|
||||
* The parameters used to bind to the sql.
|
||||
*/
|
||||
private final BindParams bindParams;
|
||||
/**
|
||||
* The parameters used to bind to the sql.
|
||||
*/
|
||||
private final BindParams bindParams;
|
||||
|
||||
/**
|
||||
* The sql update or delete statement.
|
||||
*/
|
||||
private final String sql;
|
||||
/**
|
||||
* The sql update or delete statement.
|
||||
*/
|
||||
private final String sql;
|
||||
|
||||
/**
|
||||
* The actual sql with named parameters converted.
|
||||
*/
|
||||
private String generatedSql;
|
||||
|
||||
/**
|
||||
* Some descriptive text that can be put into the transaction log.
|
||||
*/
|
||||
private String label = "";
|
||||
/**
|
||||
* Some descriptive text that can be put into the transaction log.
|
||||
*/
|
||||
private String label = "";
|
||||
|
||||
/**
|
||||
* The statement execution timeout.
|
||||
*/
|
||||
private int timeout;
|
||||
/**
|
||||
* The statement execution timeout.
|
||||
*/
|
||||
private int timeout;
|
||||
|
||||
/**
|
||||
* Automatically detect the table being modified by this sql. This will
|
||||
* register this information so that eBean invalidates cached objects if
|
||||
* required.
|
||||
*/
|
||||
private boolean isAutoTableMod = true;
|
||||
/**
|
||||
* Automatically detect the table being modified by this sql. This will
|
||||
* register this information so that eBean invalidates cached objects if
|
||||
* required.
|
||||
*/
|
||||
private boolean isAutoTableMod = true;
|
||||
|
||||
/**
|
||||
* Helper to add positioned parameters in order.
|
||||
*/
|
||||
private int addPos;
|
||||
/**
|
||||
* Helper to add positioned parameters in order.
|
||||
*/
|
||||
private int addPos;
|
||||
|
||||
/**
|
||||
* Create with server sql and bindParams object.
|
||||
* <p>
|
||||
* Useful if you are building the sql and binding parameters at the
|
||||
* same time.
|
||||
* </p>
|
||||
*/
|
||||
public DefaultSqlUpdate(EbeanServer server, String sql, BindParams bindParams) {
|
||||
this.server = server;
|
||||
this.sql = sql;
|
||||
this.bindParams = bindParams;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create with a specific server. This means you can use the
|
||||
* SqlUpdate.execute() method.
|
||||
*/
|
||||
public DefaultSqlUpdate(EbeanServer server, String sql) {
|
||||
this(server, sql, new BindParams());
|
||||
}
|
||||
/**
|
||||
* Create with server sql and bindParams object.
|
||||
* <p>
|
||||
* Useful if you are building the sql and binding parameters at the
|
||||
* same time.
|
||||
* </p>
|
||||
*/
|
||||
public DefaultSqlUpdate(EbeanServer server, String sql, BindParams bindParams) {
|
||||
this.server = server;
|
||||
this.sql = sql;
|
||||
this.bindParams = bindParams;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create with some sql.
|
||||
*/
|
||||
public DefaultSqlUpdate(String sql) {
|
||||
this(null, sql, new BindParams());
|
||||
}
|
||||
/**
|
||||
* Create with a specific server. This means you can use the
|
||||
* SqlUpdate.execute() method.
|
||||
*/
|
||||
public DefaultSqlUpdate(EbeanServer server, String sql) {
|
||||
this(server, sql, new BindParams());
|
||||
}
|
||||
|
||||
public int execute() {
|
||||
if (server != null) {
|
||||
return server.execute(this);
|
||||
} else {
|
||||
// Hopefully this doesn't catch anyone out...
|
||||
return Ebean.execute(this);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Create with some sql.
|
||||
*/
|
||||
public DefaultSqlUpdate(String sql) {
|
||||
this(null, sql, new BindParams());
|
||||
}
|
||||
|
||||
public boolean isAutoTableMod() {
|
||||
return isAutoTableMod;
|
||||
}
|
||||
public int execute() {
|
||||
if (server != null) {
|
||||
return server.execute(this);
|
||||
} else {
|
||||
// Hopefully this doesn't catch anyone out...
|
||||
return Ebean.execute(this);
|
||||
}
|
||||
}
|
||||
|
||||
public SqlUpdate setAutoTableMod(boolean isAutoTableMod) {
|
||||
this.isAutoTableMod = isAutoTableMod;
|
||||
return this;
|
||||
}
|
||||
public boolean isAutoTableMod() {
|
||||
return isAutoTableMod;
|
||||
}
|
||||
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
public SqlUpdate setAutoTableMod(boolean isAutoTableMod) {
|
||||
this.isAutoTableMod = isAutoTableMod;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SqlUpdate setLabel(String label) {
|
||||
this.label = label;
|
||||
return this;
|
||||
}
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
|
||||
public SqlUpdate setLabel(String label) {
|
||||
this.label = label;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getGeneratedSql() {
|
||||
return generatedSql;
|
||||
@@ -185,57 +130,57 @@ public final class DefaultSqlUpdate implements Serializable, SpiSqlUpdate {
|
||||
}
|
||||
|
||||
public String getSql() {
|
||||
return sql;
|
||||
}
|
||||
return sql;
|
||||
}
|
||||
|
||||
public int getTimeout() {
|
||||
return timeout;
|
||||
}
|
||||
public int getTimeout() {
|
||||
return timeout;
|
||||
}
|
||||
|
||||
public SqlUpdate setTimeout(int secs) {
|
||||
this.timeout = secs;
|
||||
return this;
|
||||
}
|
||||
public SqlUpdate setTimeout(int secs) {
|
||||
this.timeout = secs;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void addParameter(Object value) {
|
||||
setParameter(++addPos, value);
|
||||
}
|
||||
|
||||
public SqlUpdate setParameter(int position, Object value) {
|
||||
bindParams.setParameter(position, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SqlUpdate setNull(int position, int jdbcType) {
|
||||
bindParams.setNullParameter(position, jdbcType);
|
||||
return this;
|
||||
}
|
||||
public SqlUpdate setParameter(int position, Object value) {
|
||||
bindParams.setParameter(position, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SqlUpdate setNullParameter(int position, int jdbcType) {
|
||||
bindParams.setNullParameter(position, jdbcType);
|
||||
return this;
|
||||
}
|
||||
public SqlUpdate setNull(int position, int jdbcType) {
|
||||
bindParams.setNullParameter(position, jdbcType);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SqlUpdate setParameter(String name, Object param) {
|
||||
bindParams.setParameter(name, param);
|
||||
return this;
|
||||
}
|
||||
public SqlUpdate setNullParameter(int position, int jdbcType) {
|
||||
bindParams.setNullParameter(position, jdbcType);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SqlUpdate setNull(String name, int jdbcType) {
|
||||
bindParams.setNullParameter(name, jdbcType);
|
||||
return this;
|
||||
}
|
||||
public SqlUpdate setParameter(String name, Object param) {
|
||||
bindParams.setParameter(name, param);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SqlUpdate setNullParameter(String name, int jdbcType) {
|
||||
bindParams.setNullParameter(name, jdbcType);
|
||||
return this;
|
||||
}
|
||||
public SqlUpdate setNull(String name, int jdbcType) {
|
||||
bindParams.setNullParameter(name, jdbcType);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the bind parameters.
|
||||
*/
|
||||
public BindParams getBindParams() {
|
||||
return bindParams;
|
||||
}
|
||||
public SqlUpdate setNullParameter(String name, int jdbcType) {
|
||||
bindParams.setNullParameter(name, jdbcType);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the bind parameters.
|
||||
*/
|
||||
public BindParams getBindParams() {
|
||||
return bindParams;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ public class DiffHelp {
|
||||
iterator.remove();
|
||||
|
||||
} else if (beanProperty instanceof BeanPropertyAssocOne) {
|
||||
BeanPropertyAssocOne<?> assoc = (BeanPropertyAssocOne<?>)beanProperty;
|
||||
BeanPropertyAssocOne<?> assoc = (BeanPropertyAssocOne<?>) beanProperty;
|
||||
if (!assoc.isEmbedded()) {
|
||||
// flatten for assoc one beans
|
||||
if (flattened == null) {
|
||||
@@ -95,8 +95,8 @@ public class DiffHelp {
|
||||
BeanDescriptor<?> oneDesc = assoc.getTargetDescriptor();
|
||||
|
||||
ValuePair value = entry.getValue();
|
||||
Object newId = value.getNewValue() == null ? null : oneDesc.getId((EntityBean)value.getNewValue());
|
||||
Object oldId = value.getOldValue() == null ? null : oneDesc.getId((EntityBean)value.getOldValue());
|
||||
Object newId = value.getNewValue() == null ? null : oneDesc.getId((EntityBean) value.getNewValue());
|
||||
Object oldId = value.getOldValue() == null ? null : oneDesc.getId((EntityBean) value.getOldValue());
|
||||
|
||||
String propName = beanProperty.getName() + "." + oneDesc.getIdProperty().getName();
|
||||
flattened.put(propName, new ValuePair(newId, oldId));
|
||||
|
||||
@@ -5,33 +5,33 @@ import java.util.HashMap;
|
||||
/**
|
||||
* Used to reduce memory consumption of strings used in deployment processing.
|
||||
* <p>
|
||||
* Using this for now instead of String.intern() to avoid any unexpected
|
||||
* Using this for now instead of String.intern() to avoid any unexpected
|
||||
* increase in PermGen space.
|
||||
* </p>
|
||||
*/
|
||||
public final class InternString {
|
||||
|
||||
private static final HashMap<String,String> map = new HashMap<>();
|
||||
|
||||
|
||||
/**
|
||||
* Return the shared instance of this string.
|
||||
*/
|
||||
public static String intern(String s){
|
||||
|
||||
if (s == null){
|
||||
return null;
|
||||
}
|
||||
|
||||
synchronized (map) {
|
||||
String v = map.get(s);
|
||||
if (v != null){
|
||||
return v;
|
||||
} else {
|
||||
map.put(s, s);
|
||||
return s;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
private static final HashMap<String, String> map = new HashMap<>();
|
||||
|
||||
|
||||
/**
|
||||
* Return the shared instance of this string.
|
||||
*/
|
||||
public static String intern(String s) {
|
||||
|
||||
if (s == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
synchronized (map) {
|
||||
String v = map.get(s);
|
||||
if (v != null) {
|
||||
return v;
|
||||
} else {
|
||||
map.put(s, s);
|
||||
return s;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,56 +9,56 @@ import java.util.ResourceBundle;
|
||||
*/
|
||||
public class Message {
|
||||
|
||||
private static final String bundle = "com.avaje.ebeaninternal.api.message";
|
||||
private static final String bundle = "com.avaje.ebeaninternal.api.message";
|
||||
|
||||
/**
|
||||
* Return a message that has a single argument.
|
||||
*/
|
||||
public static String msg(String key, Object arg) {
|
||||
Object[] args = new Object[1];
|
||||
args[0] = arg;
|
||||
return MessageFormat.format(getPattern(key), args);
|
||||
}
|
||||
/**
|
||||
* Return a message that has a single argument.
|
||||
*/
|
||||
public static String msg(String key, Object arg) {
|
||||
Object[] args = new Object[1];
|
||||
args[0] = arg;
|
||||
return MessageFormat.format(getPattern(key), args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a message that has a two arguments.
|
||||
*/
|
||||
public static String msg(String key, Object arg, Object arg2) {
|
||||
Object[] args = new Object[2];
|
||||
args[0] = arg;
|
||||
args[1] = arg2;
|
||||
return MessageFormat.format(getPattern(key), args);
|
||||
}
|
||||
/**
|
||||
* Return a message that has a two arguments.
|
||||
*/
|
||||
public static String msg(String key, Object arg, Object arg2) {
|
||||
Object[] args = new Object[2];
|
||||
args[0] = arg;
|
||||
args[1] = arg2;
|
||||
return MessageFormat.format(getPattern(key), args);
|
||||
}
|
||||
|
||||
public static String msg(String key, Object arg, Object arg2, Object arg3) {
|
||||
Object[] args = new Object[3];
|
||||
args[0] = arg;
|
||||
args[1] = arg2;
|
||||
args[2] = arg3;
|
||||
return MessageFormat.format(getPattern(key), args);
|
||||
}
|
||||
public static String msg(String key, Object arg, Object arg2, Object arg3) {
|
||||
Object[] args = new Object[3];
|
||||
args[0] = arg;
|
||||
args[1] = arg2;
|
||||
args[2] = arg3;
|
||||
return MessageFormat.format(getPattern(key), args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a message that has an array of arguments.
|
||||
*/
|
||||
public static String msg(String key, Object[] args) {
|
||||
return MessageFormat.format(getPattern(key), args);
|
||||
}
|
||||
/**
|
||||
* Return a message that has an array of arguments.
|
||||
*/
|
||||
public static String msg(String key, Object[] args) {
|
||||
return MessageFormat.format(getPattern(key), args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a message that has a no arguments.
|
||||
*/
|
||||
public static String msg(String key) {
|
||||
return MessageFormat.format(getPattern(key), new Object[0]);
|
||||
}
|
||||
/**
|
||||
* Return a message that has a no arguments.
|
||||
*/
|
||||
public static String msg(String key) {
|
||||
return MessageFormat.format(getPattern(key), new Object[0]);
|
||||
}
|
||||
|
||||
private static String getPattern(String key) {
|
||||
try {
|
||||
ResourceBundle myResources = ResourceBundle.getBundle(bundle);
|
||||
return myResources.getString(key);
|
||||
} catch (MissingResourceException e) {
|
||||
return "MissingResource " + bundle + ":" + key;
|
||||
}
|
||||
private static String getPattern(String key) {
|
||||
try {
|
||||
ResourceBundle myResources = ResourceBundle.getBundle(bundle);
|
||||
return myResources.getString(key);
|
||||
} catch (MissingResourceException e) {
|
||||
return "MissingResource " + bundle + ":" + key;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -11,36 +11,36 @@ import com.avaje.ebeaninternal.server.persist.PersistExecute;
|
||||
*/
|
||||
public abstract class PersistRequest extends BeanRequest implements BatchPostExecute {
|
||||
|
||||
public enum Type {
|
||||
INSERT, UPDATE, DELETE, SOFT_DELETE, DELETE_PERMANENT, UPDATESQL, CALLABLESQL
|
||||
}
|
||||
public enum Type {
|
||||
INSERT, UPDATE, DELETE, SOFT_DELETE, DELETE_PERMANENT, UPDATESQL, CALLABLESQL
|
||||
}
|
||||
|
||||
protected boolean persistCascade;
|
||||
|
||||
/**
|
||||
* One of INSERT, UPDATE, DELETE, UPDATESQL or CALLABLESQL.
|
||||
*/
|
||||
protected Type type;
|
||||
|
||||
protected final PersistExecute persistExecute;
|
||||
protected boolean persistCascade;
|
||||
|
||||
/**
|
||||
* Used by CallableSqlRequest and UpdateSqlRequest.
|
||||
*/
|
||||
public PersistRequest(SpiEbeanServer server, SpiTransaction t, PersistExecute persistExecute) {
|
||||
super(server, t);
|
||||
this.persistExecute = persistExecute;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute a the request or queue/batch it for later execution.
|
||||
*/
|
||||
public abstract int executeOrQueue();
|
||||
* One of INSERT, UPDATE, DELETE, UPDATESQL or CALLABLESQL.
|
||||
*/
|
||||
protected Type type;
|
||||
|
||||
/**
|
||||
* Execute the request right now.
|
||||
*/
|
||||
public abstract int executeNow();
|
||||
protected final PersistExecute persistExecute;
|
||||
|
||||
/**
|
||||
* Used by CallableSqlRequest and UpdateSqlRequest.
|
||||
*/
|
||||
public PersistRequest(SpiEbeanServer server, SpiTransaction t, PersistExecute persistExecute) {
|
||||
super(server, t);
|
||||
this.persistExecute = persistExecute;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute a the request or queue/batch it for later execution.
|
||||
*/
|
||||
public abstract int executeOrQueue();
|
||||
|
||||
/**
|
||||
* Execute the request right now.
|
||||
*/
|
||||
public abstract int executeNow();
|
||||
|
||||
public boolean isLogSql() {
|
||||
return transaction.isLogSql();
|
||||
@@ -58,47 +58,47 @@ public abstract class PersistRequest extends BeanRequest implements BatchPostExe
|
||||
return transaction.isBatchThisRequest(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the statement.
|
||||
*/
|
||||
public int executeStatement() {
|
||||
|
||||
boolean batch = isBatchThisRequest();
|
||||
/**
|
||||
* Execute the statement.
|
||||
*/
|
||||
public int executeStatement() {
|
||||
|
||||
int rows;
|
||||
BatchControl control = transaction.getBatchControl();
|
||||
if (control != null) {
|
||||
rows = control.executeStatementOrBatch(this, batch);
|
||||
|
||||
} else if (batch) {
|
||||
// need to create the BatchControl
|
||||
control = persistExecute.createBatchControl(transaction);
|
||||
rows = control.executeStatementOrBatch(this, true);
|
||||
} else {
|
||||
rows = executeNow();
|
||||
}
|
||||
|
||||
return rows;
|
||||
}
|
||||
boolean batch = isBatchThisRequest();
|
||||
|
||||
int rows;
|
||||
BatchControl control = transaction.getBatchControl();
|
||||
if (control != null) {
|
||||
rows = control.executeStatementOrBatch(this, batch);
|
||||
|
||||
} else if (batch) {
|
||||
// need to create the BatchControl
|
||||
control = persistExecute.createBatchControl(transaction);
|
||||
rows = control.executeStatementOrBatch(this, true);
|
||||
} else {
|
||||
rows = executeNow();
|
||||
}
|
||||
|
||||
return rows;
|
||||
}
|
||||
|
||||
public void initTransIfRequired() {
|
||||
createImplicitTransIfRequired();
|
||||
persistCascade = transaction.isPersistCascade();
|
||||
}
|
||||
createImplicitTransIfRequired();
|
||||
persistCascade = transaction.isPersistCascade();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the type of this request. One of INSERT, UPDATE, DELETE, UPDATESQL
|
||||
* or CALLABLESQL.
|
||||
*/
|
||||
public Type getType() {
|
||||
return type;
|
||||
}
|
||||
/**
|
||||
* Return the type of this request. One of INSERT, UPDATE, DELETE, UPDATESQL
|
||||
* or CALLABLESQL.
|
||||
*/
|
||||
public Type getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if save and delete should cascade.
|
||||
*/
|
||||
public boolean isPersistCascade() {
|
||||
return persistCascade;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if save and delete should cascade.
|
||||
*/
|
||||
public boolean isPersistCascade() {
|
||||
return persistCascade;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ import com.avaje.ebeaninternal.server.transaction.BeanPersistIdMap;
|
||||
import com.avaje.ebeanservice.docstore.api.DocStoreUpdate;
|
||||
import com.avaje.ebeanservice.docstore.api.DocStoreUpdateContext;
|
||||
import com.avaje.ebeanservice.docstore.api.DocStoreUpdates;
|
||||
|
||||
import javax.persistence.OptimisticLockException;
|
||||
import javax.persistence.PersistenceException;
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
package com.avaje.ebeaninternal.server.core;
|
||||
|
||||
import java.sql.CallableStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
import com.avaje.ebean.CallableSql;
|
||||
import com.avaje.ebeaninternal.api.BindParams;
|
||||
import com.avaje.ebeaninternal.api.BindParams.Param;
|
||||
@@ -13,135 +9,138 @@ import com.avaje.ebeaninternal.api.SpiTransaction;
|
||||
import com.avaje.ebeaninternal.api.TransactionEventTable;
|
||||
import com.avaje.ebeaninternal.server.persist.PersistExecute;
|
||||
|
||||
import java.sql.CallableStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Persist request specifically for CallableSql.
|
||||
*/
|
||||
public final class PersistRequestCallableSql extends PersistRequest {
|
||||
|
||||
private final SpiCallableSql callableSql;
|
||||
private final SpiCallableSql callableSql;
|
||||
|
||||
private int rowCount;
|
||||
private int rowCount;
|
||||
|
||||
private String bindLog;
|
||||
private String bindLog;
|
||||
|
||||
private CallableStatement cstmt;
|
||||
private CallableStatement cstmt;
|
||||
|
||||
private BindParams bindParam;
|
||||
private BindParams bindParam;
|
||||
|
||||
/**
|
||||
* Create.
|
||||
*/
|
||||
public PersistRequestCallableSql(SpiEbeanServer server,
|
||||
CallableSql cs, SpiTransaction t, PersistExecute persistExecute) {
|
||||
/**
|
||||
* Create.
|
||||
*/
|
||||
public PersistRequestCallableSql(SpiEbeanServer server,
|
||||
CallableSql cs, SpiTransaction t, PersistExecute persistExecute) {
|
||||
|
||||
super(server, t, persistExecute);
|
||||
this.type = PersistRequest.Type.CALLABLESQL;
|
||||
this.callableSql = (SpiCallableSql)cs;
|
||||
}
|
||||
super(server, t, persistExecute);
|
||||
this.type = PersistRequest.Type.CALLABLESQL;
|
||||
this.callableSql = (SpiCallableSql) cs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int executeOrQueue() {
|
||||
return executeStatement();
|
||||
}
|
||||
@Override
|
||||
public int executeOrQueue() {
|
||||
return executeStatement();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int executeNow() {
|
||||
return persistExecute.executeSqlCallable(this);
|
||||
}
|
||||
@Override
|
||||
public int executeNow() {
|
||||
return persistExecute.executeSqlCallable(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the CallableSql.
|
||||
*/
|
||||
public SpiCallableSql getCallableSql() {
|
||||
return callableSql;
|
||||
}
|
||||
/**
|
||||
* Return the CallableSql.
|
||||
*/
|
||||
public SpiCallableSql getCallableSql() {
|
||||
return callableSql;
|
||||
}
|
||||
|
||||
/**
|
||||
* The the log of bind values.
|
||||
*/
|
||||
public void setBindLog(String bindLog) {
|
||||
this.bindLog = bindLog;
|
||||
}
|
||||
/**
|
||||
* The the log of bind values.
|
||||
*/
|
||||
public void setBindLog(String bindLog) {
|
||||
this.bindLog = bindLog;
|
||||
}
|
||||
|
||||
/**
|
||||
* Note the rowCount of the execution.
|
||||
*/
|
||||
public void checkRowCount(int count) {
|
||||
this.rowCount = count;
|
||||
}
|
||||
/**
|
||||
* Note the rowCount of the execution.
|
||||
*/
|
||||
public void checkRowCount(int count) {
|
||||
this.rowCount = count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Only called for insert with generated keys.
|
||||
*/
|
||||
public void setGeneratedKey(Object idValue) {
|
||||
}
|
||||
/**
|
||||
* Only called for insert with generated keys.
|
||||
*/
|
||||
public void setGeneratedKey(Object idValue) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform post execute processing for the CallableSql.
|
||||
*/
|
||||
public void postExecute() {
|
||||
/**
|
||||
* Perform post execute processing for the CallableSql.
|
||||
*/
|
||||
public void postExecute() {
|
||||
|
||||
if (transaction.isLogSummary()) {
|
||||
String m = "CallableSql label[" + callableSql.getLabel() + "]" + " rows[" + rowCount+ "]" + " bind[" + bindLog + "]";
|
||||
transaction.logSummary(m);
|
||||
}
|
||||
if (transaction.isLogSummary()) {
|
||||
String m = "CallableSql label[" + callableSql.getLabel() + "]" + " rows[" + rowCount + "]" + " bind[" + bindLog + "]";
|
||||
transaction.logSummary(m);
|
||||
}
|
||||
|
||||
// register table modifications with the transaction event
|
||||
TransactionEventTable tableEvents = callableSql.getTransactionEventTable();
|
||||
// register table modifications with the transaction event
|
||||
TransactionEventTable tableEvents = callableSql.getTransactionEventTable();
|
||||
|
||||
if (tableEvents != null && !tableEvents.isEmpty()) {
|
||||
transaction.getEvent().add(tableEvents);
|
||||
} else {
|
||||
transaction.markNotQueryOnly();
|
||||
}
|
||||
if (tableEvents != null && !tableEvents.isEmpty()) {
|
||||
transaction.getEvent().add(tableEvents);
|
||||
} else {
|
||||
transaction.markNotQueryOnly();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* These need to be set for use with Non-batch execution. Specifically to
|
||||
* read registered out parameters and potentially handle the
|
||||
* executeOverride() method.
|
||||
*/
|
||||
public void setBound(BindParams bindParam, CallableStatement cstmt) {
|
||||
this.bindParam = bindParam;
|
||||
this.cstmt = cstmt;
|
||||
}
|
||||
/**
|
||||
* These need to be set for use with Non-batch execution. Specifically to
|
||||
* read registered out parameters and potentially handle the
|
||||
* executeOverride() method.
|
||||
*/
|
||||
public void setBound(BindParams bindParam, CallableStatement cstmt) {
|
||||
this.bindParam = bindParam;
|
||||
this.cstmt = cstmt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the statement in normal non batch mode.
|
||||
*/
|
||||
public int executeUpdate() throws SQLException {
|
||||
/**
|
||||
* Execute the statement in normal non batch mode.
|
||||
*/
|
||||
public int executeUpdate() throws SQLException {
|
||||
|
||||
// check to see if the execution has been overridden
|
||||
// only works in non-batch mode
|
||||
if (callableSql.executeOverride(cstmt)) {
|
||||
return -1;
|
||||
// // been overridden so just return the rowCount
|
||||
// rowCount = callableSql.getRowCount();
|
||||
// return rowCount;
|
||||
}
|
||||
// check to see if the execution has been overridden
|
||||
// only works in non-batch mode
|
||||
if (callableSql.executeOverride(cstmt)) {
|
||||
return -1;
|
||||
// // been overridden so just return the rowCount
|
||||
// rowCount = callableSql.getRowCount();
|
||||
// return rowCount;
|
||||
}
|
||||
|
||||
rowCount = cstmt.executeUpdate();
|
||||
rowCount = cstmt.executeUpdate();
|
||||
|
||||
// only read in non-batch mode
|
||||
readOutParams();
|
||||
// only read in non-batch mode
|
||||
readOutParams();
|
||||
|
||||
return rowCount;
|
||||
}
|
||||
return rowCount;
|
||||
}
|
||||
|
||||
private void readOutParams() throws SQLException {
|
||||
private void readOutParams() throws SQLException {
|
||||
|
||||
List<Param> list = bindParam.positionedParameters();
|
||||
int pos = 0;
|
||||
List<Param> list = bindParam.positionedParameters();
|
||||
int pos = 0;
|
||||
|
||||
for (Param aList : list) {
|
||||
for (Param param : list) {
|
||||
pos++;
|
||||
Param param = aList;
|
||||
if (param.isOutParam()) {
|
||||
Object outValue = cstmt.getObject(pos);
|
||||
param.setOutValue(outValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -13,98 +13,98 @@ import com.avaje.ebeaninternal.server.persist.PersistExecute;
|
||||
*/
|
||||
public final class PersistRequestOrmUpdate extends PersistRequest {
|
||||
|
||||
private final BeanDescriptor<?> beanDescriptor;
|
||||
|
||||
private final SpiUpdate<?> ormUpdate;
|
||||
private final BeanDescriptor<?> beanDescriptor;
|
||||
|
||||
private int rowCount;
|
||||
private final SpiUpdate<?> ormUpdate;
|
||||
|
||||
private String bindLog;
|
||||
private int rowCount;
|
||||
|
||||
/**
|
||||
* Create.
|
||||
*/
|
||||
public PersistRequestOrmUpdate(SpiEbeanServer server, BeanManager<?> mgr, SpiUpdate<?> ormUpdate,
|
||||
SpiTransaction t, PersistExecute persistExecute) {
|
||||
|
||||
super(server, t, persistExecute);
|
||||
this.beanDescriptor = mgr.getBeanDescriptor();
|
||||
this.ormUpdate = ormUpdate;
|
||||
}
|
||||
|
||||
public BeanDescriptor<?> getBeanDescriptor() {
|
||||
return beanDescriptor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int executeNow() {
|
||||
return persistExecute.executeOrmUpdate(this);
|
||||
}
|
||||
private String bindLog;
|
||||
|
||||
@Override
|
||||
public int executeOrQueue() {
|
||||
return executeStatement();
|
||||
}
|
||||
/**
|
||||
* Create.
|
||||
*/
|
||||
public PersistRequestOrmUpdate(SpiEbeanServer server, BeanManager<?> mgr, SpiUpdate<?> ormUpdate,
|
||||
SpiTransaction t, PersistExecute persistExecute) {
|
||||
|
||||
super(server, t, persistExecute);
|
||||
this.beanDescriptor = mgr.getBeanDescriptor();
|
||||
this.ormUpdate = ormUpdate;
|
||||
}
|
||||
|
||||
public BeanDescriptor<?> getBeanDescriptor() {
|
||||
return beanDescriptor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int executeNow() {
|
||||
return persistExecute.executeOrmUpdate(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int executeOrQueue() {
|
||||
return executeStatement();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the UpdateSql.
|
||||
*/
|
||||
public SpiUpdate<?> getOrmUpdate() {
|
||||
return ormUpdate;
|
||||
}
|
||||
/**
|
||||
* Return the UpdateSql.
|
||||
*/
|
||||
public SpiUpdate<?> getOrmUpdate() {
|
||||
return ormUpdate;
|
||||
}
|
||||
|
||||
/**
|
||||
* No concurrency checking so just note the rowCount.
|
||||
*/
|
||||
public void checkRowCount(int count) {
|
||||
this.rowCount = count;
|
||||
}
|
||||
/**
|
||||
* No concurrency checking so just note the rowCount.
|
||||
*/
|
||||
public void checkRowCount(int count) {
|
||||
this.rowCount = count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Not called for this type of request.
|
||||
*/
|
||||
public void setGeneratedKey(Object idValue) {
|
||||
}
|
||||
/**
|
||||
* Not called for this type of request.
|
||||
*/
|
||||
public void setGeneratedKey(Object idValue) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the bound values.
|
||||
*/
|
||||
public void setBindLog(String bindLog) {
|
||||
this.bindLog = bindLog;
|
||||
}
|
||||
/**
|
||||
* Set the bound values.
|
||||
*/
|
||||
public void setBindLog(String bindLog) {
|
||||
this.bindLog = bindLog;
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform post execute processing.
|
||||
*/
|
||||
public void postExecute() {
|
||||
/**
|
||||
* Perform post execute processing.
|
||||
*/
|
||||
public void postExecute() {
|
||||
|
||||
OrmUpdateType ormUpdateType = ormUpdate.getOrmUpdateType();
|
||||
String tableName = ormUpdate.getBaseTable();
|
||||
|
||||
if (transaction.isLogSummary()) {
|
||||
String m = ormUpdateType + " table[" + tableName + "] rows["+ rowCount + "] bind[" + bindLog + "]";
|
||||
transaction.logSummary(m);
|
||||
}
|
||||
|
||||
if (ormUpdate.isNotifyCache()) {
|
||||
|
||||
// add the modification info to the TransactionEvent
|
||||
// this is used to invalidate cached objects etc
|
||||
switch (ormUpdateType) {
|
||||
case INSERT:
|
||||
transaction.getEvent().add(tableName, true, false, false);
|
||||
break;
|
||||
case UPDATE:
|
||||
transaction.getEvent().add(tableName, false, true, false);
|
||||
break;
|
||||
case DELETE:
|
||||
transaction.getEvent().add(tableName, false, false, true);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
OrmUpdateType ormUpdateType = ormUpdate.getOrmUpdateType();
|
||||
String tableName = ormUpdate.getBaseTable();
|
||||
|
||||
if (transaction.isLogSummary()) {
|
||||
String m = ormUpdateType + " table[" + tableName + "] rows[" + rowCount + "] bind[" + bindLog + "]";
|
||||
transaction.logSummary(m);
|
||||
}
|
||||
|
||||
if (ormUpdate.isNotifyCache()) {
|
||||
|
||||
// add the modification info to the TransactionEvent
|
||||
// this is used to invalidate cached objects etc
|
||||
switch (ormUpdateType) {
|
||||
case INSERT:
|
||||
transaction.getEvent().add(tableName, true, false, false);
|
||||
break;
|
||||
case UPDATE:
|
||||
transaction.getEvent().add(tableName, false, true, false);
|
||||
break;
|
||||
case DELETE:
|
||||
transaction.getEvent().add(tableName, false, false, true);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
package com.avaje.ebeaninternal.server.core;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import com.avaje.ebean.CallableSql;
|
||||
import com.avaje.ebean.Query;
|
||||
import com.avaje.ebean.SqlUpdate;
|
||||
@@ -10,6 +7,9 @@ import com.avaje.ebean.Transaction;
|
||||
import com.avaje.ebean.Update;
|
||||
import com.avaje.ebean.bean.EntityBean;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* API for persisting a bean.
|
||||
*/
|
||||
|
||||
@@ -218,8 +218,7 @@ public final class RelationalQueryRequest {
|
||||
int firstRow = query.getFirstRow();
|
||||
int maxRows = query.getMaxRows();
|
||||
if (firstRow > 0 || maxRows > 0) {
|
||||
return ebeanServer.getDatabasePlatform().getBasicSqlLimiter()
|
||||
.limit(sql, firstRow, maxRows);
|
||||
return ebeanServer.getDatabasePlatform().getBasicSqlLimiter().limit(sql, firstRow, maxRows);
|
||||
}
|
||||
return sql;
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ import javax.servlet.ServletContextEvent;
|
||||
|
||||
/**
|
||||
* Listens for webserver server starting and stopping events.
|
||||
*
|
||||
* <p>
|
||||
* Register this listener in the web.xml configuration file. This will listen
|
||||
* for startup and shutdown events.
|
||||
@@ -14,18 +13,18 @@ import javax.servlet.ServletContextEvent;
|
||||
*/
|
||||
public class ServletContextListener implements javax.servlet.ServletContextListener {
|
||||
|
||||
/**
|
||||
* The servlet container is stopping.
|
||||
*/
|
||||
public void contextDestroyed(ServletContextEvent event) {
|
||||
ShutdownManager.shutdown();
|
||||
}
|
||||
/**
|
||||
* The servlet container is stopping.
|
||||
*/
|
||||
public void contextDestroyed(ServletContextEvent event) {
|
||||
ShutdownManager.shutdown();
|
||||
}
|
||||
|
||||
/**
|
||||
* Do nothing on startup.
|
||||
*/
|
||||
public void contextInitialized(ServletContextEvent event) {
|
||||
/**
|
||||
* Do nothing on startup.
|
||||
*/
|
||||
public void contextInitialized(ServletContextEvent event) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -11,17 +11,17 @@ import com.avaje.ebeaninternal.api.SpiTransaction;
|
||||
*/
|
||||
final class TransWrapper {
|
||||
|
||||
final SpiTransaction transaction;
|
||||
final SpiTransaction transaction;
|
||||
|
||||
private final boolean wasCreated;
|
||||
private final boolean wasCreated;
|
||||
|
||||
/**
|
||||
* Wrap the transaction indicating if it was just created.
|
||||
*/
|
||||
TransWrapper(SpiTransaction t, boolean created) {
|
||||
transaction = t;
|
||||
wasCreated = created;
|
||||
}
|
||||
/**
|
||||
* Wrap the transaction indicating if it was just created.
|
||||
*/
|
||||
TransWrapper(SpiTransaction t, boolean created) {
|
||||
transaction = t;
|
||||
wasCreated = created;
|
||||
}
|
||||
|
||||
void batchEscalateOnCollection() {
|
||||
transaction.checkBatchEscalationOnCollection();
|
||||
@@ -33,24 +33,24 @@ final class TransWrapper {
|
||||
}
|
||||
}
|
||||
|
||||
void commitIfCreated() {
|
||||
if (wasCreated){
|
||||
transaction.commit();
|
||||
}
|
||||
}
|
||||
|
||||
void rollbackIfCreated() {
|
||||
if (wasCreated){
|
||||
transaction.rollbackIfActive();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the transaction was just created. If true it should be
|
||||
* committed after the request has been processed.
|
||||
*/
|
||||
boolean wasCreated() {
|
||||
return wasCreated;
|
||||
}
|
||||
void commitIfCreated() {
|
||||
if (wasCreated) {
|
||||
transaction.commit();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
void rollbackIfCreated() {
|
||||
if (wasCreated) {
|
||||
transaction.rollbackIfActive();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the transaction was just created. If true it should be
|
||||
* committed after the request has been processed.
|
||||
*/
|
||||
boolean wasCreated() {
|
||||
return wasCreated;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,7 +6,8 @@ import org.avaje.classpath.scanner.ClassPathScanner;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Searches for interesting classes such as Entities, Embedded and ScalarTypes.
|
||||
|
||||
@@ -24,14 +24,14 @@ class ManifestReader {
|
||||
/**
|
||||
* Read the packages from ebean.mf manifest files found as resources.
|
||||
*/
|
||||
static Set<String> readManifests(ClassLoader classLoader, String resourcePath) {
|
||||
static Set<String> readManifests(ClassLoader classLoader, String resourcePath) {
|
||||
return new ManifestReader().read(classLoader, resourcePath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read all the specific manifest files and return the set of packages containing type query beans.
|
||||
*/
|
||||
private Set<String> read(ClassLoader classLoader, String resourcePath) {
|
||||
private Set<String> read(ClassLoader classLoader, String resourcePath) {
|
||||
|
||||
try {
|
||||
Enumeration<URL> resources = classLoader.getResources(resourcePath);
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
<HTML>
|
||||
<HEAD>
|
||||
<META HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; charset=iso-8859-1">
|
||||
<TITLE>Core implementation objects</TITLE>
|
||||
<META HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; charset=iso-8859-1">
|
||||
<TITLE>Core implementation objects</TITLE>
|
||||
</HEAD>
|
||||
<Body BGCOLOR="#ffffff">
|
||||
Core implementation objects
|
||||
|
||||
|
||||
</Body>
|
||||
</HTML>
|
||||
</HTML>
|
||||
|
||||
@@ -17,6 +17,6 @@ public class CloneDataTimeZone extends SimpleDataTimeZone {
|
||||
@Override
|
||||
public Calendar getTimeZone() {
|
||||
// return cloned copy for Oracle to muck around with
|
||||
return (Calendar)zone.clone();
|
||||
return (Calendar) zone.clone();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package com.avaje.ebeaninternal.server.el;
|
||||
|
||||
import com.avaje.ebean.Filter;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import com.avaje.ebean.Filter;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
|
||||
|
||||
/**
|
||||
* Default implementation of the Filter interface.
|
||||
*/
|
||||
|
||||
@@ -224,7 +224,7 @@ class ElMatchBuilder {
|
||||
public boolean isMatch(T value) {
|
||||
|
||||
return (comparator.compareValue(min, value) <= 0
|
||||
&& comparator.compareValue(max, value) >= 0);
|
||||
&& comparator.compareValue(max, value) >= 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user