Top Description Inners Fields Constructors Methods
org.h2.schema

public final Class FunctionAlias

extends UserDefinedFunction
Class Inheritance
Imports
java.lang.reflect.Array, .InvocationTargetException, .Method, .Modifier, java.sql.Connection, .ResultSet, .ResultSetMetaData, .SQLException, java.util.ArrayList, .Arrays, org.h2.Driver, org.h2.api.ErrorCode, org.h2.engine.Constants, .DbObject, .SessionLocal, org.h2.expression.Alias, .Expression, .ExpressionColumn, org.h2.jdbc.JdbcConnection, org.h2.message.DbException, .Trace, org.h2.result.LocalResult, .ResultInterface, org.h2.table.Column, org.h2.util.JdbcUtils, .SourceCompiler, .StringUtils, .Utils, org.h2.value.DataType, .TypeInfo, .Value, .ValueNull, .ValueToObjectConverter, .ValueToObjectConverter2

Represents a user-defined function, or alias.
Authors
Thomas Mueller, Gary Tong

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
FunctionAlias.JavaMethod

There may be multiple Java methods that match a function name.

Field Summary

Modifier and TypeField and Description
private boolean
private FunctionAlias.JavaMethod[]
private String
private String
Inherited from org.h2.schema.UserDefinedFunction:
className

Constructor Summary

AccessConstructor and Description
private
FunctionAlias(Schema schema, int id, String name)

Method Summary

Modifier and TypeMethod and Description
public FunctionAlias.JavaMethod

Returns:

the Java method
findJavaMethod
(Expression[]
the argument list
args
)

Find the Java method that matches the arguments.

public String
getCreateSQL()

Implements abstract org.h2.engine.DbObject.getCreateSQL.

Construct the CREATE ...

public String
getDropSQL()

Overrides org.h2.engine.DbObject.getDropSQL.

Construct a DROP ...

public String
public FunctionAlias.JavaMethod[]

Returns:

the Java methods.
getJavaMethods
()

Get the Java methods mapped by this function.

private static String
public String
public int
getType()

Implements abstract org.h2.engine.DbObject.getType.

Get the object type.

private void
init(boolean force)

public boolean
private synchronized void
load()

private void
private void
public static FunctionAlias

Returns:

the database object
newInstance
(Schema
the schema
schema
,
int
the id
id
,
String
the name
name
,
String
the class and method name
javaClassMethod
,
boolean
create the object even if the class or method does not exist
force
)

Create a new alias based on a method name.

public static FunctionAlias

Returns:

the database object
newInstanceFromSource
(Schema
the schema
schema
,
int
the id
id
,
String
the name
name
,
String
the source code
source
,
boolean
create the object even if the class or method does not exist
force
)

Create a new alias based on source code.

public synchronized void
removeChildrenAndResources(SessionLocal
the session
session
)

Implements abstract org.h2.engine.DbObject.removeChildrenAndResources.

Delete all dependent children objects and resources of this object.

public void
setDeterministic(boolean deterministic)

Inherited from org.h2.schema.UserDefinedFunction:
checkRenamegetJavaClassName

Field Detail

deterministicback to summary
private boolean deterministic
javaMethodsback to summary
private FunctionAlias.JavaMethod[] javaMethods
methodNameback to summary
private String methodName
sourceback to summary
private String source

Constructor Detail

FunctionAliasback to summary
private FunctionAlias(Schema schema, int id, String name)

Method Detail

findJavaMethodback to summary
public FunctionAlias.JavaMethod findJavaMethod(Expression[] args)

Find the Java method that matches the arguments.

Parameters
args:Expression[]

the argument list

Returns:FunctionAlias.JavaMethod

the Java method

Exceptions
DbException:
if no matching method could be found
getCreateSQLback to summary
public String getCreateSQL()

Implements abstract org.h2.engine.DbObject.getCreateSQL.

Doc from org.h2.engine.DbObject.getCreateSQL.

Construct the CREATE ... SQL statement for this object.

Returns:String

the SQL statement

Annotations
@Override
getDropSQLback to summary
public String getDropSQL()

Overrides org.h2.engine.DbObject.getDropSQL.

Doc from org.h2.engine.DbObject.getDropSQL.

Construct a DROP ... SQL statement for this object.

Returns:String

the SQL statement

Annotations
@Override
getJavaMethodNameback to summary
public String getJavaMethodName()
getJavaMethodsback to summary
public FunctionAlias.JavaMethod[] getJavaMethods()

Get the Java methods mapped by this function.

Returns:FunctionAlias.JavaMethod[]

the Java methods.

getMethodSignatureback to summary
private static String getMethodSignature(Method m)
getSourceback to summary
public String getSource()
getTypeback to summary
public int getType()

Implements abstract org.h2.engine.DbObject.getType.

Doc from org.h2.engine.DbObject.getType.

Get the object type.

Returns:int

the object type

Annotations
@Override
initback to summary
private void init(boolean force)
isDeterministicback to summary
public boolean isDeterministic()
loadback to summary
private synchronized void load()
loadClassback to summary
private void loadClass()
loadFromSourceback to summary
private void loadFromSource()
newInstanceback to summary
public static FunctionAlias newInstance(Schema schema, int id, String name, String javaClassMethod, boolean force)

Create a new alias based on a method name.

Parameters
schema:Schema

the schema

id:int

the id

name:String

the name

javaClassMethod:String

the class and method name

force:boolean

create the object even if the class or method does not exist

Returns:FunctionAlias

the database object

newInstanceFromSourceback to summary
public static FunctionAlias newInstanceFromSource(Schema schema, int id, String name, String source, boolean force)

Create a new alias based on source code.

Parameters
schema:Schema

the schema

id:int

the id

name:String

the name

source:String

the source code

force:boolean

create the object even if the class or method does not exist

Returns:FunctionAlias

the database object

removeChildrenAndResourcesback to summary
public synchronized void removeChildrenAndResources(SessionLocal session)

Implements abstract org.h2.engine.DbObject.removeChildrenAndResources.

Doc from org.h2.engine.DbObject.removeChildrenAndResources.

Delete all dependent children objects and resources of this object.

Parameters
session:SessionLocal

the session

Annotations
@Override
setDeterministicback to summary
public void setDeterministic(boolean deterministic)
org.h2.schema back to summary

public Class FunctionAlias.JavaMethod

extends Object
implements Comparable<FunctionAlias.JavaMethod>
Class Inheritance
All Implemented Interfaces
java.lang.Comparable

There may be multiple Java methods that match a function name. Each method must have a different number of parameters however. This helper class represents one such method.

Field Summary

Modifier and TypeField and Description
private final TypeInfo
private boolean
private final int
private final Method
private int
private Class<?>
private boolean

Constructor Summary

AccessConstructor and Description
pack-priv
JavaMethod(Method method, int id)

Method Summary

Modifier and TypeMethod and Description
public int
compareTo(FunctionAlias.JavaMethod
the object to be compared.
m
)

Implements java.lang.Comparable.compareTo.

Compares this object with the specified object for order.

private Object
execute(SessionLocal session, Expression[] args, boolean columnList)

public Class<?>[]
public TypeInfo

Returns:

data type information for regular functions or null for table value functions
getDataType
()

Returns data type information for regular functions or null for table value functions.

public int
public ResultInterface

Returns:

the value
getTableValue
(SessionLocal
the session
session
,
Expression[]
the argument list
args
,
boolean
true if the function should only return the column list
columnList
)

Call the table user-defined function and return the value.

public Value

Returns:

the value
getValue
(SessionLocal
the session
session
,
Expression[]
the argument list
args
,
boolean
true if the function should only return the column list
columnList
)

Call the user-defined function and return the value.

public boolean

Returns:

if the function requires a connection
hasConnectionParam
()

Check if this function requires a database connection.

public boolean
public static ResultInterface

Returns:

the value
resultSetToResult
(SessionLocal
the session
session
,
ResultSet
the result set
resultSet
,
int
the maximum number of rows to read (0 to just read the meta data)
maxrows
)

Create a result for the given result set.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

dataTypeback to summary
private final TypeInfo dataType
hasConnectionParamback to summary
private boolean hasConnectionParam
idback to summary
private final int id
methodback to summary
private final Method method
paramCountback to summary
private int paramCount
varArgClassback to summary
private Class<?> varArgClass
varArgsback to summary
private boolean varArgs

Constructor Detail

JavaMethodback to summary
pack-priv JavaMethod(Method method, int id)

Method Detail

compareToback to summary
public int compareTo(FunctionAlias.JavaMethod m)

Implements java.lang.Comparable.compareTo.

Doc from java.lang.Comparable.compareTo.

Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

The implementor must ensure signum(x.compareTo(y)) == -signum(y.compareTo(x)) for all x and y. (This implies that x.compareTo(y) must throw an exception if and only if y.compareTo(x) throws an exception.)

The implementor must also ensure that the relation is transitive: (x.compareTo(y) > 0 && y.compareTo(z) > 0) implies x.compareTo(z) > 0.

Finally, the implementor must ensure that x.compareTo(y)==0 implies that signum(x.compareTo(z)) == signum(y.compareTo(z)), for all z.

Parameters
m:FunctionAlias.JavaMethod

the object to be compared.

Returns:int

a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

Annotations
@Override
executeback to summary
private Object execute(SessionLocal session, Expression[] args, boolean columnList)
getColumnClassesback to summary
public Class<?>[] getColumnClasses()
getDataTypeback to summary
public TypeInfo getDataType()

Returns data type information for regular functions or null for table value functions.

Returns:TypeInfo

data type information for regular functions or null for table value functions

getParameterCountback to summary
public int getParameterCount()
getTableValueback to summary
public ResultInterface getTableValue(SessionLocal session, Expression[] args, boolean columnList)

Call the table user-defined function and return the value.

Parameters
session:SessionLocal

the session

args:Expression[]

the argument list

columnList:boolean

true if the function should only return the column list

Returns:ResultInterface

the value

getValueback to summary
public Value getValue(SessionLocal session, Expression[] args, boolean columnList)

Call the user-defined function and return the value.

Parameters
session:SessionLocal

the session

args:Expression[]

the argument list

columnList:boolean

true if the function should only return the column list

Returns:Value

the value

hasConnectionParamback to summary
public boolean hasConnectionParam()

Check if this function requires a database connection.

Returns:boolean

if the function requires a connection

isVarArgsback to summary
public boolean isVarArgs()
resultSetToResultback to summary
public static ResultInterface resultSetToResult(SessionLocal session, ResultSet resultSet, int maxrows)

Create a result for the given result set.

Parameters
session:SessionLocal

the session

resultSet:ResultSet

the result set

maxrows:int

the maximum number of rows to read (0 to just read the meta data)

Returns:ResultInterface

the value

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override