org.h2.test.db
Class TestFunctions

java.lang.Object
  extended by org.h2.test.TestBase
      extended by org.h2.test.db.TestFunctions
All Implemented Interfaces:
AggregateFunction

public class TestFunctions
extends TestBase
implements AggregateFunction

Tests for user defined functions and aggregates.


Nested Class Summary
static class TestFunctions.MedianString
          This median implementation keeps all objects in memory.
 
Field Summary
 
Fields inherited from class org.h2.test.TestBase
BASE_TEST_DIR, config, start, TEMP_DIR, uniqueId
 
Constructor Summary
TestFunctions()
           
 
Method Summary
 void add(java.lang.Object value)
          This method is called once for each row.
static int addRow(java.sql.Connection conn, int id, java.lang.String name)
          This method is called via reflection from the database.
static java.sql.Blob blob(java.sql.Blob value)
          This method is called via reflection from the database.
static java.io.BufferedInputStream blob2stream(java.sql.Blob value)
          This method is called via reflection from the database.
static java.sql.Clob clob(java.sql.Clob value)
          This method is called via reflection from the database.
static java.lang.Object[] dynamic(java.lang.Object[] args)
          This method is called via reflection from the database.
static java.lang.Object[] getArray()
          This method is called via reflection from the database.
static int getCount()
          This method is called via reflection from the database.
 java.lang.Object getResult()
          This method returns the computed aggregate value.
 int getType(int[] inputTypes)
          This method must return the SQL type of the method, given the SQL type of the input data.
 void init(java.sql.Connection conn)
          This method is called when the aggregate function is used.
static void main(java.lang.String... a)
          Run just this test.
static double mean()
          This method is called via reflection from the database.
static double mean(double... values)
          This method is called via reflection from the database.
static double mean2(java.sql.Connection conn, double... values)
          This method is called via reflection from the database.
static java.math.BigDecimal noOp(java.math.BigDecimal dec)
          This method is called via reflection from the database.
static java.sql.ResultSet nullResultSet(java.sql.Connection conn)
          This method is called via reflection from the database.
static java.lang.String printMean(java.lang.String prefix, double... values)
          This method is called via reflection from the database.
static java.sql.ResultSet resultSetWithNull(java.sql.Connection conn)
          This method is called via reflection from the database.
static java.lang.String reverse(java.lang.String s)
          This method is called via reflection from the database.
static int root(int value)
          This method is called via reflection from the database.
static java.sql.ResultSet select(java.sql.Connection conn, java.lang.String sql)
          This method is called via reflection from the database.
static java.sql.ResultSet selectMaxId(java.sql.Connection conn)
          This method is called via reflection from the database.
static java.sql.ResultSet simpleFunctionTable(java.sql.Connection conn)
          This method is called via reflection from the database.
static java.sql.ResultSet simpleResultSet(java.lang.Integer rowCount, int ip, boolean bp, float fp, double dp, long lp, byte byParam, short sp)
          Test method to create a simple result set.
static java.io.BufferedInputStream stream2stream(java.io.InputStream value)
          This method is called via reflection from the database.
 void test()
          This method will be called by the test framework.
static void testDefaultConn()
          This method is called via reflection from the database.
static Value toChar(Value... args)
          This method is called via reflection from the database.
static java.util.UUID xorUUID(java.util.UUID a, java.util.UUID b)
          This method is called via reflection from the database.
 
Methods inherited from class org.h2.test.TestBase
assertContains, assertEqualDatabases, assertEqualReaders, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEqualStreams, assertFalse, assertFalse, assertKnownException, assertKnownException, assertNull, assertResult, assertResultRowCount, assertResultSetMeta, assertResultSetOrdered, assertSingleValue, assertSmaller, assertStartsWith, assertThrows, assertThrows, assertThrows, assertTrue, assertTrue, crash, createCaller, createCaller, createClassProxy, deleteDb, deleteDb, eatMemory, fail, fail, freeMemory, getBaseDir, getClassPath, getConnection, getConnection, getFilePassword, getMemoryUsed, getPassword, getPassword, getSize, getTestDir, getURL, getUser, init, init, logError, println, printTime, printTimeMemory, readString, runTest, startServerIfRequired, testCase, trace, trace, traceMemory
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TestFunctions

public TestFunctions()
Method Detail

main

public static void main(java.lang.String... a)
                 throws java.lang.Exception
Run just this test.

Parameters:
a - ignored
Throws:
java.lang.Exception

test

public void test()
          throws java.lang.Exception
Description copied from class: TestBase
This method will be called by the test framework.

Specified by:
test in class TestBase
Throws:
java.lang.Exception - if an exception in the test occurs

simpleFunctionTable

public static java.sql.ResultSet simpleFunctionTable(java.sql.Connection conn)
This method is called via reflection from the database.

Parameters:
conn - the connection
Returns:
a result set

toChar

public static Value toChar(Value... args)
This method is called via reflection from the database.

Parameters:
args - the argument list
Returns:
the value

testDefaultConn

public static void testDefaultConn()
                            throws java.sql.SQLException
This method is called via reflection from the database.

Throws:
java.sql.SQLException

blob2stream

public static java.io.BufferedInputStream blob2stream(java.sql.Blob value)
                                               throws java.sql.SQLException
This method is called via reflection from the database.

Parameters:
value - the blob
Returns:
the input stream
Throws:
java.sql.SQLException

blob

public static java.sql.Blob blob(java.sql.Blob value)
This method is called via reflection from the database.

Parameters:
value - the blob
Returns:
the blob

clob

public static java.sql.Clob clob(java.sql.Clob value)
This method is called via reflection from the database.

Parameters:
value - the blob
Returns:
the blob

stream2stream

public static java.io.BufferedInputStream stream2stream(java.io.InputStream value)
This method is called via reflection from the database.

Parameters:
value - the input stream
Returns:
the buffered input stream

addRow

public static int addRow(java.sql.Connection conn,
                         int id,
                         java.lang.String name)
                  throws java.sql.SQLException
This method is called via reflection from the database.

Parameters:
conn - the connection
id - the test id
name - the text
Returns:
the count
Throws:
java.sql.SQLException

select

public static java.sql.ResultSet select(java.sql.Connection conn,
                                        java.lang.String sql)
                                 throws java.sql.SQLException
This method is called via reflection from the database.

Parameters:
conn - the connection
sql - the SQL statement
Returns:
the result set
Throws:
java.sql.SQLException

selectMaxId

public static java.sql.ResultSet selectMaxId(java.sql.Connection conn)
                                      throws java.sql.SQLException
This method is called via reflection from the database.

Parameters:
conn - the connection
Returns:
the result set
Throws:
java.sql.SQLException

getArray

public static java.lang.Object[] getArray()
This method is called via reflection from the database.

Returns:
the test array

resultSetWithNull

public static java.sql.ResultSet resultSetWithNull(java.sql.Connection conn)
                                            throws java.sql.SQLException
This method is called via reflection from the database.

Parameters:
conn - the connection
Returns:
the result set
Throws:
java.sql.SQLException

nullResultSet

public static java.sql.ResultSet nullResultSet(java.sql.Connection conn)
This method is called via reflection from the database.

Parameters:
conn - the connection
Returns:
the result set

simpleResultSet

public static java.sql.ResultSet simpleResultSet(java.lang.Integer rowCount,
                                                 int ip,
                                                 boolean bp,
                                                 float fp,
                                                 double dp,
                                                 long lp,
                                                 byte byParam,
                                                 short sp)
Test method to create a simple result set.

Parameters:
rowCount - the number of rows
ip - an int
bp - a boolean
fp - a float
dp - a double
lp - a long
byParam - a byte
sp - a short
Returns:
a result set

root

public static int root(int value)
This method is called via reflection from the database.

Parameters:
value - the value
Returns:
the square root

mean

public static double mean()
This method is called via reflection from the database.

Returns:
1

noOp

public static java.math.BigDecimal noOp(java.math.BigDecimal dec)
This method is called via reflection from the database.

Parameters:
dec - the value
Returns:
the value

getCount

public static int getCount()
This method is called via reflection from the database.

Returns:
the count

reverse

public static java.lang.String reverse(java.lang.String s)
This method is called via reflection from the database.

Parameters:
s - the string
Returns:
the string, reversed

mean

public static double mean(double... values)
This method is called via reflection from the database.

Parameters:
values - the values
Returns:
the mean value

mean2

public static double mean2(java.sql.Connection conn,
                           double... values)
This method is called via reflection from the database.

Parameters:
conn - the connection
values - the values
Returns:
the mean value

printMean

public static java.lang.String printMean(java.lang.String prefix,
                                         double... values)
This method is called via reflection from the database.

Parameters:
prefix - the print prefix
values - the values
Returns:
the text

xorUUID

public static java.util.UUID xorUUID(java.util.UUID a,
                                     java.util.UUID b)
This method is called via reflection from the database.

Parameters:
a - the first UUID
b - the second UUID
Returns:
a xor b

dynamic

public static java.lang.Object[] dynamic(java.lang.Object[] args)
This method is called via reflection from the database.

Parameters:
args - the argument list
Returns:
an array of one element

add

public void add(java.lang.Object value)
Description copied from interface: AggregateFunction
This method is called once for each row. If the aggregate function is called with multiple parameters, those are passed as array.

Specified by:
add in interface AggregateFunction
Parameters:
value - the value(s) for this row

getResult

public java.lang.Object getResult()
Description copied from interface: AggregateFunction
This method returns the computed aggregate value.

Specified by:
getResult in interface AggregateFunction
Returns:
the aggregated value

getType

public int getType(int[] inputTypes)
Description copied from interface: AggregateFunction
This method must return the SQL type of the method, given the SQL type of the input data. The method should check here if the number of parameters passed is correct, and if not it should throw an exception.

Specified by:
getType in interface AggregateFunction
Parameters:
inputTypes - the SQL type of the parameters
Returns:
the SQL type of the result

init

public void init(java.sql.Connection conn)
Description copied from interface: AggregateFunction
This method is called when the aggregate function is used. A new object is created for each invocation.

Specified by:
init in interface AggregateFunction
Parameters:
conn - a connection to the database