xmlBlaster 2.2.0 API

org.xmlBlaster.contrib.dbwriter.info
Class SqlDescription

java.lang.Object
  extended by org.xmlBlaster.contrib.dbwriter.info.SqlDescription

public class SqlDescription
extends java.lang.Object

This info object is mainly used for two purposes: the one is the parsed object returned by each message. The other is as an info object for each table in the replication (hold in cache to contain meta information of the table on which to perform the operations (either INSERT, UPDATE or DELETE).

Author:
Michele Laghi

Field Summary
private  boolean allowDoubleInserts
           
private  java.util.List attributeKeys
           
private  java.util.Map attributes
           
private  boolean caseSensitive
           
private  java.lang.String charSet
           
private  java.util.List columnList
           
private  java.lang.String command
           
static java.lang.String COMMAND_TAG
           
private  java.util.Set configuredSearchableColumns
          if set, it means the configuration has specified which columns have to be used for searches in this table.
private  java.lang.String deleteStatementTxt
           
static java.lang.String DESC_TAG
           
private  boolean hasAddedStatements
           
static java.lang.String IDENT_TAG
           
private  java.lang.String identity
           
private  I_Info info
           
private  java.lang.String insertStatementTxt
           
private static java.util.logging.Logger log
           
static java.lang.String ME
           
(package private) static java.lang.String OLD_POSTFIX
           
(package private) static java.lang.String OLD_PREFIX
           
private  I_Parser parser
          this is only needed for tables which do not have any PK and on updates
private  boolean pk
           
private  boolean pkKnown
           
private  boolean quoteColumnNames
           
private  java.lang.String schema
           
private  boolean schemaKnown
           
private  java.lang.String updateStatementTxt
           
 
Constructor Summary
SqlDescription(I_Info info)
           
 
Method Summary
 void addAttributes(java.util.Map map)
          It copies (stores) all entries found in the map into the attributes.
 void addColumn(SqlColumn column)
           
private  boolean canAddColToSearch(SqlColumn sqlCol)
           
 void clearColumnDescriptions()
           
private  java.lang.String createInsertStatement(SqlRow row, java.util.List searchEntries)
           
private  java.lang.String createSetStatement(SqlRow row, java.util.List searchEntries)
           
private  java.lang.String createWhereStatement(SqlRow row, java.util.List searchEntries)
           
private  byte[] cutEndIfTooLong(SqlColumn col, java.lang.String colName, byte[] val)
           
 int delete(java.sql.Connection conn, SqlRow row)
          Returns the number of entries deleted
private  java.lang.String extractColumnInfo(boolean isSchema)
          Used by getSchema and getCatalog.
 ClientProperty getAttribute(java.lang.String key)
          Returns the requested attribute.
 java.lang.String[] getAttributeNames()
           
 java.util.Map getAttributesClone()
           
 java.lang.String getCatalog()
          Gets the name of the schema.
 SqlColumn getColumn(java.lang.String colName)
           
 SqlColumn getColumnAtPosition(int pos)
          Gets the column at position given by pos.
 SqlColumn[] getColumns()
           
 java.lang.String getCommand()
           
 java.lang.String getCompleteTableName()
           
static java.lang.String getDifferences(SqlDescription description1, SqlDescription description2)
           
private  double getDouble(ClientProperty prop)
           
 java.lang.String getIdentity()
           
private  long getLong(ClientProperty prop)
           
 int getNumOfColumns()
           
 java.lang.String getSchema()
          Gets the name of the schema.
private static java.lang.String getVal(SqlDescription description, java.lang.String key)
           
private  boolean hasPk()
          Note this method has only sense when used in such cases where all columns belonging to this description are in the same table.
 int insert(java.sql.Connection conn, SqlRow row)
          Returns the number of entries inserted
private  void insertIntoStatement(java.sql.PreparedStatement st, int pos, ClientProperty prop)
           
private  boolean isBinaryType(int type)
           
 boolean isColumnSearchConfigured(java.lang.String column)
           
static void main(java.lang.String[] args)
           
private static void processMapping(SqlInfo sqlInfo, I_Mapper mapper)
           
 void setAttribute(ClientProperty value)
          Stores the client property as a new value.
 void setAttribute(java.lang.String key, java.lang.String value)
          Stores the String as a new value.
 void setCommand(java.lang.String command)
           
 void setIdentity(java.lang.String identity)
           
private static void setVal(SqlDescription description, java.lang.String key, java.lang.String val)
           
 java.lang.String toXml(java.lang.String extraOffset)
           
(package private)  java.lang.String toXml(java.lang.String extraOffset, boolean doTruncate)
           
 int update(java.sql.Connection conn, SqlRow newRow, I_Parser parserForOld)
          Returns the number of entries updated
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ME

public static final java.lang.String ME
See Also:
Constant Field Values

DESC_TAG

public static final java.lang.String DESC_TAG
See Also:
Constant Field Values

IDENT_TAG

public static final java.lang.String IDENT_TAG
See Also:
Constant Field Values

COMMAND_TAG

public static final java.lang.String COMMAND_TAG
See Also:
Constant Field Values

OLD_PREFIX

static final java.lang.String OLD_PREFIX
See Also:
Constant Field Values

OLD_POSTFIX

static final java.lang.String OLD_POSTFIX
See Also:
Constant Field Values

identity

private java.lang.String identity

command

private java.lang.String command

columnList

private java.util.List columnList

updateStatementTxt

private java.lang.String updateStatementTxt

deleteStatementTxt

private java.lang.String deleteStatementTxt

insertStatementTxt

private java.lang.String insertStatementTxt

hasAddedStatements

private boolean hasAddedStatements

attributes

private java.util.Map attributes

attributeKeys

private java.util.List attributeKeys

caseSensitive

private boolean caseSensitive

quoteColumnNames

private boolean quoteColumnNames

pk

private boolean pk

pkKnown

private boolean pkKnown

schemaKnown

private boolean schemaKnown

schema

private java.lang.String schema

charSet

private java.lang.String charSet

allowDoubleInserts

private boolean allowDoubleInserts

parser

private I_Parser parser
this is only needed for tables which do not have any PK and on updates


log

private static java.util.logging.Logger log

info

private I_Info info

configuredSearchableColumns

private volatile java.util.Set configuredSearchableColumns
if set, it means the configuration has specified which columns have to be used for searches in this table. It is used for delete and update to find the entry on which to perform the operation

Constructor Detail

SqlDescription

public SqlDescription(I_Info info)
Method Detail

getSchema

public java.lang.String getSchema()
Gets the name of the schema. Since this information is not contained in the object iself but in the Column information (since views could be a combination of more than one schema or catalog), this method checks that the schema is the same for all columns. If it is different, or if it is not assigned, then null is returned.

Returns:

getCompleteTableName

public java.lang.String getCompleteTableName()

getCatalog

public java.lang.String getCatalog()
Gets the name of the schema. Since this information is not contained in the object iself but in the Column information (since views could be a combination of more than one schema or catalog), this method checks that the catalog is the same for all columns. If it is different, or if it is not assigned, then null is returned.

Returns:

extractColumnInfo

private final java.lang.String extractColumnInfo(boolean isSchema)
Used by getSchema and getCatalog.

Returns:

getAttributeNames

public java.lang.String[] getAttributeNames()

clearColumnDescriptions

public void clearColumnDescriptions()

getAttributesClone

public java.util.Map getAttributesClone()

getAttribute

public ClientProperty getAttribute(java.lang.String key)
Returns the requested attribute. If 'caseSensitive' has been set, the characters of the key are compared case sensitively. If it is set to false, then it first searches for the case sensitive match, if nothing is found it looks for the lowercase of the key, and finally if still no match it looks for the uppercase alternative. If none of these is found, null is returned.

Parameters:
key - the key of the attribute
Returns:
the ClientProperty object associated with the key, or if none found, null is returned.

setAttribute

public void setAttribute(ClientProperty value)
Stores the client property as a new value.

Parameters:
value - the value to store as an attribute.

setAttribute

public void setAttribute(java.lang.String key,
                         java.lang.String value)
Stores the String as a new value. The passed String is directly transformed into a ClientProperty object.

Parameters:
value - the value to store as an attribute.

addAttributes

public void addAttributes(java.util.Map map)
It copies (stores) all entries found in the map into the attributes. As values only String and ClientProperty objects are allowed. If another type is found, an IllegalArgumentException is thrown. If null is passed, nothing is done.

Parameters:
map -

hasPk

private final boolean hasPk()
Note this method has only sense when used in such cases where all columns belonging to this description are in the same table.

Returns:

canAddColToSearch

private final boolean canAddColToSearch(SqlColumn sqlCol)

createWhereStatement

private final java.lang.String createWhereStatement(SqlRow row,
                                                    java.util.List searchEntries)
Parameters:
searchEntries - an empty list. This will be filled with the values of the entries (ClientProperties) found in the row object: also NULL objects are considered. and which can be used as search path (either pk or all).
Returns:
a string containing the search statement. As an example: " WHERE one=? AND two=? AND three=? "

createInsertStatement

private final java.lang.String createInsertStatement(SqlRow row,
                                                     java.util.List searchEntries)
Parameters:
searchEntries - an empty list. This will be filled with the values of the entries (ClientProperties) found in the row object. Also NULL objects are now added and which can be used as search path (either pk or all).
Returns:
a string containing the search statement. As an example: " (first, second, third) VALUES ( ? , ? , ? ) "

createSetStatement

private final java.lang.String createSetStatement(SqlRow row,
                                                  java.util.List searchEntries)
Parameters:
searchEntries - an empty list. This will be filled with the values of the entries (ClientProperties) found in the row object. Also null objects are added. and which can be used as search path (either pk or all).
Returns:
a string containing the search statement. As an example: " SET one=? , two=? , three=? "

cutEndIfTooLong

private final byte[] cutEndIfTooLong(SqlColumn col,
                                     java.lang.String colName,
                                     byte[] val)

getDouble

private final double getDouble(ClientProperty prop)

getLong

private final long getLong(ClientProperty prop)

insertIntoStatement

private final void insertIntoStatement(java.sql.PreparedStatement st,
                                       int pos,
                                       ClientProperty prop)
                                throws java.sql.SQLException,
                                       java.io.IOException,
                                       java.text.ParseException
Throws:
java.sql.SQLException
java.io.IOException
java.text.ParseException

isBinaryType

private boolean isBinaryType(int type)

getVal

private static java.lang.String getVal(SqlDescription description,
                                       java.lang.String key)

setVal

private static void setVal(SqlDescription description,
                           java.lang.String key,
                           java.lang.String val)

processMapping

private static void processMapping(SqlInfo sqlInfo,
                                   I_Mapper mapper)
                            throws java.lang.Exception
Throws:
java.lang.Exception

update

public int update(java.sql.Connection conn,
                  SqlRow newRow,
                  I_Parser parserForOld)
           throws java.lang.Exception
Returns the number of entries updated

Parameters:
conn -
row -
Returns:
Throws:
java.lang.Exception

delete

public int delete(java.sql.Connection conn,
                  SqlRow row)
           throws java.lang.Exception
Returns the number of entries deleted

Parameters:
conn -
row -
Returns:
Throws:
java.lang.Exception

insert

public int insert(java.sql.Connection conn,
                  SqlRow row)
           throws java.lang.Exception
Returns the number of entries inserted

Parameters:
conn -
row -
Returns:
Throws:
java.lang.Exception

getCommand

public java.lang.String getCommand()

setCommand

public void setCommand(java.lang.String command)

getIdentity

public java.lang.String getIdentity()

setIdentity

public void setIdentity(java.lang.String identity)

addColumn

public void addColumn(SqlColumn column)

getColumns

public SqlColumn[] getColumns()

getColumn

public SqlColumn getColumn(java.lang.String colName)

getNumOfColumns

public int getNumOfColumns()

getColumnAtPosition

public SqlColumn getColumnAtPosition(int pos)
Gets the column at position given by pos. Note that the first position is 1 (not 0).

Parameters:
pos -
Returns:
Throws:
java.lang.IllegalArgumentException - if the number is less than 1 or bigger than the size of the list or if for some reason the entry has not been found.

toXml

public java.lang.String toXml(java.lang.String extraOffset)

toXml

final java.lang.String toXml(java.lang.String extraOffset,
                             boolean doTruncate)

getDifferences

public static java.lang.String getDifferences(SqlDescription description1,
                                              SqlDescription description2)

main

public static void main(java.lang.String[] args)

isColumnSearchConfigured

public boolean isColumnSearchConfigured(java.lang.String column)
Parameters:
column - the name of the column to check or null if a global check for the table.
Returns:
true if the specified column is configured as searchable false otherwise. If you passed null as the column name, then true is returned if at least one column is searchable, false otherwise.

xmlBlaster 2.2.0 API

Copyright © 1999-2014 The xmlBlaster.org contributers.