use of org.datanucleus.store.rdbms.sql.operation.SQLOperation 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);
}
}
Aggregations