|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.brains2b.task.DefaultTask | +--org.brains2b.sql.toclass.SqlClassWriter | +--org.brains2b.sql.toclass.Sql2DataC
This class generates a DataControl class in line with the DataC specifications to control insert,delete,update and select statements for a given data class.
This class is called from Sql2ClassConsole
and some other implementations
which supply the necessary information. If you use this class just to generate files look at
Sql2ClassConsole
first.
The naming of the new class file will be equal to the table name with initial caps and followed by DC. example: EMPLOYEES will become EmployeesDC. Underscores will be treated as an instance to initialize caps again. example: EMP_SALARIES will become EmpSalariesDC
The class is written to the given location and packageName. The location should not include the
package directory itself. If the package directory does not exist it will be created. If the location
does not exist you will get a FileNotFoundException
The option setReadOnly
generates a data class which will throw
an Exception
and performs no other function if you try to update,insert or delete a record through this data control, making this
data control basically a read only data control.
If you generate a data control as a view the insert,update and delete will be generated throwing only an
Exception
while updating views is not supported.
Sql2ClassConsole
,
SqlTableModel
Field Summary |
Fields inherited from class org.brains2b.sql.toclass.SqlClassWriter |
m_location, m_packageName, m_tableModel |
Fields inherited from interface org.brains2b.task.Task |
RESULT_ERROR, RESULT_OK, RESULT_WARNING |
Constructor Summary | |
Sql2DataC(java.io.File location,
java.lang.String packageName)
Constructor |
|
Sql2DataC(java.io.File location,
java.lang.String packageName,
org.brains2b.sql.meta.SqlTableModel tmodel)
Constructor |
Method Summary | |
protected java.lang.String |
getClassName(java.lang.String name)
get the classname used for generating this data control class |
java.io.File |
getResultfile()
get the file which has been created. |
protected boolean |
isOptimisticLock()
check if this Data Control should contain the code for optimistic locking. |
protected boolean |
isReadOnly()
check if this Data Control class should be generated as read only |
void |
run()
run does the actual work in this class. |
void |
setOptimisticLock(boolean b)
sets this class to generate the required code for using optimistic locking. |
void |
setReadOnly(boolean b)
set to true if this Data Control class is to be generated read only, false is the default for tables, true for Views. |
Methods inherited from class org.brains2b.sql.toclass.SqlClassWriter |
fileExists, getFile, setTableModel, varName |
Methods inherited from class org.brains2b.task.DefaultTask |
addException, addMessage, addTaskListener, fireTaskEvent, getMax, getMessages, getMin, getPosition, getResult, isFinished, progress, removeTaskListener, setFinished, setMax, setMin, setResult |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public Sql2DataC(java.io.File location, java.lang.String packageName)
This constructor does not set the TableModel, this is however required
for this class to be able to generate the datacontrol. You should set the tablemodel
by calling setTableModel(org.brains2b.sql.meta.SqlTableModel)
location
- File, set the location to write the file to, this location should exist before run is called
on this class.packageName
- String, the packageName for the class, names should be separated by dots. The packagename
is both used to set the package name of the class as to create or use the directory relative to location to write the file to.public Sql2DataC(java.io.File location, java.lang.String packageName, org.brains2b.sql.meta.SqlTableModel tmodel)
location
- File, set the location to write the file to, this location should exist before run is called
on this class.packageName
- String, the packageName for the class, names should be separated by dots. The packagename
is both used to set the package name of the class as to create or use the directory relative to location to write the file to.Method Detail |
public void run()
Output is written to the org.brains2b.log.Logger
. Dependant
on the setting there the code will show up on System.out
. This is
the case if you do nothing
run
in interface java.lang.Runnable
run
in class org.brains2b.task.DefaultTask
Runnable.run()
,
DefaultTask.setFinished(boolean)
,
Logger
public java.io.File getResultfile()
The result of this file is only valid after run()
has finished
getResultfile
in class SqlClassWriter
SqlClassWriter.getResultfile()
,
run()
protected java.lang.String getClassName(java.lang.String name)
getClassName
in class SqlClassWriter
name
- String, the table name
SqlClassWriter.getClassName(String)
protected boolean isReadOnly()
public void setReadOnly(boolean b)
This will not influence the code generated for a View
b
- boolean, true if you want it to generate read only, false otherwiseprotected boolean isOptimisticLock()
setOptimisticLock(boolean)
public void setOptimisticLock(boolean b)
Optimistic locking is done by setting a checksum value on a data class whenever
a record is selected or updated. This value is the same as the calculated hashCode.
Before a record is updated the record is refetched and the checksum is compared
to the hashCode of the newly fetched record. Whenever there is a change made to the database
values will no longer match and a 'Record has been changed by another user' Exception is thrown.
For this to work correctly the Data class used for this control class should contain a setChecksum(int)
and getChecksum()
method, something which is automatically generated if
setOptimisticLock(true)
is used on Sql2File.
b
- boolean, true if optimistic locking should be used, false otherwiseSql2File
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |