use of org.mybatis.generator.api.IntrospectedColumn in project generator by mybatis.
the class AnnotatedSelectByExampleWithBLOBsMethodGenerator method addMapperAnnotations.
@Override
public void addMapperAnnotations(Interface interfaze, Method method) {
FullyQualifiedJavaType fqjt = new FullyQualifiedJavaType(introspectedTable.getMyBatis3SqlProviderType());
StringBuilder sb = new StringBuilder();
//$NON-NLS-1$
sb.append("@SelectProvider(type=");
sb.append(fqjt.getShortName());
//$NON-NLS-1$
sb.append(".class, method=\"");
sb.append(introspectedTable.getSelectByExampleWithBLOBsStatementId());
//$NON-NLS-1$
sb.append("\")");
method.addAnnotation(sb.toString());
if (introspectedTable.isConstructorBased()) {
//$NON-NLS-1$
method.addAnnotation("@ConstructorArgs({");
} else {
//$NON-NLS-1$
method.addAnnotation("@Results({");
}
Iterator<IntrospectedColumn> iterPk = introspectedTable.getPrimaryKeyColumns().iterator();
Iterator<IntrospectedColumn> iterNonPk = introspectedTable.getNonPrimaryKeyColumns().iterator();
while (iterPk.hasNext()) {
IntrospectedColumn introspectedColumn = iterPk.next();
sb.setLength(0);
javaIndent(sb, 1);
sb.append(getResultAnnotation(interfaze, introspectedColumn, true, introspectedTable.isConstructorBased()));
if (iterPk.hasNext() || iterNonPk.hasNext()) {
sb.append(',');
}
method.addAnnotation(sb.toString());
}
while (iterNonPk.hasNext()) {
IntrospectedColumn introspectedColumn = iterNonPk.next();
sb.setLength(0);
javaIndent(sb, 1);
sb.append(getResultAnnotation(interfaze, introspectedColumn, false, introspectedTable.isConstructorBased()));
if (iterNonPk.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 AnnotatedSelectByPrimaryKeyMethodGenerator method addAnnotatedResults.
private void addAnnotatedResults(Interface interfaze, Method method) {
if (introspectedTable.isConstructorBased()) {
//$NON-NLS-1$
method.addAnnotation("@ConstructorArgs({");
} else {
//$NON-NLS-1$
method.addAnnotation("@Results({");
}
StringBuilder sb = new StringBuilder();
Iterator<IntrospectedColumn> iterPk = introspectedTable.getPrimaryKeyColumns().iterator();
Iterator<IntrospectedColumn> iterNonPk = introspectedTable.getNonPrimaryKeyColumns().iterator();
while (iterPk.hasNext()) {
IntrospectedColumn introspectedColumn = iterPk.next();
sb.setLength(0);
javaIndent(sb, 1);
sb.append(getResultAnnotation(interfaze, introspectedColumn, true, introspectedTable.isConstructorBased()));
if (iterPk.hasNext() || iterNonPk.hasNext()) {
sb.append(',');
}
method.addAnnotation(sb.toString());
}
while (iterNonPk.hasNext()) {
IntrospectedColumn introspectedColumn = iterNonPk.next();
sb.setLength(0);
javaIndent(sb, 1);
sb.append(getResultAnnotation(interfaze, introspectedColumn, false, introspectedTable.isConstructorBased()));
if (iterNonPk.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 DeleteByPrimaryKeyMethodGenerator method addInterfaceElements.
@Override
public void addInterfaceElements(Interface interfaze) {
Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>();
Method method = new Method();
method.setVisibility(JavaVisibility.PUBLIC);
method.setReturnType(FullyQualifiedJavaType.getIntInstance());
method.setName(introspectedTable.getDeleteByPrimaryKeyStatementId());
if (!isSimple && introspectedTable.getRules().generatePrimaryKeyClass()) {
FullyQualifiedJavaType type = new FullyQualifiedJavaType(introspectedTable.getPrimaryKeyType());
importedTypes.add(type);
//$NON-NLS-1$
method.addParameter(new Parameter(type, "key"));
} else {
// no primary key class - fields are in the base class
// if more than one PK field, then we need to annotate the
// parameters
// for MyBatis
List<IntrospectedColumn> introspectedColumns = introspectedTable.getPrimaryKeyColumns();
boolean annotate = introspectedColumns.size() > 1;
if (annotate) {
importedTypes.add(new FullyQualifiedJavaType(//$NON-NLS-1$
"org.apache.ibatis.annotations.Param"));
}
StringBuilder sb = new StringBuilder();
for (IntrospectedColumn introspectedColumn : introspectedColumns) {
FullyQualifiedJavaType type = introspectedColumn.getFullyQualifiedJavaType();
importedTypes.add(type);
Parameter parameter = new Parameter(type, introspectedColumn.getJavaProperty());
if (annotate) {
sb.setLength(0);
//$NON-NLS-1$
sb.append("@Param(\"");
sb.append(introspectedColumn.getJavaProperty());
//$NON-NLS-1$
sb.append("\")");
parameter.addAnnotation(sb.toString());
}
method.addParameter(parameter);
}
}
context.getCommentGenerator().addGeneralMethodComment(method, introspectedTable);
addMapperAnnotations(method);
if (context.getPlugins().clientDeleteByPrimaryKeyMethodGenerated(method, interfaze, introspectedTable)) {
addExtraImports(interfaze);
interfaze.addImportedTypes(importedTypes);
interfaze.addMethod(method);
}
}
use of org.mybatis.generator.api.IntrospectedColumn in project generator by mybatis.
the class SelectByPrimaryKeyMethodGenerator method addInterfaceElements.
@Override
public void addInterfaceElements(Interface interfaze) {
Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>();
Method method = new Method();
method.setVisibility(JavaVisibility.PUBLIC);
FullyQualifiedJavaType returnType = introspectedTable.getRules().calculateAllFieldsClass();
method.setReturnType(returnType);
importedTypes.add(returnType);
method.setName(introspectedTable.getSelectByPrimaryKeyStatementId());
if (!isSimple && introspectedTable.getRules().generatePrimaryKeyClass()) {
FullyQualifiedJavaType type = new FullyQualifiedJavaType(introspectedTable.getPrimaryKeyType());
importedTypes.add(type);
//$NON-NLS-1$
method.addParameter(new Parameter(type, "key"));
} else {
// no primary key class - fields are in the base class
// if more than one PK field, then we need to annotate the
// parameters
// for MyBatis3
List<IntrospectedColumn> introspectedColumns = introspectedTable.getPrimaryKeyColumns();
boolean annotate = introspectedColumns.size() > 1;
if (annotate) {
importedTypes.add(new FullyQualifiedJavaType(//$NON-NLS-1$
"org.apache.ibatis.annotations.Param"));
}
StringBuilder sb = new StringBuilder();
for (IntrospectedColumn introspectedColumn : introspectedColumns) {
FullyQualifiedJavaType type = introspectedColumn.getFullyQualifiedJavaType();
importedTypes.add(type);
Parameter parameter = new Parameter(type, introspectedColumn.getJavaProperty());
if (annotate) {
sb.setLength(0);
//$NON-NLS-1$
sb.append("@Param(\"");
sb.append(introspectedColumn.getJavaProperty());
//$NON-NLS-1$
sb.append("\")");
parameter.addAnnotation(sb.toString());
}
method.addParameter(parameter);
}
}
addMapperAnnotations(interfaze, method);
context.getCommentGenerator().addGeneralMethodComment(method, introspectedTable);
if (context.getPlugins().clientSelectByPrimaryKeyMethodGenerated(method, interfaze, introspectedTable)) {
addExtraImports(interfaze);
interfaze.addImportedTypes(importedTypes);
interfaze.addMethod(method);
}
}
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();
TopLevelClass topLevelClass = new TopLevelClass(introspectedTable.getBaseRecordType());
topLevelClass.setVisibility(JavaVisibility.PUBLIC);
commentGenerator.addJavaFileComment(topLevelClass);
FullyQualifiedJavaType superClass = getSuperClass();
if (superClass != null) {
topLevelClass.setSuperClass(superClass);
topLevelClass.addImportedType(superClass);
}
List<IntrospectedColumn> introspectedColumns;
if (includePrimaryKeyColumns()) {
if (includeBLOBColumns()) {
introspectedColumns = introspectedTable.getAllColumns();
} else {
introspectedColumns = introspectedTable.getNonBLOBColumns();
}
} else {
if (includeBLOBColumns()) {
introspectedColumns = introspectedTable.getNonPrimaryKeyColumns();
} else {
introspectedColumns = introspectedTable.getBaseColumns();
}
}
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);
}
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;
}
Aggregations