01: /*
02: * Copyright 2004-2008 H2 Group. Licensed under the H2 License, Version 1.0
03: * (http://h2database.com/html/license.html).
04: * Initial Developer: H2 Group
05: */
06: package org.h2.api;
07:
08: import java.sql.Connection;
09: import java.sql.SQLException;
10:
11: /**
12: * A user defined aggregate function needs to implement this interface.
13: * The class must be public and must have a public non-argument constructor.
14: */
15: public interface AggregateFunction {
16:
17: /**
18: * This method is called when the aggregate function is used.
19: * A new object is created for each invocation.
20: *
21: * @param conn a connection to the database
22: */
23: void init(Connection conn) throws SQLException;
24:
25: /**
26: * This method must return the SQL type of the method,
27: * given the SQL type of the input data.
28: * The method should check here if the number of parameters passed is correct,
29: * and if not it should throw an exception.
30: *
31: * @param inputType the SQL type of the parameters
32: * @return the SQL type of the result
33: */
34: int getType(int[] inputType) throws SQLException;
35:
36: /**
37: * This method is called once for each row.
38: * If the aggregate function is called with multiple parameters,
39: * those are passed as array.
40: *
41: * @param value the value(s) for this row
42: */
43: void add(Object value) throws SQLException;
44:
45: /**
46: * This method returns the computed aggregate value.
47: *
48: * @return the aggregated value
49: */
50: Object getResult() throws SQLException;
51: }
|