com.agimatec.sql
Class SQLWriter

java.lang.Object
  extended by java.io.Writer
      extended by com.agimatec.sql.SQLWriter
All Implemented Interfaces:
Closeable, Flushable, Appendable

public class SQLWriter
extends Writer

The SQLWriter is responsible for simplyfying SQL-Generation by providing an API to write to a SQL-String.

$Author: stumm $


Field Summary
protected static char parameterMarker
           
static byte STATE_BEGIN
           
static byte STATE_HAS_OP
           
static byte STATE_NEEDS_OP
           
 
Fields inherited from class java.io.Writer
lock
 
Constructor Summary
SQLWriter()
          Initialize the new instance.
SQLWriter(AliasDictionary useAliases)
          Initialize the new instance with a given AliasDictionary or null
 
Method Summary
 SQLWriter addParameter(Object paramValue)
          Add a parameter and write the parameter marker
 void close()
          Close the stream.
 SQLStatement createStatement()
          Create an instance of SQLStatement from the receiver
 void flipStreams()
          set the receivers selectStream as the stream and the stream as the selectStream.
 void flush()
          Flush the stream.
 AliasDictionary getAliases()
          Answer the receiver's alias dictionary.
 byte getOperatorState()
           
 String getParameterizedStatement()
          return the statement including parameter values instead of ?
 List getParameters()
          return a collection of parameters provided to the reciever
 String getSelectString()
           
 String getWhereString()
           
 SQLWriter onSelect_write(String str)
          does not change operator state. just write str.
 void setAliases(AliasDictionary aAliases)
          Set the receiver's alias dictionary.
 void setOperatorState(byte aState)
          set the operator state to the given contant.
 String toString()
          Answer the receiver's string representation, i.e. answer the content of the underlying StringWriter.
 void write(char[] cbuf, int off, int len)
          Write a portion of an array of characters.
 void write(int c)
          Write a single character.
 void write(String str)
          Write a string.
 void write(String str, int off, int len)
          Write a portion of a string.
 SQLWriter writeAnd()
          Write an AND token to the stream, if neccessary
 SQLWriter writeOperator(String operator)
           
 SQLWriter writeOr()
          Write an OR token to the stream, if neccessary
 SQLWriter writeParameterMarker()
          Write a parameter marker to the stream.
 SQLWriter writeWhere()
          Write a WHERE token to the stream, if neccessary
 
Methods inherited from class java.io.Writer
append, append, append, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

parameterMarker

protected static final char parameterMarker
See Also:
Constant Field Values

STATE_BEGIN

public static final byte STATE_BEGIN
See Also:
Constant Field Values

STATE_HAS_OP

public static final byte STATE_HAS_OP
See Also:
Constant Field Values

STATE_NEEDS_OP

public static final byte STATE_NEEDS_OP
See Also:
Constant Field Values
Constructor Detail

SQLWriter

public SQLWriter()
Initialize the new instance.


SQLWriter

public SQLWriter(AliasDictionary useAliases)
Initialize the new instance with a given AliasDictionary or null

Method Detail

flipStreams

public void flipStreams()
set the receivers selectStream as the stream and the stream as the selectStream. This method can be used to get the same APIs for writing to the select stream as you have for writing to the stream, if you know what you are currently writing on.


close

public void close()
Close the stream.

Specified by:
close in interface Closeable
Specified by:
close in class Writer

flush

public void flush()
Flush the stream. Delegate to the underlying StringWriter.

Specified by:
flush in interface Flushable
Specified by:
flush in class Writer

getAliases

public AliasDictionary getAliases()
Answer the receiver's alias dictionary.


setAliases

public void setAliases(AliasDictionary aAliases)
Set the receiver's alias dictionary.


toString

public String toString()
Answer the receiver's string representation, i.e. answer the content of the underlying StringWriter.

Overrides:
toString in class Object

getSelectString

public String getSelectString()

getWhereString

public String getWhereString()

getParameterizedStatement

public String getParameterizedStatement()
return the statement including parameter values instead of ?


createStatement

public SQLStatement createStatement()
Create an instance of SQLStatement from the receiver


write

public void write(char[] cbuf,
                  int off,
                  int len)
Write a portion of an array of characters. Delegate to the underlying StringWriter.

Specified by:
write in class Writer

write

public void write(int c)
Write a single character. Delegate to the underlying StringWriter.

Overrides:
write in class Writer

write

public void write(String str)
Write a string. Delegate to the underlying StrinWriter.

Overrides:
write in class Writer

onSelect_write

public SQLWriter onSelect_write(String str)
does not change operator state. just write str.

Returns:
this

setOperatorState

public void setOperatorState(byte aState)
set the operator state to the given contant. use when you known what you do!


getOperatorState

public byte getOperatorState()

write

public void write(String str,
                  int off,
                  int len)
Write a portion of a string. Delegate to the underlying StringWriter.

Overrides:
write in class Writer

writeAnd

public SQLWriter writeAnd()
Write an AND token to the stream, if neccessary


writeOperator

public SQLWriter writeOperator(String operator)

writeOr

public SQLWriter writeOr()
Write an OR token to the stream, if neccessary


writeParameterMarker

public SQLWriter writeParameterMarker()
Write a parameter marker to the stream.


addParameter

public SQLWriter addParameter(Object paramValue)
Add a parameter and write the parameter marker


getParameters

public List getParameters()
return a collection of parameters provided to the reciever


writeWhere

public SQLWriter writeWhere()
Write a WHERE token to the stream, if neccessary



Copyright © 2008-2012. All Rights Reserved.