This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 208830 - JDBC driver deployment does not work for sample project (GF 3.1.2)
Summary: JDBC driver deployment does not work for sample project (GF 3.1.2)
Status: VERIFIED FIXED
Alias: None
Product: serverplugins
Classification: Unclassified
Component: GlassFish (show other bugs)
Version: 7.2
Hardware: PC Mac OS X
: P2 normal (vote)
Assignee: TomasKraus
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-02-24 14:56 UTC by Petr Jiricka
Modified: 2012-04-06 12:07 UTC (History)
5 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Exception shown when trying to run on GF 3.1.1 (68.57 KB, application/octet-stream)
2012-02-27 16:08 UTC, Martin Janicek
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Petr Jiricka 2012-02-24 14:56:25 UTC
1. Create the PetCatalog sample
2. Follow the instructions in setup/SETUP_INSTRUCTIONS.html

=> When you deploy the JDBC driver will not be deployed to domain1/lib, so the deployment will fail.
Comment 1 TomasKraus 2012-02-24 15:17:30 UTC
Assigning to myself
Comment 2 Martin Janicek 2012-02-25 13:43:37 UTC
This is still stopper for 7.1.1 release or am I wrong?
Comment 3 Vince Kraemer 2012-02-26 17:01:46 UTC
Hmmm.  I think Petr would have filed this against 7.1 or 7.1.1 if he felt that it should be a release stopper for 7.1.1...  He probably would have set the priority to P1, also.  Since he did not, I figured that this was not release stopper.
Comment 4 Martin Janicek 2012-02-27 09:14:20 UTC
Well, the original issue 208706 was marked by QA engineer as release stopper for 7.1.1, so I don't see any reason why this shouldn't be a stopper as well (from the user point of view it's working in the same incorrect way - PetCatalog sample cannot be deployed to a GF 3.1.2).
We should either fix the GF problem or comment the PetCatalog sample out.
Comment 5 Petr Jiricka 2012-02-27 09:50:06 UTC
Well, this bug has a workaround: create an application from scratch that uses a MySQL datasource (e.g. through JPA) and deploy it. This will correctly deploy the driver, so a subsequent deployment of the sample will succeed. So I don't think this is a stopper for 7.1.1.
Comment 6 Martin Janicek 2012-02-27 10:01:55 UTC
It's up to you Petr. I don't think that user want to do all these stuffs just to be able to run one sample (and to be honest I don't believe that someone will be looking how-to workarround a sample). But that's just my opinion. Anyway feel free to remove '71patch1-candidate' tag.
Comment 7 Petr Jiricka 2012-02-27 12:00:45 UTC
I think we don't want to delay 7.1.1 (which is supposed to be out on Wednesday) just for this bug - right now the final build is available internally and there is no plan to rebuild. Of course if 7.1.1 is delayed, then we may want to consider it, but for that this would first need to be fixed in the trunk.
Comment 8 Martin Janicek 2012-02-27 16:08:58 UTC
Created attachment 116145 [details]
Exception shown when trying to run on GF 3.1.1

I've just tried to reproduce the issue with GF 3.1.1.
Application could be build and deployed (which is not possible in GF 3.1.2), but after so there is an exception shown when trying to run the sample. See attached file for exception log.
Comment 9 Martin Janicek 2012-02-27 16:25:24 UTC
Hmm, regarding issue 208747, comment 5 it might be a problem with my local setup. I'll look into this a little bit more.
Comment 10 Martin Janicek 2012-02-28 08:10:23 UTC
Tomas, I'm sorry but I still can't get to the point when the sample will be runnable with GF 3.1.1., so I'm not able to say how it behave in 7.1 with GF 3.1.1. I can successfully deploy application, however it can't be run (because of the attached exception). Not sure if it's just because of my (somehow broken) configuration or if it wasn't working at all.
Comment 11 TomasKraus 2012-02-28 08:40:48 UTC
I was able to build and deploy sample on both GF 3.1.1 and 3.1.2 when I added mysql JDBC driver manually into the project (e.g. JDBC jar was in PetCatalog/build/web/WEB-INF/lib - project deployment directory).
On GF 3.1.1 I was able to run sample without any problems.
On GF 3.1.2 I saw Illegal state exception when running this sample and copying JDBC jar into domain1/lib fixed this problem.

Also verified that JDBC driver library is not copied into domain1/lib by glassfish module with both GF 3.1.1 and 3.1.2. I'll try to debug and fix this.
Comment 12 TomasKraus 2012-02-28 11:07:00 UTC
I did some more testing and debugging with the help of local netbeans team. Finally we were able to get JDBC driver deployment working.

We saw following issues:

1) org.netbeans.modules.glassfish.javaee.db.Hk2DatasourceManager.getDatasources(...)
is searching for NetBeansProjects/PetCatalog/setup/glassfish-resources.xml
But there is old sun-resources.xml file in sample project.

2) org.netbeans.modules.j2ee.common.DatasourceHelper.findDatabaseConnections(...)
is trying to match database URL from application resources - jdbc:mysql://127.0.0.1:3306/petcatalog
against database connections in Services:Databases where the same connection with the same URL must exist.
Only then JDBC driver is deployed.
I had to open this Services:Databases database connection with the same URL manually.

Looks like there is no problem in JDBC driver deployment itself but PetCatalog sample may need some update to contain valid glassfish-resources.xml descriptor file and also to automatically open database connection with the same URL in netbeans.
Comment 13 Petr Jiricka 2012-02-28 12:35:15 UTC
> But there is old sun-resources.xml file in sample project.

But should not the GlassFish plugin also consider this file for compatibility reasons? Shouldn't this continue to be supported even though it's old style?
(Of course, we can update the sample as well.)

> trying to match database URL from application resources ... against database connections in 
> Services:Databases

We should at least print some information message if the URL can not be matched, so the user has some idea where the problem is. 
But I can understand why the IDE tried to match it - using Services:Databases, it can find the driver file location on the disk based on the database URL.
Comment 14 TomasKraus 2012-02-28 12:50:44 UTC
I checked deployment guide for 3.1.1 and there is glassfish-resources.xml listed.
But I'm not the one who can decide if sun-resources.xml is still supported or not.
Technically it's simple to try old file name when glassfish-resources.xml was not found. But PetCatalog sample should be updated to contain actual file name anyway.

ad 2) Is it possible to open this database connection from sample project?
If not, then setup/SETUP_INSTRUCTIONS.html should contain some information about JDBC driver deployment.
Comment 15 Petr Jiricka 2012-02-28 13:04:41 UTC
> Is it possible to open this database connection from sample project?

The important question is whether the IDE can find the driver jar file. I see that the sample contains the following in the connection pool declaration:
datasource-classname="com.mysql.jdbc.jdbc2.optional.MysqlDataSource"

Based on this, could we figure out that we need ide/modules/ext/mysql-connector-java-5.1.18-bin.jar?

I see that org.netbeans.modules.j2ee.common.DatasourceHelper.findDatabaseConnections(...) works with org.netbeans.modules.j2ee.deployment.common.api.Datasource, which has getDriverClassName(), which is related, but not the same. Can this somehow be used to improve the detection?

The j2ee.common module does not have a permanent owner, but Sergey Petrov is probably closest to this area, cc'ing Sergey. Sergey, any thoughts on how to do this?
Comment 16 Vince Kraemer 2012-02-28 17:03:31 UTC
(In reply to comment #14)
> I checked deployment guide for 3.1.1 and there is glassfish-resources.xml
> listed.
> But I'm not the one who can decide if sun-resources.xml is still supported or
> not.

the sun-resources.xml file in the sample is not being used by the server... it is being used by the plugin, right?  So the limitation of the deployment guide for 3.1.1 are not a final arbiter of the correct answer in this case.

> Technically it's simple to try old file name when glassfish-resources.xml was
> not found.

We should do this.

> But PetCatalog sample should be updated to contain actual file name
> anyway.

That should also happen.
Comment 17 Vince Kraemer 2012-02-28 18:06:07 UTC
(In reply to comment #15)
> > Is it possible to open this database connection from sample project?
> 
> The important question is whether the IDE can find the driver jar file. I see
> that the sample contains the following in the connection pool declaration:
> datasource-classname="com.mysql.jdbc.jdbc2.optional.MysqlDataSource"
> 
> Based on this, could we figure out that we need
> ide/modules/ext/mysql-connector-java-5.1.18-bin.jar?
> 
> I see that
> org.netbeans.modules.j2ee.common.DatasourceHelper.findDatabaseConnections(...)
> works with org.netbeans.modules.j2ee.deployment.common.api.Datasource, which
> has getDriverClassName(), which is related, but not the same. Can this somehow
> be used to improve the detection?
> 
> The j2ee.common module does not have a permanent owner, but Sergey Petrov is
> probably closest to this area, cc'ing Sergey. Sergey, any thoughts on how to do
> this?

It looks like the GF plugin expects the DB Connection to be registered in the IDE...  If the DB Connection isn't registered the plugin cannot conjure up the connection between a classname and a jar file.

The primary plugin files for this is glassfish.javaee/.../JDBCDriverDeployerImpl.java, glassfish.eecommon/.../JDBCDriverDeployHelper.java
Comment 18 Martin Janicek 2012-02-29 09:14:33 UTC
So what do I need to do? I mean from the Samples point of view. I understand that sun-resources.xml need to be change to glassfish-resources.xml. 
But I'm not so sure if it's only file name which need to changed or if I have to update the descriptor itself as well.
Comment 19 Sergey Petrov 2012-02-29 09:27:37 UTC
Regarding requirement to have connection registered, quite a lot of code require connections to be registered as registered connection contain full information required to connect db. But sometimes it's possible to request connection registration from user with appropriate dialog but I'm not sure it's possible from samples infrastructure as I'm not sure how samples are handled by nb.
Comment 20 Marian Mirilovic 2012-02-29 10:38:22 UTC
As NB 7.1 Patch 1 is above to be releases, re-targeting for Patch 2
Comment 21 Sergey Petrov 2012-02-29 11:07:15 UTC
2nd point regarding connection, if connection isn't properly registered there should be warning about problems with datasource resource registration, and resolve action should be available. But I see an issue here as after petCatalog creation I saw two isssues with server and with datasource but after server resolve I see no issues and datasource warning reapear only after ide restart (I'm in 7.1+gf3.1.1)
Comment 22 TomasKraus 2012-02-29 15:35:06 UTC
Reopened bug# 208747 to request rename of sun-resources.xml and to add information about database connection that is required for JDBC driver deployment into setup/SETUP_INSTRUCTIONS.html

I implemented some changes into GF module to make this code a bit more foolproof. Now waiting for Vince to review the diffs.
Comment 23 TomasKraus 2012-03-07 13:01:30 UTC
changeset:   215310:9391432a9f3d
user:        Tomas Kraus <TomasKraus@netbeans.org>
files:       glassfish.javaee/src/org/netbeans/modules/glassfish/javaee/Hk2Configuration.java
             glassfish.javaee/src/org/netbeans/modules/glassfish/javaee/Three1Configuration.java
             glassfish.javaee/src/org/netbeans/modules/glassfish/javaee/db/Hk2DatasourceManager.java
             glassfish.javaee/test/unit/src/org/netbeans/modules/glassfish/javaee/db/Hk2DatasourceManagerTest.java
description: Bug# 208747 - Resource files may be both glassfish-resources.xml and sun-resources.xml.
             File sun-resources.xml is read only when glassfish-resources.xml was not found.

changeset:   215311:72e0f41ae047
user:        Tomas Kraus <TomasKraus@netbeans.org>
files:       glassfish.eecommon/src/org/netbeans/modules/glassfish/eecommon/api/JDBCDriverDeployHelper.java
description: Bug# 208747 - Fallback JDBC driver deployment using resource driver class without configured
             database connection.

changeset:   215312:322cecaaf29a
user:        Tomas Kraus <TomasKraus@netbeans.org>
files:       glassfish.javaee/test/unit/data/178776/glassfish-resources.xml
             glassfish.javaee/test/unit/data/178776/sun-resources.xml
description: Bug# 208747 - Rename sun-resources.xml to glassfish-resources.xml in GlassFish Java EE module test
Comment 24 TomasKraus 2012-03-22 08:51:05 UTC
Switching to resolved state to get trunk verification.
Comment 25 Jiri Skrivanek 2012-03-22 13:09:51 UTC
Verified in trunk build 201203210400.
Comment 26 Marian Mirilovic 2012-03-22 13:17:21 UTC
Tomas, 
please proceed with integration into release71_fixes branch and follow
http://wiki.netbeans.org/NetBeansPatchesProcess . Thanks in advance.
Comment 27 TomasKraus 2012-04-03 13:27:07 UTC
changeset:   224305:529caa69e87d
branch:      release71_fixes
user:        Tomas Kraus <TomasKraus@netbeans.org>
date:        Mon Apr 02 18:04:29 2012 +0200
summary:     Bug# 208830 - Module version number increased and Long Description updated.

changeset:   224187:d15ca2c6c69d
branch:      release71_fixes
parent:      224019:1cd789733390
user:        Tomas Kraus <TomasKraus@netbeans.org>
date:        Mon Apr 02 17:16:51 2012 +0200
summary:     Bug# 208830 - JDBC driver deployment does not work for sample project

pushing to https://TomasKraus:***@hg.netbeans.org/releases
searching for changes
remote: added 4 changesets with 3 changes to 3 files