public abstract class SqlClassWriter
extends org.brains2b.task.DefaultTask
| Modifier and Type | Field and Description |
|---|---|
protected java.lang.String |
m_className |
protected org.brains2b.typewriter.ClassTemplate |
m_classTpl |
protected java.io.File |
m_location |
protected java.lang.String |
m_packageName |
protected org.brains2b.sql.meta.TableModel |
m_tableModel |
protected org.brains2b.sql.meta.TypesInfo |
m_typeInfo |
| Modifier | Constructor and Description |
|---|---|
protected |
SqlClassWriter(java.io.File location,
java.lang.String packageName)
Constructor
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
fileExists(java.lang.String tableName)
test if the file you want to create already exists based on the tablename
supplied.
|
protected abstract java.lang.String |
getClassName(java.lang.String name)
get the class name to be generated for the type of file.
|
protected java.io.File |
getFile(java.io.File location,
java.lang.String packageName,
java.lang.String className)
get the File name on the basis of the supplied location, packageName and className
|
abstract java.io.File |
getResultfile()
abstract method for returning the generated file
|
protected static java.lang.String |
getUnreserverdWord(java.lang.String name)
get the name to use in Java for a SQL name which was altered
to prevent a reserved word being used in the name
|
protected boolean |
isPrimaryKey(org.brains2b.sql.meta.ColumnModel column,
org.brains2b.sql.meta.TableModel table) |
void |
setTableModel(org.brains2b.sql.meta.TableModel tableModel)
sets the model for the table used for generating the file
|
void |
setTypeInfo(org.brains2b.sql.meta.TypesInfo typeInfo) |
protected java.lang.String |
varName(java.lang.String str)
check if a varName is not a java keyword and can be used as a variable name
otherwise prepend
x_ to it and use that as variable name |
protected void |
writeHeaderComment()
write a default comment header to the result file
|
addException, addMessage, addTaskListener, fireTaskEvent, getMax, getMessages, getMin, getPosition, getResult, isFinished, progress, progress, removeTaskListener, setFinished, setMax, setMin, setResultprotected java.io.File m_location
protected java.lang.String m_packageName
protected org.brains2b.sql.meta.TableModel m_tableModel
protected org.brains2b.sql.meta.TypesInfo m_typeInfo
protected org.brains2b.typewriter.ClassTemplate m_classTpl
protected java.lang.String m_className
protected SqlClassWriter(java.io.File location,
java.lang.String packageName)
location - File, set the location to write the file to, this location should exist before run is called
on this class. If this is null the current directory is usedpackageName - 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.
If this is null no package name is used when creating this file.protected abstract java.lang.String getClassName(java.lang.String name)
Implementation is left to the class extending this class
name - String, the table namepublic boolean fileExists(java.lang.String tableName)
This method will return true on any IOException except
FileNotFoundException to make sure a valid file exists after the
generation has finished.
tableName - String, the tableNameisFileSameisFileSame(File)public void setTableModel(org.brains2b.sql.meta.TableModel tableModel)
tableModel - SqlTableModel, the table model usedpublic void setTypeInfo(org.brains2b.sql.meta.TypesInfo typeInfo)
protected java.io.File getFile(java.io.File location,
java.lang.String packageName,
java.lang.String className)
throws java.io.IOException
location - File, the location.packageName - String, the new or existing packageName. If new will be created at the
location. If location is null the packageName will be ignoredclassName - String, the name of the class, a result of getClassName()java.io.IOException - thrown if createPackageDir failscreatePackageDir(File, String)protected boolean isPrimaryKey(org.brains2b.sql.meta.ColumnModel column,
org.brains2b.sql.meta.TableModel table)
protected static java.lang.String getUnreserverdWord(java.lang.String name)
name - String, the name as used in SQL, possibly with _X appendedprotected java.lang.String varName(java.lang.String str)
x_ to it and use that as variable name
This method also makes sure at least the first letter is a lowercase letter
str - String, the value which needs to be used a variable NameKeyWordspublic abstract java.io.File getResultfile()
implementation is left to the classes extending this class
protected void writeHeaderComment()