mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
Remove unused ServerConfig debugSql options, Update Tests to use agentloader
This commit is contained in:
@@ -90,7 +90,14 @@
|
||||
<version>1.1.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.avaje.ebeanorm</groupId>
|
||||
<artifactId>avaje-ebeanorm-agent</artifactId>
|
||||
<version>3.2.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.h2database</groupId>
|
||||
<artifactId>h2</artifactId>
|
||||
|
||||
@@ -139,10 +139,6 @@ public class ServerConfig {
|
||||
|
||||
private boolean ddlRun;
|
||||
|
||||
private boolean debugSql;
|
||||
|
||||
private boolean debugLazyLoad;
|
||||
|
||||
private boolean useJtaTransactionManager;
|
||||
|
||||
/**
|
||||
@@ -150,17 +146,6 @@ public class ServerConfig {
|
||||
*/
|
||||
private ExternalTransactionManager externalTransactionManager;
|
||||
|
||||
/**
|
||||
* Set to true to log using java.util.logging and otherwise uses ebean
|
||||
* transaction loggers.
|
||||
*/
|
||||
private boolean loggingToJavaLogger;
|
||||
|
||||
/**
|
||||
* The directory transaction logs go (when loggingToJavaLogger is false).
|
||||
*/
|
||||
private String loggingDirectory = "logs";
|
||||
|
||||
/**
|
||||
* Used to unwrap PreparedStatements to perform JDBC Driver specific functions
|
||||
*/
|
||||
@@ -774,119 +759,6 @@ public class ServerConfig {
|
||||
this.dbEncrypt = dbEncrypt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true to get the generated SQL queries output to the console.
|
||||
* <p>
|
||||
* To get the SQL and bind variables for insert update delete statements you
|
||||
* should use transaction logging.
|
||||
* </p>
|
||||
*/
|
||||
public boolean isDebugSql() {
|
||||
return debugSql;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set to true to get the generated SQL queries output to the console.
|
||||
* <p>
|
||||
* To get the SQL and bind variables for insert update delete statements you
|
||||
* should use transaction logging.
|
||||
* </p>
|
||||
*/
|
||||
public void setDebugSql(boolean debugSql) {
|
||||
this.debugSql = debugSql;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if there is debug logging on lazy loading events.
|
||||
*/
|
||||
public boolean isDebugLazyLoad() {
|
||||
return debugLazyLoad;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set to true to get debug logging on lazy loading events.
|
||||
*/
|
||||
public void setDebugLazyLoad(boolean debugLazyLoad) {
|
||||
this.debugLazyLoad = debugLazyLoad;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the directory where transaction logs go.
|
||||
*/
|
||||
public String getLoggingDirectory() {
|
||||
return loggingDirectory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the transaction log directory substituting any expressions such as
|
||||
* ${catalina.base} etc.
|
||||
*/
|
||||
public String getLoggingDirectoryWithEval() {
|
||||
return GlobalProperties.evaluateExpressions(loggingDirectory);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the directory that the transaction logs go in.
|
||||
* <p>
|
||||
* This will not be used if the transaction logging is going to java util
|
||||
* logging (via {@link #setLoggingToJavaLogger(boolean)}).
|
||||
* </p>
|
||||
* <p>
|
||||
* This can contain expressions like ${catalina.base} with environment
|
||||
* variables, java system properties and entries in ebean.properties.
|
||||
* </p>
|
||||
* <p>
|
||||
* e.g. ${catalina.base}/logs/trans
|
||||
* </p>
|
||||
*
|
||||
* @param loggingDirectory
|
||||
* the transaction log directory
|
||||
*/
|
||||
public void setLoggingDirectory(String loggingDirectory) {
|
||||
this.loggingDirectory = loggingDirectory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if you want to use a java.util.logging.Logger to log
|
||||
* transaction statements, bind values etc.
|
||||
* <p>
|
||||
* If this is false then the default transaction logger is used which logs the
|
||||
* transaction details to separate transaction log files.
|
||||
* </p>
|
||||
*/
|
||||
@Deprecated
|
||||
public boolean isLoggingToJavaLogger() {
|
||||
return loggingToJavaLogger;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set this to true if you want transaction logging to use a
|
||||
* java.util.logging.Logger to log the statements and bind variables etc
|
||||
* rather than the default one which creates separate transaction log files.
|
||||
*/
|
||||
@Deprecated
|
||||
public void setLoggingToJavaLogger(boolean transactionLogToJavaLogger) {
|
||||
this.loggingToJavaLogger = transactionLogToJavaLogger;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deprecated - please use isTransactionLogToJavaLogger();
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
public boolean isUseJuliTransactionLogger() {
|
||||
return isLoggingToJavaLogger();
|
||||
}
|
||||
|
||||
/**
|
||||
* Deprecated - please use setTransactionLogToJavaLogger();
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
public void setUseJuliTransactionLogger(boolean transactionLogToJavaLogger) {
|
||||
setLoggingToJavaLogger(transactionLogToJavaLogger);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set to true to run the DDL generation on startup.
|
||||
*/
|
||||
@@ -1330,15 +1202,6 @@ public class ServerConfig {
|
||||
|
||||
ddlGenerate = p.getBoolean("ddl.generate", false);
|
||||
ddlRun = p.getBoolean("ddl.run", false);
|
||||
debugSql = p.getBoolean("debug.sql", false);
|
||||
debugLazyLoad = p.getBoolean("debug.lazyload", false);
|
||||
|
||||
String s = p.get("useJuliTransactionLogger", null);
|
||||
s = p.get("loggingToJavaLogger", s);
|
||||
loggingToJavaLogger = "true".equalsIgnoreCase(s);
|
||||
|
||||
s = p.get("log.directory", "logs");
|
||||
loggingDirectory = p.get("logging.directory", s);
|
||||
|
||||
classes = getClasses(p);
|
||||
}
|
||||
|
||||
@@ -1,111 +0,0 @@
|
||||
package com.avaje.ebeaninternal.server.core;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.avaje.ebean.config.GlobalProperties;
|
||||
|
||||
/**
|
||||
* Helper used in producing debug output on lazy loading.
|
||||
*/
|
||||
public class DebugLazyLoad {
|
||||
|
||||
private final String[] ignoreList;
|
||||
|
||||
private final boolean debug;
|
||||
|
||||
public DebugLazyLoad(boolean lazyLoadDebug) {
|
||||
ignoreList = buildLazyLoadIgnoreList();
|
||||
debug = lazyLoadDebug;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if debugging is on.
|
||||
*/
|
||||
public boolean isDebug() {
|
||||
return debug;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the StackTraceElement that is believed to be the line of code that
|
||||
* triggered the lazy loading.
|
||||
* <p>
|
||||
* This is determined by going up the stack trace ignoring all the sections
|
||||
* of java and Ebean code etc until you find code not in the ignore list -
|
||||
* this is assumed to be your application code that triggered the lazy
|
||||
* loading (it could be a third party layer such as a web template).
|
||||
* </p>
|
||||
*/
|
||||
public StackTraceElement getStackTraceElement(Class<?> beanType) {
|
||||
|
||||
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
|
||||
for (int i = 0; i < stackTrace.length; i++) {
|
||||
if (isStackLine(stackTrace[i], beanType)) {
|
||||
return stackTrace[i];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the code is expected to be application code.
|
||||
*/
|
||||
private boolean isStackLine(StackTraceElement element, Class<?> beanType) {
|
||||
|
||||
String stackClass = element.getClassName();
|
||||
|
||||
if (isBeanClass(beanType, stackClass)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = 0; i < ignoreList.length; i++) {
|
||||
if (stackClass.startsWith(ignoreList[i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Recurse up the inheritance checking to see if the stackClass is
|
||||
* this beanType (or a parent type).
|
||||
*/
|
||||
private boolean isBeanClass(Class<?> beanType, String stackClass) {
|
||||
if (stackClass.startsWith(beanType.getName())) {
|
||||
return true;
|
||||
}
|
||||
Class<?> superCls = beanType.getSuperclass();
|
||||
if (superCls.equals(Object.class)){
|
||||
return false;
|
||||
} else {
|
||||
return isBeanClass(superCls, stackClass);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Build list of prefixes used to find the application code that triggered
|
||||
* the lazy loading.
|
||||
*/
|
||||
private String[] buildLazyLoadIgnoreList() {
|
||||
|
||||
List<String> ignore = new ArrayList<String>();
|
||||
|
||||
// code that should be ignored when searching
|
||||
// the stack trace elements
|
||||
ignore.add("com.avaje.ebean");
|
||||
ignore.add("java");
|
||||
ignore.add("sun.reflect");
|
||||
ignore.add("org.codehaus.groovy.runtime.");
|
||||
|
||||
String extraIgnore = GlobalProperties.get("debug.lazyload.ignore", null);
|
||||
if (extraIgnore != null) {
|
||||
String[] split = extraIgnore.split(",");
|
||||
for (int i = 0; i < split.length; i++) {
|
||||
ignore.add(split[i].trim());
|
||||
}
|
||||
}
|
||||
|
||||
return ignore.toArray(new String[ignore.size()]);
|
||||
}
|
||||
}
|
||||
@@ -69,8 +69,6 @@ public class InternalConfiguration {
|
||||
|
||||
private final BeanDescriptorManager beanDescriptorManager;
|
||||
|
||||
private final DebugLazyLoad debugLazyLoad;
|
||||
|
||||
private final TransactionManager transactionManager;
|
||||
|
||||
private final TransactionScopeManager transactionScopeManager;
|
||||
@@ -115,23 +113,18 @@ public class InternalConfiguration {
|
||||
this.beanDescriptorManager = new BeanDescriptorManager(this);
|
||||
beanDescriptorManager.deploy();
|
||||
|
||||
this.debugLazyLoad = new DebugLazyLoad(serverConfig.isDebugLazyLoad());
|
||||
|
||||
this.transactionManager = new TransactionManager(clusterManager, backgroundExecutor,
|
||||
serverConfig, beanDescriptorManager, this.getBootupClasses());
|
||||
|
||||
this.cQueryEngine = new CQueryEngine(serverConfig.getDatabasePlatform(), binder,
|
||||
backgroundExecutor);
|
||||
this.cQueryEngine = new CQueryEngine(serverConfig.getDatabasePlatform(), binder, backgroundExecutor);
|
||||
|
||||
ExternalTransactionManager externalTransactionManager = serverConfig
|
||||
.getExternalTransactionManager();
|
||||
ExternalTransactionManager externalTransactionManager = serverConfig.getExternalTransactionManager();
|
||||
if (externalTransactionManager == null && serverConfig.isUseJtaTransactionManager()) {
|
||||
externalTransactionManager = new JtaTransactionManager();
|
||||
}
|
||||
if (externalTransactionManager != null) {
|
||||
externalTransactionManager.setTransactionManager(transactionManager);
|
||||
this.transactionScopeManager = new ExternalTransactionScopeManager(transactionManager,
|
||||
externalTransactionManager);
|
||||
this.transactionScopeManager = new ExternalTransactionScopeManager(transactionManager, externalTransactionManager);
|
||||
logger.info("Using Transaction Manager [" + externalTransactionManager.getClass() + "]");
|
||||
} else {
|
||||
this.transactionScopeManager = new DefaultTransactionScopeManager(transactionManager);
|
||||
@@ -170,7 +163,6 @@ public class InternalConfiguration {
|
||||
}
|
||||
|
||||
public Persister createPersister(SpiEbeanServer server) {
|
||||
|
||||
return new DefaultPersister(server, binder, beanDescriptorManager, pstmtBatch);
|
||||
}
|
||||
|
||||
@@ -246,10 +238,6 @@ public class InternalConfiguration {
|
||||
return clusterManager;
|
||||
}
|
||||
|
||||
public DebugLazyLoad getDebugLazyLoad() {
|
||||
return debugLazyLoad;
|
||||
}
|
||||
|
||||
public SpiBackgroundExecutor getBackgroundExecutor() {
|
||||
return backgroundExecutor;
|
||||
}
|
||||
|
||||
@@ -1,13 +1,18 @@
|
||||
package com.avaje.ebean;
|
||||
|
||||
import org.avaje.agentloader.AgentLoader;
|
||||
import org.junit.BeforeClass;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class BaseTestCase extends TestCase {
|
||||
public class BaseTestCase {
|
||||
|
||||
static {
|
||||
AgentLoader.loadAgentFromClasspath("avaje-ebeanorm-agent","debug=1");
|
||||
protected static Logger logger = LoggerFactory.getLogger(BaseTestCase.class);
|
||||
|
||||
@BeforeClass
|
||||
public static void preStart() {
|
||||
logger.debug("... preStart");
|
||||
AgentLoader.loadAgentFromClasspath("avaje-ebeanorm-agent","debug=0");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,87 +1,96 @@
|
||||
package com.avaje.ebean;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.RawSql.Sql;
|
||||
|
||||
public class TestRawSqlBuilder extends BaseTestCase {
|
||||
|
||||
public void testSimple() {
|
||||
|
||||
RawSqlBuilder r = RawSqlBuilder.parse("select id from t_cust");
|
||||
Sql sql = r.getSql();
|
||||
Assert.assertEquals("id", sql.getPreFrom());
|
||||
Assert.assertEquals("from t_cust", sql.getPreWhere());
|
||||
Assert.assertEquals("", sql.getPreHaving());
|
||||
Assert.assertNull(sql.getOrderBy());
|
||||
|
||||
}
|
||||
|
||||
public void testWithWhere() {
|
||||
|
||||
RawSqlBuilder r = RawSqlBuilder.parse("select id from t_cust where id > ?");
|
||||
Sql sql = r.getSql();
|
||||
Assert.assertEquals("id", sql.getPreFrom());
|
||||
Assert.assertEquals("from t_cust where id > ?", sql.getPreWhere());
|
||||
Assert.assertEquals("", sql.getPreHaving());
|
||||
Assert.assertNull(sql.getOrderBy());
|
||||
}
|
||||
|
||||
public void testWithOrder() {
|
||||
|
||||
RawSqlBuilder r = RawSqlBuilder.parse("select id from t_cust where id > ? order by id desc");
|
||||
Sql sql = r.getSql();
|
||||
Assert.assertEquals("id", sql.getPreFrom());
|
||||
Assert.assertEquals("from t_cust where id > ?", sql.getPreWhere());
|
||||
Assert.assertEquals("", sql.getPreHaving());
|
||||
Assert.assertEquals("id desc", sql.getOrderBy());
|
||||
|
||||
r = RawSqlBuilder.parse("select id from t_cust order by id desc");
|
||||
sql = r.getSql();
|
||||
Assert.assertEquals("id", sql.getPreFrom());
|
||||
Assert.assertEquals("from t_cust", sql.getPreWhere());
|
||||
Assert.assertEquals("", sql.getPreHaving());
|
||||
Assert.assertEquals("id desc", sql.getOrderBy());
|
||||
|
||||
r = RawSqlBuilder.parse("select id, sum(x) from t_cust where id > ? group by id order by id desc");
|
||||
sql = r.getSql();
|
||||
Assert.assertEquals("id, sum(x)", sql.getPreFrom());
|
||||
Assert.assertEquals("from t_cust where id > ?", sql.getPreWhere());
|
||||
Assert.assertEquals("group by id", sql.getPreHaving());
|
||||
Assert.assertEquals("id desc", sql.getOrderBy());
|
||||
}
|
||||
|
||||
public void testWithHaving() {
|
||||
|
||||
RawSqlBuilder r = RawSqlBuilder.parse("select id, sum(x) from t_cust where id > ? group by id having sum(x) > ? order by id desc");
|
||||
Sql sql = r.getSql();
|
||||
Assert.assertEquals("id, sum(x)", sql.getPreFrom());
|
||||
Assert.assertEquals("from t_cust where id > ?", sql.getPreWhere());
|
||||
Assert.assertEquals("group by id having sum(x) > ?", sql.getPreHaving());
|
||||
Assert.assertEquals("id desc", sql.getOrderBy());
|
||||
|
||||
// no where
|
||||
r = RawSqlBuilder.parse("select id, sum(x) from t_cust group by id having sum(x) > ? order by id desc");
|
||||
sql = r.getSql();
|
||||
Assert.assertEquals("id, sum(x)", sql.getPreFrom());
|
||||
Assert.assertEquals("from t_cust", sql.getPreWhere());
|
||||
Assert.assertEquals("group by id having sum(x) > ?", sql.getPreHaving());
|
||||
Assert.assertEquals("id desc", sql.getOrderBy());
|
||||
|
||||
// no where, no order by
|
||||
r = RawSqlBuilder.parse("select id, sum(x) from t_cust group by id having sum(x) > ?");
|
||||
sql = r.getSql();
|
||||
Assert.assertEquals("id, sum(x)", sql.getPreFrom());
|
||||
Assert.assertEquals("from t_cust", sql.getPreWhere());
|
||||
Assert.assertEquals("group by id having sum(x) > ?", sql.getPreHaving());
|
||||
Assert.assertNull(sql.getOrderBy());
|
||||
|
||||
// no order by
|
||||
r = RawSqlBuilder.parse("select id, sum(x) from t_cust where id > ? group by id having sum(x) > ?");
|
||||
sql = r.getSql();
|
||||
Assert.assertEquals("id, sum(x)", sql.getPreFrom());
|
||||
Assert.assertEquals("from t_cust where id > ?", sql.getPreWhere());
|
||||
Assert.assertEquals("group by id having sum(x) > ?", sql.getPreHaving());
|
||||
Assert.assertNull(sql.getOrderBy());
|
||||
}
|
||||
@Test
|
||||
public void testSimple() {
|
||||
|
||||
RawSqlBuilder r = RawSqlBuilder.parse("select id from t_cust");
|
||||
Sql sql = r.getSql();
|
||||
Assert.assertEquals("id", sql.getPreFrom());
|
||||
Assert.assertEquals("from t_cust", sql.getPreWhere());
|
||||
Assert.assertEquals("", sql.getPreHaving());
|
||||
Assert.assertNull(sql.getOrderBy());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithWhere() {
|
||||
|
||||
RawSqlBuilder r = RawSqlBuilder.parse("select id from t_cust where id > ?");
|
||||
Sql sql = r.getSql();
|
||||
Assert.assertEquals("id", sql.getPreFrom());
|
||||
Assert.assertEquals("from t_cust where id > ?", sql.getPreWhere());
|
||||
Assert.assertEquals("", sql.getPreHaving());
|
||||
Assert.assertNull(sql.getOrderBy());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithOrder() {
|
||||
|
||||
RawSqlBuilder r = RawSqlBuilder.parse("select id from t_cust where id > ? order by id desc");
|
||||
Sql sql = r.getSql();
|
||||
Assert.assertEquals("id", sql.getPreFrom());
|
||||
Assert.assertEquals("from t_cust where id > ?", sql.getPreWhere());
|
||||
Assert.assertEquals("", sql.getPreHaving());
|
||||
Assert.assertEquals("id desc", sql.getOrderBy());
|
||||
|
||||
r = RawSqlBuilder.parse("select id from t_cust order by id desc");
|
||||
sql = r.getSql();
|
||||
Assert.assertEquals("id", sql.getPreFrom());
|
||||
Assert.assertEquals("from t_cust", sql.getPreWhere());
|
||||
Assert.assertEquals("", sql.getPreHaving());
|
||||
Assert.assertEquals("id desc", sql.getOrderBy());
|
||||
|
||||
r = RawSqlBuilder
|
||||
.parse("select id, sum(x) from t_cust where id > ? group by id order by id desc");
|
||||
sql = r.getSql();
|
||||
Assert.assertEquals("id, sum(x)", sql.getPreFrom());
|
||||
Assert.assertEquals("from t_cust where id > ?", sql.getPreWhere());
|
||||
Assert.assertEquals("group by id", sql.getPreHaving());
|
||||
Assert.assertEquals("id desc", sql.getOrderBy());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithHaving() {
|
||||
|
||||
RawSqlBuilder r = RawSqlBuilder
|
||||
.parse("select id, sum(x) from t_cust where id > ? group by id having sum(x) > ? order by id desc");
|
||||
Sql sql = r.getSql();
|
||||
Assert.assertEquals("id, sum(x)", sql.getPreFrom());
|
||||
Assert.assertEquals("from t_cust where id > ?", sql.getPreWhere());
|
||||
Assert.assertEquals("group by id having sum(x) > ?", sql.getPreHaving());
|
||||
Assert.assertEquals("id desc", sql.getOrderBy());
|
||||
|
||||
// no where
|
||||
r = RawSqlBuilder
|
||||
.parse("select id, sum(x) from t_cust group by id having sum(x) > ? order by id desc");
|
||||
sql = r.getSql();
|
||||
Assert.assertEquals("id, sum(x)", sql.getPreFrom());
|
||||
Assert.assertEquals("from t_cust", sql.getPreWhere());
|
||||
Assert.assertEquals("group by id having sum(x) > ?", sql.getPreHaving());
|
||||
Assert.assertEquals("id desc", sql.getOrderBy());
|
||||
|
||||
// no where, no order by
|
||||
r = RawSqlBuilder.parse("select id, sum(x) from t_cust group by id having sum(x) > ?");
|
||||
sql = r.getSql();
|
||||
Assert.assertEquals("id, sum(x)", sql.getPreFrom());
|
||||
Assert.assertEquals("from t_cust", sql.getPreWhere());
|
||||
Assert.assertEquals("group by id having sum(x) > ?", sql.getPreHaving());
|
||||
Assert.assertNull(sql.getOrderBy());
|
||||
|
||||
// no order by
|
||||
r = RawSqlBuilder
|
||||
.parse("select id, sum(x) from t_cust where id > ? group by id having sum(x) > ?");
|
||||
sql = r.getSql();
|
||||
Assert.assertEquals("id, sum(x)", sql.getPreFrom());
|
||||
Assert.assertEquals("from t_cust where id > ?", sql.getPreWhere());
|
||||
Assert.assertEquals("group by id having sum(x) > ?", sql.getPreHaving());
|
||||
Assert.assertNull(sql.getOrderBy());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,10 +2,10 @@ package com.avaje.ebean.server.type;
|
||||
|
||||
import java.sql.Types;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.config.ServerConfig;
|
||||
import com.avaje.ebean.config.dbplatform.H2Platform;
|
||||
import com.avaje.ebeaninternal.server.core.BootupClasses;
|
||||
@@ -18,35 +18,36 @@ import com.avaje.tests.model.ivo.CMoney;
|
||||
import com.avaje.tests.model.ivo.ExhangeCMoneyRate;
|
||||
import com.avaje.tests.model.ivo.Money;
|
||||
|
||||
public class TestTypeManager extends TestCase {
|
||||
public class TestTypeManager extends BaseTestCase {
|
||||
|
||||
public void test() {
|
||||
|
||||
ServerConfig serverConfig = new ServerConfig();
|
||||
serverConfig.setDatabasePlatform(new H2Platform());
|
||||
|
||||
BootupClasses bootupClasses = new BootupClasses();
|
||||
|
||||
DefaultTypeManager typeManager = new DefaultTypeManager(serverConfig, bootupClasses);
|
||||
|
||||
CheckImmutableResponse checkImmutable = typeManager.checkImmutable(Money.class);
|
||||
Assert.assertTrue(checkImmutable.isImmutable());
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
checkImmutable = typeManager.checkImmutable(CMoney.class);
|
||||
Assert.assertTrue(checkImmutable.isImmutable());
|
||||
ServerConfig serverConfig = new ServerConfig();
|
||||
serverConfig.setDatabasePlatform(new H2Platform());
|
||||
|
||||
ScalarDataReader<?> dataReader = typeManager.recursiveCreateScalarDataReader(ExhangeCMoneyRate.class);
|
||||
Assert.assertTrue(dataReader instanceof CtCompoundType<?>);
|
||||
BootupClasses bootupClasses = new BootupClasses();
|
||||
|
||||
dataReader = typeManager.recursiveCreateScalarDataReader(CMoney.class);
|
||||
Assert.assertTrue(dataReader instanceof CtCompoundType<?>);
|
||||
DefaultTypeManager typeManager = new DefaultTypeManager(serverConfig, bootupClasses);
|
||||
|
||||
CheckImmutableResponse checkImmutable = typeManager.checkImmutable(Money.class);
|
||||
Assert.assertTrue(checkImmutable.isImmutable());
|
||||
|
||||
checkImmutable = typeManager.checkImmutable(CMoney.class);
|
||||
Assert.assertTrue(checkImmutable.isImmutable());
|
||||
|
||||
ScalarDataReader<?> dataReader = typeManager
|
||||
.recursiveCreateScalarDataReader(ExhangeCMoneyRate.class);
|
||||
Assert.assertTrue(dataReader instanceof CtCompoundType<?>);
|
||||
|
||||
dataReader = typeManager.recursiveCreateScalarDataReader(CMoney.class);
|
||||
Assert.assertTrue(dataReader instanceof CtCompoundType<?>);
|
||||
|
||||
ScalarType<?> scalarType = typeManager.recursiveCreateScalarTypes(Money.class);
|
||||
Assert.assertTrue(scalarType.getJdbcType() == Types.DECIMAL);
|
||||
Assert.assertTrue(!scalarType.isJdbcNative());
|
||||
Assert.assertEquals(Money.class, scalarType.getType());
|
||||
|
||||
}
|
||||
|
||||
ScalarType<?> scalarType = typeManager.recursiveCreateScalarTypes(Money.class);
|
||||
Assert.assertTrue(scalarType.getJdbcType() == Types.DECIMAL);
|
||||
Assert.assertTrue(!scalarType.isJdbcNative());
|
||||
Assert.assertEquals(Money.class, scalarType.getType());
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,28 +1,31 @@
|
||||
package com.avaje.ebean.text;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class TestPathPropertiesParse extends TestCase {
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
|
||||
public void test() {
|
||||
|
||||
PathProperties s0 = PathProperties.parse("(id,name)");
|
||||
public class TestPathPropertiesParse extends BaseTestCase {
|
||||
|
||||
assertEquals(1,s0.getPaths().size());
|
||||
assertTrue(s0.get(null).contains("id"));
|
||||
assertTrue(s0.get(null).contains("name"));
|
||||
assertFalse(s0.get(null).contains("status"));
|
||||
|
||||
PathProperties s1 = PathProperties.parse(":(id,name,shipAddr(*))");
|
||||
assertEquals(2,s1.getPaths().size());
|
||||
assertEquals(3,s1.get(null).size());
|
||||
assertTrue(s1.get(null).contains("id"));
|
||||
assertTrue(s1.get(null).contains("name"));
|
||||
assertTrue(s1.get(null).contains("shipAddr"));
|
||||
assertTrue(s1.get("shipAddr").contains("*"));
|
||||
assertEquals(1,s1.get("shipAddr").size());
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
PathProperties s0 = PathProperties.parse("(id,name)");
|
||||
|
||||
Assert.assertEquals(1, s0.getPaths().size());
|
||||
Assert.assertTrue(s0.get(null).contains("id"));
|
||||
Assert.assertTrue(s0.get(null).contains("name"));
|
||||
Assert.assertFalse(s0.get(null).contains("status"));
|
||||
|
||||
PathProperties s1 = PathProperties.parse(":(id,name,shipAddr(*))");
|
||||
Assert.assertEquals(2, s1.getPaths().size());
|
||||
Assert.assertEquals(3, s1.get(null).size());
|
||||
Assert.assertTrue(s1.get(null).contains("id"));
|
||||
Assert.assertTrue(s1.get(null).contains("name"));
|
||||
Assert.assertTrue(s1.get(null).contains("shipAddr"));
|
||||
Assert.assertTrue(s1.get("shipAddr").contains("*"));
|
||||
Assert.assertEquals(1, s1.get("shipAddr").size());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+45
-44
@@ -2,57 +2,58 @@ package com.avaje.ebeaninternal.server.cluster.mcast;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebeaninternal.server.cluster.mcast.IncomingPacketsProcessed.GotAllPoint;
|
||||
|
||||
public class TestMcastMemberPackets extends TestCase {
|
||||
public class TestMcastMemberPackets extends BaseTestCase {
|
||||
|
||||
public void test() {
|
||||
|
||||
GotAllPoint member = new GotAllPoint("129.12.23.12:9089",3);
|
||||
|
||||
assertTrue(member.processPacket(1234));
|
||||
assertTrue(member.processPacket(1235));
|
||||
assertTrue(member.processPacket(1236));
|
||||
|
||||
assertEquals(1236l, member.getGotAllPoint());
|
||||
assertEquals(0, member.getMissingPackets().size());
|
||||
|
||||
assertFalse(member.processPacket(1234));
|
||||
|
||||
assertTrue(member.processPacket(1239));
|
||||
List<Long> missingPackets = member.getMissingPackets();
|
||||
assertEquals(2, missingPackets.size());
|
||||
|
||||
assertTrue(missingPackets.contains(1237l));
|
||||
assertTrue(missingPackets.contains(1238l));
|
||||
assertFalse(missingPackets.contains(1239l));
|
||||
assertFalse(missingPackets.contains(1236l));
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
missingPackets = member.getMissingPackets();
|
||||
assertEquals(2, missingPackets.size());
|
||||
assertTrue(missingPackets.contains(1237l));
|
||||
assertTrue(missingPackets.contains(1238l));
|
||||
GotAllPoint member = new GotAllPoint("129.12.23.12:9089", 3);
|
||||
|
||||
assertEquals(1236l, member.getGotAllPoint());
|
||||
|
||||
// get a missing packet
|
||||
assertTrue(member.processPacket(1237));
|
||||
assertEquals(1237l, member.getGotAllPoint());
|
||||
|
||||
missingPackets = member.getMissingPackets();
|
||||
assertEquals(1, missingPackets.size());
|
||||
assertTrue(missingPackets.contains(1238l));
|
||||
Assert.assertTrue(member.processPacket(1234));
|
||||
Assert.assertTrue(member.processPacket(1235));
|
||||
Assert.assertTrue(member.processPacket(1236));
|
||||
|
||||
Assert.assertEquals(1236l, member.getGotAllPoint());
|
||||
Assert.assertEquals(0, member.getMissingPackets().size());
|
||||
|
||||
// but we now hit maxResendIncoming
|
||||
missingPackets = member.getMissingPackets();
|
||||
assertEquals(0, missingPackets.size());
|
||||
// gave up on 1238 ..
|
||||
assertEquals(1239l, member.getGotAllPoint());
|
||||
Assert.assertFalse(member.processPacket(1234));
|
||||
|
||||
Assert.assertTrue(member.processPacket(1239));
|
||||
List<Long> missingPackets = member.getMissingPackets();
|
||||
Assert.assertEquals(2, missingPackets.size());
|
||||
|
||||
Assert.assertTrue(missingPackets.contains(1237l));
|
||||
Assert.assertTrue(missingPackets.contains(1238l));
|
||||
Assert.assertFalse(missingPackets.contains(1239l));
|
||||
Assert.assertFalse(missingPackets.contains(1236l));
|
||||
|
||||
missingPackets = member.getMissingPackets();
|
||||
Assert.assertEquals(2, missingPackets.size());
|
||||
Assert.assertTrue(missingPackets.contains(1237l));
|
||||
Assert.assertTrue(missingPackets.contains(1238l));
|
||||
|
||||
Assert.assertEquals(1236l, member.getGotAllPoint());
|
||||
|
||||
// get a missing packet
|
||||
Assert.assertTrue(member.processPacket(1237));
|
||||
Assert.assertEquals(1237l, member.getGotAllPoint());
|
||||
|
||||
missingPackets = member.getMissingPackets();
|
||||
Assert.assertEquals(1, missingPackets.size());
|
||||
Assert.assertTrue(missingPackets.contains(1238l));
|
||||
|
||||
// but we now hit maxResendIncoming
|
||||
missingPackets = member.getMissingPackets();
|
||||
Assert.assertEquals(0, missingPackets.size());
|
||||
// gave up on 1238 ..
|
||||
Assert.assertEquals(1239l, member.getGotAllPoint());
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,28 +1,32 @@
|
||||
package com.avaje.ebeaninternal.server.cluster.mcast;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class TestPacketsAcked extends TestCase {
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
|
||||
public void test() {
|
||||
|
||||
OutgoingPacketsAcked packetsAcked = new OutgoingPacketsAcked();
|
||||
|
||||
assertEquals(0l,packetsAcked.getMinimumGotAllPacketId());
|
||||
|
||||
long receivedAck = packetsAcked.receivedAck("A", new MessageAck("A", 1020l));
|
||||
assertEquals(1020l,packetsAcked.getMinimumGotAllPacketId());
|
||||
assertEquals(1020l,receivedAck);
|
||||
public class TestPacketsAcked extends BaseTestCase {
|
||||
|
||||
receivedAck = packetsAcked.receivedAck("B", new MessageAck("B", 1030l));
|
||||
assertEquals(1020l,packetsAcked.getMinimumGotAllPacketId());
|
||||
assertEquals(0l,receivedAck);
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
receivedAck = packetsAcked.receivedAck("C", new MessageAck("C", 1025l));
|
||||
assertEquals(0l,receivedAck);
|
||||
|
||||
receivedAck = packetsAcked.receivedAck("A", new MessageAck("A", 1040l));
|
||||
assertEquals(1025l,receivedAck);
|
||||
OutgoingPacketsAcked packetsAcked = new OutgoingPacketsAcked();
|
||||
|
||||
}
|
||||
Assert.assertEquals(0l, packetsAcked.getMinimumGotAllPacketId());
|
||||
|
||||
long receivedAck = packetsAcked.receivedAck("A", new MessageAck("A", 1020l));
|
||||
Assert.assertEquals(1020l, packetsAcked.getMinimumGotAllPacketId());
|
||||
Assert.assertEquals(1020l, receivedAck);
|
||||
|
||||
receivedAck = packetsAcked.receivedAck("B", new MessageAck("B", 1030l));
|
||||
Assert.assertEquals(1020l, packetsAcked.getMinimumGotAllPacketId());
|
||||
Assert.assertEquals(0l, receivedAck);
|
||||
|
||||
receivedAck = packetsAcked.receivedAck("C", new MessageAck("C", 1025l));
|
||||
Assert.assertEquals(0l, receivedAck);
|
||||
|
||||
receivedAck = packetsAcked.receivedAck("A", new MessageAck("A", 1040l));
|
||||
Assert.assertEquals(1025l, receivedAck);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,88 +1,88 @@
|
||||
package com.avaje.ebeaninternal.server.lib.sql;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class TestBusyBuffer extends TestCase {
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
|
||||
public void test() {
|
||||
|
||||
BusyConnectionBuffer b = new BusyConnectionBuffer(2,4);
|
||||
|
||||
PooledConnection p0 = new PooledConnection("0");
|
||||
PooledConnection p1 = new PooledConnection("1");
|
||||
PooledConnection p2 = new PooledConnection("2");
|
||||
PooledConnection p3 = new PooledConnection("3");
|
||||
|
||||
Assert.assertEquals(2, b.getCapacity());
|
||||
b.add(p0);
|
||||
b.add(p1);
|
||||
Assert.assertEquals(2, b.getCapacity());
|
||||
b.add(p2);
|
||||
Assert.assertEquals(6, b.getCapacity());
|
||||
b.add(p3);
|
||||
|
||||
Assert.assertEquals(0, p0.getSlotId());
|
||||
Assert.assertEquals(1, p1.getSlotId());
|
||||
Assert.assertEquals(2, p2.getSlotId());
|
||||
Assert.assertEquals(3, p3.getSlotId());
|
||||
public class TestBusyBuffer extends BaseTestCase {
|
||||
|
||||
b.remove(p2);
|
||||
b.add(p2);
|
||||
Assert.assertEquals(4, p2.getSlotId());
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
b.remove(p0);
|
||||
b.add(p0);
|
||||
Assert.assertEquals(5, p0.getSlotId());
|
||||
BusyConnectionBuffer b = new BusyConnectionBuffer(2, 4);
|
||||
|
||||
b.remove(p2);
|
||||
b.add(p2);
|
||||
Assert.assertEquals(0, p2.getSlotId());
|
||||
PooledConnection p0 = new PooledConnection("0");
|
||||
PooledConnection p1 = new PooledConnection("1");
|
||||
PooledConnection p2 = new PooledConnection("2");
|
||||
PooledConnection p3 = new PooledConnection("3");
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void test_rotate() {
|
||||
|
||||
BusyConnectionBuffer b = new BusyConnectionBuffer(2,2);
|
||||
|
||||
PooledConnection p0 = new PooledConnection("0");
|
||||
PooledConnection p1 = new PooledConnection("1");
|
||||
PooledConnection p2 = new PooledConnection("2");
|
||||
PooledConnection p3 = new PooledConnection("3");
|
||||
Assert.assertEquals(2, b.getCapacity());
|
||||
b.add(p0);
|
||||
b.add(p1);
|
||||
Assert.assertEquals(2, b.getCapacity());
|
||||
b.add(p2);
|
||||
Assert.assertEquals(6, b.getCapacity());
|
||||
b.add(p3);
|
||||
|
||||
Assert.assertEquals(2, b.getCapacity());
|
||||
Assert.assertEquals(0, p0.getSlotId());
|
||||
Assert.assertEquals(1, p1.getSlotId());
|
||||
Assert.assertEquals(2, p2.getSlotId());
|
||||
Assert.assertEquals(3, p3.getSlotId());
|
||||
|
||||
b.add(p0);
|
||||
b.add(p1);
|
||||
Assert.assertEquals(2, b.getCapacity());
|
||||
b.add(p2);
|
||||
Assert.assertEquals(4, b.getCapacity());
|
||||
b.add(p3);
|
||||
Assert.assertEquals(4, b.getCapacity());
|
||||
b.remove(p2);
|
||||
b.add(p2);
|
||||
Assert.assertEquals(4, p2.getSlotId());
|
||||
|
||||
Assert.assertEquals(0, p0.getSlotId());
|
||||
Assert.assertEquals(1, p1.getSlotId());
|
||||
Assert.assertEquals(2, p2.getSlotId());
|
||||
Assert.assertEquals(3, p3.getSlotId());
|
||||
b.remove(p0);
|
||||
b.add(p0);
|
||||
Assert.assertEquals(5, p0.getSlotId());
|
||||
|
||||
|
||||
b.remove(p2);
|
||||
b.remove(p0);
|
||||
b.remove(p3);
|
||||
b.add(p2);
|
||||
Assert.assertEquals(0, p2.getSlotId());
|
||||
b.remove(p2);
|
||||
b.add(p2);
|
||||
Assert.assertEquals(0, p2.getSlotId());
|
||||
|
||||
b.remove(p0);
|
||||
b.add(p0);
|
||||
// p1 is still in it's slot
|
||||
Assert.assertEquals(2, p0.getSlotId());
|
||||
}
|
||||
|
||||
b.remove(p2);
|
||||
b.add(p2);
|
||||
Assert.assertEquals(3, p2.getSlotId());
|
||||
public void test_rotate() {
|
||||
|
||||
BusyConnectionBuffer b = new BusyConnectionBuffer(2, 2);
|
||||
|
||||
PooledConnection p0 = new PooledConnection("0");
|
||||
PooledConnection p1 = new PooledConnection("1");
|
||||
PooledConnection p2 = new PooledConnection("2");
|
||||
PooledConnection p3 = new PooledConnection("3");
|
||||
|
||||
Assert.assertEquals(2, b.getCapacity());
|
||||
|
||||
b.add(p0);
|
||||
b.add(p1);
|
||||
Assert.assertEquals(2, b.getCapacity());
|
||||
b.add(p2);
|
||||
Assert.assertEquals(4, b.getCapacity());
|
||||
b.add(p3);
|
||||
Assert.assertEquals(4, b.getCapacity());
|
||||
|
||||
Assert.assertEquals(0, p0.getSlotId());
|
||||
Assert.assertEquals(1, p1.getSlotId());
|
||||
Assert.assertEquals(2, p2.getSlotId());
|
||||
Assert.assertEquals(3, p3.getSlotId());
|
||||
|
||||
b.remove(p2);
|
||||
b.remove(p0);
|
||||
b.remove(p3);
|
||||
b.add(p2);
|
||||
Assert.assertEquals(0, p2.getSlotId());
|
||||
|
||||
b.remove(p0);
|
||||
b.add(p0);
|
||||
// p1 is still in it's slot
|
||||
Assert.assertEquals(2, p0.getSlotId());
|
||||
|
||||
b.remove(p2);
|
||||
b.add(p2);
|
||||
Assert.assertEquals(3, p2.getSlotId());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,84 +2,83 @@ package com.avaje.ebeaninternal.server.lib.sql;
|
||||
|
||||
import java.sql.Connection;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.config.DataSourceConfig;
|
||||
import com.avaje.ebeaninternal.server.core.DefaultBackgroundExecutor;
|
||||
import com.avaje.ebeaninternal.server.lib.sql.DataSourcePool.Status;
|
||||
|
||||
public class TestDataSourceMax extends TestCase {
|
||||
public class TestDataSourceMax extends BaseTestCase {
|
||||
|
||||
public void test() {
|
||||
|
||||
boolean runThisManuallyNow = true;
|
||||
|
||||
if (!runThisManuallyNow){
|
||||
return;
|
||||
}
|
||||
|
||||
String name = "h2";
|
||||
|
||||
DataSourceConfig dsConfig = new DataSourceConfig();
|
||||
dsConfig.loadSettings(name);
|
||||
dsConfig.setMinConnections(3);
|
||||
dsConfig.setMaxConnections(3);
|
||||
dsConfig.setWaitTimeoutMillis(30000);
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
DataSourcePool pool = new DataSourcePool(null, name, dsConfig);
|
||||
boolean runThisManuallyNow = true;
|
||||
|
||||
Assert.assertEquals(3, pool.getMaxSize());
|
||||
|
||||
DefaultBackgroundExecutor bg = new DefaultBackgroundExecutor(10, 2, 180, 30, "testDs");
|
||||
|
||||
try {
|
||||
for (int i = 0; i < 12; i++) {
|
||||
//Thread.sleep(10*i);
|
||||
bg.execute(new ConnRunner(pool, 100));
|
||||
}
|
||||
|
||||
System.out.println("main thread sleep ... "+pool.getStatus(false));
|
||||
|
||||
Thread.sleep(1000);
|
||||
Status status = pool.getStatus(false);
|
||||
System.out.println(status);
|
||||
|
||||
// this dumpOrder was for 3 vectors used in PooledConnectionQueue
|
||||
// that logged the order of wait, notify and obtain events
|
||||
// I have remove that code.
|
||||
|
||||
// String s = pool.dumpOrder();
|
||||
// System.err.println(s);
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
if (!runThisManuallyNow) {
|
||||
return;
|
||||
}
|
||||
|
||||
private static class ConnRunner implements Runnable {
|
||||
|
||||
final DataSourcePool pool;
|
||||
final long sleepMillis;
|
||||
|
||||
ConnRunner(DataSourcePool pool, long sleepMillis) {
|
||||
this.pool = pool;
|
||||
this.sleepMillis = sleepMillis;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
try {
|
||||
Connection connection = pool.getConnection();
|
||||
Thread.sleep(sleepMillis);
|
||||
connection.close();
|
||||
} catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
String name = "h2";
|
||||
|
||||
DataSourceConfig dsConfig = new DataSourceConfig();
|
||||
dsConfig.loadSettings(name);
|
||||
dsConfig.setMinConnections(3);
|
||||
dsConfig.setMaxConnections(3);
|
||||
dsConfig.setWaitTimeoutMillis(30000);
|
||||
|
||||
DataSourcePool pool = new DataSourcePool(null, name, dsConfig);
|
||||
|
||||
Assert.assertEquals(3, pool.getMaxSize());
|
||||
|
||||
DefaultBackgroundExecutor bg = new DefaultBackgroundExecutor(10, 2, 180, 30, "testDs");
|
||||
|
||||
try {
|
||||
for (int i = 0; i < 12; i++) {
|
||||
// Thread.sleep(10*i);
|
||||
bg.execute(new ConnRunner(pool, 100));
|
||||
}
|
||||
|
||||
System.out.println("main thread sleep ... " + pool.getStatus(false));
|
||||
|
||||
Thread.sleep(1000);
|
||||
Status status = pool.getStatus(false);
|
||||
System.out.println(status);
|
||||
|
||||
// this dumpOrder was for 3 vectors used in PooledConnectionQueue
|
||||
// that logged the order of wait, notify and obtain events
|
||||
// I have remove that code.
|
||||
|
||||
// String s = pool.dumpOrder();
|
||||
// System.err.println(s);
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static class ConnRunner implements Runnable {
|
||||
|
||||
final DataSourcePool pool;
|
||||
final long sleepMillis;
|
||||
|
||||
ConnRunner(DataSourcePool pool, long sleepMillis) {
|
||||
this.pool = pool;
|
||||
this.sleepMillis = sleepMillis;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
try {
|
||||
Connection connection = pool.getConnection();
|
||||
Thread.sleep(sleepMillis);
|
||||
connection.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,73 +1,75 @@
|
||||
package com.avaje.ebeaninternal.server.lib.sql;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class TestFreeBuffer extends TestCase {
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
|
||||
public void test() {
|
||||
|
||||
FreeConnectionBuffer b = new FreeConnectionBuffer(3);
|
||||
|
||||
PooledConnection p0 = new PooledConnection("0");
|
||||
PooledConnection p1 = new PooledConnection("1");
|
||||
PooledConnection p2 = new PooledConnection("2");
|
||||
//PooledConnection p3 = new PooledConnection("3");
|
||||
public class TestFreeBuffer extends BaseTestCase {
|
||||
|
||||
Assert.assertEquals(3, b.getCapacity());
|
||||
Assert.assertEquals(0, b.size());
|
||||
Assert.assertEquals(true, b.isEmpty());
|
||||
|
||||
b.add(p0);
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
Assert.assertEquals(1, b.size());
|
||||
Assert.assertEquals(false, b.isEmpty());
|
||||
FreeConnectionBuffer b = new FreeConnectionBuffer(3);
|
||||
|
||||
PooledConnection r0 = b.remove();
|
||||
Assert.assertTrue(p0 == r0);
|
||||
|
||||
Assert.assertEquals(0, b.size());
|
||||
Assert.assertEquals(true, b.isEmpty());
|
||||
PooledConnection p0 = new PooledConnection("0");
|
||||
PooledConnection p1 = new PooledConnection("1");
|
||||
PooledConnection p2 = new PooledConnection("2");
|
||||
// PooledConnection p3 = new PooledConnection("3");
|
||||
|
||||
b.add(p0);
|
||||
b.add(p1);
|
||||
b.add(p2);
|
||||
Assert.assertEquals(3, b.getCapacity());
|
||||
Assert.assertEquals(0, b.size());
|
||||
Assert.assertEquals(true, b.isEmpty());
|
||||
|
||||
Assert.assertEquals(3, b.size());
|
||||
b.add(p0);
|
||||
|
||||
PooledConnection r1 = b.remove();
|
||||
Assert.assertTrue(p0 == r1);
|
||||
PooledConnection r2 = b.remove();
|
||||
Assert.assertTrue(p1 == r2);
|
||||
Assert.assertEquals(1, b.size());
|
||||
Assert.assertEquals(false, b.isEmpty());
|
||||
|
||||
Assert.assertEquals(1, b.size());
|
||||
b.add(p0);
|
||||
Assert.assertEquals(2, b.size());
|
||||
PooledConnection r3 = b.remove();
|
||||
Assert.assertTrue(p2 == r3);
|
||||
Assert.assertEquals(1, b.size());
|
||||
PooledConnection r4 = b.remove();
|
||||
Assert.assertTrue(p0 == r4);
|
||||
Assert.assertEquals(0, b.size());
|
||||
PooledConnection r0 = b.remove();
|
||||
Assert.assertTrue(p0 == r0);
|
||||
|
||||
b.add(p2);
|
||||
b.add(p1);
|
||||
b.add(p0);
|
||||
Assert.assertEquals(0, b.size());
|
||||
Assert.assertEquals(true, b.isEmpty());
|
||||
|
||||
Assert.assertEquals(3, b.size());
|
||||
b.add(p0);
|
||||
b.add(p1);
|
||||
b.add(p2);
|
||||
|
||||
PooledConnection r5 = b.remove();
|
||||
Assert.assertTrue(p2 == r5);
|
||||
Assert.assertEquals(2, b.size());
|
||||
|
||||
PooledConnection r6 = b.remove();
|
||||
Assert.assertTrue(p1 == r6);
|
||||
Assert.assertEquals(1, b.size());
|
||||
|
||||
PooledConnection r7 = b.remove();
|
||||
Assert.assertTrue(p0 == r7);
|
||||
Assert.assertEquals(0, b.size());
|
||||
Assert.assertEquals(3, b.size());
|
||||
|
||||
}
|
||||
PooledConnection r1 = b.remove();
|
||||
Assert.assertTrue(p0 == r1);
|
||||
PooledConnection r2 = b.remove();
|
||||
Assert.assertTrue(p1 == r2);
|
||||
|
||||
Assert.assertEquals(1, b.size());
|
||||
b.add(p0);
|
||||
Assert.assertEquals(2, b.size());
|
||||
PooledConnection r3 = b.remove();
|
||||
Assert.assertTrue(p2 == r3);
|
||||
Assert.assertEquals(1, b.size());
|
||||
PooledConnection r4 = b.remove();
|
||||
Assert.assertTrue(p0 == r4);
|
||||
Assert.assertEquals(0, b.size());
|
||||
|
||||
b.add(p2);
|
||||
b.add(p1);
|
||||
b.add(p0);
|
||||
|
||||
Assert.assertEquals(3, b.size());
|
||||
|
||||
PooledConnection r5 = b.remove();
|
||||
Assert.assertTrue(p2 == r5);
|
||||
Assert.assertEquals(2, b.size());
|
||||
|
||||
PooledConnection r6 = b.remove();
|
||||
Assert.assertTrue(p1 == r6);
|
||||
Assert.assertEquals(1, b.size());
|
||||
|
||||
PooledConnection r7 = b.remove();
|
||||
Assert.assertTrue(p0 == r7);
|
||||
Assert.assertEquals(0, b.size());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,78 +2,79 @@ package com.avaje.ebeaninternal.server.loadcontext;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class TestDLoadWeakList extends TestCase {
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
|
||||
|
||||
public void test() {
|
||||
|
||||
String s0 = new String("zero");
|
||||
String s1 = new String("one");
|
||||
String s2 = new String("two");
|
||||
String s3 = new String("three");
|
||||
String s4 = new String("four");
|
||||
String s5 = new String("five");
|
||||
String s6 = new String("six");
|
||||
String s7 = new String("seven");
|
||||
String s8 = new String("eight");
|
||||
String s9 = new String("nine");
|
||||
String s10 = new String("ten");
|
||||
|
||||
DLoadWeakList<Object> list = new DLoadWeakList<Object>();
|
||||
|
||||
list.add(s0);
|
||||
list.add(s1);
|
||||
list.add(s2);
|
||||
list.add(s3);
|
||||
list.add(s4);
|
||||
list.add(s5);
|
||||
list.add(s6);
|
||||
list.add(s7);
|
||||
list.add(s8);
|
||||
list.add(s9);
|
||||
list.add(s10);
|
||||
|
||||
Assert.assertEquals(11, list.list.size());
|
||||
|
||||
System.gc();
|
||||
|
||||
try {
|
||||
Thread.sleep(300);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// this is really only a HINT, so no guarantee
|
||||
// .. but the SUN JVM does do the business
|
||||
System.gc();
|
||||
|
||||
Assert.assertEquals(11, list.list.size());
|
||||
public class TestDLoadWeakList extends BaseTestCase {
|
||||
|
||||
List<Object> b0 = list.getLoadBatch(0, 2);
|
||||
Assert.assertEquals(2, b0.size());
|
||||
Assert.assertEquals("zero", b0.get(0));
|
||||
Assert.assertEquals("one", b0.get(1));
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
try {
|
||||
b0 = list.getLoadBatch(0, 2);
|
||||
Assert.assertTrue(false);
|
||||
} catch (IllegalStateException e){
|
||||
Assert.assertTrue(true);
|
||||
}
|
||||
b0 = list.getNextBatch(2);
|
||||
Assert.assertEquals(2, b0.size());
|
||||
Assert.assertEquals("two", b0.get(0));
|
||||
Assert.assertEquals("three", b0.get(1));
|
||||
String s0 = new String("zero");
|
||||
String s1 = new String("one");
|
||||
String s2 = new String("two");
|
||||
String s3 = new String("three");
|
||||
String s4 = new String("four");
|
||||
String s5 = new String("five");
|
||||
String s6 = new String("six");
|
||||
String s7 = new String("seven");
|
||||
String s8 = new String("eight");
|
||||
String s9 = new String("nine");
|
||||
String s10 = new String("ten");
|
||||
|
||||
list.removeEntry(1);
|
||||
|
||||
b0 = list.getLoadBatch(7, 2);
|
||||
Assert.assertEquals(2, b0.size());
|
||||
Assert.assertEquals("seven", b0.get(0));
|
||||
Assert.assertEquals("eight", b0.get(1));
|
||||
DLoadWeakList<Object> list = new DLoadWeakList<Object>();
|
||||
|
||||
}
|
||||
list.add(s0);
|
||||
list.add(s1);
|
||||
list.add(s2);
|
||||
list.add(s3);
|
||||
list.add(s4);
|
||||
list.add(s5);
|
||||
list.add(s6);
|
||||
list.add(s7);
|
||||
list.add(s8);
|
||||
list.add(s9);
|
||||
list.add(s10);
|
||||
|
||||
Assert.assertEquals(11, list.list.size());
|
||||
|
||||
System.gc();
|
||||
|
||||
try {
|
||||
Thread.sleep(300);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// this is really only a HINT, so no guarantee
|
||||
// .. but the SUN JVM does do the business
|
||||
System.gc();
|
||||
|
||||
Assert.assertEquals(11, list.list.size());
|
||||
|
||||
List<Object> b0 = list.getLoadBatch(0, 2);
|
||||
Assert.assertEquals(2, b0.size());
|
||||
Assert.assertEquals("zero", b0.get(0));
|
||||
Assert.assertEquals("one", b0.get(1));
|
||||
|
||||
try {
|
||||
b0 = list.getLoadBatch(0, 2);
|
||||
Assert.assertTrue(false);
|
||||
} catch (IllegalStateException e) {
|
||||
Assert.assertTrue(true);
|
||||
}
|
||||
b0 = list.getNextBatch(2);
|
||||
Assert.assertEquals(2, b0.size());
|
||||
Assert.assertEquals("two", b0.get(0));
|
||||
Assert.assertEquals("three", b0.get(1));
|
||||
|
||||
list.removeEntry(1);
|
||||
|
||||
b0 = list.getLoadBatch(7, 2);
|
||||
Assert.assertEquals(2, b0.size());
|
||||
Assert.assertEquals("seven", b0.get(0));
|
||||
Assert.assertEquals("eight", b0.get(1));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+93
-92
@@ -3,105 +3,106 @@ package com.avaje.ebeaninternal.server.loadcontext;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class TestDLoadWeakListWithGC extends TestCase {
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
|
||||
|
||||
private void doStuffInMethodScope(DLoadWeakList<Object> list) {
|
||||
String s5 = new String("five");
|
||||
String s6 = new String("six");
|
||||
String s7 = new String("seven");
|
||||
String s8 = new String("eight");
|
||||
String s9 = new String("nine");
|
||||
String s10 = new String("ten");
|
||||
|
||||
list.add(s5);
|
||||
list.add(s6);
|
||||
list.add(s7);
|
||||
list.add(s8);
|
||||
list.add(s9);
|
||||
list.add(s10);
|
||||
}
|
||||
|
||||
public void test() {
|
||||
|
||||
String s0 = new String("zero");
|
||||
String s1 = new String("one");
|
||||
String s2 = new String("two");
|
||||
String s3 = new String("three");
|
||||
String s4 = new String("four");
|
||||
|
||||
DLoadWeakList<Object> list = new DLoadWeakList<Object>();
|
||||
|
||||
list.add(s0);
|
||||
list.add(s1);
|
||||
list.add(s2);
|
||||
list.add(s3);
|
||||
list.add(s4);
|
||||
|
||||
int initialSize = list.list.size();
|
||||
|
||||
doStuffInMethodScope(list);
|
||||
Assert.assertEquals(11, list.list.size());
|
||||
|
||||
System.gc();
|
||||
|
||||
try {
|
||||
Thread.sleep(300);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// this is really only a HINT, so no guarantee
|
||||
// .. but the SUN JVM does do the business
|
||||
System.gc();
|
||||
|
||||
Assert.assertEquals(11, list.list.size());
|
||||
|
||||
// these weak refs are still good as we still
|
||||
// have a hard reference to the objects in scope
|
||||
for (int i = 0; i < initialSize; i++) {
|
||||
WeakReference<Object> weakReference = list.list.get(i);
|
||||
Assert.assertNotNull(weakReference);
|
||||
Assert.assertNotNull(weakReference.get());
|
||||
}
|
||||
public class TestDLoadWeakListWithGC extends BaseTestCase {
|
||||
|
||||
// these weak refs are all null as we don't have
|
||||
// hard refs to the objects in scope ... and it just
|
||||
// so happens the System.gc() in sun jvm is aggressive here.
|
||||
for (int i = initialSize; i < list.list.size(); i++) {
|
||||
WeakReference<Object> weakReference = list.list.get(i);
|
||||
Assert.assertNotNull(weakReference);
|
||||
Assert.assertNull(weakReference.get());
|
||||
}
|
||||
private void doStuffInMethodScope(DLoadWeakList<Object> list) {
|
||||
String s5 = new String("five");
|
||||
String s6 = new String("six");
|
||||
String s7 = new String("seven");
|
||||
String s8 = new String("eight");
|
||||
String s9 = new String("nine");
|
||||
String s10 = new String("ten");
|
||||
|
||||
List<Object> b0 = list.getLoadBatch(0, 2);
|
||||
Assert.assertEquals(2, b0.size());
|
||||
Assert.assertEquals("zero", b0.get(0));
|
||||
Assert.assertEquals("one", b0.get(1));
|
||||
list.add(s5);
|
||||
list.add(s6);
|
||||
list.add(s7);
|
||||
list.add(s8);
|
||||
list.add(s9);
|
||||
list.add(s10);
|
||||
}
|
||||
|
||||
try {
|
||||
b0 = list.getLoadBatch(0, 2);
|
||||
Assert.assertTrue(false);
|
||||
} catch (IllegalStateException e){
|
||||
Assert.assertTrue(true);
|
||||
}
|
||||
b0 = list.getNextBatch(2);
|
||||
Assert.assertEquals(2, b0.size());
|
||||
Assert.assertEquals("two", b0.get(0));
|
||||
Assert.assertEquals("three", b0.get(1));
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
list.removeEntry(1);
|
||||
String s0 = new String("zero");
|
||||
String s1 = new String("one");
|
||||
String s2 = new String("two");
|
||||
String s3 = new String("three");
|
||||
String s4 = new String("four");
|
||||
|
||||
try {
|
||||
// past the gc blown area
|
||||
b0 = list.getLoadBatch(7, 2);
|
||||
Assert.assertTrue(false);
|
||||
} catch (IllegalStateException e){
|
||||
Assert.assertTrue(true);
|
||||
}
|
||||
DLoadWeakList<Object> list = new DLoadWeakList<Object>();
|
||||
|
||||
}
|
||||
list.add(s0);
|
||||
list.add(s1);
|
||||
list.add(s2);
|
||||
list.add(s3);
|
||||
list.add(s4);
|
||||
|
||||
int initialSize = list.list.size();
|
||||
|
||||
doStuffInMethodScope(list);
|
||||
Assert.assertEquals(11, list.list.size());
|
||||
|
||||
System.gc();
|
||||
|
||||
try {
|
||||
Thread.sleep(300);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// this is really only a HINT, so no guarantee
|
||||
// .. but the SUN JVM does do the business
|
||||
System.gc();
|
||||
|
||||
Assert.assertEquals(11, list.list.size());
|
||||
|
||||
// these weak refs are still good as we still
|
||||
// have a hard reference to the objects in scope
|
||||
for (int i = 0; i < initialSize; i++) {
|
||||
WeakReference<Object> weakReference = list.list.get(i);
|
||||
Assert.assertNotNull(weakReference);
|
||||
Assert.assertNotNull(weakReference.get());
|
||||
}
|
||||
|
||||
// these weak refs are all null as we don't have
|
||||
// hard refs to the objects in scope ... and it just
|
||||
// so happens the System.gc() in sun jvm is aggressive here.
|
||||
for (int i = initialSize; i < list.list.size(); i++) {
|
||||
WeakReference<Object> weakReference = list.list.get(i);
|
||||
Assert.assertNotNull(weakReference);
|
||||
Assert.assertNull(weakReference.get());
|
||||
}
|
||||
|
||||
List<Object> b0 = list.getLoadBatch(0, 2);
|
||||
Assert.assertEquals(2, b0.size());
|
||||
Assert.assertEquals("zero", b0.get(0));
|
||||
Assert.assertEquals("one", b0.get(1));
|
||||
|
||||
try {
|
||||
b0 = list.getLoadBatch(0, 2);
|
||||
Assert.assertTrue(false);
|
||||
} catch (IllegalStateException e) {
|
||||
Assert.assertTrue(true);
|
||||
}
|
||||
b0 = list.getNextBatch(2);
|
||||
Assert.assertEquals(2, b0.size());
|
||||
Assert.assertEquals("two", b0.get(0));
|
||||
Assert.assertEquals("three", b0.get(1));
|
||||
|
||||
list.removeEntry(1);
|
||||
|
||||
try {
|
||||
// past the gc blown area
|
||||
b0 = list.getLoadBatch(7, 2);
|
||||
Assert.assertTrue(false);
|
||||
} catch (IllegalStateException e) {
|
||||
Assert.assertTrue(true);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,85 +10,84 @@ import com.avaje.ebean.EbeanServer;
|
||||
import com.avaje.ebeaninternal.server.expression.DefaultExpressionFactory;
|
||||
import com.avaje.tests.model.basic.Order;
|
||||
|
||||
|
||||
public class TestQueryLanguage extends TestCase {
|
||||
|
||||
public void test() {
|
||||
|
||||
|
||||
DefaultOrmQuery<Order> q = check("find order join customer (id, name)");
|
||||
OrmQueryDetail detail = q.getDetail();
|
||||
OrmQueryProperties chunk = detail.getChunk("customer", false);
|
||||
Set<String> props = chunk.getAllIncludedProperties();
|
||||
|
||||
Assert.assertTrue(props.contains("id"));
|
||||
Assert.assertTrue(props.contains("name"));
|
||||
|
||||
q = check("find order join customer(id, name)");
|
||||
detail = q.getDetail();
|
||||
chunk = detail.getChunk("customer", false);
|
||||
props = chunk.getAllIncludedProperties();
|
||||
|
||||
Assert.assertTrue(props.contains("id"));
|
||||
Assert.assertTrue(props.contains("name"));
|
||||
Assert.assertFalse(chunk.isCache());
|
||||
Assert.assertFalse(chunk.isReadOnly());
|
||||
public void test() {
|
||||
|
||||
q = check("find order join customer(+cache +readonly, id, name)");
|
||||
detail = q.getDetail();
|
||||
chunk = detail.getChunk("customer", false);
|
||||
props = chunk.getAllIncludedProperties();
|
||||
Assert.assertTrue(props.contains("id"));
|
||||
Assert.assertTrue(props.contains("name"));
|
||||
Assert.assertTrue(chunk.isCache());
|
||||
Assert.assertTrue(chunk.isReadOnly());
|
||||
DefaultOrmQuery<Order> q = check("find order join customer (id, name)");
|
||||
OrmQueryDetail detail = q.getDetail();
|
||||
OrmQueryProperties chunk = detail.getChunk("customer", false);
|
||||
Set<String> props = chunk.getAllIncludedProperties();
|
||||
|
||||
q = check("find order join customer(+cache +readonly,id,name)");
|
||||
detail = q.getDetail();
|
||||
chunk = detail.getChunk("customer", false);
|
||||
props = chunk.getAllIncludedProperties();
|
||||
Assert.assertTrue(props.contains("id"));
|
||||
Assert.assertTrue(props.contains("name"));
|
||||
Assert.assertTrue(chunk.isCache());
|
||||
Assert.assertTrue(chunk.isReadOnly());
|
||||
Assert.assertTrue(props.contains("id"));
|
||||
Assert.assertTrue(props.contains("name"));
|
||||
|
||||
q = check("find order(id,status) join customer(+cache +readonly,id,name)");
|
||||
detail = q.getDetail();
|
||||
chunk = detail.getChunk("customer", false);
|
||||
props = chunk.getAllIncludedProperties();
|
||||
Assert.assertTrue(props.contains("id"));
|
||||
Assert.assertTrue(props.contains("name"));
|
||||
Assert.assertTrue(chunk.isCache());
|
||||
Assert.assertTrue(chunk.isReadOnly());
|
||||
q = check("find order join customer(id, name)");
|
||||
detail = q.getDetail();
|
||||
chunk = detail.getChunk("customer", false);
|
||||
props = chunk.getAllIncludedProperties();
|
||||
|
||||
chunk = detail.getChunk(null, false);
|
||||
props = chunk.getAllIncludedProperties();
|
||||
Assert.assertTrue(props.contains("id"));
|
||||
Assert.assertTrue(props.contains("status"));
|
||||
Assert.assertFalse(props.contains("orderDate"));
|
||||
|
||||
q = check("find order(id,status) join customer(+cache +readonly,id,name) where id > :minId order by status");
|
||||
detail = q.getDetail();
|
||||
chunk = detail.getChunk("customer", false);
|
||||
props = chunk.getAllIncludedProperties();
|
||||
Assert.assertTrue(props.contains("id"));
|
||||
Assert.assertTrue(props.contains("name"));
|
||||
Assert.assertTrue(chunk.isCache());
|
||||
Assert.assertTrue(chunk.isReadOnly());
|
||||
|
||||
String orderBy = q.getOrderBy().toStringFormat();
|
||||
Assert.assertEquals("status", orderBy);
|
||||
}
|
||||
|
||||
private DefaultOrmQuery<Order> check(String q) {
|
||||
Assert.assertTrue(props.contains("id"));
|
||||
Assert.assertTrue(props.contains("name"));
|
||||
Assert.assertFalse(chunk.isCache());
|
||||
Assert.assertFalse(chunk.isReadOnly());
|
||||
|
||||
EbeanServer server = Ebean.getServer(null);
|
||||
q = check("find order join customer(+cache +readonly, id, name)");
|
||||
detail = q.getDetail();
|
||||
chunk = detail.getChunk("customer", false);
|
||||
props = chunk.getAllIncludedProperties();
|
||||
Assert.assertTrue(props.contains("id"));
|
||||
Assert.assertTrue(props.contains("name"));
|
||||
Assert.assertTrue(chunk.isCache());
|
||||
Assert.assertTrue(chunk.isReadOnly());
|
||||
|
||||
OrmQueryDetailParser p = new OrmQueryDetailParser(q);
|
||||
p.parse();
|
||||
DefaultOrmQuery<Order> qry = new DefaultOrmQuery<Order>(Order.class, server, new DefaultExpressionFactory(), (String)null);
|
||||
p.assign(qry);
|
||||
q = check("find order join customer(+cache +readonly,id,name)");
|
||||
detail = q.getDetail();
|
||||
chunk = detail.getChunk("customer", false);
|
||||
props = chunk.getAllIncludedProperties();
|
||||
Assert.assertTrue(props.contains("id"));
|
||||
Assert.assertTrue(props.contains("name"));
|
||||
Assert.assertTrue(chunk.isCache());
|
||||
Assert.assertTrue(chunk.isReadOnly());
|
||||
|
||||
return qry;
|
||||
}
|
||||
q = check("find order(id,status) join customer(+cache +readonly,id,name)");
|
||||
detail = q.getDetail();
|
||||
chunk = detail.getChunk("customer", false);
|
||||
props = chunk.getAllIncludedProperties();
|
||||
Assert.assertTrue(props.contains("id"));
|
||||
Assert.assertTrue(props.contains("name"));
|
||||
Assert.assertTrue(chunk.isCache());
|
||||
Assert.assertTrue(chunk.isReadOnly());
|
||||
|
||||
chunk = detail.getChunk(null, false);
|
||||
props = chunk.getAllIncludedProperties();
|
||||
Assert.assertTrue(props.contains("id"));
|
||||
Assert.assertTrue(props.contains("status"));
|
||||
Assert.assertFalse(props.contains("orderDate"));
|
||||
|
||||
q = check("find order(id,status) join customer(+cache +readonly,id,name) where id > :minId order by status");
|
||||
detail = q.getDetail();
|
||||
chunk = detail.getChunk("customer", false);
|
||||
props = chunk.getAllIncludedProperties();
|
||||
Assert.assertTrue(props.contains("id"));
|
||||
Assert.assertTrue(props.contains("name"));
|
||||
Assert.assertTrue(chunk.isCache());
|
||||
Assert.assertTrue(chunk.isReadOnly());
|
||||
|
||||
String orderBy = q.getOrderBy().toStringFormat();
|
||||
Assert.assertEquals("status", orderBy);
|
||||
}
|
||||
|
||||
private DefaultOrmQuery<Order> check(String q) {
|
||||
|
||||
EbeanServer server = Ebean.getServer(null);
|
||||
|
||||
OrmQueryDetailParser p = new OrmQueryDetailParser(q);
|
||||
p.parse();
|
||||
DefaultOrmQuery<Order> qry = new DefaultOrmQuery<Order>(Order.class, server,
|
||||
new DefaultExpressionFactory(), (String) null);
|
||||
p.assign(qry);
|
||||
|
||||
return qry;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package com.avaje.tests.basic;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.Query;
|
||||
import com.avaje.tests.model.basic.Address;
|
||||
@@ -10,8 +12,9 @@ import com.avaje.tests.model.basic.Customer;
|
||||
import com.avaje.tests.model.basic.Order;
|
||||
import com.avaje.tests.model.basic.ResetBasicData;
|
||||
|
||||
public class TestAssocOneEqExpression extends TestCase {
|
||||
public class TestAssocOneEqExpression extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
@@ -1,16 +1,19 @@
|
||||
package com.avaje.tests.basic;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.Query;
|
||||
import com.avaje.ebeaninternal.api.SpiEbeanServer;
|
||||
import com.avaje.tests.model.basic.Order;
|
||||
import com.avaje.tests.model.basic.ResetBasicData;
|
||||
|
||||
public class TestBackgroundFetchAfter extends TestCase {
|
||||
public class TestBackgroundFetchAfter extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void testWrtJoin() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
@@ -2,9 +2,10 @@ package com.avaje.tests.basic;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.AdminAutofetch;
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.Query;
|
||||
import com.avaje.tests.model.basic.Customer;
|
||||
@@ -12,8 +13,9 @@ import com.avaje.tests.model.basic.Order;
|
||||
import com.avaje.tests.model.basic.OrderDetail;
|
||||
import com.avaje.tests.model.basic.ResetBasicData;
|
||||
|
||||
public class TestBatchLazy extends TestCase {
|
||||
public class TestBatchLazy extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void testMe() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
package com.avaje.tests.basic;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.tests.model.basic.Order;
|
||||
import com.avaje.tests.model.basic.ResetBasicData;
|
||||
|
||||
public class TestBatchLazyMany extends TestCase {
|
||||
public class TestBatchLazyMany extends BaseTestCase {
|
||||
|
||||
|
||||
@Test
|
||||
public void testMe() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
@@ -1,16 +1,18 @@
|
||||
package com.avaje.tests.basic;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.tests.model.basic.Order;
|
||||
import com.avaje.tests.model.basic.Order.Status;
|
||||
import com.avaje.tests.model.basic.ResetBasicData;
|
||||
|
||||
public class TestBeanReferenceRefresh extends TestCase {
|
||||
public class TestBeanReferenceRefresh extends BaseTestCase {
|
||||
|
||||
|
||||
@Test
|
||||
public void testMe() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
@@ -3,15 +3,18 @@ package com.avaje.tests.basic;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.tests.model.basic.Customer;
|
||||
import com.avaje.tests.model.basic.Order;
|
||||
import com.avaje.tests.model.basic.ResetBasicData;
|
||||
|
||||
public class TestDeleteByIdCollection extends TestCase {
|
||||
public class TestDeleteByIdCollection extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
@@ -25,8 +28,8 @@ public class TestDeleteByIdCollection extends TestCase {
|
||||
Customer c0Back = Ebean.find(Customer.class, c0.getId());
|
||||
Customer c1Back = Ebean.find(Customer.class, ""+c1.getId());
|
||||
|
||||
assertNotNull(c0Back);
|
||||
assertNotNull(c1Back);
|
||||
Assert.assertNotNull(c0Back);
|
||||
Assert.assertNotNull(c1Back);
|
||||
|
||||
List<String> ids = new ArrayList<String>();
|
||||
// also test id type conversion
|
||||
@@ -39,8 +42,8 @@ public class TestDeleteByIdCollection extends TestCase {
|
||||
c0Back = Ebean.find(Customer.class, c0.getId());
|
||||
c1Back = Ebean.find(Customer.class, ""+c1.getId());
|
||||
|
||||
assertNull(c0Back);
|
||||
assertNull(c1Back);
|
||||
Assert.assertNull(c0Back);
|
||||
Assert.assertNull(c1Back);
|
||||
}
|
||||
|
||||
public void testDelByStatement() {
|
||||
@@ -53,8 +56,8 @@ public class TestDeleteByIdCollection extends TestCase {
|
||||
Order o0Back = Ebean.find(Order.class, order0.getId());
|
||||
Order o1Back = Ebean.find(Order.class, order1.getId());
|
||||
|
||||
assertNotNull(o0Back);
|
||||
assertNotNull(o1Back);
|
||||
Assert.assertNotNull(o0Back);
|
||||
Assert.assertNotNull(o1Back);
|
||||
|
||||
|
||||
List<Object> ids = new ArrayList<Object>();
|
||||
@@ -67,8 +70,8 @@ public class TestDeleteByIdCollection extends TestCase {
|
||||
o0Back = Ebean.find(Order.class, order0.getId());
|
||||
o1Back = Ebean.find(Order.class, order1.getId());
|
||||
|
||||
assertNull(o0Back);
|
||||
assertNull(o1Back);
|
||||
Assert.assertNull(o0Back);
|
||||
Assert.assertNull(o1Back);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,38 +1,36 @@
|
||||
package com.avaje.tests.basic;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.tests.model.basic.PFile;
|
||||
import com.avaje.tests.model.basic.PFileContent;
|
||||
|
||||
public class TestDeleteImportedPartial extends TestCase {
|
||||
|
||||
public void test() {
|
||||
|
||||
public class TestDeleteImportedPartial extends BaseTestCase {
|
||||
|
||||
PFile persistentFile = new PFile("test.txt", new PFileContent("test".getBytes()));
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
Ebean.save(persistentFile);
|
||||
Integer id = persistentFile.getId();
|
||||
Integer contentId = persistentFile.getFileContent().getId();
|
||||
PFile persistentFile = new PFile("test.txt", new PFileContent("test".getBytes()));
|
||||
|
||||
PFile partialPfile = Ebean.find(PFile.class)
|
||||
.select("id")
|
||||
.where().idEq(persistentFile.getId())
|
||||
.findUnique();
|
||||
|
||||
// should delete file and fileContent
|
||||
Ebean.delete(partialPfile);
|
||||
System.out.println("finished delete");
|
||||
Ebean.save(persistentFile);
|
||||
Integer id = persistentFile.getId();
|
||||
Integer contentId = persistentFile.getFileContent().getId();
|
||||
|
||||
PFile file1 = Ebean.find(PFile.class, id);
|
||||
PFileContent content1 = Ebean.find(PFileContent.class, contentId);
|
||||
PFile partialPfile = Ebean.find(PFile.class).select("id").where().idEq(persistentFile.getId())
|
||||
.findUnique();
|
||||
|
||||
Assert.assertNull(file1);
|
||||
Assert.assertNull(content1);
|
||||
|
||||
}
|
||||
// should delete file and fileContent
|
||||
Ebean.delete(partialPfile);
|
||||
System.out.println("finished delete");
|
||||
|
||||
PFile file1 = Ebean.find(PFile.class, id);
|
||||
PFileContent content1 = Ebean.find(PFileContent.class, contentId);
|
||||
|
||||
Assert.assertNull(file1);
|
||||
Assert.assertNull(content1);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,49 +1,51 @@
|
||||
package com.avaje.tests.basic;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.tests.model.basic.PersistentFile;
|
||||
import com.avaje.tests.model.basic.PersistentFileContent;
|
||||
|
||||
public class TestDeleteOneToOne extends TestCase {
|
||||
|
||||
public void testCreateDeletePersistentFile() {
|
||||
public class TestDeleteOneToOne extends BaseTestCase {
|
||||
|
||||
PersistentFile persistentFile = new PersistentFile("test.txt", new PersistentFileContent("test".getBytes()));
|
||||
@Test
|
||||
public void testCreateDeletePersistentFile() {
|
||||
|
||||
Ebean.save(persistentFile);
|
||||
Integer id = persistentFile.getId();
|
||||
Integer contentId = persistentFile.getPersistentFileContent().getId();
|
||||
PersistentFile persistentFile = new PersistentFile("test.txt", new PersistentFileContent(
|
||||
"test".getBytes()));
|
||||
|
||||
// should delete file and fileContent
|
||||
Ebean.delete(PersistentFile.class, id);
|
||||
Ebean.save(persistentFile);
|
||||
Integer id = persistentFile.getId();
|
||||
Integer contentId = persistentFile.getPersistentFileContent().getId();
|
||||
|
||||
PersistentFile file1 = Ebean.find(PersistentFile.class, id);
|
||||
PersistentFileContent content1 = Ebean.find(PersistentFileContent.class, contentId);
|
||||
// should delete file and fileContent
|
||||
Ebean.delete(PersistentFile.class, id);
|
||||
|
||||
Assert.assertNull(file1);
|
||||
Assert.assertNull(content1);
|
||||
PersistentFile file1 = Ebean.find(PersistentFile.class, id);
|
||||
PersistentFileContent content1 = Ebean.find(PersistentFileContent.class, contentId);
|
||||
|
||||
}
|
||||
Assert.assertNull(file1);
|
||||
Assert.assertNull(content1);
|
||||
|
||||
// public void testDeleteMany() {
|
||||
//
|
||||
// Customer c = new Customer();
|
||||
// c.setName("Fiona");
|
||||
// c.setStatus(Customer.Status.ACTIVE);
|
||||
// c.addContact(new Contact("Fiona", "Black"));
|
||||
// c.addContact(new Contact("Tracy", "Red"));
|
||||
//
|
||||
// Ebean.save(c);
|
||||
//
|
||||
// Ebean.delete(Customer.class, c.getId());
|
||||
//
|
||||
// Customer deletedCustomer = Ebean.find(Customer.class, c.getId());
|
||||
//
|
||||
// Assert.assertNull(deletedCustomer);
|
||||
//
|
||||
// }
|
||||
}
|
||||
|
||||
// public void testDeleteMany() {
|
||||
//
|
||||
// Customer c = new Customer();
|
||||
// c.setName("Fiona");
|
||||
// c.setStatus(Customer.Status.ACTIVE);
|
||||
// c.addContact(new Contact("Fiona", "Black"));
|
||||
// c.addContact(new Contact("Tracy", "Red"));
|
||||
//
|
||||
// Ebean.save(c);
|
||||
//
|
||||
// Ebean.delete(Customer.class, c.getId());
|
||||
//
|
||||
// Customer deletedCustomer = Ebean.find(Customer.class, c.getId());
|
||||
//
|
||||
// Assert.assertNull(deletedCustomer);
|
||||
//
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -1,33 +1,34 @@
|
||||
package com.avaje.tests.basic;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.tests.model.basic.PFile;
|
||||
import com.avaje.tests.model.basic.PFileContent;
|
||||
|
||||
public class TestDeleteOneToOneMultiple extends TestCase {
|
||||
|
||||
public void testCreateDeletePersistentFile() {
|
||||
public class TestDeleteOneToOneMultiple extends BaseTestCase {
|
||||
|
||||
PFile persistentFile = new PFile("test.txt", new PFileContent("test".getBytes()));
|
||||
@Test
|
||||
public void testCreateDeletePersistentFile() {
|
||||
|
||||
Ebean.save(persistentFile);
|
||||
Integer id = persistentFile.getId();
|
||||
Integer contentId = persistentFile.getFileContent().getId();
|
||||
PFile persistentFile = new PFile("test.txt", new PFileContent("test".getBytes()));
|
||||
|
||||
// should delete file and fileContent
|
||||
Ebean.delete(PFile.class, id);
|
||||
System.out.println("finished delete");
|
||||
Ebean.save(persistentFile);
|
||||
Integer id = persistentFile.getId();
|
||||
Integer contentId = persistentFile.getFileContent().getId();
|
||||
|
||||
PFile file1 = Ebean.find(PFile.class, id);
|
||||
PFileContent content1 = Ebean.find(PFileContent.class, contentId);
|
||||
// should delete file and fileContent
|
||||
Ebean.delete(PFile.class, id);
|
||||
System.out.println("finished delete");
|
||||
|
||||
Assert.assertNull(file1);
|
||||
Assert.assertNull(content1);
|
||||
PFile file1 = Ebean.find(PFile.class, id);
|
||||
PFileContent content1 = Ebean.find(PFileContent.class, contentId);
|
||||
|
||||
}
|
||||
Assert.assertNull(file1);
|
||||
Assert.assertNull(content1);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
package com.avaje.tests.basic;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.tests.model.basic.TMapSuperEntity;
|
||||
|
||||
public class TestDeletePartialNoVersion extends TestCase {
|
||||
public class TestDeletePartialNoVersion extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void testNoVersion() {
|
||||
|
||||
TMapSuperEntity e = new TMapSuperEntity();
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
package com.avaje.tests.basic;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.EbeanServer;
|
||||
import com.avaje.tests.model.embedded.EMain;
|
||||
|
||||
public class TestDynamicUpdate extends TestCase {
|
||||
public class TestDynamicUpdate extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void testUpdate() {
|
||||
|
||||
// insert
|
||||
@@ -18,7 +21,7 @@ public class TestDynamicUpdate extends TestCase {
|
||||
EbeanServer server = Ebean.getServer(null);
|
||||
server.save(b);
|
||||
|
||||
assertNotNull(b.getId());
|
||||
Assert.assertNotNull(b.getId());
|
||||
|
||||
// reload object und update the name
|
||||
EMain b2 = server.find(EMain.class, b.getId());
|
||||
@@ -29,7 +32,7 @@ public class TestDynamicUpdate extends TestCase {
|
||||
server.beginTransaction();
|
||||
try {
|
||||
EMain b3 = server.find(EMain.class, b.getId());
|
||||
assertEquals("ABC", b3.getEmbeddable().getDescription());
|
||||
Assert.assertEquals("ABC", b3.getEmbeddable().getDescription());
|
||||
} finally {
|
||||
server.endTransaction();
|
||||
}
|
||||
@@ -39,6 +42,6 @@ public class TestDynamicUpdate extends TestCase {
|
||||
server.save(b4);
|
||||
|
||||
EMain b5 = server.find(EMain.class, b.getId());
|
||||
assertEquals("123", b5.getEmbeddable().getDescription());
|
||||
Assert.assertEquals("123", b5.getEmbeddable().getDescription());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,23 +2,26 @@ package com.avaje.tests.basic;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.BeanState;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.tests.model.basic.Customer;
|
||||
import com.avaje.tests.model.basic.Order;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
|
||||
public class TestEnhancementCollectionInitialisation extends TestCase {
|
||||
public class TestEnhancementCollectionInitialisation extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void testListInitialisation() {
|
||||
|
||||
Customer customer = new Customer();
|
||||
BeanState beanState = Ebean.getBeanState(customer);
|
||||
if (beanState != null) {
|
||||
List<Order> orders = customer.getOrders();
|
||||
assertNotNull(orders);
|
||||
Assert.assertNotNull(orders);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,28 +2,27 @@ package com.avaje.tests.basic;
|
||||
|
||||
import javax.persistence.PersistenceException;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.config.GlobalProperties;
|
||||
import com.avaje.tests.model.basic.Order;
|
||||
|
||||
public class TestErrorBindLog extends TestCase {
|
||||
public class TestErrorBindLog extends BaseTestCase {
|
||||
|
||||
public void test() {
|
||||
|
||||
GlobalProperties.put("somethingelse", "d:/junk2");
|
||||
try {
|
||||
Ebean.find(Order.class)
|
||||
.where().gt("id", "JUNK")
|
||||
.findList();
|
||||
|
||||
} catch (PersistenceException e){
|
||||
String msg = e.getMessage();
|
||||
e.printStackTrace();
|
||||
Assert.assertTrue(msg.contains("Bind values:"));
|
||||
}
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
GlobalProperties.put("somethingelse", "d:/junk2");
|
||||
try {
|
||||
Ebean.find(Order.class).where().gt("id", "JUNK").findList();
|
||||
|
||||
} catch (PersistenceException e) {
|
||||
String msg = e.getMessage();
|
||||
e.printStackTrace();
|
||||
Assert.assertTrue(msg.contains("Bind values:"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,65 +2,64 @@ package com.avaje.tests.basic;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.EbeanServer;
|
||||
import com.avaje.ebean.Update;
|
||||
import com.avaje.tests.model.basic.EBasic;
|
||||
|
||||
public class TestExplicitInsert extends TestCase {
|
||||
public class TestExplicitInsert extends BaseTestCase {
|
||||
|
||||
public void test() {
|
||||
|
||||
//GlobalProperties.put("ebean.classes", ""+LDPerson.class.toString()+","+EBasic.class.toString());
|
||||
|
||||
EBasic b = new EBasic();
|
||||
b.setName("exp insert");
|
||||
b.setDescription("explicit insert");
|
||||
b.setStatus(EBasic.Status.ACTIVE);
|
||||
|
||||
EbeanServer server = Ebean.getServer(null);
|
||||
server.insert(b);
|
||||
|
||||
assertNotNull(b.getId());
|
||||
|
||||
EBasic b2 = server.find(EBasic.class, b.getId());
|
||||
b2.setId(null);
|
||||
|
||||
b2.setName("force insert");
|
||||
server.insert(b2);
|
||||
|
||||
assertNotNull(b2.getId());
|
||||
assertTrue(!b.getId().equals(b2.getId()));
|
||||
|
||||
|
||||
List<EBasic> list = server.find(EBasic.class)
|
||||
.setMaxRows(10)
|
||||
.findList();
|
||||
|
||||
assertTrue(list.size() >= 2);
|
||||
|
||||
int firstRow = 1;
|
||||
List<EBasic> list2 = server.find(EBasic.class)
|
||||
.order().asc("id")
|
||||
.setFirstRow(firstRow)
|
||||
.setMaxRows(10)
|
||||
.findList();
|
||||
|
||||
int expectedCount = list.size() -firstRow;
|
||||
if (expectedCount > 0){
|
||||
assertEquals(expectedCount, list2.size());
|
||||
} else {
|
||||
assertTrue(list2.isEmpty());
|
||||
}
|
||||
|
||||
Update<EBasic> update = Ebean.createUpdate(EBasic.class, "update ebasic set description = 'test'");
|
||||
|
||||
int rows = update.execute();
|
||||
|
||||
assertTrue(rows > 0);
|
||||
Ebean.externalModification("e_basic", true, false, true);
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
// GlobalProperties.put("ebean.classes",
|
||||
// ""+LDPerson.class.toString()+","+EBasic.class.toString());
|
||||
|
||||
EBasic b = new EBasic();
|
||||
b.setName("exp insert");
|
||||
b.setDescription("explicit insert");
|
||||
b.setStatus(EBasic.Status.ACTIVE);
|
||||
|
||||
EbeanServer server = Ebean.getServer(null);
|
||||
server.insert(b);
|
||||
|
||||
Assert.assertNotNull(b.getId());
|
||||
|
||||
EBasic b2 = server.find(EBasic.class, b.getId());
|
||||
b2.setId(null);
|
||||
|
||||
b2.setName("force insert");
|
||||
server.insert(b2);
|
||||
|
||||
Assert.assertNotNull(b2.getId());
|
||||
Assert.assertTrue(!b.getId().equals(b2.getId()));
|
||||
|
||||
List<EBasic> list = server.find(EBasic.class).setMaxRows(10).findList();
|
||||
|
||||
Assert.assertTrue(list.size() >= 2);
|
||||
|
||||
int firstRow = 1;
|
||||
List<EBasic> list2 = server.find(EBasic.class).order().asc("id").setFirstRow(firstRow)
|
||||
.setMaxRows(10).findList();
|
||||
|
||||
int expectedCount = list.size() - firstRow;
|
||||
if (expectedCount > 0) {
|
||||
Assert.assertEquals(expectedCount, list2.size());
|
||||
} else {
|
||||
Assert.assertTrue(list2.isEmpty());
|
||||
}
|
||||
|
||||
|
||||
Update<EBasic> update = Ebean.createUpdate(EBasic.class,
|
||||
"update ebasic set description = 'test'");
|
||||
|
||||
int rows = update.execute();
|
||||
|
||||
Assert.assertTrue(rows > 0);
|
||||
Ebean.externalModification("e_basic", true, false, true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,17 +4,19 @@ import java.util.List;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.FutureIds;
|
||||
import com.avaje.ebean.Query;
|
||||
import com.avaje.tests.model.basic.Order;
|
||||
import com.avaje.tests.model.basic.ResetBasicData;
|
||||
|
||||
public class TestFetchId extends TestCase {
|
||||
|
||||
|
||||
public class TestFetchId extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void testFetchId() throws InterruptedException, ExecutionException {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
@@ -5,66 +5,68 @@ import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.tests.model.basic.EBasicVer;
|
||||
|
||||
public class TestIUDVanilla extends TestCase {
|
||||
public class TestIUDVanilla extends BaseTestCase {
|
||||
|
||||
public void test() {
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
EBasicVer e0 = new EBasicVer();
|
||||
e0.setName("vanilla");
|
||||
EBasicVer e0 = new EBasicVer();
|
||||
e0.setName("vanilla");
|
||||
|
||||
Ebean.save(e0);
|
||||
Ebean.save(e0);
|
||||
|
||||
// // only use the below test when not using enhancement
|
||||
// boolean entity = (e0 instanceof EntityBean);
|
||||
// Assert.assertTrue(!entity);
|
||||
// // only use the below test when not using enhancement
|
||||
// boolean entity = (e0 instanceof EntityBean);
|
||||
// Assert.assertTrue(!entity);
|
||||
|
||||
Assert.assertNotNull(e0.getId());
|
||||
Assert.assertNotNull(e0.getLastUpdate());
|
||||
Assert.assertNotNull(e0.getId());
|
||||
Assert.assertNotNull(e0.getLastUpdate());
|
||||
|
||||
Timestamp lastUpdate0 = e0.getLastUpdate();
|
||||
Timestamp lastUpdate0 = e0.getLastUpdate();
|
||||
|
||||
e0.setName("modified");
|
||||
Ebean.save(e0);
|
||||
e0.setName("modified");
|
||||
Ebean.save(e0);
|
||||
|
||||
Timestamp lastUpdate1 = e0.getLastUpdate();
|
||||
Assert.assertNotNull(lastUpdate1);
|
||||
Assert.assertNotSame(lastUpdate0, lastUpdate1);
|
||||
Timestamp lastUpdate1 = e0.getLastUpdate();
|
||||
Assert.assertNotNull(lastUpdate1);
|
||||
Assert.assertNotSame(lastUpdate0, lastUpdate1);
|
||||
|
||||
EBasicVer e2 = Ebean.getServer(null).createEntityBean(EBasicVer.class);
|
||||
EBasicVer e2 = Ebean.getServer(null).createEntityBean(EBasicVer.class);
|
||||
|
||||
HashSet<String> loaded = new HashSet<String>();
|
||||
loaded.add("id");
|
||||
loaded.add("lastUpdate");
|
||||
loaded.add("name");
|
||||
HashSet<String> loaded = new HashSet<String>();
|
||||
loaded.add("id");
|
||||
loaded.add("lastUpdate");
|
||||
loaded.add("name");
|
||||
|
||||
e2.setId(e0.getId());
|
||||
e2.setLastUpdate(lastUpdate1);
|
||||
e2.setId(e0.getId());
|
||||
e2.setLastUpdate(lastUpdate1);
|
||||
|
||||
Ebean.getBeanState(e2).setLoaded(loaded);
|
||||
e2.setName("forcedUpdate");
|
||||
Ebean.save(e2);
|
||||
Ebean.getBeanState(e2).setLoaded(loaded);
|
||||
e2.setName("forcedUpdate");
|
||||
Ebean.save(e2);
|
||||
|
||||
EBasicVer e3 = new EBasicVer();
|
||||
e3.setId(e0.getId());
|
||||
e3.setName("ModNoOCC");
|
||||
// e3.setLastUpdate(e2.getLastUpdate());
|
||||
EBasicVer e3 = new EBasicVer();
|
||||
e3.setId(e0.getId());
|
||||
e3.setName("ModNoOCC");
|
||||
// e3.setLastUpdate(e2.getLastUpdate());
|
||||
|
||||
Ebean.update(e3);
|
||||
|
||||
e3.setName("ModAgain");
|
||||
e3.setDescription("Banana");
|
||||
|
||||
|
||||
Set<String> updateProps = new HashSet<String>();
|
||||
updateProps.add("name");
|
||||
updateProps.add("description");
|
||||
|
||||
Ebean.update(e3, updateProps);
|
||||
Ebean.update(e3);
|
||||
|
||||
}
|
||||
e3.setName("ModAgain");
|
||||
e3.setDescription("Banana");
|
||||
|
||||
Set<String> updateProps = new HashSet<String>();
|
||||
updateProps.add("name");
|
||||
updateProps.add("description");
|
||||
|
||||
Ebean.update(e3, updateProps);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,23 +3,23 @@ package com.avaje.tests.basic;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.tests.model.basic.Order;
|
||||
|
||||
public class TestInEmpty extends TestCase {
|
||||
public class TestInEmpty extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
List<Order> list = Ebean.find(Order.class).where().gt("id", 0).in("id", new Object[0])
|
||||
.findList();
|
||||
|
||||
Assert.assertEquals(0, list.size());
|
||||
|
||||
}
|
||||
|
||||
public void test() {
|
||||
|
||||
List<Order> list = Ebean.find(Order.class)
|
||||
.where()
|
||||
.gt("id", 0)
|
||||
.in("id",new Object[0])
|
||||
.findList();
|
||||
|
||||
Assert.assertEquals(0, list.size());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,16 +3,18 @@ package com.avaje.tests.basic;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.tests.model.basic.Car;
|
||||
import com.avaje.tests.model.basic.Truck;
|
||||
import com.avaje.tests.model.basic.Vehicle;
|
||||
|
||||
public class TestInheritRef extends TestCase {
|
||||
public class TestInheritRef extends BaseTestCase {
|
||||
|
||||
|
||||
@Test
|
||||
public void testAssocOne() {
|
||||
|
||||
Ebean.createUpdate(Vehicle.class, "delete from vehicle");
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package com.avaje.tests.basic;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebeaninternal.api.SpiEbeanServer;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
|
||||
@@ -10,8 +12,9 @@ import com.avaje.ebeaninternal.server.deploy.BeanProperty;
|
||||
import com.avaje.ebeaninternal.server.type.ScalarType;
|
||||
import com.avaje.tests.model.basic.TJodaEntity;
|
||||
|
||||
public class TestJodaType extends TestCase {
|
||||
public class TestJodaType extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
SpiEbeanServer server = (SpiEbeanServer)Ebean.getServer(null);
|
||||
|
||||
@@ -5,8 +5,10 @@ import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.Query;
|
||||
import com.avaje.tests.model.basic.Address;
|
||||
@@ -15,7 +17,7 @@ import com.avaje.tests.model.basic.Trip;
|
||||
import com.avaje.tests.model.basic.Vehicle;
|
||||
import com.avaje.tests.model.basic.VehicleDriver;
|
||||
|
||||
public class TestJoinInheritance extends TestCase {
|
||||
public class TestJoinInheritance extends BaseTestCase {
|
||||
|
||||
|
||||
/**
|
||||
@@ -32,6 +34,7 @@ public class TestJoinInheritance extends TestCase {
|
||||
* column was not being skipped - but the query reads happily - only the data is
|
||||
* then wrong in the address object.
|
||||
*/
|
||||
@Test
|
||||
public void testJoinHierarchyAssocOne() {
|
||||
|
||||
Ebean.createUpdate(Vehicle.class, "delete from vehicle");
|
||||
|
||||
@@ -2,17 +2,18 @@ package com.avaje.tests.basic;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.tests.model.basic.Contact;
|
||||
import com.avaje.tests.model.basic.Customer;
|
||||
import com.avaje.tests.model.basic.ResetBasicData;
|
||||
|
||||
public class TestLazyLoadEmptyOneToMany extends TestCase {
|
||||
public class TestLazyLoadEmptyOneToMany extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
@@ -4,17 +4,19 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.BeanState;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.tests.model.basic.Address;
|
||||
import com.avaje.tests.model.basic.Customer;
|
||||
import com.avaje.tests.model.basic.ResetBasicData;
|
||||
|
||||
public class TestLazyLoadInCache extends TestCase {
|
||||
public class TestLazyLoadInCache extends BaseTestCase {
|
||||
|
||||
|
||||
@Test
|
||||
public void testLoadInCache() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
@@ -3,24 +3,30 @@ package com.avaje.tests.basic;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.Query;
|
||||
import com.avaje.ebeaninternal.api.SpiEbeanServer;
|
||||
import com.avaje.tests.model.basic.Order;
|
||||
import com.avaje.tests.model.basic.ResetBasicData;
|
||||
|
||||
public class TestLimitQuery extends TestCase {
|
||||
|
||||
public class TestLimitQuery extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void testNothing() {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLimitWithMany() {
|
||||
rob();
|
||||
rob();
|
||||
}
|
||||
|
||||
private void rob() {
|
||||
ResetBasicData.reset();
|
||||
|
||||
|
||||
@@ -3,14 +3,17 @@ package com.avaje.tests.basic;
|
||||
import java.util.Map;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.tests.model.basic.Country;
|
||||
import com.avaje.tests.model.basic.ResetBasicData;
|
||||
|
||||
public class TestLoadBeanCache extends TestCase {
|
||||
public class TestLoadBeanCache extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void testLoad() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
@@ -2,10 +2,10 @@ package com.avaje.tests.basic;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.Transaction;
|
||||
import com.avaje.tests.model.basic.Customer;
|
||||
@@ -13,72 +13,71 @@ import com.avaje.tests.model.basic.EBasicVer;
|
||||
import com.avaje.tests.model.basic.Order;
|
||||
import com.avaje.tests.model.basic.ResetBasicData;
|
||||
|
||||
public class TestLogTransLogOnError extends TestCase {
|
||||
public class TestLogTransLogOnError extends BaseTestCase {
|
||||
|
||||
public void testQueryError() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
Transaction t = Ebean.beginTransaction();
|
||||
try {
|
||||
//t.log("--- hello");
|
||||
Ebean.find(Customer.class).findList();
|
||||
Ebean.find(Order.class).where().gt("id", 1).findList();
|
||||
|
||||
EBasicVer newBean = new EBasicVer();
|
||||
newBean.setDescription("something");
|
||||
newBean.setName("aName");
|
||||
|
||||
//Ebean.save(newBean);
|
||||
|
||||
//t.log("--- next query should error");
|
||||
List<Customer> list = Ebean.find(Customer.class)
|
||||
.where().eq("id", "NotAnInt!!")
|
||||
.findList();
|
||||
|
||||
Assert.assertEquals(0, list.size());
|
||||
// Get here with mysql?
|
||||
//Assert.assertTrue(false);
|
||||
|
||||
} catch (RuntimeException e){
|
||||
//e.printStackTrace();
|
||||
Assert.assertTrue(true);
|
||||
|
||||
} finally {
|
||||
Ebean.endTransaction();
|
||||
}
|
||||
@Test
|
||||
public void testQueryError() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
Transaction t = Ebean.beginTransaction();
|
||||
try {
|
||||
// t.log("--- hello");
|
||||
Ebean.find(Customer.class).findList();
|
||||
Ebean.find(Order.class).where().gt("id", 1).findList();
|
||||
|
||||
EBasicVer newBean = new EBasicVer();
|
||||
newBean.setDescription("something");
|
||||
newBean.setName("aName");
|
||||
|
||||
// Ebean.save(newBean);
|
||||
|
||||
// t.log("--- next query should error");
|
||||
List<Customer> list = Ebean.find(Customer.class).where().eq("id", "NotAnInt!!").findList();
|
||||
|
||||
Assert.assertEquals(0, list.size());
|
||||
// Get here with mysql?
|
||||
// Assert.assertTrue(false);
|
||||
|
||||
} catch (RuntimeException e) {
|
||||
// e.printStackTrace();
|
||||
Assert.assertTrue(true);
|
||||
|
||||
} finally {
|
||||
Ebean.endTransaction();
|
||||
}
|
||||
|
||||
public void testPersistError() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
Transaction t = Ebean.beginTransaction();
|
||||
try {
|
||||
//t.log("--- hello testPersistError");
|
||||
Ebean.find(Customer.class).findList();
|
||||
|
||||
EBasicVer newBean = new EBasicVer();
|
||||
newBean.setDescription("something sdfjksdjflsjdflsjdflksjdfkjd fsjdfkjsdkfjsdkfjskdjfskjdf"
|
||||
+" sjdf sdjflksjdfkjsdlfkjsdkfjs ksjdfksjdlfjsldf something sdfjksdjflsjdflsjdflksjdfkjd"
|
||||
+"fsjdfkjsdkfjsdkfjskdjfskjdf sjdf sdjflksjdfkjsdlfkjsdkfjs ksjdfksjdlfjsldf something s"
|
||||
+"dfjksdjflsjdflsjdflksjdfkjd fsjdfkjsdkfjsdkfjskdjfskjdf sjdf sdjflksjdfkjsdlfkjsdkfjs ");
|
||||
newBean.setName("aName");
|
||||
|
||||
//t.log("--- next insert should error");
|
||||
Ebean.save(newBean);
|
||||
|
||||
// never get here
|
||||
Assert.assertTrue(false);
|
||||
|
||||
} catch (RuntimeException e){
|
||||
//e.printStackTrace();
|
||||
Assert.assertTrue(true);
|
||||
|
||||
} finally {
|
||||
Ebean.endTransaction();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void testPersistError() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
Transaction t = Ebean.beginTransaction();
|
||||
try {
|
||||
// t.log("--- hello testPersistError");
|
||||
Ebean.find(Customer.class).findList();
|
||||
|
||||
EBasicVer newBean = new EBasicVer();
|
||||
newBean
|
||||
.setDescription("something sdfjksdjflsjdflsjdflksjdfkjd fsjdfkjsdkfjsdkfjskdjfskjdf"
|
||||
+ " sjdf sdjflksjdfkjsdlfkjsdkfjs ksjdfksjdlfjsldf something sdfjksdjflsjdflsjdflksjdfkjd"
|
||||
+ "fsjdfkjsdkfjsdkfjskdjfskjdf sjdf sdjflksjdfkjsdlfkjsdkfjs ksjdfksjdlfjsldf something s"
|
||||
+ "dfjksdjflsjdflsjdflksjdfkjd fsjdfkjsdkfjsdkfjskdjfskjdf sjdf sdjflksjdfkjsdlfkjsdkfjs ");
|
||||
newBean.setName("aName");
|
||||
|
||||
// t.log("--- next insert should error");
|
||||
Ebean.save(newBean);
|
||||
|
||||
// never get here
|
||||
Assert.assertTrue(false);
|
||||
|
||||
} catch (RuntimeException e) {
|
||||
// e.printStackTrace();
|
||||
Assert.assertTrue(true);
|
||||
|
||||
} finally {
|
||||
Ebean.endTransaction();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,42 +2,44 @@ package com.avaje.tests.basic;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.common.BeanList;
|
||||
import com.avaje.tests.model.basic.MRole;
|
||||
import com.avaje.tests.model.basic.MUser;
|
||||
|
||||
public class TestM2MCascadeOne extends TestCase {
|
||||
public class TestM2MCascadeOne extends BaseTestCase {
|
||||
|
||||
public void test() {
|
||||
|
||||
MUser u = new MUser();
|
||||
u.setUserName("testM2M");
|
||||
|
||||
List<MRole> roles = u.getRoles();
|
||||
if (roles != null){
|
||||
if (roles instanceof BeanList<?>){
|
||||
System.out.println("enhancement checkNullManyFields=true successful");
|
||||
}
|
||||
}
|
||||
|
||||
Ebean.save(u);
|
||||
|
||||
MRole r0 = new MRole();
|
||||
r0.setRoleName("rol_0");
|
||||
Ebean.save(r0);
|
||||
|
||||
MRole r1 = new MRole();
|
||||
r1.setRoleName("rol_1");
|
||||
|
||||
MUser u1 = Ebean.find(MUser.class, u.getUserid());
|
||||
|
||||
u1.addRole(r0);
|
||||
u1.addRole(r1);
|
||||
|
||||
Ebean.save(u1);
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
MUser u = new MUser();
|
||||
u.setUserName("testM2M");
|
||||
|
||||
List<MRole> roles = u.getRoles();
|
||||
if (roles != null) {
|
||||
if (roles instanceof BeanList<?>) {
|
||||
System.out.println("enhancement checkNullManyFields=true successful");
|
||||
}
|
||||
}
|
||||
|
||||
Ebean.save(u);
|
||||
|
||||
MRole r0 = new MRole();
|
||||
r0.setRoleName("rol_0");
|
||||
Ebean.save(r0);
|
||||
|
||||
MRole r1 = new MRole();
|
||||
r1.setRoleName("rol_1");
|
||||
|
||||
MUser u1 = Ebean.find(MUser.class, u.getUserid());
|
||||
|
||||
u1.addRole(r0);
|
||||
u1.addRole(r1);
|
||||
|
||||
Ebean.save(u1);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,99 +4,93 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.Query;
|
||||
import com.avaje.tests.model.basic.MRole;
|
||||
import com.avaje.tests.model.basic.MUser;
|
||||
|
||||
public class TestM2MVanilla extends TestCase {
|
||||
public class TestM2MVanilla extends BaseTestCase {
|
||||
|
||||
public void testVanilla() {
|
||||
@Test
|
||||
public void testVanilla() {
|
||||
|
||||
MRole r1 = new MRole();
|
||||
r1.setRoleName("role1");
|
||||
Ebean.save(r1);
|
||||
MRole r1 = new MRole();
|
||||
r1.setRoleName("role1");
|
||||
Ebean.save(r1);
|
||||
|
||||
MRole r2 = new MRole();
|
||||
r2.setRoleName("role2");
|
||||
Ebean.save(r2);
|
||||
MRole r2 = new MRole();
|
||||
r2.setRoleName("role2");
|
||||
Ebean.save(r2);
|
||||
|
||||
MRole r3 = new MRole();
|
||||
r3.setRoleName("role3");
|
||||
Ebean.save(r3);
|
||||
MRole r3 = new MRole();
|
||||
r3.setRoleName("role3");
|
||||
Ebean.save(r3);
|
||||
|
||||
MUser u0 = new MUser();
|
||||
u0.setUserName("something");
|
||||
MUser u0 = new MUser();
|
||||
u0.setUserName("something");
|
||||
|
||||
Ebean.save(u0);
|
||||
Ebean.save(u0);
|
||||
|
||||
MUser user = Ebean.find(MUser.class, u0.getUserid());
|
||||
MUser user = Ebean.find(MUser.class, u0.getUserid());
|
||||
|
||||
List<MRole> roleList = new ArrayList<MRole>();
|
||||
roleList.add(r1);
|
||||
roleList.add(r2);
|
||||
List<MRole> roleList = new ArrayList<MRole>();
|
||||
roleList.add(r1);
|
||||
roleList.add(r2);
|
||||
|
||||
user.setRoles(roleList);
|
||||
user.setRoles(roleList);
|
||||
|
||||
Ebean.save(user);
|
||||
//Ebean.saveManyToManyAssociations(user, "roles");
|
||||
Ebean.save(user);
|
||||
// Ebean.saveManyToManyAssociations(user, "roles");
|
||||
|
||||
MUser checkUser = Ebean.find(MUser.class, u0.getUserid());
|
||||
List<MRole> checkRoles = checkUser.getRoles();
|
||||
Assert.assertNotNull(checkRoles);
|
||||
Assert.assertEquals(2, checkRoles.size());
|
||||
MUser checkUser = Ebean.find(MUser.class, u0.getUserid());
|
||||
List<MRole> checkRoles = checkUser.getRoles();
|
||||
Assert.assertNotNull(checkRoles);
|
||||
Assert.assertEquals(2, checkRoles.size());
|
||||
|
||||
checkRoles.add(r3);
|
||||
|
||||
Ebean.save(checkUser);
|
||||
//Ebean.saveManyToManyAssociations(checkUser, "roles");
|
||||
|
||||
MUser checkUser2 = Ebean.find(MUser.class, u0.getUserid());
|
||||
List<MRole> checkRoles2 = checkUser2.getRoles();
|
||||
Assert.assertNotNull(checkRoles2);
|
||||
Assert.assertEquals("added a role", 3, checkRoles2.size());
|
||||
checkRoles.add(r3);
|
||||
|
||||
Query<MUser> rolesQuery0 = Ebean.find(MUser.class)
|
||||
.where().eq("roles", r1)
|
||||
.query();
|
||||
|
||||
rolesQuery0.findList();
|
||||
Ebean.save(checkUser);
|
||||
// Ebean.saveManyToManyAssociations(checkUser, "roles");
|
||||
|
||||
Query<MUser> rolesQuery = Ebean.find(MUser.class)
|
||||
.where().in("roles", roleList)
|
||||
.query();
|
||||
|
||||
List<MUser> userInRolesList = rolesQuery.findList();
|
||||
Assert.assertTrue(userInRolesList.size() > 0);
|
||||
|
||||
List<MUser> list = Ebean.find(MUser.class)
|
||||
.where().in("roles", roleList)
|
||||
.filterMany("roles").eq("roleName", "role1")
|
||||
.findList();
|
||||
|
||||
MUser mUser = list.get(0);
|
||||
List<MRole> roles = mUser.getRoles();
|
||||
Assert.assertEquals(1, roles.size());
|
||||
|
||||
Ebean.refreshMany(mUser, "roles");
|
||||
Assert.assertEquals(1, mUser.getRoles().size());
|
||||
|
||||
|
||||
checkRoles2.remove(0);
|
||||
checkRoles2.remove(0);
|
||||
Ebean.saveManyToManyAssociations(checkUser2,"roles");
|
||||
|
||||
MUser checkUser2 = Ebean.find(MUser.class, u0.getUserid());
|
||||
List<MRole> checkRoles2 = checkUser2.getRoles();
|
||||
Assert.assertNotNull(checkRoles2);
|
||||
Assert.assertEquals("added a role", 3, checkRoles2.size());
|
||||
|
||||
checkUser2 = Ebean.find(MUser.class, u0.getUserid());
|
||||
checkRoles2 = checkUser2.getRoles();
|
||||
Assert.assertNotNull(checkRoles2);
|
||||
Assert.assertEquals("added a role", 1, checkRoles2.size());
|
||||
Query<MUser> rolesQuery0 = Ebean.find(MUser.class).where().eq("roles", r1).query();
|
||||
|
||||
|
||||
Ebean.delete(checkUser2);
|
||||
|
||||
}
|
||||
rolesQuery0.findList();
|
||||
|
||||
Query<MUser> rolesQuery = Ebean.find(MUser.class).where().in("roles", roleList).query();
|
||||
|
||||
List<MUser> userInRolesList = rolesQuery.findList();
|
||||
Assert.assertTrue(userInRolesList.size() > 0);
|
||||
|
||||
List<MUser> list = Ebean.find(MUser.class).where().in("roles", roleList).filterMany("roles")
|
||||
.eq("roleName", "role1").findList();
|
||||
|
||||
MUser mUser = list.get(0);
|
||||
List<MRole> roles = mUser.getRoles();
|
||||
Assert.assertEquals(1, roles.size());
|
||||
|
||||
Ebean.refreshMany(mUser, "roles");
|
||||
Assert.assertEquals(1, mUser.getRoles().size());
|
||||
|
||||
checkRoles2.remove(0);
|
||||
checkRoles2.remove(0);
|
||||
Ebean.saveManyToManyAssociations(checkUser2, "roles");
|
||||
|
||||
checkUser2 = Ebean.find(MUser.class, u0.getUserid());
|
||||
checkRoles2 = checkUser2.getRoles();
|
||||
Assert.assertNotNull(checkRoles2);
|
||||
Assert.assertEquals("added a role", 1, checkRoles2.size());
|
||||
|
||||
Ebean.delete(checkUser2);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,16 +4,18 @@ import java.sql.Date;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.tests.model.basic.Order;
|
||||
import com.avaje.tests.model.basic.OrderDetail;
|
||||
import com.avaje.tests.model.basic.ResetBasicData;
|
||||
|
||||
public class TestManyLazyLoad extends TestCase {
|
||||
public class TestManyLazyLoad extends BaseTestCase {
|
||||
|
||||
|
||||
@Test
|
||||
public void testLazyLoadRef() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
@@ -2,16 +2,17 @@ package com.avaje.tests.basic;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.Query;
|
||||
import com.avaje.tests.model.basic.TMapSuperEntity;
|
||||
|
||||
public class TestMappedSuper extends TestCase {
|
||||
public class TestMappedSuper extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
TMapSuperEntity e = new TMapSuperEntity();
|
||||
|
||||
@@ -1,59 +1,61 @@
|
||||
package com.avaje.tests.basic;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.tests.model.basic.OCar;
|
||||
import com.avaje.tests.model.basic.OEngine;
|
||||
import com.avaje.tests.model.basic.OGearBox;
|
||||
|
||||
public class TestMultipleOneToOneIUD extends TestCase {
|
||||
public class TestMultipleOneToOneIUD extends BaseTestCase {
|
||||
|
||||
public void test() {
|
||||
|
||||
OEngine engine = new OEngine();
|
||||
engine.setShortDesc("engine 1");
|
||||
|
||||
OGearBox gearBox = new OGearBox();
|
||||
gearBox.setBoxDesc("6 speed manual");
|
||||
gearBox.setSize(6);
|
||||
|
||||
OCar car = new OCar();
|
||||
car.setVin("xx4534");
|
||||
car.setName("test car");
|
||||
car.setEngine(engine);
|
||||
|
||||
Ebean.beginTransaction();
|
||||
try {
|
||||
Ebean.save(gearBox);
|
||||
Ebean.save(car);
|
||||
|
||||
assertNotNull(car.getId());
|
||||
assertNotNull(engine.getEngineId());
|
||||
assertNotNull(gearBox.getId());
|
||||
|
||||
Ebean.commitTransaction();
|
||||
|
||||
} finally {
|
||||
Ebean.endTransaction();
|
||||
}
|
||||
|
||||
OCar c2 = Ebean.find(OCar.class, car.getId());
|
||||
assertNotNull(c2);
|
||||
assertNotNull(c2.getEngine());
|
||||
// gearBox not assigned yet
|
||||
assertNull(c2.getGearBox());
|
||||
|
||||
// ok, assign gearBox
|
||||
c2.setGearBox(gearBox);
|
||||
Ebean.save(c2);
|
||||
|
||||
// now all should be there...
|
||||
OCar c3 = Ebean.find(OCar.class, car.getId());
|
||||
assertNotNull(c3);
|
||||
assertNotNull(c3.getEngine());
|
||||
assertNotNull(c3.getGearBox());
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
|
||||
OEngine engine = new OEngine();
|
||||
engine.setShortDesc("engine 1");
|
||||
|
||||
OGearBox gearBox = new OGearBox();
|
||||
gearBox.setBoxDesc("6 speed manual");
|
||||
gearBox.setSize(6);
|
||||
|
||||
OCar car = new OCar();
|
||||
car.setVin("xx4534");
|
||||
car.setName("test car");
|
||||
car.setEngine(engine);
|
||||
|
||||
Ebean.beginTransaction();
|
||||
try {
|
||||
Ebean.save(gearBox);
|
||||
Ebean.save(car);
|
||||
|
||||
Assert.assertNotNull(car.getId());
|
||||
Assert.assertNotNull(engine.getEngineId());
|
||||
Assert.assertNotNull(gearBox.getId());
|
||||
|
||||
Ebean.commitTransaction();
|
||||
|
||||
} finally {
|
||||
Ebean.endTransaction();
|
||||
}
|
||||
|
||||
OCar c2 = Ebean.find(OCar.class, car.getId());
|
||||
Assert.assertNotNull(c2);
|
||||
Assert.assertNotNull(c2.getEngine());
|
||||
// gearBox not assigned yet
|
||||
Assert.assertNull(c2.getGearBox());
|
||||
|
||||
// ok, assign gearBox
|
||||
c2.setGearBox(gearBox);
|
||||
Ebean.save(c2);
|
||||
|
||||
// now all should be there...
|
||||
OCar c3 = Ebean.find(OCar.class, car.getId());
|
||||
Assert.assertNotNull(c3);
|
||||
Assert.assertNotNull(c3.getEngine());
|
||||
Assert.assertNotNull(c3.getGearBox());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,24 +1,26 @@
|
||||
package com.avaje.tests.basic;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.tests.model.basic.MNonUpdPropEntity;
|
||||
|
||||
public class TestNonUpdateProperty extends TestCase {
|
||||
public class TestNonUpdateProperty extends BaseTestCase {
|
||||
|
||||
public void test() {
|
||||
|
||||
MNonUpdPropEntity e = new MNonUpdPropEntity();
|
||||
e.setName("name");
|
||||
e.setNote("note");
|
||||
|
||||
Ebean.save(e);
|
||||
|
||||
MNonUpdPropEntity e2 = Ebean.find(MNonUpdPropEntity.class, e.getId());
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
e2.setName("mod");
|
||||
Ebean.update(e2);
|
||||
|
||||
}
|
||||
MNonUpdPropEntity e = new MNonUpdPropEntity();
|
||||
e.setName("name");
|
||||
e.setNote("note");
|
||||
|
||||
Ebean.save(e);
|
||||
|
||||
MNonUpdPropEntity e2 = Ebean.find(MNonUpdPropEntity.class, e.getId());
|
||||
|
||||
e2.setName("mod");
|
||||
Ebean.update(e2);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,16 +3,19 @@ package com.avaje.tests.basic;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.Query;
|
||||
import com.avaje.tests.model.basic.Customer;
|
||||
import com.avaje.tests.model.basic.Order;
|
||||
import com.avaje.tests.model.basic.ResetBasicData;
|
||||
|
||||
public class TestOrderByAnnotation extends TestCase {
|
||||
public class TestOrderByAnnotation extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void testOrderBy() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
@@ -2,36 +2,35 @@ package com.avaje.tests.basic;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.tests.model.basic.Customer;
|
||||
import com.avaje.tests.model.basic.Order;
|
||||
import com.avaje.tests.model.basic.ResetBasicData;
|
||||
|
||||
public class TestOrderTotalAmountFormula extends TestCase {
|
||||
public class TestOrderTotalAmountFormula extends BaseTestCase {
|
||||
|
||||
public void testAsJoin() {
|
||||
@Test
|
||||
public void testAsJoin() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
List<Customer> l0 = Ebean.find(Customer.class)
|
||||
.select("id, name")
|
||||
.fetch("orders", "status, totalAmount")
|
||||
.where()
|
||||
.eq("orders.details.product.name", "Desk")
|
||||
.like("contacts.firstName", "Ji%")
|
||||
ResetBasicData.reset();
|
||||
|
||||
.findList();
|
||||
List<Customer> l0 = Ebean.find(Customer.class).select("id, name")
|
||||
.fetch("orders", "status, totalAmount").where().eq("orders.details.product.name", "Desk")
|
||||
.like("contacts.firstName", "Ji%")
|
||||
|
||||
for (Customer c0 : l0) {
|
||||
System.out.println("customer: "+c0.getId());
|
||||
List<Order> orders = c0.getOrders();
|
||||
for (Order order : orders) {
|
||||
System.out.println("... order:"+order);
|
||||
}
|
||||
}
|
||||
.findList();
|
||||
|
||||
for (Customer c0 : l0) {
|
||||
System.out.println("customer: " + c0.getId());
|
||||
List<Order> orders = c0.getOrders();
|
||||
for (Order order : orders) {
|
||||
System.out.println("... order:" + order);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,52 +3,46 @@ package com.avaje.tests.basic;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.tests.model.basic.OrderAggregate;
|
||||
import com.avaje.tests.model.basic.ResetBasicData;
|
||||
|
||||
public class TestOrderTotalAmountReportBean extends TestCase {
|
||||
public class TestOrderTotalAmountReportBean extends BaseTestCase {
|
||||
|
||||
public void test() {
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
ResetBasicData.reset();
|
||||
|
||||
List<OrderAggregate> l0 =
|
||||
Ebean.find(OrderAggregate.class)
|
||||
.findList();
|
||||
|
||||
for (OrderAggregate r0 : l0) {
|
||||
System.out.println(r0);
|
||||
}
|
||||
|
||||
List<OrderAggregate> list =
|
||||
Ebean.createNamedQuery(OrderAggregate.class,"total.amount")
|
||||
.where().gt("order.id", 0)
|
||||
.having().gt("totalAmount", 50)
|
||||
.findList();
|
||||
|
||||
for (OrderAggregate r1 : list) {
|
||||
System.out.println(r1);
|
||||
Assert.assertTrue(r1.getTotalAmount() > 20.50);
|
||||
// partial object query without totalItems
|
||||
// ... no lazy loading invoked on this type of bean
|
||||
Assert.assertTrue(r1.getTotalItems() == null);
|
||||
}
|
||||
|
||||
|
||||
List<OrderAggregate> l2 =
|
||||
Ebean.createQuery(OrderAggregate.class)
|
||||
.where().gt("order.id", 0)
|
||||
.having().lt("totalItems", 3).gt("totalAmount", 50)
|
||||
.findList();
|
||||
|
||||
for (OrderAggregate r2 : l2) {
|
||||
//System.out.println(r2);
|
||||
Assert.assertTrue(r2.getTotalItems() < 3);
|
||||
}
|
||||
|
||||
List<OrderAggregate> l0 = Ebean.find(OrderAggregate.class).findList();
|
||||
|
||||
for (OrderAggregate r0 : l0) {
|
||||
System.out.println(r0);
|
||||
}
|
||||
|
||||
List<OrderAggregate> list = Ebean.createNamedQuery(OrderAggregate.class, "total.amount")
|
||||
.where().gt("order.id", 0).having().gt("totalAmount", 50).findList();
|
||||
|
||||
for (OrderAggregate r1 : list) {
|
||||
System.out.println(r1);
|
||||
Assert.assertTrue(r1.getTotalAmount() > 20.50);
|
||||
// partial object query without totalItems
|
||||
// ... no lazy loading invoked on this type of bean
|
||||
Assert.assertTrue(r1.getTotalItems() == null);
|
||||
}
|
||||
|
||||
List<OrderAggregate> l2 = Ebean.createQuery(OrderAggregate.class).where().gt("order.id", 0)
|
||||
.having().lt("totalItems", 3).gt("totalAmount", 50).findList();
|
||||
|
||||
for (OrderAggregate r2 : l2) {
|
||||
// System.out.println(r2);
|
||||
Assert.assertTrue(r2.getTotalItems() < 3);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,30 +3,30 @@ package com.avaje.tests.basic;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.SqlRow;
|
||||
import com.avaje.tests.model.basic.ResetBasicData;
|
||||
|
||||
public class TestOrderTotalAmountSql extends TestCase {
|
||||
public class TestOrderTotalAmountSql extends BaseTestCase {
|
||||
|
||||
public void test() {
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
ResetBasicData.reset();
|
||||
|
||||
String sql = "select order_id, sum(order_qty*unit_price) as total_amount from o_order_detail where order_qty > :minQty group by order_id";
|
||||
List<SqlRow> sqlRows =
|
||||
Ebean.createSqlQuery(sql)
|
||||
.setParameter("minQty",1)
|
||||
.findList();
|
||||
|
||||
for (SqlRow sqlRow : sqlRows) {
|
||||
Integer id = sqlRow.getInteger("order_id");
|
||||
Double amount = sqlRow.getDouble("total_amount");
|
||||
Assert.assertNotNull("sqlRows: "+sqlRows,id);
|
||||
Assert.assertNotNull("sqlRows: "+sqlRows,amount);
|
||||
}
|
||||
String sql = "select order_id, sum(order_qty*unit_price) as total_amount from o_order_detail where order_qty > :minQty group by order_id";
|
||||
List<SqlRow> sqlRows = Ebean.createSqlQuery(sql).setParameter("minQty", 1).findList();
|
||||
|
||||
for (SqlRow sqlRow : sqlRows) {
|
||||
Integer id = sqlRow.getInteger("order_id");
|
||||
Double amount = sqlRow.getDouble("total_amount");
|
||||
Assert.assertNotNull("sqlRows: " + sqlRows, id);
|
||||
Assert.assertNotNull("sqlRows: " + sqlRows, amount);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,8 +4,10 @@ import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.EbeanServer;
|
||||
import com.avaje.ebean.Page;
|
||||
@@ -13,7 +15,7 @@ import com.avaje.ebean.PagingList;
|
||||
import com.avaje.ebean.Query;
|
||||
import com.avaje.tests.model.basic.TOne;
|
||||
|
||||
public class TestPaging extends TestCase {
|
||||
public class TestPaging extends BaseTestCase {
|
||||
|
||||
|
||||
private void loadData() {
|
||||
@@ -41,6 +43,7 @@ public class TestPaging extends TestCase {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() throws Exception {
|
||||
|
||||
loadData();
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
package com.avaje.tests.basic;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.tests.model.basic.Customer;
|
||||
import com.avaje.tests.model.basic.Order;
|
||||
import com.avaje.tests.model.basic.ResetBasicData;
|
||||
|
||||
public class TestPersistenceContext extends TestCase {
|
||||
public class TestPersistenceContext extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
@@ -1,59 +1,49 @@
|
||||
package com.avaje.tests.basic;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.Query;
|
||||
import com.avaje.tests.model.basic.Order;
|
||||
import com.avaje.tests.model.basic.ResetBasicData;
|
||||
|
||||
public class TestQuery extends TestCase
|
||||
{
|
||||
public class TestQuery extends BaseTestCase {
|
||||
|
||||
public void testCountOrderBy()
|
||||
{
|
||||
@Test
|
||||
public void testCountOrderBy() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
ResetBasicData.reset();
|
||||
|
||||
Query<Order> query = Ebean.find(Order.class)
|
||||
.setAutofetch(false)
|
||||
.order().asc("orderDate")
|
||||
.order().desc("id");
|
||||
//.orderBy("orderDate");
|
||||
Query<Order> query = Ebean.find(Order.class).setAutofetch(false).order().asc("orderDate")
|
||||
.order().desc("id");
|
||||
// .orderBy("orderDate");
|
||||
|
||||
int rc = query.findList().size();
|
||||
//int rc = query.findRowCount();
|
||||
Assert.assertTrue(rc > 0);
|
||||
//String generatedSql = query.getGeneratedSql();
|
||||
//Assert.assertFalse(generatedSql.contains("order by"));
|
||||
int rc = query.findList().size();
|
||||
// int rc = query.findRowCount();
|
||||
Assert.assertTrue(rc > 0);
|
||||
// String generatedSql = query.getGeneratedSql();
|
||||
// Assert.assertFalse(generatedSql.contains("order by"));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void testForUpdate()
|
||||
{
|
||||
ResetBasicData.reset();
|
||||
public void testForUpdate() {
|
||||
ResetBasicData.reset();
|
||||
|
||||
Query<Order> query = Ebean.find(Order.class)
|
||||
.setAutofetch(false)
|
||||
.setForUpdate(false)
|
||||
.setMaxRows(1)
|
||||
.order().asc("orderDate")
|
||||
.order().desc("id");
|
||||
|
||||
int rc = query.findList().size();
|
||||
Assert.assertTrue(rc > 0);
|
||||
assertTrue(query.getGeneratedSql().toLowerCase().indexOf("for update") < 0);
|
||||
Query<Order> query = Ebean.find(Order.class).setAutofetch(false).setForUpdate(false)
|
||||
.setMaxRows(1).order().asc("orderDate").order().desc("id");
|
||||
|
||||
query = Ebean.find(Order.class)
|
||||
.setAutofetch(false)
|
||||
.setForUpdate(true)
|
||||
.setMaxRows(1)
|
||||
.order().asc("orderDate")
|
||||
.order().desc("id");
|
||||
int rc = query.findList().size();
|
||||
Assert.assertTrue(rc > 0);
|
||||
Assert.assertTrue(query.getGeneratedSql().toLowerCase().indexOf("for update") < 0);
|
||||
|
||||
rc = query.findList().size();
|
||||
Assert.assertTrue(rc > 0);
|
||||
assertTrue(query.getGeneratedSql().toLowerCase().indexOf("for update") > -1);
|
||||
}
|
||||
query = Ebean.find(Order.class).setAutofetch(false).setForUpdate(true).setMaxRows(1).order()
|
||||
.asc("orderDate").order().desc("id");
|
||||
|
||||
rc = query.findList().size();
|
||||
Assert.assertTrue(rc > 0);
|
||||
Assert.assertTrue(query.getGeneratedSql().toLowerCase().indexOf("for update") > -1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,19 @@
|
||||
package com.avaje.tests.basic;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.OrderBy;
|
||||
import com.avaje.ebean.Query;
|
||||
import com.avaje.tests.model.basic.Order;
|
||||
import com.avaje.tests.model.basic.ResetBasicData;
|
||||
|
||||
public class TestQueryParse extends TestCase {
|
||||
public class TestQueryParse extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
//GlobalProperties.put("ebean.ddl.generate", "false");
|
||||
//GlobalProperties.put("ebean.ddl.run", "false");
|
||||
|
||||
@@ -3,30 +3,30 @@ package com.avaje.tests.basic;
|
||||
import java.sql.Timestamp;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.Query;
|
||||
import com.avaje.tests.model.basic.Order;
|
||||
import com.avaje.tests.model.basic.ResetBasicData;
|
||||
|
||||
public class TestQueryWhereBetween extends TestCase {
|
||||
public class TestQueryWhereBetween extends BaseTestCase {
|
||||
|
||||
public void testCountOrderBy() {
|
||||
@Test
|
||||
public void testCountOrderBy() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
ResetBasicData.reset();
|
||||
|
||||
Timestamp t = new Timestamp(System.currentTimeMillis());
|
||||
Timestamp t = new Timestamp(System.currentTimeMillis());
|
||||
|
||||
Query<Order> query = Ebean.find(Order.class)
|
||||
.setAutofetch(false)
|
||||
.where().betweenProperties("cretime","updtime", t)
|
||||
.order().asc("orderDate")
|
||||
.order().desc("id");
|
||||
Query<Order> query = Ebean.find(Order.class).setAutofetch(false).where()
|
||||
.betweenProperties("cretime", "updtime", t).order().asc("orderDate").order().desc("id");
|
||||
|
||||
query.findList();
|
||||
query.findList();
|
||||
|
||||
String sql = query.getGeneratedSql();
|
||||
Assert.assertTrue(sql.indexOf("between t0.cretime and t0.updtime") > -1);
|
||||
}
|
||||
String sql = query.getGeneratedSql();
|
||||
Assert.assertTrue(sql.indexOf("between t0.cretime and t0.updtime") > -1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package com.avaje.tests.basic;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.cache.ServerCache;
|
||||
import com.avaje.ebean.cache.ServerCacheManager;
|
||||
@@ -12,109 +14,106 @@ import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
|
||||
import com.avaje.tests.model.basic.Country;
|
||||
import com.avaje.tests.model.basic.ResetBasicData;
|
||||
|
||||
public class TestQueryWithCache extends TestCase {
|
||||
public class TestQueryWithCache extends BaseTestCase {
|
||||
|
||||
|
||||
// public void testJoinCache() {
|
||||
//
|
||||
// ResetBasicData.reset();
|
||||
//
|
||||
// Ebean.getServer(null).runCacheWarming();
|
||||
//
|
||||
// Query<Order> query = Ebean.createQuery(Order.class)
|
||||
// .setAutofetch(false)
|
||||
// .fetch("customer","+cache +readonly")
|
||||
// .setId(1);
|
||||
//
|
||||
// Order order = query.findUnique();
|
||||
// Customer customer = order.getCustomer();
|
||||
// Assert.assertTrue(Ebean.getBeanState(customer).isReadOnly());
|
||||
//
|
||||
//// // invoke lazy loading
|
||||
//// customer.getName();
|
||||
////
|
||||
//// order = query.findUnique();
|
||||
//// customer = order.getCustomer();
|
||||
//// custState = Ebean.getBeanState(customer);
|
||||
//// Assert.assertFalse(custState.isReadOnly());
|
||||
//
|
||||
// }
|
||||
//
|
||||
// public void testFindId() {
|
||||
//
|
||||
// ResetBasicData.reset();
|
||||
//
|
||||
// Order o = Ebean.find(Order.class)
|
||||
// .setUseCache(true)
|
||||
// .setReadOnly(true)
|
||||
// .setId(1)
|
||||
// .findUnique();
|
||||
//
|
||||
// BeanState beanState = Ebean.getBeanState(o);
|
||||
// Assert.assertTrue(beanState.isReadOnly());
|
||||
//
|
||||
// Order o2 = Ebean.find(Order.class)
|
||||
// .setUseCache(true)
|
||||
// .setReadOnly(true)
|
||||
// .setId(1)
|
||||
// .findUnique();
|
||||
//
|
||||
// BeanState beanState2 = Ebean.getBeanState(o2);
|
||||
//
|
||||
// // same instance as readOnly = true
|
||||
// Assert.assertTrue("not same instance", o != o2);
|
||||
// Assert.assertTrue(beanState2.isReadOnly());
|
||||
//
|
||||
// Order o3 = Ebean.find(Order.class)
|
||||
// .setUseCache(true)
|
||||
// .setReadOnly(false)
|
||||
// .setId(1)
|
||||
// .findUnique();
|
||||
//
|
||||
// // NOT the same instance as readOnly = false
|
||||
// Assert.assertTrue("not same instance", o != o3);
|
||||
// }
|
||||
|
||||
public void testCountryDeploy() {
|
||||
// public void testJoinCache() {
|
||||
//
|
||||
// ResetBasicData.reset();
|
||||
//
|
||||
// Ebean.getServer(null).runCacheWarming();
|
||||
//
|
||||
// Query<Order> query = Ebean.createQuery(Order.class)
|
||||
// .setAutofetch(false)
|
||||
// .fetch("customer","+cache +readonly")
|
||||
// .setId(1);
|
||||
//
|
||||
// Order order = query.findUnique();
|
||||
// Customer customer = order.getCustomer();
|
||||
// Assert.assertTrue(Ebean.getBeanState(customer).isReadOnly());
|
||||
//
|
||||
// // // invoke lazy loading
|
||||
// // customer.getName();
|
||||
// //
|
||||
// // order = query.findUnique();
|
||||
// // customer = order.getCustomer();
|
||||
// // custState = Ebean.getBeanState(customer);
|
||||
// // Assert.assertFalse(custState.isReadOnly());
|
||||
//
|
||||
// }
|
||||
//
|
||||
// public void testFindId() {
|
||||
//
|
||||
// ResetBasicData.reset();
|
||||
//
|
||||
// Order o = Ebean.find(Order.class)
|
||||
// .setUseCache(true)
|
||||
// .setReadOnly(true)
|
||||
// .setId(1)
|
||||
// .findUnique();
|
||||
//
|
||||
// BeanState beanState = Ebean.getBeanState(o);
|
||||
// Assert.assertTrue(beanState.isReadOnly());
|
||||
//
|
||||
// Order o2 = Ebean.find(Order.class)
|
||||
// .setUseCache(true)
|
||||
// .setReadOnly(true)
|
||||
// .setId(1)
|
||||
// .findUnique();
|
||||
//
|
||||
// BeanState beanState2 = Ebean.getBeanState(o2);
|
||||
//
|
||||
// // same instance as readOnly = true
|
||||
// Assert.assertTrue("not same instance", o != o2);
|
||||
// Assert.assertTrue(beanState2.isReadOnly());
|
||||
//
|
||||
// Order o3 = Ebean.find(Order.class)
|
||||
// .setUseCache(true)
|
||||
// .setReadOnly(false)
|
||||
// .setId(1)
|
||||
// .findUnique();
|
||||
//
|
||||
// // NOT the same instance as readOnly = false
|
||||
// Assert.assertTrue("not same instance", o != o3);
|
||||
// }
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
SpiEbeanServer server = (SpiEbeanServer)Ebean.getServer(null);
|
||||
BeanDescriptor<Country> beanDescriptor = server.getBeanDescriptor(Country.class);
|
||||
CacheOptions cacheOptions = beanDescriptor.getCacheOptions();
|
||||
|
||||
Assert.assertNotNull(cacheOptions);
|
||||
Assert.assertTrue(cacheOptions.isUseCache());
|
||||
Assert.assertTrue(cacheOptions.isReadOnly());
|
||||
Assert.assertTrue(beanDescriptor.isCacheSharableBeans());
|
||||
|
||||
ServerCacheManager serverCacheManager = server.getServerCacheManager();
|
||||
serverCacheManager.clear(Country.class);
|
||||
|
||||
ServerCache beanCache = serverCacheManager.getBeanCache(Country.class);
|
||||
Assert.assertEquals(0, beanCache.size());
|
||||
|
||||
Country nz1 = Ebean.getReference(Country.class, "NZ");
|
||||
Assert.assertEquals(0, beanCache.size());
|
||||
|
||||
// has the effect of loading the cache via lazy loading
|
||||
nz1.getName();
|
||||
Assert.assertEquals(1, beanCache.size());
|
||||
|
||||
Country nz2 = Ebean.getReference(Country.class, "NZ");
|
||||
Country nz2b = Ebean.getReference(Country.class, "NZ");
|
||||
|
||||
Country nz3 = Ebean.find(Country.class, "NZ");
|
||||
@Test
|
||||
public void testCountryDeploy() {
|
||||
|
||||
Country nz4 = Ebean.find(Country.class)
|
||||
.setId("NZ")
|
||||
.setAutofetch(false)
|
||||
.setUseCache(false)
|
||||
.findUnique();
|
||||
|
||||
Assert.assertTrue(nz2 == nz2b);
|
||||
Assert.assertTrue(nz2 == nz3);
|
||||
Assert.assertTrue(nz3 != nz4);
|
||||
|
||||
}
|
||||
ResetBasicData.reset();
|
||||
|
||||
SpiEbeanServer server = (SpiEbeanServer) Ebean.getServer(null);
|
||||
BeanDescriptor<Country> beanDescriptor = server.getBeanDescriptor(Country.class);
|
||||
CacheOptions cacheOptions = beanDescriptor.getCacheOptions();
|
||||
|
||||
Assert.assertNotNull(cacheOptions);
|
||||
Assert.assertTrue(cacheOptions.isUseCache());
|
||||
Assert.assertTrue(cacheOptions.isReadOnly());
|
||||
Assert.assertTrue(beanDescriptor.isCacheSharableBeans());
|
||||
|
||||
ServerCacheManager serverCacheManager = server.getServerCacheManager();
|
||||
serverCacheManager.clear(Country.class);
|
||||
|
||||
ServerCache beanCache = serverCacheManager.getBeanCache(Country.class);
|
||||
Assert.assertEquals(0, beanCache.size());
|
||||
|
||||
Country nz1 = Ebean.getReference(Country.class, "NZ");
|
||||
Assert.assertEquals(0, beanCache.size());
|
||||
|
||||
// has the effect of loading the cache via lazy loading
|
||||
nz1.getName();
|
||||
Assert.assertEquals(1, beanCache.size());
|
||||
|
||||
Country nz2 = Ebean.getReference(Country.class, "NZ");
|
||||
Country nz2b = Ebean.getReference(Country.class, "NZ");
|
||||
|
||||
Country nz3 = Ebean.find(Country.class, "NZ");
|
||||
|
||||
Country nz4 = Ebean.find(Country.class).setId("NZ").setAutofetch(false).setUseCache(false)
|
||||
.findUnique();
|
||||
|
||||
Assert.assertTrue(nz2 == nz2b);
|
||||
Assert.assertTrue(nz2 == nz3);
|
||||
Assert.assertTrue(nz3 != nz4);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,8 +5,10 @@ import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.bean.BeanCollection;
|
||||
import com.avaje.tests.model.basic.Address;
|
||||
@@ -15,8 +17,9 @@ import com.avaje.tests.model.basic.Order;
|
||||
import com.avaje.tests.model.basic.OrderDetail;
|
||||
import com.avaje.tests.model.basic.ResetBasicData;
|
||||
|
||||
public class TestReadOnlyPropagation extends TestCase {
|
||||
public class TestReadOnlyPropagation extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void testReadOnly() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
package com.avaje.tests.basic;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.tests.model.basic.PersistentFile;
|
||||
import com.avaje.tests.model.basic.PersistentFileContent;
|
||||
|
||||
public class TestSaveDeleteOneToOne extends TestCase {
|
||||
public class TestSaveDeleteOneToOne extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void testCreateDeletePersistentFile() {
|
||||
PersistentFile persistentFile = new PersistentFile("test.txt",
|
||||
new PersistentFileContent("test".getBytes()));
|
||||
@@ -17,6 +20,7 @@ public class TestSaveDeleteOneToOne extends TestCase {
|
||||
Ebean.delete(persistentFile);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateLoadDeletePersistentFile() {
|
||||
PersistentFile persistentFile = new PersistentFile("test.txt",
|
||||
new PersistentFileContent("test".getBytes()));
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
package com.avaje.tests.basic;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.tests.model.basic.PFile;
|
||||
import com.avaje.tests.model.basic.PFileContent;
|
||||
|
||||
public class TestSaveDeleteOneToOneMultiple extends TestCase {
|
||||
public class TestSaveDeleteOneToOneMultiple extends BaseTestCase {
|
||||
|
||||
// public void testCreateDeletePFile() {
|
||||
// PFile persistentFile = new PFile("test.txt",
|
||||
@@ -17,6 +19,7 @@ public class TestSaveDeleteOneToOneMultiple extends TestCase {
|
||||
// Ebean.delete(persistentFile);
|
||||
// }
|
||||
|
||||
@Test
|
||||
public void testCreateLoadDeletePFile() {
|
||||
PFile persistentFile = new PFile("test.txt",
|
||||
new PFileContent("test".getBytes()));
|
||||
|
||||
@@ -3,8 +3,10 @@ package com.avaje.tests.basic;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.bean.BeanCollection;
|
||||
import com.avaje.tests.model.basic.Order;
|
||||
@@ -12,12 +14,13 @@ import com.avaje.tests.model.basic.OrderDetail;
|
||||
import com.avaje.tests.model.basic.Product;
|
||||
import com.avaje.tests.model.basic.ResetBasicData;
|
||||
|
||||
public class TestSharedInstancePropagation extends TestCase {
|
||||
public class TestSharedInstancePropagation extends BaseTestCase {
|
||||
|
||||
|
||||
/**
|
||||
* Test that the sharedInstance status is propagated on lazy loading.
|
||||
*/
|
||||
@Test
|
||||
public void testSharedListNavigate() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
@@ -1,61 +1,64 @@
|
||||
package com.avaje.tests.basic;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.BeanState;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.tests.model.basic.Customer;
|
||||
|
||||
public class TestTransient extends TestCase {
|
||||
public class TestTransient extends BaseTestCase {
|
||||
|
||||
public void testTransient() {
|
||||
@Test
|
||||
public void testTransient() {
|
||||
|
||||
Customer cnew = new Customer();
|
||||
cnew.setName("testTrans");
|
||||
Customer cnew = new Customer();
|
||||
cnew.setName("testTrans");
|
||||
|
||||
Ebean.save(cnew);
|
||||
Integer custId = cnew.getId();
|
||||
Ebean.save(cnew);
|
||||
Integer custId = cnew.getId();
|
||||
|
||||
Customer c = Ebean.find(Customer.class).setAutofetch(false).setId(custId).findUnique();
|
||||
Customer c = Ebean.find(Customer.class).setAutofetch(false).setId(custId).findUnique();
|
||||
|
||||
Assert.assertNotNull(c);
|
||||
Assert.assertNotNull(c);
|
||||
|
||||
BeanState beanState = Ebean.getBeanState(c);
|
||||
Assert.assertFalse("not new or dirty as transient", beanState.isNewOrDirty());
|
||||
BeanState beanState = Ebean.getBeanState(c);
|
||||
Assert.assertFalse("not new or dirty as transient", beanState.isNewOrDirty());
|
||||
|
||||
c.getLock().tryLock();
|
||||
try {
|
||||
c.setSelected(Boolean.TRUE);
|
||||
} finally {
|
||||
c.getLock().unlock();
|
||||
}
|
||||
|
||||
Boolean selected = c.getSelected();
|
||||
Assert.assertNotNull(selected);
|
||||
|
||||
Assert.assertFalse("not new or dirty as transient", beanState.isNewOrDirty());
|
||||
|
||||
Ebean.save(c);
|
||||
|
||||
selected = c.getSelected();
|
||||
Assert.assertNotNull(selected);
|
||||
|
||||
c.setName("Modified");
|
||||
Assert.assertTrue("dirty now", beanState.isNewOrDirty());
|
||||
|
||||
selected = c.getSelected();
|
||||
Assert.assertNotNull(selected);
|
||||
|
||||
Ebean.save(c);
|
||||
Assert.assertFalse("Not dirty after save", beanState.isNewOrDirty());
|
||||
|
||||
selected = c.getSelected();
|
||||
Assert.assertNotNull(selected);
|
||||
|
||||
String updateStmt = "update customer set name = 'Rob' where id = :id";
|
||||
int rows = Ebean.createUpdate(Customer.class, updateStmt).set("id", custId).execute();
|
||||
|
||||
Assert.assertTrue("changed name back", 1 == rows);
|
||||
c.getLock().tryLock();
|
||||
try {
|
||||
c.setSelected(Boolean.TRUE);
|
||||
} finally {
|
||||
c.getLock().unlock();
|
||||
}
|
||||
|
||||
Boolean selected = c.getSelected();
|
||||
Assert.assertNotNull(selected);
|
||||
|
||||
Assert.assertFalse("not new or dirty as transient", beanState.isNewOrDirty());
|
||||
|
||||
Ebean.save(c);
|
||||
|
||||
selected = c.getSelected();
|
||||
Assert.assertNotNull(selected);
|
||||
|
||||
c.setName("Modified");
|
||||
Assert.assertTrue("dirty now", beanState.isNewOrDirty());
|
||||
|
||||
selected = c.getSelected();
|
||||
Assert.assertNotNull(selected);
|
||||
|
||||
Ebean.save(c);
|
||||
Assert.assertFalse("Not dirty after save", beanState.isNewOrDirty());
|
||||
|
||||
selected = c.getSelected();
|
||||
Assert.assertNotNull(selected);
|
||||
|
||||
String updateStmt = "update customer set name = 'Rob' where id = :id";
|
||||
int rows = Ebean.createUpdate(Customer.class, updateStmt).set("id", custId).execute();
|
||||
|
||||
Assert.assertTrue("changed name back", 1 == rows);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,39 +2,40 @@ package com.avaje.tests.basic;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.tests.model.basic.Customer;
|
||||
import com.avaje.tests.model.basic.Order;
|
||||
import com.avaje.tests.model.basic.ResetBasicData;
|
||||
|
||||
public class TestUpdateManyToOne extends TestCase{
|
||||
public class TestUpdateManyToOne extends BaseTestCase {
|
||||
|
||||
public void test() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
List<Customer> custs = Ebean.find(Customer.class).findList();
|
||||
|
||||
|
||||
List<Order> orders = Ebean.find(Order.class).setMaxRows(1).findList();
|
||||
|
||||
Order order = orders.get(0);
|
||||
Customer customer = order.getCustomer();
|
||||
|
||||
Customer changeCust = null;
|
||||
for (Customer c : custs) {
|
||||
if (!customer.getId().equals(c.getId())){
|
||||
changeCust = c;
|
||||
break;
|
||||
}
|
||||
}
|
||||
order.setCustomer(changeCust);
|
||||
Ebean.save(order);
|
||||
|
||||
order.setCustomer(customer);
|
||||
Ebean.save(order);
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
List<Customer> custs = Ebean.find(Customer.class).findList();
|
||||
|
||||
List<Order> orders = Ebean.find(Order.class).setMaxRows(1).findList();
|
||||
|
||||
Order order = orders.get(0);
|
||||
Customer customer = order.getCustomer();
|
||||
|
||||
Customer changeCust = null;
|
||||
for (Customer c : custs) {
|
||||
if (!customer.getId().equals(c.getId())) {
|
||||
changeCust = c;
|
||||
break;
|
||||
}
|
||||
}
|
||||
order.setCustomer(changeCust);
|
||||
Ebean.save(order);
|
||||
|
||||
order.setCustomer(customer);
|
||||
Ebean.save(order);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
package com.avaje.tests.basic;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.tests.model.basic.TUuidEntity;
|
||||
|
||||
public class TestUuidInsert extends TestCase {
|
||||
public class TestUuidInsert extends BaseTestCase {
|
||||
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
TUuidEntity e = new TUuidEntity();
|
||||
|
||||
@@ -2,42 +2,44 @@ package com.avaje.tests.basic;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.tests.model.basic.UUOne;
|
||||
import com.avaje.tests.model.basic.UUTwo;
|
||||
|
||||
public class TestUuidInsertMasterDetail extends TestCase {
|
||||
public class TestUuidInsertMasterDetail extends BaseTestCase {
|
||||
|
||||
public void testInsert() {
|
||||
|
||||
UUTwo two = new UUTwo();
|
||||
two.setName("something");
|
||||
|
||||
ArrayList<UUTwo> list = new ArrayList<UUTwo>();
|
||||
list.add(two);
|
||||
|
||||
UUOne one = new UUOne();
|
||||
one.setName("some one");
|
||||
one.setComments(list);
|
||||
@Test
|
||||
public void testInsert() {
|
||||
|
||||
Ebean.save(one);
|
||||
|
||||
UUOne oneB = Ebean.find(UUOne.class, one.getId());
|
||||
UUTwo two = new UUTwo();
|
||||
two.setName("something");
|
||||
|
||||
ArrayList<UUTwo> list = new ArrayList<UUTwo>();
|
||||
list.add(two);
|
||||
|
||||
UUOne one = new UUOne();
|
||||
one.setName("some one");
|
||||
one.setComments(list);
|
||||
|
||||
Ebean.save(one);
|
||||
|
||||
UUOne oneB = Ebean.find(UUOne.class, one.getId());
|
||||
|
||||
UUTwo twoB = new UUTwo();
|
||||
twoB.setName("another something");
|
||||
oneB.getComments().add(twoB);
|
||||
|
||||
Ebean.save(oneB);
|
||||
}
|
||||
|
||||
public void testNullFK() {
|
||||
|
||||
UUTwo two = new UUTwo();
|
||||
two.setName("something");
|
||||
Ebean.save(two);
|
||||
}
|
||||
|
||||
UUTwo twoB = new UUTwo();
|
||||
twoB.setName("another something");
|
||||
oneB.getComments().add(twoB);
|
||||
|
||||
Ebean.save(oneB);
|
||||
}
|
||||
|
||||
public void testNullFK() {
|
||||
|
||||
UUTwo two = new UUTwo();
|
||||
two.setName("something");
|
||||
Ebean.save(two);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,8 +5,10 @@ package com.avaje.tests.basic;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.Transaction;
|
||||
import com.avaje.ebean.bean.PersistenceContext;
|
||||
@@ -14,9 +16,9 @@ import com.avaje.ebeaninternal.api.SpiTransaction;
|
||||
import com.avaje.tests.model.basic.Order;
|
||||
import com.avaje.tests.model.basic.ResetBasicData;
|
||||
|
||||
public class TestWeakPersistenceContext extends TestCase {
|
||||
public class TestWeakPersistenceContext extends BaseTestCase {
|
||||
|
||||
|
||||
@Test
|
||||
public void testOne() {
|
||||
|
||||
PersistenceContext ctx = inner();
|
||||
|
||||
@@ -3,35 +3,34 @@ package com.avaje.tests.basic;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.Query;
|
||||
import com.avaje.tests.model.basic.Customer;
|
||||
import com.avaje.tests.model.basic.Order;
|
||||
import com.avaje.tests.model.basic.ResetBasicData;
|
||||
|
||||
public class TestWhereAnnotation extends TestCase {
|
||||
public class TestWhereAnnotation extends BaseTestCase {
|
||||
|
||||
public void testWhere() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
Customer custTest = ResetBasicData.createCustAndOrder("testWhereAnn");
|
||||
|
||||
Customer customer = Ebean.find(Customer.class, custTest.getId());
|
||||
List<Order> orders = customer.getOrders();
|
||||
|
||||
Assert.assertTrue(orders.size() > 0);
|
||||
|
||||
|
||||
Query<Customer> q1 = Ebean.find(Customer.class)
|
||||
.setUseCache(false)
|
||||
.fetch("orders")
|
||||
.where().idEq(1)
|
||||
.query();
|
||||
|
||||
q1.findUnique();
|
||||
String s1 = q1.getGeneratedSql();
|
||||
Assert.assertTrue(s1.contains("t1.order_date is not null"));
|
||||
}
|
||||
@Test
|
||||
public void testWhere() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
Customer custTest = ResetBasicData.createCustAndOrder("testWhereAnn");
|
||||
|
||||
Customer customer = Ebean.find(Customer.class, custTest.getId());
|
||||
List<Order> orders = customer.getOrders();
|
||||
|
||||
Assert.assertTrue(orders.size() > 0);
|
||||
|
||||
Query<Customer> q1 = Ebean.find(Customer.class).setUseCache(false).fetch("orders").where()
|
||||
.idEq(1).query();
|
||||
|
||||
q1.findUnique();
|
||||
String s1 = q1.getGeneratedSql();
|
||||
Assert.assertTrue(s1.contains("t1.order_date is not null"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,10 @@ package com.avaje.tests.basic.delete;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebeaninternal.api.SpiEbeanServer;
|
||||
import com.avaje.tests.model.basic.Customer;
|
||||
@@ -11,29 +13,27 @@ import com.avaje.tests.model.basic.Order;
|
||||
import com.avaje.tests.model.basic.OrderDetail;
|
||||
import com.avaje.tests.model.basic.ResetBasicData;
|
||||
|
||||
public class TestDeleteByIdList extends TestCase {
|
||||
public class TestDeleteByIdList extends BaseTestCase {
|
||||
|
||||
public void test() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
OrderDetail dummy = Ebean.getReference(OrderDetail.class, 1);
|
||||
SpiEbeanServer server = (SpiEbeanServer)Ebean.getServer(null);
|
||||
server.getBeanDescriptor(OrderDetail.class).cachePutBeanData(dummy);
|
||||
|
||||
Customer c0 = ResetBasicData.createCustAndOrder("DelIdList-0");
|
||||
assertNotNull(c0);
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
Customer c1 = ResetBasicData.createCustAndOrder("DelIdList-1");
|
||||
ResetBasicData.reset();
|
||||
|
||||
List<Object> orderIds = Ebean.find(Order.class)
|
||||
.where().in("customer", c0,c1)
|
||||
.findIds();
|
||||
OrderDetail dummy = Ebean.getReference(OrderDetail.class, 1);
|
||||
SpiEbeanServer server = (SpiEbeanServer) Ebean.getServer(null);
|
||||
server.getBeanDescriptor(OrderDetail.class).cachePutBeanData(dummy);
|
||||
|
||||
assertEquals(2, orderIds.size());
|
||||
|
||||
|
||||
Ebean.delete(Order.class, orderIds);
|
||||
|
||||
}
|
||||
Customer c0 = ResetBasicData.createCustAndOrder("DelIdList-0");
|
||||
Assert.assertNotNull(c0);
|
||||
|
||||
Customer c1 = ResetBasicData.createCustAndOrder("DelIdList-1");
|
||||
|
||||
List<Object> orderIds = Ebean.find(Order.class).where().in("customer", c0, c1).findIds();
|
||||
|
||||
Assert.assertEquals(2, orderIds.size());
|
||||
|
||||
Ebean.delete(Order.class, orderIds);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,10 @@ package com.avaje.tests.basic.delete;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebeaninternal.api.SpiEbeanServer;
|
||||
import com.avaje.tests.model.basic.Customer;
|
||||
@@ -11,28 +13,27 @@ import com.avaje.tests.model.basic.Order;
|
||||
import com.avaje.tests.model.basic.OrderDetail;
|
||||
import com.avaje.tests.model.basic.ResetBasicData;
|
||||
|
||||
public class TestDeleteCascadeById extends TestCase {
|
||||
public class TestDeleteCascadeById extends BaseTestCase {
|
||||
|
||||
public void test() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
OrderDetail dummy = Ebean.getReference(OrderDetail.class, 1);
|
||||
SpiEbeanServer server = (SpiEbeanServer)Ebean.getServer(null);
|
||||
server.getBeanDescriptor(OrderDetail.class).cachePutBeanData(dummy);
|
||||
|
||||
Customer cust = ResetBasicData.createCustAndOrder("DelCas");
|
||||
assertNotNull(cust);
|
||||
|
||||
List<Order> orders = Ebean.find(Order.class)
|
||||
.where().eq("customer", cust)
|
||||
.findList();
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
assertEquals(1, orders.size());
|
||||
Order o = orders.get(0);
|
||||
assertNotNull(o);
|
||||
|
||||
Ebean.delete(o);
|
||||
|
||||
}
|
||||
ResetBasicData.reset();
|
||||
|
||||
OrderDetail dummy = Ebean.getReference(OrderDetail.class, 1);
|
||||
SpiEbeanServer server = (SpiEbeanServer) Ebean.getServer(null);
|
||||
server.getBeanDescriptor(OrderDetail.class).cachePutBeanData(dummy);
|
||||
|
||||
Customer cust = ResetBasicData.createCustAndOrder("DelCas");
|
||||
Assert.assertNotNull(cust);
|
||||
|
||||
List<Order> orders = Ebean.find(Order.class).where().eq("customer", cust).findList();
|
||||
|
||||
Assert.assertEquals(1, orders.size());
|
||||
Order o = orders.get(0);
|
||||
Assert.assertNotNull(o);
|
||||
|
||||
Ebean.delete(o);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,10 +3,10 @@ package com.avaje.tests.basic.encrypt;
|
||||
import java.sql.Date;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.SqlQuery;
|
||||
import com.avaje.ebean.SqlRow;
|
||||
@@ -14,90 +14,78 @@ import com.avaje.ebean.config.dbplatform.DbEncrypt;
|
||||
import com.avaje.ebeaninternal.api.SpiEbeanServer;
|
||||
import com.avaje.tests.model.basic.EBasicEncrypt;
|
||||
|
||||
public class TestEncrypt extends TestCase {
|
||||
public class TestEncrypt extends BaseTestCase {
|
||||
|
||||
public void test() {
|
||||
|
||||
EBasicEncrypt e = new EBasicEncrypt();
|
||||
e.setName("testname");
|
||||
e.setDescription("testdesc");
|
||||
e.setDob(new Date(System.currentTimeMillis()-100000));
|
||||
|
||||
Ebean.save(e);
|
||||
|
||||
Date earlyDob = new Date(System.currentTimeMillis()-500000);
|
||||
|
||||
List<EBasicEncrypt> qlList =
|
||||
Ebean.createQuery(EBasicEncrypt.class, "where description like :d and dob >= :dob")
|
||||
.setParameter("d", "testde%")
|
||||
.setParameter("dob", earlyDob)
|
||||
.findList();
|
||||
|
||||
Assert.assertTrue(qlList.size() > 0);
|
||||
|
||||
qlList =
|
||||
Ebean.createQuery(EBasicEncrypt.class, "find e (id, description) where description = :d")
|
||||
.setParameter("d", "testdesc")
|
||||
.findList();
|
||||
|
||||
Assert.assertTrue(qlList.size() == 1);
|
||||
|
||||
|
||||
|
||||
SqlQuery q = Ebean.createSqlQuery("select * from e_basicenc where id = :id");
|
||||
q.setParameter("id", e.getId());
|
||||
|
||||
SqlRow row = q.findUnique();
|
||||
String name = row.getString("name");
|
||||
Object desc = row.get("description");
|
||||
System.out.println("SqlRow: "+name+" "+desc);
|
||||
|
||||
EBasicEncrypt e1 = Ebean.find(EBasicEncrypt.class, e.getId());
|
||||
|
||||
String desc1 = e1.getDescription();
|
||||
System.out.println("Decrypted: "+desc1+" "+e1.getDob());
|
||||
|
||||
|
||||
e1.setName("testmod");
|
||||
e1.setDescription("moddesc");
|
||||
|
||||
Ebean.save(e1);
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
EBasicEncrypt e2 = Ebean.find(EBasicEncrypt.class, e.getId());
|
||||
|
||||
String desc2 = e2.getDescription();
|
||||
System.out.println("moddesc="+desc2);
|
||||
|
||||
SpiEbeanServer server = (SpiEbeanServer)Ebean.getServer(null);
|
||||
DbEncrypt dbEncrypt = server.getDatabasePlatform().getDbEncrypt();
|
||||
|
||||
if (dbEncrypt == null){
|
||||
// can not test the where clause
|
||||
System.out.println("TestEncrypt: Not testing where clause as no DbEncrypt");
|
||||
|
||||
} else {
|
||||
|
||||
List<EBasicEncrypt> list =
|
||||
Ebean.find(EBasicEncrypt.class)
|
||||
.where().eq("description", "moddesc")
|
||||
.findList();
|
||||
|
||||
Assert.assertEquals(1, list.size());
|
||||
|
||||
list
|
||||
= Ebean.find(EBasicEncrypt.class)
|
||||
.where().startsWith("description", "modde")
|
||||
.findList();
|
||||
|
||||
Assert.assertEquals(1, list.size());
|
||||
|
||||
list =
|
||||
Ebean.createQuery(EBasicEncrypt.class, "where description like :d")
|
||||
.setParameter("d", "modde%")
|
||||
.findList();
|
||||
|
||||
Assert.assertNotNull(list);
|
||||
}
|
||||
EBasicEncrypt e = new EBasicEncrypt();
|
||||
e.setName("testname");
|
||||
e.setDescription("testdesc");
|
||||
e.setDob(new Date(System.currentTimeMillis() - 100000));
|
||||
|
||||
Ebean.save(e);
|
||||
|
||||
Date earlyDob = new Date(System.currentTimeMillis() - 500000);
|
||||
|
||||
List<EBasicEncrypt> qlList = Ebean
|
||||
.createQuery(EBasicEncrypt.class, "where description like :d and dob >= :dob")
|
||||
.setParameter("d", "testde%").setParameter("dob", earlyDob).findList();
|
||||
|
||||
Assert.assertTrue(qlList.size() > 0);
|
||||
|
||||
qlList = Ebean
|
||||
.createQuery(EBasicEncrypt.class, "find e (id, description) where description = :d")
|
||||
.setParameter("d", "testdesc").findList();
|
||||
|
||||
Assert.assertTrue(qlList.size() == 1);
|
||||
|
||||
SqlQuery q = Ebean.createSqlQuery("select * from e_basicenc where id = :id");
|
||||
q.setParameter("id", e.getId());
|
||||
|
||||
SqlRow row = q.findUnique();
|
||||
String name = row.getString("name");
|
||||
Object desc = row.get("description");
|
||||
System.out.println("SqlRow: " + name + " " + desc);
|
||||
|
||||
EBasicEncrypt e1 = Ebean.find(EBasicEncrypt.class, e.getId());
|
||||
|
||||
String desc1 = e1.getDescription();
|
||||
System.out.println("Decrypted: " + desc1 + " " + e1.getDob());
|
||||
|
||||
e1.setName("testmod");
|
||||
e1.setDescription("moddesc");
|
||||
|
||||
Ebean.save(e1);
|
||||
|
||||
EBasicEncrypt e2 = Ebean.find(EBasicEncrypt.class, e.getId());
|
||||
|
||||
String desc2 = e2.getDescription();
|
||||
System.out.println("moddesc=" + desc2);
|
||||
|
||||
SpiEbeanServer server = (SpiEbeanServer) Ebean.getServer(null);
|
||||
DbEncrypt dbEncrypt = server.getDatabasePlatform().getDbEncrypt();
|
||||
|
||||
if (dbEncrypt == null) {
|
||||
// can not test the where clause
|
||||
System.out.println("TestEncrypt: Not testing where clause as no DbEncrypt");
|
||||
|
||||
} else {
|
||||
|
||||
List<EBasicEncrypt> list = Ebean.find(EBasicEncrypt.class).where()
|
||||
.eq("description", "moddesc").findList();
|
||||
|
||||
Assert.assertEquals(1, list.size());
|
||||
|
||||
list = Ebean.find(EBasicEncrypt.class).where().startsWith("description", "modde").findList();
|
||||
|
||||
Assert.assertEquals(1, list.size());
|
||||
|
||||
list = Ebean.createQuery(EBasicEncrypt.class, "where description like :d")
|
||||
.setParameter("d", "modde%").findList();
|
||||
|
||||
Assert.assertNotNull(list);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,55 +3,57 @@ package com.avaje.tests.basic.encrypt;
|
||||
import java.sql.Timestamp;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.SqlQuery;
|
||||
import com.avaje.ebean.SqlRow;
|
||||
import com.avaje.tests.model.basic.EBasicEncryptBinary;
|
||||
|
||||
public class TestEncryptBinary extends TestCase {
|
||||
public class TestEncryptBinary extends BaseTestCase {
|
||||
|
||||
public void test() {
|
||||
|
||||
Timestamp t0 = new Timestamp(System.currentTimeMillis());
|
||||
EBasicEncryptBinary e = new EBasicEncryptBinary();
|
||||
e.setName("test1");
|
||||
e.setDescription("testdesc1");
|
||||
e.setSomeTime(t0);
|
||||
e.setData("HelloWorld".getBytes());
|
||||
|
||||
Ebean.save(e);
|
||||
|
||||
|
||||
SqlQuery q = Ebean.createSqlQuery("select * from e_basicenc_bin where id = :id");
|
||||
q.setParameter("id", e.getId());
|
||||
|
||||
SqlRow row = q.findUnique();
|
||||
String name = row.getString("name");
|
||||
Object data = row.get("data");
|
||||
Object someTimeData = row.get("some_time");
|
||||
System.out.println("SqlRow name:"+name+" data:"+data+" someTime:"+someTimeData);
|
||||
|
||||
EBasicEncryptBinary e1 = Ebean.find(EBasicEncryptBinary.class, e.getId());
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
Timestamp t1 = e1.getSomeTime();
|
||||
byte[] data1 = e1.getData();
|
||||
String s = new String(data1);
|
||||
String desc1 = e1.getDescription();
|
||||
System.out.println("Decrypted data:"+s+" desc:"+desc1);
|
||||
|
||||
Assert.assertEquals(t0, t1);
|
||||
|
||||
e1.setName("testmod");
|
||||
e1.setDescription("moddesc");
|
||||
|
||||
Ebean.save(e1);
|
||||
Timestamp t0 = new Timestamp(System.currentTimeMillis());
|
||||
EBasicEncryptBinary e = new EBasicEncryptBinary();
|
||||
e.setName("test1");
|
||||
e.setDescription("testdesc1");
|
||||
e.setSomeTime(t0);
|
||||
e.setData("HelloWorld".getBytes());
|
||||
|
||||
Ebean.save(e);
|
||||
|
||||
SqlQuery q = Ebean.createSqlQuery("select * from e_basicenc_bin where id = :id");
|
||||
q.setParameter("id", e.getId());
|
||||
|
||||
SqlRow row = q.findUnique();
|
||||
String name = row.getString("name");
|
||||
Object data = row.get("data");
|
||||
Object someTimeData = row.get("some_time");
|
||||
System.out.println("SqlRow name:" + name + " data:" + data + " someTime:" + someTimeData);
|
||||
|
||||
EBasicEncryptBinary e1 = Ebean.find(EBasicEncryptBinary.class, e.getId());
|
||||
|
||||
Timestamp t1 = e1.getSomeTime();
|
||||
byte[] data1 = e1.getData();
|
||||
String s = new String(data1);
|
||||
String desc1 = e1.getDescription();
|
||||
System.out.println("Decrypted data:" + s + " desc:" + desc1);
|
||||
|
||||
Assert.assertEquals(t0, t1);
|
||||
|
||||
e1.setName("testmod");
|
||||
e1.setDescription("moddesc");
|
||||
|
||||
Ebean.save(e1);
|
||||
|
||||
EBasicEncryptBinary e2 = Ebean.find(EBasicEncryptBinary.class, e.getId());
|
||||
|
||||
String desc2 = e2.getDescription();
|
||||
System.out.println("moddesc=" + desc2);
|
||||
}
|
||||
|
||||
EBasicEncryptBinary e2 = Ebean.find(EBasicEncryptBinary.class, e.getId());
|
||||
|
||||
String desc2 = e2.getDescription();
|
||||
System.out.println("moddesc="+desc2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
package com.avaje.tests.basic.event;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.tests.model.basic.TWithPreInsert;
|
||||
|
||||
public class TestPreInsertValidation extends TestCase {
|
||||
public class TestPreInsertValidation extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
TWithPreInsert e = new TWithPreInsert();
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
package com.avaje.tests.basic.event;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.Query;
|
||||
import com.avaje.tests.model.basic.ResetBasicData;
|
||||
import com.avaje.tests.model.basic.TOne;
|
||||
|
||||
public class TestQueryAdapter extends TestCase {
|
||||
public class TestQueryAdapter extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void testSimple() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
@@ -2,32 +2,34 @@ package com.avaje.tests.basic.join;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.tests.model.basic.Order;
|
||||
import com.avaje.tests.model.basic.Order.Status;
|
||||
import com.avaje.tests.model.basic.ResetBasicData;
|
||||
|
||||
public class TestSecondaryJoin extends TestCase {
|
||||
public class TestSecondaryJoin extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
List<Order> list = Ebean.find(Order.class)
|
||||
// .select("*")
|
||||
// .join("customer")
|
||||
.findList();
|
||||
|
||||
Order o0 = list.get(0);
|
||||
o0.setCustomerName("Banan");
|
||||
o0.setStatus(Status.APPROVED);
|
||||
|
||||
Ebean.save(o0);
|
||||
|
||||
System.out.println("done");
|
||||
|
||||
}
|
||||
|
||||
public void test() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
List<Order> list = Ebean.find(Order.class)
|
||||
//.select("*")
|
||||
//.join("customer")
|
||||
.findList();
|
||||
|
||||
Order o0 = list.get(0);
|
||||
o0.setCustomerName("Banan");
|
||||
o0.setStatus(Status.APPROVED);
|
||||
|
||||
Ebean.save(o0);
|
||||
|
||||
System.out.println("done");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,27 +1,28 @@
|
||||
package com.avaje.tests.basic.lob;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.EbeanServer;
|
||||
import com.avaje.tests.model.basic.EBasicClobNoVer;
|
||||
|
||||
public class TestBasicClobNoVer extends TestCase {
|
||||
public class TestBasicClobNoVer extends BaseTestCase {
|
||||
|
||||
public void test() {
|
||||
|
||||
EBasicClobNoVer entity = new EBasicClobNoVer();
|
||||
entity.setName("test");
|
||||
entity.setDescription("This is a test");
|
||||
EbeanServer server = Ebean.getServer(null);
|
||||
server.save(entity);
|
||||
|
||||
Ebean.find(EBasicClobNoVer.class).select("*").findList();
|
||||
|
||||
server.refresh(entity);
|
||||
System.out.println("description=" + entity.getDescription());
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
EBasicClobNoVer entity = new EBasicClobNoVer();
|
||||
entity.setName("test");
|
||||
entity.setDescription("This is a test");
|
||||
EbeanServer server = Ebean.getServer(null);
|
||||
server.save(entity);
|
||||
|
||||
Ebean.find(EBasicClobNoVer.class).select("*").findList();
|
||||
|
||||
server.refresh(entity);
|
||||
System.out.println("description=" + entity.getDescription());
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,30 +1,32 @@
|
||||
package com.avaje.tests.basic.lob;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.tests.model.basic.TBytesOnly;
|
||||
|
||||
public class TestByteOnly extends TestCase {
|
||||
public class TestByteOnly extends BaseTestCase {
|
||||
|
||||
public void test() {
|
||||
|
||||
byte[] content = new byte[]{1,1};
|
||||
TBytesOnly e = new TBytesOnly();
|
||||
e.setContent(content);
|
||||
|
||||
Ebean.save(e);
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
byte[] content2 = new byte[]{1,1};
|
||||
byte[] content = new byte[] { 1, 1 };
|
||||
TBytesOnly e = new TBytesOnly();
|
||||
e.setContent(content);
|
||||
|
||||
Ebean.save(e);
|
||||
|
||||
byte[] content2 = new byte[] { 1, 1 };
|
||||
|
||||
TBytesOnly e2 = Ebean.find(TBytesOnly.class, e.getId());
|
||||
e2.setContent(content2);
|
||||
|
||||
Ebean.save(e2);
|
||||
|
||||
// Ebean.getServer(null).getAdminAutofetch().collectUsageViaGC();
|
||||
// Ebean.getServer(null).getAdminAutofetch().updateTunedQueryInfo();
|
||||
System.out.println("done");
|
||||
}
|
||||
|
||||
TBytesOnly e2 = Ebean.find(TBytesOnly.class, e.getId());
|
||||
e2.setContent(content2);
|
||||
|
||||
Ebean.save(e2);
|
||||
|
||||
//Ebean.getServer(null).getAdminAutofetch().collectUsageViaGC();
|
||||
//Ebean.getServer(null).getAdminAutofetch().updateTunedQueryInfo();
|
||||
System.out.println("done");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,41 +1,44 @@
|
||||
package com.avaje.tests.basic.one2one;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
|
||||
public class TestOne2OneBookingInvoice extends TestCase {
|
||||
|
||||
public void test() {
|
||||
Booking b = new Booking();
|
||||
public class TestOne2OneBookingInvoice extends BaseTestCase {
|
||||
|
||||
Invoice ai = new Invoice();
|
||||
Invoice ci = new Invoice();
|
||||
@Test
|
||||
public void test() {
|
||||
Booking b = new Booking();
|
||||
|
||||
ai.setBooking(b);
|
||||
ci.setBooking(b);
|
||||
Invoice ai = new Invoice();
|
||||
Invoice ci = new Invoice();
|
||||
|
||||
b.setAgentInvoice(ai);
|
||||
b.setClientInvoice(ci);
|
||||
ai.setBooking(b);
|
||||
ci.setBooking(b);
|
||||
|
||||
Ebean.save(b);
|
||||
|
||||
Booking b1 = Ebean.find(Booking.class, b.getId());
|
||||
|
||||
Invoice ai1 = b1.getAgentInvoice();
|
||||
Assert.assertNotNull(ai1);
|
||||
|
||||
Booking b2 = ai1.getBooking();
|
||||
Assert.assertNotNull(b2);
|
||||
Assert.assertEquals(b1.getId(), b2.getId());
|
||||
Assert.assertSame(b1, b2);
|
||||
|
||||
Invoice ci1 = b1.getClientInvoice();
|
||||
Booking b3 = ci1.getBooking();
|
||||
Assert.assertNotNull(b3);
|
||||
Assert.assertEquals(b1.getId(), b2.getId());
|
||||
Assert.assertSame(b1, b2);
|
||||
|
||||
}
|
||||
b.setAgentInvoice(ai);
|
||||
b.setClientInvoice(ci);
|
||||
|
||||
Ebean.save(b);
|
||||
|
||||
Booking b1 = Ebean.find(Booking.class, b.getId());
|
||||
|
||||
Invoice ai1 = b1.getAgentInvoice();
|
||||
Assert.assertNotNull(ai1);
|
||||
|
||||
Booking b2 = ai1.getBooking();
|
||||
Assert.assertNotNull(b2);
|
||||
Assert.assertEquals(b1.getId(), b2.getId());
|
||||
Assert.assertSame(b1, b2);
|
||||
|
||||
Invoice ci1 = b1.getClientInvoice();
|
||||
Booking b3 = ci1.getBooking();
|
||||
Assert.assertNotNull(b3);
|
||||
Assert.assertEquals(b1.getId(), b2.getId());
|
||||
Assert.assertSame(b1, b2);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,21 @@
|
||||
package com.avaje.tests.basic.one2one;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
|
||||
public class TestOneToOneWheelTire extends TestCase {
|
||||
public class TestOneToOneWheelTire extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
Wheel w = new Wheel();
|
||||
Tire t = new Tire();
|
||||
t.setWheel(w);
|
||||
w.setTire(t);
|
||||
|
||||
Ebean.save(t);
|
||||
}
|
||||
|
||||
public void test() {
|
||||
|
||||
Wheel w = new Wheel();
|
||||
Tire t = new Tire();
|
||||
t.setWheel(w);
|
||||
w.setTire(t);
|
||||
|
||||
Ebean.save(t);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package com.avaje.tests.basic.type;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.SqlQuery;
|
||||
import com.avaje.ebean.SqlRow;
|
||||
@@ -11,60 +11,60 @@ import com.avaje.tests.model.basic.EBasic;
|
||||
import com.avaje.tests.model.basic.EBasic.Status;
|
||||
import com.avaje.tests.model.basic.EBasicEnumId;
|
||||
|
||||
public class TestEnumValueAnnotation extends TestCase {
|
||||
public class TestEnumValueAnnotation extends BaseTestCase {
|
||||
|
||||
public void test(){
|
||||
|
||||
EBasic b = new EBasic();
|
||||
b.setName("Banana");
|
||||
b.setStatus(Status.NEW);
|
||||
|
||||
Ebean.save(b);
|
||||
|
||||
SqlQuery q = Ebean.createSqlQuery("select * from e_basic where id = :id");
|
||||
q.setParameter("id", b.getId());
|
||||
|
||||
SqlRow sqlRow = q.findUnique();
|
||||
String strStatus = sqlRow.getString("status");
|
||||
|
||||
Assert.assertEquals("N", strStatus);
|
||||
|
||||
EBasic b2 = new EBasic();
|
||||
b2.setName("Apple");
|
||||
b2.setStatus(Status.NEW);
|
||||
|
||||
|
||||
Ebean.save(b2);
|
||||
|
||||
EBasic b3 = Ebean.find(EBasic.class, b2.getId());
|
||||
b3.setName("Orange");
|
||||
|
||||
Ebean.save(b3);
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
EBasic b = new EBasic();
|
||||
b.setName("Banana");
|
||||
b.setStatus(Status.NEW);
|
||||
|
||||
Ebean.save(b);
|
||||
|
||||
SqlQuery q = Ebean.createSqlQuery("select * from e_basic where id = :id");
|
||||
q.setParameter("id", b.getId());
|
||||
|
||||
SqlRow sqlRow = q.findUnique();
|
||||
String strStatus = sqlRow.getString("status");
|
||||
|
||||
Assert.assertEquals("N", strStatus);
|
||||
|
||||
EBasic b2 = new EBasic();
|
||||
b2.setName("Apple");
|
||||
b2.setStatus(Status.NEW);
|
||||
|
||||
Ebean.save(b2);
|
||||
|
||||
EBasic b3 = Ebean.find(EBasic.class, b2.getId());
|
||||
b3.setName("Orange");
|
||||
|
||||
Ebean.save(b3);
|
||||
|
||||
}
|
||||
|
||||
public void testAsId() {
|
||||
EBasicEnumId b = new EBasicEnumId();
|
||||
b.setName("Banana");
|
||||
b.setStatus(EBasicEnumId.Status.NEW);
|
||||
|
||||
Ebean.save(b);
|
||||
|
||||
SqlQuery q = Ebean.createSqlQuery("select * from e_basic_enum_id where status = :status");
|
||||
q.setParameter("status", b.getStatus());
|
||||
|
||||
SqlRow sqlRow = q.findUnique();
|
||||
String strStatus = sqlRow.getString("status");
|
||||
|
||||
Assert.assertEquals("N", strStatus);
|
||||
|
||||
try {
|
||||
b = Ebean.find(EBasicEnumId.class, b.getStatus());
|
||||
} catch (java.lang.IllegalArgumentException iae) {
|
||||
Assert.fail("The use of an enum as id should work : " + iae.getLocalizedMessage());
|
||||
}
|
||||
|
||||
public void testAsId(){
|
||||
EBasicEnumId b = new EBasicEnumId();
|
||||
b.setName("Banana");
|
||||
b.setStatus(EBasicEnumId.Status.NEW);
|
||||
|
||||
Ebean.save(b);
|
||||
|
||||
SqlQuery q = Ebean.createSqlQuery("select * from e_basic_enum_id where status = :status");
|
||||
q.setParameter("status", b.getStatus());
|
||||
|
||||
SqlRow sqlRow = q.findUnique();
|
||||
String strStatus = sqlRow.getString("status");
|
||||
|
||||
Assert.assertEquals("N", strStatus);
|
||||
|
||||
try{
|
||||
b = Ebean.find(EBasicEnumId.class, b.getStatus());
|
||||
}catch(java.lang.IllegalArgumentException iae){
|
||||
fail("The use of an enum as id should work : " + iae.getLocalizedMessage() );
|
||||
}
|
||||
|
||||
Assert.assertEquals(EBasicEnumId.Status.NEW, b.getStatus());
|
||||
}
|
||||
|
||||
|
||||
Assert.assertEquals(EBasicEnumId.Status.NEW, b.getStatus());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,36 +4,34 @@ import java.util.Currency;
|
||||
import java.util.Locale;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.tests.model.basic.ESomeType;
|
||||
|
||||
public class TestExtraScalarTypes extends TestCase {
|
||||
public class TestExtraScalarTypes extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
Locale locale = Locale.getDefault();
|
||||
Currency currency = Currency.getInstance(locale);
|
||||
TimeZone tz = TimeZone.getDefault();
|
||||
|
||||
ESomeType e = new ESomeType();
|
||||
e.setLocale(locale);
|
||||
e.setTimeZone(tz);
|
||||
e.setCurrency(currency);
|
||||
|
||||
Ebean.save(e);
|
||||
|
||||
ESomeType e2 = Ebean.find(ESomeType.class).setAutofetch(false).setId(e.getId()).findUnique();
|
||||
|
||||
Assert.assertNotNull(e2.getCurrency());
|
||||
Assert.assertNotNull(e2.getLocale());
|
||||
Assert.assertNotNull(e2.getTimeZone());
|
||||
}
|
||||
|
||||
public void test() {
|
||||
|
||||
Locale locale = Locale.getDefault();
|
||||
Currency currency = Currency.getInstance(locale);
|
||||
TimeZone tz = TimeZone.getDefault();
|
||||
|
||||
ESomeType e = new ESomeType();
|
||||
e.setLocale(locale);
|
||||
e.setTimeZone(tz);
|
||||
e.setCurrency(currency);
|
||||
|
||||
Ebean.save(e);
|
||||
|
||||
ESomeType e2 = Ebean.find(ESomeType.class)
|
||||
.setAutofetch(false)
|
||||
.setId(e.getId())
|
||||
.findUnique();
|
||||
|
||||
Assert.assertNotNull(e2.getCurrency());
|
||||
Assert.assertNotNull(e2.getLocale());
|
||||
Assert.assertNotNull(e2.getTimeZone());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
package com.avaje.tests.basic.type;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.tests.model.basic.TOne;
|
||||
|
||||
public class TestQueryBooleanProperty extends TestCase {
|
||||
public class TestQueryBooleanProperty extends BaseTestCase {
|
||||
|
||||
public void test() {
|
||||
|
||||
// when run in MySql is test for BUG 323
|
||||
Ebean.find(TOne.class)
|
||||
.where().eq("active", true)
|
||||
.findList();
|
||||
}
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
// when run in MySql is test for BUG 323
|
||||
Ebean.find(TOne.class).where().eq("active", true).findList();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,33 +2,34 @@ package com.avaje.tests.basic.type;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.SqlQuery;
|
||||
import com.avaje.ebean.SqlRow;
|
||||
import com.avaje.tests.model.basic.TUuidEntity;
|
||||
|
||||
public class TestSqlRowUUID extends TestCase {
|
||||
public class TestSqlRowUUID extends BaseTestCase {
|
||||
|
||||
public void test() {
|
||||
|
||||
TUuidEntity e = new TUuidEntity();
|
||||
e.setName("blah");
|
||||
|
||||
Ebean.save(e);
|
||||
|
||||
SqlQuery q = Ebean.createSqlQuery("select * from tuuid_entity where id = :id");
|
||||
q.setParameter("id", e.getId());
|
||||
SqlRow sqlRow = q.findUnique();
|
||||
|
||||
UUID id = sqlRow.getUUID("id");
|
||||
|
||||
Assert.assertNotNull(id);
|
||||
|
||||
Boolean b = sqlRow.getBoolean("name");
|
||||
Assert.assertFalse(b);
|
||||
}
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
TUuidEntity e = new TUuidEntity();
|
||||
e.setName("blah");
|
||||
|
||||
Ebean.save(e);
|
||||
|
||||
SqlQuery q = Ebean.createSqlQuery("select * from tuuid_entity where id = :id");
|
||||
q.setParameter("id", e.getId());
|
||||
SqlRow sqlRow = q.findUnique();
|
||||
|
||||
UUID id = sqlRow.getUUID("id");
|
||||
|
||||
Assert.assertNotNull(id);
|
||||
|
||||
Boolean b = sqlRow.getBoolean("name");
|
||||
Assert.assertFalse(b);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,20 +1,22 @@
|
||||
package com.avaje.tests.basic.type;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.config.GlobalProperties;
|
||||
|
||||
public class TestTransientMap extends TestCase {
|
||||
public class TestTransientMap extends BaseTestCase {
|
||||
|
||||
public void testMe() {
|
||||
|
||||
GlobalProperties.put("classes", BSimpleWithGen.class.toString());
|
||||
|
||||
BSimpleWithGen b = new BSimpleWithGen();
|
||||
b.setName("blah");
|
||||
|
||||
Ebean.save(b);
|
||||
|
||||
}
|
||||
@Test
|
||||
public void testMe() {
|
||||
|
||||
GlobalProperties.put("classes", BSimpleWithGen.class.toString());
|
||||
|
||||
BSimpleWithGen b = new BSimpleWithGen();
|
||||
b.setName("blah");
|
||||
|
||||
Ebean.save(b);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,17 +4,19 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.Transaction;
|
||||
import com.avaje.tests.model.basic.UTDetail;
|
||||
import com.avaje.tests.model.basic.UTMaster;
|
||||
|
||||
public class TestBatchInsertSimple extends TestCase {
|
||||
public class TestBatchInsertSimple extends BaseTestCase {
|
||||
|
||||
Random random = new Random();
|
||||
|
||||
@Test
|
||||
public void testSimpleJdbcBatching() {
|
||||
|
||||
int numOfMasters = 10;// 2 + random.nextInt(8);
|
||||
@@ -28,11 +30,11 @@ public class TestBatchInsertSimple extends TestCase {
|
||||
try {
|
||||
transaction.setBatchMode(true);
|
||||
transaction.setBatchSize(4);
|
||||
//transaction.setLogLevel(LogLevel.SUMMARY);
|
||||
//transaction.setBatchGetGeneratedKeys(false);
|
||||
// transaction.setLogLevel(LogLevel.SUMMARY);
|
||||
// transaction.setBatchGetGeneratedKeys(false);
|
||||
|
||||
Ebean.save(masters);
|
||||
|
||||
|
||||
transaction.commit();
|
||||
|
||||
} finally {
|
||||
@@ -52,7 +54,7 @@ public class TestBatchInsertSimple extends TestCase {
|
||||
int qty = 1 + random.nextInt(99);
|
||||
double amount = random.nextDouble();
|
||||
|
||||
details.add(createDetail(masterPos+"-"+i, qty, amount));
|
||||
details.add(createDetail(masterPos + "-" + i, qty, amount));
|
||||
}
|
||||
master.setDetails(details);
|
||||
return master;
|
||||
@@ -71,8 +73,8 @@ public class TestBatchInsertSimple extends TestCase {
|
||||
detail.setQty(Integer.valueOf(qty));
|
||||
detail.setAmount(Double.valueOf(amount));
|
||||
|
||||
//System.out.println("-- "+detail);
|
||||
|
||||
// System.out.println("-- "+detail);
|
||||
|
||||
return detail;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,10 +5,10 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.Expr;
|
||||
import com.avaje.ebean.FetchConfig;
|
||||
@@ -20,237 +20,188 @@ import com.avaje.tests.model.basic.Customer;
|
||||
import com.avaje.tests.model.basic.Order;
|
||||
import com.avaje.tests.model.basic.ResetBasicData;
|
||||
|
||||
public class TestBasicLazy extends TestCase
|
||||
{
|
||||
public class TestBasicLazy extends BaseTestCase {
|
||||
|
||||
public void testQueries()
|
||||
{
|
||||
@Test
|
||||
public void testQueries() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
ResetBasicData.reset();
|
||||
|
||||
Order order = Ebean.find(Order.class)
|
||||
.select("totalAmount")
|
||||
.setMaxRows(1)
|
||||
.order("id")
|
||||
.findUnique();
|
||||
Order order = Ebean.find(Order.class).select("totalAmount").setMaxRows(1).order("id")
|
||||
.findUnique();
|
||||
|
||||
Assert.assertNotNull(order);
|
||||
Assert.assertNotNull(order);
|
||||
|
||||
Customer customer = order.getCustomer();
|
||||
Assert.assertNotNull(customer);
|
||||
Assert.assertNotNull(customer.getName());
|
||||
Customer customer = order.getCustomer();
|
||||
Assert.assertNotNull(customer);
|
||||
Assert.assertNotNull(customer.getName());
|
||||
|
||||
Address address = customer.getBillingAddress();
|
||||
Assert.assertNotNull(address);
|
||||
Assert.assertNotNull(address.getCity());
|
||||
Address address = customer.getBillingAddress();
|
||||
Assert.assertNotNull(address);
|
||||
Assert.assertNotNull(address.getCity());
|
||||
}
|
||||
|
||||
public void test_N1N() {
|
||||
ResetBasicData.reset();
|
||||
|
||||
// safety check to see if our customer we are going to use for the test has
|
||||
// some contacts
|
||||
Customer c = Ebean.find(Customer.class).setId(1).findUnique();
|
||||
Assert.assertNotNull(c.getContacts());
|
||||
Assert.assertTrue("no contacts on test customer 1", c.getContacts().size() > 0);
|
||||
|
||||
// start transaction so we have a "long running" persistence context
|
||||
Transaction tx = Ebean.beginTransaction();
|
||||
try {
|
||||
List<Order> order = Ebean.find(Order.class).where(Expr.eq("customer.id", 1)).findList();
|
||||
|
||||
Assert.assertNotNull(order);
|
||||
Assert.assertTrue(order.size() > 0);
|
||||
|
||||
Customer customer = order.get(0).getCustomer();
|
||||
Assert.assertNotNull(customer);
|
||||
Assert.assertEquals(1, customer.getId().intValue());
|
||||
|
||||
// this should lazily fetch the contacts
|
||||
List<Contact> contacts = customer.getContacts();
|
||||
|
||||
Assert.assertNotNull(contacts);
|
||||
Assert.assertTrue("contacts not lazily fetched", contacts.size() > 0);
|
||||
} finally {
|
||||
tx.commit();
|
||||
}
|
||||
|
||||
public void test_N1N()
|
||||
{
|
||||
ResetBasicData.reset();
|
||||
}
|
||||
|
||||
// safety check to see if our customer we are going to use for the test has some contacts
|
||||
Customer c = Ebean.find(Customer.class).setId(1).findUnique();
|
||||
assertNotNull(c.getContacts());
|
||||
assertTrue("no contacts on test customer 1", c.getContacts().size() > 0);
|
||||
|
||||
// start transaction so we have a "long running" persistence context
|
||||
Transaction tx = Ebean.beginTransaction();
|
||||
try
|
||||
{
|
||||
List<Order> order = Ebean.find(Order.class)
|
||||
.where(Expr.eq("customer.id", 1))
|
||||
.findList();
|
||||
public void testRaceCondition_Simple() throws Throwable {
|
||||
ResetBasicData.reset();
|
||||
|
||||
assertNotNull(order);
|
||||
assertTrue(order.size() > 0);
|
||||
|
||||
Customer customer = order.get(0).getCustomer();
|
||||
assertNotNull(customer);
|
||||
assertEquals(1, customer.getId().intValue());
|
||||
Order order = Ebean.find(Order.class).select("totalAmount").setMaxRows(1).order("id")
|
||||
.findUnique();
|
||||
|
||||
// this should lazily fetch the contacts
|
||||
List<Contact> contacts = customer.getContacts();
|
||||
|
||||
assertNotNull(contacts);
|
||||
assertTrue("contacts not lazily fetched", contacts.size() > 0);
|
||||
Assert.assertNotNull(order);
|
||||
|
||||
final Customer customer = order.getCustomer();
|
||||
Assert.assertNotNull(customer);
|
||||
|
||||
Assert.assertTrue(Ebean.getBeanState(customer).isReference());
|
||||
|
||||
final Throwable throwables[] = new Throwable[2];
|
||||
Thread t1 = new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
Assert.assertNotNull(customer.getName());
|
||||
} catch (Throwable e) {
|
||||
throwables[0] = e;
|
||||
}
|
||||
finally
|
||||
{
|
||||
tx.commit();
|
||||
}
|
||||
};
|
||||
|
||||
Thread t2 = new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
Assert.assertNotNull(customer.getName());
|
||||
} catch (Throwable e) {
|
||||
throwables[1] = e;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
try {
|
||||
// prepare for race condition
|
||||
MyTestDataSourcePoolListener.SLEEP_AFTER_BORROW = 2000;
|
||||
|
||||
t1.start();
|
||||
t2.start();
|
||||
t1.join();
|
||||
t2.join();
|
||||
} finally {
|
||||
MyTestDataSourcePoolListener.SLEEP_AFTER_BORROW = 0;
|
||||
}
|
||||
|
||||
public void testRaceCondition_Simple() throws Throwable
|
||||
{
|
||||
ResetBasicData.reset();
|
||||
Assert.assertFalse(Ebean.getBeanState(customer).isReference());
|
||||
|
||||
Order order = Ebean.find(Order.class)
|
||||
.select("totalAmount")
|
||||
.setMaxRows(1)
|
||||
.order("id")
|
||||
.findUnique();
|
||||
if (throwables[0] != null) {
|
||||
throw throwables[0];
|
||||
}
|
||||
if (throwables[1] != null) {
|
||||
throw throwables[1];
|
||||
}
|
||||
}
|
||||
|
||||
Assert.assertNotNull(order);
|
||||
private final AtomicBoolean mutex = new AtomicBoolean(false);
|
||||
private List<Order> orders;
|
||||
|
||||
final Customer customer = order.getCustomer();
|
||||
Assert.assertNotNull(customer);
|
||||
private List<Throwable> exceptions = Collections.synchronizedList(new ArrayList<Throwable>());
|
||||
|
||||
Assert.assertTrue(Ebean.getBeanState(customer).isReference());
|
||||
private class FetchThread extends Thread {
|
||||
private int index;
|
||||
|
||||
final Throwable throwables[] = new Throwable[2];
|
||||
Thread t1 = new Thread()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
try
|
||||
{
|
||||
Assert.assertNotNull(customer.getName());
|
||||
}
|
||||
catch (Throwable e)
|
||||
{
|
||||
throwables[0] = e;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Thread t2 = new Thread()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
try
|
||||
{
|
||||
Assert.assertNotNull(customer.getName());
|
||||
}
|
||||
catch (Throwable e)
|
||||
{
|
||||
throwables[1] = e;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
try
|
||||
{
|
||||
// prepare for race condition
|
||||
MyTestDataSourcePoolListener.SLEEP_AFTER_BORROW = 2000;
|
||||
|
||||
t1.start();
|
||||
t2.start();
|
||||
t1.join();
|
||||
t2.join();
|
||||
}
|
||||
finally
|
||||
{
|
||||
MyTestDataSourcePoolListener.SLEEP_AFTER_BORROW = 0;
|
||||
}
|
||||
|
||||
Assert.assertFalse(Ebean.getBeanState(customer).isReference());
|
||||
|
||||
if (throwables[0] != null)
|
||||
{
|
||||
throw throwables[0];
|
||||
}
|
||||
if (throwables[1] != null)
|
||||
{
|
||||
throw throwables[1];
|
||||
}
|
||||
private FetchThread(ThreadGroup tg, int index) {
|
||||
super(tg, "fetcher-" + index);
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
private final AtomicBoolean mutex = new AtomicBoolean(false);
|
||||
private List<Order> orders;
|
||||
|
||||
private List<Throwable> exceptions = Collections.synchronizedList(new ArrayList<Throwable>());
|
||||
|
||||
private class FetchThread extends Thread
|
||||
{
|
||||
private int index;
|
||||
|
||||
private FetchThread(ThreadGroup tg, int index)
|
||||
{
|
||||
super(tg, "fetcher-" + index);
|
||||
this.index = index;
|
||||
@Override
|
||||
public void run() {
|
||||
synchronized (mutex) {
|
||||
System.err.println("** WAIT **");
|
||||
try {
|
||||
while (!mutex.get()) {
|
||||
mutex.wait(100);
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
synchronized (mutex)
|
||||
{
|
||||
System.err.println("** WAIT **");
|
||||
try
|
||||
{
|
||||
while (!mutex.get())
|
||||
{
|
||||
mutex.wait(100);
|
||||
}
|
||||
}
|
||||
catch (InterruptedException e)
|
||||
{
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
try {
|
||||
System.err.println("** DO LAZY FETCH **");
|
||||
orders.get(index).getCustomer().getName();
|
||||
} catch (Throwable e) {
|
||||
exceptions.add(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
System.err.println("** DO LAZY FETCH **");
|
||||
orders.get(index).getCustomer().getName();
|
||||
}
|
||||
catch (Throwable e)
|
||||
{
|
||||
exceptions.add(e);
|
||||
}
|
||||
}
|
||||
public void testRaceCondition_Complex() throws Throwable {
|
||||
ResetBasicData.reset();
|
||||
|
||||
ThreadGroup tg = new ThreadGroup("fetchers");
|
||||
new FetchThread(tg, 0).start();
|
||||
new FetchThread(tg, 1).start();
|
||||
new FetchThread(tg, 2).start();
|
||||
new FetchThread(tg, 3).start();
|
||||
new FetchThread(tg, 0).start();
|
||||
new FetchThread(tg, 1).start();
|
||||
new FetchThread(tg, 2).start();
|
||||
new FetchThread(tg, 3).start();
|
||||
|
||||
orders = Ebean.find(Order.class).fetch("customer", new FetchConfig().lazy(100)).findList();
|
||||
Assert.assertTrue(orders.size() >= 4);
|
||||
|
||||
try {
|
||||
MyTestDataSourcePoolListener.SLEEP_AFTER_BORROW = 2000;
|
||||
|
||||
synchronized (mutex) {
|
||||
mutex.set(true);
|
||||
mutex.notifyAll();
|
||||
}
|
||||
|
||||
while (tg.activeCount() > 0) {
|
||||
Thread.sleep(100);
|
||||
}
|
||||
} finally {
|
||||
MyTestDataSourcePoolListener.SLEEP_AFTER_BORROW = 0;
|
||||
}
|
||||
|
||||
public void testRaceCondition_Complex() throws Throwable
|
||||
{
|
||||
ResetBasicData.reset();
|
||||
|
||||
ThreadGroup tg = new ThreadGroup("fetchers");
|
||||
new FetchThread(tg, 0).start();
|
||||
new FetchThread(tg, 1).start();
|
||||
new FetchThread(tg, 2).start();
|
||||
new FetchThread(tg, 3).start();
|
||||
new FetchThread(tg, 0).start();
|
||||
new FetchThread(tg, 1).start();
|
||||
new FetchThread(tg, 2).start();
|
||||
new FetchThread(tg, 3).start();
|
||||
|
||||
orders = Ebean.find(Order.class)
|
||||
.fetch("customer", new FetchConfig().lazy(100))
|
||||
.findList();
|
||||
assertTrue(orders.size() >= 4);
|
||||
|
||||
try
|
||||
{
|
||||
MyTestDataSourcePoolListener.SLEEP_AFTER_BORROW = 2000;
|
||||
|
||||
synchronized (mutex)
|
||||
{
|
||||
mutex.set(true);
|
||||
mutex.notifyAll();
|
||||
}
|
||||
|
||||
while(tg.activeCount() > 0)
|
||||
{
|
||||
Thread.sleep(100);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
MyTestDataSourcePoolListener.SLEEP_AFTER_BORROW = 0;
|
||||
}
|
||||
|
||||
if (exceptions.size() > 0)
|
||||
{
|
||||
System.err.println("Seen Exceptions:");
|
||||
for (Throwable exception : exceptions)
|
||||
{
|
||||
exception.printStackTrace();
|
||||
}
|
||||
Assert.fail();
|
||||
}
|
||||
if (exceptions.size() > 0) {
|
||||
System.err.println("Seen Exceptions:");
|
||||
for (Throwable exception : exceptions) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
Assert.fail();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,16 +2,17 @@ package com.avaje.tests.batchload;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.tests.model.basic.Contact;
|
||||
import com.avaje.tests.model.basic.Customer;
|
||||
|
||||
public class TestBasicNavOnEmpty extends TestCase {
|
||||
public class TestBasicNavOnEmpty extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
Customer c = new Customer();
|
||||
|
||||
@@ -5,14 +5,16 @@ import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.cache.ServerCacheManager;
|
||||
import com.avaje.ebean.config.GlobalProperties;
|
||||
import com.avaje.tests.model.basic.UUOne;
|
||||
|
||||
public class TestBatchLazyWithCacheHits extends TestCase {
|
||||
public class TestBatchLazyWithCacheHits extends BaseTestCase {
|
||||
|
||||
private UUOne insert(String name) {
|
||||
UUOne one = new UUOne();
|
||||
@@ -21,7 +23,8 @@ public class TestBatchLazyWithCacheHits extends TestCase {
|
||||
Ebean.save(one);
|
||||
return one;
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testOnCacheHit() {
|
||||
|
||||
GlobalProperties.put("ebean.lazyLoadBatchSize", "5");
|
||||
|
||||
@@ -6,15 +6,18 @@ import java.util.UUID;
|
||||
import javax.persistence.EntityNotFoundException;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.FetchConfig;
|
||||
import com.avaje.tests.model.basic.UUOne;
|
||||
import com.avaje.tests.model.basic.UUTwo;
|
||||
|
||||
public class TestBatchLazyWithDeleted extends TestCase {
|
||||
public class TestBatchLazyWithDeleted extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void testOnDeleted() {
|
||||
|
||||
UUOne oneA = new UUOne();
|
||||
|
||||
@@ -1,31 +1,31 @@
|
||||
package com.avaje.tests.batchload;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.tests.model.basic.Customer;
|
||||
import com.avaje.tests.model.basic.Order;
|
||||
import com.avaje.tests.model.basic.Order.Status;
|
||||
import com.avaje.tests.model.basic.ResetBasicData;
|
||||
|
||||
public class TestEmptyManyLazyLoad extends TestCase {
|
||||
public class TestEmptyManyLazyLoad extends BaseTestCase {
|
||||
|
||||
public void test() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
Customer c = Ebean.find(Customer.class)
|
||||
.findList()
|
||||
.get(0);
|
||||
|
||||
Order o = new Order();
|
||||
o.setCustomer(c);
|
||||
o.setStatus(Status.NEW);
|
||||
|
||||
Ebean.save(o);
|
||||
|
||||
Order o2 = Ebean.find(Order.class, o.getId());
|
||||
o2.getDetails().size();
|
||||
|
||||
}
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
Customer c = Ebean.find(Customer.class).findList().get(0);
|
||||
|
||||
Order o = new Order();
|
||||
o.setCustomer(c);
|
||||
o.setStatus(Status.NEW);
|
||||
|
||||
Ebean.save(o);
|
||||
|
||||
Order o2 = Ebean.find(Order.class, o.getId());
|
||||
o2.getDetails().size();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,8 +3,10 @@ package com.avaje.tests.batchload;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.Query;
|
||||
import com.avaje.tests.model.basic.Address;
|
||||
@@ -12,30 +14,28 @@ import com.avaje.tests.model.basic.Customer;
|
||||
import com.avaje.tests.model.basic.Order;
|
||||
import com.avaje.tests.model.basic.ResetBasicData;
|
||||
|
||||
public class TestLazyJoin extends TestCase {
|
||||
public class TestLazyJoin extends BaseTestCase {
|
||||
|
||||
public void testLazyOnNonLoaded() {
|
||||
@Test
|
||||
public void testLazyOnNonLoaded() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
ResetBasicData.reset();
|
||||
|
||||
Query<Order> query = Ebean.find(Order.class)
|
||||
.select("status")
|
||||
.fetch("customer", "+lazy(10) name, status")
|
||||
.fetch("customer.contacts");
|
||||
Query<Order> query = Ebean.find(Order.class).select("status")
|
||||
.fetch("customer", "+lazy(10) name, status").fetch("customer.contacts");
|
||||
|
||||
List<Order> list = query.findList();
|
||||
List<Order> list = query.findList();
|
||||
|
||||
|
||||
Order order = list.get(0);
|
||||
Customer customer = order.getCustomer();
|
||||
|
||||
// this invokes lazy loading on a property that is
|
||||
// not one of the selected ones (name, status) ... and
|
||||
// therefore the lazy load query selects all properties
|
||||
// in the customer (not just name and status)
|
||||
Address billingAddress = customer.getBillingAddress();
|
||||
Order order = list.get(0);
|
||||
Customer customer = order.getCustomer();
|
||||
|
||||
// this invokes lazy loading on a property that is
|
||||
// not one of the selected ones (name, status) ... and
|
||||
// therefore the lazy load query selects all properties
|
||||
// in the customer (not just name and status)
|
||||
Address billingAddress = customer.getBillingAddress();
|
||||
|
||||
Assert.assertNotNull(billingAddress);
|
||||
}
|
||||
|
||||
Assert.assertNotNull(billingAddress);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,8 +3,10 @@ package com.avaje.tests.batchload;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.FetchConfig;
|
||||
import com.avaje.ebean.Query;
|
||||
@@ -14,87 +16,75 @@ import com.avaje.tests.model.basic.Customer;
|
||||
import com.avaje.tests.model.basic.Order;
|
||||
import com.avaje.tests.model.basic.ResetBasicData;
|
||||
|
||||
public class TestLazyJoin2 extends TestCase {
|
||||
public class TestLazyJoin2 extends BaseTestCase {
|
||||
|
||||
public void testLazyOnNonLoaded() {
|
||||
@Test
|
||||
public void testLazyOnNonLoaded() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
ResetBasicData.reset();
|
||||
|
||||
// This will use 3 SQL queries to build this object graph
|
||||
List<Order> l0 = Ebean.find(Order.class)
|
||||
.select("status, shipDate")
|
||||
|
||||
.fetch("details", "orderQty, unitPrice", new FetchConfig().query())
|
||||
.fetch("details.product", "sku, name")
|
||||
|
||||
.fetch("customer", "name", new FetchConfig().query(10))
|
||||
.fetch("customer.contacts","firstName, lastName, mobile")
|
||||
.fetch("customer.shippingAddress","line1, city")
|
||||
.order().asc("id")
|
||||
.findList();
|
||||
|
||||
|
||||
Order o0 = l0.get(0);
|
||||
Customer c0 = o0.getCustomer();
|
||||
List<Contact> contacts = c0.getContacts();
|
||||
Assert.assertTrue(contacts.size() > 0);
|
||||
|
||||
// query 1) find order (status, shipDate)
|
||||
// query 2) find orderDetail (quantity, price) join product (sku, name) where order.id in (?,? ...)
|
||||
// query 3) find customer (name) join contacts (*) join shippingAddress (*) where id in (?,?,?,?,?)
|
||||
|
||||
|
||||
// This will use 3 SQL queries to build this object graph
|
||||
List<Order> l0 = Ebean.find(Order.class).select("status, shipDate")
|
||||
|
||||
|
||||
List<Order> orders = Ebean.find(Order.class)
|
||||
//.select("status")
|
||||
.fetch("customer", new FetchConfig().query(3).lazy(10))
|
||||
.order().asc("id")
|
||||
.findList();
|
||||
//.join("customer.contacts");
|
||||
.fetch("details", "orderQty, unitPrice", new FetchConfig().query())
|
||||
.fetch("details.product", "sku, name")
|
||||
|
||||
//List<Order> list = query.findList();
|
||||
.fetch("customer", "name", new FetchConfig().query(10))
|
||||
.fetch("customer.contacts", "firstName, lastName, mobile")
|
||||
.fetch("customer.shippingAddress", "line1, city").order().asc("id").findList();
|
||||
|
||||
|
||||
Order order = orders.get(0);
|
||||
Customer customer = order.getCustomer();
|
||||
|
||||
// this invokes lazy loading on a property that is
|
||||
// not one of the selected ones (name, status) ... and
|
||||
// therefore the lazy load query selects all properties
|
||||
// in the customer (not just name and status)
|
||||
Address billingAddress = customer.getBillingAddress();
|
||||
Order o0 = l0.get(0);
|
||||
Customer c0 = o0.getCustomer();
|
||||
List<Contact> contacts = c0.getContacts();
|
||||
Assert.assertTrue(contacts.size() > 0);
|
||||
|
||||
// query 1) find order (status, shipDate)
|
||||
// query 2) find orderDetail (quantity, price) join product (sku, name)
|
||||
// where order.id in (?,? ...)
|
||||
// query 3) find customer (name) join contacts (*) join shippingAddress (*)
|
||||
// where id in (?,?,?,?,?)
|
||||
|
||||
List<Order> orders = Ebean.find(Order.class)
|
||||
// .select("status")
|
||||
.fetch("customer", new FetchConfig().query(3).lazy(10)).order().asc("id").findList();
|
||||
// .join("customer.contacts");
|
||||
|
||||
// List<Order> list = query.findList();
|
||||
|
||||
Order order = orders.get(0);
|
||||
Customer customer = order.getCustomer();
|
||||
|
||||
// this invokes lazy loading on a property that is
|
||||
// not one of the selected ones (name, status) ... and
|
||||
// therefore the lazy load query selects all properties
|
||||
// in the customer (not just name and status)
|
||||
Address billingAddress = customer.getBillingAddress();
|
||||
|
||||
Assert.assertNotNull(billingAddress);
|
||||
|
||||
List<Order> list = Ebean.find(Order.class).fetch("customer", "name", new FetchConfig().lazy(5))
|
||||
.fetch("customer.contacts", "contactName, phone, email").fetch("customer.shippingAddress")
|
||||
.where().eq("status", Order.Status.NEW).order().asc("id").findList();
|
||||
|
||||
Order order2 = list.get(0);
|
||||
Customer customer2 = order2.getCustomer();
|
||||
// customer2.getStatus();
|
||||
String name = customer2.getName();
|
||||
Assert.assertNotNull(name);
|
||||
|
||||
String q = "find order join customer (+query(1) +lazy(10) name, status) join customer.contacts ";
|
||||
Query<Order> query = Ebean.createQuery(Order.class, q);
|
||||
|
||||
List<Order> list3 = query.findList();
|
||||
Order order3 = list3.get(0);
|
||||
String n3 = order3.getCustomer().getName();
|
||||
|
||||
for (Order o3 : list3) {
|
||||
o3.getCustomer().getName();
|
||||
}
|
||||
|
||||
Assert.assertNotNull(n3);
|
||||
|
||||
}
|
||||
|
||||
Assert.assertNotNull(billingAddress);
|
||||
|
||||
|
||||
List<Order> list = Ebean.find(Order.class)
|
||||
.fetch("customer","name", new FetchConfig().lazy(5))
|
||||
.fetch("customer.contacts","contactName, phone, email")
|
||||
.fetch("customer.shippingAddress")
|
||||
.where().eq("status",Order.Status.NEW)
|
||||
.order().asc("id")
|
||||
.findList();
|
||||
|
||||
Order order2 = list.get(0);
|
||||
Customer customer2 = order2.getCustomer();
|
||||
//customer2.getStatus();
|
||||
String name = customer2.getName();
|
||||
Assert.assertNotNull(name);
|
||||
|
||||
String q = "find order join customer (+query(1) +lazy(10) name, status) join customer.contacts ";
|
||||
Query<Order> query = Ebean.createQuery(Order.class, q);
|
||||
|
||||
List<Order> list3 = query.findList();
|
||||
Order order3 = list3.get(0);
|
||||
String n3 = order3.getCustomer().getName();
|
||||
|
||||
for (Order o3 : list3) {
|
||||
o3.getCustomer().getName();
|
||||
}
|
||||
|
||||
Assert.assertNotNull(n3);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,43 +2,42 @@ package com.avaje.tests.batchload;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.FetchConfig;
|
||||
import com.avaje.tests.model.basic.Contact;
|
||||
import com.avaje.tests.model.basic.Customer;
|
||||
import com.avaje.tests.model.basic.ResetBasicData;
|
||||
|
||||
public class TestLazyLoadEmptyCollection extends TestCase {
|
||||
public class TestLazyLoadEmptyCollection extends BaseTestCase {
|
||||
|
||||
public void test() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
Customer c = new Customer();
|
||||
c.setName("lazytest");
|
||||
|
||||
Contact con = new Contact("jim", "slim");
|
||||
c.addContact(con);
|
||||
|
||||
Ebean.save(c);
|
||||
|
||||
List<Customer> list = Ebean.find(Customer.class)
|
||||
.fetch("contacts", new FetchConfig().query(0))
|
||||
.fetch("contacts.notes", new FetchConfig().query(100))
|
||||
.findList();
|
||||
|
||||
for (Customer customer : list) {
|
||||
List<Contact> contacts = customer.getContacts();
|
||||
for (Contact contact : contacts) {
|
||||
contact.getNotes();
|
||||
}
|
||||
System.out.println(customer);
|
||||
System.out.println(contacts);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
Customer c = new Customer();
|
||||
c.setName("lazytest");
|
||||
|
||||
Contact con = new Contact("jim", "slim");
|
||||
c.addContact(con);
|
||||
|
||||
Ebean.save(c);
|
||||
|
||||
List<Customer> list = Ebean.find(Customer.class).fetch("contacts", new FetchConfig().query(0))
|
||||
.fetch("contacts.notes", new FetchConfig().query(100)).findList();
|
||||
|
||||
for (Customer customer : list) {
|
||||
List<Contact> contacts = customer.getContacts();
|
||||
for (Contact contact : contacts) {
|
||||
contact.getNotes();
|
||||
}
|
||||
System.out.println(customer);
|
||||
System.out.println(contacts);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,13 +5,16 @@ import java.util.UUID;
|
||||
import javax.persistence.EntityNotFoundException;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.tests.model.basic.UUOne;
|
||||
|
||||
public class TestLazyLoadNonExistantBean extends TestCase {
|
||||
public class TestLazyLoadNonExistantBean extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void testSimple() {
|
||||
|
||||
UUID uuid = UUID.randomUUID();
|
||||
|
||||
@@ -2,45 +2,44 @@ package com.avaje.tests.batchload;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.BeanState;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.tests.model.basic.Customer;
|
||||
import com.avaje.tests.model.basic.ResetBasicData;
|
||||
|
||||
public class TestLoadOnDirty extends TestCase {
|
||||
public class TestLoadOnDirty extends BaseTestCase {
|
||||
|
||||
public void test() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
List<Customer> custs = Ebean.find(Customer.class).findList();
|
||||
|
||||
Customer customer = Ebean.find(Customer.class)
|
||||
.setId(custs.get(0).getId())
|
||||
.select("name")
|
||||
.findUnique();
|
||||
|
||||
BeanState beanState = Ebean.getBeanState(customer);
|
||||
Assert.assertTrue(!beanState.isNew());
|
||||
Assert.assertTrue(!beanState.isDirty());
|
||||
Assert.assertTrue(!beanState.isNewOrDirty());
|
||||
Assert.assertNotNull(beanState.getLoadedProps());
|
||||
|
||||
customer.setName("dirtyNameProp");
|
||||
Assert.assertTrue(beanState.isDirty());
|
||||
Assert.assertTrue(beanState.getChangedProps().contains("name"));
|
||||
Assert.assertEquals(1, beanState.getChangedProps().size());
|
||||
|
||||
customer.setStatus(Customer.Status.INACTIVE);
|
||||
|
||||
Assert.assertTrue(beanState.isDirty());
|
||||
Assert.assertTrue(beanState.getChangedProps().contains("status"));
|
||||
Assert.assertTrue(beanState.getChangedProps().contains("name"));
|
||||
Assert.assertEquals(2, beanState.getChangedProps().size());
|
||||
|
||||
}
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
List<Customer> custs = Ebean.find(Customer.class).findList();
|
||||
|
||||
Customer customer = Ebean.find(Customer.class).setId(custs.get(0).getId()).select("name")
|
||||
.findUnique();
|
||||
|
||||
BeanState beanState = Ebean.getBeanState(customer);
|
||||
Assert.assertTrue(!beanState.isNew());
|
||||
Assert.assertTrue(!beanState.isDirty());
|
||||
Assert.assertTrue(!beanState.isNewOrDirty());
|
||||
Assert.assertNotNull(beanState.getLoadedProps());
|
||||
|
||||
customer.setName("dirtyNameProp");
|
||||
Assert.assertTrue(beanState.isDirty());
|
||||
Assert.assertTrue(beanState.getChangedProps().contains("name"));
|
||||
Assert.assertEquals(1, beanState.getChangedProps().size());
|
||||
|
||||
customer.setStatus(Customer.Status.INACTIVE);
|
||||
|
||||
Assert.assertTrue(beanState.isDirty());
|
||||
Assert.assertTrue(beanState.getChangedProps().contains("status"));
|
||||
Assert.assertTrue(beanState.getChangedProps().contains("name"));
|
||||
Assert.assertEquals(2, beanState.getChangedProps().size());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,8 +3,10 @@ package com.avaje.tests.batchload;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.BeanState;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.Query;
|
||||
@@ -14,56 +16,52 @@ import com.avaje.tests.model.basic.Customer;
|
||||
import com.avaje.tests.model.basic.Order;
|
||||
import com.avaje.tests.model.basic.ResetBasicData;
|
||||
|
||||
public class TestQueryJoin extends TestCase {
|
||||
public class TestQueryJoin extends BaseTestCase {
|
||||
|
||||
|
||||
public void test() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
|
||||
// Need to make sure the customer cache is cleared for the later
|
||||
// asserts on the lazy loading
|
||||
ServerCache custCache = Ebean.getServerCacheManager().getBeanCache(Customer.class);
|
||||
custCache.clear();
|
||||
|
||||
Query<Order> query = Ebean.find(Order.class)
|
||||
.select("status")
|
||||
//.join("details","+query(10)")
|
||||
.fetch("customer","+lazy(10) name, status")
|
||||
.fetch("customer.contacts")
|
||||
.orderBy().asc("id");
|
||||
//.join("customer.billingAddress");
|
||||
|
||||
List<Order> list = query.findList();
|
||||
|
||||
//list.get(0).getShipDate();
|
||||
|
||||
Order order = list.get(0);
|
||||
BeanState beanStateOrder = Ebean.getBeanState(order);
|
||||
Assert.assertNotNull(beanStateOrder.getLoadedProps());
|
||||
//Assert.assertTrue(beanStateOrder.getLoadedProps().contains("id"));
|
||||
Assert.assertTrue(beanStateOrder.getLoadedProps().contains("status"));
|
||||
Assert.assertTrue(beanStateOrder.getLoadedProps().contains("shipments"));
|
||||
Assert.assertTrue(beanStateOrder.getLoadedProps().contains("customer"));
|
||||
|
||||
Customer customer = order.getCustomer();
|
||||
BeanState beanStateCustomer = Ebean.getBeanState(customer);
|
||||
Assert.assertNull(beanStateCustomer.getLoadedProps());
|
||||
|
||||
customer.getName();
|
||||
Assert.assertNotNull(beanStateCustomer.getLoadedProps());
|
||||
Assert.assertTrue(beanStateCustomer.getLoadedProps().contains("name"));
|
||||
Assert.assertTrue(beanStateCustomer.getLoadedProps().contains("status"));
|
||||
Assert.assertFalse(beanStateCustomer.getLoadedProps().contains("billingAddress"));
|
||||
|
||||
customer.getName();
|
||||
|
||||
Address billingAddress = customer.getBillingAddress();
|
||||
System.out.println(billingAddress);
|
||||
billingAddress.getLine1();
|
||||
|
||||
Assert.assertTrue(list.size() > 0);
|
||||
|
||||
}
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
// Need to make sure the customer cache is cleared for the later
|
||||
// asserts on the lazy loading
|
||||
ServerCache custCache = Ebean.getServerCacheManager().getBeanCache(Customer.class);
|
||||
custCache.clear();
|
||||
|
||||
Query<Order> query = Ebean.find(Order.class).select("status")
|
||||
// .join("details","+query(10)")
|
||||
.fetch("customer", "+lazy(10) name, status").fetch("customer.contacts").orderBy().asc("id");
|
||||
// .join("customer.billingAddress");
|
||||
|
||||
List<Order> list = query.findList();
|
||||
|
||||
// list.get(0).getShipDate();
|
||||
|
||||
Order order = list.get(0);
|
||||
BeanState beanStateOrder = Ebean.getBeanState(order);
|
||||
Assert.assertNotNull(beanStateOrder.getLoadedProps());
|
||||
// Assert.assertTrue(beanStateOrder.getLoadedProps().contains("id"));
|
||||
Assert.assertTrue(beanStateOrder.getLoadedProps().contains("status"));
|
||||
Assert.assertTrue(beanStateOrder.getLoadedProps().contains("shipments"));
|
||||
Assert.assertTrue(beanStateOrder.getLoadedProps().contains("customer"));
|
||||
|
||||
Customer customer = order.getCustomer();
|
||||
BeanState beanStateCustomer = Ebean.getBeanState(customer);
|
||||
Assert.assertNull(beanStateCustomer.getLoadedProps());
|
||||
|
||||
customer.getName();
|
||||
Assert.assertNotNull(beanStateCustomer.getLoadedProps());
|
||||
Assert.assertTrue(beanStateCustomer.getLoadedProps().contains("name"));
|
||||
Assert.assertTrue(beanStateCustomer.getLoadedProps().contains("status"));
|
||||
Assert.assertFalse(beanStateCustomer.getLoadedProps().contains("billingAddress"));
|
||||
|
||||
customer.getName();
|
||||
|
||||
Address billingAddress = customer.getBillingAddress();
|
||||
System.out.println(billingAddress);
|
||||
billingAddress.getLine1();
|
||||
|
||||
Assert.assertTrue(list.size() > 0);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,32 +3,33 @@ package com.avaje.tests.batchload;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.FetchConfig;
|
||||
import com.avaje.tests.model.basic.Order;
|
||||
import com.avaje.tests.model.basic.ResetBasicData;
|
||||
|
||||
public class TestQueryJoinToAssocOne extends TestCase {
|
||||
public class TestQueryJoinToAssocOne extends BaseTestCase {
|
||||
|
||||
public void testLazyOnNonLoaded() {
|
||||
@Test
|
||||
public void testLazyOnNonLoaded() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
ResetBasicData.reset();
|
||||
|
||||
// This will use 3 SQL queries to build this object graph
|
||||
List<Order> l0 = Ebean.find(Order.class)
|
||||
.select("status, shipDate")
|
||||
.fetch("details", "orderQty, unitPrice", new FetchConfig().query())
|
||||
.fetch("details.product", "sku, name")
|
||||
|
||||
//.join("customer", "name", new JoinConfig().query(10))
|
||||
//.join("customer.contacts","firstName, lastName, mobile")
|
||||
//.join("customer.shippingAddress","line1, city")
|
||||
.findList();
|
||||
|
||||
Assert.assertTrue(l0.size() > 0);
|
||||
|
||||
|
||||
}
|
||||
// This will use 3 SQL queries to build this object graph
|
||||
List<Order> l0 = Ebean.find(Order.class).select("status, shipDate")
|
||||
.fetch("details", "orderQty, unitPrice", new FetchConfig().query())
|
||||
.fetch("details.product", "sku, name")
|
||||
|
||||
// .join("customer", "name", new JoinConfig().query(10))
|
||||
// .join("customer.contacts","firstName, lastName, mobile")
|
||||
// .join("customer.shippingAddress","line1, city")
|
||||
.findList();
|
||||
|
||||
Assert.assertTrue(l0.size() > 0);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,27 +1,27 @@
|
||||
package com.avaje.tests.batchload;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.FetchConfig;
|
||||
import com.avaje.tests.model.basic.Customer;
|
||||
|
||||
public class TestSecondQueryNoRows extends TestCase {
|
||||
public class TestSecondQueryNoRows extends BaseTestCase {
|
||||
|
||||
public void test() {
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
Customer cnew = new Customer();
|
||||
cnew.setName("testSecQueryNoRows");
|
||||
Customer cnew = new Customer();
|
||||
cnew.setName("testSecQueryNoRows");
|
||||
|
||||
Ebean.save(cnew);
|
||||
Ebean.save(cnew);
|
||||
|
||||
Customer c = Ebean.find(Customer.class)
|
||||
.setAutofetch(false)
|
||||
.setId(cnew.getId())
|
||||
.fetch("contacts", new FetchConfig().query())
|
||||
.findUnique();
|
||||
Customer c = Ebean.find(Customer.class).setAutofetch(false).setId(cnew.getId())
|
||||
.fetch("contacts", new FetchConfig().query()).findUnique();
|
||||
|
||||
Assert.assertNotNull(c);
|
||||
}
|
||||
Assert.assertNotNull(c);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,42 +2,35 @@ package com.avaje.tests.batchload;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.tests.model.basic.Customer;
|
||||
import com.avaje.tests.model.basic.Order;
|
||||
import com.avaje.tests.model.basic.ResetBasicData;
|
||||
|
||||
public class TestSecondaryQueries extends TestCase {
|
||||
public class TestSecondaryQueries extends BaseTestCase {
|
||||
|
||||
public void testQueries() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
Order testOrder = ResetBasicData.createOrderCustAndOrder("testSecQry10");
|
||||
Integer custId = testOrder.getCustomer().getId();
|
||||
|
||||
|
||||
Customer cust = Ebean.find(Customer.class)
|
||||
.select("name")
|
||||
.fetch("contacts","+query")
|
||||
.setId(custId)
|
||||
.findUnique();
|
||||
|
||||
Assert.assertNotNull(cust);
|
||||
|
||||
List<Order> list = Ebean.find(Order.class)
|
||||
.select("status")
|
||||
.fetch("details","+query(10)")
|
||||
.fetch("customer","+query name, status")
|
||||
.fetch("customer.contacts")
|
||||
.where().eq("status", Order.Status.NEW)
|
||||
.findList();
|
||||
@Test
|
||||
public void testQueries() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
Order testOrder = ResetBasicData.createOrderCustAndOrder("testSecQry10");
|
||||
Integer custId = testOrder.getCustomer().getId();
|
||||
|
||||
Customer cust = Ebean.find(Customer.class).select("name").fetch("contacts", "+query")
|
||||
.setId(custId).findUnique();
|
||||
|
||||
Assert.assertNotNull(cust);
|
||||
|
||||
List<Order> list = Ebean.find(Order.class).select("status").fetch("details", "+query(10)")
|
||||
.fetch("customer", "+query name, status").fetch("customer.contacts").where()
|
||||
.eq("status", Order.Status.NEW).findList();
|
||||
|
||||
Assert.assertTrue(list.size() > 0);
|
||||
}
|
||||
|
||||
Assert.assertTrue(list.size() > 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+133
-130
@@ -1,144 +1,147 @@
|
||||
package com.avaje.tests.cache;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.cache.ServerCache;
|
||||
import com.avaje.ebean.cache.ServerCacheStatistics;
|
||||
import com.avaje.tests.model.basic.Country;
|
||||
import com.avaje.tests.model.basic.ResetBasicData;
|
||||
|
||||
public class TestCacheBasic extends TestCase {
|
||||
public class TestCacheBasic extends BaseTestCase {
|
||||
|
||||
|
||||
public void test(){
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
Ebean.getServerCacheManager().clear(Country.class);
|
||||
ServerCache countryCache = Ebean.getServerCacheManager().getBeanCache(Country.class);
|
||||
|
||||
Ebean.runCacheWarming(Country.class);
|
||||
Assert.assertTrue(countryCache.size() > 0);
|
||||
|
||||
// reset the statistics
|
||||
countryCache.getStatistics(true);
|
||||
|
||||
Country c0 = Ebean.getReference(Country.class, "NZ");
|
||||
ServerCacheStatistics statistics = countryCache.getStatistics(false);
|
||||
int hc = statistics.getHitCount();
|
||||
Assert.assertEquals(1, hc);
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
// Country c1 = Ebean.getReference(Country.class, "NZ");
|
||||
// Assert.assertEquals(2, countryCache.getStatistics(false).getHitCount());
|
||||
// //Assert.assertEquals(100, countryCache.getStatistics(false).getHitRatio());
|
||||
//
|
||||
// // same instance as caching with readOnly=true
|
||||
// Assert.assertTrue(c0 != c1);
|
||||
//
|
||||
// c0.getName();
|
||||
// c1.getName();
|
||||
//
|
||||
// // reset the statistics
|
||||
// Assert.assertEquals(2,countryCache.getStatistics(true).getHitCount());
|
||||
// // now the count should be 0 again
|
||||
// Assert.assertEquals(0, countryCache.getStatistics(false).getHitCount());
|
||||
// // and hitRatio is 0 as well
|
||||
// Assert.assertEquals(0, countryCache.getStatistics(false).getHitRatio());
|
||||
//
|
||||
// // hit the country cache automatically via join
|
||||
//
|
||||
// Customer custTest = ResetBasicData.createCustAndOrder("cacheBasic");
|
||||
// Integer id = custTest.getId();
|
||||
// Customer customer = Ebean.find(Customer.class, id);
|
||||
//
|
||||
// Address billingAddress = customer.getBillingAddress();
|
||||
// Country c2 = billingAddress.getCountry();
|
||||
// c2.getName();
|
||||
//
|
||||
// Assert.assertTrue(countryCache.getStatistics(false).getHitCount() > 0);
|
||||
//
|
||||
// //Country c3 = Ebean.getReference(Country.class, "NZ");
|
||||
// //Country c4 = Ebean.find(Country.class, "NZ");
|
||||
//
|
||||
//
|
||||
// // clear the cache
|
||||
// Ebean.getServerCacheManager().clear(Country.class);
|
||||
// // reset statistics
|
||||
// countryCache.getStatistics(true);
|
||||
//
|
||||
// // try to hit the country cache automatically via join
|
||||
// customer = Ebean.find(Customer.class, id);
|
||||
// billingAddress = customer.getBillingAddress();
|
||||
// Country c5 = billingAddress.getCountry();
|
||||
// // but cache is empty so c5 is reference that will load cache
|
||||
// // if it is lazy loaded
|
||||
// Assert.assertEquals("empty cache",0,countryCache.getStatistics(false).getSize());
|
||||
// //Assert.assertEquals("missCount 1",1,countryCache.getStatistics(false).getMissCount());
|
||||
//
|
||||
// // lazy load on c5 populates the cache
|
||||
// c5.getName();
|
||||
// Assert.assertEquals("cache populated via lazy load",1,countryCache.getStatistics(false).getSize());
|
||||
//
|
||||
// // now these get hits in the cache
|
||||
// Country c6 = Ebean.find(Country.class, "NZ");
|
||||
//
|
||||
// Assert.assertTrue("different instance as cache cleared",c2 != c5);
|
||||
// Assert.assertTrue("these 2 are different",c5 != c6);
|
||||
//
|
||||
// // by default readOnly based on deployment annotation
|
||||
// Assert.assertTrue("read only",Ebean.getBeanState(c6).isReadOnly());
|
||||
//
|
||||
// try {
|
||||
// // can't modify a readOnly bean
|
||||
// c6.setName("Nu Zilund");
|
||||
// Assert.assertFalse("Never get here",true);
|
||||
// } catch (IllegalStateException e){
|
||||
// Assert.assertTrue("This is readOnly",true);
|
||||
// }
|
||||
//
|
||||
// Country c8 = Ebean.find(Country.class)
|
||||
// .setId("NZ")
|
||||
// .setReadOnly(false)
|
||||
// .findUnique();
|
||||
//
|
||||
// // Explicitly NOT readOnly
|
||||
// Assert.assertFalse("NOT read only",Ebean.getBeanState(c8).isReadOnly());
|
||||
//
|
||||
// Assert.assertEquals("1 countries in cache", 1, countryCache.size());
|
||||
// c8.setName("Nu Zilund");
|
||||
// // the update will remove the entry from the cache
|
||||
// Ebean.save(c8);
|
||||
//
|
||||
// Assert.assertEquals("1 country in cache", 1, countryCache.size());
|
||||
//
|
||||
// Country c9 = Ebean.find(Country.class)
|
||||
// .setReadOnly(false)
|
||||
// .setId("NZ")
|
||||
// .findUnique();
|
||||
//
|
||||
// // Find loads cache ...
|
||||
// Assert.assertFalse(Ebean.getBeanState(c9).isReadOnly());
|
||||
// Assert.assertTrue(countryCache.size() > 0);
|
||||
//
|
||||
// Country c10 = Ebean.find(Country.class,"NZ");
|
||||
//
|
||||
// Assert.assertTrue(Ebean.getBeanState(c10).isReadOnly());
|
||||
// Assert.assertTrue(countryCache.size() > 0);
|
||||
//
|
||||
// Ebean.getServerCacheManager().clear(Country.class);
|
||||
// Assert.assertEquals("0 country in cache", 0, countryCache.size());
|
||||
//
|
||||
// // reference doesn't load cache yet
|
||||
// Country c11 = Ebean.getReference(Country.class, "NZ");
|
||||
//
|
||||
// // still 0 in cache
|
||||
// Assert.assertEquals("0 country in cache", 0, countryCache.size());
|
||||
//
|
||||
// // will invoke lazy loading..
|
||||
// c11.getName();
|
||||
// Assert.assertTrue(countryCache.size() > 0);
|
||||
ResetBasicData.reset();
|
||||
|
||||
}
|
||||
Ebean.getServerCacheManager().clear(Country.class);
|
||||
ServerCache countryCache = Ebean.getServerCacheManager().getBeanCache(Country.class);
|
||||
|
||||
Ebean.runCacheWarming(Country.class);
|
||||
Assert.assertTrue(countryCache.size() > 0);
|
||||
|
||||
// reset the statistics
|
||||
countryCache.getStatistics(true);
|
||||
|
||||
Country c0 = Ebean.getReference(Country.class, "NZ");
|
||||
ServerCacheStatistics statistics = countryCache.getStatistics(false);
|
||||
int hc = statistics.getHitCount();
|
||||
Assert.assertEquals(1, hc);
|
||||
|
||||
// Country c1 = Ebean.getReference(Country.class, "NZ");
|
||||
// Assert.assertEquals(2, countryCache.getStatistics(false).getHitCount());
|
||||
// //Assert.assertEquals(100,
|
||||
// countryCache.getStatistics(false).getHitRatio());
|
||||
//
|
||||
// // same instance as caching with readOnly=true
|
||||
// Assert.assertTrue(c0 != c1);
|
||||
//
|
||||
// c0.getName();
|
||||
// c1.getName();
|
||||
//
|
||||
// // reset the statistics
|
||||
// Assert.assertEquals(2,countryCache.getStatistics(true).getHitCount());
|
||||
// // now the count should be 0 again
|
||||
// Assert.assertEquals(0, countryCache.getStatistics(false).getHitCount());
|
||||
// // and hitRatio is 0 as well
|
||||
// Assert.assertEquals(0, countryCache.getStatistics(false).getHitRatio());
|
||||
//
|
||||
// // hit the country cache automatically via join
|
||||
//
|
||||
// Customer custTest = ResetBasicData.createCustAndOrder("cacheBasic");
|
||||
// Integer id = custTest.getId();
|
||||
// Customer customer = Ebean.find(Customer.class, id);
|
||||
//
|
||||
// Address billingAddress = customer.getBillingAddress();
|
||||
// Country c2 = billingAddress.getCountry();
|
||||
// c2.getName();
|
||||
//
|
||||
// Assert.assertTrue(countryCache.getStatistics(false).getHitCount() > 0);
|
||||
//
|
||||
// //Country c3 = Ebean.getReference(Country.class, "NZ");
|
||||
// //Country c4 = Ebean.find(Country.class, "NZ");
|
||||
//
|
||||
//
|
||||
// // clear the cache
|
||||
// Ebean.getServerCacheManager().clear(Country.class);
|
||||
// // reset statistics
|
||||
// countryCache.getStatistics(true);
|
||||
//
|
||||
// // try to hit the country cache automatically via join
|
||||
// customer = Ebean.find(Customer.class, id);
|
||||
// billingAddress = customer.getBillingAddress();
|
||||
// Country c5 = billingAddress.getCountry();
|
||||
// // but cache is empty so c5 is reference that will load cache
|
||||
// // if it is lazy loaded
|
||||
// Assert.assertEquals("empty cache",0,countryCache.getStatistics(false).getSize());
|
||||
// //Assert.assertEquals("missCount 1",1,countryCache.getStatistics(false).getMissCount());
|
||||
//
|
||||
// // lazy load on c5 populates the cache
|
||||
// c5.getName();
|
||||
// Assert.assertEquals("cache populated via lazy load",1,countryCache.getStatistics(false).getSize());
|
||||
//
|
||||
// // now these get hits in the cache
|
||||
// Country c6 = Ebean.find(Country.class, "NZ");
|
||||
//
|
||||
// Assert.assertTrue("different instance as cache cleared",c2 != c5);
|
||||
// Assert.assertTrue("these 2 are different",c5 != c6);
|
||||
//
|
||||
// // by default readOnly based on deployment annotation
|
||||
// Assert.assertTrue("read only",Ebean.getBeanState(c6).isReadOnly());
|
||||
//
|
||||
// try {
|
||||
// // can't modify a readOnly bean
|
||||
// c6.setName("Nu Zilund");
|
||||
// Assert.assertFalse("Never get here",true);
|
||||
// } catch (IllegalStateException e){
|
||||
// Assert.assertTrue("This is readOnly",true);
|
||||
// }
|
||||
//
|
||||
// Country c8 = Ebean.find(Country.class)
|
||||
// .setId("NZ")
|
||||
// .setReadOnly(false)
|
||||
// .findUnique();
|
||||
//
|
||||
// // Explicitly NOT readOnly
|
||||
// Assert.assertFalse("NOT read only",Ebean.getBeanState(c8).isReadOnly());
|
||||
//
|
||||
// Assert.assertEquals("1 countries in cache", 1, countryCache.size());
|
||||
// c8.setName("Nu Zilund");
|
||||
// // the update will remove the entry from the cache
|
||||
// Ebean.save(c8);
|
||||
//
|
||||
// Assert.assertEquals("1 country in cache", 1, countryCache.size());
|
||||
//
|
||||
// Country c9 = Ebean.find(Country.class)
|
||||
// .setReadOnly(false)
|
||||
// .setId("NZ")
|
||||
// .findUnique();
|
||||
//
|
||||
// // Find loads cache ...
|
||||
// Assert.assertFalse(Ebean.getBeanState(c9).isReadOnly());
|
||||
// Assert.assertTrue(countryCache.size() > 0);
|
||||
//
|
||||
// Country c10 = Ebean.find(Country.class,"NZ");
|
||||
//
|
||||
// Assert.assertTrue(Ebean.getBeanState(c10).isReadOnly());
|
||||
// Assert.assertTrue(countryCache.size() > 0);
|
||||
//
|
||||
// Ebean.getServerCacheManager().clear(Country.class);
|
||||
// Assert.assertEquals("0 country in cache", 0, countryCache.size());
|
||||
//
|
||||
// // reference doesn't load cache yet
|
||||
// Country c11 = Ebean.getReference(Country.class, "NZ");
|
||||
//
|
||||
// // still 0 in cache
|
||||
// Assert.assertEquals("0 country in cache", 0, countryCache.size());
|
||||
//
|
||||
// // will invoke lazy loading..
|
||||
// c11.getName();
|
||||
// Assert.assertTrue(countryCache.size() > 0);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+59
-57
@@ -2,76 +2,78 @@ package com.avaje.tests.cache;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.cache.ServerCache;
|
||||
import com.avaje.tests.model.basic.Contact;
|
||||
import com.avaje.tests.model.basic.Customer;
|
||||
import com.avaje.tests.model.basic.ResetBasicData;
|
||||
|
||||
public class TestCacheCollectionIds extends TestCase {
|
||||
public class TestCacheCollectionIds extends BaseTestCase {
|
||||
|
||||
public void test() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
ServerCache custCache = Ebean.getServerCacheManager().getBeanCache(Customer.class);
|
||||
ServerCache contactCache = Ebean.getServerCacheManager().getBeanCache(Contact.class);
|
||||
ServerCache custManyIdsCache = Ebean.getServerCacheManager().getCollectionIdsCache(Customer.class,"contacts");
|
||||
|
||||
//Ebean.getServerCacheManager().setCaching(Customer.class, true);
|
||||
//Ebean.getServerCacheManager().setCaching(Contact.class, true);
|
||||
|
||||
custCache.clear();
|
||||
custManyIdsCache.clear();
|
||||
|
||||
List<Customer> list = Ebean.find(Customer.class)
|
||||
.setAutofetch(false)
|
||||
.setLoadBeanCache(true)
|
||||
.order().asc("id")
|
||||
.findList();
|
||||
|
||||
Assert.assertTrue(list.size() > 1);
|
||||
//Assert.assertEquals(list.size(), custCache.getStatistics(false).getSize());
|
||||
|
||||
Customer customer = list.get(0);
|
||||
List<Contact> contacts = customer.getContacts();
|
||||
//Assert.assertEquals(0, custManyIdsCache.getStatistics(false).getSize());
|
||||
contacts.size();
|
||||
Assert.assertTrue(contacts.size() > 1);
|
||||
//Assert.assertEquals(1, custManyIdsCache.getStatistics(false).getSize());
|
||||
//Assert.assertEquals(0, custManyIdsCache.getStatistics(false).getHitCount());
|
||||
|
||||
fetchCustomer(customer.getId());
|
||||
//Assert.assertEquals(1, custManyIdsCache.getStatistics(false).getHitCount());
|
||||
|
||||
fetchCustomer(customer.getId());
|
||||
//Assert.assertEquals(2, custManyIdsCache.getStatistics(false).getHitCount());
|
||||
|
||||
int currentNumContacts = fetchCustomer(customer.getId());
|
||||
//Assert.assertEquals(3, custManyIdsCache.getStatistics(false).getHitCount());
|
||||
|
||||
|
||||
Contact newContact = ResetBasicData.createContact("Check", "CollIds");
|
||||
newContact.setCustomer(customer);
|
||||
|
||||
Ebean.save(newContact);
|
||||
ResetBasicData.reset();
|
||||
|
||||
int currentNumContacts2 = fetchCustomer(customer.getId());
|
||||
Assert.assertEquals(currentNumContacts+1, currentNumContacts2);
|
||||
|
||||
|
||||
System.out.println("custCache:"+custCache.getStatistics(false));
|
||||
System.out.println("contactCache:"+contactCache.getStatistics(false));
|
||||
System.out.println("custManyIdsCache:"+custManyIdsCache.getStatistics(false));
|
||||
|
||||
}
|
||||
ServerCache custCache = Ebean.getServerCacheManager().getBeanCache(Customer.class);
|
||||
ServerCache contactCache = Ebean.getServerCacheManager().getBeanCache(Contact.class);
|
||||
ServerCache custManyIdsCache = Ebean.getServerCacheManager().getCollectionIdsCache(
|
||||
Customer.class, "contacts");
|
||||
|
||||
// Ebean.getServerCacheManager().setCaching(Customer.class, true);
|
||||
// Ebean.getServerCacheManager().setCaching(Contact.class, true);
|
||||
|
||||
custCache.clear();
|
||||
custManyIdsCache.clear();
|
||||
|
||||
List<Customer> list = Ebean.find(Customer.class).setAutofetch(false).setLoadBeanCache(true)
|
||||
.order().asc("id").findList();
|
||||
|
||||
Assert.assertTrue(list.size() > 1);
|
||||
// Assert.assertEquals(list.size(),
|
||||
// custCache.getStatistics(false).getSize());
|
||||
|
||||
Customer customer = list.get(0);
|
||||
List<Contact> contacts = customer.getContacts();
|
||||
// Assert.assertEquals(0, custManyIdsCache.getStatistics(false).getSize());
|
||||
contacts.size();
|
||||
Assert.assertTrue(contacts.size() > 1);
|
||||
// Assert.assertEquals(1, custManyIdsCache.getStatistics(false).getSize());
|
||||
// Assert.assertEquals(0,
|
||||
// custManyIdsCache.getStatistics(false).getHitCount());
|
||||
|
||||
fetchCustomer(customer.getId());
|
||||
// Assert.assertEquals(1,
|
||||
// custManyIdsCache.getStatistics(false).getHitCount());
|
||||
|
||||
fetchCustomer(customer.getId());
|
||||
// Assert.assertEquals(2,
|
||||
// custManyIdsCache.getStatistics(false).getHitCount());
|
||||
|
||||
int currentNumContacts = fetchCustomer(customer.getId());
|
||||
// Assert.assertEquals(3,
|
||||
// custManyIdsCache.getStatistics(false).getHitCount());
|
||||
|
||||
Contact newContact = ResetBasicData.createContact("Check", "CollIds");
|
||||
newContact.setCustomer(customer);
|
||||
|
||||
Ebean.save(newContact);
|
||||
|
||||
int currentNumContacts2 = fetchCustomer(customer.getId());
|
||||
Assert.assertEquals(currentNumContacts + 1, currentNumContacts2);
|
||||
|
||||
System.out.println("custCache:" + custCache.getStatistics(false));
|
||||
System.out.println("contactCache:" + contactCache.getStatistics(false));
|
||||
System.out.println("custManyIdsCache:" + custManyIdsCache.getStatistics(false));
|
||||
|
||||
}
|
||||
|
||||
private int fetchCustomer(Integer id) {
|
||||
|
||||
|
||||
Customer customer2 = Ebean.find(Customer.class).setId(id)
|
||||
// .setUseCache(true)
|
||||
.findUnique();
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user