# This patch file was generated by NetBeans IDE # Following Index: paths are relative to: /home/matthias/NetBeansProjects/core-main # This patch can be applied using context Tools: Patch action on respective folder. # It uses platform neutral UTF-8 encoding and \n newlines. # Above lines and this line are ignored by the patching process. Index: db.metadata.model/nbproject/project.properties --- db.metadata.model/nbproject/project.properties +++ db.metadata.model/nbproject/project.properties @@ -3,7 +3,7 @@ test.unit.cp.extra=\ ${nb_all}/db/external/derby-10.2.2.0.jar:\ - ${nb_all}/db.drivers/external/mysql-connector-java-5.1.18-bin.jar + ${nb_all}/db.drivers/external/mysql-connector-java-5.1.23-bin.jar test.config.stableBTD.includes=**/*Test.class test.config.stableBTD.excludes=\ Index: db.metadata.model/src/org/netbeans/modules/db/metadata/model/api/Autoincrement.java --- db.metadata.model/src/org/netbeans/modules/db/metadata/model/api/Autoincrement.java +++ db.metadata.model/src/org/netbeans/modules/db/metadata/model/api/Autoincrement.java @@ -0,0 +1,49 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2010 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2008 Sun Microsystems, Inc. + */ + +package org.netbeans.modules.db.metadata.model.api; + +import java.sql.DatabaseMetaData; + +public enum Autoincrement { + AUTOINCREMENT, NOT_AUTOINCREMENT, UNKNOWN; +} Index: db.metadata.model/src/org/netbeans/modules/db/metadata/model/api/Column.java --- db.metadata.model/src/org/netbeans/modules/db/metadata/model/api/Column.java +++ db.metadata.model/src/org/netbeans/modules/db/metadata/model/api/Column.java @@ -71,4 +71,22 @@ public int getPosition() { return impl.getPosition(); } + + /** + * Return whether this column is generated or not + * + * @return whether this column is generated + */ + public Generated getGenerated() { + return impl.getGenerated(); } + + /** + * Return whether this column is autoincrement or not + * + * @return whether this column is autoincrement + */ + public Autoincrement getAutoincrement() { + return impl.getAutoincrement(); + } +} Index: db.metadata.model/src/org/netbeans/modules/db/metadata/model/api/Generated.java --- db.metadata.model/src/org/netbeans/modules/db/metadata/model/api/Generated.java +++ db.metadata.model/src/org/netbeans/modules/db/metadata/model/api/Generated.java @@ -0,0 +1,49 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2010 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2008 Sun Microsystems, Inc. + */ + +package org.netbeans.modules.db.metadata.model.api; + +import java.sql.DatabaseMetaData; + +public enum Generated { + GENERATED, NOT_GENERATED, UNKNOWN; +} Index: db.metadata.model/src/org/netbeans/modules/db/metadata/model/jdbc/JDBCColumn.java --- db.metadata.model/src/org/netbeans/modules/db/metadata/model/jdbc/JDBCColumn.java +++ db.metadata.model/src/org/netbeans/modules/db/metadata/model/jdbc/JDBCColumn.java @@ -42,6 +42,8 @@ package org.netbeans.modules.db.metadata.model.jdbc; +import org.netbeans.modules.db.metadata.model.api.Autoincrement; +import org.netbeans.modules.db.metadata.model.api.Generated; import org.netbeans.modules.db.metadata.model.api.Nullable; import org.netbeans.modules.db.metadata.model.api.SQLType; import org.netbeans.modules.db.metadata.model.api.Tuple; @@ -56,11 +58,15 @@ private final Tuple parent; private final JDBCValue value; private final int position; + private final Generated generated; + private final Autoincrement autoincrement; - public JDBCColumn(Tuple parent, int position, JDBCValue value) { + public JDBCColumn(Tuple parent, int position, Generated generated, Autoincrement autoincrement, JDBCValue value) { this.parent = parent; this.value = value; this.position = position; + this.generated = generated; + this.autoincrement = autoincrement; } public final Tuple getParent() { @@ -115,4 +121,15 @@ public int getPosition() { return position; } + + @Override + public Autoincrement getAutoincrement() { + return autoincrement; } + + @Override + public Generated getGenerated() { + return generated; + } + +} Index: db.metadata.model/src/org/netbeans/modules/db/metadata/model/jdbc/JDBCFunction.java --- db.metadata.model/src/org/netbeans/modules/db/metadata/model/jdbc/JDBCFunction.java +++ db.metadata.model/src/org/netbeans/modules/db/metadata/model/jdbc/JDBCFunction.java @@ -51,7 +51,9 @@ import java.util.logging.Level; import java.util.logging.Logger; import org.netbeans.modules.db.metadata.model.MetadataUtilities; +import org.netbeans.modules.db.metadata.model.api.Autoincrement; import org.netbeans.modules.db.metadata.model.api.Column; +import org.netbeans.modules.db.metadata.model.api.Generated; import org.netbeans.modules.db.metadata.model.api.MetadataException; import org.netbeans.modules.db.metadata.model.api.Parameter; import org.netbeans.modules.db.metadata.model.api.Schema; @@ -123,7 +125,7 @@ } protected JDBCColumn createJDBCColumn(int position, ResultSet rs) throws SQLException { - return new JDBCColumn(this.getFunction(), position, JDBCValue.createFunctionValue(rs, this.getFunction())); + return new JDBCColumn(this.getFunction(), position, Generated.UNKNOWN, Autoincrement.UNKNOWN, JDBCValue.createFunctionValue(rs, this.getFunction())); } protected JDBCParameter createJDBCParameter(int position, ResultSet rs) throws SQLException { Index: db.metadata.model/src/org/netbeans/modules/db/metadata/model/jdbc/JDBCProcedure.java --- db.metadata.model/src/org/netbeans/modules/db/metadata/model/jdbc/JDBCProcedure.java +++ db.metadata.model/src/org/netbeans/modules/db/metadata/model/jdbc/JDBCProcedure.java @@ -52,7 +52,9 @@ import java.util.logging.Level; import java.util.logging.Logger; import org.netbeans.modules.db.metadata.model.MetadataUtilities; +import org.netbeans.modules.db.metadata.model.api.Autoincrement; import org.netbeans.modules.db.metadata.model.api.Column; +import org.netbeans.modules.db.metadata.model.api.Generated; import org.netbeans.modules.db.metadata.model.api.MetadataException; import org.netbeans.modules.db.metadata.model.api.Parameter; import org.netbeans.modules.db.metadata.model.api.Parameter.Direction; @@ -127,7 +129,7 @@ } protected JDBCColumn createJDBCColumn(int position, ResultSet rs) throws SQLException { - return new JDBCColumn(this.getProcedure(), position, JDBCValue.createProcedureValue(rs, this.getProcedure())); + return new JDBCColumn(this.getProcedure(), position, Generated.UNKNOWN, Autoincrement.UNKNOWN, JDBCValue.createProcedureValue(rs, this.getProcedure())); } protected JDBCParameter createJDBCParameter(int position, ResultSet rs) throws SQLException { Index: db.metadata.model/src/org/netbeans/modules/db/metadata/model/jdbc/JDBCTable.java --- db.metadata.model/src/org/netbeans/modules/db/metadata/model/jdbc/JDBCTable.java +++ db.metadata.model/src/org/netbeans/modules/db/metadata/model/jdbc/JDBCTable.java @@ -148,13 +148,33 @@ protected JDBCColumn createJDBCColumn(ResultSet rs) throws SQLException { int position = 0; JDBCValue jdbcValue; + Autoincrement autoincrement = Autoincrement.UNKNOWN; + Generated generated = Generated.UNKNOWN; if (isOdbc(rs)) { jdbcValue = JDBCValue.createTableColumnValueODBC(rs, this.getTable()); } else { + // Check existence of relevant columns + if (rs.getMetaData().getColumnCount() >= 23) { + String autoincrementString = rs.getString("IS_AUTOINCREMENT"); + if ("YES".equalsIgnoreCase(autoincrementString)) { + autoincrement = Autoincrement.AUTOINCREMENT; + } else if ("NO".equalsIgnoreCase(autoincrementString)) { + autoincrement = Autoincrement.NOT_AUTOINCREMENT; + } + } + if (rs.getMetaData().getColumnCount() >= 24) { + String generatedcolumnString = rs.getString("IS_GENERATEDCOLUMN"); + if ("YES".equalsIgnoreCase(generatedcolumnString)) { + generated = Generated.GENERATED; + } else if ("NO".equalsIgnoreCase(generatedcolumnString)) { + generated = Generated.NOT_GENERATED; + } + } position = rs.getInt("ORDINAL_POSITION"); jdbcValue = JDBCValue.createTableColumnValue(rs, this.getTable()); } - return new JDBCColumn(this.getTable(), position, jdbcValue); + + return new JDBCColumn(this.getTable(), position, generated, autoincrement, jdbcValue); } /** Returns true if this table is under ODBC connection. In such a case Index: db.metadata.model/src/org/netbeans/modules/db/metadata/model/jdbc/JDBCView.java --- db.metadata.model/src/org/netbeans/modules/db/metadata/model/jdbc/JDBCView.java +++ db.metadata.model/src/org/netbeans/modules/db/metadata/model/jdbc/JDBCView.java @@ -51,7 +51,9 @@ import java.util.logging.Level; import java.util.logging.Logger; import org.netbeans.modules.db.metadata.model.MetadataUtilities; +import org.netbeans.modules.db.metadata.model.api.Autoincrement; import org.netbeans.modules.db.metadata.model.api.Column; +import org.netbeans.modules.db.metadata.model.api.Generated; import org.netbeans.modules.db.metadata.model.api.MetadataException; import org.netbeans.modules.db.metadata.model.api.Schema; import org.netbeans.modules.db.metadata.model.spi.ViewImplementation; @@ -99,8 +101,27 @@ protected JDBCColumn createJDBCColumn(ResultSet rs) throws SQLException { int ordinalPosition = rs.getInt("ORDINAL_POSITION"); - return new JDBCColumn(this.getView(), ordinalPosition, JDBCValue.createTableColumnValue(rs, this.getView())); + Autoincrement autoincrement = Autoincrement.UNKNOWN; + Generated generated = Generated.UNKNOWN; + // Check existence of relevant columns + if( rs.getMetaData().getColumnCount() >= 23 ) { + String autoincrementString = rs.getString("IS_AUTOINCREMENT"); + if("YES".equalsIgnoreCase(autoincrementString)) { + autoincrement = Autoincrement.AUTOINCREMENT; + } else if("NO".equalsIgnoreCase(autoincrementString)) { + autoincrement = Autoincrement.NOT_AUTOINCREMENT; } + } + if( rs.getMetaData().getColumnCount() >= 24 ) { + String generatedcolumnString = rs.getString("IS_GENERATEDCOLUMN"); + if("YES".equalsIgnoreCase(generatedcolumnString)) { + generated = Generated.GENERATED; + } else if("NO".equalsIgnoreCase(generatedcolumnString)) { + generated = Generated.NOT_GENERATED; + } + } + return new JDBCColumn(this.getView(), ordinalPosition, generated, autoincrement, JDBCValue.createTableColumnValue(rs, this.getView())); + } protected void createColumns() { Map newColumns = new LinkedHashMap(); Index: db.metadata.model/src/org/netbeans/modules/db/metadata/model/spi/ColumnImplementation.java --- db.metadata.model/src/org/netbeans/modules/db/metadata/model/spi/ColumnImplementation.java +++ db.metadata.model/src/org/netbeans/modules/db/metadata/model/spi/ColumnImplementation.java @@ -43,7 +43,9 @@ package org.netbeans.modules.db.metadata.model.spi; import org.netbeans.modules.db.metadata.model.MetadataAccessor; +import org.netbeans.modules.db.metadata.model.api.Autoincrement; import org.netbeans.modules.db.metadata.model.api.Column; +import org.netbeans.modules.db.metadata.model.api.Generated; import org.netbeans.modules.db.metadata.model.api.Tuple; /** @@ -64,4 +66,22 @@ public abstract Tuple getParent(); public abstract int getPosition(); + + /** + * Implementers are expected to override this method, + * for compatibility this gets a dummy implementation + * returning UNKNOWN + */ + public Generated getGenerated() { + return Generated.UNKNOWN; } + + /** + * Implementers are expected to override this method, + * for compatibility this gets a dummy implementation + * returning UNKNOWN + */ + public Autoincrement getAutoincrement() { + return Autoincrement.UNKNOWN; + } +} Index: db.metadata.model/test/unit/src/org/netbeans/modules/db/metadata/model/jdbc/JDBCMetadataDerbyTest.java --- db.metadata.model/test/unit/src/org/netbeans/modules/db/metadata/model/jdbc/JDBCMetadataDerbyTest.java +++ db.metadata.model/test/unit/src/org/netbeans/modules/db/metadata/model/jdbc/JDBCMetadataDerbyTest.java @@ -48,6 +48,8 @@ import java.util.Arrays; import java.util.Collection; import java.util.HashSet; +import static junit.framework.Assert.assertTrue; +import org.netbeans.modules.db.metadata.model.api.Autoincrement; import org.netbeans.modules.db.metadata.model.api.Catalog; import org.netbeans.modules.db.metadata.model.api.Column; import org.netbeans.modules.db.metadata.model.api.ForeignKey; @@ -83,7 +85,7 @@ conn = DriverManager.getConnection("jdbc:derby:" + getWorkDirPath() + "/test;create=true"); stmt = conn.createStatement(); stmt.executeUpdate("CREATE TABLE FOO (" + - "ID INT NOT NULL, " + + "ID INT NOT NULL GENERATED ALWAYS AS IDENTITY, " + "FOO_NAME VARCHAR(16), " + "CONSTRAINT FOO_PK PRIMARY KEY (ID, FOO_NAME))"); stmt.executeUpdate("CREATE TABLE BAR (" + @@ -281,4 +283,17 @@ assertEquals(col1, pkcols[1]); assertEquals(col2, pkcols[0]); } + + public void testAutoincrementDetection() { + Schema schema = metadata.getDefaultSchema(); + Table table = schema.getTable("FOO"); + assertTrue(table.getColumn("ID").getAutoincrement() == Autoincrement.AUTOINCREMENT); + assertTrue(table.getColumn("FOO_NAME").getAutoincrement() == Autoincrement.NOT_AUTOINCREMENT); + table = schema.getTable("BAR"); + assertTrue(table.getColumn("i+d").getAutoincrement() == Autoincrement.NOT_AUTOINCREMENT); + assertTrue(table.getColumn("FOO_ID").getAutoincrement() == Autoincrement.NOT_AUTOINCREMENT); + assertTrue(table.getColumn("FOO_NAME").getAutoincrement() == Autoincrement.NOT_AUTOINCREMENT); + assertTrue(table.getColumn("BAR_NAME").getAutoincrement() == Autoincrement.NOT_AUTOINCREMENT); + assertTrue(table.getColumn("DEC_COL").getAutoincrement() == Autoincrement.NOT_AUTOINCREMENT); } +} Index: db.metadata.model/test/unit/src/org/netbeans/modules/db/metadata/model/jdbc/JDBCMetadataMySQLTest.java --- db.metadata.model/test/unit/src/org/netbeans/modules/db/metadata/model/jdbc/JDBCMetadataMySQLTest.java +++ db.metadata.model/test/unit/src/org/netbeans/modules/db/metadata/model/jdbc/JDBCMetadataMySQLTest.java @@ -48,6 +48,7 @@ import java.util.Arrays; import java.util.Collection; import java.util.HashSet; +import org.netbeans.modules.db.metadata.model.api.Autoincrement; import org.netbeans.modules.db.metadata.model.api.Catalog; import org.netbeans.modules.db.metadata.model.api.Column; import org.netbeans.modules.db.metadata.model.api.ForeignKey; @@ -399,4 +400,23 @@ assertEquals(2, col.getScale()); assertEquals("JDBCColumn[name=bar_digit, type=DECIMAL, length=0, precision=12, radix=10, scale=2, nullable=NOT_NULLABLE, ordinal_position=4]", col.toString()); } + + public void testAutoincrementDetection() { + Schema schema = metadata.getDefaultSchema(); + Table table = schema.getTable("groucho"); + assertTrue(table.getColumn("id").getAutoincrement() == Autoincrement.NOT_AUTOINCREMENT); + assertTrue(table.getColumn("id2").getAutoincrement() == Autoincrement.NOT_AUTOINCREMENT); + table = schema.getTable("foo"); + assertTrue(table.getColumn("id").getAutoincrement() == Autoincrement.AUTOINCREMENT); + assertTrue(table.getColumn("FOO_NAME").getAutoincrement() == Autoincrement.NOT_AUTOINCREMENT); + assertTrue(table.getColumn("harpo_id").getAutoincrement() == Autoincrement.NOT_AUTOINCREMENT); + table = schema.getTable("bar"); + assertTrue(table.getColumn("i+d").getAutoincrement() == Autoincrement.NOT_AUTOINCREMENT); + assertTrue(table.getColumn("foo_id").getAutoincrement() == Autoincrement.NOT_AUTOINCREMENT); + assertTrue(table.getColumn("bar_name").getAutoincrement() == Autoincrement.NOT_AUTOINCREMENT); + assertTrue(table.getColumn("bar_digit").getAutoincrement() == Autoincrement.NOT_AUTOINCREMENT); + Catalog c = metadata.getCatalog("test2"); + table = c.getSyntheticSchema().getTable("harpo"); + assertTrue(table.getColumn("id").getAutoincrement() == Autoincrement.AUTOINCREMENT); } +}