@@ -72,7 +72,7 @@ public static <T> SelectById<T> queryId(Class<T> entityType, Object id) {
7272 */
7373 public static <T > SelectById <T > queryMap (Class <T > entityType , Map <String , ?> id ) {
7474 QueryRoot root = new ByEntityTypeResolver (entityType );
75- IdSpec idSpec = new SingleMapIdSpec (id );
75+ IdSpec idSpec = new SingleMapIdSpec (checkIdMap ( id ) );
7676 return new SelectById <>(root , idSpec );
7777 }
7878
@@ -90,6 +90,9 @@ public static <T> SelectById<T> queryObjectId(Class<T> entityType, ObjectId id)
9090 * @since 5.0
9191 */
9292 public static <T > SelectById <T > queryIds (Class <T > entityType , Object ... ids ) {
93+ if (ids == null ) {
94+ throw new CayenneRuntimeException ("Null ids" );
95+ }
9396 QueryRoot root = new ByEntityTypeResolver (entityType );
9497 IdSpec idSpec = new MultiScalarIdSpec (Arrays .asList (ids ));
9598 return new SelectById <>(root , idSpec );
@@ -99,6 +102,9 @@ public static <T> SelectById<T> queryIds(Class<T> entityType, Object... ids) {
99102 * @since 5.0
100103 */
101104 public static <T > SelectById <T > queryIdsCollection (Class <T > entityType , Collection <Object > ids ) {
105+ if (ids == null ) {
106+ throw new CayenneRuntimeException ("Null ids" );
107+ }
102108 QueryRoot root = new ByEntityTypeResolver (entityType );
103109 IdSpec idSpec = new MultiScalarIdSpec (ids );
104110 return new SelectById <>(root , idSpec );
@@ -109,6 +115,14 @@ public static <T> SelectById<T> queryIdsCollection(Class<T> entityType, Collecti
109115 */
110116 @ SafeVarargs
111117 public static <T > SelectById <T > queryMaps (Class <T > entityType , Map <String , ?>... ids ) {
118+ if (ids == null ) {
119+ throw new CayenneRuntimeException ("Null ids" );
120+ }
121+
122+ for (Map <String , ?> id : ids ) {
123+ checkIdMap (id );
124+ }
125+
112126 QueryRoot root = new ByEntityTypeResolver (entityType );
113127 IdSpec idSpec = MultiMapIdSpec .ofMap (ids );
114128 return new SelectById <>(root , idSpec );
@@ -118,6 +132,11 @@ public static <T> SelectById<T> queryMaps(Class<T> entityType, Map<String, ?>...
118132 * @since 5.0
119133 */
120134 public static <T > SelectById <T > queryMapsCollection (Class <T > entityType , Collection <Map <String , ?>> ids ) {
135+ if (ids == null ) {
136+ throw new CayenneRuntimeException ("Null ids" );
137+ }
138+
139+ ids .forEach (SelectById ::checkIdMap );
121140 QueryRoot root = new ByEntityTypeResolver (entityType );
122141 IdSpec idSpec = MultiMapIdSpec .ofMapCollection (ids );
123142 return new SelectById <>(root , idSpec );
@@ -127,8 +146,8 @@ public static <T> SelectById<T> queryMapsCollection(Class<T> entityType, Collect
127146 * @since 5.0
128147 */
129148 public static <T > SelectById <T > queryObjectIds (Class <T > entityType , ObjectId ... ids ) {
130- if (ids == null || ids . length == 0 ) {
131- throw new CayenneRuntimeException ("Null or empty ids" );
149+ if (ids == null ) {
150+ throw new CayenneRuntimeException ("Null ids" );
132151 }
133152 String entityName = ids [0 ].getEntityName ();
134153 for (ObjectId id : ids ) {
@@ -144,8 +163,8 @@ public static <T> SelectById<T> queryObjectIds(Class<T> entityType, ObjectId...
144163 * @since 5.0
145164 */
146165 public static <T > SelectById <T > queryObjectIdsCollection (Class <T > entityType , Collection <ObjectId > ids ) {
147- if (ids == null || ids . isEmpty () ) {
148- throw new CayenneRuntimeException ("Null or empty ids" );
166+ if (ids == null ) {
167+ throw new CayenneRuntimeException ("Null ids" );
149168 }
150169 String entityName = ids .iterator ().next ().getEntityName ();
151170 for (ObjectId id : ids ) {
@@ -253,7 +272,7 @@ public static SelectById<DataRow> dataRowQueryId(Class<?> entityType, Object id)
253272 */
254273 public static SelectById <DataRow > dataRowQueryMap (Class <?> entityType , Map <String , ?> id ) {
255274 QueryRoot root = new ByEntityTypeResolver (entityType );
256- IdSpec idSpec = new SingleMapIdSpec (id );
275+ IdSpec idSpec = new SingleMapIdSpec (checkIdMap ( id ) );
257276 return new SelectById <>(root , idSpec , true );
258277 }
259278
@@ -271,6 +290,9 @@ public static SelectById<DataRow> dataRowQueryObjectId(ObjectId id) {
271290 * @since 5.0
272291 */
273292 public static SelectById <DataRow > dataRowQueryIds (Class <?> entityType , Object ... ids ) {
293+ if (ids == null ) {
294+ throw new CayenneRuntimeException ("Null ids" );
295+ }
274296 QueryRoot root = new ByEntityTypeResolver (entityType );
275297 IdSpec idSpec = new MultiScalarIdSpec (Arrays .asList (ids ));
276298 return new SelectById <>(root , idSpec , true );
@@ -280,6 +302,9 @@ public static SelectById<DataRow> dataRowQueryIds(Class<?> entityType, Object...
280302 * @since 5.0
281303 */
282304 public static SelectById <DataRow > dataRowQueryIdsCollection (Class <?> entityType , Collection <Object > ids ) {
305+ if (ids == null ) {
306+ throw new CayenneRuntimeException ("Null ids" );
307+ }
283308 QueryRoot root = new ByEntityTypeResolver (entityType );
284309 IdSpec idSpec = new MultiScalarIdSpec (ids );
285310 return new SelectById <>(root , idSpec , true );
@@ -290,6 +315,14 @@ public static SelectById<DataRow> dataRowQueryIdsCollection(Class<?> entityType,
290315 */
291316 @ SafeVarargs
292317 public static SelectById <DataRow > dataRowQueryMaps (Class <?> entityType , Map <String , ?>... ids ) {
318+ if (ids == null ) {
319+ throw new CayenneRuntimeException ("Null ids" );
320+ }
321+
322+ for (Map <String , ?> id : ids ) {
323+ checkIdMap (id );
324+ }
325+
293326 QueryRoot root = new ByEntityTypeResolver (entityType );
294327 IdSpec idSpec = MultiMapIdSpec .ofMap (ids );
295328 return new SelectById <>(root , idSpec , true );
@@ -299,6 +332,12 @@ public static SelectById<DataRow> dataRowQueryMaps(Class<?> entityType, Map<Stri
299332 * @since 5.0
300333 */
301334 public static SelectById <DataRow > dataRowQueryMapsCollection (Class <?> entityType , Collection <Map <String , ?>> ids ) {
335+ if (ids == null ) {
336+ throw new CayenneRuntimeException ("Null ids" );
337+ }
338+
339+ ids .forEach (SelectById ::checkIdMap );
340+
302341 QueryRoot root = new ByEntityTypeResolver (entityType );
303342 IdSpec idSpec = MultiMapIdSpec .ofMapCollection (ids );
304343 return new SelectById <>(root , idSpec , true );
@@ -308,8 +347,8 @@ public static SelectById<DataRow> dataRowQueryMapsCollection(Class<?> entityType
308347 * @since 5.0
309348 */
310349 public static SelectById <DataRow > dataRowQueryObjectIds (ObjectId ... ids ) {
311- if (ids == null || ids . length == 0 ) {
312- throw new CayenneRuntimeException ("Null or empty ids" );
350+ if (ids == null ) {
351+ throw new CayenneRuntimeException ("Null ids" );
313352 }
314353 String entityName = ids [0 ].getEntityName ();
315354 for (ObjectId id : ids ) {
@@ -325,8 +364,8 @@ public static SelectById<DataRow> dataRowQueryObjectIds(ObjectId... ids) {
325364 * @since 5.0
326365 */
327366 public static SelectById <DataRow > dataRowQueryObjectIdsCollection (Collection <ObjectId > ids ) {
328- if (ids == null || ids . isEmpty () ) {
329- throw new CayenneRuntimeException ("Null or empty ids" );
367+ if (ids == null ) {
368+ throw new CayenneRuntimeException ("Null ids" );
330369 }
331370 String entityName = ids .iterator ().next ().getEntityName ();
332371 for (ObjectId id : ids ) {
@@ -603,6 +642,14 @@ private static void checkObjectId(ObjectId id, String entityName) {
603642 }
604643 }
605644
645+ private static Map <String , ?> checkIdMap (Map <String , ?> id ) {
646+ if (id == null || id .isEmpty ()) {
647+ throw new CayenneRuntimeException ("Null or empty id map" );
648+ }
649+
650+ return id ;
651+ }
652+
606653 @ SafeVarargs
607654 private static <E , R > Collection <R > foldArguments (Function <E , R > mapper , E first , E ... other ) {
608655 List <R > result = new ArrayList <>(1 + other .length );
@@ -680,7 +727,8 @@ protected SingleMapIdSpec(Map<String, ?> id) {
680727
681728 @ Override
682729 public Expression getQualifier (ObjEntity entity ) {
683- return matchAllDbExp (id , Expression .EQUAL_TO );
730+ Expression expression = matchAllDbExp (id , Expression .EQUAL_TO );
731+ return expression == null ? expFalse () : expression ;
684732 }
685733 }
686734
@@ -722,10 +770,13 @@ protected MultiMapIdSpec(Collection<Map<String, ?>> ids) {
722770 public Expression getQualifier (ObjEntity entity ) {
723771 List <Expression > expressions = new ArrayList <>();
724772 for (Map <String , ?> id : ids ) {
725- expressions .add (matchAllDbExp (id , Expression .EQUAL_TO ));
773+ Expression expression = matchAllDbExp (id , Expression .EQUAL_TO );
774+ if (expression != null ) {
775+ expressions .add (expression );
776+ }
726777 }
727778
728- return or (expressions );
779+ return expressions . isEmpty () ? expFalse () : or (expressions );
729780 }
730781 }
731782
0 commit comments