mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-08 08:39:19 +00:00
initial add of EbeanORM server based on v2.8.1
This commit is contained in:
1 parent
2b74d0f9d9
commit
96ce4c0ddf
1188 files changed
+135034
No files matched your search
+58
@@ -0,0 +1,58 @@
|
||||
package com.avaje.ebeaninternal.server.cluster.mcast;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import com.avaje.ebeaninternal.server.cluster.mcast.IncomingPacketsProcessed.GotAllPoint;
|
||||
|
||||
public class TestMcastMemberPackets extends TestCase {
|
||||
|
||||
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));
|
||||
|
||||
missingPackets = member.getMissingPackets();
|
||||
assertEquals(2, missingPackets.size());
|
||||
assertTrue(missingPackets.contains(1237l));
|
||||
assertTrue(missingPackets.contains(1238l));
|
||||
|
||||
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));
|
||||
|
||||
|
||||
// but we now hit maxResendIncoming
|
||||
missingPackets = member.getMissingPackets();
|
||||
assertEquals(0, missingPackets.size());
|
||||
// gave up on 1238 ..
|
||||
assertEquals(1239l, member.getGotAllPoint());
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.avaje.ebeaninternal.server.cluster.mcast;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class TestPacketsAcked extends TestCase {
|
||||
|
||||
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);
|
||||
|
||||
receivedAck = packetsAcked.receivedAck("B", new MessageAck("B", 1030l));
|
||||
assertEquals(1020l,packetsAcked.getMinimumGotAllPacketId());
|
||||
assertEquals(0l,receivedAck);
|
||||
|
||||
receivedAck = packetsAcked.receivedAck("C", new MessageAck("C", 1025l));
|
||||
assertEquals(0l,receivedAck);
|
||||
|
||||
receivedAck = packetsAcked.receivedAck("A", new MessageAck("A", 1040l));
|
||||
assertEquals(1025l,receivedAck);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
package com.avaje.ebeaninternal.server.lib.sql;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
public class TestBusyBuffer extends TestCase {
|
||||
|
||||
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());
|
||||
|
||||
b.remove(p2);
|
||||
b.add(p2);
|
||||
Assert.assertEquals(4, p2.getSlotId());
|
||||
|
||||
b.remove(p0);
|
||||
b.add(p0);
|
||||
Assert.assertEquals(5, p0.getSlotId());
|
||||
|
||||
b.remove(p2);
|
||||
b.add(p2);
|
||||
Assert.assertEquals(0, 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());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package com.avaje.ebeaninternal.server.lib.sql;
|
||||
|
||||
import java.sql.Connection;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
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 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);
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
package com.avaje.ebeaninternal.server.lib.sql;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
public class TestFreeBuffer extends TestCase {
|
||||
|
||||
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");
|
||||
|
||||
Assert.assertEquals(3, b.getCapacity());
|
||||
Assert.assertEquals(0, b.size());
|
||||
Assert.assertEquals(true, b.isEmpty());
|
||||
|
||||
b.add(p0);
|
||||
|
||||
Assert.assertEquals(1, b.size());
|
||||
Assert.assertEquals(false, b.isEmpty());
|
||||
|
||||
PooledConnection r0 = b.remove();
|
||||
Assert.assertTrue(p0 == r0);
|
||||
|
||||
Assert.assertEquals(0, b.size());
|
||||
Assert.assertEquals(true, b.isEmpty());
|
||||
|
||||
b.add(p0);
|
||||
b.add(p1);
|
||||
b.add(p2);
|
||||
|
||||
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());
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
package com.avaje.ebeaninternal.server.loadcontext;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
public class TestDLoadWeakList extends TestCase {
|
||||
|
||||
|
||||
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());
|
||||
|
||||
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));
|
||||
|
||||
}
|
||||
}
|
||||
+107
@@ -0,0 +1,107 @@
|
||||
package com.avaje.ebeaninternal.server.loadcontext;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
public class TestDLoadWeakListWithGC extends TestCase {
|
||||
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
package com.avaje.ebeaninternal.server.querydefn;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.EbeanServer;
|
||||
import com.avaje.ebeaninternal.server.expression.DefaultExpressionFactory;
|
||||
import com.avaje.ebeaninternal.server.querydefn.DefaultOrmQuery;
|
||||
import com.avaje.ebeaninternal.server.querydefn.OrmQueryDetail;
|
||||
import com.avaje.ebeaninternal.server.querydefn.OrmQueryDetailParser;
|
||||
import com.avaje.ebeaninternal.server.querydefn.OrmQueryProperties;
|
||||
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());
|
||||
|
||||
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());
|
||||
|
||||
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());
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.avaje.ebeaninternal.server.rawsql;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import com.avaje.ebean.RawSql;
|
||||
import com.avaje.ebean.RawSqlBuilder;
|
||||
import com.avaje.ebean.RawSql.Sql;
|
||||
|
||||
public class TestRawSqlParsing extends TestCase {
|
||||
|
||||
public void test() {
|
||||
|
||||
String sql
|
||||
= " select order_id, sum(order_qty*unit_price) as totalAmount"
|
||||
+ " from o_order_detail "
|
||||
+ " group by order_id";
|
||||
|
||||
RawSql rawSql = RawSqlBuilder
|
||||
.parse(sql)
|
||||
.columnMapping("order_id","order.id")
|
||||
//.columnMapping("sum(order_qty*unit_price)","totalAmount")
|
||||
.create();
|
||||
|
||||
Sql rs = rawSql.getSql();
|
||||
|
||||
String s = rs.toString();
|
||||
System.out.println(s);
|
||||
assertTrue(s, s.contains("[order_id, sum"));
|
||||
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user