Index: .cvsignore =================================================================== RCS file: .cvsignore diff -N .cvsignore --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ .cvsignore 3 Apr 2006 13:52:24 -0000 @@ -0,0 +1 @@ +build Index: arch.xml =================================================================== RCS file: arch.xml diff -N arch.xml --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ arch.xml 3 Apr 2006 13:52:24 -0000 @@ -0,0 +1,1000 @@ + + + +]> + + + + &api-questions; + + + + +

+ This module provides the + which contains friend APIs related to the database support. +

+
+ + + + + +

+ All Javadoc-specified functionality should be covered by unit tests. +

+
+ + + + + +

+ The implementation is done. The target milestone is promo-G. +

+
+ + + + + + +

+ The code completion for Java Persistence API annotations displays database + metadata (tables and columns). When the tables or columns change because of the + user interaction with the Database Explorer, the code completion needs to refresh + the cached metadata. In order to listen on these changes, the code completion + registers an implementation of the MetaDataListener in the + Databases/MetaDataListeners of the system file system. + The code completion is the only client of this module at this moment. +

+
+
+ + + + + +

+ This module provides friend APIs related to the database support. It can + serve as a place to put friend APIs which cannot be exported by the + Database Explorer module, since it already exports a public API. +

+
+ + + + + + + + + + + + +

+ The module does not contain any UI, so it does not need to be internationalized. +

+
+ + + + + +

+ The module does not define nor implement any standards. +

+
+ + + + + +

+ The module does not save nor read any settings. +

+
+ + + + + +

+ The module requires JRE 1.4. +

+
+ + + + + +

+ JRE is enough. +

+
+ + + + + + + + + + + + +

+ The module does not depend on any projects outside NetBeans. +

+
+ + + + + +

+ The module should run in the samy way on all platforms. +

+
+ + + + + +

+ Only friend modules can declare a dependency on this module. +

+
+ + + + + +

+ Just the module JAR needs to be deployed. +

+
+ + + + + +

+ Yes. +

+
+ + + + + +

+ Only API packages are exported, and only to the friend modules. +

+
+ + + + + +

+ Anywhere. +

+
+ + + + + +

+ No. +

+
+ + + + + +

+ No. +

+
+ + + + + +

+ No. +

+
+ + + + + +

+ No. +

+
+ + + + + +

+ No. +

+
+ + + + + +

+ No. +

+
+ + + + + +

+ No. +

+
+ + + + + +

+ No. +

+
+ + + + + +

+ The API is thread-safe. Events are fired synchronously. +

+
+ + + + + +

+ None. +

+
+ + + + + +

+ None. +

+
+ + + + + +

+ The module does not write any files and it only reads instance files from a folder + in the from the system file system. +

+
+ + + + + +

+ FolderLookup is used to locate the clients. +

+
+ + + + + +

+ The module registers an implementation of an interface defined by the + Database Explorer in the default lookup in order to obtain the metadata change events. +

+
+ + + + + +

+ No. +

+
+ + + + + +

+ No. +

+
+ + + + + +

+ No. +

+
+ + + + + +

+ None known. +

+
+ + + + + +

+ Some memory is needed to store the list of registered clients. +

+
+ + + + + +

+ No. +

+
+ + + + + +

+ No. +

+
+ + + + + +

+ Performance scales linearly with the number of registered clients. +

+
+ + + + + +

+ The plugged in code is expected to execute quickly. +

+
+ + + + + +

+ No. +

+
+ + + + + +

+ No. +

+
+ + + + + +

+ No. +

+
+ + + + + +

+ The module provides its own layer containing the Databases/MetaDataListeners + folder in which the clients register their implementations of + MetaDataListener. +

+
+ + + + + +

+ No. +

+
+ + + + + +

+ No. +

+
+ + + + + +

+ No. +

+
+ + + + + +

+ No. +

+
+ +
Index: build.xml =================================================================== RCS file: build.xml diff -N build.xml --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ build.xml 3 Apr 2006 13:52:24 -0000 @@ -0,0 +1,4 @@ + + + + Index: manifest.mf =================================================================== RCS file: manifest.mf diff -N manifest.mf --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ manifest.mf 3 Apr 2006 13:52:24 -0000 @@ -0,0 +1,4 @@ +Manifest-Version: 1.0 +OpenIDE-Module: org.netbeans.modules.dbapi +OpenIDE-Module-Layer: org/netbeans/modules/dbapi/resources/layer.xml +OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/dbapi/resources/Bundle.properties Index: nbproject/.cvsignore =================================================================== RCS file: nbproject/.cvsignore diff -N nbproject/.cvsignore --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ nbproject/.cvsignore 3 Apr 2006 13:52:24 -0000 @@ -0,0 +1 @@ +private Index: nbproject/project.properties =================================================================== RCS file: nbproject/project.properties diff -N nbproject/project.properties --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ nbproject/project.properties 3 Apr 2006 13:52:24 -0000 @@ -0,0 +1,15 @@ +# Sun Public License Notice +# +# The contents of this file are subject to the Sun Public License +# Version 1.0 (the "License"). You may not use this file except in +# compliance with the License. A copy of the License is available at +# http://www.sun.com/ +# +# The Original Code is NetBeans. The Initial Developer of the Original +# Code is Sun Microsystems, Inc. Portions Copyright 1997-2005 Sun +# Microsystems, Inc. All Rights Reserved. + +javadoc.title=Database APIs +javadoc.arch=${basedir}/arch.xml + +spec.version.base=1.0.0 Index: nbproject/project.xml =================================================================== RCS file: nbproject/project.xml diff -N nbproject/project.xml --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ nbproject/project.xml 3 Apr 2006 13:52:24 -0000 @@ -0,0 +1,56 @@ + + + org.netbeans.modules.apisupport.project + + + org.netbeans.modules.dbapi + + + org.netbeans.modules.db + + + + 0 + + + + + org.openide.filesystems + + + + 6.4 + + + + org.openide.loaders + + + + 5.9 + + + + org.openide.nodes + + + + 6.7 + + + + org.openide.util + + + + 6.8 + + + + + org.netbeans.modules.j2ee.persistence + org.netbeans.modules.db.api.explorer + + + + Index: src/META-INF/services/org.netbeans.modules.db.explorer.DbMetaDataListener =================================================================== RCS file: src/META-INF/services/org.netbeans.modules.db.explorer.DbMetaDataListener diff -N src/META-INF/services/org.netbeans.modules.db.explorer.DbMetaDataListener --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/META-INF/services/org.netbeans.modules.db.explorer.DbMetaDataListener 3 Apr 2006 13:52:24 -0000 @@ -0,0 +1 @@ +org.netbeans.modules.dbapi.DbMetaDataListenerImpl Index: src/org/netbeans/modules/db/api/explorer/MetaDataListener.java =================================================================== RCS file: src/org/netbeans/modules/db/api/explorer/MetaDataListener.java diff -N src/org/netbeans/modules/db/api/explorer/MetaDataListener.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/netbeans/modules/db/api/explorer/MetaDataListener.java 3 Apr 2006 13:52:24 -0000 @@ -0,0 +1,42 @@ +/* + * Sun Public License Notice + * + * The contents of this file are subject to the Sun Public License + * Version 1.0 (the "License"). You may not use this file except in + * compliance with the License. A copy of the License is available at + * http://www.sun.com/ + * + * The Original Code is NetBeans. The Initial Developer of the Original + * Code is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.netbeans.modules.db.api.explorer; + +import org.netbeans.api.db.explorer.DatabaseConnection; + +/** + * Interface allowing to listen on changes of the database metadata caused + * by the Database Explorer, such as adding or dropping a table or a column. + * + * @author Andrei Badea + */ +public interface MetaDataListener { + + /** + * Invoked when the list of tables in the database represented by the + * dbconn parameter has changed. + * + * @param dbconn the database connection whose tables have changed + */ + void tablesChanged(DatabaseConnection dbconn); + + /** + * Invoked when the structure of a table in the database represented by the + * dbconn parameter has changed. + * + * @param dbconn the database connection whose table have changed + * @param tableName the name of the table which changed + */ + void tableChanged(DatabaseConnection dbconn, String tableName); +} Index: src/org/netbeans/modules/dbapi/DbMetaDataListenerImpl.java =================================================================== RCS file: src/org/netbeans/modules/dbapi/DbMetaDataListenerImpl.java diff -N src/org/netbeans/modules/dbapi/DbMetaDataListenerImpl.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/netbeans/modules/dbapi/DbMetaDataListenerImpl.java 3 Apr 2006 13:52:24 -0000 @@ -0,0 +1,56 @@ +/* + * Sun Public License Notice + * + * The contents of this file are subject to the Sun Public License + * Version 1.0 (the "License"). You may not use this file except in + * compliance with the License. A copy of the License is available at + * http://www.sun.com/ + * + * The Original Code is NetBeans. The Initial Developer of the Original + * Code is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.netbeans.modules.dbapi; + +import java.util.Iterator; +import org.netbeans.api.db.explorer.DatabaseConnection; +import org.netbeans.modules.db.api.explorer.MetaDataListener; +import org.netbeans.modules.db.explorer.DbMetaDataListener; +import org.openide.filesystems.FileObject; +import org.openide.filesystems.Repository; +import org.openide.loaders.DataFolder; +import org.openide.loaders.FolderLookup; +import org.openide.util.Lookup; + +/** + * + * @author Andrei Badea + */ +public class DbMetaDataListenerImpl implements DbMetaDataListener { + + /** + * Static because of the tests. + */ + static final String REFRESH_LISTENERS_PATH = "Databases/MetaDataListeners"; // NOI18N + + private final Lookup.Result listeners = getListeners(); + + public void tablesChanged(DatabaseConnection dbconn) { + for (Iterator i = listeners.allInstances().iterator(); i.hasNext();) { + ((MetaDataListener)i.next()).tablesChanged(dbconn); + } + } + + public void tableChanged(DatabaseConnection dbconn, String tableName) { + for (Iterator i = listeners.allInstances().iterator(); i.hasNext();) { + ((MetaDataListener)i.next()).tableChanged(dbconn, tableName); + } + } + + private static Lookup.Result getListeners() { + FileObject fo = Repository.getDefault().getDefaultFileSystem().findResource(REFRESH_LISTENERS_PATH); + DataFolder folder = DataFolder.findFolder(fo); + return new FolderLookup(folder).getLookup().lookup(new Lookup.Template(MetaDataListener.class)); + } +} Index: src/org/netbeans/modules/dbapi/resources/Bundle.properties =================================================================== RCS file: src/org/netbeans/modules/dbapi/resources/Bundle.properties diff -N src/org/netbeans/modules/dbapi/resources/Bundle.properties --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/netbeans/modules/dbapi/resources/Bundle.properties 3 Apr 2006 13:52:24 -0000 @@ -0,0 +1,4 @@ +OpenIDE-Module-Name=Database APIs +OpenIDE-Module-Display-Category=Database +OpenIDE-Module-Short-Description=Database support APIs +OpenIDE-Module-Long-Description=Provides friend APIs related to the database support. Index: src/org/netbeans/modules/dbapi/resources/layer.xml =================================================================== RCS file: src/org/netbeans/modules/dbapi/resources/layer.xml diff -N src/org/netbeans/modules/dbapi/resources/layer.xml --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/netbeans/modules/dbapi/resources/layer.xml 3 Apr 2006 13:52:24 -0000 @@ -0,0 +1,8 @@ + + + + + + + + Index: test/unit/src/org/netbeans/modules/dbapi/DbMetaDataListenerImplTest.java =================================================================== RCS file: test/unit/src/org/netbeans/modules/dbapi/DbMetaDataListenerImplTest.java diff -N test/unit/src/org/netbeans/modules/dbapi/DbMetaDataListenerImplTest.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ test/unit/src/org/netbeans/modules/dbapi/DbMetaDataListenerImplTest.java 3 Apr 2006 13:52:24 -0000 @@ -0,0 +1,79 @@ +/* + * Sun Public License Notice + * + * The contents of this file are subject to the Sun Public License + * Version 1.0 (the "License"). You may not use this file except in + * compliance with the License. A copy of the License is available at + * http://www.sun.com/ + * + * The Original Code is NetBeans. The Initial Developer of the Original + * Code is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.netbeans.modules.dbapi; + +import java.net.URL; +import org.netbeans.api.db.explorer.DatabaseConnection; +import org.netbeans.api.db.explorer.JDBCDriver; +import org.netbeans.junit.NbTestCase; +import org.netbeans.modules.db.api.explorer.MetaDataListener; +import org.netbeans.modules.db.explorer.DbMetaDataListener; +import org.openide.filesystems.FileObject; +import org.openide.filesystems.FileSystem; +import org.openide.filesystems.FileUtil; +import org.openide.filesystems.Repository; + +/** + * + * @author Andrei Badea + */ +public class DbMetaDataListenerImplTest extends NbTestCase { + + public DbMetaDataListenerImplTest(String testName) { + super(testName); + } + + /** + * Tests the registered listeners are invoked when the tableChanged and tablesChanged + * methods of DbMetaDataListenerImpl are invoked. + */ + public void testListenerFired() throws Exception { + JDBCDriver driver = JDBCDriver.create("foo", "Foo", "org.example.Foo", new URL[0]); + DatabaseConnection dbconn = DatabaseConnection.create(driver, "url", "user", "schema", "pwd", false); + + class TestListener implements MetaDataListener { + + DatabaseConnection dbconn; + String tableName; + + public void tablesChanged(DatabaseConnection dbconn) { + this.dbconn = dbconn; + } + + public void tableChanged(DatabaseConnection dbconn, String tableName) { + this.dbconn = dbconn; + this.tableName = tableName; + } + } + + FileSystem sfs = Repository.getDefault().getDefaultFileSystem(); + FileObject listenersFO = FileUtil.createFolder(sfs.getRoot(), DbMetaDataListenerImpl.REFRESH_LISTENERS_PATH); + FileObject listenerFO = listenersFO.createData("TestListener", "instance"); + TestListener listener = new TestListener(); + listenerFO.setAttribute("instanceCreate", listener); + + DbMetaDataListener dbListener = new DbMetaDataListenerImpl(); + + assertNull(listener.dbconn); + dbListener.tablesChanged(dbconn); + assertSame(dbconn, listener.dbconn); + + listener.dbconn = null; + assertNull(listener.dbconn); + assertNull(listener.tableName); + dbListener.tableChanged(dbconn, "TABLE"); + assertSame(dbconn, listener.dbconn); + assertEquals("TABLE", listener.tableName); + } +}