Skip to content

Commit

Permalink
TEIIDDES-1518: Refactor UdfManager
Browse files Browse the repository at this point in the history
* Creates interfaces and wrapper implementations for FunctionLibrary,
  FunctionForm

* Uses descriptors to avoid references to both FunctionMethod and
  FunctionParameter

* Adds a TeiidServerVersionListener for when the default server is changed,
  the UdfManager is notified and can update its function libraries
  according to the new server version
  • Loading branch information
Paul Richardson committed Dec 7, 2012
1 parent 6907c1f commit 469a193
Show file tree
Hide file tree
Showing 21 changed files with 792 additions and 174 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.ResourceBundle;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.CopyOnWriteArrayList;
import org.eclipse.core.resources.IFile;
Expand Down Expand Up @@ -93,6 +95,7 @@
import org.teiid.designer.core.workspace.ModelWorkspaceManager;
import org.teiid.designer.core.workspace.ModelWorkspaceManagerSaveParticipant;
import org.teiid.designer.runtime.registry.TeiidRuntimeRegistry;
import org.teiid.designer.runtime.spi.ITeiidServerVersionListener;
import org.teiid.designer.runtime.version.spi.ITeiidServerVersion;
import org.teiid.designer.runtime.version.spi.TeiidServerVersion;
import org.teiid.designer.sql.IQueryService;
Expand Down Expand Up @@ -340,6 +343,8 @@ public static enum RegistryOption {

private static ITeiidServerVersion teiidServerVersion = null;

private static Set<ITeiidServerVersionListener> teiidServerVersionListeners;

/**
* Add all model resource sets known through the EXTERNAL_RESOURCE_SET extension to the specified container
*
Expand Down Expand Up @@ -2083,13 +2088,46 @@ public static ITeiidServerVersion getTeiidServerVersion() {
return teiidServerVersion;
}

/**
* Add a listener to be notified in the event the default server
* version is changed
*
* @param listener
*/
public static void addTeiidServerVersionListener(ITeiidServerVersionListener listener) {
if (teiidServerVersionListeners == null)
teiidServerVersionListeners = new HashSet<ITeiidServerVersionListener>();

teiidServerVersionListeners.add(listener);
}

/**
* Remove a listener no longer interested in listening
* to changes is server version
*
* @param listener
*/
public static void removeTeiidServerVersionListener(ITeiidServerVersionListener listener) {
if (teiidServerVersionListeners == null)
return;

teiidServerVersionListeners.remove(listener);
}

/**
* Set the version of the targeted teiid server
*
* @param serverVersion
*/
public static void setTeiidServerVersion(ITeiidServerVersion serverVersion) {
teiidServerVersion = serverVersion;

if (teiidServerVersionListeners == null)
return;

for (ITeiidServerVersionListener listener : teiidServerVersionListeners) {
listener.versionChanged(serverVersion);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,11 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.teiid.core.designer.util.CoreArgCheck;
import org.teiid.core.designer.util.I18nUtil;
import org.teiid.designer.udf.IFunctionForm;
import org.teiid.designer.udf.IFunctionLibrary;
import org.teiid.designer.udf.UdfManager;

import org.teiid.query.function.FunctionForm;
import org.teiid.query.function.FunctionLibrary;
import org.teiid.query.sql.LanguageObject;
import org.teiid.query.sql.symbol.Constant;
import org.teiid.query.sql.symbol.Expression;
import org.teiid.query.sql.symbol.Function;
import org.teiid.query.ui.builder.util.BuilderUtils;

/**
Expand Down Expand Up @@ -52,14 +46,14 @@ public class FunctionEditorModel extends AbstractLanguageObjectEditorModel {

private String category;
private String[] functions; // collection of function names valid for current category
private FunctionForm[] functionForms;
private IFunctionForm[] functionForms;

private static String defaultCategory;

/** The function library. All information about functions is obtained from here. */
private FunctionLibrary funcLib;
private IFunctionLibrary funcLib;

private FunctionForm selectedFunctionForm;
private IFunctionForm selectedFunctionForm;

// /////////////////////////////////////////////////////////////////////////////////////////////
// CONSTRUCTORS
Expand All @@ -85,8 +79,8 @@ public void clear() {
super.clear();
}

private FunctionForm findFunctionForm( String theFunctionName ) {
FunctionForm result = null;
private IFunctionForm findFunctionForm( String theFunctionName ) {
IFunctionForm result = null;

if (functionForms != null) {
for (int i = 0; i < functionForms.length; i++) {
Expand All @@ -104,7 +98,7 @@ public String[] getCategories() {
// not sure if users can dynamically add categories.
// make this construct categories each time this method is called
categories = null;
funcLib = UdfManager.INSTANCE.getFunctionLibrary(); //new FunctionLibrary(SystemFunctionManager.getSystemFunctions(),
funcLib = UdfManager.getInstance().getFunctionLibrary(); //new FunctionLibrary(SystemFunctionManager.getSystemFunctions(),
//new FunctionTree(new UDFSource(Collections.EMPTY_LIST)));
List list = funcLib.getFunctionCategories();

Expand Down Expand Up @@ -256,15 +250,15 @@ public void setCategory( String theCategory ) {

if ((forms != null) && !forms.isEmpty()) {
int size = forms.size();
functionForms = new FunctionForm[size];
functionForms = new IFunctionForm[size];
functions = new String[size];

for (int i = 0; i < size; i++) {
functionForms[i] = (FunctionForm)forms.get(i);
functionForms[i] = (IFunctionForm) forms.get(i);
functions[i] = functionForms[i].getDisplayString();
}
} else {
functionForms = new FunctionForm[1];
functionForms = new IFunctionForm[1];
functions = new String[1];
functions[0] = NONE;
}
Expand All @@ -280,7 +274,7 @@ private void setFunction( Function theFunction ) {
clear();
} else {
Expression[] newArgValues = theFunction.getArgs();
FunctionForm functionForm = funcLib.findFunctionForm(theFunction.getName(), newArgValues.length);
IFunctionForm functionForm = funcLib.findFunctionForm(theFunction.getName(), newArgValues.length);

if( functionForm != null ) {
setCategory(functionForm.getCategory());
Expand Down Expand Up @@ -309,7 +303,7 @@ public void setFunctionArgValue( Expression theValue,
}

public void setFunctionName( String theName ) {
FunctionForm functionForm = findFunctionForm(theName);
IFunctionForm functionForm = findFunctionForm(theName);
CoreArgCheck.isNotNull(functionForm);

if ((selectedFunctionForm == null) || !selectedFunctionForm.equals(functionForm)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import org.teiid.designer.runtime.spi.IExecutionConfigurationListener;
import org.teiid.designer.sql.IQueryService;
import org.teiid.designer.type.IDataTypeManagerService;
import org.teiid.designer.udf.IFunctionForm;
import org.teiid.designer.udf.IFunctionLibrary;
import org.teiid.designer.udf.UdfManager;
import org.teiid.query.ui.UiConstants;

Expand Down Expand Up @@ -87,15 +89,10 @@ private void init() {
Iterator iter;
try {
// FUNCTION NAMES List
FunctionLibrary functionLib = UdfManager.INSTANCE.getSystemFunctionLibrary();
List allCategories = functionLib.getFunctionCategories();
iter = allCategories.iterator();
while (iter.hasNext()) {
String catName = (String)iter.next();
List catFunctions = functionLib.getFunctionForms(catName);
Iterator funcIter = catFunctions.iterator();
while (funcIter.hasNext()) {
FunctionForm fForm = (FunctionForm)funcIter.next();
IFunctionLibrary functionLib = UdfManager.getInstance().getSystemFunctionLibrary();
List<String> allCategories = functionLib.getFunctionCategories();
for (String category : allCategories) {
for (IFunctionForm fForm : functionLib.getFunctionForms(category)) {
String fName = fForm.getName();
allFunctionNames.add(fName);
String start = fName.substring(0, 1);
Expand Down
3 changes: 2 additions & 1 deletion plugins/org.teiid.designer.spi/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ Export-Package: org.teiid.datatools.connectivity.spi,
org.teiid.designer.runtime.spi,
org.teiid.designer.runtime.version.spi,
org.teiid.designer.sql,
org.teiid.designer.type
org.teiid.designer.type,
org.teiid.designer.udf
Bundle-Activator: org.teiid.designer.DesignerSPIPlugin
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* JBoss, Home of Professional Open Source.
*
* See the LEGAL.txt file distributed with this work for information regarding copyright ownership and licensing.
*
* See the AUTHORS.txt file distributed with this work for a full listing of individual contributors.
*/
package org.teiid.designer.runtime.spi;

import org.teiid.designer.runtime.version.spi.ITeiidServerVersion;

/**
*
*/
public interface ITeiidServerVersionListener {

/**
* Version of teiid server has been changed
*
* @param version
*/
void versionChanged(ITeiidServerVersion version);

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
*/
package org.teiid.designer.sql;

import java.util.List;
import java.util.Set;
import org.teiid.designer.udf.FunctionMethodDescriptor;
import org.teiid.designer.udf.IFunctionLibrary;

/**
*
Expand Down Expand Up @@ -55,4 +58,23 @@ public interface IQueryService {
* @return type name
*/
String getJDBCSQLTypeName(int jdbcType);

/**
* Create a new default function library
*
* @return instance of {@link IFunctionLibrary}
*/
IFunctionLibrary createFunctionLibrary();

/**
* Create a new function library with custom functions
* derived from the given list of descriptors
*
* @param functionMethodDescriptors
*
* @return instance of {@link IFunctionLibrary}
*/
IFunctionLibrary createFunctionLibrary(List<FunctionMethodDescriptor> functionMethodDescriptors);


}

0 comments on commit 469a193

Please sign in to comment.