|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object edu.northwestern.at.utils.db.mysql.MySQLInsertGenerator
public class MySQLInsertGenerator
A MySQL insert statement generator.
This class provides for constructing a MySQL-specific SQL Insert statement that takes multiple value lists in one insert. This kind of insert typically runs an order of magnitude faster than individual inserts.
Field Summary | |
---|---|
protected java.lang.String[] |
fieldNames
The name of the column fields, in order, for each data row. |
protected java.lang.StringBuffer |
insertBuffer
The string buffer in which to build the insert statement. |
protected boolean[] |
isNumeric
True if a field is a number, false otherwise. |
protected java.lang.String |
tableName
The name of the database table into which to insert the data rows. |
Constructor Summary | |
---|---|
MySQLInsertGenerator(java.lang.String tableName,
java.lang.String[] fieldNames,
boolean[] isNumeric)
Create a MySQL insert generator. |
Method Summary | |
---|---|
void |
addRow(java.lang.Object[] rowData)
Add a row of data. |
protected java.lang.String |
escapeSingleQuotes(java.lang.String value)
Escapes single quotes in a data value. |
java.lang.String |
getInsert()
Get the insert statement. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected java.lang.String tableName
protected java.lang.String[] fieldNames
protected boolean[] isNumeric
protected java.lang.StringBuffer insertBuffer
Constructor Detail |
---|
public MySQLInsertGenerator(java.lang.String tableName, java.lang.String[] fieldNames, boolean[] isNumeric)
tableName
- The database table name to receive the data.fieldNames
- The name of the column fields, in order, for
each data row.isNumeric
- True if the associated field is numeric, false
for a string. Method Detail |
---|
protected java.lang.String escapeSingleQuotes(java.lang.String value)
value
- The value to escape.
public void addRow(java.lang.Object[] rowData)
rowData
- An Object[] array containing the data values.
Each row value must have a proper toString() method defined. The number of row values must match the number of field names passed in the contructor. If there are two many values, the extra values are ignored. If there are too few values, database null values are added.
public java.lang.String getInsert()
The string buffer used to build the insert statement is emptied. Any subsequent calls to addRow will start a new insert statement with the same table name and field names are defined in the constructor call.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |