001: /*
002: * Copyright 2004-2008 H2 Group. Licensed under the H2 License, Version 1.0
003: * (http://h2database.com/html/license.html).
004: * Initial Developer: H2 Group
005: */
006: package org.h2.bnf;
007:
008: import java.util.HashMap;
009: import java.util.HashSet;
010:
011: import org.h2.server.web.DbTableOrView;
012:
013: /**
014: * A query context object. It contains the list of table and alias objects.
015: * Used for autocomplete.
016: */
017: public class Sentence {
018:
019: /**
020: * The possible choices of the item depend on the context.
021: * For example the item represents a table name of the current database.
022: */
023: public static final int CONTEXT = 0;
024: static final int KEYWORD = 1;
025: static final int FUNCTION = 2;
026: public String text;
027: HashMap next;
028: long max;
029: private DbTableOrView lastTable;
030: private HashSet tables;
031: private HashMap aliases;
032:
033: boolean stop() {
034: return System.currentTimeMillis() > max;
035: }
036:
037: /**
038: * Add a word to the set of next tokens.
039: *
040: * @param n the token name
041: * @param string an example text
042: * @param type the type
043: */
044: public void add(String n, String string, int type) {
045: next.put(type + "#" + n, string);
046: }
047:
048: /**
049: * Add an alias name and object
050: *
051: * @param alias the alias name
052: * @param table the alias table
053: */
054: public void addAlias(String alias, DbTableOrView table) {
055: if (aliases == null) {
056: aliases = new HashMap();
057: }
058: aliases.put(alias, table);
059: }
060:
061: /**
062: * Add a table.
063: *
064: * @param table the table
065: */
066: public void addTable(DbTableOrView table) {
067: lastTable = table;
068: if (tables == null) {
069: tables = new HashSet();
070: }
071: tables.add(table);
072: }
073:
074: /**
075: * Get the set of tables.
076: *
077: * @return the set of tables
078: */
079: public HashSet getTables() {
080: return tables;
081: }
082:
083: /**
084: * Get the alias map.
085: *
086: * @return the alias map
087: */
088: public HashMap getAliases() {
089: return aliases;
090: }
091:
092: /**
093: * Get the last added table.
094: *
095: * @return the last table
096: */
097: public DbTableOrView getLastTable() {
098: return lastTable;
099: }
100: }
|