use of org.mybatis.generator.api.IntrospectedColumn in project generator by mybatis.
the class UpdateByPrimaryKeyWithoutBLOBsElementGenerator method addElements.
@Override
public void addElements(XmlElement parentElement) {
List<IntrospectedColumn> columns;
if (isSimple) {
columns = introspectedTable.getNonPrimaryKeyColumns();
} else {
columns = introspectedTable.getBaseColumns();
}
XmlElement answer = buildUpdateByPrimaryKeyElement(introspectedTable.getUpdateByPrimaryKeyStatementId(), introspectedTable.getBaseRecordType(), columns);
if (context.getPlugins().sqlMapUpdateByPrimaryKeyWithoutBLOBsElementGenerated(answer, introspectedTable)) {
parentElement.addElement(answer);
}
}
use of org.mybatis.generator.api.IntrospectedColumn in project generator by mybatis.
the class ObjectFactory method createIntrospectedColumn.
public static IntrospectedColumn createIntrospectedColumn(Context context) {
String type = context.getIntrospectedColumnImpl();
if (!stringHasValue(type)) {
type = IntrospectedColumn.class.getName();
}
IntrospectedColumn answer = (IntrospectedColumn) createInternalObject(type);
answer.setContext(context);
return answer;
}
use of org.mybatis.generator.api.IntrospectedColumn in project generator by mybatis.
the class ExampleWhereClauseElementGenerator method addElements.
@Override
public void addElements(XmlElement parentElement) {
// $NON-NLS-1$
XmlElement answer = new XmlElement("sql");
if (isForUpdateByExample) {
answer.addAttribute(new Attribute("id", // $NON-NLS-1$
introspectedTable.getMyBatis3UpdateByExampleWhereClauseId()));
} else {
answer.addAttribute(new Attribute("id", // $NON-NLS-1$
introspectedTable.getExampleWhereClauseId()));
}
context.getCommentGenerator().addComment(answer);
// $NON-NLS-1$
XmlElement whereElement = new XmlElement("where");
answer.addElement(whereElement);
// $NON-NLS-1$
XmlElement outerForEachElement = new XmlElement("foreach");
if (isForUpdateByExample) {
outerForEachElement.addAttribute(new Attribute("collection", // $NON-NLS-1$ //$NON-NLS-2$
"example.oredCriteria"));
} else {
outerForEachElement.addAttribute(new Attribute("collection", // $NON-NLS-1$ //$NON-NLS-2$
"oredCriteria"));
}
// $NON-NLS-1$ //$NON-NLS-2$
outerForEachElement.addAttribute(new Attribute("item", "criteria"));
// $NON-NLS-1$ //$NON-NLS-2$
outerForEachElement.addAttribute(new Attribute("separator", "or"));
whereElement.addElement(outerForEachElement);
// $NON-NLS-1$
XmlElement ifElement = new XmlElement("if");
// $NON-NLS-1$ //$NON-NLS-2$
ifElement.addAttribute(new Attribute("test", "criteria.valid"));
outerForEachElement.addElement(ifElement);
// $NON-NLS-1$
XmlElement trimElement = new XmlElement("trim");
// $NON-NLS-1$ //$NON-NLS-2$
trimElement.addAttribute(new Attribute("prefix", "("));
// $NON-NLS-1$ //$NON-NLS-2$
trimElement.addAttribute(new Attribute("suffix", ")"));
// $NON-NLS-1$ //$NON-NLS-2$
trimElement.addAttribute(new Attribute("prefixOverrides", "and"));
ifElement.addElement(trimElement);
trimElement.addElement(getMiddleForEachElement(null));
for (IntrospectedColumn introspectedColumn : introspectedTable.getNonBLOBColumns()) {
if (stringHasValue(introspectedColumn.getTypeHandler())) {
trimElement.addElement(getMiddleForEachElement(introspectedColumn));
}
}
if (context.getPlugins().sqlMapExampleWhereClauseElementGenerated(answer, introspectedTable)) {
parentElement.addElement(answer);
}
}
use of org.mybatis.generator.api.IntrospectedColumn in project generator by mybatis.
the class UpdateByExampleSelectiveElementGenerator method addElements.
@Override
public void addElements(XmlElement parentElement) {
// $NON-NLS-1$
XmlElement answer = new XmlElement("update");
answer.addAttribute(new Attribute("id", // $NON-NLS-1$
introspectedTable.getUpdateByExampleSelectiveStatementId()));
// $NON-NLS-1$ //$NON-NLS-2$
answer.addAttribute(new Attribute("parameterType", "map"));
context.getCommentGenerator().addComment(answer);
StringBuilder sb = new StringBuilder();
// $NON-NLS-1$
sb.append("update ");
sb.append(introspectedTable.getAliasedFullyQualifiedTableNameAtRuntime());
answer.addElement(new TextElement(sb.toString()));
// $NON-NLS-1$
XmlElement dynamicElement = new XmlElement("set");
answer.addElement(dynamicElement);
for (IntrospectedColumn introspectedColumn : ListUtilities.removeGeneratedAlwaysColumns(introspectedTable.getAllColumns())) {
sb.setLength(0);
// $NON-NLS-1$
sb.append(introspectedColumn.getJavaProperty("row."));
// $NON-NLS-1$
sb.append(" != null");
// $NON-NLS-1$
XmlElement isNotNullElement = new XmlElement("if");
// $NON-NLS-1$
isNotNullElement.addAttribute(new Attribute("test", sb.toString()));
dynamicElement.addElement(isNotNullElement);
sb.setLength(0);
sb.append(MyBatis3FormattingUtilities.getAliasedEscapedColumnName(introspectedColumn));
// $NON-NLS-1$
sb.append(" = ");
// $NON-NLS-1$
sb.append(MyBatis3FormattingUtilities.getParameterClause(introspectedColumn, "row."));
sb.append(',');
isNotNullElement.addElement(new TextElement(sb.toString()));
}
answer.addElement(getUpdateByExampleIncludeElement());
if (context.getPlugins().sqlMapUpdateByExampleSelectiveElementGenerated(answer, introspectedTable)) {
parentElement.addElement(answer);
}
}
use of org.mybatis.generator.api.IntrospectedColumn in project generator by mybatis.
the class DatabaseIntrospector method calculateExtraColumnInformation.
private void calculateExtraColumnInformation(TableConfiguration tc, Map<ActualTableName, List<IntrospectedColumn>> columns) {
StringBuilder sb = new StringBuilder();
Pattern pattern = null;
String replaceString = null;
if (tc.getColumnRenamingRule() != null) {
pattern = Pattern.compile(tc.getColumnRenamingRule().getSearchString());
replaceString = tc.getColumnRenamingRule().getReplaceString();
// $NON-NLS-1$
replaceString = replaceString == null ? "" : replaceString;
}
for (Map.Entry<ActualTableName, List<IntrospectedColumn>> entry : columns.entrySet()) {
for (IntrospectedColumn introspectedColumn : entry.getValue()) {
String calculatedColumnName;
if (pattern == null) {
calculatedColumnName = introspectedColumn.getActualColumnName();
} else {
Matcher matcher = pattern.matcher(introspectedColumn.getActualColumnName());
calculatedColumnName = matcher.replaceAll(replaceString);
}
if (isTrue(tc.getProperty(PropertyRegistry.TABLE_USE_ACTUAL_COLUMN_NAMES))) {
introspectedColumn.setJavaProperty(JavaBeansUtil.getValidPropertyName(calculatedColumnName));
} else if (isTrue(tc.getProperty(PropertyRegistry.TABLE_USE_COMPOUND_PROPERTY_NAMES))) {
sb.setLength(0);
sb.append(calculatedColumnName);
sb.append('_');
sb.append(JavaBeansUtil.getCamelCaseString(introspectedColumn.getRemarks(), true));
introspectedColumn.setJavaProperty(JavaBeansUtil.getValidPropertyName(sb.toString()));
} else {
introspectedColumn.setJavaProperty(JavaBeansUtil.getCamelCaseString(calculatedColumnName, false));
}
FullyQualifiedJavaType fullyQualifiedJavaType = javaTypeResolver.calculateJavaType(introspectedColumn);
if (fullyQualifiedJavaType != null) {
introspectedColumn.setFullyQualifiedJavaType(fullyQualifiedJavaType);
introspectedColumn.setJdbcTypeName(javaTypeResolver.calculateJdbcTypeName(introspectedColumn));
} else {
// type cannot be resolved. Check for ignored or overridden
boolean warn = !tc.isColumnIgnored(introspectedColumn.getActualColumnName());
ColumnOverride co = tc.getColumnOverride(introspectedColumn.getActualColumnName());
if (co != null && stringHasValue(co.getJavaType())) {
warn = false;
}
// if the type is not supported, then we'll report a warning
if (warn) {
introspectedColumn.setFullyQualifiedJavaType(FullyQualifiedJavaType.getObjectInstance());
// $NON-NLS-1$
introspectedColumn.setJdbcTypeName("OTHER");
String warning = getString(// $NON-NLS-1$
"Warning.14", Integer.toString(introspectedColumn.getJdbcType()), entry.getKey().toString(), introspectedColumn.getActualColumnName());
warnings.add(warning);
}
}
if (context.autoDelimitKeywords() && SqlReservedWords.containsWord(introspectedColumn.getActualColumnName())) {
introspectedColumn.setColumnNameDelimited(true);
}
if (tc.isAllColumnDelimitingEnabled()) {
introspectedColumn.setColumnNameDelimited(true);
}
}
}
}
Aggregations