01: package net.sourceforge.squirrel_sql.plugins.derby.tokenizer;
02:
03: /*
04: * Copyright (C) 2007 Rob Manning
05: * manningr@users.sourceforge.net
06: *
07: * Based on initial work from Johan Compagner.
08: *
09: * This library is free software; you can redistribute it and/or
10: * modify it under the terms of the GNU Lesser General Public
11: * License as published by the Free Software Foundation; either
12: * version 2.1 of the License, or (at your option) any later version.
13: *
14: * This library is distributed in the hope that it will be useful,
15: * but WITHOUT ANY WARRANTY; without even the implied warranty of
16: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17: * Lesser General Public License for more details.
18: *
19: * You should have received a copy of the GNU Lesser General Public
20: * License along with this library; if not, write to the Free Software
21: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22: */
23: import net.sourceforge.squirrel_sql.fw.sql.IQueryTokenizer;
24: import net.sourceforge.squirrel_sql.fw.sql.ITokenizerFactory;
25: import net.sourceforge.squirrel_sql.fw.sql.QueryTokenizer;
26:
27: /**
28: * This class is loaded by the Derby Plugin and registered with all Derby
29: * Sessions as the query tokenizer if the plugin is loaded. It handles some
30: * of the syntax allowed in ij scripts that would be hard to parse in a
31: * generic way for any database. Specifically, it handles "run 'script'"
32: * commands which
33: *
34: * @author manningr
35: */
36: public class DerbyQueryTokenizer extends QueryTokenizer implements
37: IQueryTokenizer {
38: private static final String DERBY_SCRIPT_INCLUDE_PREFIX = "run ";
39:
40: public DerbyQueryTokenizer(String sep, String linecomment,
41: boolean removeMultiLineComment) {
42: super (sep, linecomment, removeMultiLineComment);
43: }
44:
45: public void setScriptToTokenize(String script) {
46: super .setScriptToTokenize(script);
47:
48: expandFileIncludes(DERBY_SCRIPT_INCLUDE_PREFIX);
49:
50: _queryIterator = _queries.iterator();
51: }
52:
53: /**
54: * Sets the ITokenizerFactory which is used to create additional instances
55: * of the IQueryTokenizer - this is used for handling file includes
56: * recursively.
57: */
58: protected void setFactory() {
59: _tokenizerFactory = new ITokenizerFactory() {
60: public IQueryTokenizer getTokenizer() {
61: return new DerbyQueryTokenizer(
62: DerbyQueryTokenizer.this._querySep,
63: DerbyQueryTokenizer.this._lineCommentBegin,
64: DerbyQueryTokenizer.this._removeMultiLineComment);
65: }
66: };
67: }
68:
69: }
|