Issue 76357 - Add support to determine if a column is auto-increment diff --git a/dbschema/manifest.mf b/dbschema/manifest.mf --- a/dbschema/manifest.mf +++ b/dbschema/manifest.mf @@ -1,6 +1,6 @@ Manifest-Version: 1.0 Manifest-Version: 1.0 OpenIDE-Module: org.netbeans.modules.dbschema/1 -OpenIDE-Module-Implementation-Version: 3 +OpenIDE-Module-Implementation-Version: 4 OpenIDE-Module-Layer: org/netbeans/modules/dbschema/jdbcimpl/resources/mf-layer.xml OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/dbschema/resources/Bundle.properties AutoUpdate-Show-In-Client: false diff --git a/dbschema/src/org/netbeans/modules/dbschema/ColumnElement.java b/dbschema/src/org/netbeans/modules/dbschema/ColumnElement.java --- a/dbschema/src/org/netbeans/modules/dbschema/ColumnElement.java +++ b/dbschema/src/org/netbeans/modules/dbschema/ColumnElement.java @@ -170,6 +170,17 @@ public class ColumnElement extends DBMem return SQLTypeUtil.isBlob(getType()); } //end convenience methods + + /** + * Returns whether the column is an auto-increment column + * + * @return true if the column is an auto-increment column; false otherwise, + * Also returns false if the underlying implementation does not provide + * that information. + */ + public boolean isAutoIncrement() { + return getColumnImpl().isAutoIncrement(); + } /** Returns whether the column is nullable. * @return a flag representing whether the column is nullable @@ -262,6 +273,8 @@ public class ColumnElement extends DBMem */ public int getType (); + public boolean isAutoIncrement(); + /** Set the value type of the column. * @param type the type * @throws DBException if impossible @@ -331,6 +344,9 @@ public class ColumnElement extends DBMem /** Scale of column */ private Integer _scale; + + /** Whether column is auto-increment */ + private boolean _autoIncrement; /** Default constructor. */ @@ -349,6 +365,7 @@ public class ColumnElement extends DBMem _length = column.getLength(); _precision = column.getPrecision(); _scale = column.getScale(); + _autoIncrement = column.isAutoIncrement(); } /** Type of the column. @@ -442,5 +459,9 @@ public class ColumnElement extends DBMem _scale = scale; firePropertyChange (PROP_SCALE, old, scale); } + + public boolean isAutoIncrement() { + throw new UnsupportedOperationException("Not supported yet."); + } } } diff --git a/dbschema/src/org/netbeans/modules/dbschema/jdbcimpl/ColumnElementImpl.java b/dbschema/src/org/netbeans/modules/dbschema/jdbcimpl/ColumnElementImpl.java --- a/dbschema/src/org/netbeans/modules/dbschema/jdbcimpl/ColumnElementImpl.java +++ b/dbschema/src/org/netbeans/modules/dbschema/jdbcimpl/ColumnElementImpl.java @@ -50,6 +50,7 @@ public class ColumnElementImpl extends D protected Integer _length; protected Integer _precision; protected Integer _scale; + protected boolean _isAutoIncrement; /** Creates new ColumnElementImpl */ public ColumnElementImpl() { @@ -61,12 +62,14 @@ public class ColumnElementImpl extends D } /** Creates new ColumnElementImpl */ - public ColumnElementImpl(String name, String type, String isNullable, String size, String decimal) { + public ColumnElementImpl(String name, String type, String isNullable, boolean isAutoIncrement, String size, String decimal) { super(name); _type = new Integer(type).intValue(); + _isAutoIncrement = isAutoIncrement; + int nullable = new Integer(isNullable).intValue(); - + /* if (isNullable.trim().equals("YES")) //NOI18N _isNullable = true; @@ -173,4 +176,8 @@ public class ColumnElementImpl extends D public void setScale(Integer scale) throws DBException { _scale = scale; } + + public boolean isAutoIncrement() { + throw new UnsupportedOperationException("Not supported yet."); + } } diff --git a/dbschema/src/org/netbeans/modules/dbschema/jdbcimpl/TableElementImpl.java b/dbschema/src/org/netbeans/modules/dbschema/jdbcimpl/TableElementImpl.java --- a/dbschema/src/org/netbeans/modules/dbschema/jdbcimpl/TableElementImpl.java +++ b/dbschema/src/org/netbeans/modules/dbschema/jdbcimpl/TableElementImpl.java @@ -44,10 +44,13 @@ import java.sql.*; import java.sql.*; import java.util.*; +import java.util.logging.Level; +import java.util.logging.Logger; import org.netbeans.modules.dbschema.*; import org.netbeans.modules.dbschema.util.*; public class TableElementImpl extends DBElementImpl implements TableElement.Impl { + private static Logger LOGGER = Logger.getLogger(TableElementImpl.class.getName()); private DBElementsCollection columns; private DBElementsCollection indexes; @@ -179,6 +182,7 @@ public class TableElementImpl extends DB int sqlType; String sqlTypeName; String colName, colNull, colSize, colDec; + boolean colAutoIncrement; if (rs != null) { HashMap rset = new HashMap(); while (rs.next()) { @@ -194,6 +198,15 @@ public class TableElementImpl extends DB colNull = (String) rset.get(new Integer(11)); colSize = (String) rset.get(new Integer(7)); colDec = (String) rset.get(new Integer(9)); + + try { + // In JDBC4 column 12 is "Remarks", a String not a boolean, so this + // will throw an exception and we just set autoIncrement to false + colAutoIncrement = rs.getBoolean(12); + } catch (SQLException e) { + LOGGER.log(Level.FINE, null, e); + colAutoIncrement = false; + } rset.clear(); } else { sqlType = rs.getInt("DATA_TYPE"); //NOI18N @@ -202,6 +215,13 @@ public class TableElementImpl extends DB colNull = Integer.toString(rs.getInt("NULLABLE")); //NOI18N colSize = rs.getString("COLUMN_SIZE"); //NOI18N colDec = rs.getString("DECIMAL_DIGITS"); //NOI18N + + try { + colAutoIncrement = rs.getBoolean("AUTO_INCREMENT"); // NOI18N + } catch (SQLException sqle) { + LOGGER.log(Level.FINE, null, sqle); + colAutoIncrement = false; + } } String dbProductName = dmd.getDatabaseProductName().trim(); @@ -232,7 +252,8 @@ public class TableElementImpl extends DB colSize = Integer.toString(Integer.MAX_VALUE); } - ColumnElementImpl cei = new ColumnElementImpl(colName, Integer.toString(sqlType), colNull, colSize, colDec); + ColumnElementImpl cei = new ColumnElementImpl(colName, Integer.toString(sqlType), + colNull, colAutoIncrement, colSize, colDec); ColumnElement ce = new ColumnElement(cei, (TableElement) element); ColumnElement[] c = {ce}; changeColumns(c, DBElement.Impl.ADD);