use of org.datanucleus.plugin.PluginManager in project datanucleus-rdbms by datanucleus.
the class SQLExpressionFactory method invokeOperation.
/**
* Accessor for the result of an SQLOperation call on the supplied expression with the supplied args.
* Throws a NucleusException is the method is not supported.
* @param name Operation to be invoked
* @param expr The first expression to perform the operation on
* @param expr2 The second expression to perform the operation on
* @return The result
* @throws UnsupportedOperationException if the operation is not specified
*/
public SQLExpression invokeOperation(String name, SQLExpression expr, SQLExpression expr2) {
// Check for instantiated plugin SQLOperation
DatastoreAdapter dba = storeMgr.getDatastoreAdapter();
SQLOperation operation = sqlOperationsByName.get(name);
if (operation != null) {
return operation.getExpression(expr, expr2);
}
// Check for built-in SQLOperation class definition
Class sqlOpClass = dba.getSQLOperationClass(name);
if (sqlOpClass != null) {
try {
// Instantiate it
operation = (SQLOperation) sqlOpClass.newInstance();
sqlOperationsByName.put(name, operation);
return operation.getExpression(expr, expr2);
} catch (Exception e) {
throw new NucleusException("Error creating SQLOperation of type " + sqlOpClass.getName() + " for operation " + name);
}
}
// Check for plugin definition of this operation for this datastore
// 1). Try datastore-dependent key
String datastoreId = dba.getVendorID();
String key = getSQLOperationKey(datastoreId, name);
boolean datastoreDependent = true;
if (!pluginSqlOperationKeysSupported.contains(key)) {
// 2). No datastore-dependent method, so try a datastore-independent key
key = getSQLOperationKey(null, name);
datastoreDependent = false;
if (!pluginSqlOperationKeysSupported.contains(key)) {
throw new UnsupportedOperationException("Operation " + name + " on datastore=" + datastoreId + " not supported");
}
}
PluginManager pluginMgr = storeMgr.getNucleusContext().getPluginManager();
String[] attrNames = (datastoreDependent ? new String[] { "name", "datastore" } : new String[] { "name" });
String[] attrValues = (datastoreDependent ? new String[] { name, datastoreId } : new String[] { name });
try {
operation = (SQLOperation) pluginMgr.createExecutableExtension("org.datanucleus.store.rdbms.sql_operation", attrNames, attrValues, "evaluator", null, null);
synchronized (operation) {
sqlOperationsByName.put(key, operation);
return operation.getExpression(expr, expr2);
}
} catch (Exception e) {
throw new NucleusUserException(Localiser.msg("060011", "operation=" + name), e);
}
}
use of org.datanucleus.plugin.PluginManager in project datanucleus-rdbms by datanucleus.
the class SQLExpressionFactory method getMethod.
/**
* Accessor for the method defined by the class/method names and supplied args.
* Throws a NucleusException is the method is not supported.
* Note that if the class name passed in is not for a listed class with that method defined then will check all remaining defined methods for a superclass.
* @param className Class we are invoking the method on
* @param methodName Name of the method
* @param args Any arguments to the method call (ignored currently) TODO Check the arguments
* @return The method
*/
protected SQLMethod getMethod(String className, String methodName, List args) {
String datastoreId = storeMgr.getDatastoreAdapter().getVendorID();
// Try to find datastore-dependent evaluator for class+method
MethodKey methodKey1 = getSQLMethodKey(datastoreId, className, methodName);
MethodKey methodKey2 = null;
SQLMethod method = sqlMethodsByKey.get(methodKey1);
if (method == null) {
// Try to find datastore-independent evaluator for class+method
methodKey2 = getSQLMethodKey(null, className, methodName);
method = sqlMethodsByKey.get(methodKey2);
}
if (method != null) {
return method;
}
// No existing instance, so check the built-in SQLMethods from DatastoreAdapter
Class sqlMethodCls = storeMgr.getDatastoreAdapter().getSQLMethodClass(className, methodName, clr);
if (sqlMethodCls != null) {
// Built-in SQLMethod found, so instantiate it, cache it and return it
try {
method = (SQLMethod) sqlMethodCls.newInstance();
MethodKey key = getSQLMethodKey(datastoreId, className, methodName);
sqlMethodsByKey.put(key, method);
return method;
} catch (Exception e) {
throw new NucleusException("Error creating SQLMethod of type " + sqlMethodCls.getName() + " for class=" + className + " method=" + methodName);
}
}
// Check the plugin mechanism
// 1). Try datastore-dependent key
boolean datastoreDependent = true;
if (!pluginSqlMethodsKeysSupported.contains(methodKey1)) {
// 2). No datastore-dependent method, so try a datastore-independent key
datastoreDependent = false;
if (!pluginSqlMethodsKeysSupported.contains(methodKey2)) {
// Not listed as supported for this particular class+method, so maybe is for a superclass
boolean unsupported = true;
if (!StringUtils.isWhitespace(className)) {
Class cls = clr.classForName(className);
// Try datastore-dependent
for (MethodKey methodKey : pluginSqlMethodsKeysSupported) {
if (methodKey.methodName.equals(methodName) && methodKey.datastoreName.equals(datastoreId)) {
Class methodCls = null;
try {
methodCls = clr.classForName(methodKey.clsName);
} catch (ClassNotResolvedException cnre) {
// Maybe generic array support?
}
if (methodCls != null && methodCls.isAssignableFrom(cls)) {
// This one is usable here, for superclass
method = sqlMethodsByKey.get(methodKey);
if (method != null) {
MethodKey superMethodKey = new MethodKey();
superMethodKey.clsName = className;
superMethodKey.methodName = methodKey.methodName;
superMethodKey.datastoreName = methodKey.datastoreName;
// Cache the same method under this class also
sqlMethodsByKey.put(superMethodKey, method);
return method;
}
className = methodKey.clsName;
datastoreId = methodKey.datastoreName;
datastoreDependent = true;
unsupported = false;
break;
}
}
}
if (unsupported) {
// Try datastore-independent
for (MethodKey methodKey : pluginSqlMethodsKeysSupported) {
if (methodKey.methodName.equals(methodName) && methodKey.datastoreName.equals("ALL")) {
Class methodCls = null;
try {
methodCls = clr.classForName(methodKey.clsName);
} catch (ClassNotResolvedException cnre) {
// Maybe generic array support?
}
if (methodCls != null && methodCls.isAssignableFrom(cls)) {
// This one is usable here, for superclass
method = sqlMethodsByKey.get(methodKey);
if (method != null) {
MethodKey superMethodKey = new MethodKey();
superMethodKey.clsName = className;
superMethodKey.methodName = methodKey.methodName;
superMethodKey.datastoreName = methodKey.datastoreName;
// Cache the same method under this class also
sqlMethodsByKey.put(superMethodKey, method);
return method;
}
className = methodKey.clsName;
datastoreId = methodKey.datastoreName;
datastoreDependent = false;
unsupported = false;
break;
}
}
}
}
}
if (unsupported) {
if (className != null) {
throw new NucleusUserException(Localiser.msg("060008", methodName, className));
}
throw new NucleusUserException(Localiser.msg("060009", methodName));
}
}
}
// Fallback to plugin lookup of class+method[+datastore]
PluginManager pluginMgr = storeMgr.getNucleusContext().getPluginManager();
String[] attrNames = (datastoreDependent ? new String[] { "class", "method", "datastore" } : new String[] { "class", "method" });
String[] attrValues = (datastoreDependent ? new String[] { className, methodName, datastoreId } : new String[] { className, methodName });
try {
method = (SQLMethod) pluginMgr.createExecutableExtension("org.datanucleus.store.rdbms.sql_method", attrNames, attrValues, "evaluator", new Class[] {}, new Object[] {});
// Register the method
sqlMethodsByKey.put(getSQLMethodKey(datastoreDependent ? datastoreId : null, className, methodName), method);
return method;
} catch (Exception e) {
throw new NucleusUserException(Localiser.msg("060011", "class=" + className + " method=" + methodName), e);
}
}
use of org.datanucleus.plugin.PluginManager in project datanucleus-core by datanucleus.
the class AnnotationManagerImpl method getMetaDataForClass.
/**
* Accessor for the MetaData for the specified class, read from annotations.
* The annotations can be of any supported type.
* @param cls The class
* @param pmd PackageMetaData to use as a parent
* @param clr ClassLoader resolver
* @return The ClassMetaData
*/
public AbstractClassMetaData getMetaDataForClass(Class cls, PackageMetaData pmd, ClassLoaderResolver clr) {
if (cls == null || cls.isAnnotation()) {
return null;
}
Annotation[] annotations = cls.getAnnotations();
if (annotations == null || annotations.length == 0) {
return null;
}
// Find an annotation reader for this classes annotations (if we have one)
String readerClassName = null;
for (Annotation annotation : annotations) {
String reader = annotationReaderLookup.get(annotation.annotationType().getName());
if (reader != null) {
readerClassName = reader;
break;
}
// Try any sub-annotations in case this is a meta-annotation
Annotation[] subAnnotations = annotation.annotationType().getAnnotations();
for (Annotation subAnnotation : subAnnotations) {
reader = annotationReaderLookup.get(subAnnotation.annotationType().getName());
if (reader != null) {
readerClassName = reader;
break;
}
}
}
if (readerClassName == null) {
NucleusLogger.METADATA.debug(Localiser.msg("044202", cls.getName()));
return null;
}
AnnotationReader reader = annotationReaders.get(readerClassName);
if (reader == null) {
// Try to create this AnnotationReader
try {
Class[] ctrArgs = new Class[] { ClassConstants.METADATA_MANAGER };
Object[] ctrParams = new Object[] { metadataMgr };
PluginManager pluginMgr = metadataMgr.getNucleusContext().getPluginManager();
reader = (AnnotationReader) pluginMgr.createExecutableExtension("org.datanucleus.annotations", "reader", readerClassName, "reader", ctrArgs, ctrParams);
// Save the annotation reader in case we have more of this type
annotationReaders.put(readerClassName, reader);
} catch (Exception e) {
NucleusLogger.METADATA.warn(Localiser.msg("MetaData.AnnotationReaderNotFound", readerClassName));
return null;
}
}
return reader.getMetaDataForClass(cls, pmd, clr);
}
use of org.datanucleus.plugin.PluginManager in project tests by datanucleus.
the class SpatialAdaptersTest method testDatabaseProductNames.
public void testDatabaseProductNames() throws SQLException {
PluginManager pluginMgr = ((JDOPersistenceManagerFactory) pmf).getNucleusContext().getPluginManager();
ClassLoaderResolver clr = ((JDOPersistenceManagerFactory) pmf).getNucleusContext().getClassLoaderResolver(null);
DatastoreAdapterFactory factory = DatastoreAdapterFactory.getInstance();
assertEquals("org.datanucleus.store.types.geospatial.rdbms.adapter.MySQLSpatialAdapter", factory.getAdapterClass(pluginMgr, null, "MySQL", clr).getName());
assertEquals("org.datanucleus.store.types.geospatial.rdbms.adapter.OracleSpatialAdapter", factory.getAdapterClass(pluginMgr, null, "Oracle", clr).getName());
assertEquals("org.datanucleus.store.types.geospatial.rdbms.adapter.PostGISAdapter", factory.getAdapterClass(pluginMgr, null, "PostgreSQL", clr).getName());
}
use of org.datanucleus.plugin.PluginManager in project datanucleus-core by datanucleus.
the class QueryManagerImpl method getInMemoryEvaluatorForMethod.
/* (non-Javadoc)
* @see org.datanucleus.store.query.QueryManager#getInMemoryEvaluatorForMethod(java.lang.Class, java.lang.String)
*/
@Override
public InvocationEvaluator getInMemoryEvaluatorForMethod(Class type, String methodName) {
String lookupName = type != null ? (type.getName() + ":" + methodName) : methodName;
// Hardcode support for Array.size()/Array.length()/Array.contains() since not currently pluggable
if (type != null && type.isArray()) {
lookupName = "ARRAY:" + methodName;
}
InvocationEvaluator eval = inmemoryQueryMethodEvaluatorByName.get(lookupName);
if (eval != null) {
return eval;
}
// Load built-in handler for this class+method
ClassLoaderResolver clr = nucleusCtx.getClassLoaderResolver(type != null ? type.getClassLoader() : null);
if (type == null) {
if ("Math.abs".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.AbsFunction();
if ("Math.sqrt".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.SqrtFunction();
if ("Math.acos".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.ArcCosineFunction();
if ("Math.asin".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.ArcSineFunction();
if ("Math.atan".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.ArcTangentFunction();
if ("Math.cos".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.CosineFunction();
if ("Math.sin".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.SineFunction();
if ("Math.tan".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.TangentFunction();
if ("Math.log".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.LogFunction();
if ("Math.exp".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.ExpFunction();
if ("Math.floor".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.FloorFunction();
if ("Math.ceil".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.CeilFunction();
if ("Math.toDegrees".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.DegreesFunction();
if ("Math.toRadians".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.RadiansFunction();
if ("CURRENT_DATE".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.CurrentDateFunction();
if ("CURRENT_TIME".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.CurrentTimeFunction();
if ("CURRENT_TIMESTAMP".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.CurrentTimestampFunction();
if ("ABS".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.AbsFunction();
if ("SQRT".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.SqrtFunction();
if ("MOD".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.ModFunction();
if ("COALESCE".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.CoalesceFunction();
if ("COS".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.CosineFunction();
if ("SIN".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.SineFunction();
if ("TAN".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.TangentFunction();
if ("ACOS".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.ArcCosineFunction();
if ("ASIN".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.ArcSineFunction();
if ("ATAN".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.ArcTangentFunction();
if ("CEIL".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.CeilFunction();
if ("FLOOR".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.FloorFunction();
if ("LOG".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.LogFunction();
if ("EXP".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.ExpFunction();
if ("NULLIF".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.NullIfFunction();
if ("SIZE".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.SizeFunction();
if ("UPPER".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.UpperFunction();
if ("LOWER".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.LowerFunction();
if ("LENGTH".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.LengthFunction();
if ("CONCAT".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.ConcatFunction();
if ("SUBSTRING".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.SubstringFunction();
if ("LOCATE".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.LocateFunction();
if ("TRIM".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.TrimFunction();
if ("TRIM_LEADING".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.TrimFunction();
if ("TRIM_TRAILING".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.TrimFunction();
if ("DEGREES".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.DegreesFunction();
if ("RADIANS".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.RadiansFunction();
if ("YEAR".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.TemporalYearMethod();
if ("MONTH".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.TemporalMonthMethod();
if ("MONTH_JAVA".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.TemporalMonthJavaMethod();
if ("DAY".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.TemporalDayMethod();
if ("HOUR".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.TemporalHourMethod();
if ("MINUTE".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.TemporalMinuteMethod();
if ("SECOND".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.TemporalSecondMethod();
if (eval != null) {
inmemoryQueryMethodEvaluatorByName.put(lookupName, eval);
return eval;
}
} else {
if (type != null && type.isArray()) {
if ("size".equals(methodName))
eval = new ArraySizeMethod();
if ("length".equals(methodName))
eval = new ArraySizeMethod();
if ("contains".equals(methodName))
eval = new ArrayContainsMethod();
} else if (type.isEnum()) {
if ("matches".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.EnumMatchesMethod();
if ("toString".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.EnumToStringMethod();
if ("ordinal".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.EnumOrdinalMethod();
} else if ("java.lang.String".equals(type.getName())) {
if ("charAt".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.StringCharAtMethod();
if ("concat".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.StringConcatMethod();
if ("endsWith".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.StringEndsWithMethod();
if ("equals".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.StringEqualsMethod();
if ("equalsIgnoreCase".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.StringEqualsIgnoreCaseMethod();
if ("indexOf".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.StringIndexOfMethod();
if ("length".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.StringLengthMethod();
if ("matches".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.StringMatchesMethod();
if ("startsWith".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.StringStartsWithMethod();
if ("substring".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.StringSubstringMethod();
if ("toUpperCase".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.StringToUpperCaseMethod();
if ("toLowerCase".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.StringToLowerCaseMethod();
if ("trim".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.StringTrimMethod();
if ("trimLeft".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.StringTrimLeftMethod();
if ("trimRight".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.StringTrimRightMethod();
} else if (java.util.Collection.class.isAssignableFrom(type)) {
if ("size".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.ContainerSizeMethod();
if ("isEmpty".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.ContainerIsEmptyMethod();
if ("contains".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.CollectionContainsMethod();
} else if (java.util.Map.class.isAssignableFrom(type)) {
if ("size".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.ContainerSizeMethod();
if ("isEmpty".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.ContainerIsEmptyMethod();
if ("containsKey".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.MapContainsKeyMethod();
if ("containsValue".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.MapContainsValueMethod();
if ("containsEntry".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.MapContainsEntryMethod();
if ("get".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.MapGetMethod();
} else if (java.util.Optional.class.isAssignableFrom(type)) {
if ("isPresent".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.OptionalIsPresentMethod();
if ("get".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.OptionalGetMethod();
if ("orElse".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.OptionalOrElseMethod();
} else if (java.util.Date.class.isAssignableFrom(type)) {
if ("getTime".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.DateGetTimeMethod();
if ("getDay".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.DateGetDayMethod();
if ("getDate".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.DateGetDayMethod();
if ("getDayOfWeek".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.DateGetDayOfWeekMethod();
if ("getMonth".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.DateGetMonthMethod();
if ("getYear".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.DateGetYearMethod();
if ("getHour".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.DateGetHoursMethod();
if ("getMinute".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.DateGetMinutesMethod();
if ("getSecond".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.DateGetSecondsMethod();
} else if (java.time.LocalDate.class.isAssignableFrom(type)) {
if ("getDayOfMonth".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.LocalDateGetDayOfMonth();
if ("getDayOfWeek".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.LocalDateGetDayOfWeek();
if ("getMonthValue".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.LocalDateGetMonthValue();
if ("getYear".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.LocalDateGetYear();
} else if (java.time.LocalTime.class.isAssignableFrom(type)) {
if ("getHour".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.LocalTimeGetHour();
if ("getMinute".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.LocalTimeGetMinute();
if ("getSecond".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.LocalTimeGetSecond();
} else if (java.time.LocalDateTime.class.isAssignableFrom(type)) {
if ("getDayOfMonth".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.LocalDateTimeGetDayOfMonth();
if ("getDayOfWeek".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.LocalDateTimeGetDayOfWeek();
if ("getMonthValue".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.LocalDateTimeGetMonthValue();
if ("getYear".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.LocalDateTimeGetYear();
if ("getHour".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.LocalDateTimeGetHour();
if ("getMinute".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.LocalDateTimeGetMinute();
if ("getSecond".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.LocalDateTimeGetSecond();
} else if (java.time.MonthDay.class.isAssignableFrom(type)) {
if ("getDayOfMonth".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.MonthDayGetDayOfMonth();
if ("getMonthValue".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.MonthDayGetMonthValue();
} else if (java.time.Period.class.isAssignableFrom(type)) {
if ("getDays".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.PeriodGetDays();
if ("getMonths".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.PeriodGetMonths();
if ("getYears".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.PeriodGetYears();
} else if (java.time.YearMonth.class.isAssignableFrom(type)) {
if ("getYear".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.YearMonthGetYear();
if ("getMonthValue".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.YearMonthGetMonthValue();
}
if (eval == null && java.lang.Object.class.isAssignableFrom(type) && "getClass".equals(methodName))
eval = new org.datanucleus.query.inmemory.method.ObjectGetClassMethod();
if (eval != null) {
inmemoryQueryMethodEvaluatorByName.put(lookupName, eval);
return eval;
}
}
// Fallback to the plugin mechanism
PluginManager pluginMgr = nucleusCtx.getPluginManager();
ConfigurationElement[] elems = pluginMgr.getConfigurationElementsForExtension("org.datanucleus.query_method_evaluators", "method", methodName);
if (elems == null) {
return null;
}
// TODO Lookup with class specified when type != null
InvocationEvaluator requiredEvaluator = null;
for (int i = 0; i < elems.length; i++) {
try {
String evalName = elems[i].getAttribute("evaluator");
eval = (InvocationEvaluator) pluginMgr.createExecutableExtension("org.datanucleus.query_method_evaluators", new String[] { "method", "evaluator" }, new String[] { methodName, evalName }, "evaluator", null, null);
String elemClsName = elems[i].getAttribute("class");
if (elemClsName != null && StringUtils.isWhitespace(elemClsName)) {
elemClsName = null;
}
if (elemClsName == null) {
// Static method call
if (type == null) {
// Evaluator is applicable to the required type
requiredEvaluator = eval;
}
inmemoryQueryMethodEvaluatorByName.put(lookupName, eval);
} else {
Class elemCls = clr.classForName(elemClsName);
if (elemCls.isAssignableFrom(type)) {
// Evaluator is applicable to the required type
requiredEvaluator = eval;
}
inmemoryQueryMethodEvaluatorByName.put(lookupName, eval);
}
} catch (Exception e) {
// Impossible to create the evaluator (class doesn't exist?) TODO Log this?
}
}
return requiredEvaluator;
}
Aggregations