ua.gradsoft.xwikisql.impl
Class InMemorySqlResult

java.lang.Object
  extended by ua.gradsoft.xwikisql.impl.InMemorySqlResult
All Implemented Interfaces:
java.util.Enumeration<SqlResultRow>, SqlErrorable, SqlResult

public class InMemorySqlResult
extends java.lang.Object
implements SqlResult

SQLResult, which holds all in memory


Constructor Summary
InMemorySqlResult(SqlDatabase theDatabase, java.sql.ResultSet rs)
           
 
Method Summary
 void clearError()
          clear all information about error, so wasError become false.
 int getColumnIndex(java.lang.String name)
          retrieve column index by name;
 java.lang.String getColumnName(int index)
          get column name if one exists, otherwise handle error.
 java.lang.String getColumnType(int index)
          retrieve name of column type by column index,
 java.lang.String getColumnType(java.lang.String name)
          retrieve name of column type by column name, as specified in java.sql.Types
 int getColumnTypeAsInt(int index)
          retrieve int value of column type by index,
 int getColumnTypeAsInt(java.lang.String name)
          retrieve int value of column type by name, as specified in java.sql.Types
 java.lang.Exception getLastException()
          get last Exception
 boolean getLogEnabled()
          when this propery is set to true - do logging according with settings in xwiki configurations, otherwise - complete disable one.
 int getNColumns()
          get number of columns
 int getNRows()
          get number of rows.
 boolean getThrowExceptions()
          when this property is set to true, than engine throws exception on error, otherwise - method usially return null and exceptions are saved for further retrieving.
 java.lang.Exception handleError(java.lang.String msg, java.lang.String sql, java.lang.Exception ex)
          also set own last exception and wasError to appropriative values.
 boolean hasColumnName(java.lang.String name)
          check if name is one of column names.
 boolean hasMoreElements()
           
 boolean isNotAllRows()
          Indicate situation, where we does not retrieve all rows.
 SqlResultRow nextElement()
           
 void setLastException(java.lang.Exception ex)
          set last Exception
 void setLogEnabled(boolean value)
          set logEnabled property,
 void setThrowExceptions(boolean value)
          set throwExceptions property,
 boolean wasError()
          true if error was handled (and later not cleared) during some previous operations on this object
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

InMemorySqlResult

public InMemorySqlResult(SqlDatabase theDatabase,
                         java.sql.ResultSet rs)
                  throws java.sql.SQLException
Throws:
java.sql.SQLException
Method Detail

hasMoreElements

public boolean hasMoreElements()
Specified by:
hasMoreElements in interface java.util.Enumeration<SqlResultRow>

nextElement

public SqlResultRow nextElement()
Specified by:
nextElement in interface java.util.Enumeration<SqlResultRow>

handleError

public java.lang.Exception handleError(java.lang.String msg,
                                       java.lang.String sql,
                                       java.lang.Exception ex)
Description copied from interface: SqlErrorable
also set own last exception and wasError to appropriative values. If configuartion parameter throwException is set, throw received exception

Specified by:
handleError in interface SqlErrorable
Parameters:
msg - - message to log (or throw). Can be null if nothing specifcs.
sql - - sql which cause this error. Can be null if unavaible.
ex - - previous exception in chain, if exists.
Returns:
exception, which consists from message and cause.

wasError

public boolean wasError()
Description copied from interface: SqlErrorable
true if error was handled (and later not cleared) during some previous operations on this object

Specified by:
wasError in interface SqlErrorable
Returns:
true if one of previous actions cause sql error.

getLastException

public java.lang.Exception getLastException()
Description copied from interface: SqlErrorable
get last Exception

Specified by:
getLastException in interface SqlErrorable
Returns:
last exception if wasError, otherwise null.

setLastException

public void setLastException(java.lang.Exception ex)
Description copied from interface: SqlErrorable
set last Exception

Specified by:
setLastException in interface SqlErrorable

clearError

public void clearError()
Description copied from interface: SqlErrorable
clear all information about error, so wasError become false.

Specified by:
clearError in interface SqlErrorable

getThrowExceptions

public boolean getThrowExceptions()
Description copied from interface: SqlErrorable
when this property is set to true, than engine throws exception on error, otherwise - method usially return null and exceptions are saved for further retrieving.

Specified by:
getThrowExceptions in interface SqlErrorable
See Also:
SqlPluginConfiguration.getThrowExceptions(), SqlErrorable.setThrowExceptions(boolean)

setThrowExceptions

public void setThrowExceptions(boolean value)
Description copied from interface: SqlErrorable
set throwExceptions property,

Specified by:
setThrowExceptions in interface SqlErrorable
Parameters:
value - -- value to set
See Also:
SqlErrorable.getThrowExceptions()

getLogEnabled

public boolean getLogEnabled()
Description copied from interface: SqlErrorable
when this propery is set to true - do logging according with settings in xwiki configurations, otherwise - complete disable one. Initial value is true (by default) and set from value of parent object. (and for top-level objects can be set via configuration.)

Specified by:
getLogEnabled in interface SqlErrorable
See Also:
SqlPluginConfiguration.getLogEnabled()

setLogEnabled

public void setLogEnabled(boolean value)
Description copied from interface: SqlErrorable
set logEnabled property,

Specified by:
setLogEnabled in interface SqlErrorable
Parameters:
value - -- value to set
See Also:
SqlErrorable.getLogEnabled()

isNotAllRows

public boolean isNotAllRows()
Description copied from interface: SqlResult
Indicate situation, where we does not retrieve all rows. (for example, when select statement return us more than configurated maximumRows)

Specified by:
isNotAllRows in interface SqlResult
Returns:
true, if not all rows retrieced into sql result, otherwise false.

getNRows

public int getNRows()
Description copied from interface: SqlResult
get number of rows.

Specified by:
getNRows in interface SqlResult
Returns:
number of rows.

getNColumns

public int getNColumns()
Description copied from interface: SqlResult
get number of columns

Specified by:
getNColumns in interface SqlResult
Returns:
number of colums.

hasColumnName

public boolean hasColumnName(java.lang.String name)
Description copied from interface: SqlResult
check if name is one of column names.

Specified by:
hasColumnName in interface SqlResult
Parameters:
name - to check.
Returns:
true if name is really a column name.

getColumnName

public java.lang.String getColumnName(int index)
Description copied from interface: SqlResult
get column name if one exists, otherwise handle error.

Specified by:
getColumnName in interface SqlResult
Parameters:
index - (starting from 0)
Returns:
name of appropriative column.

getColumnTypeAsInt

public int getColumnTypeAsInt(java.lang.String name)
Description copied from interface: SqlResult
retrieve int value of column type by name, as specified in java.sql.Types

Specified by:
getColumnTypeAsInt in interface SqlResult
Parameters:
name - - colum name.
Returns:
type of colum as int (or null)
See Also:
Types

getColumnTypeAsInt

public int getColumnTypeAsInt(int index)
Description copied from interface: SqlResult
retrieve int value of column type by index,

Specified by:
getColumnTypeAsInt in interface SqlResult
Parameters:
index - - index of column (starting from 0)
Returns:
type of colum as int (or null)

getColumnType

public java.lang.String getColumnType(java.lang.String name)
Description copied from interface: SqlResult
retrieve name of column type by column name, as specified in java.sql.Types

Specified by:
getColumnType in interface SqlResult
Parameters:
name - - colum name.
Returns:
typename
See Also:
Types

getColumnType

public java.lang.String getColumnType(int index)
Description copied from interface: SqlResult
retrieve name of column type by column index,

Specified by:
getColumnType in interface SqlResult
Parameters:
index - - index of column (starting from 0)
Returns:
column type as string.
See Also:
Types

getColumnIndex

public int getColumnIndex(java.lang.String name)
Description copied from interface: SqlResult
retrieve column index by name;

Specified by:
getColumnIndex in interface SqlResult
Returns:
columnIndex (started from 0) or -1 if such name is not exists.