@Override void processResultSet(DbEntity dbEntity, DbLoadDataStore map, ResultSet rs) throws SQLException { String columnName = rs.getString("COLUMN_NAME"); DbAttribute attribute = dbEntity.getAttribute(columnName); if (attribute == null) { // why an attribute might be null is not quiet clear // but there is a bug report 731406 indicating that it is // possible so just print the warning, and ignore LOGGER.warn("Can't locate attribute for primary key: " + columnName); return; } attribute.setPrimaryKey(true); ((DetectedDbEntity) dbEntity).setPrimaryKeyName(rs.getString("PK_NAME")); } }
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)); } String precision = atts.getValue("", "precision"); if (precision != null) { attrib.setPrecision(Integer.parseInt(precision)); } attrib.setPrimaryKey(TRUE.equalsIgnoreCase(atts.getValue("", "isPrimaryKey"))); attrib.setMandatory(TRUE.equalsIgnoreCase(atts.getValue("", "isMandatory"))); attrib.setGenerated(TRUE.equalsIgnoreCase(atts.getValue("", "isGenerated"))); }
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"))); }
private void processStartDerivedDbAttribute(Attributes atts) { String name = atts.getValue("", "name"); String type = atts.getValue("", "type"); String spec = atts.getValue("", "spec"); attrib = new DerivedDbAttribute(name); attrib.setType(TypesMapping.getSqlTypeByName(type)); ((DerivedDbAttribute) attrib).setExpressionSpec(spec); dbEntity.addAttribute(attrib); String temp = atts.getValue("", "length"); if (temp != null) { attrib.setMaxLength(Integer.parseInt(temp)); } temp = atts.getValue("", "precision"); if (temp != null) { attrib.setPrecision(Integer.parseInt(temp)); } temp = atts.getValue("", "isPrimaryKey"); if (temp != null && temp.equalsIgnoreCase(TRUE)) { attrib.setPrimaryKey(true); } temp = atts.getValue("", "isMandatory"); if (temp != null && temp.equalsIgnoreCase(TRUE)) { attrib.setMandatory(true); } temp = atts.getValue("", "isGroupBy"); if (temp != null && temp.equalsIgnoreCase(TRUE)) { ((DerivedDbAttribute) attrib).setGroupBy(true); } }
attr.setPrimaryKey(flag); if (flag) { attr.setMandatory(true);
@Override public void execute(MergerContext mergerContext) { DbEntity e = getEntity(); for (DbAttribute attr : e.getAttributes()) { boolean wasPrimaryKey = attr.isPrimaryKey(); boolean willBePrimaryKey = primaryKeyNewAttributeNames.contains(attr .getName() .toUpperCase()); if (wasPrimaryKey != willBePrimaryKey) { attr.setPrimaryKey(willBePrimaryKey); e.dbAttributeChanged(new AttributeEvent(this, attr, e)); mergerContext.getDelegate().dbAttributeModified(attr); } } } }
attribute.setPrimaryKey(true);