templates.velocity.java5g.pertable.metadata.vm Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sql2java-generator Show documentation
Show all versions of sql2java-generator Show documentation
executable jar of sql2java generator
#parse( "table.include.vm" )
#parse( "header.include.vm" )
#parse( "macros.include.vm" )
######################
#set ( $javaClassName = $table.asMetaDataClassNSP() )
#set ( $beanClass = $table.asBeanClassNSP() )
$codewriter.setCurrentJavaFilename(${pkg}, "${javaClassName}.java")
package ${pkg};
import java.util.List;
import java.util.Arrays;
import gu.sql2java.annotations.RowMeta;
import gu.sql2java.RowMetaData;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableList;
#set( $localScope = $table.getColumnsByVisibility('LOCAL'))
#set( $thriftScope = $table.getColumnsByVisibility('THRIFT'))
#set( $jsonScope = $table.getColumnsByVisibility('JSON'))
/**
* Class to supply table meta data for the $tablename table.
* @author guyadong
*/
@RowMeta(tablename="$tablename"##
#if(!$localScope.empty),localScopeColumns={#join($localScope '"$e.name"' ',')}#end##
#if(!$thriftScope.empty),thriftScopeColumns={#join($thriftScope '"$e.name"' ',')}#end##
#if(!$jsonScope.empty),jsonScopeColumns={#join($jsonScope '"$e.name"' ',')}#end)
public class ${javaClassName} extends RowMetaData implements Constant
{
#if($table.junctionTable)
private static final ImmutableMap JUNCTION_TABLE_PK_MAP =
ImmutableMap.builder()
#join($table.primaryKeys '.put("$e.name","${e.foreignColumn.tableName}.$e.foreignColumn.name")
' '').build();
#else
private static final ImmutableMap JUNCTION_TABLE_PK_MAP = ImmutableMap.of();
#end
private static final ImmutableList FOREIGN_KEYS =
ImmutableList.builder()
#foreach($fk in $table.getForeignKeysAsList())
.add("$fk.fkName (#join($fk.columns '$e.name' ',')) REFERENCES ${fk.foreignTable.name}(#join($fk.columns '$e.foreignColumn.name' ',')) $fk.updateRule $fk.deleteRule")
#end
.build();
private static final ImmutableList IMPORTED_FKNAMES =
ImmutableList.builder()
#foreachImportedTables($table " .add(""$m_fkName($m_importedTable.name)"") " '' '
')
.build();
private static final ImmutableList INDEXS =
ImmutableList.builder()
#foreach($index in $table.getIndices())
#set( $indexColumns = $index.getIndexColumnsList())
.add("$index.name (#join($indexColumns '$e.name' ',')) #if($index.isUnique())UNIQUE#end")
#end##($index in $table.getIndices())
.build();
private static final List GETTERS = Arrays.asList(#join($columns '"$e.getGetMethod()"' ','));
private static final List SETTERS = Arrays.asList(#join($columns '"$e.getSetMethod()"' ','));
private static final String AUTO_INCREMENT_COLUMN = "$!{table.autoincrement.name}";
#if ( $table.hasVersionColumn() )
#set ($lockColumn = $table.getVersionColumn() )
private static final Class> LOCK_COLUMN_TYPE = ${lockColumn.getJavaType()}.class;
private static final String LOCK_COLUMN_NAME = "${lockColumn.name}";
#else
private static final Class> LOCK_COLUMN_TYPE = null;
private static final String LOCK_COLUMN_NAME = null;
#end
public ${javaClassName}(){
super(
"$tablename",
"$table.type",
${beanClass}.class,
"$coreClass",
${table.asManagerInterfaceNSP()}.class,
ALIAS_NAME,
${tablename.toUpperCase()}_FIELDS_LIST,
${tablename.toUpperCase()}_COLUMN_TYPE_NAME_LIST,
${tablename.toUpperCase()}_JAVA_FIELDS_LIST,
GETTERS,
SETTERS,
${tablename.toUpperCase()}_FIELD_TYPES,
${tablename.toUpperCase()}_FIELD_SIZES,
${tablename.toUpperCase()}_FIELD_SQL_TYPES,
${tablename.toUpperCase()}_PK_FIELDS_LIST,
JUNCTION_TABLE_PK_MAP,
LOCK_COLUMN_TYPE,
LOCK_COLUMN_NAME,
FOREIGN_KEYS,
IMPORTED_FKNAMES,
INDEXS,
AUTO_INCREMENT_COLUMN
);
}
}