Index: apichanges.xml =================================================================== RCS file: /cvs/j2eeserver/apichanges.xml,v retrieving revision 1.23 diff -u -r1.23 apichanges.xml --- apichanges.xml 13 Oct 2006 13:08:52 -0000 1.23 +++ apichanges.xml 28 Mar 2007 14:13:40 -0000 @@ -86,6 +86,25 @@ + + + + Adding an API for JDBC driver deployment. + + + + + + +

+ API for JDBC driver deployment and a utility class for working with data sources was added. +

+
+ + + + +
Index: nbproject/project.properties =================================================================== RCS file: /cvs/j2eeserver/nbproject/project.properties,v retrieving revision 1.14 diff -u -r1.14 project.properties --- nbproject/project.properties 20 Oct 2006 10:20:24 -0000 1.14 +++ nbproject/project.properties 28 Mar 2007 14:13:40 -0000 @@ -17,7 +17,7 @@ is.autoload=true javac.source=1.5 -spec.version.base=1.21.0 +spec.version.base=1.24.0 javadoc.overview=${basedir}/api/doc/overview.html javadoc.arch=${basedir}/arch.xml Index: src/org/netbeans/modules/j2ee/deployment/common/api/DatasourceHelper.java =================================================================== RCS file: src/org/netbeans/modules/j2ee/deployment/common/api/DatasourceHelper.java diff -N src/org/netbeans/modules/j2ee/deployment/common/api/DatasourceHelper.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/netbeans/modules/j2ee/deployment/common/api/DatasourceHelper.java 28 Mar 2007 14:13:40 -0000 @@ -0,0 +1,106 @@ +/* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (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.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.netbeans.modules.j2ee.deployment.common.api; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import org.netbeans.api.db.explorer.ConnectionManager; +import org.netbeans.api.db.explorer.DatabaseConnection; +import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider; + +/** + * An utility class for working with data sources. + * + * @author Andrei Badea + * + * @since 1.24 + */ +public class DatasourceHelper { + + private DatasourceHelper() { + } + + /** + * Finds the database connections whose database URL and user name equal + * the database URL and the user name of the passed data source. + * + * @param datasource the data source. + * + * @return the list of database connections; never null. + * + * @throws NullPointerException if the datasource parameter was null. + */ + public static List findDatabaseConnections(Datasource datasource) { + if (datasource == null) { + throw new NullPointerException("The datasource parameter cannot be null."); // NOI18N + } + String databaseUrl = datasource.getUrl(); + String user = datasource.getUsername(); + if (databaseUrl == null || user == null) { + return Collections.emptyList(); + } + List result = new ArrayList(); + for (DatabaseConnection dbconn : ConnectionManager.getDefault().getConnections()) { + if (databaseUrl.equals(dbconn.getDatabaseURL()) && user.equals(dbconn.getUser())) { + result.add(dbconn); + } + } + if (result.size() > 0) { + return Collections.unmodifiableList(result); + } else { + return Collections.emptyList(); + } + } + + /** + * Finds the data source with the given JNDI name in the module and + * project data sources of the given provider. + * + * @param provider the {@link J2eeModuleProvider provider} whose data sources + * are to be searched; cannot be null. + * @param jndiName the JNDI name to search for; cannot be null. + * + * @return the found data source or null if no data source was found. + * + * @throws NullPointerException if either the provider + * or the jndiName parameter was null. + */ + public static Datasource findDatasource(J2eeModuleProvider provider, String jndiName) + throws ConfigurationException { + if (provider == null) { + throw new NullPointerException("The provider parameter cannot be null."); // NOI18N + } + if (jndiName == null) { + throw new NullPointerException("The jndiName parameter cannot be null."); // NOI18N + } + for (Datasource datasource : provider.getServerDatasources()) { + if (jndiName.equals(datasource.getJndiName())) { + return datasource; + } + } + for (Datasource datasource : provider.getModuleDatasources()) { + if (jndiName.equals(datasource.getJndiName())) { + return datasource; + } + } + return null; + } +} Index: src/org/netbeans/modules/j2ee/deployment/plugins/spi/JDBCDriverDeployer.java =================================================================== RCS file: src/org/netbeans/modules/j2ee/deployment/plugins/spi/JDBCDriverDeployer.java diff -N src/org/netbeans/modules/j2ee/deployment/plugins/spi/JDBCDriverDeployer.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/netbeans/modules/j2ee/deployment/plugins/spi/JDBCDriverDeployer.java 28 Mar 2007 14:13:40 -0000 @@ -0,0 +1,59 @@ +/* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (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.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.netbeans.modules.j2ee.deployment.plugins.spi; + +import java.util.Set; +import javax.enterprise.deploy.spi.Target; +import javax.enterprise.deploy.spi.status.ProgressObject; +import org.netbeans.modules.j2ee.deployment.common.api.Datasource; + +/** + * JDBC driver deployer useful for deploying drivers to the server. + *

+ * Implementation of JDBC driver deployer should be registerd via the {@link + * OptionalDeploymentManagerFactory}. + * + * @author sherold + * + * @since 1.24 + */ +public interface JDBCDriverDeployer { + + /** + * Returns true if the specified target supports deployment of JDBC drivers, + * false otherwise. + * + * @params target the JDBC drivers maight be deployed to. + * + * @return true if the specified target supports deployment of JDBC drivers, + * false otherwise. + */ + boolean supportsDeployJDBCDrivers(Target target); + + /** + * Deploys JDBC drivers for all the specified resources to the specified target + * server if the drivers have not been deployed yet. + * + * @param target where the drivers should be deployed to. + * @param datasources + */ + ProgressObject deployJDBCDrivers(Target target, Set datasources); + +} Index: src/org/netbeans/modules/j2ee/deployment/plugins/spi/OptionalDeploymentManagerFactory.java =================================================================== RCS file: /cvs/j2eeserver/src/org/netbeans/modules/j2ee/deployment/plugins/spi/Attic/OptionalDeploymentManagerFactory.java,v retrieving revision 1.1.2.3 diff -u -r1.1.2.3 OptionalDeploymentManagerFactory.java --- src/org/netbeans/modules/j2ee/deployment/plugins/spi/OptionalDeploymentManagerFactory.java 21 Mar 2007 23:38:17 -0000 1.1.2.3 +++ src/org/netbeans/modules/j2ee/deployment/plugins/spi/OptionalDeploymentManagerFactory.java 28 Mar 2007 14:13:40 -0000 @@ -93,4 +93,17 @@ public DatasourceManager getDatasourceManager(DeploymentManager dm) { return null; } + + /** + * Creates a JDBC driver deployer for the specified deployment manager. + * + * @param dm deployment manager. + * + * @return JDBC driver deployer for the specified deployment manager or null + * if JDBC driver deployment is not supported. + * @since 1.24 + */ + public JDBCDriverDeployer getJDBCDriverDeployer(DeploymentManager dm) { + return null; + } }