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.schema;
07:
08: import java.sql.SQLException;
09:
10: import org.h2.engine.DbObject;
11: import org.h2.engine.Session;
12: import org.h2.expression.ValueExpression;
13: import org.h2.message.Message;
14: import org.h2.message.Trace;
15: import org.h2.table.Table;
16: import org.h2.value.Value;
17:
18: /**
19: * A user defined constant as created by the SQL statement
20: * CREATE CONSTANT
21: */
22: public class Constant extends SchemaObjectBase {
23:
24: private Value value;
25: private ValueExpression expression;
26:
27: public Constant(Schema schema, int id, String name) {
28: super (schema, id, name, Trace.SCHEMA);
29: }
30:
31: public String getCreateSQLForCopy(Table table, String quotedName) {
32: throw Message.getInternalError();
33: }
34:
35: public String getDropSQL() {
36: return null;
37: }
38:
39: public String getCreateSQL() {
40: StringBuffer buff = new StringBuffer();
41: buff.append("CREATE CONSTANT ");
42: buff.append(getSQL());
43: buff.append(" VALUE ");
44: buff.append(value.getSQL());
45: return buff.toString();
46: }
47:
48: public int getType() {
49: return DbObject.CONSTANT;
50: }
51:
52: public void removeChildrenAndResources(Session session)
53: throws SQLException {
54: database.removeMeta(session, getId());
55: invalidate();
56: }
57:
58: public void checkRename() throws SQLException {
59: }
60:
61: public void setValue(Value value) {
62: this .value = value;
63: expression = ValueExpression.get(value);
64: }
65:
66: public ValueExpression getValue() {
67: return expression;
68: }
69:
70: }
|