Class TestFunctions

  • All Implemented Interfaces:
    AggregateFunction

    public class TestFunctions
    extends org.h2.test.TestDb
    implements AggregateFunction
    Tests for user defined functions and aggregates.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  TestFunctions.MedianString
      This median implementation keeps all objects in memory.
      static class  TestFunctions.MedianStringType
      This median implementation keeps all objects in memory.
      • Nested classes/interfaces inherited from class org.h2.test.TestDb

        org.h2.test.TestDb.Child
      • Nested classes/interfaces inherited from class org.h2.test.TestBase

        org.h2.test.TestBase.VoidCallable
    • Field Summary

      • Fields inherited from class org.h2.test.TestBase

        BASE_TEST_DIR, config, start, uniqueId
    • Constructor Summary

      Constructors 
      Constructor Description
      TestFunctions()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      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.lang.Integer[][] arrayParameters1​(java.lang.String[][] x)
      This method is called with reflection.
      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 long currentTimestampOverride()
      This method is called via reflection from the database.
      static java.lang.String[] dynamic​(java.lang.String[] args)
      This method is called via reflection from the database.
      static java.sql.ResultSet functionTableWithParameter​(java.sql.Connection conn, int p)
      This method is called via reflection from the database.
      static java.lang.String[] 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.
      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.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.sql.ResultSet varArgsFunctionTable​(int... values)
      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.TestDb

        buildChild, deleteDb, deleteDb, getConnection, getConnection, getURL
      • Methods inherited from class org.h2.test.TestBase

        assertContains, assertEmpty, assertEqualDatabases, assertEqualReaders, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEqualStreams, assertFalse, assertFalse, assertKnownException, assertKnownException, assertNotContaining, assertNotNull, assertNotNull, assertNull, assertResult, assertResultRowCount, assertResultSetMeta, assertResultSetOrdered, assertResultSetOrdered, assertSame, assertSingleValue, assertSmaller, assertStartsWith, assertThrows, assertThrows, assertThrows, assertThrows, assertThrows, assertThrows, assertThrows, assertThrows, assertTrue, assertTrue, checkErrorCode, crash, createCaller, createFailingStream, eatMemory, execute, execute, fail, fail, freeMemory, getBaseDir, getClassPath, getFilePassword, getJVM, getMemoryUsed, getMemoryUsedBytes, getPassword, getPassword, getPowerOffCount, getSize, getTestDir, getTestName, getUser, init, init, isEnabled, logError, logErrorMessage, println, printTime, printTimeMemory, readString, runTest, setPowerOffCount, testFromMain, throwException, 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: org.h2.test.TestBase
        This method will be called by the test framework.
        Specified by:
        test in class org.h2.test.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
      • functionTableWithParameter

        public static java.sql.ResultSet functionTableWithParameter​(java.sql.Connection conn,
                                                                    int p)
        This method is called via reflection from the database.
        Parameters:
        conn - the connection
        p - the parameter
        Returns:
        a result set
      • varArgsFunctionTable

        public static java.sql.ResultSet varArgsFunctionTable​(int... values)
                                                       throws java.sql.SQLException
        This method is called via reflection from the database.
        Parameters:
        values - the value array
        Returns:
        a result set
        Throws:
        java.sql.SQLException
      • 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
      • arrayParameters1

        public static java.lang.Integer[][] arrayParameters1​(java.lang.String[][] x)
        This method is called with reflection.
        Parameters:
        x - argument
        Returns:
        result
      • 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.String[] 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
      • 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.String[] dynamic​(java.lang.String[] args)
        This method is called via reflection from the database.
        Parameters:
        args - the argument list
        Returns:
        an array of one element
      • currentTimestampOverride

        public static long currentTimestampOverride()
        This method is called via reflection from the database.
        Returns:
        a fixed number
      • 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. This method must preserve previously added values and must be able to reevaluate result if more values were added since its previous invocation.
        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, Types
        Returns:
        the SQL type of the result