org.brains2b.sql.toclass
Class Sql2File

java.lang.Object
  extended byorg.brains2b.task.DefaultTask
      extended byorg.brains2b.sql.toclass.SqlClassWriter
          extended byorg.brains2b.sql.toclass.Sql2File
All Implemented Interfaces:
java.lang.Runnable, org.brains2b.task.Task

public class Sql2File
extends SqlClassWriter

This class writes an SQL Table which is supplied through an SqlTableModel to a data class, with the necessary accessors

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, but with initial caps. example: EMPLOYEES will become Employees. Underscores will be treated as an instance to initialize caps again. example: EMP_SALARIES will become EmpSalaries

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 dennis@brains2b.nl

See Also:
Sql2ClassConsole, SqlTableModel, Sql2DataC

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
Sql2File(java.io.File location, java.lang.String packageName)
          Constructor
Sql2File(java.io.File location, java.lang.String packageName, org.brains2b.sql.meta.SqlTableModel tm)
          Constructor
 
Method Summary
protected  java.lang.String getClassName(java.lang.String name)
          get the class name for the data class
 java.io.File getResultfile()
          get the file which has been created.
protected  boolean isOptimisticLock()
          does this class use optimistic locking
 void run()
          run does the actual work in this class.
 void setOptimisticLock(boolean b)
          set this to true if optimistic locking should be used.
 void setTableModel(org.brains2b.sql.meta.SqlTableModel tableModel)
          overwritten to retrieve the columns for local use
 
Methods inherited from class org.brains2b.sql.toclass.SqlClassWriter
fileExists, getFile, 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

Sql2File

public Sql2File(java.io.File location,
                java.lang.String packageName,
                org.brains2b.sql.meta.SqlTableModel tm)
Constructor

Parameters:
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.
tm - org.brains2b.sql.meta.SqlTableModel, the table model to base this dataclass on

Sql2File

public Sql2File(java.io.File location,
                java.lang.String packageName)
Constructor

This constructor does not set the TableModel, this is however required for this class to be able to generate the file. You should set the tablemodel by calling setTableModel(org.brains2b.sql.meta.SqlTableModel)

Parameters:
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.
See Also:
setTableModel(SqlTableModel)
Method Detail

setTableModel

public void setTableModel(org.brains2b.sql.meta.SqlTableModel tableModel)
overwritten to retrieve the columns for local use

Overrides:
setTableModel in class SqlClassWriter
Parameters:
tableModel - SqlTableModel, the table model used
See Also:
SqlClassWriter.setTableModel(SqlTableModel)

run

public void run()
run does the actual work in this class.

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

See Also:
Runnable.run(), DefaultTask.setFinished(boolean), Logger

getResultfile

public java.io.File getResultfile()
get the file which has been created.

The result of this file is only valid after run()has finished

Specified by:
getResultfile in class SqlClassWriter
Returns:
File, the newly created file
See Also:
SqlClassWriter.getResultfile(), run()

getClassName

protected java.lang.String getClassName(java.lang.String name)
get the class name for the data class

Specified by:
getClassName in class SqlClassWriter
Parameters:
name - String, the table name
Returns:
String the name of the new class with proper capitalization
See Also:
SqlClassWriter.getClassName(String)

isOptimisticLock

protected boolean isOptimisticLock()
does this class use optimistic locking

Returns:
true if optimistic locking should be used, false otherwise

setOptimisticLock

public void setOptimisticLock(boolean b)
set this to true if optimistic locking should be used.

by default optimistic locking is not used.

Parameters:
b - boolean