2014-06-11 13:22:01 -04:00
package com.moparisthebest.jdbc ;
2018-05-20 01:40:31 -04:00
import com.mchange.v2.c3p0.DataSources ;
2018-04-21 01:27:45 -04:00
import com.moparisthebest.jdbc.codegen.JdbcMapperFactory ;
import com.moparisthebest.jdbc.codegen.QmDao ;
import com.moparisthebest.jdbc.codegen.QueryMapperQmDao ;
2018-05-10 16:37:05 -04:00
import com.moparisthebest.jdbc.codegen.QueryMapperTypeQmDao ;
2014-06-11 13:22:01 -04:00
import com.moparisthebest.jdbc.dto.* ;
2019-02-07 01:09:15 -05:00
import com.moparisthebest.jdbc.util.Bindable ;
2018-04-24 00:04:53 -04:00
import com.moparisthebest.jdbc.util.ResultSetIterable ;
2019-02-07 01:09:15 -05:00
import com.moparisthebest.jdbc.util.SqlBuilder ;
2017-05-17 15:45:45 -04:00
import org.junit.* ;
import org.junit.runner.RunWith ;
import org.junit.runners.Parameterized ;
2014-06-11 13:22:01 -04:00
2018-05-20 01:40:31 -04:00
import javax.sql.DataSource ;
2014-06-11 13:22:01 -04:00
import java.sql.Connection ;
import java.sql.DriverManager ;
2017-06-08 23:02:12 -04:00
import java.sql.SQLException ;
2014-06-11 14:30:22 -04:00
import java.util.* ;
2017-06-12 22:57:43 -04:00
//IFJAVA8_START
2018-05-07 23:49:56 -04:00
import java.time.* ;
2018-05-04 00:26:04 -04:00
import java.util.stream.Collectors ;
import java.util.stream.Stream ;
2017-06-12 22:57:43 -04:00
//IFJAVA8_END
2014-06-11 13:22:01 -04:00
2018-09-24 00:04:50 -04:00
import static com.moparisthebest.jdbc.OptimalInList.* ;
2014-06-11 13:22:01 -04:00
import static com.moparisthebest.jdbc.TryClose.tryClose ;
2017-06-08 23:02:12 -04:00
import static org.junit.Assert.assertArrayEquals ;
2017-05-18 14:26:23 -04:00
import static org.junit.Assert.assertEquals ;
import static org.junit.Assert.assertNull ;
2014-06-11 13:22:01 -04:00
/ * *
* Created by mopar on 6 / 10 / 14 .
* /
2017-05-17 15:45:45 -04:00
@RunWith ( Parameterized . class )
2014-06-11 13:22:01 -04:00
public class QueryMapperTest {
2018-05-15 22:41:02 -04:00
private static final long birthDateMillis = 1000 ; // this used to be 0 but mysql TIMESTAMP can only represent '1970-01-01 00:00:01' not '1970-01-01 00:00:00', nice! o_O
public static final Person fieldPerson1 = new FieldPerson ( 1 , new Date ( birthDateMillis ) , " First " , " Person " ) ;
public static final Boss fieldBoss1 = new FieldBoss ( 2 , new Date ( birthDateMillis ) , " Second " , " Person " , " Finance " , " Second " ) ;
public static final Boss fieldBoss2 = new FieldBoss ( 3 , new Date ( birthDateMillis ) , " Third " , " Person " , " Finance " , null ) ;
public static final Boss fieldBoss3 = new FieldBoss ( 4 , new Date ( birthDateMillis ) , null , " Person " , " Finance " , " Fourth " ) ;
public static final Person fieldPerson2 = new FieldPerson ( 5 , new Date ( birthDateMillis ) , " Second " , " Person " ) ;
public static final Person fieldPerson3 = new FieldPerson ( 6 , new Date ( birthDateMillis ) , " Third " , " Person " ) ;
public static final Person fieldPerson1NullName = new FieldPerson ( 1 , new Date ( birthDateMillis ) , null , null ) ;
2018-01-12 16:46:22 -05:00
2017-06-08 23:02:12 -04:00
public static final Person [ ] people = new Person [ ] { fieldPerson1 , fieldPerson2 , fieldPerson3 } ;
2017-06-13 22:56:00 -04:00
public static final Boss [ ] bosses = new Boss [ ] { fieldBoss1 , fieldBoss2 , fieldBoss3 } ;
public static final Val [ ] vals = new Val [ ] {
new Val ( 1 , 1969 , " 1969 " ) ,
new Val ( 2 , 0 , " America/New_York " ) ,
new Val ( 3 , - 5 , " -5 " ) ,
2018-01-12 16:46:22 -05:00
new Val ( 4 , 4 , null ) ,
2017-06-13 22:56:00 -04:00
} ;
2014-06-11 13:22:01 -04:00
2017-05-18 14:26:23 -04:00
public static final Person setPerson1 = new SetPerson ( fieldPerson1 ) ;
public static final Boss setBoss1 = new SetBoss ( fieldBoss1 ) ;
public static final Boss setBoss2 = new SetBoss ( fieldBoss2 ) ;
public static final Boss setBoss3 = new SetBoss ( fieldBoss3 ) ;
2014-06-11 13:22:01 -04:00
2017-05-18 14:26:23 -04:00
public static final Person reverseFieldPerson1 = new ReverseFieldPerson ( fieldPerson1 ) ;
public static final Boss reverseFieldBoss1 = new ReverseFieldBoss ( fieldBoss1 ) ;
public static final Boss reverseFieldBoss2 = new ReverseFieldBoss ( fieldBoss2 ) ;
public static final Boss reverseFieldBoss3 = new ReverseFieldBoss ( fieldBoss3 ) ;
2014-06-11 13:22:01 -04:00
2017-05-18 14:26:23 -04:00
public static final Person reverseSetPerson1 = new ReverseSetPerson ( fieldPerson1 ) ;
public static final Boss reverseSetBoss1 = new ReverseSetBoss ( fieldBoss1 ) ;
public static final Boss reverseSetBoss2 = new ReverseSetBoss ( fieldBoss2 ) ;
public static final Boss reverseSetBoss3 = new ReverseSetBoss ( fieldBoss3 ) ;
2014-06-11 13:22:01 -04:00
2018-05-15 07:03:55 -04:00
public static final Collection < String > jdbcUrls ;
2018-05-20 01:40:31 -04:00
public static final Map < String , DataSource > dataSources = new HashMap < String , DataSource > ( ) ;
2014-06-11 13:22:01 -04:00
2018-05-23 23:41:19 -04:00
public static final Class < ? > mssqlConnection = classForName ( " com.microsoft.sqlserver.jdbc.ISQLServerConnection " ) ;
2017-05-18 14:59:16 -04:00
static {
2018-05-15 07:03:55 -04:00
final Collection < String > jUrls = new ArrayList < String > ( ) ;
final String jdbcUrl = System . getProperty ( " jdbcUrl " , " all " ) ;
2018-05-22 00:08:14 -04:00
if ( jdbcUrl . equals ( " all " ) | | jdbcUrl . equals ( " bind " ) ) {
jUrls . add ( " jdbc:hsqldb:mem:testDB " ) ;
2018-05-15 07:03:55 -04:00
jUrls . add ( " jdbc:derby:memory:testDB;create=true " ) ;
jUrls . add ( " jdbc:h2:mem:testDB " ) ;
2018-05-15 21:56:43 -04:00
jUrls . add ( " jdbc:sqlite::memory: " ) ;
2018-05-22 00:08:14 -04:00
} else if ( jdbcUrl . equals ( " hsql " ) | | jdbcUrl . equals ( " hsqldb " ) | | jdbcUrl . equals ( " unnest " ) ) {
2018-05-15 07:03:55 -04:00
jUrls . add ( " jdbc:hsqldb:mem:testDB " ) ;
} else if ( jdbcUrl . equals ( " derby " ) ) {
jUrls . add ( " jdbc:derby:memory:testDB;create=true " ) ;
2018-05-22 00:08:14 -04:00
} else if ( jdbcUrl . equals ( " h2 " ) | | jdbcUrl . equals ( " any " ) ) {
2018-05-15 07:03:55 -04:00
jUrls . add ( " jdbc:h2:mem:testDB " ) ;
2018-05-15 21:56:43 -04:00
} else if ( jdbcUrl . equals ( " sqlite " ) ) {
jUrls . add ( " jdbc:sqlite::memory: " ) ;
2018-05-15 07:03:55 -04:00
} else {
jUrls . add ( jdbcUrl ) ;
}
2018-05-15 07:24:57 -04:00
for ( int x = 1 ; ; + + x ) {
final String extrajdbcUrl = System . getProperty ( " jdbcUrl " + x ) ;
2018-05-15 07:03:55 -04:00
if ( extrajdbcUrl ! = null )
jUrls . add ( extrajdbcUrl ) ;
2018-05-15 07:24:57 -04:00
else
break ;
2014-06-11 13:22:01 -04:00
}
2018-05-15 07:03:55 -04:00
jdbcUrls = Collections . unmodifiableCollection ( jUrls ) ;
2018-05-15 07:24:57 -04:00
/ * IFJAVA6_START
// this seems to only be needed for java <8
for ( final String driverClass : new String [ ] { " org.hsqldb.jdbc.JDBCDriver " , " org.h2.Driver " } )
try {
Class . forName ( driverClass ) ;
} catch ( Exception e ) {
// ignore, any real errors will be caught during test running
}
IFJAVA6_END * /
2018-05-20 01:40:31 -04:00
for ( final String jUrl : jdbcUrls ) {
// oracle randomly fails without using a datasource...
// https://dba.stackexchange.com/questions/110819/oracle-intermittently-throws-ora-12516-tnslistener-could-not-find-available-h
if ( jUrl . startsWith ( " jdbc:oracle " ) )
try {
dataSources . put ( jUrl , DataSources . pooledDataSource ( DataSources . unpooledDataSource ( jUrl ) ) ) ;
} catch ( SQLException e ) {
throw new RuntimeException ( e ) ;
}
}
2017-05-18 14:59:16 -04:00
}
2018-01-12 16:46:22 -05:00
public static void insertPerson ( final QueryMapper qm , final Person person ) throws SQLException {
qm . executeUpdate ( " INSERT INTO person (person_no, birth_date, last_name, first_name) VALUES (?, ?, ?, ?) " , person . getPersonNo ( ) , person . getBirthDate ( ) , person . getLastName ( ) , person . getFirstName ( ) ) ;
}
2017-07-01 02:07:04 -04:00
public static Connection getConnection ( ) throws SQLException {
2018-05-15 07:03:55 -04:00
return getConnection ( jdbcUrls . iterator ( ) . next ( ) ) ;
2017-05-18 14:26:23 -04:00
}
2018-05-15 07:03:55 -04:00
public static Connection getConnection ( final String url ) throws SQLException {
2018-05-20 01:40:31 -04:00
final DataSource ds = dataSources . get ( url ) ;
final Connection conn = ds ! = null ? ds . getConnection ( ) : DriverManager . getConnection ( url ) ;
2018-05-15 07:03:55 -04:00
QueryMapper qm = null ;
try {
qm = new QueryMapper ( conn ) ;
try {
if ( fieldPerson1 . getPersonNo ( ) = = qm . toObject ( " SELECT person_no FROM person WHERE person_no = ? " , Long . class , fieldPerson1 . getPersonNo ( ) ) )
return conn ;
} catch ( Exception e ) {
// ignore, means the database hasn't been set up yet
}
2018-05-20 01:40:31 -04:00
if ( isWrapperFor ( conn , oracleConnection ) ) {
// OracleArrayInList support requires types created
qm . executeUpdate ( " create or replace TYPE \" ARRAY_NUM_TYPE \" is table of number " ) ;
qm . executeUpdate ( " create or replace TYPE \" ARRAY_STR_TYPE \" is table of varchar2(32767) " ) ;
}
if ( isWrapperFor ( conn , mssqlConnection ) ) {
2018-05-16 01:34:36 -04:00
// mssql doesn't support inserting into TIMESTAMP
qm . executeUpdate ( " CREATE TABLE person (person_no NUMERIC, first_name VARCHAR(40), last_name VARCHAR(40), birth_date DATETIME) " ) ;
2018-05-16 23:52:21 -04:00
} else {
// derby doesn't support DATETIME
qm . executeUpdate ( " CREATE TABLE person (person_no NUMERIC, first_name VARCHAR(40), last_name VARCHAR(40), birth_date TIMESTAMP) " ) ;
2018-05-16 01:34:36 -04:00
}
2018-05-15 07:03:55 -04:00
qm . executeUpdate ( " CREATE TABLE boss (person_no NUMERIC, department VARCHAR(40)) " ) ;
qm . executeUpdate ( " CREATE TABLE val (val_no NUMERIC, num_val NUMERIC, str_val VARCHAR(40)) " ) ;
for ( final Person person : people )
insertPerson ( qm , person ) ;
for ( final Boss boss : bosses ) {
qm . executeUpdate ( " INSERT INTO person (person_no, birth_date, last_name, first_name) VALUES (?, ?, ?, ?) " , boss . getPersonNo ( ) , boss . getBirthDate ( ) , boss . getLastName ( ) , boss . getFirstName ( ) = = null ? boss . getFirst_name ( ) : boss . getFirstName ( ) ) ;
qm . executeUpdate ( " INSERT INTO boss (person_no, department) VALUES (?, ?) " , boss . getPersonNo ( ) , boss . getDepartment ( ) ) ;
}
for ( final Val val : vals )
qm . executeUpdate ( " INSERT INTO val (val_no, num_val, str_val) VALUES (?, ?, ?) " , val . valNo , val . numVal , val . strVal ) ;
} finally {
tryClose ( qm ) ;
}
return conn ;
2014-06-11 13:22:01 -04:00
}
2018-05-15 07:03:55 -04:00
protected Connection conn ;
2018-04-21 01:27:45 -04:00
protected QmDao qm ;
2018-05-15 07:03:55 -04:00
protected final String jdbcUrl ;
protected final int qmDaoType ;
2017-05-17 15:45:45 -04:00
protected final ResultSetMapper rsm ;
2018-05-15 07:03:55 -04:00
public QueryMapperTest ( final String jdbcUrl , final int qmDaoType , final ResultSetMapper rsm ) {
this . jdbcUrl = jdbcUrl ;
2018-05-10 16:37:05 -04:00
this . qmDaoType = qmDaoType ;
2017-05-17 15:45:45 -04:00
this . rsm = rsm ;
}
@Before
2018-05-15 07:03:55 -04:00
public void open ( ) throws SQLException {
this . conn = getConnection ( jdbcUrl ) ;
2018-05-10 16:37:05 -04:00
switch ( qmDaoType ) {
case 0 :
this . qm = new QueryMapperQmDao ( conn , rsm ) ;
return ;
case 1 :
this . qm = new QueryMapperTypeQmDao ( conn , rsm ) ;
return ;
case 2 :
this . qm = JdbcMapperFactory . create ( QmDao . class , conn ) ;
return ;
}
throw new RuntimeException ( " unknown qmDaoType " ) ;
2017-05-17 15:45:45 -04:00
}
@After
public void close ( ) {
tryClose ( qm ) ;
2018-05-15 07:03:55 -04:00
tryClose ( conn ) ;
2017-05-17 15:45:45 -04:00
}
@Parameterized.Parameters ( name = " {0} " )
public static Collection < Object [ ] > getParameters ( )
{
2018-05-15 07:03:55 -04:00
final Collection < Object [ ] > params = new ArrayList < Object [ ] > ( ) ;
for ( final String jdbcUrl : jdbcUrls )
params . addAll ( Arrays . asList ( new Object [ ] [ ] {
{ jdbcUrl , 0 , new ResultSetMapper ( ) } ,
{ jdbcUrl , 0 , new CachingResultSetMapper ( ) } ,
{ jdbcUrl , 0 , new CaseInsensitiveMapResultSetMapper ( ) } ,
{ jdbcUrl , 0 , new CompilingResultSetMapper ( new CompilingRowToObjectMapper . Cache ( true ) ) } ,
{ jdbcUrl , 1 , new ResultSetMapper ( ) } ,
{ jdbcUrl , 1 , new CachingResultSetMapper ( ) } ,
{ jdbcUrl , 1 , new CaseInsensitiveMapResultSetMapper ( ) } ,
{ jdbcUrl , 1 , new CompilingResultSetMapper ( new CompilingRowToObjectMapper . Cache ( true ) ) } ,
{ jdbcUrl , 2 , null /* means QmDao.class is used */ } ,
} ) ) ;
return params ;
2017-05-17 15:45:45 -04:00
}
2014-06-11 13:22:01 -04:00
// fields
@Test
public void testFieldRegularPerson ( ) throws Throwable {
2018-04-21 01:27:45 -04:00
final Person expected = fieldPerson1 ;
Assert . assertEquals ( expected , qm . getFieldRegularPerson ( expected . getPersonNo ( ) ) ) ;
2014-06-11 13:22:01 -04:00
}
2018-01-15 13:24:53 -05:00
@Test
public void testBuilderPerson ( ) throws Throwable {
2018-04-21 01:27:45 -04:00
final Person expected = new BuilderPerson ( fieldPerson1 ) ;
Assert . assertEquals ( expected , qm . getBuilderPerson ( expected . getPersonNo ( ) ) ) ;
2018-01-15 13:24:53 -05:00
}
2014-06-11 13:22:01 -04:00
@Test
public void testFieldRegularAndUnderscore ( ) throws Throwable {
2018-04-21 01:27:45 -04:00
final Person expected = fieldBoss1 ;
Assert . assertEquals ( expected , qm . getFieldRegularAndUnderscore ( expected . getPersonNo ( ) ) ) ;
2014-06-11 13:22:01 -04:00
}
@Test
public void testFieldRegularAndUnderscoreReverse ( ) throws Throwable {
2018-05-10 16:01:57 -04:00
final Person expected = fieldBoss1 ;
2018-04-21 01:27:45 -04:00
Assert . assertEquals ( expected , qm . getFieldRegularAndUnderscoreReverse ( expected . getPersonNo ( ) ) ) ;
2014-06-11 13:22:01 -04:00
}
2018-05-10 16:01:57 -04:00
@Test
public void testFieldRegularAndUnderscoreNoConstructor ( ) throws Throwable {
final Person expected = fieldBoss1 ;
Assert . assertEquals ( expected , qm . getFieldRegularAndUnderscoreNoConstructor ( expected . getPersonNo ( ) ) ) ;
}
@Test
public void testFieldRegularAndUnderscoreReverseNoConstructor ( ) throws Throwable {
final Person expected = fieldBoss1 ;
Assert . assertEquals ( expected , qm . getFieldRegularAndUnderscoreReverseNoConstructor ( expected . getPersonNo ( ) ) ) ;
}
2014-06-11 13:22:01 -04:00
@Test
public void testFieldRegular ( ) throws Throwable {
2018-04-21 01:27:45 -04:00
final Person expected = fieldBoss2 ;
Assert . assertEquals ( expected , qm . getFieldRegular ( expected . getPersonNo ( ) ) ) ;
2014-06-11 13:22:01 -04:00
}
@Test
public void testFieldUnderscore ( ) throws Throwable {
2018-04-21 01:27:45 -04:00
final Person expected = fieldBoss3 ;
Assert . assertEquals ( expected , qm . getFieldUnderscore ( expected . getPersonNo ( ) ) ) ;
2014-06-11 13:22:01 -04:00
}
// sets
@Test
public void testSetRegularPerson ( ) throws Throwable {
2018-04-21 01:27:45 -04:00
final Person expected = setPerson1 ;
Assert . assertEquals ( expected , qm . getSetRegularPerson ( expected . getPersonNo ( ) ) ) ;
2014-06-11 13:22:01 -04:00
}
2018-05-10 16:01:57 -04:00
@Test
public void testSetRegularPersonNoConstructor ( ) throws Throwable {
final Person expected = setPerson1 ;
Assert . assertEquals ( expected , qm . getSetRegularPersonNoConstructor ( expected . getPersonNo ( ) ) ) ;
}
2014-06-11 13:22:01 -04:00
@Test
public void testSetRegularAndUnderscore ( ) throws Throwable {
2018-04-21 01:27:45 -04:00
final Person expected = setBoss1 ;
Assert . assertEquals ( expected , qm . getSetRegularAndUnderscore ( expected . getPersonNo ( ) ) ) ;
2014-06-11 13:22:01 -04:00
}
@Test
public void testSetRegularAndUnderscoreReverse ( ) throws Throwable {
2018-04-21 01:27:45 -04:00
final Person expected = setBoss1 ;
Assert . assertEquals ( expected , qm . getSetRegularAndUnderscoreReverse ( expected . getPersonNo ( ) ) ) ;
2014-06-11 13:22:01 -04:00
}
@Test
public void testSetRegular ( ) throws Throwable {
2018-04-21 01:27:45 -04:00
final Person expected = setBoss2 ;
Assert . assertEquals ( expected , qm . getSetRegular ( expected . getPersonNo ( ) ) ) ;
2014-06-11 13:22:01 -04:00
}
@Test
public void testSetUnderscore ( ) throws Throwable {
2018-04-21 01:27:45 -04:00
final Person expected = setBoss3 ;
Assert . assertEquals ( expected , qm . getSetUnderscore ( expected . getPersonNo ( ) ) ) ;
2014-06-11 13:22:01 -04:00
}
// reverse fields
@Test
public void testReverseFieldRegularPerson ( ) throws Throwable {
2018-04-21 01:27:45 -04:00
final Person expected = reverseFieldPerson1 ;
Assert . assertEquals ( expected , qm . getReverseFieldRegularPerson ( expected . getPersonNo ( ) ) ) ;
2014-06-11 13:22:01 -04:00
}
@Test
public void testReverseFieldRegularAndUnderscore ( ) throws Throwable {
2018-04-21 01:27:45 -04:00
final Person expected = reverseFieldBoss1 ;
Assert . assertEquals ( expected , qm . getReverseFieldRegularAndUnderscore ( expected . getPersonNo ( ) ) ) ;
2014-06-11 13:22:01 -04:00
}
@Test
public void testReverseFieldRegularAndUnderscoreReverse ( ) throws Throwable {
2018-04-21 01:27:45 -04:00
final Person expected = reverseFieldBoss1 ;
Assert . assertEquals ( expected , qm . getReverseFieldRegularAndUnderscoreReverse ( expected . getPersonNo ( ) ) ) ;
2014-06-11 13:22:01 -04:00
}
@Test
public void testReverseFieldRegular ( ) throws Throwable {
2018-04-21 01:27:45 -04:00
final Person expected = reverseFieldBoss3 ;
Assert . assertEquals ( expected , qm . getReverseFieldRegular ( expected . getPersonNo ( ) ) ) ;
2014-06-11 13:22:01 -04:00
}
@Test
public void testReverseFieldUnderscore ( ) throws Throwable {
2018-04-21 01:27:45 -04:00
final Person expected = reverseFieldBoss2 ;
Assert . assertEquals ( expected , qm . getReverseFieldUnderscore ( expected . getPersonNo ( ) ) ) ;
2014-06-11 13:22:01 -04:00
}
// reverse sets
@Test
public void testReverseSetRegularPerson ( ) throws Throwable {
2018-04-21 01:27:45 -04:00
final Person expected = reverseSetPerson1 ;
Assert . assertEquals ( expected , qm . getReverseSetRegularPerson ( expected . getPersonNo ( ) ) ) ;
2014-06-11 13:22:01 -04:00
}
@Test
public void testReverseSetRegularAndUnderscore ( ) throws Throwable {
2018-04-21 01:27:45 -04:00
final Person expected = reverseSetBoss1 ;
Assert . assertEquals ( expected , qm . getReverseSetRegularAndUnderscore ( expected . getPersonNo ( ) ) ) ;
2014-06-11 13:22:01 -04:00
}
@Test
public void testReverseSetRegularAndUnderscoreReverse ( ) throws Throwable {
2018-04-21 01:27:45 -04:00
final Person expected = reverseSetBoss1 ;
Assert . assertEquals ( expected , qm . getReverseSetRegularAndUnderscoreReverse ( expected . getPersonNo ( ) ) ) ;
2014-06-11 13:22:01 -04:00
}
@Test
public void testReverseSetRegular ( ) throws Throwable {
2018-04-21 01:27:45 -04:00
final Person expected = reverseSetBoss3 ;
Assert . assertEquals ( expected , qm . getReverseSetRegular ( expected . getPersonNo ( ) ) ) ;
2014-06-11 13:22:01 -04:00
}
@Test
public void testReverseSetUnderscore ( ) throws Throwable {
2018-04-21 01:27:45 -04:00
final Person expected = reverseSetBoss2 ;
Assert . assertEquals ( expected , qm . getReverseSetUnderscore ( expected . getPersonNo ( ) ) ) ;
2014-06-11 13:22:01 -04:00
}
2014-06-11 14:30:22 -04:00
@Test
public void testSelectListMap ( ) throws Throwable {
final List < Map < String , String > > arrayMap = getListMap ( ) ;
2018-04-24 00:04:53 -04:00
Assert . assertEquals ( arrayMap , qm . getAllNames ( ) ) ;
2014-06-11 14:30:22 -04:00
}
@Test
public void testSelectArrayMap ( ) throws Throwable {
final List < Map < String , String > > arrayMap = getListMap ( ) ;
2018-04-24 00:04:53 -04:00
assertArrayEquals ( arrayMap . toArray ( new Map [ arrayMap . size ( ) ] ) , qm . getAllNamesArray ( ) ) ;
2014-06-11 14:30:22 -04:00
}
2014-06-19 08:57:23 -04:00
@Test
public void testSelectMapString ( ) throws Throwable {
final Map < String , String > map = new HashMap < String , String > ( ) ;
for ( final Person person : new Person [ ] { fieldPerson1 , fieldBoss1 , fieldBoss2 } )
map . put ( person . getFirstName ( ) , person . getLastName ( ) ) ;
2018-04-24 00:04:53 -04:00
Assert . assertEquals ( map , qm . getAllNameMap ( ) ) ;
2014-06-19 08:57:23 -04:00
}
2017-05-17 15:45:45 -04:00
@Test
public void testSelectMapLongPerson ( ) throws Throwable {
final Map < Long , Person > map = new HashMap < Long , Person > ( ) ;
for ( final Person person : new Person [ ] {
2018-04-24 00:04:53 -04:00
qm . getFieldRegular ( 2 ) ,
qm . getFieldRegular ( 3 ) ,
qm . getFieldRegular ( 4 ) ,
2017-05-17 15:45:45 -04:00
} )
map . put ( person . getPersonNo ( ) , person ) ;
2018-04-24 00:04:53 -04:00
Assert . assertEquals ( map , qm . getMapLongPerson ( ) ) ;
2017-05-17 15:45:45 -04:00
}
2014-06-19 08:57:23 -04:00
@Test
public void testSelectMapLong ( ) throws Throwable {
final Map < Long , Long > map = new HashMap < Long , Long > ( ) ;
for ( final Person person : new Person [ ] { fieldPerson1 , fieldBoss1 , fieldBoss2 } )
map . put ( person . getPersonNo ( ) , person . getPersonNo ( ) ) ;
2018-04-24 00:04:53 -04:00
Assert . assertEquals ( map , qm . getMapLongLong ( ) ) ;
2014-06-19 08:57:23 -04:00
}
2014-06-25 12:10:12 -04:00
@Test
public void testSelectLongObject ( ) throws Throwable {
final Long expected = fieldPerson1 . getPersonNo ( ) ;
2018-04-24 00:04:53 -04:00
Assert . assertEquals ( expected , qm . getPersonNo ( expected ) ) ;
2014-06-25 12:10:12 -04:00
}
@Test
public void testSelectLongPrimitive ( ) throws Throwable {
2014-07-24 12:13:47 -04:00
final long expected = fieldPerson1 . getPersonNo ( ) ;
2018-04-24 00:04:53 -04:00
Assert . assertEquals ( expected , qm . getPersonNoPrimitive ( expected ) ) ;
2014-06-25 12:10:12 -04:00
}
2017-05-17 15:45:45 -04:00
@Test
public void testSelectIntPrimitive ( ) throws Throwable {
final int expected = ( int ) fieldPerson1 . getPersonNo ( ) ;
2018-04-24 00:04:53 -04:00
Assert . assertEquals ( expected , qm . getPersonNoPrimitiveInt ( expected ) ) ;
2017-05-17 15:45:45 -04:00
}
2014-07-24 12:13:47 -04:00
@Test
public void testSelectLongObjectArray ( ) throws Throwable {
final Long [ ] expected = { fieldPerson1 . getPersonNo ( ) } ;
2018-04-24 00:04:53 -04:00
assertArrayEquals ( expected , qm . getPersonNoObjectArray ( expected [ 0 ] ) ) ;
2014-07-24 12:13:47 -04:00
}
2018-05-09 23:20:40 -04:00
2015-03-16 13:18:37 -04:00
@Test
2017-05-17 15:45:45 -04:00
public void testSelectObjectArray ( ) throws Throwable {
2015-03-16 13:18:37 -04:00
final Long [ ] arr = { 1L , 2L , 3L } ;
2018-04-24 00:04:53 -04:00
assertArrayEquals ( arr , qm . getLongObjectArray ( ) ) ;
2015-03-16 13:18:37 -04:00
}
2017-05-17 15:45:45 -04:00
@Test
public void testSelectPrimitiveArray ( ) throws Throwable {
final long [ ] arr = { 1L , 2L , 3L } ;
2018-05-09 23:20:40 -04:00
assertArrayEquals ( arr , qm . getLongPrimitiveArray ( ) ) ;
2017-05-17 15:45:45 -04:00
}
2018-05-09 23:20:40 -04:00
2015-03-16 14:50:08 -04:00
@Test ( expected = com . moparisthebest . jdbc . MapperException . class )
public void testNoDefaultConstructorFails ( ) throws Throwable {
2018-04-24 00:04:53 -04:00
if ( qm instanceof QueryMapperQmDao )
( ( QueryMapperQmDao ) qm ) . getQm ( ) . toObject ( " SELECT 1, 2, 3 FROM person WHERE person_no = ? " , Long . class , fieldPerson1 . getPersonNo ( ) ) ;
else
throw new MapperException ( " JdbcMapper wouldn't compile so skipping this... " ) ;
2015-03-16 14:50:08 -04:00
}
2018-09-24 00:04:50 -04:00
@Test
public void testGetGeneratedKeysSingleLong ( ) throws SQLException {
2019-02-04 23:23:37 -05:00
QueryMapper qm = null ;
2018-09-24 00:30:16 -04:00
try {
2019-02-04 23:23:37 -05:00
qm = new QueryMapper ( this . qm . getConnection ( ) ) ;
2018-09-24 00:30:16 -04:00
// auto increment stuff for getGeneratedKeys, how obnoxious are these subtle differences...
if ( isWrapperFor ( qm . getConnection ( ) , classForName ( " org.sqlite.SQLiteConnection " ) ) ) {
qm . executeUpdate ( " CREATE TABLE a_thaoeu_table( \ n " +
" a_thaoeu_table_no INTEGER PRIMARY KEY AUTOINCREMENT, \ n " +
" a_thaoeu_table_val NUMERIC \ n " +
" ) " ) ;
} else if ( isWrapperFor ( qm . getConnection ( ) , classForName ( " org.mariadb.jdbc.MariaDbPooledConnection " ) ) ) {
qm . executeUpdate ( " CREATE TABLE a_thaoeu_table( \ n " +
" a_thaoeu_table_no INTEGER PRIMARY KEY AUTO_INCREMENT, \ n " +
" a_thaoeu_table_val NUMERIC \ n " +
" ) " ) ;
} else if ( isWrapperFor ( qm . getConnection ( ) , postgreConnection ) ) {
qm . executeUpdate ( " CREATE TABLE a_thaoeu_table( \ n " +
" a_thaoeu_table_no SERIAL PRIMARY KEY, \ n " +
" a_thaoeu_table_val NUMERIC \ n " +
" ) " ) ;
} else if ( isWrapperFor ( qm . getConnection ( ) , mssqlConnection ) ) {
qm . executeUpdate ( " CREATE TABLE a_thaoeu_table( \ n " +
" a_thaoeu_table_no INTEGER IDENTITY(1,1) PRIMARY KEY, \ n " +
" a_thaoeu_table_val NUMERIC \ n " +
" ) " ) ;
} else if ( isWrapperFor ( qm . getConnection ( ) , oracleConnection ) ) {
qm . executeUpdate ( " CREATE TABLE a_thaoeu_table( \ n " +
2018-09-24 00:51:18 -04:00
" a_thaoeu_table_no NUMBER PRIMARY KEY, \ n " +
2018-09-24 00:30:16 -04:00
" a_thaoeu_table_val NUMERIC \ n " +
" ) " ) ;
qm . executeUpdate ( " CREATE SEQUENCE a_thaoeu_table_seq \ n " +
" MINVALUE 1 \ n " +
" START WITH 1 \ n " +
" INCREMENT BY 1 \ n " +
" CACHE 10 " ) ;
2019-02-05 23:11:45 -05:00
// if this is JdbcMapper, not QueryMapper, this will fail unless compiled for ORACLE, so just exit early unless that's the case
if ( ! ( this . qm instanceof QueryMapperQmDao ) & & ! " ORACLE " . equals ( System . getProperty ( " jdbcMapper.databaseType " ) ) )
return ;
2018-09-24 00:30:16 -04:00
// so different we have to do test here
for ( long expected = 1 ; expected < 5 ; + + expected ) {
2019-02-04 23:23:37 -05:00
final long autoTableNo = this . qm . insertGetGeneratedKeyOracle ( expected * 2 ) ;
2018-09-24 00:30:16 -04:00
assertEquals ( expected , autoTableNo ) ;
}
return ;
} else {
return ; // can't do test...
2018-09-24 00:04:50 -04:00
}
2018-09-24 00:30:16 -04:00
for ( long expected = 1 ; expected < 5 ; + + expected ) {
2019-02-04 23:23:37 -05:00
final long autoTableNo = this . qm . insertGetGeneratedKey ( expected * 2 ) ;
2018-09-24 00:30:16 -04:00
assertEquals ( expected , autoTableNo ) ;
}
} finally {
2019-02-04 23:23:37 -05:00
if ( qm ! = null )
try {
qm . executeUpdate ( " DROP TABLE a_thaoeu_table " ) ;
qm . executeUpdate ( " DROP SEQUENCE a_thaoeu_table_seq " ) ;
} catch ( Exception e ) {
// ignore
}
tryClose ( qm ) ;
2018-09-24 00:04:50 -04:00
}
}
2014-06-11 14:30:22 -04:00
private List < Map < String , String > > getListMap ( ) {
final List < Map < String , String > > arrayMap = new ArrayList < Map < String , String > > ( ) ;
for ( final Person person : new Person [ ] { fieldPerson1 , fieldBoss1 , fieldBoss2 } ) {
final Map < String , String > map = new HashMap < String , String > ( ) ;
map . put ( " last_name " , person . getLastName ( ) ) ;
map . put ( " first_name " , person . getFirstName ( ) ) ;
arrayMap . add ( map ) ;
}
return arrayMap ;
}
2017-05-18 14:26:23 -04:00
@Test
public void testCaseInsensitiveMap ( ) throws Throwable {
2018-04-24 00:04:53 -04:00
final Map < String , String > map = qm . getBobTomMap ( ) . get ( 0 ) ;
2017-05-18 14:26:23 -04:00
if ( rsm instanceof CaseInsensitiveMapResultSetMapper ) {
assertEquals ( " bob " , map . get ( " bob " ) ) ;
assertEquals ( " bob " , map . get ( " Bob " ) ) ;
assertEquals ( " bob " , map . get ( " BoB " ) ) ;
assertEquals ( " bob " , map . get ( " BOb " ) ) ;
assertEquals ( " bob " , map . get ( " BOB " ) ) ;
assertEquals ( " tom " , map . get ( " tom " ) ) ;
assertEquals ( " tom " , map . get ( " Tom " ) ) ;
assertEquals ( " tom " , map . get ( " ToM " ) ) ;
assertEquals ( " tom " , map . get ( " TOm " ) ) ;
assertEquals ( " tom " , map . get ( " TOM " ) ) ;
} else {
assertEquals ( " bob " , map . get ( " bob " ) ) ;
assertNull ( map . get ( " Bob " ) ) ;
assertNull ( map . get ( " BoB " ) ) ;
assertNull ( map . get ( " BOb " ) ) ;
assertNull ( map . get ( " BOB " ) ) ;
assertEquals ( " tom " , map . get ( " tom " ) ) ;
assertNull ( map . get ( " Tom " ) ) ;
assertNull ( map . get ( " ToM " ) ) ;
assertNull ( map . get ( " TOm " ) ) ;
assertNull ( map . get ( " TOM " ) ) ;
}
}
2017-06-08 23:02:12 -04:00
2018-04-24 00:04:53 -04:00
@Test
public void testCaseInsensitiveMapJdbcMapper ( ) throws Throwable {
final Map < String , String > map = qm . getBobTomMapCaseInsensitive ( ) . get ( 0 ) ;
assertEquals ( " bob " , map . get ( " bob " ) ) ;
assertEquals ( " bob " , map . get ( " Bob " ) ) ;
assertEquals ( " bob " , map . get ( " BoB " ) ) ;
assertEquals ( " bob " , map . get ( " BOb " ) ) ;
assertEquals ( " bob " , map . get ( " BOB " ) ) ;
assertEquals ( " tom " , map . get ( " tom " ) ) ;
assertEquals ( " tom " , map . get ( " Tom " ) ) ;
assertEquals ( " tom " , map . get ( " ToM " ) ) ;
assertEquals ( " tom " , map . get ( " TOm " ) ) ;
assertEquals ( " tom " , map . get ( " TOM " ) ) ;
}
2017-06-08 23:02:12 -04:00
@Test
public void testList ( ) throws SQLException {
2018-04-24 00:04:53 -04:00
final List < FieldPerson > fromDb = qm . getThreePeople ( people [ 0 ] . getPersonNo ( ) , people [ 1 ] . getPersonNo ( ) , people [ 2 ] . getPersonNo ( ) ) ;
2017-06-08 23:02:12 -04:00
assertArrayEquals ( people , fromDb . toArray ( ) ) ;
}
@Test
public void testResultSetIterable ( ) throws SQLException {
2018-04-24 00:04:53 -04:00
final ResultSetIterable < FieldPerson > rsi = qm . getThreePeopleResultSetIterable ( people [ 0 ] . getPersonNo ( ) , people [ 1 ] . getPersonNo ( ) , people [ 2 ] . getPersonNo ( ) ) ;
2017-06-08 23:02:12 -04:00
final List < FieldPerson > fromDb = new ArrayList < FieldPerson > ( ) ;
for ( final FieldPerson fieldPerson : rsi )
fromDb . add ( fieldPerson ) ;
rsi . close ( ) ;
assertArrayEquals ( people , fromDb . toArray ( ) ) ;
}
2018-05-04 00:26:04 -04:00
2018-05-07 23:10:20 -04:00
//IFJAVA8_START
2017-06-12 22:57:43 -04:00
@Test
public void testStream ( ) throws SQLException {
final List < FieldPerson > fromDb ;
2018-05-04 00:26:04 -04:00
try ( Stream < FieldPerson > rsi = qm . getThreePeopleStream ( people [ 0 ] . getPersonNo ( ) , people [ 1 ] . getPersonNo ( ) , people [ 2 ] . getPersonNo ( ) ) ) {
2017-06-12 22:57:43 -04:00
fromDb = rsi . collect ( Collectors . toList ( ) ) ;
}
assertArrayEquals ( people , fromDb . toArray ( ) ) ;
}
2018-05-07 23:10:20 -04:00
//IFJAVA8_END
2017-06-13 21:42:32 -04:00
2018-05-07 23:49:56 -04:00
2017-06-13 21:42:32 -04:00
@Test
public void testEnumPerson ( ) throws SQLException {
2018-05-07 23:49:56 -04:00
assertEquals ( new EnumPerson ( FirstName . First ) , qm . getEnumPerson ( fieldPerson1 . getPersonNo ( ) ) ) ;
2017-06-13 21:42:32 -04:00
}
2018-01-12 16:46:22 -05:00
@Test
public void testEnumPersonConstructor ( ) throws SQLException {
2018-05-07 23:49:56 -04:00
assertEquals ( new EnumPerson ( FirstName . First ) , qm . getEnumPersonConstructor ( fieldPerson1 . getPersonNo ( ) ) ) ;
2018-01-12 16:46:22 -05:00
}
2017-06-13 21:42:32 -04:00
@Test
public void testEnum ( ) throws SQLException {
2018-05-07 23:49:56 -04:00
assertEquals ( FirstName . First , qm . getFirstName ( fieldPerson1 . getPersonNo ( ) ) ) ;
2017-06-13 21:42:32 -04:00
}
2017-06-13 22:56:00 -04:00
2018-01-12 16:46:22 -05:00
@Test
public void testEnumPersonNull ( ) throws SQLException {
2018-05-07 23:49:56 -04:00
assertEquals ( new EnumPerson ( null ) , qm . getEnumPersonNull ( ) ) ;
2018-01-12 16:46:22 -05:00
}
@Test
public void testEnumNull ( ) throws SQLException {
2018-05-07 23:49:56 -04:00
assertNull ( qm . getFirstNameNull ( ) ) ;
2018-01-12 16:46:22 -05:00
}
2018-01-15 12:54:59 -05:00
@Test
public void testCaseInsensitiveMethods ( ) throws SQLException {
final CaseSensitivePerson expected = new CaseSensitivePerson ( ) ;
expected . setmPersonFirstName ( fieldPerson1 . getFirstName ( ) ) ;
2018-05-07 23:49:56 -04:00
assertEquals ( expected , qm . getCaseSensitivePerson ( fieldPerson1 . getPersonNo ( ) ) ) ;
2018-01-15 12:54:59 -05:00
}
2018-05-07 23:49:56 -04:00
//IFJAVA8_START
2017-06-13 22:56:00 -04:00
@Test
public void testInstant ( ) throws SQLException {
assertEquals ( fieldPerson1 . getBirthDate ( ) . toInstant ( ) ,
2018-05-07 23:49:56 -04:00
qm . getBirthdateInstant ( fieldPerson1 . getPersonNo ( ) ) ) ;
2017-06-13 22:56:00 -04:00
}
@Test
public void testLocalDateTime ( ) throws SQLException {
assertEquals ( fieldPerson1 . getBirthDate ( ) . toInstant ( ) . atZone ( ZoneId . systemDefault ( ) ) . toLocalDateTime ( ) ,
2018-05-07 23:49:56 -04:00
qm . getBirthdateLocalDateTime ( fieldPerson1 . getPersonNo ( ) ) ) ;
2017-06-13 22:56:00 -04:00
}
@Test
public void testLocalDate ( ) throws SQLException {
assertEquals ( fieldPerson1 . getBirthDate ( ) . toInstant ( ) . atZone ( ZoneId . systemDefault ( ) ) . toLocalDate ( ) ,
2018-05-07 23:49:56 -04:00
qm . getBirthdateLocalDate ( fieldPerson1 . getPersonNo ( ) ) ) ;
2017-06-13 22:56:00 -04:00
}
@Test
public void testLocalTime ( ) throws SQLException {
assertEquals ( fieldPerson1 . getBirthDate ( ) . toInstant ( ) . atZone ( ZoneId . systemDefault ( ) ) . toLocalTime ( ) ,
2018-05-07 23:49:56 -04:00
qm . getBirthdateLocalTime ( fieldPerson1 . getPersonNo ( ) ) ) ;
2017-06-13 22:56:00 -04:00
}
@Test
public void testZonedDateTime ( ) throws SQLException {
assertEquals ( fieldPerson1 . getBirthDate ( ) . toInstant ( ) . atZone ( ZoneId . systemDefault ( ) ) ,
2018-05-07 23:49:56 -04:00
qm . getBirthdateZonedDateTime ( fieldPerson1 . getPersonNo ( ) ) ) ;
2017-06-13 22:56:00 -04:00
}
@Test
public void testOffsetDateTime ( ) throws SQLException {
assertEquals ( fieldPerson1 . getBirthDate ( ) . toInstant ( ) . atZone ( ZoneId . systemDefault ( ) ) . toOffsetDateTime ( ) ,
2018-05-07 23:49:56 -04:00
qm . getBirthdateOffsetDateTime ( fieldPerson1 . getPersonNo ( ) ) ) ;
2017-06-13 22:56:00 -04:00
}
@Test
public void testZonedOffsetTime ( ) throws SQLException {
assertEquals ( fieldPerson1 . getBirthDate ( ) . toInstant ( ) . atZone ( ZoneId . systemDefault ( ) ) . toOffsetDateTime ( ) . toOffsetTime ( ) ,
2018-05-07 23:49:56 -04:00
qm . getBirthdateOffsetTime ( fieldPerson1 . getPersonNo ( ) ) ) ;
2017-06-13 22:56:00 -04:00
}
@Test
public void testYearInt ( ) throws SQLException {
final Val val = vals [ 0 ] ;
assertEquals ( Year . of ( ( int ) val . numVal ) ,
2018-05-07 23:49:56 -04:00
qm . getYearInt ( val . valNo )
2017-06-13 22:56:00 -04:00
) ;
}
@Test
public void testYearString ( ) throws SQLException {
final Val val = vals [ 0 ] ;
assertEquals ( Year . parse ( val . strVal ) ,
2018-05-07 23:49:56 -04:00
qm . getYearString ( val . valNo )
2017-06-13 22:56:00 -04:00
) ;
}
@Test
public void testZoneId ( ) throws SQLException {
final Val val = vals [ 1 ] ;
assertEquals ( ZoneId . of ( val . strVal ) ,
2018-05-07 23:49:56 -04:00
qm . getZoneId ( val . valNo )
2017-06-13 22:56:00 -04:00
) ;
}
@Test
public void testZoneOffsetInt ( ) throws SQLException {
final Val val = vals [ 2 ] ;
2018-05-07 23:49:56 -04:00
assertEquals ( ZoneOffset . ofHours ( ( int ) val . numVal ) ,
qm . getZoneOffsetInt ( val . valNo )
2017-06-13 22:56:00 -04:00
) ;
}
@Test
public void testZoneOffsetStr ( ) throws SQLException {
final Val val = vals [ 2 ] ;
2018-05-07 23:49:56 -04:00
assertEquals ( ZoneOffset . of ( val . strVal ) ,
qm . getZoneOffsetString ( val . valNo )
2017-06-13 22:56:00 -04:00
) ;
}
2018-05-22 00:08:14 -04:00
@Test
public void testListQueryMapperStream ( ) throws SQLException {
final List < FieldPerson > fromDb = qm . getFieldPeopleStream ( Stream . of ( people [ 0 ] . getPersonNo ( ) , people [ 1 ] . getPersonNo ( ) , people [ 2 ] . getPersonNo ( ) ) ) ;
assertArrayEquals ( people , fromDb . toArray ( ) ) ;
}
2018-05-07 23:49:56 -04:00
//IFJAVA8_END
2018-05-22 00:08:14 -04:00
@Test
public void testListQueryMapperList ( ) throws SQLException {
final List < FieldPerson > fromDb = qm . getFieldPeople ( Arrays . asList ( people [ 0 ] . getPersonNo ( ) , people [ 1 ] . getPersonNo ( ) , people [ 2 ] . getPersonNo ( ) ) ) ;
assertArrayEquals ( people , fromDb . toArray ( ) ) ;
}
@Test
public void testListQueryMapperListMultiple ( ) throws SQLException {
final List < FieldPerson > fromDb = qm . getFieldPeopleByName (
Arrays . asList ( people [ 0 ] . getPersonNo ( ) , people [ 1 ] . getPersonNo ( ) , people [ 2 ] . getPersonNo ( ) ) ,
Arrays . asList ( people [ 0 ] . getFirstName ( ) , people [ 1 ] . getFirstName ( ) , people [ 2 ] . getFirstName ( ) ) ) ;
assertArrayEquals ( people , fromDb . toArray ( ) ) ;
}
2018-05-22 23:09:57 -04:00
@Test
public void testListQueryMapperListNotIn ( ) throws SQLException {
final List < FieldPerson > fromDb = qm . getFieldPeopleNotIn ( Arrays . asList ( bosses [ 0 ] . getPersonNo ( ) , bosses [ 1 ] . getPersonNo ( ) , bosses [ 2 ] . getPersonNo ( ) ) ) ;
assertArrayEquals ( people , fromDb . toArray ( ) ) ;
}
2019-02-07 01:09:15 -05:00
@Test
public void testSelectRandomSql ( ) throws Throwable {
final List < Long > arr = Arrays . asList ( 1L , 2L , 3L ) ;
assertEquals ( arr , qm . selectRandomSql ( " person_no in (1,2,3) " ) ) ;
assertEquals ( arr , qm . selectRandomSql ( 1L , " OR person_no in (2,3) " , " NoNameMatch " ) ) ;
assertEquals ( Collections . singletonList ( 2L ) , qm . selectRandomSql ( 2L , " " , " NoNameMatch " ) ) ;
}
@Test
public void testSelectRandomSqlBuilder ( ) throws Throwable {
final List < Long > arr = Arrays . asList ( 1L , 2L , 3L ) ;
2019-02-09 00:06:13 -05:00
assertEquals ( arr , qm . selectRandomSqlBuilder ( qm . sqlBuilder ( ) . appendInList ( " person_no " , arr ) ) ) ;
assertEquals ( arr , qm . selectRandomSqlBuilder ( qm . sqlBuilder ( ) . append ( " person_no = ? OR " , 1L ) . appendInList ( " person_no " , Arrays . asList ( 2L , 3L ) ) ) ) ;
assertEquals ( arr , qm . selectRandomSqlBuilder ( qm . sqlBuilder ( ) . append ( " person_no = 1 OR " ) . appendInList ( " person_no " , Arrays . asList ( 2L , 3L ) ) ) ) ;
assertEquals ( arr , qm . selectRandomSqlBuilder ( 1L , qm . sqlBuilder ( ) . append ( " OR person_no in (2,3) " ) , " NoNameMatch " ) ) ;
assertEquals ( Collections . singletonList ( 2L ) , qm . selectRandomSqlBuilder ( 2L , qm . sqlBuilder ( ) , " NoNameMatch " ) ) ;
2019-02-07 01:09:15 -05:00
assertEquals ( Collections . singletonList ( 3L ) , qm . selectRandomSqlBuilder ( 3L , Bindable . empty , " NoNameMatch " ) ) ;
2019-02-09 00:06:13 -05:00
assertEquals ( arr , qm . selectRandomSqlBuilder ( 2L , qm . sqlBuilder ( ) . append ( " OR person_no = ? OR " , 1L ) . appendInList ( " person_no " , Collections . singletonList ( 3L ) ) , " NoNameMatch " ) ) ;
2019-02-07 01:09:15 -05:00
}
2014-06-11 13:22:01 -04:00
}