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
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/nbproject/project.xml b/dbschema/nbproject/project.xml
--- a/dbschema/nbproject/project.xml
+++ b/dbschema/nbproject/project.xml
@@ -153,6 +153,42 @@
+
+
+ unit
+
+ org.netbeans.core
+
+
+
+ org.netbeans.core.output2
+
+
+
+ org.netbeans.modules.db
+
+
+
+ org.netbeans.modules.editor.mimelookup.impl
+
+
+
+ org.netbeans.modules.javahelp
+
+
+
+ org.netbeans.modules.masterfs
+
+
+ org.netbeans.modules.settings
+
+
+
+ org.openide.modules
+
+
+
+
org.netbeans.modules.j2ee.ejbcore
org.netbeans.modules.j2ee.persistence
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 @@
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 int getType ();
+ public boolean isAutoIncrement();
+
/** Set the value type of the column.
* @param type the type
* @throws DBException if impossible
@@ -331,6 +344,9 @@
/** Scale of column */
private Integer _scale;
+
+ /** Whether column is auto-increment */
+ private boolean _autoIncrement;
/** Default constructor.
*/
@@ -349,6 +365,7 @@
_length = column.getLength();
_precision = column.getPrecision();
_scale = column.getScale();
+ _autoIncrement = column.isAutoIncrement();
}
/** Type of the column.
@@ -442,5 +459,9 @@
_scale = scale;
firePropertyChange (PROP_SCALE, old, scale);
}
+
+ public boolean isAutoIncrement() {
+ return _autoIncrement;
+ }
}
}
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 @@
protected Integer _length;
protected Integer _precision;
protected Integer _scale;
+ protected boolean _isAutoIncrement;
/** Creates new ColumnElementImpl */
public ColumnElementImpl() {
@@ -61,12 +62,14 @@
}
/** 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 void setScale(Integer scale) throws DBException {
_scale = scale;
}
+
+ public boolean isAutoIncrement() {
+ return _isAutoIncrement;
+ }
}
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.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 @@
int sqlType;
String sqlTypeName;
String colName, colNull, colSize, colDec;
+ String strAutoIncrement = null;
if (rs != null) {
HashMap rset = new HashMap();
while (rs.next()) {
@@ -194,6 +198,8 @@
colNull = (String) rset.get(new Integer(11));
colSize = (String) rset.get(new Integer(7));
colDec = (String) rset.get(new Integer(9));
+
+ strAutoIncrement = (String)rset.get(new Integer(23));
rset.clear();
} else {
sqlType = rs.getInt("DATA_TYPE"); //NOI18N
@@ -202,7 +208,16 @@
colNull = Integer.toString(rs.getInt("NULLABLE")); //NOI18N
colSize = rs.getString("COLUMN_SIZE"); //NOI18N
colDec = rs.getString("DECIMAL_DIGITS"); //NOI18N
+
+ try {
+ strAutoIncrement = rs.getString("IS_AUTOINCREMENT");
+ } catch (SQLException sqle) {
+ LOGGER.log(Level.FINE, null, sqle);
+ strAutoIncrement = null;
+ }
}
+
+ boolean colAutoIncrement = strAutoIncrement != null && strAutoIncrement.equals("YES");
String dbProductName = dmd.getDatabaseProductName().trim();
//Oracle driver hacks
@@ -232,7 +247,8 @@
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);
@@ -714,5 +730,5 @@
public void setKeyCollection (DBElementsCollection collection) {
keys = collection;
}
-
+
}
diff --git a/dbschema/test/build-unit.xml b/dbschema/test/build-unit.xml
new file mode 100644
--- /dev/null
+++ b/dbschema/test/build-unit.xml
@@ -0,0 +1,48 @@
+
+
+
+
+
+
+
+
diff --git a/dbschema/test/build.xml b/dbschema/test/build.xml
new file mode 100644
--- /dev/null
+++ b/dbschema/test/build.xml
@@ -0,0 +1,62 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/dbschema/test/cfg-unit.xml b/dbschema/test/cfg-unit.xml
new file mode 100644
--- /dev/null
+++ b/dbschema/test/cfg-unit.xml
@@ -0,0 +1,58 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/dbschema/test/private.properties.template b/dbschema/test/private.properties.template
new file mode 100644
--- /dev/null
+++ b/dbschema/test/private.properties.template
@@ -0,0 +1,62 @@
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+#
+# Copyright 2008 Sun Microsystems, Inc. All rights reserved.
+#
+# 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. Sun designates this
+# particular file as subject to the "Classpath" exception as provided
+# by Sun 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.
+
+# TODO - allow this to run across all databases in one go.
+
+# MySQL
+test-unit-sys-prop.db.url=jdbc:mysql://localhost:8889/test
+test-unit-sys-prop.db.user=root
+test-unit-sys-prop.db.password=root
+test-unit-sys-prop.db.schema=test
+test-unit-sys-prop.db.driver.jarpath=nbinst:///modules/ext/mysql-connector-java-5.1.5-bin.jar
+test-unit-sys-prop.db.driver.classname=com.mysql.jdbc.Driver
+
+# Java DB
+#test-unit-sys-prop.db.url=jdbc:derby://localhost:1527/test;create=true
+#test-unit-sys-prop.db.user=foo
+#test-unit-sys-prop.db.password=bar
+#test-unit-sys-prop.db.schema=FOO
+#test-unit-sys-prop.db.driver.jarpath=file:///Users/David/glassfish/javadb/lib/derbyclient.jar
+#test-unit-sys-prop.db.driver.classname=org.apache.derby.jdbc.ClientDriver
+
+# PostgreSQL
+#test-unit-sys-prop.db.url=jdbc:postgresql://localhost:5432/postgres
+#test-unit-sys-prop.db.user=postgres
+#test-unit-sys-prop.db.password=postgres
+#test-unit-sys-prop.db.schema=public
+#test-unit-sys-prop.db.driver.jarpath=nbinst:///modules/ext/postgresql-8.3-603.jdbc3.jar
+#test-unit-sys-prop.db.driver.classname=org.postgresql.Driver
diff --git a/dbschema/test/unit/src/org/netbeans/modules/dbschema/ColumnElementTest.java b/dbschema/test/unit/src/org/netbeans/modules/dbschema/ColumnElementTest.java
new file mode 100644
--- /dev/null
+++ b/dbschema/test/unit/src/org/netbeans/modules/dbschema/ColumnElementTest.java
@@ -0,0 +1,226 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
+ *
+ * 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. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun 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.dbschema;
+
+import java.io.File;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.sql.Connection;
+import java.sql.Driver;
+import java.sql.SQLException;
+import java.util.Properties;
+import org.netbeans.api.db.explorer.JDBCDriverManager;
+import org.netbeans.junit.NbTestCase;
+import org.netbeans.modules.dbschema.jdbcimpl.ConnectionProvider;
+import org.netbeans.modules.dbschema.jdbcimpl.SchemaElementImpl;
+import org.netbeans.modules.dbschema.test.dbsupport.DbSupport;
+import org.netbeans.modules.dbschema.test.dbsupport.DbSupport.FEATURE;
+import org.openide.modules.ModuleInfo;
+import org.openide.util.Lookup;
+
+/**
+ *
+ * @author David
+ */
+public class ColumnElementTest extends NbTestCase {
+ private String url;
+ private String user;
+ private String password;
+ private String jarpath;
+ private Connection conn;
+ private String driverClassName;
+ private String schema;
+ private DbSupport dbsupport;
+
+
+ public ColumnElementTest(String testName) {
+ super(testName);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ try {
+ super.setUp();
+
+ Lookup.getDefault().lookup(ModuleInfo.class);
+
+ // We need to set up netbeans.dirs so that the NBInst URLMapper correctly
+ // finds our driver jar file
+ File jarFile = new File(JDBCDriverManager.class.getProtectionDomain().getCodeSource().getLocation().toURI());
+ File clusterDir = jarFile.getParentFile().getParentFile();
+ System.setProperty("netbeans.dirs", clusterDir.getAbsolutePath());
+
+ getProperties();
+
+ dbsupport = DbSupport.getInstance(driverClassName);
+
+ conn = getConnection();
+ } catch (SQLException sqle) {
+ reportSQLException(sqle);
+ throw sqle;
+ }
+ }
+
+ private void reportSQLException(SQLException sqle) {
+ while (sqle != null) {
+ sqle.printStackTrace();
+ sqle = sqle.getNextException();
+ }
+ }
+
+ private void getProperties() {
+ url = System.getProperty("db.url", null);
+ user = System.getProperty("db.user", null);
+ password = System.getProperty("db.password", null);
+ driverClassName = System.getProperty("db.driver.classname");
+ schema = System.getProperty("db.schema");
+
+ jarpath = System.getProperty("db.driver.jarpath", null);
+
+ String message = "\nPlease set the following in nbproject/private/private.properties:\n" +
+ "test-unit-sys-prop.db.url=\n" +
+ "test-unit-sys-prop.db.user=\n" +
+ "test-unit-sys-prop.db.password= (optional)\n" +
+ "test-unit-sys-prop.db.schema=\n" +
+ "test-unit-sys-prop.db.driver.jarpath= (can use 'nbinst:///' protocol',\n" +
+ "test-unit-sys-prop.db.driver.classname=\n\n" +
+ "A template is available in test/private.properties.template";
+
+
+ if (url == null) {
+ fail("db.url was not set. " + message);
+ }
+ if (user == null) {
+ fail("db.user was not set. " + message);
+ }
+ if (schema == null) {
+ fail("db.schema was not set. " + message);
+ }
+ if (jarpath == null) {
+ fail("db.driver.jarpath was not set. " + message);
+ }
+ if (driverClassName == null) {
+ fail("db.driver.classname was not set. " + message);
+ }
+ }
+
+ private Connection getConnection() throws Exception {
+ Driver driver = getDriver();
+ Properties props = new Properties();
+ props.put("user", user == null ? "" : user);
+ if (password != null) {
+ props.put("password", password);
+ }
+
+ Connection connection = driver.connect(url, props);
+ assertNotNull(connection);
+
+ return connection;
+ }
+
+ private Driver getDriver() throws Exception {
+ URLClassLoader driverLoader = new URLClassLoader(new URL[] {new URL(jarpath)});
+ return (Driver)Class.forName(driverClassName, true, driverLoader).newInstance();
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ public void testAutoIncrementColumn() throws Exception {
+ try {
+ String tableName = "aitable";
+ String columnName = "aicolumn";
+
+ if (! dbsupport.supportsFeature(FEATURE.AUTOINCREMENT)) {
+ return;
+ }
+
+ SchemaElement schemaElement = getSchemaElement();
+ TableElement[] tables = schemaElement.getTables();
+ TableElement table = null;
+ for ( TableElement tab : tables) {
+ System.out.println(tab.getName().getName());
+ if(tab.getName().getName().toLowerCase().contains(tableName)) {
+ table = tab;
+ break;
+ }
+ }
+ assertNotNull(table);
+
+ ColumnElement[] columns = table.getColumns();
+ ColumnElement col = null;
+ ColumnElement othercol = null;
+
+ for (ColumnElement column : columns) {
+ if (column.getName().getName().toLowerCase().contains(columnName)) {
+ col = column;
+ } else {
+ othercol = column;
+ }
+ }
+ assertNotNull(col);
+ assertNotNull(othercol);
+
+ assertTrue(col.isAutoIncrement());
+ assertFalse(othercol.isAutoIncrement());
+ } catch (SQLException sqle) {
+ reportSQLException(sqle);
+ throw sqle;
+ }
+ }
+
+ /**
+ * Get the schema element representing the selected tables.
+ */
+ private SchemaElement getSchemaElement() throws SQLException, DBException {
+
+ ConnectionProvider connectionProvider = new ConnectionProvider(conn, driverClassName);
+ connectionProvider.setSchema(schema);
+ SchemaElementImpl impl = new SchemaElementImpl(connectionProvider);
+ SchemaElement schemaElement = new SchemaElement(impl);
+ schemaElement.setName(DBIdentifier.create("test-schema")); // NOI18N
+ impl.initTables(connectionProvider);
+
+ return schemaElement;
+ }
+
+}
diff --git a/dbschema/test/unit/src/org/netbeans/modules/dbschema/test/dbsupport/DbSupport.java b/dbschema/test/unit/src/org/netbeans/modules/dbschema/test/dbsupport/DbSupport.java
new file mode 100644
--- /dev/null
+++ b/dbschema/test/unit/src/org/netbeans/modules/dbschema/test/dbsupport/DbSupport.java
@@ -0,0 +1,91 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
+ *
+ * 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. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun 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.dbschema.test.dbsupport;
+
+import java.sql.Connection;
+import java.util.Collection;
+
+/**
+ *
+ * @author David
+ */
+public abstract class DbSupport {
+ public enum VENDOR { MYSQL, JAVADB, POSTGRES, UNKNOWN };
+
+ public enum FEATURE { SEQUENCE, AUTOINCREMENT } ;
+
+ public static VENDOR getVendor(String driverClass) {
+ if ( "com.mysql.jdbc.Driver".equals(driverClass)) {
+ return VENDOR.MYSQL;
+ } else if ("org.apache.derby.jdbc.ClientDriver".equals(driverClass)) {
+ return VENDOR.JAVADB;
+ } else if ("org.apache.derby.jdbc.EmbeddedDriver".equals(driverClass)) {
+ return VENDOR.JAVADB;
+ } else if ("org.postgresql.Driver".equals(driverClass)) {
+ return VENDOR.POSTGRES;
+ } else {
+ return VENDOR.UNKNOWN;
+ }
+ }
+ public static DbSupport getInstance(String driverClass) {
+ if ( "com.mysql.jdbc.Driver".equals(driverClass)) {
+ return MySQLDBSupport.getInstance();
+ } else if ("org.apache.derby.jdbc.ClientDriver".equals(driverClass)) {
+ return JavaDbSupport.getInstance();
+ } else if ("org.apache.derby.jdbc.EmbeddedDriver".equals(driverClass)) {
+ return JavaDbSupport.getInstance();
+ } else if ("org.postgresql.Driver".equals(driverClass)) {
+ return PostgresDbSupport.getInstance();
+ } else {
+ throw new RuntimeException("No support for database with driver class" + driverClass);
+ }
+ }
+
+ public boolean supportsFeature(FEATURE feature) {
+ return getSupportedFeatures().contains(feature);
+ }
+
+ protected abstract Collection getSupportedFeatures();
+
+ public abstract void createAITable(Connection conn, String tableName, String columnName) throws Exception;
+
+ public abstract void createSequenceTable(Connection conn, String tableName, String columnName) throws Exception;
+
+}
diff --git a/dbschema/test/unit/src/org/netbeans/modules/dbschema/test/dbsupport/JavaDbSupport.java b/dbschema/test/unit/src/org/netbeans/modules/dbschema/test/dbsupport/JavaDbSupport.java
new file mode 100644
--- /dev/null
+++ b/dbschema/test/unit/src/org/netbeans/modules/dbschema/test/dbsupport/JavaDbSupport.java
@@ -0,0 +1,84 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
+ *
+ * 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. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun 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.dbschema.test.dbsupport;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.Arrays;
+import java.util.Collection;
+
+/**
+ *
+ * @author David
+ */
+public class JavaDbSupport extends DbSupport {
+ private static final JavaDbSupport DEFAULT = new JavaDbSupport();
+
+ public static JavaDbSupport getInstance() {
+ return DEFAULT;
+ }
+
+ private static final FEATURE[] FEATURES = { FEATURE.AUTOINCREMENT };
+ private static final Collection FEATURE_LIST = Arrays.asList(FEATURES);
+
+ public Collection getSupportedFeatures() {
+ return FEATURE_LIST;
+ }
+
+ public void createSequenceTable(Connection conn, String tableName, String columnName) throws Exception {
+ throw new UnsupportedOperationException("Java DB doesn't do sequences");
+ }
+
+ public void createAITable(Connection conn, String tableName, String columnName) throws Exception {
+ try {
+ conn.createStatement().execute("DROP TABLE " + tableName);
+ } catch ( SQLException sqle ) {
+ System.out.println("WARNING: Got exception trying to drop table: " + sqle.getMessage());
+ }
+
+ String sql = "CREATE TABLE " + tableName +
+ " ( " + columnName + " INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY " +
+ "CONSTRAINT " + columnName + "_PK PRIMARY KEY, " +
+ "othercol VARCHAR(255))";
+
+ conn.createStatement().execute(sql);
+ }
+
+}
diff --git a/dbschema/test/unit/src/org/netbeans/modules/dbschema/test/dbsupport/MySQLDBSupport.java b/dbschema/test/unit/src/org/netbeans/modules/dbschema/test/dbsupport/MySQLDBSupport.java
new file mode 100644
--- /dev/null
+++ b/dbschema/test/unit/src/org/netbeans/modules/dbschema/test/dbsupport/MySQLDBSupport.java
@@ -0,0 +1,82 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
+ *
+ * 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. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun 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.dbschema.test.dbsupport;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.Arrays;
+import java.util.Collection;
+
+/**
+ *
+ * @author David
+ */
+public class MySQLDBSupport extends DbSupport {
+ private static final MySQLDBSupport DEFAULT = new MySQLDBSupport();
+
+ public static MySQLDBSupport getInstance() {
+ return DEFAULT;
+ }
+
+ private static final FEATURE[] FEATURES = { FEATURE.AUTOINCREMENT };
+ private static final Collection FEATURE_LIST = Arrays.asList(FEATURES);
+
+ public Collection getSupportedFeatures() {
+ return FEATURE_LIST;
+ }
+
+ public void createAITable(Connection conn, String tableName, String columnName) throws Exception {
+ try {
+ conn.createStatement().execute("DROP TABLE " + tableName);
+ } catch ( SQLException sqle ) {
+ System.out.println("WARNING: Got exception trying to drop table: " + sqle.getMessage());
+ }
+
+ String sql = "CREATE TABLE " + tableName +
+ " ( " + columnName + " MEDIUMINT NOT NULL AUTO_INCREMENT, PRIMARY KEY(" + columnName + "), " +
+ "othercol VARCHAR(255))";
+ conn.createStatement().execute(sql);
+ }
+
+ public void createSequenceTable(Connection conn, String tableName, String columnName) throws Exception {
+ throw new UnsupportedOperationException("MySQL doesn't do sequences");
+ }
+
+}
diff --git a/dbschema/test/unit/src/org/netbeans/modules/dbschema/test/dbsupport/PostgresDbSupport.java b/dbschema/test/unit/src/org/netbeans/modules/dbschema/test/dbsupport/PostgresDbSupport.java
new file mode 100644
--- /dev/null
+++ b/dbschema/test/unit/src/org/netbeans/modules/dbschema/test/dbsupport/PostgresDbSupport.java
@@ -0,0 +1,88 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
+ *
+ * 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. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun 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.dbschema.test.dbsupport;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.Arrays;
+import java.util.Collection;
+
+/**
+ *
+ * @author David
+ */
+public class PostgresDbSupport extends DbSupport {
+ private static final PostgresDbSupport DEFAULT = new PostgresDbSupport();
+
+ public static PostgresDbSupport getInstance() {
+ return DEFAULT;
+ }
+ private static final FEATURE[] FEATURES = { FEATURE.SEQUENCE };
+ private static final Collection FEATURE_LIST = Arrays.asList(FEATURES);
+
+ public Collection getSupportedFeatures() {
+ return FEATURE_LIST;
+ }
+
+ public void createAITable(Connection conn, String tableName, String columnName) throws Exception {
+ throw new UnsupportedOperationException("Postgres doesn't do auto-increment, only sequences");
+ }
+
+ public void createSequenceTable(Connection conn, String tableName, String columnName) throws Exception {
+ try {
+ conn.createStatement().execute("DROP TABLE " + tableName);
+ } catch ( SQLException sqle ) {
+ System.out.println("WARNING: Got exception trying to drop table: " + sqle.getMessage());
+ }
+
+ try {
+ conn.createStatement().execute("DROP SEQUENCE " + tableName + "_seq CASCADE");
+ } catch ( SQLException sqle ) {
+ System.out.println("WARNING: Got exception trying to drop sequence: " + sqle.getMessage());
+ }
+
+ conn.createStatement().execute("CREATE SEQUENCE " + tableName + "_seq");
+ String sql = "CREATE TABLE " + tableName + " (" + columnName +
+ " INTEGER NOT NULL PRIMARY KEY DEFAULT nextval('" + tableName + "_seq'), " +
+ " othercol VARCHAR(255))";
+
+ conn.createStatement().execute(sql);
+ }
+}