use of org.mybatis.generator.api.dom.java.FullyQualifiedJavaType in project generator by mybatis.
the class ExampleGenerator method getSetInOrNotInMethod.
/**
*
* @param introspectedColumn
* @param inMethod
* if true generates an "in" method, else generates a "not in"
* method
* @return a generated method for the in or not in method
*/
private Method getSetInOrNotInMethod(IntrospectedColumn introspectedColumn, boolean inMethod) {
Method method = new Method();
method.setVisibility(JavaVisibility.PUBLIC);
FullyQualifiedJavaType type = FullyQualifiedJavaType.getNewListInstance();
if (introspectedColumn.getFullyQualifiedJavaType().isPrimitive()) {
type.addTypeArgument(introspectedColumn.getFullyQualifiedJavaType().getPrimitiveTypeWrapper());
} else {
type.addTypeArgument(introspectedColumn.getFullyQualifiedJavaType());
}
//$NON-NLS-1$
method.addParameter(new Parameter(type, "values"));
StringBuilder sb = new StringBuilder();
sb.append(introspectedColumn.getJavaProperty());
sb.setCharAt(0, Character.toUpperCase(sb.charAt(0)));
//$NON-NLS-1$
sb.insert(0, "and");
if (inMethod) {
//$NON-NLS-1$
sb.append("In");
} else {
//$NON-NLS-1$
sb.append("NotIn");
}
method.setName(sb.toString());
method.setReturnType(FullyQualifiedJavaType.getCriteriaInstance());
sb.setLength(0);
if (introspectedColumn.isJDBCDateColumn()) {
//$NON-NLS-1$
sb.append("addCriterionForJDBCDate(\"");
} else if (introspectedColumn.isJDBCTimeColumn()) {
//$NON-NLS-1$
sb.append("addCriterionForJDBCTime(\"");
} else if (stringHasValue(introspectedColumn.getTypeHandler())) {
//$NON-NLS-1$
sb.append("add");
sb.append(introspectedColumn.getJavaProperty());
sb.setCharAt(3, Character.toUpperCase(sb.charAt(3)));
//$NON-NLS-1$
sb.append("Criterion(\"");
} else {
//$NON-NLS-1$
sb.append("addCriterion(\"");
}
sb.append(MyBatis3FormattingUtilities.getAliasedActualColumnName(introspectedColumn));
if (inMethod) {
//$NON-NLS-1$
sb.append(" in");
} else {
//$NON-NLS-1$
sb.append(" not in");
}
//$NON-NLS-1$
sb.append("\", values, \"");
sb.append(introspectedColumn.getJavaProperty());
//$NON-NLS-1$
sb.append("\");");
method.addBodyLine(sb.toString());
//$NON-NLS-1$
method.addBodyLine("return (Criteria) this;");
return method;
}
use of org.mybatis.generator.api.dom.java.FullyQualifiedJavaType in project generator by mybatis.
the class PrimaryKeyGenerator method getCompilationUnits.
@Override
public List<CompilationUnit> getCompilationUnits() {
FullyQualifiedTable table = introspectedTable.getFullyQualifiedTable();
progressCallback.startTask(getString("Progress.7", //$NON-NLS-1$
table.toString()));
Plugin plugins = context.getPlugins();
CommentGenerator commentGenerator = context.getCommentGenerator();
TopLevelClass topLevelClass = new TopLevelClass(introspectedTable.getPrimaryKeyType());
topLevelClass.setVisibility(JavaVisibility.PUBLIC);
commentGenerator.addJavaFileComment(topLevelClass);
String rootClass = getRootClass();
if (rootClass != null) {
topLevelClass.setSuperClass(new FullyQualifiedJavaType(rootClass));
topLevelClass.addImportedType(topLevelClass.getSuperClass());
}
if (introspectedTable.isConstructorBased()) {
addParameterizedConstructor(topLevelClass);
if (!introspectedTable.isImmutable()) {
addDefaultConstructor(topLevelClass);
}
}
commentGenerator.addModelClassComment(topLevelClass, introspectedTable);
for (IntrospectedColumn introspectedColumn : introspectedTable.getPrimaryKeyColumns()) {
if (RootClassInfo.getInstance(rootClass, warnings).containsProperty(introspectedColumn)) {
continue;
}
Field field = getJavaBeansField(introspectedColumn, context, introspectedTable);
if (plugins.modelFieldGenerated(field, topLevelClass, introspectedColumn, introspectedTable, Plugin.ModelClassType.PRIMARY_KEY)) {
topLevelClass.addField(field);
topLevelClass.addImportedType(field.getType());
}
Method method = getJavaBeansGetter(introspectedColumn, context, introspectedTable);
if (plugins.modelGetterMethodGenerated(method, topLevelClass, introspectedColumn, introspectedTable, Plugin.ModelClassType.PRIMARY_KEY)) {
topLevelClass.addMethod(method);
}
if (!introspectedTable.isImmutable()) {
method = getJavaBeansSetter(introspectedColumn, context, introspectedTable);
if (plugins.modelSetterMethodGenerated(method, topLevelClass, introspectedColumn, introspectedTable, Plugin.ModelClassType.PRIMARY_KEY)) {
topLevelClass.addMethod(method);
}
}
}
List<CompilationUnit> answer = new ArrayList<CompilationUnit>();
if (context.getPlugins().modelPrimaryKeyClassGenerated(topLevelClass, introspectedTable)) {
answer.add(topLevelClass);
}
return answer;
}
use of org.mybatis.generator.api.dom.java.FullyQualifiedJavaType in project generator by mybatis.
the class FullyQualifiedJavaTypeTest method testJavaType.
@Test
public void testJavaType() {
FullyQualifiedJavaType fqjt = //$NON-NLS-1$
new FullyQualifiedJavaType("java.lang.String");
assertFalse(fqjt.isExplicitlyImported());
//$NON-NLS-1$
assertEquals("String", fqjt.getShortName());
//$NON-NLS-1$
assertEquals("java.lang.String", fqjt.getFullyQualifiedName());
//$NON-NLS-1$
assertEquals("java.lang", fqjt.getPackageName());
assertEquals(0, fqjt.getImportList().size());
}
use of org.mybatis.generator.api.dom.java.FullyQualifiedJavaType in project generator by mybatis.
the class FullyQualifiedJavaTypeTest method testWildcardType3.
@Test
public void testWildcardType3() {
FullyQualifiedJavaType fqjt = new FullyQualifiedJavaType("java.util.Map<? extends java.util.List<?>, ?>");
assertTrue(fqjt.isExplicitlyImported());
//$NON-NLS-1$
assertEquals("Map<? extends List<?>, ?>", fqjt.getShortName());
//$NON-NLS-1$
assertEquals("java.util.Map<? extends java.util.List<?>, ?>", fqjt.getFullyQualifiedName());
//$NON-NLS-1$
assertEquals("java.util", fqjt.getPackageName());
assertEquals(2, fqjt.getImportList().size());
//$NON-NLS-1$
assertEquals("java.util.Map", fqjt.getFullyQualifiedNameWithoutTypeParameters());
}
use of org.mybatis.generator.api.dom.java.FullyQualifiedJavaType in project generator by mybatis.
the class SupersGenerator method getBaseInterface.
private Interface getBaseInterface() {
FullyQualifiedJavaType fqjt = new FullyQualifiedJavaType(BASE_PACKAGE + ".BaseInterface");
Interface ifc = new Interface(fqjt);
ifc.setVisibility(JavaVisibility.PUBLIC);
return ifc;
}
Aggregations