public void setScale(String newVal, DbAttribute attr) { if (newVal == null || newVal.trim().length() <= 0) { attr.setScale(-1); } else { try { attr.setScale(Integer.parseInt(newVal)); } catch (NumberFormatException ex) { JOptionPane.showMessageDialog( null, "Invalid precision (" + newVal + "), only numbers are allowed.", "Invalid Precision Value", JOptionPane.ERROR_MESSAGE); } } }
private void processStartDbAttribute(Attributes atts) { String name = atts.getValue("", "name"); String type = atts.getValue("", "type"); attrib = new DbAttribute(name); attrib.setType(TypesMapping.getSqlTypeByName(type)); dbEntity.addAttribute(attrib); String length = atts.getValue("", "length"); if (length != null) { attrib.setMaxLength(Integer.parseInt(length)); } // this is an obsolete 1.2 'precision' attribute that really meant // 'scale' String pseudoPrecision = atts.getValue("", "precision"); if (pseudoPrecision != null) { attrib.setScale(Integer.parseInt(pseudoPrecision)); } String precision = atts.getValue("", "attributePrecision"); if (precision != null) { attrib.setAttributePrecision(Integer.parseInt(precision)); } String scale = atts.getValue("", "scale"); if (scale != null) { attrib.setScale(Integer.parseInt(scale)); } attrib.setPrimaryKey(TRUE.equalsIgnoreCase(atts.getValue("", "isPrimaryKey"))); attrib.setMandatory(TRUE.equalsIgnoreCase(atts.getValue("", "isMandatory"))); attrib.setGenerated(TRUE.equalsIgnoreCase(atts.getValue("", "isGenerated"))); }
/** * @since 1.7 * @deprecated since 2.4 in favor of {@link #valueConverter(Class, ValueConverter)}. */ @Deprecated public LmRuntimeBuilder withJdbcNormalizer(Class<?> javaType, JdbcNormalizer<?> normalizer) { return valueConverter(javaType, (v, s) -> { DbAttribute placeholder = new DbAttribute("_placeholder"); placeholder.setScale(s); placeholder.setType(TypesMapping.getSqlTypeByJava(javaType)); return normalizer.normalize(v, placeholder); }); }
/** * Fixes some reverse engineering problems. Namely if a columns is created * as DECIMAL and has non-positive precision it is converted to INTEGER. */ @Override public DbAttribute buildAttribute(String name, String typeName, int type, int size, int scale, boolean allowNulls) { DbAttribute attr = super.buildAttribute(name, typeName, type, size, scale, allowNulls); if (type == Types.DECIMAL && scale <= 0) { attr.setType(Types.INTEGER); attr.setScale(-1); } else if (type == Types.OTHER) { // in this case we need to guess the attribute type // based on its string value if (ORACLE_FLOAT.equals(typeName)) { attr.setType(Types.FLOAT); } else if (ORACLE_BLOB.equals(typeName)) { attr.setType(Types.BLOB); } else if (ORACLE_CLOB.equals(typeName)) { attr.setType(Types.CLOB); } else if (ORACLE_NCLOB.equals(typeName)) { attr.setType(Types.NCLOB); } } else if (type == Types.DATE) { // Oracle DATE can store JDBC TIMESTAMP if ("DATE".equals(typeName)) { attr.setType(Types.TIMESTAMP); } } return attr; }
@Override public DbAttribute buildAttribute(String name, String typeName, int type, int size, int scale, boolean allowNulls) { DbAttribute attr = new DbAttribute(); attr.setName(name); attr.setType(type); attr.setMandatory(!allowNulls); if (size >= 0) { attr.setMaxLength(size); } if (scale >= 0) { attr.setScale(scale); } return attr; }
@Override public void execute(MergerContext mergerContext) { columnOriginal.setType(columnNew.getType()); columnOriginal.setMaxLength(columnNew.getMaxLength()); columnOriginal.setAttributePrecision(columnNew.getAttributePrecision()); columnOriginal.setScale(columnNew.getScale()); mergerContext.getDelegate().dbAttributeModified(columnOriginal); }