Java源码示例:org.mybatis.generator.api.dom.java.PrimitiveTypeWrapper

示例1
@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);
    }
}
 
示例2
@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);
    }
}
 
示例3
@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);
    }
}
 
示例4
@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);
    }
}