| 
 | OOoRunner test harness | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
util
Class  DBTools
java.lang.Object | +--util.DBTools
- public class DBTools- extends Object
Provides useful methods for working with SOffice databases. Database creation, data transfering, outputting infromation.
| Inner Class Summary | |
|  class | DBTools.DataSourceInfoIt's just a structure with some useful methods for representing com.sun.star.sdb.DataSourceservice. | 
| Field Summary | |
| static int | TST_BINARY_STREAM | 
| static String | TST_BINARY_STREAM_F | 
| static int | TST_BOOLEAN | 
| static String | TST_BOOLEAN_F | 
| static int | TST_CHARACTER_STREAM | 
| static String | TST_CHARACTER_STREAM_F | 
| static int | TST_DATE | 
| static String | TST_DATE_F | 
| static int | TST_DOUBLE | 
| static String | TST_DOUBLE_F | 
| static int | TST_INT | 
| static String | TST_INT_F | 
| static String | TST_JDBC_DRIVER | 
| static int[] | TST_STREAM_LENGTHSArray of lengths of streams for each row in of the TST_TABLE_VALUESconstants. | 
| static int | TST_STRING | 
| static String | TST_STRING_F | 
| static Object[][] | TST_TABLE_VALUESValues for filling test table. | 
| Constructor Summary | |
| DBTools(XMultiServiceFactory xMSF)Creates class instance. | |
| Method Summary | |
|  void | addRowToTestTable(XConnection con,
                  String table,
                  Object[] values,
                  int streamLength)Inserts row into test table of the specified connection. | 
|  XConnection | connectToDBase(String contextName,
               String dbDir)Registers DBase database (directory with DBF files) in the global DB context, then connects to it. | 
|  XConnection | connectToSource(Object dbSource)Performs connection to DataSource specified. | 
|  XConnection | connectToTestDB(String docPath)Connects to DataSourcespecially created for testing. | 
|  XConnection | connectToTextDB(String contextName,
                String dbDir,
                String fileExtension)RESERVED. | 
| protected  void | createMySQLTable(Statement statement,
                 String tbl_name)Creates test table specified. | 
|  int | deleteAllRows(XConnection con,
              String table)Empties the table in the specified source. | 
| static String | dirToUrl(String dir)Convert system pathname to SOffice URL string (for example 'C:\Temp\DBDir\' -> 'file:///C|/Temp/DBDir/'). | 
| protected  void | dropMySQLTable(Statement statement,
               String tbl_name)Drops table. | 
|  void | initializeTestTable(XConnection con,
                    String table)Initializes test table specified of the connection specified. | 
|  void | initTestTableUsingJDBC(String tbl_name,
                       DBTools.DataSourceInfo dsi)Initializes test table specified of the connection specified using JDBC driver. | 
| protected  void | insertContentMySQLTable(Statement statement,
                        String tbl_name)Inserts data from TST_TABLE_VALUESconstant array
 to test tabletbl_name. | 
|  DBTools.DataSourceInfo | newDataSourceInfo()Returns new instance of DataSourceInfoclass. | 
|  DBTools.DataSourceInfo | newDataSourceInfo(Object dataSource)Returns new instance of DataSourceInfoclass. | 
|  void | printRegisteredDatabasesInfo(PrintWriter out)Prints full info about currently registered DataSource's. | 
|  void | registerDB(String name,
           Object dataSource)Registers the datasource on the specified name in DatabaseContextservice. | 
|  Object | registerTestDB(String docPath)Registers Test data source in the DatabaseContextservice. | 
|  void | reRegisterDB(String name,
             Object dataSource)First tries to revoke the datasource with the specified name and then registers a new one. | 
|  void | revokeDB(String name)Revokes datasource from global DB context. | 
| Methods inherited from class java.lang.Object | 
| clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait | 
| Field Detail | 
TST_JDBC_DRIVER
public static final String TST_JDBC_DRIVER
TST_STRING
public static final int TST_STRING
TST_INT
public static final int TST_INT
TST_DOUBLE
public static final int TST_DOUBLE
TST_DATE
public static final int TST_DATE
TST_BOOLEAN
public static final int TST_BOOLEAN
TST_CHARACTER_STREAM
public static final int TST_CHARACTER_STREAM
TST_BINARY_STREAM
public static final int TST_BINARY_STREAM
TST_STRING_F
public static final String TST_STRING_F
TST_INT_F
public static final String TST_INT_F
TST_DOUBLE_F
public static final String TST_DOUBLE_F
TST_DATE_F
public static final String TST_DATE_F
TST_BOOLEAN_F
public static final String TST_BOOLEAN_F
TST_CHARACTER_STREAM_F
public static final String TST_CHARACTER_STREAM_F
TST_BINARY_STREAM_F
public static final String TST_BINARY_STREAM_F
TST_TABLE_VALUES
public static final Object[][] TST_TABLE_VALUES
- Values for filling test table.
TST_STREAM_LENGTHS
public static final int[] TST_STREAM_LENGTHS
- Array of lengths of streams for each row in of the
 TST_TABLE_VALUESconstants.
| Constructor Detail | 
DBTools
public DBTools(XMultiServiceFactory xMSF)
- Creates class instance.- Parameters:
- xMSF-- XMultiServiceFactory.
 
| Method Detail | 
newDataSourceInfo
public DBTools.DataSourceInfo newDataSourceInfo()
- Returns new instance of DataSourceInfoclass.
newDataSourceInfo
public DBTools.DataSourceInfo newDataSourceInfo(Object dataSource)
- Returns new instance of DataSourceInfoclass.
registerDB
public void registerDB(String name, Object dataSource) throws Exception
- Registers the datasource on the specified name in
 DatabaseContextservice.- Parameters:
- name- Name which dataSource will have in global context.- dataSource-- DataSourceobject which is to be registered.
 
reRegisterDB
public void reRegisterDB(String name, Object dataSource) throws Exception
- First tries to revoke the datasource with the specified
 name and then registers a new one.- Parameters:
- name- Name which dataSource will have in global context.- dataSource-- DataSourceobject which is to be registered.
 
connectToTextDB
public XConnection connectToTextDB(String contextName, String dbDir, String fileExtension) throws Exception
- RESERVED. Not used.
connectToDBase
public XConnection connectToDBase(String contextName, String dbDir) throws Exception
- Registers DBase database (directory with DBF files) in the
 global DB context, then connects to it.- Parameters:
- contextName- Name under which DB will be registered.- dbDir- The directory with DBF tables.
- Returns:
- Connection to the DB.
 
connectToSource
public XConnection connectToSource(Object dbSource) throws Exception
- Performs connection to DataSource specified.- Parameters:
- dbSource-- com.sun.star.sdb.DataSourceservice specified data source which must be already registered in the- DatabaseContextservice.- dbSource- Data source to be connected to.
- Returns:
- Connection to the data source.
 
registerTestDB
public Object registerTestDB(String docPath) throws Exception
- Registers Test data source in the DatabaseContextservice. This source always has name'APITestDatabase'and it is registered in subdirectoryTestDBof directorydocPathwhich is supposed to be a directory with test documents, but can be any other (it must have subdirectory with DBF tables). If such data source doesn't exists or exists with different URL it is recreated and reregistered.- Parameters:
- docPath- Path to database- TestDBdirectory.
- Returns:
- com.sun.star.sdb.DataSourceservice implementation which represents TestDB.
 
connectToTestDB
public XConnection connectToTestDB(String docPath) throws Exception
- Connects to DataSourcespecially created for testing. This source always has name'APITestDatabase'and it is registered in subdirectoryTestDBof directorydocPathwhich is supposed to be a directory with test documents, but can be any other (it must have subdirectory with DBF tables). If such data source doesn't exists or exists with different URL it is recreated and reregistered. Finally connection performed.- Parameters:
- docPath- Path to database- TestDBdirectory.
- Returns:
- Connection to test database.
 
deleteAllRows
public int deleteAllRows(XConnection con, String table) throws SQLException
- Empties the table in the specified source.- Parameters:
- con- Connection to the DataSource where appropriate table exists.- table- The name of the table where all rows will be deleted.
- Returns:
- Number of rows deleted.
 
addRowToTestTable
public void addRowToTestTable(XConnection con, String table, Object[] values, int streamLength) throws SQLException
- Inserts row into test table of the specified connection.
 Test table has some predefined format which includes as much
 field types as possible. For every column type constants
 TST_STRING,TST_INT, etc. are declared for column index fast find.- Parameters:
- con- Connection to data source where test table exists.- table- Test table name.- values- Values to be inserted into test table. Values of this array inserted into appropriate fields depending on their types. So- Stringvalue of the array is inserted into the field of- CHARACTERtype, etc.- streamLength- Is optional. It is used only if in values list- XCharacterInputStreamor- XBinaryInputStreamtypes specified. In this case the parameter specifies the length of the stream for inserting.
 
initializeTestTable
public void initializeTestTable(XConnection con, String table) throws SQLException
- Initializes test table specified of the connection specified.
 Deletes all record from table, and then inserts data from
 TST_TABLE_VALUESconstant array.Test table has some predefined format which includes as much field types as possible. For every column type constants TST_STRING,TST_INT, etc. are declared for column index fast find.- Parameters:
- con- Connection to data source where test table exists.- table- Test table name.
 
printRegisteredDatabasesInfo
public void printRegisteredDatabasesInfo(PrintWriter out)
- Prints full info about currently registered DataSource's.
dirToUrl
public static String dirToUrl(String dir)
- Convert system pathname to SOffice URL string (for example 'C:\Temp\DBDir\' -> 'file:///C|/Temp/DBDir/'). Already converted string retured unchanged.
revokeDB
public void revokeDB(String name) throws Exception
- Revokes datasource from global DB context.- Parameters:
- name- DataSource name to be revoked.
 
initTestTableUsingJDBC
public void initTestTableUsingJDBC(String tbl_name, DBTools.DataSourceInfo dsi) throws SQLException, ClassNotFoundException
- Initializes test table specified of the connection specified
 using JDBC driver. Drops table with the name tbl_name, creates new table with this name and then inserts data fromTST_TABLE_VALUESconstant array.Test table has some predefined format which includes as much field types as possible. For every column type constants TST_STRING,TST_INT, etc. are declared for column index fast find.- Parameters:
- tbl_name- Test table name.
 
insertContentMySQLTable
protected void insertContentMySQLTable(Statement statement, String tbl_name) throws SQLException
- Inserts data from TST_TABLE_VALUESconstant array to test tabletbl_name.- Parameters:
- statement- object used for executing a static SQL statement and obtaining the results produced by it.- tbl_name- Test table name.
 
createMySQLTable
protected void createMySQLTable(Statement statement, String tbl_name) throws SQLException
- Creates test table specified.
 Test table has some predefined format which includes as much
 field types as possible. For every column type constants
 TST_STRING,TST_INT, etc. are declared for column index fast find.- Parameters:
- statement- object used for executing a static SQL statement and obtaining the results produced by it.- table- Test table name.
 
dropMySQLTable
protected void dropMySQLTable(Statement statement, String tbl_name) throws SQLException
- Drops table.- Parameters:
- statement- object used for executing a static SQL statement and obtaining the results produced by it.- table- Test table name.
 
| 
 | OOoRunner test harness | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||

