diff -c -r1.11.6.2 -r1.11.6.2.4.2 Index: j2eeserver/src/org/netbeans/modules/j2ee/deployment/config/ConfigSupportImpl.java =================================================================== RCS file: /cvs/j2eeserver/src/org/netbeans/modules/j2ee/deployment/config/ConfigSupportImpl.java,v retrieving revision 1.40.2.4 retrieving revision 1.40.2.4.4.5 diff -c -r1.40.2.4 -r1.40.2.4.4.5 *** j2eeserver/src/org/netbeans/modules/j2ee/deployment/config/ConfigSupportImpl.java 18 Jan 2006 19:32:46 -0000 1.40.2.4 --- j2eeserver/src/org/netbeans/modules/j2ee/deployment/config/ConfigSupportImpl.java 19 Feb 2006 21:34:49 -0000 1.40.2.4.4.5 *************** *** 23,28 **** --- 23,30 ---- import java.util.HashMap; import java.util.Iterator; import java.util.Map; + import java.util.Set; + import javax.enterprise.deploy.spi.exceptions.OperationUnsupportedException; import org.netbeans.modules.j2ee.deployment.common.api.OriginalCMPMapping; import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider; import org.netbeans.modules.j2ee.deployment.impl.Server; *************** *** 36,41 **** --- 38,44 ---- import org.netbeans.modules.j2ee.deployment.impl.ServerInstance; import org.netbeans.modules.j2ee.deployment.impl.ServerRegistry; import org.netbeans.modules.j2ee.deployment.plugins.api.ConfigurationSupport; + import org.netbeans.modules.j2ee.deployment.plugins.api.Datasource; import org.openide.ErrorManager; import org.openide.filesystems.FileLock; import org.openide.filesystems.FileObject; *************** *** 291,296 **** --- 294,348 ---- ConfigurationSupport serverConfig = server.getConfigurationSupport(); serverConfig.ensureResourceDefined(config, ejbBean); } + + public Set getDatasources() { + + Set projectDS = null; + + if (server != null) { + ConfigurationSupport configSupport = server.getConfigurationSupport(); + if (configSupport != null) { + DeploymentConfiguration config = getDeploymentConfiguration(); + if (config != null) { + projectDS = configSupport.getDatasources(config); + } + } + } + + return projectDS; + } + + public boolean isDatasourceCreationSupported() { + ConfigurationSupport configSupport = server.getConfigurationSupport(); + + if (configSupport == null) + return false; + + return configSupport.isDatasourceCreationSupported(); + } + + public Datasource createDatasource(String jndiName, String url, String username, String password, String driver) + throws OperationUnsupportedException + { + + Datasource ds = null; + + if (server != null) { + ConfigurationSupport configSupport = server.getConfigurationSupport(); + if (configSupport != null) { + DeploymentConfiguration config = getDeploymentConfiguration(); + if (config != null) { + try { + ds = configSupport.createDatasource(config, jndiName, url, username, password, driver); + } catch (ConfigurationException ce) { + ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ce); + } + } + } + } + + return ds; + } // DeploymentConfigurationProvider implementation ------------------------- Index: j2eeserver/src/org/netbeans/modules/j2ee/deployment/devmodules/api/Deployment.java =================================================================== RCS file: /cvs/j2eeserver/src/org/netbeans/modules/j2ee/deployment/devmodules/api/Deployment.java,v retrieving revision 1.21.6.1 retrieving revision 1.21.6.1.4.1 diff -c -r1.21.6.1 -r1.21.6.1.4.1 *** j2eeserver/src/org/netbeans/modules/j2ee/deployment/devmodules/api/Deployment.java 24 Nov 2005 19:26:09 -0000 1.21.6.1 --- j2eeserver/src/org/netbeans/modules/j2ee/deployment/devmodules/api/Deployment.java 22 Feb 2006 13:48:57 -0000 1.21.6.1.4.1 *************** *** 64,69 **** --- 64,70 ---- } public String deploy (J2eeModuleProvider jmp, boolean debugmode, String clientModuleUrl, String clientUrlPart, boolean forceRedeploy, Logger logger) throws DeploymentException { + DeploymentTargetImpl target = new DeploymentTargetImpl(jmp, clientModuleUrl); TargetModule[] modules = null; final J2eeModule module = target.getModule(); *************** *** 74,79 **** --- 75,82 ---- try { progress.start(); + jmp.deployDatasources(); + ServerString server = target.getServer(); //will throw exception if bad server id if (module == null) { Index: j2eeserver/src/org/netbeans/modules/j2ee/deployment/devmodules/spi/J2eeModuleProvider.java =================================================================== RCS file: /cvs/j2eeserver/src/org/netbeans/modules/j2ee/deployment/devmodules/spi/J2eeModuleProvider.java,v retrieving revision 1.47.30.3 retrieving revision 1.47.30.3.4.6 diff -c -r1.47.30.3 -r1.47.30.3.4.6 *** j2eeserver/src/org/netbeans/modules/j2ee/deployment/devmodules/spi/J2eeModuleProvider.java 2 Nov 2005 03:09:08 -0000 1.47.30.3 --- j2eeserver/src/org/netbeans/modules/j2ee/deployment/devmodules/spi/J2eeModuleProvider.java 22 Feb 2006 13:48:57 -0000 1.47.30.3.4.6 *************** *** 15,22 **** --- 15,28 ---- import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; + import java.io.IOException; import java.io.OutputStream; + import java.util.Iterator; + import java.util.Map; + import java.util.Set; import javax.enterprise.deploy.spi.Target; + import javax.enterprise.deploy.spi.exceptions.ConfigurationException; + import javax.enterprise.deploy.spi.exceptions.OperationUnsupportedException; import org.netbeans.modules.j2ee.deployment.common.api.OriginalCMPMapping; import org.netbeans.modules.j2ee.deployment.common.api.ValidationException; import org.netbeans.modules.j2ee.deployment.config.*; *************** *** 27,38 **** --- 33,48 ---- import org.netbeans.modules.j2ee.deployment.impl.ServerRegistry; import org.netbeans.modules.j2ee.deployment.impl.ServerString; import org.netbeans.modules.j2ee.deployment.impl.ServerTarget; + import org.netbeans.modules.j2ee.deployment.plugins.api.Datasource; + import org.netbeans.modules.j2ee.deployment.plugins.api.DatasourceManager.DatasourceAlreadyExistsException; import org.netbeans.modules.j2ee.deployment.plugins.api.InstanceProperties; import org.netbeans.modules.j2ee.deployment.plugins.api.ServerDebugInfo; import org.netbeans.modules.j2ee.deployment.common.api.SourceFileMap; import org.netbeans.modules.j2ee.deployment.plugins.api.StartServer; import org.netbeans.modules.j2ee.deployment.plugins.api.VerifierSupport; + import org.openide.ErrorManager; import org.openide.filesystems.FileObject; + import org.openide.filesystems.FileUtil; import org.openide.util.WeakListeners; import java.io.File; import java.util.ArrayList; *************** *** 117,122 **** --- 127,212 ---- } /** + * Gets the data sources deployed on the target server instance. + * + * @return set of data sources + */ + public Set getServerDatasources() { + ServerInstance si = ServerRegistry.getInstance ().getServerInstance (getServerInstanceID ()); + Set deployedDS = si.getDatasources(); + return deployedDS; + } + + /** + * Gets the data sources saved in the module. + * + * @return set of data sources or null + */ + public Set getModuleDatasources() { + Set projectDS = getConfigSupport().getDatasources(); + return projectDS; + } + + /** + * Tests whether data source creation is supported. + * + * @return true if data source creation is supported + */ + public boolean isDatasourceCreationSupported() { + return getConfigSupport().isDatasourceCreationSupported(); + } + + + /** + * Creates and saves data source in the module if it does not exist yet on the target server or in the module. + * Data source is considered to be existing when JNDI name of the found data source and the one + * just created equal. + * + * @param jndiName name of data source + * @param url database URL + * @param username database user + * @param password user's password + * @param driver FQN of database driver class + * @return conflicting data source or null if no such data source exists yet + */ + public final Datasource createDatasource(String jndiName, String url, String username, String password, String driver) { + + //check whether the ds is not already on the server + Set deployedDS = getServerDatasources(); + if (deployedDS != null) { + for (Iterator it = deployedDS.iterator(); it.hasNext();) { + Datasource ds = (Datasource) it.next(); + if (jndiName.equals(ds.getJndiName())) + return ds; // ds with the same JNDI name already exists on the server, do not create new one + } + } + + Datasource ds = null; + try { + //btw, ds existence in a project is verified directly in the deployment configuration + ds = getConfigSupport().createDatasource(jndiName, url, username, password, driver); + } catch (OperationUnsupportedException oue) { + ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, oue); + } + + return ds; + } + + /** + * Deploys data sources saved in the module. + * + * @exception ConfigurationException if there is some problem with data source configuration + * @exception DatasourceAlreadyExistsException if module data source(s) are conflicting + * with data source(s) already deployed on the server + */ + public void deployDatasources() throws ConfigurationException, DatasourceAlreadyExistsException { + ServerInstance si = ServerRegistry.getInstance ().getServerInstance (getServerInstanceID ()); + Set moduleDS = getModuleDatasources(); + si.deployDatasources(moduleDS); + } + + + /** * Register a listener which will be notified when some of the properties * change. * *************** *** 206,211 **** --- 296,331 ---- * @param ejbtype dtd name for type of ejb: 'message-drive', 'entity', 'session'. */ public void ensureResourceDefinedForEjb(String ejbname, String ejbtype); + + /** + * Tests whether data source creation is supported. + * + * @return true if data source creation is supported + */ + public boolean isDatasourceCreationSupported(); + + /** + * Gets the data sources saved in the module. + * + * @return set of data sources + */ + public Set getDatasources(); + + /** + * Creates and saves data source in the module if it does not exist yet in the module. + * Data source is considered to be existing when JNDI name of the found data source and the one + * just created equal. + * + * @param jndiName name of data source + * @param url database URL + * @param username database user + * @param password user's password + * @param driver FQN of database driver class + * @return conflicting data source or null if no such data source exists yet + * @exception OperationUnsupportedException if operation is not supported + */ + public Datasource createDatasource(String jndiName, String url, String username, String password, String driver) + throws OperationUnsupportedException; } /** Index: j2eeserver/src/org/netbeans/modules/j2ee/deployment/impl/ServerInstance.java =================================================================== RCS file: /cvs/j2eeserver/src/org/netbeans/modules/j2ee/deployment/impl/ServerInstance.java,v retrieving revision 1.61.2.4 retrieving revision 1.61.2.4.4.5 diff -c -r1.61.2.4 -r1.61.2.4.4.5 *** j2eeserver/src/org/netbeans/modules/j2ee/deployment/impl/ServerInstance.java 18 Jan 2006 19:32:46 -0000 1.61.2.4 --- j2eeserver/src/org/netbeans/modules/j2ee/deployment/impl/ServerInstance.java 22 Feb 2006 13:48:56 -0000 1.61.2.4.4.5 *************** *** 18,36 **** import java.beans.PropertyChangeListener; import javax.enterprise.deploy.spi.*; import javax.enterprise.deploy.shared.*; import javax.enterprise.deploy.spi.status.*; import javax.swing.JButton; import javax.swing.SwingUtilities; - import org.netbeans.api.debugger.Breakpoint; - import org.netbeans.api.debugger.DebuggerEngine; import org.netbeans.api.debugger.DebuggerManager; import org.netbeans.api.debugger.DebuggerManagerAdapter; - import org.netbeans.api.debugger.DebuggerManagerListener; import org.netbeans.api.debugger.Session; - import org.netbeans.api.debugger.Watch; import org.netbeans.api.debugger.jpda.AttachingDICookie; import org.netbeans.api.debugger.jpda.JPDADebugger; import org.netbeans.modules.j2ee.deployment.plugins.api.*; import org.openide.filesystems.*; import java.util.*; import javax.enterprise.deploy.spi.exceptions.DeploymentManagerCreationException; --- 18,34 ---- import java.beans.PropertyChangeListener; import javax.enterprise.deploy.spi.*; import javax.enterprise.deploy.shared.*; + import javax.enterprise.deploy.spi.exceptions.ConfigurationException; import javax.enterprise.deploy.spi.status.*; import javax.swing.JButton; import javax.swing.SwingUtilities; import org.netbeans.api.debugger.DebuggerManager; import org.netbeans.api.debugger.DebuggerManagerAdapter; import org.netbeans.api.debugger.Session; import org.netbeans.api.debugger.jpda.AttachingDICookie; import org.netbeans.api.debugger.jpda.JPDADebugger; import org.netbeans.modules.j2ee.deployment.plugins.api.*; + import org.netbeans.modules.j2ee.deployment.plugins.api.DatasourceManager.DatasourceAlreadyExistsException; import org.openide.filesystems.*; import java.util.*; import javax.enterprise.deploy.spi.exceptions.DeploymentManagerCreationException; *************** *** 86,91 **** --- 84,90 ---- private J2eePlatformImpl j2eePlatformImpl; private StartServer startServer; private FindJSPServlet findJSPServlet; + private DatasourceManager dsMgr; private final Set targetsStartedByIde = new HashSet(); // valued by target name private Map targets; // keyed by target name, valued by ServerTarget private boolean managerStartedByIde = false; *************** *** 417,422 **** --- 416,461 ---- } } return findJSPServlet; + } + + private DatasourceManager getDatasourceManager() { + + if (dsMgr == null) { + DeploymentManager dm = getDeploymentManager(); + dsMgr = server.getOptionalFactory().getDatasourceManager(dm); + } + + return dsMgr; + } + + /** + * Gets the data sources deployed on the this server instance. + * + * @return set of data sources + */ + public Set getDatasources() { + + DatasourceManager dsMgr = getDatasourceManager(); + + Set deployedDS = new HashSet(); + if (dsMgr != null) + deployedDS = dsMgr.getDatasources(); + + return deployedDS; + } + + /** + * Deploys data sources saved in the module. + * + * @exception ConfigurationException if there is some problem with data source configuration + * @exception DatasourceAlreadyExistsException if module data source(s) are conflicting + * with data source(s) already deployed on the server + */ + public void deployDatasources(Set datasources) throws ConfigurationException, DatasourceAlreadyExistsException { + + DatasourceManager dsMgr = getDatasourceManager(); + + dsMgr.deployDatasources(datasources); } //---------- State API's: running, debuggable, startedByIDE ----------- Index: j2eeserver/src/org/netbeans/modules/j2ee/deployment/plugins/api/ConfigurationSupport.java =================================================================== RCS file: /cvs/j2eeserver/src/org/netbeans/modules/j2ee/deployment/plugins/api/ConfigurationSupport.java,v retrieving revision 1.2.42.2 retrieving revision 1.2.42.2.4.5 diff -c -r1.2.42.2 -r1.2.42.2.4.5 *** j2eeserver/src/org/netbeans/modules/j2ee/deployment/plugins/api/ConfigurationSupport.java 2 Nov 2005 03:09:10 -0000 1.2.42.2 --- j2eeserver/src/org/netbeans/modules/j2ee/deployment/plugins/api/ConfigurationSupport.java 19 Feb 2006 21:34:48 -0000 1.2.42.2.4.5 *************** *** 14,23 **** --- 14,26 ---- package org.netbeans.modules.j2ee.deployment.plugins.api; import java.io.File; + import java.util.HashSet; + import java.util.Set; import javax.enterprise.deploy.model.DDBean; import javax.enterprise.deploy.model.DeployableObject; import javax.enterprise.deploy.spi.DeploymentConfiguration; import javax.enterprise.deploy.spi.exceptions.ConfigurationException; + import javax.enterprise.deploy.spi.exceptions.OperationUnsupportedException; import org.netbeans.api.project.FileOwnerQuery; import org.netbeans.api.project.Project; import org.netbeans.modules.j2ee.deployment.common.api.OriginalCMPMapping; *************** *** 236,239 **** --- 239,282 ---- * @since 1.12 */ public abstract void updateResourceDir(DeploymentConfiguration config, File resourceDir); + + /** + * Gets the data sources saved in the module. + * + * @param config deployment configuration + * @return set of data sources + */ + public Set getDatasources(DeploymentConfiguration config) { + return new HashSet(); + } + + /** + * Tests whether data source creation is supported. + * + * @return true if data source creation is supported. Default implementation returns false. + */ + public boolean isDatasourceCreationSupported() { + return false; + } + + /** + * Creates and saves data source in the module if it does not exist yet in the module. + * Data source is considered to be existing when JNDI name of the found data source and the one + * just created equal. + * + * @param config deployment configuration + * @param jndiName name of data source + * @param url database URL + * @param username database user + * @param password user's password + * @param driver FQN of database driver class + * @return conflicting data source or null if no such data source exists yet + * @exception OperationUnsupportedException if operation is not supported + * @exception ConfigurationException if data source configuration file is not parseable + */ + public Datasource createDatasource(DeploymentConfiguration config, String jndiName, String url, String username, String password, String driver) + throws OperationUnsupportedException, ConfigurationException + { + throw new OperationUnsupportedException(""); + } } Index: j2eeserver/src/org/netbeans/modules/j2ee/deployment/plugins/api/OptionalDeploymentManagerFactory.java =================================================================== RCS file: /cvs/j2eeserver/src/org/netbeans/modules/j2ee/deployment/plugins/api/OptionalDeploymentManagerFactory.java,v retrieving revision 1.4 retrieving revision 1.4.36.2 diff -c -r1.4 -r1.4.36.2 *** j2eeserver/src/org/netbeans/modules/j2ee/deployment/plugins/api/OptionalDeploymentManagerFactory.java 30 May 2005 09:16:01 -0000 1.4 --- j2eeserver/src/org/netbeans/modules/j2ee/deployment/plugins/api/OptionalDeploymentManagerFactory.java 19 Feb 2006 21:34:48 -0000 1.4.36.2 *************** *** 58,61 **** --- 58,71 ---- public WizardDescriptor.InstantiatingIterator getAddInstanceIterator() { return null; } + + /** + * Creates DatasourceManager for the given deployment manager. + * + * @return data source manager created. Default implementation returns null. + */ + public DatasourceManager getDatasourceManager(DeploymentManager dm) { + return null; + } + }