use of org.mybatis.generator.api.IntrospectedColumn in project generator by mybatis.
the class BaseRecordGenerator method getCompilationUnits.
@Override
public List<CompilationUnit> getCompilationUnits() {
FullyQualifiedTable table = introspectedTable.getFullyQualifiedTable();
progressCallback.startTask(getString("Progress.8", //$NON-NLS-1$
table.toString()));
Plugin plugins = context.getPlugins();
CommentGenerator commentGenerator = context.getCommentGenerator();
FullyQualifiedJavaType type = new FullyQualifiedJavaType(introspectedTable.getBaseRecordType());
TopLevelClass topLevelClass = new TopLevelClass(type);
topLevelClass.setVisibility(JavaVisibility.PUBLIC);
commentGenerator.addJavaFileComment(topLevelClass);
FullyQualifiedJavaType superClass = getSuperClass();
if (superClass != null) {
topLevelClass.setSuperClass(superClass);
topLevelClass.addImportedType(superClass);
}
commentGenerator.addModelClassComment(topLevelClass, introspectedTable);
List<IntrospectedColumn> introspectedColumns = getColumnsInThisClass();
if (introspectedTable.isConstructorBased()) {
addParameterizedConstructor(topLevelClass);
if (!introspectedTable.isImmutable()) {
addDefaultConstructor(topLevelClass);
}
}
String rootClass = getRootClass();
for (IntrospectedColumn introspectedColumn : introspectedColumns) {
if (RootClassInfo.getInstance(rootClass, warnings).containsProperty(introspectedColumn)) {
continue;
}
Field field = getJavaBeansField(introspectedColumn, context, introspectedTable);
if (plugins.modelFieldGenerated(field, topLevelClass, introspectedColumn, introspectedTable, Plugin.ModelClassType.BASE_RECORD)) {
topLevelClass.addField(field);
topLevelClass.addImportedType(field.getType());
}
Method method = getJavaBeansGetter(introspectedColumn, context, introspectedTable);
if (plugins.modelGetterMethodGenerated(method, topLevelClass, introspectedColumn, introspectedTable, Plugin.ModelClassType.BASE_RECORD)) {
topLevelClass.addMethod(method);
}
if (!introspectedTable.isImmutable()) {
method = getJavaBeansSetter(introspectedColumn, context, introspectedTable);
if (plugins.modelSetterMethodGenerated(method, topLevelClass, introspectedColumn, introspectedTable, Plugin.ModelClassType.BASE_RECORD)) {
topLevelClass.addMethod(method);
}
}
}
List<CompilationUnit> answer = new ArrayList<CompilationUnit>();
if (context.getPlugins().modelBaseRecordClassGenerated(topLevelClass, introspectedTable)) {
answer.add(topLevelClass);
}
return answer;
}
use of org.mybatis.generator.api.IntrospectedColumn in project generator by mybatis.
the class AnnotatedUpdateByPrimaryKeyWithoutBLOBsMethodGenerator method addMapperAnnotations.
@Override
public void addMapperAnnotations(Method method) {
//$NON-NLS-1$
method.addAnnotation("@Update({");
StringBuilder sb = new StringBuilder();
javaIndent(sb, 1);
//$NON-NLS-1$
sb.append("\"update ");
sb.append(escapeStringForJava(introspectedTable.getFullyQualifiedTableNameAtRuntime()));
//$NON-NLS-1$
sb.append("\",");
method.addAnnotation(sb.toString());
// set up for first column
sb.setLength(0);
javaIndent(sb, 1);
//$NON-NLS-1$
sb.append("\"set ");
Iterator<IntrospectedColumn> iter;
if (isSimple) {
iter = ListUtilities.removeGeneratedAlwaysColumns(introspectedTable.getNonPrimaryKeyColumns()).iterator();
} else {
iter = ListUtilities.removeGeneratedAlwaysColumns(introspectedTable.getBaseColumns()).iterator();
}
while (iter.hasNext()) {
IntrospectedColumn introspectedColumn = iter.next();
sb.append(escapeStringForJava(getEscapedColumnName(introspectedColumn)));
//$NON-NLS-1$
sb.append(" = ");
sb.append(getParameterClause(introspectedColumn));
if (iter.hasNext()) {
sb.append(',');
}
//$NON-NLS-1$
sb.append("\",");
method.addAnnotation(sb.toString());
// set up for the next column
if (iter.hasNext()) {
sb.setLength(0);
javaIndent(sb, 1);
//$NON-NLS-1$
sb.append(" \"");
}
}
boolean and = false;
iter = introspectedTable.getPrimaryKeyColumns().iterator();
while (iter.hasNext()) {
IntrospectedColumn introspectedColumn = iter.next();
sb.setLength(0);
javaIndent(sb, 1);
if (and) {
//$NON-NLS-1$
sb.append(" \"and ");
} else {
//$NON-NLS-1$
sb.append("\"where ");
and = true;
}
sb.append(escapeStringForJava(getEscapedColumnName(introspectedColumn)));
//$NON-NLS-1$
sb.append(" = ");
sb.append(getParameterClause(introspectedColumn));
sb.append('\"');
if (iter.hasNext()) {
sb.append(',');
}
method.addAnnotation(sb.toString());
}
//$NON-NLS-1$
method.addAnnotation("})");
}
use of org.mybatis.generator.api.IntrospectedColumn in project generator by mybatis.
the class ProviderInsertSelectiveMethodGenerator method addClassElements.
@Override
public void addClassElements(TopLevelClass topLevelClass) {
Set<String> staticImports = new TreeSet<String>();
Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>();
if (useLegacyBuilder) {
//$NON-NLS-1$
staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.BEGIN");
//$NON-NLS-1$
staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.INSERT_INTO");
//$NON-NLS-1$
staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.SQL");
//$NON-NLS-1$
staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.VALUES");
} else {
importedTypes.add(NEW_BUILDER_IMPORT);
}
FullyQualifiedJavaType fqjt = introspectedTable.getRules().calculateAllFieldsClass();
importedTypes.add(fqjt);
Method method = new Method(introspectedTable.getInsertSelectiveStatementId());
method.setVisibility(JavaVisibility.PUBLIC);
method.setReturnType(FullyQualifiedJavaType.getStringInstance());
//$NON-NLS-1$
method.addParameter(new Parameter(fqjt, "record"));
context.getCommentGenerator().addGeneralMethodComment(method, introspectedTable);
if (useLegacyBuilder) {
//$NON-NLS-1$
method.addBodyLine("BEGIN();");
} else {
//$NON-NLS-1$
method.addBodyLine("SQL sql = new SQL();");
}
method.addBodyLine(//$NON-NLS-1$
String.format(//$NON-NLS-1$
"%sINSERT_INTO(\"%s\");", builderPrefix, escapeStringForJava(introspectedTable.getFullyQualifiedTableNameAtRuntime())));
for (IntrospectedColumn introspectedColumn : ListUtilities.removeIdentityAndGeneratedAlwaysColumns(introspectedTable.getAllColumns())) {
//$NON-NLS-1$
method.addBodyLine("");
if (!introspectedColumn.getFullyQualifiedJavaType().isPrimitive() && !introspectedColumn.isSequenceColumn()) {
method.addBodyLine(//$NON-NLS-1$
String.format(//$NON-NLS-1$
"if (record.%s() != null) {", getGetterMethodName(introspectedColumn.getJavaProperty(), introspectedColumn.getFullyQualifiedJavaType())));
}
method.addBodyLine(//$NON-NLS-1$
String.format(//$NON-NLS-1$
"%sVALUES(\"%s\", \"%s\");", builderPrefix, escapeStringForJava(getEscapedColumnName(introspectedColumn)), getParameterClause(introspectedColumn)));
if (!introspectedColumn.getFullyQualifiedJavaType().isPrimitive() && !introspectedColumn.isSequenceColumn()) {
//$NON-NLS-1$
method.addBodyLine("}");
}
}
//$NON-NLS-1$
method.addBodyLine("");
if (useLegacyBuilder) {
//$NON-NLS-1$
method.addBodyLine("return SQL();");
} else {
//$NON-NLS-1$
method.addBodyLine("return sql.toString();");
}
if (context.getPlugins().providerInsertSelectiveMethodGenerated(method, topLevelClass, introspectedTable)) {
topLevelClass.addStaticImports(staticImports);
topLevelClass.addImportedTypes(importedTypes);
topLevelClass.addMethod(method);
}
}
use of org.mybatis.generator.api.IntrospectedColumn in project generator by mybatis.
the class RecordWithBLOBsGenerator method addParameterizedConstructor.
private void addParameterizedConstructor(TopLevelClass topLevelClass) {
Method method = new Method();
method.setVisibility(JavaVisibility.PUBLIC);
method.setConstructor(true);
method.setName(topLevelClass.getType().getShortName());
context.getCommentGenerator().addGeneralMethodComment(method, introspectedTable);
for (IntrospectedColumn introspectedColumn : introspectedTable.getAllColumns()) {
method.addParameter(new Parameter(introspectedColumn.getFullyQualifiedJavaType(), introspectedColumn.getJavaProperty()));
topLevelClass.addImportedType(introspectedColumn.getFullyQualifiedJavaType());
}
boolean comma = false;
StringBuilder sb = new StringBuilder();
//$NON-NLS-1$
sb.append("super(");
for (IntrospectedColumn introspectedColumn : introspectedTable.getNonBLOBColumns()) {
if (comma) {
//$NON-NLS-1$
sb.append(", ");
} else {
comma = true;
}
sb.append(introspectedColumn.getJavaProperty());
}
//$NON-NLS-1$
sb.append(");");
method.addBodyLine(sb.toString());
for (IntrospectedColumn introspectedColumn : introspectedTable.getBLOBColumns()) {
sb.setLength(0);
//$NON-NLS-1$
sb.append("this.");
sb.append(introspectedColumn.getJavaProperty());
//$NON-NLS-1$
sb.append(" = ");
sb.append(introspectedColumn.getJavaProperty());
sb.append(';');
method.addBodyLine(sb.toString());
}
topLevelClass.addMethod(method);
}
use of org.mybatis.generator.api.IntrospectedColumn in project generator by mybatis.
the class SimpleModelGenerator method addParameterizedConstructor.
private void addParameterizedConstructor(TopLevelClass topLevelClass) {
Method method = new Method();
method.setVisibility(JavaVisibility.PUBLIC);
method.setConstructor(true);
method.setName(topLevelClass.getType().getShortName());
context.getCommentGenerator().addGeneralMethodComment(method, introspectedTable);
List<IntrospectedColumn> constructorColumns = introspectedTable.getAllColumns();
for (IntrospectedColumn introspectedColumn : constructorColumns) {
method.addParameter(new Parameter(introspectedColumn.getFullyQualifiedJavaType(), introspectedColumn.getJavaProperty()));
}
StringBuilder sb = new StringBuilder();
if (introspectedTable.getRules().generatePrimaryKeyClass()) {
boolean comma = false;
//$NON-NLS-1$
sb.append("super(");
for (IntrospectedColumn introspectedColumn : introspectedTable.getPrimaryKeyColumns()) {
if (comma) {
//$NON-NLS-1$
sb.append(", ");
} else {
comma = true;
}
sb.append(introspectedColumn.getJavaProperty());
}
//$NON-NLS-1$
sb.append(");");
method.addBodyLine(sb.toString());
}
List<IntrospectedColumn> introspectedColumns = introspectedTable.getAllColumns();
for (IntrospectedColumn introspectedColumn : introspectedColumns) {
sb.setLength(0);
//$NON-NLS-1$
sb.append("this.");
sb.append(introspectedColumn.getJavaProperty());
//$NON-NLS-1$
sb.append(" = ");
sb.append(introspectedColumn.getJavaProperty());
sb.append(';');
method.addBodyLine(sb.toString());
}
topLevelClass.addMethod(method);
}
Aggregations