File D:\maven-qcr-plugin-testsunitaires\qcr4java\h2-1.3.170-sources\target\site\qc\lecode\engine\UserAggregate.java.html

1 /*
2 * Copyright 2004-2011 H2 Group. Multiple-Licensed under the H2 License,
3 * Version 1.0, and under the Eclipse Public License, Version 1.0
4 * (http://h2database.com/html/license.html).
5 * Initial Developer: H2 Group
6 */
7 package org.h2.engine;
8
9 import org.h2.api.AggregateFunction;
10 import org.h2.command.Parser;
11 import org.h2.message.DbException;
12 import org.h2.message.Trace;
13 import org.h2.table.Table;
14 import org.h2.util.Utils;
15
16 /**
17 * Represents a user-defined aggregate function.
18 */
19 public class UserAggregate extends DbObjectBase {
20
21 private String className;
22 private Class<?> javaClass;
23
24 public UserAggregate(Database db, int id, String name, String className, boolean force) {
25 initDbObjectBase(db, id, name, Trace.FUNCTION);
26 this.className = className;
27 if (!force) {
28 getInstance();
29 }
30 }
31
32 public AggregateFunction getInstance() {
33 if (javaClass == null) {
34 javaClass = Utils.loadUserClass(className);
35 }
36 Object obj;
37 try {
38 obj = javaClass.newInstance();
39 AggregateFunction agg = (AggregateFunction) obj;
40 return agg;
41 } catch (Exception e) {
42 throw DbException.convert(e);
43 }
44 }
45
46 public String getCreateSQLForCopy(Table table, String quotedName) {
47 throw DbException.throwInternalError();
48 }
49
50 public String getDropSQL() {
51 return "DROP AGGREGATE IF EXISTS " + getSQL();
52 }
53
54 public String getCreateSQL() {
55 return "CREATE FORCE AGGREGATE " + getSQL() + " FOR " + Parser.quoteIdentifier(className);
56 }
57
58 public int getType() {
59 return DbObject.AGGREGATE;
60 }
61
62 public synchronized void removeChildrenAndResources(Session session) {
63 database.removeMeta(session, getId());
64 className = null;
65 javaClass = null;
66 invalidate();
67 }
68
69 public void checkRename() {
70 throw DbException.getUnsupportedException("AGGREGATE");
71 }
72
73 public String getJavaClassName() {
74 return this.className;
75 }
76
77 }
78