Skip to content

Commit

Permalink
fix: minor fixes with SQL operators on arrays and empty strings
Browse files Browse the repository at this point in the history
  • Loading branch information
lvca committed Aug 21, 2024
1 parent ee2b356 commit 2c52a2a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@ public class MultiValue {
* @return true if it's an array, a collection or a map, otherwise false
*/
public static boolean isMultiValue(final Class<?> iType) {
return Collection.class.isAssignableFrom(iType) || Map.class.isAssignableFrom(iType) || MultiIterator.class.isAssignableFrom(iType) || (
Iterable.class.isAssignableFrom(iType) && !Identifiable.class.isAssignableFrom(iType)) || iType.isArray() || ResultSet.class.isAssignableFrom(iType);
return Collection.class.isAssignableFrom(iType) || Map.class.isAssignableFrom(iType) || MultiIterator.class.isAssignableFrom(
iType) || (
Iterable.class.isAssignableFrom(iType) && !Identifiable.class.isAssignableFrom(iType)) || iType.isArray()
|| ResultSet.class.isAssignableFrom(iType);
}

/**
Expand Down Expand Up @@ -149,7 +151,8 @@ else if (object.getClass().isArray())
return Array.get(object, 0);
} catch (final RuntimeException e) {
// IGNORE IT
LogManager.instance().log(object, Level.FINE, "Error on reading the first item of the Multi-value field '%s'", null, object, e);
LogManager.instance()
.log(object, Level.FINE, "Error on reading the first item of the Multi-value field '%s'", null, object, e);
}

return null;
Expand Down Expand Up @@ -189,7 +192,8 @@ else if (object instanceof Iterable<?>) {
return Array.get(object, Array.getLength(object) - 1);
} catch (final RuntimeException e) {
// IGNORE IT
LogManager.instance().log(object, Level.FINE, "Error on reading the last item of the Multi-value field '%s'", null, object, e);
LogManager.instance()
.log(object, Level.FINE, "Error on reading the last item of the Multi-value field '%s'", null, object, e);
}

return null;
Expand Down Expand Up @@ -232,11 +236,15 @@ else if (iObject instanceof Set<?>) {
return o;
}
}
} else if (iObject.getClass().isArray())
} else if (iObject.getClass().isArray()) {
if (iIndex >= Array.getLength(iObject))
return null;
return Array.get(iObject, iIndex);
else if (iObject instanceof Iterator<?> || iObject instanceof Iterable<?>) {
} else if (iObject instanceof Iterator<?> || iObject instanceof Iterable<?>) {

final Iterator<Object> it = (iObject instanceof Iterable<?>) ? ((Iterable<Object>) iObject).iterator() : (Iterator<Object>) iObject;
final Iterator<Object> it = (iObject instanceof Iterable<?>) ?
((Iterable<Object>) iObject).iterator() :
(Iterator<Object>) iObject;
if (it.hasNext()) {
for (int i = 0; it.hasNext(); ++i) {
final Object o = it.next();
Expand All @@ -253,7 +261,8 @@ else if (iObject instanceof Iterator<?> || iObject instanceof Iterable<?>) {
}
} catch (final RuntimeException e) {
// IGNORE IT
LogManager.instance().log(iObject, Level.FINE, "Error on reading the first item of the Multi-value field '%s'", null, iObject, e);
LogManager.instance()
.log(iObject, Level.FINE, "Error on reading the first item of the Multi-value field '%s'", null, iObject, e);
}
return null;
}
Expand Down Expand Up @@ -613,7 +622,8 @@ public static Object remove(Object iObject, Object iToRemove, final boolean iAll
return iObject;
}

protected static void removeFromOCollection(final Object iObject, final Collection<Object> coll, final Object iToRemove, final boolean iAllOccurrences) {
protected static void removeFromOCollection(final Object iObject, final Collection<Object> coll, final Object iToRemove,
final boolean iAllOccurrences) {
if (iAllOccurrences && !(iObject instanceof Set)) {
// BROWSE THE COLLECTION ONE BY ONE TO REMOVE ALL THE OCCURRENCES
coll.removeIf(iToRemove::equals);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ public Object execute(final Object value, final Identifiable iCurrentRecord, fin
final Object[] iParams) {
if (value instanceof Number)
return ((Number) value).intValue();
return value != null ? Integer.valueOf(value.toString().trim()) : null;
return value != null && !value.toString().isEmpty() ? Integer.valueOf(value.toString().trim()) : null;
}
}

0 comments on commit 2c52a2a

Please sign in to comment.