Java Code Examples for org.mybatis.generator.api.IntrospectedColumn#setJdbcTypeName()
The following examples show how to use
org.mybatis.generator.api.IntrospectedColumn#setJdbcTypeName() .
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: RenameExampleClassAndMethodsPluginTest.java From mybatis-generator-plugins with Apache License 2.0 | 5 votes |
@SuppressWarnings({ "unchecked", "rawtypes" }) @Test public void shouldRemoveIdColumnsFromUpdateStatements() throws Exception { RenameExampleClassAndMethodsPlugin plugin = spy(this.plugin); IntrospectedColumn column = new IntrospectedColumn(); column.setActualColumnName("actual_name"); column.setJavaProperty("someProperty"); column.setJdbcTypeName("DOUBLE"); List<IntrospectedColumn> columns = new ArrayList<>(); columns.add(column); // Given willDoNothing().given(plugin).removeIdColumns(anyListOf(String.class), any(Element.class), any(XmlElement.class), anyInt()); given(introspectedTable.getPrimaryKeyColumns()).willReturn(columns); given(tableConfiguration.getAlias()).willReturn("alias"); // When plugin.removeIdColumns(introspectedTable, element); // Then ArgumentCaptor<List> updatesCaptor = ArgumentCaptor.forClass(List.class); verify(plugin, times(1)).removeIdColumns(updatesCaptor.capture(), eq(element), isNull(XmlElement.class), eq(-1)); List<String> updates = updatesCaptor.getValue(); assertThat(updates).hasSameSizeAs(columns); String update = updates.get(0); assertThat(update).isEqualTo("alias.actual_name = #{record.someProperty,jdbcType=DOUBLE},"); }
Example 2
Source File: DatabaseIntrospector.java From mapper-generator-javafx with Apache License 2.0 | 4 votes |
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(); 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 = true; if (tc.isColumnIgnored(introspectedColumn .getActualColumnName())) { warn = false; } 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()); introspectedColumn.setJdbcTypeName("OTHER"); String warning = getString("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); } } } }
Example 3
Source File: DatabaseIntrospector.java From mapper-generator-javafx with Apache License 2.0 | 4 votes |
private void applyColumnOverrides(TableConfiguration tc, Map<ActualTableName, List<IntrospectedColumn>> columns) { for (Map.Entry<ActualTableName, List<IntrospectedColumn>> entry : columns .entrySet()) { for (IntrospectedColumn introspectedColumn : entry.getValue()) { ColumnOverride columnOverride = tc .getColumnOverride(introspectedColumn .getActualColumnName()); if (columnOverride != null) { if (logger.isDebugEnabled()) { logger.debug(getString("Tracing.4", introspectedColumn.getActualColumnName(), entry .getKey().toString())); } if (stringHasValue(columnOverride .getJavaProperty())) { introspectedColumn.setJavaProperty(columnOverride .getJavaProperty()); } if (stringHasValue(columnOverride .getJavaType())) { introspectedColumn .setFullyQualifiedJavaType(new FullyQualifiedJavaType( columnOverride.getJavaType())); } if (stringHasValue(columnOverride .getJdbcType())) { introspectedColumn.setJdbcTypeName(columnOverride .getJdbcType()); } if (stringHasValue(columnOverride .getTypeHandler())) { introspectedColumn.setTypeHandler(columnOverride .getTypeHandler()); } if (columnOverride.isColumnNameDelimited()) { introspectedColumn.setColumnNameDelimited(true); } introspectedColumn.setGeneratedAlways(columnOverride.isGeneratedAlways()); introspectedColumn.setProperties(columnOverride .getProperties()); } } } }
Example 4
Source File: DatabaseIntrospector.java From mybatis-generator-core-fix with Apache License 2.0 | 4 votes |
/** * Apply column overrides. * * @param tc * the tc * @param columns * the columns */ private void applyColumnOverrides(TableConfiguration tc, Map<ActualTableName, List<IntrospectedColumn>> columns) { for (Map.Entry<ActualTableName, List<IntrospectedColumn>> entry : columns .entrySet()) { for (IntrospectedColumn introspectedColumn : entry.getValue()) { ColumnOverride columnOverride = tc .getColumnOverride(introspectedColumn .getActualColumnName()); if (columnOverride != null) { if (logger.isDebugEnabled()) { logger.debug(getString("Tracing.4", //$NON-NLS-1$ introspectedColumn.getActualColumnName(), entry .getKey().toString())); } if (stringHasValue(columnOverride .getJavaProperty())) { introspectedColumn.setJavaProperty(columnOverride .getJavaProperty()); } if (stringHasValue(columnOverride .getJavaType())) { introspectedColumn .setFullyQualifiedJavaType(new FullyQualifiedJavaType( columnOverride.getJavaType())); } if (stringHasValue(columnOverride .getJdbcType())) { introspectedColumn.setJdbcTypeName(columnOverride .getJdbcType()); } if (stringHasValue(columnOverride .getTypeHandler())) { introspectedColumn.setTypeHandler(columnOverride .getTypeHandler()); } if (columnOverride.isColumnNameDelimited()) { introspectedColumn.setColumnNameDelimited(true); } introspectedColumn.setProperties(columnOverride .getProperties()); } } } }
Example 5
Source File: DatabaseIntrospector.java From mybatis-generator-plus with Apache License 2.0 | 4 votes |
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(); replaceString = replaceString == null ? "" : replaceString; //$NON-NLS-1$ } 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( getValidPropertyName(calculatedColumnName)); } else if (isTrue(tc .getProperty(PropertyRegistry.TABLE_USE_COMPOUND_PROPERTY_NAMES))) { sb.setLength(0); sb.append(calculatedColumnName); sb.append('_'); sb.append(getCamelCaseString( introspectedColumn.getRemarks(), true)); introspectedColumn.setJavaProperty( getValidPropertyName(sb.toString())); } else { introspectedColumn.setJavaProperty( 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 = true; if (tc.isColumnIgnored(introspectedColumn .getActualColumnName())) { warn = false; } ColumnOverride co = tc.getColumnOverride(introspectedColumn .getActualColumnName()); if (co != null) { if (stringHasValue(co.getJavaType()) && stringHasValue(co.getJavaType())) { warn = false; } } // if the type is not supported, then we'll report a warning if (warn) { introspectedColumn .setFullyQualifiedJavaType(FullyQualifiedJavaType .getObjectInstance()); introspectedColumn.setJdbcTypeName("OTHER"); //$NON-NLS-1$ String warning = getString("Warning.14", //$NON-NLS-1$ Integer.toString(introspectedColumn.getJdbcType()), entry.getKey().toString(), introspectedColumn.getActualColumnName()); warnings.add(warning); } } if (context.autoDelimitKeywords()) { if (SqlReservedWords.containsWord(introspectedColumn .getActualColumnName())) { introspectedColumn.setColumnNameDelimited(true); } } if (tc.isAllColumnDelimitingEnabled()) { introspectedColumn.setColumnNameDelimited(true); } } } }
Example 6
Source File: DatabaseIntrospector.java From mybatis-generator-plus with Apache License 2.0 | 4 votes |
private void applyColumnOverrides(TableConfiguration tc, Map<ActualTableName, List<IntrospectedColumn>> columns) { for (Map.Entry<ActualTableName, List<IntrospectedColumn>> entry : columns .entrySet()) { for (IntrospectedColumn introspectedColumn : entry.getValue()) { ColumnOverride columnOverride = tc .getColumnOverride(introspectedColumn .getActualColumnName()); if (columnOverride != null) { if (logger.isDebugEnabled()) { logger.debug(getString("Tracing.4", //$NON-NLS-1$ introspectedColumn.getActualColumnName(), entry .getKey().toString())); } if (stringHasValue(columnOverride .getJavaProperty())) { introspectedColumn.setJavaProperty(columnOverride .getJavaProperty()); } if (stringHasValue(columnOverride .getJavaType())) { introspectedColumn .setFullyQualifiedJavaType(new FullyQualifiedJavaType( columnOverride.getJavaType())); } if (stringHasValue(columnOverride .getJdbcType())) { introspectedColumn.setJdbcTypeName(columnOverride .getJdbcType()); } if (stringHasValue(columnOverride .getTypeHandler())) { introspectedColumn.setTypeHandler(columnOverride .getTypeHandler()); } if (columnOverride.isColumnNameDelimited()) { introspectedColumn.setColumnNameDelimited(true); } introspectedColumn.setProperties(columnOverride .getProperties()); } } } }