Java Code Examples for org.mybatis.generator.api.dom.java.FullyQualifiedJavaType#isPrimitive()
The following examples show how to use
org.mybatis.generator.api.dom.java.FullyQualifiedJavaType#isPrimitive() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WrapObjectPlugin.java From mybatis-generator-plugins with Apache License 2.0 | 5 votes |
private boolean objectClassHasFieldGetter(Field field) { FullyQualifiedJavaType type = field.getType(); String prefix = type.isPrimitive() && type.getShortName().equals("boolean") ? "is" : "get"; String capitalized = StringUtils.capitalize(field.getName()); String getterName = prefix + capitalized; String setterName = "set" + capitalized; String wrappedGetter = getterName; if (hasGetter(getterName)) { gettersToWrap.add(getterName); settersToWrap.add(setterName); wrappedGetters.put(getterName, wrappedGetter); return true; } // Check for possibility of boolean mismatch field (Boolean/boolean) if (type.isPrimitive() && type.getShortName().equals("boolean") && hasGetter("get" + capitalized)) { gettersToWrap.add(getterName); settersToWrap.add(setterName); wrappedGetters.put(getterName, "get" + capitalized); return true; } else if (!type.isPrimitive() && type.getFullyQualifiedName().equals("java.lang.Boolean") && hasGetter("is" + capitalized)) { gettersToWrap.add(getterName); settersToWrap.add(setterName); wrappedGetters.put(getterName, "is" + capitalized); return true; } return false; }
Example 2
Source File: InsertMethodGenerator.java From mybatis-generator-core-fix with Apache License 2.0 | 4 votes |
@Override public void addImplementationElements(TopLevelClass topLevelClass) { Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>(); Method method = getMethodShell(importedTypes); FullyQualifiedJavaType returnType = method.getReturnType(); StringBuilder sb = new StringBuilder(); if (returnType != null) { sb.append("Object newKey = "); //$NON-NLS-1$ } sb.append(daoTemplate.getInsertMethod(introspectedTable .getIbatis2SqlMapNamespace(), introspectedTable .getInsertStatementId(), "record")); //$NON-NLS-1$ method.addBodyLine(sb.toString()); if (returnType != null) { if ("Object".equals(returnType.getShortName())) { //$NON-NLS-1$ // no need to cast if the return type is Object method.addBodyLine("return newKey;"); //$NON-NLS-1$ } else { sb.setLength(0); if (returnType.isPrimitive()) { PrimitiveTypeWrapper ptw = returnType .getPrimitiveTypeWrapper(); sb.append("return (("); //$NON-NLS-1$ sb.append(ptw.getShortName()); sb.append(") newKey"); //$NON-NLS-1$ sb.append(")."); //$NON-NLS-1$ sb.append(ptw.getToPrimitiveMethod()); sb.append(';'); } else { sb.append("return ("); //$NON-NLS-1$ sb.append(returnType.getShortName()); sb.append(") newKey;"); //$NON-NLS-1$ } method.addBodyLine(sb.toString()); } } if (context.getPlugins().clientInsertMethodGenerated(method, topLevelClass, introspectedTable)) { topLevelClass.addImportedTypes(importedTypes); topLevelClass.addMethod(method); } }
Example 3
Source File: InsertSelectiveMethodGenerator.java From mybatis-generator-core-fix with Apache License 2.0 | 4 votes |
@Override public void addImplementationElements(TopLevelClass topLevelClass) { Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>(); Method method = getMethodShell(importedTypes); FullyQualifiedJavaType returnType = method.getReturnType(); StringBuilder sb = new StringBuilder(); if (returnType != null) { sb.append("Object newKey = "); //$NON-NLS-1$ } sb.append(daoTemplate.getInsertMethod(introspectedTable .getIbatis2SqlMapNamespace(), introspectedTable .getInsertSelectiveStatementId(), "record")); //$NON-NLS-1$ method.addBodyLine(sb.toString()); if (returnType != null) { if ("Object".equals(returnType.getShortName())) { //$NON-NLS-1$ // no need to cast if the return type is Object method.addBodyLine("return newKey;"); //$NON-NLS-1$ } else { sb.setLength(0); if (returnType.isPrimitive()) { PrimitiveTypeWrapper ptw = returnType .getPrimitiveTypeWrapper(); sb.append("return (("); //$NON-NLS-1$ sb.append(ptw.getShortName()); sb.append(") newKey"); //$NON-NLS-1$ sb.append(")."); //$NON-NLS-1$ sb.append(ptw.getToPrimitiveMethod()); sb.append(';'); } else { sb.append("return ("); //$NON-NLS-1$ sb.append(returnType.getShortName()); sb.append(") newKey;"); //$NON-NLS-1$ } method.addBodyLine(sb.toString()); } } if (context.getPlugins().clientInsertSelectiveMethodGenerated( method, topLevelClass, introspectedTable)) { topLevelClass.addImportedTypes(importedTypes); topLevelClass.addMethod(method); } }
Example 4
Source File: InsertMethodGenerator.java From mybatis-generator-plus with Apache License 2.0 | 4 votes |
@Override public void addImplementationElements(TopLevelClass topLevelClass) { Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>(); Method method = getMethodShell(importedTypes); FullyQualifiedJavaType returnType = method.getReturnType(); StringBuilder sb = new StringBuilder(); if (returnType != null) { sb.append("Object newKey = "); //$NON-NLS-1$ } sb.append(daoTemplate.getInsertMethod(introspectedTable .getIbatis2SqlMapNamespace(), introspectedTable .getInsertStatementId(), "record")); //$NON-NLS-1$ method.addBodyLine(sb.toString()); if (returnType != null) { if ("Object".equals(returnType.getShortName())) { //$NON-NLS-1$ // no need to cast if the return type is Object method.addBodyLine("return newKey;"); //$NON-NLS-1$ } else { sb.setLength(0); if (returnType.isPrimitive()) { PrimitiveTypeWrapper ptw = returnType .getPrimitiveTypeWrapper(); sb.append("return (("); //$NON-NLS-1$ sb.append(ptw.getShortName()); sb.append(") newKey"); //$NON-NLS-1$ sb.append(")."); //$NON-NLS-1$ sb.append(ptw.getToPrimitiveMethod()); sb.append(';'); } else { sb.append("return ("); //$NON-NLS-1$ sb.append(returnType.getShortName()); sb.append(") newKey;"); //$NON-NLS-1$ } method.addBodyLine(sb.toString()); } } if (context.getPlugins().clientInsertMethodGenerated(method, topLevelClass, introspectedTable)) { topLevelClass.addImportedTypes(importedTypes); topLevelClass.addMethod(method); } }
Example 5
Source File: InsertSelectiveMethodGenerator.java From mybatis-generator-plus with Apache License 2.0 | 4 votes |
@Override public void addImplementationElements(TopLevelClass topLevelClass) { Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>(); Method method = getMethodShell(importedTypes); FullyQualifiedJavaType returnType = method.getReturnType(); StringBuilder sb = new StringBuilder(); if (returnType != null) { sb.append("Object newKey = "); //$NON-NLS-1$ } sb.append(daoTemplate.getInsertMethod(introspectedTable .getIbatis2SqlMapNamespace(), introspectedTable .getInsertSelectiveStatementId(), "record")); //$NON-NLS-1$ method.addBodyLine(sb.toString()); if (returnType != null) { if ("Object".equals(returnType.getShortName())) { //$NON-NLS-1$ // no need to cast if the return type is Object method.addBodyLine("return newKey;"); //$NON-NLS-1$ } else { sb.setLength(0); if (returnType.isPrimitive()) { PrimitiveTypeWrapper ptw = returnType .getPrimitiveTypeWrapper(); sb.append("return (("); //$NON-NLS-1$ sb.append(ptw.getShortName()); sb.append(") newKey"); //$NON-NLS-1$ sb.append(")."); //$NON-NLS-1$ sb.append(ptw.getToPrimitiveMethod()); sb.append(';'); } else { sb.append("return ("); //$NON-NLS-1$ sb.append(returnType.getShortName()); sb.append(") newKey;"); //$NON-NLS-1$ } method.addBodyLine(sb.toString()); } } if (context.getPlugins().clientInsertSelectiveMethodGenerated( method, topLevelClass, introspectedTable)) { topLevelClass.addImportedTypes(importedTypes); topLevelClass.addMethod(method); } }