|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectscone.netobjects.DBTableAdapter
public class DBTableAdapter
stores the database meta information about a TableRecord.
i.e. it knows how to map a TableRecord obect to and from a database.
Database fields are seperated into three cases:
Field Summary | |
---|---|
protected int |
autoincrementLine
|
static int |
BLOB
Column type in database is Blob: quote values |
protected java.sql.Connection |
con
|
static java.lang.String |
COPYRIGHT
|
protected static java.lang.String |
dbURI
|
protected static java.lang.String |
driverName
|
static int |
FIELD
Ordinary field |
protected int |
fieldCount
Number of fields per record |
protected java.lang.String[] |
fieldDefaults
Array with default values of fields |
protected java.lang.String[] |
fieldNames
Array of field names |
protected int[] |
fieldTypes
Array of field types: STRING, NUMBER, BLOB |
static int |
GENERATED
Generated Key: AUTO_INCREMENT |
protected int |
generatedKey
The generated key, used if database is not available (con==null || useDB==false) |
static int |
KEY
Key value field: Use to select record in database for update operation |
protected int |
keyNumber
|
protected int[] |
keyTypes
|
static int |
NUMBER
Column type in database is Numerical: do not quote values |
protected static java.lang.String |
password
|
protected static boolean |
requireDb
|
static int |
STRING
Column type in database is String: quote values |
protected java.lang.String |
tableName
The name of the database table |
protected static boolean |
useDb
|
protected static java.lang.String |
userName
|
Constructor Summary | |
---|---|
DBTableAdapter(java.lang.String tableName)
creates a new DBTableAdapter object |
Method Summary | |
---|---|
void |
addField(java.lang.String fieldName,
int fieldType,
java.lang.String fieldDefault,
int keyType)
adds a field to the table definition. |
void |
createInDB(TableRecord set)
Creates a record in the database and fills it with key values If a generated key exists, it reads the value from the database. |
void |
dbCheck(TableRecord set)
tries to read from the database an fills the TableRecord if a set exists. |
void |
dbCreate(TableRecord set)
creates a new Set in the database |
protected static void |
dbError()
this method should be called when an SQLException has been caught. |
void |
dbInit(TableRecord set)
tries to find an equivalent set in the database or creates one if it does not exist. |
protected static void |
dontUseDb()
this method should be called when an SQLException has been caught. |
static java.lang.String |
escape(java.lang.String s)
Calls escape(StringBuffer s) |
static java.lang.String |
escape(java.lang.StringBuffer s)
Escape is used to escape characters, that cause problems with mySQL or mm.mysql The following strings are converted: null (0) -> \0 Backspace (8) -> \b New line (10) -> \n CR (13) -> \r Double qoutes " (34) -> \" Single quote ' (39) -> \' Percent % (92) -> \% Underscore _ (95) -> \_ Math brackets { } (123, 124) -> \( \) Pipe | (124) -> \| |
protected boolean |
fill(TableRecord set,
java.sql.ResultSet results)
tries to read from the ResultSet into the TableRecord. |
static java.sql.Connection |
getConnection()
returns a new Connection to the database |
java.lang.String |
getTableName()
Returns the name of this table |
boolean |
getValuesFromDb(TableRecord set)
tries to load the values corresponding to the TableRecord from the database. |
java.lang.String |
getWhereClause(TableRecord set)
generates a where clause to find the specified TableRecord in the database. |
static void |
init()
initializes the DB class by parsing scone/config/db.ini |
void |
init(TableRecord set)
initializes a TableRecord object. |
protected FieldValueHashTable |
initFields(TableRecord set)
creates a new FieldValueHashTable with the names and defaults of the fields |
static java.sql.ResultSet |
queryDb(java.sql.Connection con,
java.lang.String tableName,
java.lang.String sqlClause)
tries to load the values corresponding to the TableRecord from the database. |
static int |
rowCountDb(java.sql.Connection con,
java.lang.String tableName,
java.lang.String sqlClause)
Tries to get the number of rows in the database to a given query. |
static java.lang.String |
safeString(java.lang.String unsafe)
Ensures that a String is not null |
static java.lang.String |
unEscape(java.lang.String s)
|
static java.lang.String |
unEscape(java.lang.StringBuffer s)
unEscape Strings read from DB to original values |
void |
updateDB(TableRecord set)
writes the values from the TableRecord into the database |
static boolean |
useDb()
returns true, if the database is used, and false if local memory is used instead |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String COPYRIGHT
public static final int STRING
public static final int NUMBER
public static final int BLOB
public static final int GENERATED
public static final int KEY
public static final int FIELD
protected java.lang.String[] fieldNames
protected int[] fieldTypes
protected java.lang.String[] fieldDefaults
protected int fieldCount
protected int[] keyTypes
protected int keyNumber
protected int autoincrementLine
protected java.lang.String tableName
protected java.sql.Connection con
protected int generatedKey
protected static java.lang.String driverName
protected static java.lang.String dbURI
protected static java.lang.String userName
protected static java.lang.String password
protected static boolean useDb
protected static boolean requireDb
Constructor Detail |
---|
public DBTableAdapter(java.lang.String tableName)
tableName
- the name of the tableMethod Detail |
---|
public java.lang.String getTableName()
public void addField(java.lang.String fieldName, int fieldType, java.lang.String fieldDefault, int keyType)
fieldName
- the name of the fieldfieldType
- the type of the field. Legal values are: String
, Number
fieldDefault
- the default value in String formatkeyType
- whether the field is part of a key.protected FieldValueHashTable initFields(TableRecord set)
set
- the TableRecord
public void init(TableRecord set)
set
- the TableRecord objectpublic void dbInit(TableRecord set)
set
- the TableRecord objectpublic void dbCheck(TableRecord set)
set
- the TableRecordpublic void dbCreate(TableRecord set)
set
- the TableRecordpublic void updateDB(TableRecord set)
set
- the TableRecordpublic boolean getValuesFromDb(TableRecord set)
set
- the TableRecord
public static java.sql.ResultSet queryDb(java.sql.Connection con, java.lang.String tableName, java.lang.String sqlClause)
con
- A connection to the DBtableName
- The name of the table in the scone databasesqlClause
- A where or order by clause for the querey.
public static int rowCountDb(java.sql.Connection con, java.lang.String tableName, java.lang.String sqlClause)
con
- A connection to the DBtableName
- The name of the table in the scone databasesqlClause
- A where or order by clause for the querey.
protected boolean fill(TableRecord set, java.sql.ResultSet results)
set
- the TableRecordresults
- the ResultSet
public void createInDB(TableRecord set)
set
- the TableRecordpublic java.lang.String getWhereClause(TableRecord set)
where
clause to find the specified TableRecord in the database.
set
- the TableRecord
where
clause corresponding to the TableRecord objectpublic static java.lang.String safeString(java.lang.String unsafe)
unsafe
- the String
null
>public static java.lang.String escape(java.lang.String s)
public static java.lang.String escape(java.lang.StringBuffer s)
The following strings are converted:
public static java.lang.String unEscape(java.lang.String s)
public static java.lang.String unEscape(java.lang.StringBuffer s)
public static void init()
public static java.sql.Connection getConnection()
Connection
to the database
protected static void dontUseDb()
protected static void dbError()
public static boolean useDb()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |