View Javadoc

1   package org.modeshape.sequencer.ddl;
2   
3   import java.util.Arrays;
4   import java.util.List;
5   import org.modeshape.graph.property.Name;
6   
7   public interface DdlConstants {
8   
9       public static final long KILO = 1024;
10      public static final long MEGA = KILO * 1024;
11      public static final long GIGA = MEGA * 1024;
12  
13      public static final String DEFAULT_TERMINATOR = ";";
14  
15      /*
16       * Character Strings
17       */
18      public static final String SPACE = " ";
19      public static final String PERIOD = ".";
20      public static final String COMMA = ",";
21      public static final String SEMICOLON = ";";
22      public static final String L_PAREN = "(";
23      public static final String R_PAREN = ")";
24      public static final String L_SQUOTE = "’";
25  
26      /*
27       * Table Constraint ID's
28       */
29      public static final int CONSTRAINT_UC = 0;
30      public static final int CONSTRAINT_FK = 1;
31      public static final int CONSTRAINT_PK = 2;
32      public static final int CONSTRAINT_C = 3;
33  
34      public static final String PRIMARY_KEY = "PRIMARY KEY";
35      public static final String FOREIGN_KEY = "FOREIGN KEY";
36  
37      /*
38       * Common DDL Keywords
39       */
40      public static final String ALTER = "ALTER";
41      public static final String CHECK = "CHECK";
42      public static final String COLUMN = "COLUMN";
43      public static final String CONSTRAINT = "CONSTRAINT";
44      public static final String CREATE = "CREATE";
45      public static final String DECLARE = "DECLARE";
46      public static final String DROP = "DROP";
47      public static final String FOREIGN = "FOREIGN";
48      public static final String GRANT = "GRANT";
49      public static final String REVOKE = "REVOKE";
50      public static final String INDEX = "INDEX";
51      public static final String INSERT = "INSERT";
52      public static final String UPDATE = "UPDATE";
53      public static final String DELETE = "DELETE";
54      public static final String SELECT = "SELECT";
55      public static final String KEY = "KEY";
56      public static final String OFF = "OFF";
57      public static final String ON = "ON";
58      public static final String PRIMARY = "PRIMARY";
59      public static final String SCHEMA = "SCHEMA";
60      public static final String SET = "SET";
61      public static final String TABLE = "TABLE";
62      public static final String UNIQUE = "UNIQUE";
63      public static final String VIEW = "VIEW";
64  
65      /*
66       * Default Value ID's
67       */
68      public static final int DEFAULT_ID_UNDEFINED = -1;
69      public static final int DEFAULT_ID_LITERAL = 0;
70      public static final int DEFAULT_ID_DATETIME = 1;
71      public static final int DEFAULT_ID_USER = 2;
72      public static final int DEFAULT_ID_CURRENT_USER = 3;
73      public static final int DEFAULT_ID_SESSION_USER = 4;
74      public static final int DEFAULT_ID_SYSTEM_USER = 5;
75      public static final int DEFAULT_ID_NULL = 6;
76  
77      public static final String MISSING_TERMINATOR_NODE_LITERAL = "missingTerminator";
78  
79      interface DropBehavior {
80          public static final String CASCADE = "CASCADE";
81          public static final String RESTRICT = "RESTRICT";
82      }
83  
84      interface MatchType {
85          public static final String FULL = "FULL";
86          public static final String PARTIAL = "PARTIAL";
87      }
88  
89      interface ReferencialAction {
90          public static final String CASCADE = "CASCADE";
91          public static final String SET_NULL = "SET NULL";
92          public static final String SET_DEFAULT = "SET DEFAULT";
93          public static final String NO_ACTION = "NO ACTION";
94      }
95  
96      // Basic SQL 92 statement start phrases
97      interface StatementStartPhrases {
98          public static final String[] STMT_CREATE_SCHEMA = {CREATE, SCHEMA};
99          public static final String[] STMT_CREATE_TABLE = {CREATE, TABLE}; // { GLOBAL | LOCAL } TEMPORARY ] TABLE
100         public static final String[] STMT_CREATE_GLOBAL_TEMPORARY_TABLE = {CREATE, "GLOBAL", "TEMPORARY", TABLE};
101         public static final String[] STMT_CREATE_LOCAL_TEMPORARY_TABLE = {CREATE, "LOCAL", "TEMPORARY", TABLE};
102         public static final String[] STMT_CREATE_VIEW = {CREATE, VIEW};
103         public static final String[] STMT_CREATE_OR_REPLACE_VIEW = {CREATE, "OR", "REPLACE", VIEW};
104         public static final String[] STMT_CREATE_ASSERTION = {CREATE, "ASSERTION"};
105         public static final String[] STMT_CREATE_CHARACTER_SET = {CREATE, "CHARACTER", SET};
106         public static final String[] STMT_CREATE_COLLATION = {CREATE, "COLLATION"};
107         public static final String[] STMT_CREATE_DOMAIN = {CREATE, "DOMAIN"};
108         public static final String[] STMT_CREATE_TRANSLATION = {CREATE, "TRANSLATION"};
109         public static final String[] STMT_ALTER_TABLE = {ALTER, TABLE};
110         public static final String[] STMT_ALTER_DOMAIN = {ALTER, "DOMAIN"};
111         public static final String[] STMT_GRANT = {GRANT};
112         public static final String[] STMT_REVOKE = {REVOKE};
113         public static final String[] STMT_DROP_SCHEMA = {DROP, SCHEMA};
114         public static final String[] STMT_DROP_TABLE = {DROP, TABLE};
115         public static final String[] STMT_DROP_VIEW = {DROP, VIEW};
116         public static final String[] STMT_DROP_DOMAIN = {DROP, "DOMAIN"};
117         public static final String[] STMT_DROP_CHARACTER_SET = {DROP, "CHARACTER", SET};
118         public static final String[] STMT_DROP_COLLATION = {DROP, "COLLATION"};
119         public static final String[] STMT_DROP_TRANSLATION = {DROP, "TRANSLATION"};
120         public static final String[] STMT_DROP_ASSERTION = {DROP, "ASSERTION"};
121         public static final String[] STMT_INSERT_INTO = {"INSERT", "INTO"};
122         public static final String[] STMT_SET_DEFINE = {"SET", "DEFINE"};
123 
124         public final static String[][] SQL_92_ALL_PHRASES = {STMT_CREATE_SCHEMA, STMT_CREATE_TABLE,
125             STMT_CREATE_GLOBAL_TEMPORARY_TABLE, STMT_CREATE_LOCAL_TEMPORARY_TABLE, STMT_CREATE_VIEW, STMT_CREATE_OR_REPLACE_VIEW,
126             STMT_CREATE_ASSERTION, STMT_CREATE_CHARACTER_SET, STMT_CREATE_COLLATION, STMT_CREATE_TRANSLATION, STMT_CREATE_DOMAIN,
127             STMT_ALTER_TABLE, STMT_ALTER_DOMAIN, STMT_GRANT, STMT_REVOKE, STMT_DROP_SCHEMA, STMT_DROP_TABLE, STMT_DROP_VIEW,
128             STMT_DROP_DOMAIN, STMT_DROP_CHARACTER_SET, STMT_DROP_COLLATION, STMT_DROP_TRANSLATION, STMT_DROP_ASSERTION,
129             STMT_INSERT_INTO, STMT_SET_DEFINE};
130 
131         // <schema definition>
132         // | <table definition>
133         // | <view definition>
134         // | <grant statement>
135         // | <domain definition>
136         // | <character set definition>
137         // | <collation definition>
138         // | <translation definition>
139         // | <assertion definition>
140         public final static Name[] VALID_SCHEMA_CHILD_TYPES = {StandardDdlLexicon.TYPE_CREATE_TABLE_STATEMENT,
141             StandardDdlLexicon.TYPE_CREATE_VIEW_STATEMENT, StandardDdlLexicon.TYPE_GRANT_ON_TABLE_STATEMENT,
142             StandardDdlLexicon.TYPE_GRANT_ON_DOMAIN_STATEMENT, StandardDdlLexicon.TYPE_GRANT_ON_TRANSLATION_STATEMENT,
143             StandardDdlLexicon.TYPE_GRANT_ON_COLLATION_STATEMENT, StandardDdlLexicon.TYPE_GRANT_ON_CHARACTER_SET_STATEMENT,
144             StandardDdlLexicon.TYPE_CREATE_DOMAIN_STATEMENT, StandardDdlLexicon.TYPE_CREATE_CHARACTER_SET_STATEMENT,
145             StandardDdlLexicon.TYPE_CREATE_COLLATION_STATEMENT, StandardDdlLexicon.TYPE_CREATE_TRANSLATION_STATEMENT,
146             StandardDdlLexicon.TYPE_CREATE_ASSERTION_STATEMENT};
147     }
148 
149     /**
150      * Constants related to Data Types
151      */
152     interface DataTypes {
153         public static final int DTYPE_CODE_ANY = -1;
154         public static final int DTYPE_CODE_CHAR_STRING = 0;
155         public static final int DTYPE_CODE_NCHAR_STRING = 1;
156         public static final int DTYPE_CODE_BIT_STRING = 2;
157         public static final int DTYPE_CODE_EXACT_NUMERIC = 3;
158         public static final int DTYPE_CODE_APROX_NUMERIC = 4;
159         public static final int DTYPE_CODE_DATE_TIME = 5;
160         public static final int DTYPE_CODE_MISC = 6;
161         public static final int DTYPE_CODE_CUSTOM = 7;
162 
163         // CHAR
164         public static final String[] DTYPE_CHARACTER = {"CHARACTER"};
165         public static final String[] DTYPE_CHAR = {"CHAR"};
166         public static final String[] DTYPE_CHARACTER_VARYING = {"CHARACTER", "VARYING"};
167         public static final String[] DTYPE_CHAR_VARYING = {"CHAR", "VARYING"};
168         public static final String[] DTYPE_VARCHAR = {"VARCHAR"};
169         // NATIONAL CHAR
170         public static final String[] DTYPE_NATIONAL_CHARACTER = {"NATIONAL", "CHARACTER"};
171         public static final String[] DTYPE_NATIONAL_CHAR = {"NATIONAL", "CHAR"};
172         public static final String[] DTYPE_NATIONAL_CHARACTER_VARYING = {"NATIONAL", "CHARACTER", "VARYING"};
173         public static final String[] DTYPE_NATIONAL_CHAR_VARYING = {"NATIONAL", "CHAR", "VARYING"};
174         public static final String[] DTYPE_NCHAR_VARYING = {"NCHAR", "VARYING"};
175         public static final String[] DTYPE_NCHAR = {"NCHAR"};
176         // BIT STRING
177         public static final String[] DTYPE_BIT = {"BIT"};
178         public static final String[] DTYPE_BIT_VARYING = {"BIT", "VARYING"};
179         // EXACT NUMERIC
180         public static final String[] DTYPE_NUMERIC = {"NUMERIC"};
181         public static final String[] DTYPE_DEC = {"DEC"};
182         public static final String[] DTYPE_DECIMAL = {"DECIMAL"};
183         public static final String[] DTYPE_INTEGER = {"INTEGER"};
184         public static final String[] DTYPE_INT = {"INT"};
185         public static final String[] DTYPE_SMALLINT = {"SMALLINT"};
186         // APPROXIMATE NUMERIC
187         public static final String[] DTYPE_FLOAT = {"FLOAT"};
188         public static final String[] DTYPE_REAL = {"REAL"};
189         public static final String[] DTYPE_DOUBLE_PRECISION = {"DOUBLE", "PRECISION"};
190         // DATE-TIME
191         public static final String[] DTYPE_DATE = {"DATE"};
192         public static final String[] DTYPE_TIME = {"TIME"};
193         public static final String[] DTYPE_TIMESTAMP = {"TIMESTAMP"};
194         // INTERVAL
195         public static final String[] DTYPE_INTERVAL = {"INTERVAL"};
196 
197         public final static List<String> DATATYPE_START_WORDS = Arrays.asList(new String[] {"CHAR", "CHARACTER", "VARCHAR",
198             "NATIONAL", "NCHAR", "BIT", "NUMERIC", "DEC", "DECIMAL", "INT", "INTEGER", "SMALLINT", "FLOAT", "REAL", "DOUBLE",
199             "DATE", "TIME", "TIMESTAMP", "INTERVAL"});
200     }
201 
202     @SuppressWarnings( "nls" )
203     public final static String[] SQL_92_RESERVED_WORDS = {"ABSOLUTE", "ACTION", "ADD", "ALL", "ALLOCATE", ALTER, "AND", "ANY",
204         "ARE", "AS", "ASC", "ASSERTION", "AT", "AUTHORIZATION", "AVG", "BEGIN", "BETWEEN", "BIT", "BIT_LENGTH", "BOTH", "BY",
205         "CASCADE", "CASCADED", "CASE", "CAST", "CATALOG", "CHAR", "CHARACTER", "CHAR_LENGTH", "CHARACTER_LENGTH", CHECK, "CLOSE",
206         "COALESCE", "COLLATE", "COLLATION", COLUMN, "COMMIT", "CONNECT", "CONNECTION", CONSTRAINT, "CONSTRAINTS", "CONTINUE",
207         "CONVERT", "CORRESPONDING", "COUNT", CREATE, "CROSS", "CURRENT", "CURRENT_DATE", "CURRENT_TIME", "CURRENT_TIMESTAMP",
208         "CURRENT_USER", "CURSOR", "DATE", "DAY", "DEALLOCATE", "DEC", "DECIMAL", DECLARE, "DEFAULT", "DEFERRABLE", "DEFERRED",
209         "DELETE", "DESC", "DESCRIBE", "DESCRIPTOR", "DIAGNOSTICS", "DISCONNECT", "DISTINCT", "DOMAIN", "DOUBLE", DROP, "ELSE",
210         "END", "END_EXEC", "ESCAPE", "EXCEPT", "EXCEPTION", "EXEC", "EXECUTE", "EXISTS", "EXTERNAL", "EXTRACT", "FALSE", "FETCH",
211         "FIRST", "FLOAT", "FOR", FOREIGN, "FOUND", "FROM", "FULL", "GET", "GLOBAL", "GO", "GOTO", GRANT, "GROUP", "HAVING",
212         "HOUR", "IDENTITY", "IMMEDIATE", "IN", "INDICATOR", "INITIALLY", "INNER", "INPUT", "INSENSITIVE", INSERT, "INT",
213         "INTEGER", "INTERSECT", "INTERVAL", "INTO", "IS", "ISOLATION", "JOIN", KEY, "LANGUAGE", "LAST", "LEADING", "LEFT",
214         "LEVEL", "LIKE", "LOCAL", "LOWER", "MATCH", "MAX", "MIN", "MINUTE", "MODULE", "MONTH", "NAMES", "NATIONAL", "NATURAL",
215         "NCHAR", "NEXT", "NO", "NOT", "NULL", "NULLIF", "NUMERIC", "OCTET_LENGTH", "OF", ON, "ONLY", "OPEN", "OPTION", "OR",
216         "ORDER", "OUTER", "OUTPUT", "OVERLAPS", "PAD", "PARTIAL", "POSITION", "PRECISION", "PREPARE", "PRESERVE", PRIMARY,
217         "PRIOR", "PRIVILEGES", "PROCEDURE", "PUBLIC", "READ", "REAL", "REFERENCES", "RELATIVE", "RESTRICT", "REVOKE", "RIGHT",
218         "ROLLBACK", "ROWS", SCHEMA, "SCROLL", "SECOND", "SECTION", "SELECT", "SESSION", "SESSION_USER", SET, "SIZE", "SMALLINT",
219         "SOME", "SPACE", "SQL", "SQLCODE", "SQLERROR", "SQLSTATE", "SUBSTRING", "SUM", "SYSTEM_USER", TABLE, "TEMPORARY", "THEN",
220         "TIME", "TIMESTAMP", "TIMEZONE_HOUR", "TIMEZONE_MINUTE", "TO", "TRAILING", "TRANSACTION", "TRANSLATE", "TRANSLATION",
221         "TRIM", "TRUE", "UNION", UNIQUE, "UNKNOWN", "UPDATE", "UPPER", "USAGE", "USER", "USING", "VALUE", "VALUES", "VARCHAR",
222         "VARYING", VIEW, "WHEN", "WHENEVER", "WHERE", "WITH", "WORK", "WRITE", "YEAR", "ZONE"};
223 
224     interface Problems {
225         public static final int OK = 0;
226         public static final int WARNING = 1;
227         public static final int ERROR = 2;
228     }
229 
230     interface AstNodeNames {
231         public static final String TABLE_DEFINITION = "TABLE_DEFINITION";
232         public static final String ALTER_TABLE_DEFINITION = "ALTER_TABLE_DEFINITION";
233         public static final String COLUMN_DEFINITION = "COLUMN_DEFINITION";
234         public static final String COLUMN_REFERENCE = "COLUMN_REFERENCE";
235         public static final String TABLE_CONSTRAINT = "TABLE_CONSTRAINT";
236         // public static final String TABLE_OPTION = "TABLE_OPTION";
237         public static final String ADD_COLUMN_DEFINITION = "ADD_COLUMN_DEFINITION";
238         public static final String ADD_TABLE_CONSTRAINT = "ADD_TABLE_CONSTRAINT";
239         public static final String DROP_COLUMN_DEFINITION = "DROP_COLUMN_DEFINITION";
240         public static final String DROP_TABLE_CONSTRAINT = "DROP_TABLE_CONSTRAINT";
241         public static final String ALTER_COLUMN_DEFINITION = "ALTER_COLUMN_DEFINITION";
242 
243     }
244 }