|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objecthenplus.SQLStatementSeparator
public class SQLStatementSeparator
Simple parser that separates SQLStatements. Example.
----------------------- statementSeparator.append("select * from foo; echo $foobar \n"); while (statementSeparator.hasNext()) { String stmt = statementSeparator.next(); if (stmt.startsWith("echo")) { // is ok, this command works always without ';' statementSeparator.consumed(); System.err.println(stmt.substring("echo ".length()); } else { // SQL-command. we require a semicolon at the end. if (!stmt.charAt(stmt.length()-1) == ';') { statementSeparator.cont(); // continue. } else { statementSeparator.consumed(); SQLExecute(stmt); } } } -----------------------FIXME: this is a bit rough and accummulated some ideas. Should be cleaned up.
Constructor Summary | |
---|---|
SQLStatementSeparator()
|
Method Summary | |
---|---|
void |
append(String s)
add a new line including the '\n' to the input buffer. |
void |
consumed()
after having called next() and you were pleased with the result call this method to state, that you consumed it. |
void |
cont()
after having called next(), call cont(), if you are not yet pleased with the result; the parser should read to the next possible end. |
void |
discard()
discard any input. |
PropertyHolder |
getRemoveCommentsProperty()
returns a property holder for the remove comments property. |
boolean |
hasNext()
returns true, if the parser can find a complete command that either ends with newline or with ';' |
String |
next()
returns the next command; requires to call hasNext() before. |
void |
pop()
|
void |
push()
push the current state and start with a clean one. |
void |
removeComments(boolean b)
set, whether comments should be removed. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public SQLStatementSeparator()
Method Detail |
---|
public void push()
public void pop()
public void append(String s)
public void discard()
public void cont()
public void consumed()
public boolean hasNext() throws IllegalStateException
IllegalStateException
public String next() throws IllegalStateException
IllegalStateException
public PropertyHolder getRemoveCommentsProperty()
public void removeComments(boolean b)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |