Skip to content

Commit

Permalink
TEIIDDES-1667 Ability to define UDF with vararg
Browse files Browse the repository at this point in the history
  • Loading branch information
mdrillin committed May 14, 2013
1 parent ac6ad10 commit b8fb6af
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.eclipse.emf.common.util.ResourceLocator;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.common.util.WrappedException;
import org.eclipse.emf.ecore.EObject;
import org.osgi.framework.BundleContext;
import org.teiid.core.designer.PluginUtil;
import org.teiid.core.designer.util.PluginUtilImpl;
Expand Down Expand Up @@ -200,4 +201,28 @@ void handleNewModelEvent(final ModelWorkspaceNotification notification) {
}
}
}

/**
*
* @param modelObject the emf model object
* @param propertyID the extension property ID
* @return the string value of the property. may be null
*/
public static String getExtensionProperty(EObject modelObject, String propertyID) {
String value = null;

if (modelObject != null) {
final ModelExtensionRegistry registry = ExtensionPlugin.getInstance().getRegistry();
final String prefix = FunctionModelExtensionConstants.NAMESPACE_PROVIDER.getNamespacePrefix();
final FunctionModelExtensionAssistant assistant = (FunctionModelExtensionAssistant)registry.getModelExtensionAssistant(prefix);

try {
value = assistant.getPropertyValue(modelObject, propertyID);
} catch (Exception e) {
Util.log(e);
}
}

return value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.eclipse.emf.common.util.ResourceLocator;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.common.util.WrappedException;
import org.eclipse.emf.ecore.EObject;
import org.osgi.framework.BundleContext;
import org.teiid.core.designer.PluginUtil;
import org.teiid.core.designer.util.PluginUtilImpl;
Expand Down Expand Up @@ -211,4 +212,28 @@ void handleNewModelEvent(final ModelWorkspaceNotification notification) {
}
}
}

/**
*
* @param modelObject the emf model object
* @param propertyID the extension property ID
* @return the string value of the property. may be null
*/
public static String getExtensionProperty(EObject modelObject, String propertyID) {
String value = null;

if (modelObject != null) {
final ModelExtensionRegistry registry = ExtensionPlugin.getInstance().getRegistry();
final String prefix = RelationalModelExtensionConstants.NAMESPACE_PROVIDER.getNamespacePrefix();
final RelationalModelExtensionAssistant assistant = (RelationalModelExtensionAssistant)registry.getModelExtensionAssistant(prefix);

try {
value = assistant.getPropertyValue(modelObject, propertyID);
} catch (Exception e) {
Util.log(e);
}
}

return value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ protected ModelExtensionPropertyDefinition getPropertyDefinition(final Object mo

// must be a procedure in a physical model to have these properties
if (PropertyName.same(PropertyName.NON_PREPARED, propId)) {
if ((modelObject instanceof Procedure) && ModelUtil.isPhysical(modelObject)) {
if ((modelObject instanceof Procedure) && isPhysical) {
return propDefn;
}

Expand All @@ -138,54 +138,32 @@ protected ModelExtensionPropertyDefinition getPropertyDefinition(final Object mo

// 'UDF' properties are supported in physical or virtual models now, when function=true
if ( PropertyName.same(PropertyName.JAVA_CLASS, propId) || PropertyName.same(PropertyName.JAVA_METHOD, propId)
|| PropertyName.same(PropertyName.FUNCTION_CATEGORY, propId) || PropertyName.same(PropertyName.UDF_JAR_PATH, propId)) {
|| PropertyName.same(PropertyName.FUNCTION_CATEGORY, propId) || PropertyName.same(PropertyName.UDF_JAR_PATH, propId)
|| PropertyName.same(PropertyName.VARARGS, propId) || PropertyName.same(PropertyName.NULL_ON_NULL, propId)
|| PropertyName.same(PropertyName.DETERMINISTIC, propId) || PropertyName.same(PropertyName.AGGREGATE, propId)) {
if ((modelObject instanceof Procedure) && isFunction) {
return propDefn;
}

// make sure model object does not have these extension properties for when function is false
removeProperty(modelObject, PropertyName.DETERMINISTIC.toString());
removeProperty(modelObject, PropertyName.JAVA_CLASS.toString());
removeProperty(modelObject, PropertyName.JAVA_METHOD.toString());
removeProperty(modelObject, PropertyName.FUNCTION_CATEGORY.toString());
removeProperty(modelObject, PropertyName.UDF_JAR_PATH.toString());
removeProperty(modelObject, PropertyName.VARARGS.toString());
removeProperty(modelObject, PropertyName.NULL_ON_NULL.toString());
removeProperty(modelObject, PropertyName.AGGREGATE.toString());
removeProperty(modelObject, PropertyName.ANALYTIC.toString());
removeProperty(modelObject, PropertyName.ALLOWS_ORDER_BY.toString());
removeProperty(modelObject, PropertyName.USES_DISTINCT_ROWS.toString());
removeProperty(modelObject, PropertyName.DECOMPOSABLE.toString());
removeProperty(modelObject, PropertyName.ALLOWS_DISTINCT.toString());

// EObject should not have these property definitions
return null;
}

// must be a procedure in a physical model and have function property set to true to have these properties
if (PropertyName.same(PropertyName.DETERMINISTIC, propId)) {
if ((modelObject instanceof Procedure) && isFunction) {
return propDefn;
}

// make sure model object does not have this extension property for when function is false
removeProperty(modelObject, PropertyName.DETERMINISTIC.toString());

// EObject should not have these property definitions
return null;
}

// must have function set to true to have aggregate property
if (PropertyName.same(PropertyName.AGGREGATE, propId)) {
if ((modelObject instanceof Procedure) ) {
if (isFunction) {
return propDefn;
}

// make sure model object does not have these extension properties for when function is false
removeProperty(modelObject, PropertyName.AGGREGATE.toString());
removeProperty(modelObject, PropertyName.ANALYTIC.toString());
removeProperty(modelObject, PropertyName.ALLOWS_ORDER_BY.toString());
removeProperty(modelObject, PropertyName.USES_DISTINCT_ROWS.toString());
removeProperty(modelObject, PropertyName.DECOMPOSABLE.toString());
removeProperty(modelObject, PropertyName.ALLOWS_DISTINCT.toString());
}

// EObject should not have the aggregate property definition
return null;
}

if (PropertyName.same(PropertyName.ANALYTIC, propId) || PropertyName.same(PropertyName.ALLOWS_ORDER_BY, propId)
|| PropertyName.same(PropertyName.USES_DISTINCT_ROWS, propId)
|| PropertyName.same(PropertyName.ALLOWS_DISTINCT, propId)
Expand All @@ -210,18 +188,6 @@ protected ModelExtensionPropertyDefinition getPropertyDefinition(final Object mo
return null;
}

if( PropertyName.same(PropertyName.VARARGS, propId)
|| PropertyName.same(PropertyName.NULL_ON_NULL, propId)) {
if ((modelObject instanceof Procedure) && ModelUtil.isPhysical(modelObject)) {
if (isFunction) {
return propDefn;
}
removeProperty(modelObject, PropertyName.VARARGS.toString());
removeProperty(modelObject, PropertyName.NULL_ON_NULL.toString());
}
return null;
}

return propDefn;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class FunctionMethodDescriptor {
private final String schema;
private String pushDownLiteral;
private boolean deterministic;
private boolean varArgs;

/**
* @param metadataID
Expand Down Expand Up @@ -141,4 +142,18 @@ public boolean isDeterministic() {
public void setDeterministic(boolean deterministic) {
this.deterministic = deterministic;
}

/**
* @return the varArgs
*/
public boolean isVariableArgs() {
return this.varArgs;
}

/**
* @param varArgs
*/
public void setVariableArgs(boolean varArgs) {
this.varArgs = varArgs;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.util.List;
import java.util.Properties;
import java.util.Set;

import org.eclipse.core.internal.resources.Marker;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
Expand All @@ -39,11 +40,13 @@
import org.teiid.designer.core.workspace.ResourceChangeUtilities;
import org.teiid.designer.core.workspace.WorkspaceResourceFinderUtil;
import org.teiid.designer.metamodels.core.ModelType;
import org.teiid.designer.metamodels.function.FunctionPlugin;
import org.teiid.designer.metamodels.function.ScalarFunction;
import org.teiid.designer.metamodels.relational.DirectionKind;
import org.teiid.designer.metamodels.relational.Procedure;
import org.teiid.designer.metamodels.relational.ProcedureParameter;
import org.teiid.designer.metamodels.relational.RelationalPackage;
import org.teiid.designer.metamodels.relational.RelationalPlugin;
import org.teiid.designer.metamodels.relational.util.PushdownFunctionData;
import org.teiid.designer.query.IQueryService;
import org.teiid.designer.runtime.spi.ITeiidServer;
Expand Down Expand Up @@ -430,6 +433,13 @@ public synchronized IFunctionLibrary<IFunctionForm, IFunctionDescriptor> getFunc

fMethodDescriptor.setPushDown(function.getPushDown().getLiteral());
fMethodDescriptor.setDeterministic(function.isDeterministic());

boolean varArgs = false;
String propValue = FunctionPlugin.getExtensionProperty(function, "function:varargs"); //$NON-NLS-1$
if( propValue != null && propValue.length() > 0 ) {
varArgs = Boolean.parseBoolean(propValue);
}
fMethodDescriptor.setVariableArgs(varArgs);

functionMethodDescriptors.add(fMethodDescriptor);
}
Expand Down Expand Up @@ -515,6 +525,13 @@ public synchronized IFunctionLibrary<IFunctionForm, IFunctionDescriptor> getFunc
fMethodDescriptor.setPushDown(Boolean.toString(true));
fMethodDescriptor.setDeterministic(wrappedProcedure.isDeterministic());

boolean varArgs = false;
String propValue = RelationalPlugin.getExtensionProperty(procedure, "relational:varargs"); //$NON-NLS-1$
if( propValue != null && propValue.length() > 0 ) {
varArgs = Boolean.parseBoolean(propValue);
}
fMethodDescriptor.setVariableArgs(varArgs);

functionMethodDescriptors.add(fMethodDescriptor);
}
}
Expand Down Expand Up @@ -589,6 +606,7 @@ class ScalarFunctionFinder implements ModelVisitor {

Collection<ScalarFunction> functions;

@SuppressWarnings("unused")
@Override
public boolean visit(EObject object) throws ModelerCoreException {
// Tables are contained by Catalogs, Schemas and Resources
Expand All @@ -603,6 +621,7 @@ public boolean visit(EObject object) throws ModelerCoreException {
return false;
}

@SuppressWarnings("unused")
@Override
public boolean visit(Resource resource) throws ModelerCoreException {
return true;
Expand Down
2 changes: 1 addition & 1 deletion plugins/teiid/org.teiid.8.3.x
Submodule org.teiid.8.3.x updated 1 files
+1 −0 designer/org/teiid83/sql/QueryService.java
2 changes: 1 addition & 1 deletion plugins/teiid/org.teiid.8.4.x
Submodule org.teiid.8.4.x updated 1 files
+2 −0 designer/org/teiid84/sql/QueryService.java

0 comments on commit b8fb6af

Please sign in to comment.