MiG InfoCom MiG Calendar DBConnect Guide User Manual

Page 17

Advertising
background image

MiG InfoCom AB

some level. You can set the level on the Logger to get everything from
errors to fine grained details of what is happening. For troubleshooting
it is almost a must to use logging since the DBConnect is using a
background thread to do the database operations.

There is a method

setLogger(Logger l)

on all of the above

objects types.

For information on Logging see the documentation for Java 1.4+ API
at java.sun.com. E.g.

http://java.sun.com/j2se/1.4.2/docs/guide/util/logging/

Creating a Database from the Mappings

Primary for testing and debugging DBConnect has utility methods for
creating a database (or more correct the tables) according to the
current property mappings. The database itself isn't created, nor are
the database users.

DBUtil.createTable(con, tableDef, dropFirst,
constaints)

will create the table.

DBUtil.createUpdateTable(con, tableDef,
dropFirst, constaints)

will create the update table, if any.

DBUtil.createIDToManyTables(con, tableDef,
dropFirst, constaints)

will create the any external Join

tables.

Constraints on the tables, such as primary keys, are not automatically
handled, but can be sent into the method as an optional argument and
will be shunted to the database. For instance the standard SQL
phrase

”PRIMARY KEY (activity_id, category_id)”

can be used to specify that those two columns should be part of the
primary key for an

IDToManyTable

.

Note that the create tables method returns the SQL as a

String

. If

you set the connection to

null

the database will not be contacted,

and thus no tables created, but you can get the SQL string. The SQL
can then be used as a reference on how DBConnect expects the
database to look like. It can also be used to send the code manually to
the database with a tool provided by the database vendor.

See the demo code for examples.

Deleting Table Data

There is also a utility method for delete all data in a table. To delete all
rows in a table use:

DBUtil.deleteDataInTable(connection

,

tableName)

DBConnect Guide

Page 17 / 25

Advertising