templates.velocity.casban.perschema.constant.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( "schema.include.vm" )
#parse( "header.include.vm" )
#set ( $javaClassName = 'Constant' )
$codewriter.setCurrentJavaFilename($pkg, "${javaClassName}.java")
package $pkg;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.LinkedHashSet;
import gu.sql2java.annotations.SchemaComponent;
import gu.sql2java.annotations.SchemaConstantSupplier;
import com.gitee.l0km.casban.CasbanCachedClassScanner;
import com.gitee.l0km.casban.annotations.AnnotationFieldNames;
import com.gitee.l0km.casban.exception.PackageScanException;
#####################
/**
* constant declare by casban
*/
public class $javaClassName {
/** alias name of connection */
public static String ALIAS_NAME = readAssociatedConstant("ALIAS_NAME");
/** same prefix of all tablename */
public static String SAME_PREFIX = readAssociatedConstant("SAME_PREFIX");
//////////////////////////////////////
// TABLE CLASS DECLARE
//////////////////////////////////////
#foreach($t in $tables)
public static final Class extends $t.asBeanClass($isGeneral)> $t.asConstantVar()_CLASS = readAssociatedConstant("$t.asConstantVar()_CLASS");
#end
public static final String[] TABLE_CORE_NAMES = new String[]{#join($tables '"$e.corename"' ',')};
public static final List TABLE_CORE_NAME_LIST = Collections.unmodifiableList(Arrays.asList(TABLE_CORE_NAMES));
public static final Set TABLE_CORE_NAME_SET = Collections.unmodifiableSet(new LinkedHashSet<>(Arrays.asList(TABLE_CORE_NAMES)));
//////////////////////////////////////
// COLUMN COLUMN CONSTANT
//////////////////////////////////////
#join($tables '
public static final int $e.asConstantVar()_COLUMN_COUNT = readAssociatedConstant("$e.asConstantVar("_COLUMN_COUNT")");
public static final int $e.asConstantVar()_PK_COUNT = readAssociatedConstant("$e.asConstantVar("_PK_COUNT")");' '')
//////////////////////////////////////
// COLUMN ID DECLARE
//////////////////////////////////////
#foreach($t in $tables)
#foreach ( $column in $t.columns )
#set ( $vcmo = $velocityCount - 1 )
/** Identify the $column.getFullNameNsp() field. */
public static final int $column.getIDAssociated() = readAssociatedConstant("$column.getIDAssociated()");
#end
#end
//////////////////////////////////////
// COLUMN NAME DECLARE
//////////////////////////////////////
#foreach($t in $tables)
/////////////////// $t.name ////////////
/** table name without same prefix for the $t.name table.*/
public static final String $t.asConstantVar()_CORE = "$t.corename";
/** native table name for the $t.name table.*/
public static final String $t.asConstantVar()_NAME = readAssociatedConstant("$t.asConstantVar()_NAME");
/** Contains all the pk fields name of the $t.name table.*/
public static final String $t.asConstantVar()_PK_FIELDS = readAssociatedConstant("$t.asConstantVar()_PK_FIELDS");
public static final List $t.asConstantVar()_PK_FIELDS_LIST = readAssociatedConstant("$t.asConstantVar()_PK_FIELDS_LIST");
/** Contains all the full fields of the $t.name table.*/
public static final String $t.asConstantVar()_FULL_FIELDS =readAssociatedConstant("$t.asConstantVar()_FULL_FIELDS");
public static final List $t.asConstantVar()_FULL_FIELDS_LIST = readAssociatedConstant("$t.asConstantVar()_FULL_FIELDS_LIST");
public static final Set $t.asConstantVar()_FULL_FIELDS_SET = readAssociatedConstant("$t.asConstantVar()_FULL_FIELDS_SET");
/** Field that contains the comma separated fields of the $t.name table. */
public static final String $t.asConstantVar()_FIELDS = readAssociatedConstant("$t.asConstantVar()_FIELDS");
public static final List $t.asConstantVar()_FIELDS_LIST = readAssociatedConstant("$t.asConstantVar()_FIELDS_LIST");
public static final Set $t.asConstantVar()_FIELDS_SET = readAssociatedConstant("$t.asConstantVar()_FIELDS_SET");
#join($t.columns 'public static final String $e.getNameAssociated() = readAssociatedConstant("$e.getNameAssociated()");
' '')##
/** Field that contains the comma separated java fields of the $t.name table. */
public static final String $t.asConstantVar()_JAVA_FIELDS = readAssociatedConstant("$t.asConstantVar()_JAVA_FIELDS");;
public static final List $t.asConstantVar()_JAVA_FIELDS_LIST = readAssociatedConstant("$t.asConstantVar()_JAVA_FIELDS_LIST");
public static final Set $t.asConstantVar()_JAVA_FIELDS_SET = readAssociatedConstant("$t.asConstantVar()_JAVA_FIELDS_SET");
/** column type names of the $t.name table. */
public static final String[] $t.asConstantVar()_COLUMN_TYPE_NAMES = readAssociatedConstant("$t.asConstantVar()_COLUMN_TYPE_NAMES");
public static final List $t.asConstantVar()_COLUMN_TYPE_NAME_LIST = readAssociatedConstant("$t.asConstantVar()_COLUMN_TYPE_NAME_LIST");
/** Field java types of the $t.name table. */
public static final Class>[] $t.asConstantVar()_FIELD_TYPES = readAssociatedConstant("$t.asConstantVar()_FIELD_TYPES");
/** Field size of the $t.name table. */
public static final int[] $t.asConstantVar()_FIELD_SIZES = readAssociatedConstant("$t.asConstantVar()_FIELD_SIZES");
/** Field SQL types of the $t.name table. */
public static final int[] $t.asConstantVar()_FIELD_SQL_TYPES = readAssociatedConstant("$t.asConstantVar()_FIELD_SQL_TYPES");
#end
static T readAssociatedConstant(Object entryValue) {
try {
return CasbanCachedClassScanner.getInstance().readValueByEntry(SchemaComponent.class,SchemaConstantSupplier.class,AnnotationFieldNames.ASSOCIATED,entryValue);
} catch (PackageScanException e) {
throw new PackageScanException(
String.format("NOT FOUND OR FOUND VALUE with %s=%s,caused by %s",AnnotationFieldNames.ASSOCIATED,entryValue,e.getMessage()));
}
}
static T readAssociatedConstant(Object entryValue, T defaultValue) {
return CasbanCachedClassScanner.getInstance().readValueByEntry(SchemaComponent.class,SchemaConstantSupplier.class,AnnotationFieldNames.ASSOCIATED,entryValue,defaultValue);
}
/**
* determine if tablename is a core name
* @param tablename
*/
public static boolean isCorename(String tablename) {
return TABLE_CORE_NAME_SET.contains(asCorename(tablename));
}
/**
* return new string without prefix if tablename start with {@link #SAME_PREFIX},
* otherwise return tablename self.
* @param tablename
*/
public static String asCorename(String tablename) {
if(null != tablename && tablename.startsWith(SAME_PREFIX)) {
return tablename.substring(SAME_PREFIX.length());
}
return tablename;
}
/**
* return new string with prefix {@link #SAME_PREFIX} if it is a core name,
* otherwise return tablename self.
* @param tablename
*/
public static String asNativeName(String tablename) {
if(isCorename(tablename) && !tablename.startsWith(SAME_PREFIX)) {
return SAME_PREFIX+tablename;
}
return tablename;
}
}