geronimo-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Aaron Mulder <ammul...@alumni.princeton.edu>
Subject Re: Application Scoped JDBC Connector for CMP
Date Sat, 18 Jun 2005 16:04:23 GMT
	I'm not sure if a bug report is necessary, but we should probably 
try to figure out what went wrong with your previous code.  It looked 
reasonable on the face of it.  We might need more extensive reference 
tests.  :)

	Anyway, when David was talking about not needing the resource-ref,
ley me try to explain.  You'd use a resource-ref if you code was going to
look up a DB pool directly, to execute some manual SQL or something.  But
you don't need it for CMP.  For CMP, the cmp-connection-factory is all you
need to identify the database.

Aaron

On Fri, 17 Jun 2005, Neal Sanche wrote:
> Hi Aaron, and also David,
> 
> Thanks again guys. I removed the confusing <resource-ref> elements, and 
> added the <resource-link> as you both suggested. And I'm happy to say 
> that my application scoped JDBC Datasource is now working nicely.
> 
> I'd say that a 'bug report' isn't really necessary here. :) I'm just 
> learning from the myriad of complete/incomplete/conflicting documents 
> I've been finding scattered around. When I find confusing issues like 
> that, I'm sure the best source is to ask here first, and get my facts 
> straight.
> 
> Thanks so much, guys for the 'light shedding'.
> 
> Cheers.
> 
> -Neal
> 
> Aaron Mulder wrote:
> 
> >	What happens if you change the cmp-connection-factory in 
> >openejb-jar.xml to look like this:
> >
> >    <cmp-connection-factory>
> >        <resource-link>MysqlDataSource</resource-link>
> >    </cmp-connection-factory>                        
> >
> >Aaron                           
> >
> >On Fri, 17 Jun 2005, Neal Sanche wrote:
> >  
> >
> >>Hi All,
> >>
> >>I'm currently having trouble with a CMP bean getting access to a MySql 
> >>database when the deployment plans for the JDBC Connector are 
> >>application scoped. Here's what I've done, can you see something wrong 
> >>with what I'm doing?
> >>
> >>application.xml
> >>
> >><DEFANGED_application
> >>       xmlns="http://java.sun.com/xml/ns/j2ee"
> >>       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> >>       xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
> >>       http://java.sun.com/xml/ns/j2ee/application_1_4.xsd"
> >>       version="1.4">
> >>    <module>
> >>        <ejb>phonebook-ejb.jar</ejb>
> >>    </module>
> >>    <module>
> >>        <web>
> >>            <web-uri>phonebook.war</web-uri>
> >>            <context-root>/phonebook</context-root>
> >>        </web>
> >>    </module>
> >>    <module>
> >>        <connector>tranql-connector-1.0-SNAPSHOT.rar</connector>
> >>    </module>
> >></application>
> >>
> >>geronimo-application.xml
> >>
> >><DEFANGED_application
> >>       xmlns="http://geronimo.apache.org/xml/ns/j2ee/application"
> >>       configId="org/acme/PhoneBook">
> >>    <module>
> >>        <connector>tranql-connector-1.0-SNAPSHOT.rar</connector>
> >>        <alt-dd>mysql-plan.xml</alt-dd>
> >>    </module>
> >></application>
> >>
> >>mysql-plan.xml
> >>
> >><connector xmlns="http://geronimo.apache.org/xml/ns/j2ee/connector"
> >>    version="1.5" configId="MysqlDatabase" 
> >>parentId="org/apache/geronimo/Server">
> >>    <dependency>
> >>        <uri>mysql/jars/mysql-connector-java-3.1.8-bin.jar</uri>
> >>    </dependency>
> >>    <resourceadapter>
> >>        <outbound-resourceadapter>
> >>            <connection-definition>
> >>                <connectionfactory-interface> javax.sql.DataSource 
> >></connectionfactory-interface>
> >>                <connectiondefinition-instance>
> >>                    <name>MysqlDataSource</name>
> >>                    <config-property-setting name="UserName"> geronimo

> >></config-property-setting>
> >>                    <config-property-setting name="Password"> geronimo

> >></config-property-setting>
> >>                    <config-property-setting name="Driver"> 
> >>com.mysql.jdbc.Driver </config-property-setting>
> >>                    <config-property-setting name="ConnectionURL"> 
> >>jdbc:mysql://localhost/geronimo </config-property-setting>
> >>                    <config-property-setting 
> >>name="CommitBeforeAutocommit"> false </config-property-setting>
> >>                    <config-property-setting 
> >>name="ExceptionSorterClass"> 
> >>org.tranql.connector.NoExceptionsAreFatalSorter </config-property-setting>
> >>                    <connectionmanager>
> >>                        <local-transaction/>
> >>                        <single-pool>
> >>                            <max-size>10</max-size>
> >>                            <min-size>0</min-size>
> >>                            <blocking-timeout-milliseconds> 5000 
> >></blocking-timeout-milliseconds>
> >>                            <idle-timeout-minutes>30</idle-timeout-minutes>
> >>                            <match-one/>
> >>                        </single-pool>
> >>                    </connectionmanager>
> >>                    <global-jndi-name> jdbc/MysqlDatabase 
> >></global-jndi-name>
> >>                </connectiondefinition-instance>
> >>            </connection-definition>
> >>        </outbound-resourceadapter>
> >>    </resourceadapter>
> >></connector>
> >>
> >>openejb-jar.xml
> >>
> >><openejb-jar
> >>    xmlns="http://www.openejb.org/xml/ns/openejb-jar"
> >>    configId="org/acme/PhonebookEJB"
> >>    parentId="MysqlDatabase">
> >>    <cmp-connection-factory>
> >>        <DEFANGED_application>org/acme/PhoneBook</application>
> >>        <module>MysqlDatabase</module>
> >>        <name>MysqlDataSource</name>
> >>    </cmp-connection-factory>
> >>    <enterprise-beans>
> >>        <entity>
> >>            <ejb-name>PhoneBookEntry</ejb-name>
> >>            <jndi-name>PhoneBookEntry</jndi-name>
> >>            
> >><local-jndi-name>java:comp/env/ejb/PhoneBookEntryLocal</local-jndi-name>
> >>            <table-name>phone</table-name>
> >>            <cmp-field-mapping>
> >>                <cmp-field-name>name</cmp-field-name>
> >>                <table-column>name</table-column>
> >>            </cmp-field-mapping>
> >>            <cmp-field-mapping>
> >>                <cmp-field-name>phoneNumber</cmp-field-name>
> >>                <table-column>phone</table-column>
> >>            </cmp-field-mapping>
> >>            <resource-ref>
> >>                <ref-name>jdbc/basic/entityDatabase</ref-name>
> >>                <DEFANGED_application>null</application>
> >>                <module>MysqlDatabase</module>
> >>                <name>PhonebookDBPool</name>
> >>            </resource-ref>
> >>        </entity>
> >>
> >>        <session>
> >>            <ejb-name>PhoneBookSession</ejb-name>
> >>            
> >><jndi-name>org.acme.phonebook.ejb/PhoneBookSession/Home</jndi-name>
> >>            
> >><local-jndi-name>java:comp/env/ejb/PhoneBookSessionLocal</local-jndi-name>
> >>        </session>
> >>    </enterprise-beans>
> >></openejb-jar>
> >>
> >>and finally, in my ejb-jar.xml inside the <entity> I have this:
> >>
> >>         <resource-ref >
> >>            <description><![CDATA[This is a reference to a JDBC 
> >>database.]]></description>
> >>            <res-ref-name>jdbc/basic/entityDatabase</res-ref-name>
> >>            <res-type>javax.sql.DataSource</res-type>
> >>            <res-auth>Container</res-auth>
> >>         </resource-ref>
> >>
> >>Now, the strange thing is that if I deploy the mysql-plan.xml file in 
> >>the global scoped fashion, I can write the the database by creating CMP 
> >>beans. But if I use the application scoped method, I get the following 
> >>error:
> >>
> >>22:15:19,898 WARN  [SystemExceptionInterceptor] PhoneBookSession
> >>java.lang.NullPointerException
> >>        at 
> >>org.tranql.sql.DataSourceDelegate.getConnection(DataSourceDelegate.ja
> >>va:36)
> >>        at 
> >>org.tranql.sql.jdbc.JDBCUpdateCommand.execute(JDBCUpdateCommand.java:
> >>62)
> >>        at 
> >>org.tranql.cache.SimpleFlushStrategy.flush(SimpleFlushStrategy.java:5
> >>9)
> >>        at 
> >>org.tranql.cache.SimpleFlushStrategy.flush(SimpleFlushStrategy.java:4
> >>6)
> >>        at org.tranql.cache.InTxCache.flush(InTxCache.java:85)
> >>        at 
> >>org.apache.geronimo.transaction.context.AbstractTransactionContext.fl
> >>ushState(AbstractTransactionContext.java:116)
> >>        at 
> >>org.apache.geronimo.transaction.context.InheritableTransactionContext
> >>.complete(InheritableTransactionContext.java:172)
> >>        at 
> >>org.apache.geronimo.transaction.context.InheritableTransactionContext
> >>.commit(InheritableTransactionContext.java:143)
> >>        at 
> >>org.openejb.transaction.ContainerPolicy$TxRequiresNew.invoke(Containe
> >>rPolicy.java:246)
> >>        at 
> >>org.openejb.transaction.TransactionContextInterceptor.invoke(Transact
> >>ionContextInterceptor.java:80)
> >>        at 
> >>org.openejb.slsb.StatelessInstanceInterceptor.invoke(StatelessInstanc
> >>eInterceptor.java:98)
> >>        at 
> >>org.openejb.transaction.ContainerPolicy$TxRequiresNew.invoke(Containe
> >>rPolicy.java:234)
> >>        at 
> >>org.openejb.transaction.TransactionContextInterceptor.invoke(Transact...
> >>
> >>What am I doing wrong for Application scoping my database configuration?
> >>
> >>Thanks in advance, and sorry for all of the cut-n-pasting here.
> >>
> >>Cheers.
> >>
> >>-Neal
> >>
> >>
> >>    
> >>
> 
> 

Mime
View raw message