use of org.mybatis.generator.api.IntrospectedColumn in project generator by mybatis.
the class BaseColumnListElementGenerator method addElements.
@Override
public void addElements(XmlElement parentElement) {
//$NON-NLS-1$
XmlElement answer = new XmlElement("sql");
answer.addAttribute(new //$NON-NLS-1$
Attribute(//$NON-NLS-1$
"id", introspectedTable.getBaseColumnListId()));
context.getCommentGenerator().addComment(answer);
StringBuilder sb = new StringBuilder();
Iterator<IntrospectedColumn> iter = introspectedTable.getNonBLOBColumns().iterator();
while (iter.hasNext()) {
sb.append(Ibatis2FormattingUtilities.getSelectListPhrase(iter.next()));
if (iter.hasNext()) {
//$NON-NLS-1$
sb.append(", ");
}
if (sb.length() > 80) {
answer.addElement(new TextElement(sb.toString()));
sb.setLength(0);
}
}
if (sb.length() > 0) {
answer.addElement(new TextElement(sb.toString()));
}
if (context.getPlugins().sqlMapBaseColumnListElementGenerated(answer, introspectedTable)) {
parentElement.addElement(answer);
}
}
use of org.mybatis.generator.api.IntrospectedColumn in project generator by mybatis.
the class SelectByPrimaryKeyMethodGenerator method getMethodShell.
private Method getMethodShell(Set<FullyQualifiedJavaType> importedTypes) {
Method method = new Method();
method.setVisibility(JavaVisibility.PUBLIC);
FullyQualifiedJavaType returnType = introspectedTable.getRules().calculateAllFieldsClass();
method.setReturnType(returnType);
importedTypes.add(returnType);
method.setName(getDAOMethodNameCalculator().getSelectByPrimaryKeyMethodName(introspectedTable));
if (introspectedTable.getRules().generatePrimaryKeyClass()) {
FullyQualifiedJavaType type = new FullyQualifiedJavaType(introspectedTable.getPrimaryKeyType());
importedTypes.add(type);
//$NON-NLS-1$
method.addParameter(new Parameter(type, "_key"));
} else {
for (IntrospectedColumn introspectedColumn : introspectedTable.getPrimaryKeyColumns()) {
FullyQualifiedJavaType type = introspectedColumn.getFullyQualifiedJavaType();
importedTypes.add(type);
method.addParameter(new Parameter(type, introspectedColumn.getJavaProperty()));
}
}
for (FullyQualifiedJavaType fqjt : daoTemplate.getCheckedExceptions()) {
method.addException(fqjt);
importedTypes.add(fqjt);
}
context.getCommentGenerator().addGeneralMethodComment(method, introspectedTable);
return method;
}
use of org.mybatis.generator.api.IntrospectedColumn in project generator by mybatis.
the class DeleteByPrimaryKeyMethodGenerator method getMethodShell.
private Method getMethodShell(Set<FullyQualifiedJavaType> importedTypes) {
Method method = new Method();
method.setVisibility(JavaVisibility.PUBLIC);
method.setReturnType(FullyQualifiedJavaType.getIntInstance());
method.setName(getDAOMethodNameCalculator().getDeleteByPrimaryKeyMethodName(introspectedTable));
if (introspectedTable.getRules().generatePrimaryKeyClass()) {
FullyQualifiedJavaType type = new FullyQualifiedJavaType(introspectedTable.getPrimaryKeyType());
importedTypes.add(type);
//$NON-NLS-1$
method.addParameter(new Parameter(type, "_key"));
} else {
for (IntrospectedColumn introspectedColumn : introspectedTable.getPrimaryKeyColumns()) {
FullyQualifiedJavaType type = introspectedColumn.getFullyQualifiedJavaType();
importedTypes.add(type);
method.addParameter(new Parameter(type, introspectedColumn.getJavaProperty()));
}
}
for (FullyQualifiedJavaType fqjt : daoTemplate.getCheckedExceptions()) {
method.addException(fqjt);
importedTypes.add(fqjt);
}
context.getCommentGenerator().addGeneralMethodComment(method, introspectedTable);
return method;
}
use of org.mybatis.generator.api.IntrospectedColumn in project generator by mybatis.
the class DeleteByPrimaryKeyMethodGenerator method addImplementationElements.
@Override
public void addImplementationElements(TopLevelClass topLevelClass) {
Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>();
Method method = getMethodShell(importedTypes);
StringBuilder sb = new StringBuilder();
if (!introspectedTable.getRules().generatePrimaryKeyClass()) {
// no primary key class, but primary key is enabled. Primary
// key columns must be in the base class.
FullyQualifiedJavaType keyType = new FullyQualifiedJavaType(introspectedTable.getBaseRecordType());
topLevelClass.addImportedType(keyType);
sb.setLength(0);
sb.append(keyType.getShortName());
//$NON-NLS-1$
sb.append(" _key = new ");
sb.append(keyType.getShortName());
//$NON-NLS-1$
sb.append("();");
method.addBodyLine(sb.toString());
for (IntrospectedColumn introspectedColumn : introspectedTable.getPrimaryKeyColumns()) {
sb.setLength(0);
//$NON-NLS-1$
sb.append("_key.");
sb.append(getSetterMethodName(introspectedColumn.getJavaProperty()));
sb.append('(');
sb.append(introspectedColumn.getJavaProperty());
//$NON-NLS-1$
sb.append(");");
method.addBodyLine(sb.toString());
}
}
sb.setLength(0);
//$NON-NLS-1$
sb.append("int rows = ");
sb.append(daoTemplate.getDeleteMethod(introspectedTable.getIbatis2SqlMapNamespace(), introspectedTable.getDeleteByPrimaryKeyStatementId(), //$NON-NLS-1$
"_key"));
method.addBodyLine(sb.toString());
//$NON-NLS-1$
method.addBodyLine("return rows;");
if (context.getPlugins().clientDeleteByPrimaryKeyMethodGenerated(method, topLevelClass, introspectedTable)) {
topLevelClass.addImportedTypes(importedTypes);
topLevelClass.addMethod(method);
}
}
use of org.mybatis.generator.api.IntrospectedColumn in project generator by mybatis.
the class BaseRecordGenerator 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 = includeBLOBColumns() ? introspectedTable.getAllColumns() : introspectedTable.getNonBLOBColumns();
for (IntrospectedColumn introspectedColumn : constructorColumns) {
method.addParameter(new Parameter(introspectedColumn.getFullyQualifiedJavaType(), introspectedColumn.getJavaProperty()));
topLevelClass.addImportedType(introspectedColumn.getFullyQualifiedJavaType());
}
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 = getColumnsInThisClass();
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