[ 1981760 ] Improve Query class
* org.compiere.model.Query.Query(String tableName, String whereClause, String trxName) ctor should take ctx parameter too, bug introduced in rev. 5343
This commit is contained in:
parent
96d1d0ea48
commit
4227d852a0
|
@ -24,6 +24,7 @@ import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Properties;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
import org.adempiere.exceptions.DBException;
|
import org.adempiere.exceptions.DBException;
|
||||||
|
@ -60,8 +61,8 @@ public class Query {
|
||||||
this.trxName = trxName;
|
this.trxName = trxName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Query(String tableName, String whereClause, String trxName) {
|
public Query(Properties ctx, String tableName, String whereClause, String trxName) {
|
||||||
this(MTable.get(Env.getCtx(), tableName), whereClause, trxName);
|
this(MTable.get(ctx, tableName), whereClause, trxName);
|
||||||
if (this.table == null)
|
if (this.table == null)
|
||||||
throw new IllegalArgumentException("Table Name Not Found - "+tableName);
|
throw new IllegalArgumentException("Table Name Not Found - "+tableName);
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ public class QueryTest extends AdempiereTestCase {
|
||||||
public void testQuery_NoTable() throws Exception {
|
public void testQuery_NoTable() throws Exception {
|
||||||
boolean exThrowed = false;
|
boolean exThrowed = false;
|
||||||
try {
|
try {
|
||||||
new Query("NO_TABLE_DEFINED", null, getTrxName());
|
new Query(getCtx(), "NO_TABLE_DEFINED", null, getTrxName());
|
||||||
}
|
}
|
||||||
catch (RuntimeException e) {
|
catch (RuntimeException e) {
|
||||||
exThrowed = true;
|
exThrowed = true;
|
||||||
|
@ -31,7 +31,7 @@ public class QueryTest extends AdempiereTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testList() throws Exception {
|
public void testList() throws Exception {
|
||||||
List<MTable> list = new Query("AD_Table", "TableName IN (?,?)", getTrxName())
|
List<MTable> list = new Query(getCtx(), "AD_Table", "TableName IN (?,?)", getTrxName())
|
||||||
.setParameters(new Object[]{"C_Invoice", "M_InOut"})
|
.setParameters(new Object[]{"C_Invoice", "M_InOut"})
|
||||||
.setOrderBy("TableName")
|
.setOrderBy("TableName")
|
||||||
.list();
|
.list();
|
||||||
|
@ -43,7 +43,7 @@ public class QueryTest extends AdempiereTestCase {
|
||||||
public void testScroll() throws Exception {
|
public void testScroll() throws Exception {
|
||||||
POResultSet<MTable> rs = null;
|
POResultSet<MTable> rs = null;
|
||||||
try {
|
try {
|
||||||
rs = new Query("AD_Table", "TableName IN (?,?)", getTrxName())
|
rs = new Query(getCtx(), "AD_Table", "TableName IN (?,?)", getTrxName())
|
||||||
.setParameters(new Object[]{"C_Invoice", "M_InOut"})
|
.setParameters(new Object[]{"C_Invoice", "M_InOut"})
|
||||||
.setOrderBy("TableName")
|
.setOrderBy("TableName")
|
||||||
.scroll();
|
.scroll();
|
||||||
|
@ -70,7 +70,7 @@ public class QueryTest extends AdempiereTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testIterate() throws Exception {
|
public void testIterate() throws Exception {
|
||||||
Iterator<MTable> it = new Query("AD_Table", "TableName IN (?,?)", getTrxName())
|
Iterator<MTable> it = new Query(getCtx(), "AD_Table", "TableName IN (?,?)", getTrxName())
|
||||||
.setParameters(new Object[]{"C_Invoice", "M_InOut"})
|
.setParameters(new Object[]{"C_Invoice", "M_InOut"})
|
||||||
.setOrderBy("TableName")
|
.setOrderBy("TableName")
|
||||||
.iterate();
|
.iterate();
|
||||||
|
@ -92,7 +92,7 @@ public class QueryTest extends AdempiereTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCount() throws Exception {
|
public void testCount() throws Exception {
|
||||||
int count = new Query("AD_Table", "TableName IN (?,?)", getTrxName())
|
int count = new Query(getCtx(), "AD_Table", "TableName IN (?,?)", getTrxName())
|
||||||
.setParameters(new Object[]{"C_Invoice", "M_InOut"})
|
.setParameters(new Object[]{"C_Invoice", "M_InOut"})
|
||||||
.setOrderBy("TableName")
|
.setOrderBy("TableName")
|
||||||
.count();
|
.count();
|
||||||
|
@ -102,7 +102,7 @@ public class QueryTest extends AdempiereTestCase {
|
||||||
public void testCount_BadSQL() throws Exception {
|
public void testCount_BadSQL() throws Exception {
|
||||||
boolean exThrowed = false;
|
boolean exThrowed = false;
|
||||||
try {
|
try {
|
||||||
new Query("AD_Table", "TableName IN (?,?) AND BAD_SQL", getTrxName())
|
new Query(getCtx(), "AD_Table", "TableName IN (?,?) AND BAD_SQL", getTrxName())
|
||||||
.setParameters(new Object[]{"C_Invoice", "M_InOut"})
|
.setParameters(new Object[]{"C_Invoice", "M_InOut"})
|
||||||
.setOrderBy("TableName")
|
.setOrderBy("TableName")
|
||||||
.count();
|
.count();
|
||||||
|
@ -114,12 +114,12 @@ public class QueryTest extends AdempiereTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCount_NoValues() throws Exception {
|
public void testCount_NoValues() throws Exception {
|
||||||
int count = new Query("AD_Table", "1=2", getTrxName()).count();
|
int count = new Query(getCtx(), "AD_Table", "1=2", getTrxName()).count();
|
||||||
assertEquals("Counter should be ZERO", 0, count);
|
assertEquals("Counter should be ZERO", 0, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testFirst() throws Exception {
|
public void testFirst() throws Exception {
|
||||||
MTable t = new Query("AD_Table", "TableName IN (?,?)", getTrxName())
|
MTable t = new Query(getCtx(), "AD_Table", "TableName IN (?,?)", getTrxName())
|
||||||
.setParameters(new Object[]{"C_Invoice", "M_InOut"})
|
.setParameters(new Object[]{"C_Invoice", "M_InOut"})
|
||||||
.setOrderBy("TableName")
|
.setOrderBy("TableName")
|
||||||
.first();
|
.first();
|
||||||
|
|
Loading…
Reference in New Issue