001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.db.api.sql;
043:
044: import java.util.Arrays;
045:
046: /**
047: * An utility class for working with SQL keywords. Currently it provides
048: * the list of reserved and non-reserved SQL-99 keywords.
049: *
050: * @author Andrei Badea
051: *
052: * @since 1.2
053: */
054: public final class SQLKeywords {
055:
056: // the following lists are searched using binary search
057: // so they should be lexicographically sorted
058:
059: // the source of the SQL-99 keyword lists is
060: // the SQL-99 Complete book by Gulutzan and Pelzer
061:
062: /**
063: * The list of SQL-99 reserved keywords. Not private because of the tests.
064: */
065: static final String[] SQL99_RESERVED = { "ABSOLUTE", //NOI18N
066: "ACTION", //NOI18N
067: "ADD", //NOI18N
068: "ADMIN", //NOI18N
069: "AFTER", //NOI18N
070: "AGGREGATE", //NOI18N
071: "ALIAS", //NOI18N
072: "ALL", //NOI18N
073: "ALLOCATE", //NOI18N
074: "ALTER", //NOI18N
075: "AND", //NOI18N
076: "ANY", //NOI18N
077: "ARE", //NOI18N
078: "ARRAY", //NOI18N
079: "AS", //NOI18N
080: "ASC", //NOI18N
081: "ASSERTION", //NOI18N
082: "AT", //NOI18N
083: "AUTHORIZATION", //NOI18N
084: "BEFORE", //NOI18N
085: "BEGIN", //NOI18N
086: "BINARY", //NOI18N
087: "BIT", //NOI18N
088: "BLOB", //NOI18N
089: "BOOLEAN", //NOI18N
090: "BOTH", //NOI18N
091: "BREADTH", //NOI18N
092: "BY", //NOI18N
093: "CALL", //NOI18N
094: "CASCADE", //NOI18N
095: "CASCADED", //NOI18N
096: "CASE", //NOI18N
097: "CAST", //NOI18N
098: "CATALOG", //NOI18N
099: "CHAR", //NOI18N
100: "CHARACTER", //NOI18N
101: "CHECK", //NOI18N
102: "CLASS", //NOI18N
103: "CLOB", //NOI18N
104: "CLOSE", //NOI18N
105: "COLLATE", //NOI18N
106: "COLLATION", //NOI18N
107: "COLUMN", //NOI18N
108: "COMMIT", //NOI18N
109: "COMPLETION", //NOI18N
110: "CONDITION", //NOI18N
111: "CONNECT", //NOI18N
112: "CONNECTION", //NOI18N
113: "CONSTRAINT", //NOI18N
114: "CONSTRAINTS", //NOI18N
115: "CONSTRUCTOR", //NOI18N
116: "CONTAINS", //NOI18N
117: "CONTINUE", //NOI18N
118: "CORRESPONDING", //NOI18N
119: "CREATE", //NOI18N
120: "CROSS", //NOI18N
121: "CUBE", //NOI18N
122: "CURRENT", //NOI18N
123: "CURRENT_DATE", //NOI18N
124: "CURRENT_PATH", //NOI18N
125: "CURRENT_ROLE", //NOI18N
126: "CURRENT_TIME", //NOI18N
127: "CURRENT_TIMESTAMP", //NOI18N
128: "CURRENT_USER", //NOI18N
129: "CURSOR", //NOI18N
130: "CYCLE", //NOI18N
131: "DATA", //NOI18N
132: "DATALINK", //NOI18N
133: "DATE", //NOI18N
134: "DAY", //NOI18N
135: "DEALLOCATE", //NOI18N
136: "DEC", //NOI18N
137: "DECIMAL", //NOI18N
138: "DECLARE", //NOI18N
139: "DEFAULT", //NOI18N
140: "DEFERRABLE", //NOI18N
141: "DEFERRED", //NOI18N
142: "DELETE", //NOI18N
143: "DEPTH", //NOI18N
144: "DEREF", //NOI18N
145: "DESC", //NOI18N
146: "DESCRIBE", //NOI18N
147: "DESCRIPTOR", //NOI18N
148: "DESTROY", //NOI18N
149: "DESTRUCTOR", //NOI18N
150: "DETERMINISTIC", //NOI18N
151: "DIAGNOSTICS", //NOI18N
152: "DICTIONARY", //NOI18N
153: "DISCONNECT", //NOI18N
154: "DISTINCT", //NOI18N
155: "DO", //NOI18N
156: "DOMAIN", //NOI18N
157: "DOUBLE", //NOI18N
158: "DROP", //NOI18N
159: "DYNAMIC", //NOI18N
160: "EACH", //NOI18N
161: "ELSE", //NOI18N
162: "ELSEIF", //NOI18N
163: "END", //NOI18N
164: "END-EXEC", //NOI18N
165: "EQUALS", //NOI18N
166: "ESCAPE", //NOI18N
167: "EVERY", //NOI18N
168: "EXCEPT", //NOI18N
169: "EXCEPTION", //NOI18N
170: "EXEC", //NOI18N
171: "EXECUTE", //NOI18N
172: "EXIT", //NOI18N
173: "EXPAND", //NOI18N
174: "EXPANDING", //NOI18N
175: "EXTERNAL", //NOI18N
176: "FALSE", //NOI18N
177: "FETCH", //NOI18N
178: "FIRST", //NOI18N
179: "FLOAT", //NOI18N
180: "FOR", //NOI18N
181: "FOREIGN", //NOI18N
182: "FOUND", //NOI18N
183: "FREE", //NOI18N
184: "FROM", //NOI18N
185: "FULL", //NOI18N
186: "FUNCTION", //NOI18N
187: "GENERAL", //NOI18N
188: "GET", //NOI18N
189: "GLOBAL", //NOI18N
190: "GO", //NOI18N
191: "GOTO", //NOI18N
192: "GRANT", //NOI18N
193: "GROUP", //NOI18N
194: "GROUPING", //NOI18N
195: "HANDLER", //NOI18N
196: "HASH", //NOI18N
197: "HAVING", //NOI18N
198: "HOST", //NOI18N
199: "HOUR", //NOI18N
200: "IDENTITY", //NOI18N
201: "IF", //NOI18N
202: "IGNORE", //NOI18N
203: "IMMEDIATE", //NOI18N
204: "IN", //NOI18N
205: "INDICATOR", //NOI18N
206: "INITIALIZE", //NOI18N
207: "INITIALLY", //NOI18N
208: "INNER", //NOI18N
209: "INOUT", //NOI18N
210: "INPUT", //NOI18N
211: "INSERT", //NOI18N
212: "INT", //NOI18N
213: "INTEGER", //NOI18N
214: "INTERSECT", //NOI18N
215: "INTERVAL", //NOI18N
216: "INTO", //NOI18N
217: "IS", //NOI18N
218: "ISOLATION", //NOI18N
219: "ITERATE", //NOI18N
220: "JOIN", //NOI18N
221: "KEY", //NOI18N
222: "LANGUAGE", //NOI18N
223: "LARGE", //NOI18N
224: "LAST", //NOI18N
225: "LATERAL", //NOI18N
226: "LEADING", //NOI18N
227: "LEAVE", //NOI18N
228: "LEFT", //NOI18N
229: "LESS", //NOI18N
230: "LEVEL", //NOI18N
231: "LIKE", //NOI18N
232: "LIMIT", //NOI18N
233: "LOCAL", //NOI18N
234: "LOCALTIME", //NOI18N
235: "LOCALTIMESTAMP", //NOI18N
236: "LOCATOR", //NOI18N
237: "LOOP", //NOI18N
238: "MATCH", //NOI18N
239: "MEETS", //NOI18N
240: "MINUTE", //NOI18N
241: "MODIFIES", //NOI18N
242: "MODIFY", //NOI18N
243: "MODULE", //NOI18N
244: "MONTH", //NOI18N
245: "NAMES", //NOI18N
246: "NATIONAL", //NOI18N
247: "NATURAL", //NOI18N
248: "NCHAR", //NOI18N
249: "NCLOB", //NOI18N
250: "NEW", //NOI18N
251: "NEXT", //NOI18N
252: "NO", //NOI18N
253: "NONE", //NOI18N
254: "NORMALIZE", //NOI18N
255: "NOT", //NOI18N
256: "NULL", //NOI18N
257: "NUMERIC", //NOI18N
258: "OBJECT", //NOI18N
259: "OF", //NOI18N
260: "OFF", //NOI18N
261: "OLD", //NOI18N
262: "ON", //NOI18N
263: "ONLY", //NOI18N
264: "OPEN", //NOI18N
265: "OPERATION", //NOI18N
266: "OPTION", //NOI18N
267: "OR", //NOI18N
268: "ORDER", //NOI18N
269: "ORDINALITY", //NOI18N
270: "OUT", //NOI18N
271: "OUTER", //NOI18N
272: "OUTPUT", //NOI18N
273: "PAD", //NOI18N
274: "PARAMETER", //NOI18N
275: "PARAMETERS", //NOI18N
276: "PARTIAL", //NOI18N
277: "PATH", //NOI18N
278: "PERIOD", //NOI18N
279: "POSTFIX", //NOI18N
280: "PRECEDES", //NOI18N
281: "PRECISION", //NOI18N
282: "PREFIX", //NOI18N
283: "PREORDER", //NOI18N
284: "PREPARE", //NOI18N
285: "PRESERVE", //NOI18N
286: "PRIMARY", //NOI18N
287: "PRIOR", //NOI18N
288: "PRIVILEGES", //NOI18N
289: "PROCEDURE", //NOI18N
290: "PUBLIC", //NOI18N
291: "READ", //NOI18N
292: "READS", //NOI18N
293: "REAL", //NOI18N
294: "RECURSIVE", //NOI18N
295: "REDO", //NOI18N
296: "REF", //NOI18N
297: "REFERENCES", //NOI18N
298: "REFERENCING", //NOI18N
299: "RELATIVE", //NOI18N
300: "REPEAT", //NOI18N
301: "RESIGNAL", //NOI18N
302: "RESTRICT", //NOI18N
303: "RESULT", //NOI18N
304: "RETURN", //NOI18N
305: "RETURNS", //NOI18N
306: "REVOKE", //NOI18N
307: "RIGHT", //NOI18N
308: "ROLE", //NOI18N
309: "ROLLBACK", //NOI18N
310: "ROLLUP", //NOI18N
311: "ROUTINE", //NOI18N
312: "ROW", //NOI18N
313: "ROWS", //NOI18N
314: "SAVEPOINT", //NOI18N
315: "SCHEMA", //NOI18N
316: "SCROLL", //NOI18N
317: "SEARCH", //NOI18N
318: "SECOND", //NOI18N
319: "SECTION", //NOI18N
320: "SELECT", //NOI18N
321: "SEQUENCE", //NOI18N
322: "SESSION", //NOI18N
323: "SESSION_USER", //NOI18N
324: "SET", //NOI18N
325: "SETS", //NOI18N
326: "SIGNAL", //NOI18N
327: "SIZE", //NOI18N
328: "SMALLINT", //NOI18N
329: "SOME", //NOI18N
330: "SPACE", //NOI18N
331: "SPECIFIC", //NOI18N
332: "SPECIFICTYPE", //NOI18N
333: "SQL", //NOI18N
334: "SQLEXCEPTION", //NOI18N
335: "SQLSTATE", //NOI18N
336: "SQLWARNING", //NOI18N
337: "START", //NOI18N
338: "STATE", //NOI18N
339: "STATEMENT", //NOI18N
340: "STATIC", //NOI18N
341: "STRUCTURE", //NOI18N
342: "SYSTEM_USER", //NOI18N
343: "TABLE", //NOI18N
344: "TEMPORARY", //NOI18N
345: "TERMINATE", //NOI18N
346: "THAN", //NOI18N
347: "THEN", //NOI18N
348: "TIME", //NOI18N
349: "TIMESTAMP", //NOI18N
350: "TIMEZONE_HOUR", //NOI18N
351: "TIMEZONE_MINUTE", //NOI18N
352: "TO", //NOI18N
353: "TRAILING", //NOI18N
354: "TRANSACTION", //NOI18N
355: "TRANSLATION", //NOI18N
356: "TREAT", //NOI18N
357: "TRIGGER", //NOI18N
358: "TRUE", //NOI18N
359: "UNDER", //NOI18N
360: "UNION", //NOI18N
361: "UNIQUE", //NOI18N
362: "UNKNOWN", //NOI18N
363: "UNTIL", //NOI18N
364: "UPDATE", //NOI18N
365: "USAGE", //NOI18N
366: "USER", //NOI18N
367: "USING", //NOI18N
368: "VALUE", //NOI18N
369: "VALUES", //NOI18N
370: "VARCHAR", //NOI18N
371: "VARIABLE", //NOI18N
372: "VARYING", //NOI18N
373: "VIEW", //NOI18N
374: "WHEN", //NOI18N
375: "WHENEVER", //NOI18N
376: "WHERE", //NOI18N
377: "WHILE", //NOI18N
378: "WITH", //NOI18N
379: "WITHOUT", //NOI18N
380: "WORK", //NOI18N
381: "WRITE", //NOI18N
382: "YEAR", //NOI18N
383: "ZONE", //NOI18N
384: };
385:
386: /**
387: * The list of SQL-99 non-reserved keywords. Not private because of the tests.
388: */
389: static final String[] SQL99_NON_RESERVED = { "ABS", //NOI18N
390: "ADA", //NOI18N
391: "ASENSITIVE", //NOI18N
392: "ASSIGNMENT", //NOI18N
393: "ASYMMETRIC", //NOI18N
394: "ATOMIC", //NOI18N
395: "AVG", //NOI18N
396: "BETWEEN", //NOI18N
397: "BITVAR", //NOI18N
398: "BIT_LENGTH", //NOI18N
399: "BLOCKED", //NOI18N
400: "C", //NOI18N
401: "CARDINALITY", //NOI18N
402: "CATALOG_NAME", //NOI18N
403: "CHAIN", //NOI18N
404: "CHARACTER_LENGTH", //NOI18N
405: "CHARACTER_SET_CATALOG", //NOI18N
406: "CHARACTER_SET_NAME", //NOI18N
407: "CHARACTER_SET_SCHEMA", //NOI18N
408: "CHAR_LENGTH", //NOI18N
409: "CHECKED", //NOI18N
410: "CLASS_ORIGIN", //NOI18N
411: "COALESCE", //NOI18N
412: "COBOL", //NOI18N
413: "COLLATION_CATALOG", //NOI18N
414: "COLLATION_NAME", //NOI18N
415: "COLLATION_SCHEMA", //NOI18N
416: "COLUMN_NAME", //NOI18N
417: "COMMAND_FUNCTION", //NOI18N
418: "COMMAND_FUNCTION_CODE", //NOI18N
419: "COMMITTED", //NOI18N
420: "CONCATENATE", //NOI18N
421: "CONDITION_NUMBER", //NOI18N
422: "CONNECTION_NAME", //NOI18N
423: "CONSTRAINT_CATALOG", //NOI18N
424: "CONSTRAINT_NAME", //NOI18N
425: "CONSTRAINT_SCHEMA", //NOI18N
426: "CONTAINS", //NOI18N
427: "CONTROL", //NOI18N
428: "CONVERT", //NOI18N
429: "COUNT", //NOI18N
430: "CURSOR_NAME", //NOI18N
431: "DATETIME_INTERVAL_CODE", //NOI18N
432: "DATETIME_INTERVAL_PRECISION", //NOI18N
433: "DB", //NOI18N
434: "DISPATCH", //NOI18N
435: "DLCOMMENT", //NOI18N
436: "DLFILESIZE", //NOI18N
437: "DLFILESIZEEXACT", //NOI18N
438: "DLLINKTYPE", //NOI18N
439: "DLURLCOMPLETE", //NOI18N
440: "DLURLPATH", //NOI18N
441: "DLURLPATHONLY", //NOI18N
442: "DLURLSCHEMA", //NOI18N
443: "DLURLSERVER", //NOI18N
444: "DLVALUE", //NOI18N
445: "DYNAMIC_FUNCTION", //NOI18N
446: "DYNAMIC_FUNCTION_CODE", //NOI18N
447: "EXISTING", //NOI18N
448: "EXISTS", //NOI18N
449: "EXTRACT", //NOI18N
450: "FILE", //NOI18N
451: "FINAL", //NOI18N
452: "FORTRAN", //NOI18N
453: "GENERATED", //NOI18N
454: "HOLD", //NOI18N
455: "INFIX", //NOI18N
456: "INSENSITIVE", //NOI18N
457: "INSTANTIABLE", //NOI18N
458: "INTEGRITY", //NOI18N
459: "KEY_MEMBER", //NOI18N
460: "KEY_TYPE", //NOI18N
461: "LENGTH", //NOI18N
462: "LINK", //NOI18N
463: "LOWER", //NOI18N
464: "MAX", //NOI18N
465: "MESSAGE_LENGTH", //NOI18N
466: "MESSAGE_OCTET_LENGTH", //NOI18N
467: "MESSAGE_TEXT", //NOI18N
468: "METHOD", //NOI18N
469: "MIN", //NOI18N
470: "MOD", //NOI18N
471: "MORE", //NOI18N
472: "MUMPS", //NOI18N
473: "NAME", //NOI18N
474: "NULLABLE", //NOI18N
475: "NULLIF", //NOI18N
476: "NUMBER", //NOI18N
477: "OCTET_LENGTH", //NOI18N
478: "OPTIONS", //NOI18N
479: "OVERLAPS", //NOI18N
480: "OVERLAY", //NOI18N
481: "OVERRIDING", //NOI18N
482: "PARAMETER_MODE", //NOI18N
483: "PARAMETER_NAME", //NOI18N
484: "PARAMETER_ORDINAL_POSITION", //NOI18N
485: "PARAMETER_SPECIFIC_CATALOG", //NOI18N
486: "PARAMETER_SPECIFIC_NAME", //NOI18N
487: "PARAMETER_SPECIFIC_SCHEMA", //NOI18N
488: "PASCAL", //NOI18N
489: "PERMISSION", //NOI18N
490: "PLI", //NOI18N
491: "POSITION", //NOI18N
492: "RECOVERY", //NOI18N
493: "REPEATABLE", //NOI18N
494: "RESTORE", //NOI18N
495: "RETURNED_LENGTH", //NOI18N
496: "RETURNED_OCTET_LENGTH", //NOI18N
497: "RETURNED_SQLSTATE", //NOI18N
498: "ROUTINE_CATALOG", //NOI18N
499: "ROUTINE_NAME", //NOI18N
500: "ROUTINE_SCHEMA", //NOI18N
501: "ROW_COUNT", //NOI18N
502: "ROW_TYPE_CATALOG", //NOI18N
503: "ROW_TYPE_NAME", //NOI18N
504: "ROW_TYPE_SCHEMA", //NOI18N
505: "SCALE", //NOI18N
506: "SCHEMA_NAME", //NOI18N
507: "SELECTIVE", //NOI18N
508: "SELF", //NOI18N
509: "SENSITIVE", //NOI18N
510: "SERIALIZABLE", //NOI18N
511: "SERVER_NAME", //NOI18N
512: "SIMILAR", //NOI18N
513: "SIMPLE", //NOI18N
514: "SOURCE", //NOI18N
515: "SPECIFIC_NAME", //NOI18N
516: "STRUCTURE", //NOI18N
517: "STYLE", //NOI18N
518: "SUBCLASS_ORIGIN", //NOI18N
519: "SUBLIST", //NOI18N
520: "SUBSTRING", //NOI18N
521: "SUM", //NOI18N
522: "SYMMETRIC", //NOI18N
523: "SYSTEM", //NOI18N
524: "TABLE_NAME", //NOI18N
525: "TRANSACTIONS_COMMITTED", //NOI18N
526: "TRANSACTIONS_ROLLED_BACK", //NOI18N
527: "TRANSACTION_ACTIVE", //NOI18N
528: "TRANSFORM", //NOI18N
529: "TRANSLATE", //NOI18N
530: "TRIGGER_CATALOG", //NOI18N
531: "TRIGGER_NAME", //NOI18N
532: "TRIGGER_SCHEMA", //NOI18N
533: "TRIM", //NOI18N
534: "TYPE", //NOI18N
535: "UNCOMMITTED", //NOI18N
536: "UNLINK", //NOI18N
537: "UNNAMED", //NOI18N
538: "UPPER", //NOI18N
539: "USER_DEFINED_TYPE_CATALOG", //NOI18N
540: "USER_DEFINED_TYPE_NAME", //NOI18N
541: "USER_DEFINED_TYPE_SCHEMA", //NOI18N
542: "YES", //NOI18N
543: };
544:
545: private SQLKeywords() {
546: }
547:
548: /**
549: * Returns true if the given identifier is a SQL-99 reserved keyword.
550: *
551: * @param identifier the identifier to test; case does not matter; cannot be null.
552: * @return true if <code>identifier</code> is a SQL-99 reserved keyword,
553: * false otherwise.
554: * @throws NullPointerException if <code>identifier</code> is null.
555: */
556: public static boolean isSQL99ReservedKeyword(String identifier) {
557: if (identifier == null) {
558: throw new NullPointerException(
559: "The identifier cannot be null"); // NOI18N
560: }
561: return Arrays.binarySearch(SQL99_RESERVED, identifier
562: .toUpperCase()) >= 0;
563: }
564:
565: /**
566: * Returns true if the given identifier is a SQL-99 non-reserved keyword.
567: *
568: * @param identifier the identifier to test; case does not matter; cannot be null.
569: * @return true if <code>identifier</code> is a SQL-99 non-reserved keyword,
570: * false otherwise.
571: * @throws NullPointerException if <code>identifier</code> is null.
572: */
573: public static boolean isSQL99NonReservedKeyword(String identifier) {
574: if (identifier == null) {
575: throw new NullPointerException(
576: "The identifier cannot be null"); // NOI18N
577: }
578: return Arrays.binarySearch(SQL99_NON_RESERVED, identifier
579: .toUpperCase()) >= 0;
580: }
581:
582: /**
583: * Returns true if the given identifier is a SQL-99 keyword (reserved or
584: * non-reserved).
585: *
586: * @param identifier the identifier to test; case does not matter; cannot be null.
587: * @return true if <code>identifier</code> is a SQL-99 non-reserved keyword,
588: * false otherwise.
589: * @throws NullPointerException if <code>identifier</code> is null.
590: */
591: public static boolean isSQL99Keyword(String identifier) {
592: return isSQL99ReservedKeyword(identifier)
593: || isSQL99NonReservedKeyword(identifier);
594: }
595: }
|