use of com.hazelcast.query.QueryException in project hazelcast by hazelcast.
the class PredicateBuilderImpl method and.
@Override
public PredicateBuilder and(Predicate predicate) {
if (predicate != PredicateBuilderImpl.this) {
throw new QueryException("Illegal and statement expected: " + PredicateBuilderImpl.class.getSimpleName() + ", found: " + ((predicate == null) ? "null" : predicate.getClass().getSimpleName()));
}
int index = lsPredicates.size() - 2;
Predicate first = lsPredicates.remove(index);
Predicate second = lsPredicates.remove(index);
return addPredicate(Predicates.and(first, second));
}
use of com.hazelcast.query.QueryException in project hazelcast by hazelcast.
the class ReflectionHelper method createGetter.
public static Getter createGetter(Object obj, String attribute) {
if (obj == null || obj == IndexImpl.NULL) {
return NULL_GETTER;
}
final Class targetClazz = obj.getClass();
Class clazz = targetClazz;
Getter getter;
try {
Getter parent = null;
List<String> possibleMethodNames = new ArrayList<String>(INITIAL_CAPACITY);
for (final String fullname : attribute.split("\\.")) {
String baseName = removeModifierSuffix(fullname);
String modifier = getModifierSuffix(fullname, baseName);
Getter localGetter = null;
possibleMethodNames.clear();
possibleMethodNames.add(baseName);
final String camelName = Character.toUpperCase(baseName.charAt(0)) + baseName.substring(1);
possibleMethodNames.add("get" + camelName);
possibleMethodNames.add("is" + camelName);
if (baseName.equals(THIS_ATTRIBUTE_NAME.value())) {
localGetter = GetterFactory.newThisGetter(parent, obj);
} else {
if (parent != null) {
clazz = parent.getReturnType();
}
for (String methodName : possibleMethodNames) {
try {
final Method method = clazz.getMethod(methodName);
method.setAccessible(true);
localGetter = GetterFactory.newMethodGetter(obj, parent, method, modifier);
if (localGetter == NULL_GETTER) {
return localGetter;
}
clazz = method.getReturnType();
break;
} catch (NoSuchMethodException ignored) {
EmptyStatement.ignore(ignored);
}
}
if (localGetter == null) {
try {
final Field field = clazz.getField(baseName);
localGetter = GetterFactory.newFieldGetter(obj, parent, field, modifier);
if (localGetter == NULL_GETTER) {
return localGetter;
}
clazz = field.getType();
} catch (NoSuchFieldException ignored) {
EmptyStatement.ignore(ignored);
}
}
if (localGetter == null) {
Class c = clazz;
while (!c.isInterface() && !Object.class.equals(c)) {
try {
final Field field = c.getDeclaredField(baseName);
field.setAccessible(true);
localGetter = GetterFactory.newFieldGetter(obj, parent, field, modifier);
if (localGetter == NULL_GETTER) {
return NULL_GETTER;
}
clazz = field.getType();
break;
} catch (NoSuchFieldException ignored) {
c = c.getSuperclass();
}
}
}
}
if (localGetter == null) {
throw new IllegalArgumentException("There is no suitable accessor for '" + baseName + "' on class '" + clazz + "'");
}
parent = localGetter;
}
getter = parent;
return getter;
} catch (Throwable e) {
throw new QueryException(e);
}
}
use of com.hazelcast.query.QueryException in project hazelcast by hazelcast.
the class ReflectionHelper method createGetter.
public static Getter createGetter(Object obj, String attribute, boolean failOnMissingAttribute) {
if (obj == null || obj == NULL) {
return NULL_GETTER;
}
final Class targetClazz = obj.getClass();
Class clazz = targetClazz;
Getter getter;
try {
Getter parent = null;
List<String> possibleMethodNames = new ArrayList<String>(INITIAL_CAPACITY);
for (final String fullname : attribute.split("\\.")) {
String baseName = removeModifierSuffix(fullname);
String modifier = getModifierSuffix(fullname, baseName);
Getter localGetter = null;
possibleMethodNames.clear();
possibleMethodNames.add(baseName);
final String camelName = Character.toUpperCase(baseName.charAt(0)) + baseName.substring(1);
possibleMethodNames.add("get" + camelName);
possibleMethodNames.add("is" + camelName);
if (baseName.equals(THIS_ATTRIBUTE_NAME.value())) {
localGetter = GetterFactory.newThisGetter(parent, obj);
} else {
if (parent != null) {
clazz = parent.getReturnType();
}
for (String methodName : possibleMethodNames) {
try {
final Method method = clazz.getMethod(methodName);
method.setAccessible(true);
localGetter = GetterFactory.newMethodGetter(obj, parent, method, modifier);
if (localGetter == NULL_GETTER || localGetter == NULL_MULTIVALUE_GETTER) {
return localGetter;
}
clazz = method.getReturnType();
break;
} catch (NoSuchMethodException ignored) {
ignore(ignored);
}
}
if (localGetter == null) {
try {
final Field field = clazz.getField(baseName);
localGetter = GetterFactory.newFieldGetter(obj, parent, field, modifier);
if (localGetter == NULL_GETTER || localGetter == NULL_MULTIVALUE_GETTER) {
return localGetter;
}
clazz = field.getType();
} catch (NoSuchFieldException ignored) {
ignore(ignored);
}
}
if (localGetter == null) {
Class c = clazz;
while (!c.isInterface() && !Object.class.equals(c)) {
try {
final Field field = c.getDeclaredField(baseName);
field.setAccessible(true);
localGetter = GetterFactory.newFieldGetter(obj, parent, field, modifier);
if (localGetter == NULL_GETTER || localGetter == NULL_MULTIVALUE_GETTER) {
return localGetter;
}
clazz = field.getType();
break;
} catch (NoSuchFieldException ignored) {
c = c.getSuperclass();
}
}
}
}
if (localGetter == null) {
if (failOnMissingAttribute) {
throw new IllegalArgumentException("There is no suitable accessor for '" + baseName + "' on class '" + clazz.getName() + "'");
} else {
return NULL_GETTER;
}
}
parent = localGetter;
}
getter = parent;
return getter;
} catch (Throwable e) {
throw new QueryException(e);
}
}
use of com.hazelcast.query.QueryException in project hazelcast by hazelcast.
the class ParallelPartitionScanExecutorTest method execute_fail.
@Test
public void execute_fail() {
PartitionScanRunner runner = mock(PartitionScanRunner.class);
ParallelPartitionScanExecutor executor = executor(runner);
Predicate predicate = Predicates.equal("attribute", 1);
QueryResult queryResult = new QueryResult(IterationType.ENTRY, null, null, Long.MAX_VALUE, false);
doThrow(new QueryException()).when(runner).run(anyString(), eq(predicate), anyInt(), isA(QueryResult.class));
expected.expect(QueryException.class);
executor.execute("Map", predicate, asList(1, 2, 3), queryResult);
}
use of com.hazelcast.query.QueryException in project hazelcast by hazelcast.
the class CallerRunsPartitionScanExecutorTest method execute_fail.
@Test
public void execute_fail() {
PartitionScanRunner runner = mock(PartitionScanRunner.class);
CallerRunsPartitionScanExecutor executor = new CallerRunsPartitionScanExecutor(runner);
Predicate predicate = Predicates.equal("attribute", 1);
QueryResult queryResult = new QueryResult(IterationType.ENTRY, null, null, Long.MAX_VALUE, false);
doThrow(new QueryException()).when(runner).run(anyString(), eq(predicate), anyInt(), eq(queryResult));
expected.expect(QueryException.class);
executor.execute("Map", predicate, asList(1, 2, 3), queryResult);
}
Aggregations