Debian Codegraph @

src/main/org/h2/schema/Constant.java

raw
1 /*
2 * Copyright 2004-2023 H2 Group. Multiple-Licensed under the MPL 2.0,
3 * and the EPL 1.0 (https://h2database.com/html/license.html).
4 * Initial Developer: H2 Group
5 */
6 package org.h2.schema;
7
8 import org.h2.engine.DbObject;
9 import org.h2.engine.SessionLocal;
10 import org.h2.expression.ValueExpression;
11 import org.h2.message.Trace;
12 import org.h2.value.Value;
13
14 /**
15 * A user-defined constant as created by the SQL statement
16 * CREATE CONSTANT
17 */
18 public final class Constant extends SchemaObject {
19
20 private Value value;
21 private ValueExpression expression;
22
23 public Constant(Schema schema, int id, String name) {
24 super(schema, id, name, Trace.SCHEMA);
25 }
26
27 @Override
28 public String getCreateSQL() {
29 StringBuilder builder = new StringBuilder("CREATE CONSTANT ");
30 getSQL(builder, DEFAULT_SQL_FLAGS).append(" VALUE ");
31 return value.getSQL(builder, DEFAULT_SQL_FLAGS).toString();
32 }
33
34 @Override
35 public int getType() {
36 return DbObject.CONSTANT;
37 }
38
39 @Override
40 public void removeChildrenAndResources(SessionLocal session) {
41 database.removeMeta(session, getId());
42 invalidate();
43 }
44
45 public void setValue(Value value) {
46 this.value = value;
47 expression = ValueExpression.get(value);
48 }
49
50 public ValueExpression getValue() {
51 return expression;
52 }
53
54 }