>
> At that point I think we're outside the bounds of what H2 should 
> provide, and you should probably just implement that yourself in your 
> own main() function. 
>
> However, I'm happy to make some more of the AutoRegisterFunctionAliases 
> methods public again, if that will help? 
>

hmm ... ok i'm sprinting ahead --- maybe a interface like:

public interface FunctionRegistry 
{ 
public Map<String,String> getRegistryMap(); 
} 
 
should be recognized by AutoRegisterFunctionAliases like the aggregate 
interface.

then the would-be implementors need not public registerFunction/
registerAggregate, 
but simply return a map of aliasName/classMethodName to be registered.

hope you like the attached patch.

> i also have in the queue stubs for all mysql 5.6 functions not 
> > implemented by h2. 
> > 
>
> Unless you actually have a use-case for those, I'd not be terribly keen 
> on cluttering up the code with them. 
>

no you need not fear -- this will be a separated google-code project, so 
users may pick what they want.

C

-- 
You received this message because you are subscribed to the Google Groups "H2 
Database" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/h2-database/-/edRdtdqYQMsJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/h2-database?hl=en.

Index: src/main/org/h2/ext/AutoRegisterFunctionAliases.java
===================================================================
--- src/main/org/h2/ext/AutoRegisterFunctionAliases.java	(revision 4287)
+++ src/main/org/h2/ext/AutoRegisterFunctionAliases.java	(working copy)
@@ -12,6 +12,11 @@
 import java.lang.reflect.Modifier;
 import java.net.URL;
 import java.util.Collections;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+
+import org.h2.api.FunctionRegistry;
 import org.h2.command.ddl.CreateAggregate;
 import org.h2.command.ddl.CreateFunctionAlias;
 import org.h2.engine.Session;
@@ -80,13 +85,26 @@
                 registerAggregate(trace, session, schema, className, alias);
                 return;
             }
+            else if ("org.h2.api.FunctionRegistry".equalsIgnoreCase(x.getCanonicalName())) {
+            	try {
+					for(Entry<String, String> fndef : ((FunctionRegistry)x.newInstance()).getRegistryMap().entrySet()) {
+						String methodAlias = fndef.getKey();
+						String methodName = fndef.getValue();
+						registerFunction(trace, session, schema, className, methodName, methodAlias);
+					}
+				} catch (Exception xe) {
+					trace.error(xe, "registration error: class {0}", clazz);
+				}
+                return;
+            }
+            
         }
 
         // not an aggregate implementation
         for (Method m : clazz.getDeclaredMethods()) {
             if (m.getName().toUpperCase().startsWith("FN_") && m.isAccessible()
                     && (m.getModifiers() & Modifier.STATIC) == Modifier.STATIC) {
-                registerFunction(trace, session, schema, className, m.getName(), m.getName().substring(3));
+            	registerFunction(trace, session, schema, className, m.getName(), m.getName().substring(3));
             }
         }
     }
Index: src/main/org/h2/api/FunctionRegistry.java
===================================================================
--- src/main/org/h2/api/FunctionRegistry.java	(revision 0)
+++ src/main/org/h2/api/FunctionRegistry.java	(revision 0)
@@ -0,0 +1,8 @@
+package org.h2.api;
+
+import java.util.Map;
+
+public interface FunctionRegistry 
+{ 
+public Map<String,String> getRegistryMap(); 
+} 
\ No newline at end of file

Reply via email to