[jboss-cvs] jboss-docs/adminguide/docbook/en/modules ...

Sam Griffith sam.griffith at jboss.com
Mon Feb 19 17:30:28 EST 2007


  User: sgriffith
  Date: 07/02/19 17:30:28

  Modified:    adminguide/docbook/en/modules  appendix-alternative_DBs.xml
  Log:
  This is the first cut of the addding a new datasource appendix.
  
  Revision  Changes    Path
  1.2       +104 -4    jboss-docs/adminguide/docbook/en/modules/appendix-alternative_DBs.xml
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: appendix-alternative_DBs.xml
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-docs/adminguide/docbook/en/modules/appendix-alternative_DBs.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -b -r1.1 -r1.2
  --- appendix-alternative_DBs.xml	19 Feb 2007 18:11:09 -0000	1.1
  +++ appendix-alternative_DBs.xml	19 Feb 2007 22:30:27 -0000	1.2
  @@ -103,11 +103,111 @@
   			Creating a DataSource for MySQL
   		</title>
   		<para>
  +			JBoss allows us to create new data sources for our applications as well as providing one known as <literal>defaultDS</literal>. These datasource definitions can be found in the <literal>deploy</literal> directory of our server definition. The datasource definitions are deployable just like WAR and EAR files. The datasource files can be recognized by looking for the XML files (.xml) that end in <literal>*-ds.xml</literal>. The HyperSonic datasource file is named <literal>hsqldb-ds.xml</literal>. You can look at that file for an exmaple. The things to notice when you look at the HyperSonic datasource are that it's defined with the jndi-name of <literal>defaultDS</literal> it has the username and password included in it, and some other odds and ends.
  +		</para>
  +		<para>
  +			A MySQL datasource definition can be found in <literal>jboss-4.2.0.CR1/docs/examples/jca</literal>.  If you look in there you'll find a file called <literal>mysql-ds.xml</literal>. It looks like this:
  +			<programlisting>
  +				<?xml version="1.0" encoding="UTF-8"?>
  +
  +				<!-- $Id: appendix-alternative_DBs.xml,v 1.2 2007/02/19 22:30:27 sgriffith Exp $ -->
  +				<!--  Datasource config for MySQL using 3.0.9 available from:
  +				http://www.mysql.com/downloads/api-jdbc-stable.html
  +				-->
  +
  +				<datasources>
  +				  <local-tx-datasource>
  +				    <jndi-name>MySqlDS</jndi-name>
  +				    <connection-url>jdbc:mysql://mysql-hostname:3306/jbossdb</connection-url>
  +				    <driver-class>com.mysql.jdbc.Driver</driver-class>
  +				    <user-name>x</user-name>
  +				    <password>y</password>
  +				    <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter</exception-sorter-class-name>
  +				    <!-- should only be used on drivers after 3.22.1 with "ping" support
  +				    <valid-connection-checker-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLValidConnectionChecker</valid-connection-checker-class-name>
  +				    -->
  +				    <!-- sql to call when connection is created
  +				    <new-connection-sql>some arbitrary sql</new-connection-sql>
  +				      -->
  +				    <!-- sql to call on an existing pooled connection when it is obtained from pool - MySQLValidConnectionChecker is preferred for newer drivers
  +				    <check-valid-connection-sql>some arbitrary sql</check-valid-connection-sql>
  +				      -->
   			
  +				    <!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml (optional) -->
  +				    <metadata>
  +				       <type-mapping>mySQL</type-mapping>
  +				    </metadata>
  +				  </local-tx-datasource>
  +				</datasources>
  +			</programlisting>
  +		</para>
  +		<para>
  +			We need to copy that file to the <literal>deploy</literal> directory for our server. (In our case "default"). Once we do that we need to change the <literal>connection-url</literal> to <literal>jdbc:mysql://localhost:3306/jboss</literal>. For the username put <literal>sam</literal> and for the password put <literal>password</literal>.
  +			<programlisting>
  +				<?xml version="1.0" encoding="UTF-8"?>
  +
  +				<!-- $Id: appendix-alternative_DBs.xml,v 1.2 2007/02/19 22:30:27 sgriffith Exp $ -->
  +				<!--  Datasource config for MySQL using 3.0.9 available from:
  +				http://www.mysql.com/downloads/api-jdbc-stable.html
  +				-->
  +
  +				<datasources>
  +				  <local-tx-datasource>
  +				    <jndi-name>MySqlDS</jndi-name>
  +				    <connection-url>jdbc:mysql://localhost:3306/jboss</connection-url>
  +				    <driver-class>com.mysql.jdbc.Driver</driver-class>
  +				    <user-name>sam</user-name>
  +				    <password>password</password>
  +				    <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter</exception-sorter-class-name>
  +				    <!-- should only be used on drivers after 3.22.1 with "ping" support
  +				    <valid-connection-checker-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLValidConnectionChecker</valid-connection-checker-class-name>
  +				    -->
  +				    <!-- sql to call when connection is created
  +				    <new-connection-sql>some arbitrary sql</new-connection-sql>
  +				      -->
  +				    <!-- sql to call on an existing pooled connection when it is obtained from pool - MySQLValidConnectionChecker is preferred for newer drivers
  +				    <check-valid-connection-sql>some arbitrary sql</check-valid-connection-sql>
  +				      -->
  +
  +				    <!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml (optional) -->
  +				    <metadata>
  +				       <type-mapping>mySQL</type-mapping>
  +				    </metadata>
  +				  </local-tx-datasource>
  +				</datasources>
  +			</programlisting>
  +		</para>
  +			<para>When you save the file you should see the datasource be bound by JBoss in the console output like below. Each time you save the file the datasource will be bound and unbound, so you may see multiple entries like below.
  +			<programlisting>
  +				15:57:26,891 INFO  [WrapperDataSourceService] Bound ConnectionManager 'jboss.jca:service=DataSourceBinding,name=MySqlDS' to JNDI name 'java:MySqlDS'
  +			</programlisting>
  +		</para>
  +		<para>
  +			This is how you configure a datasource for use in JBoss application server. Not we did not take the HyperSonic datasource away as it is used by many JBoss services. If you are going to deploy to production, you will want to configure each service to use a specific datasource. Such as configuring JMS to use MySQL instead of the <literal>defaultDS</literal>.
   		</para>
   	</section>
   	
  -	<programlisting>validate:
  -   ??? [java] ImplementationTitle: JBoss [Zion]
  +	<section>
  +		<title>Linking a Datasource to your Application</title>
  +		<para>
  +			To configure your application to use MySQL, look for a *jbosscmp-jdbc.xml deployment descriptor. It is located in your servers <literal>conf</literal> directory. 
  +			<programlisting>
  +				<jbosscmp-jdbc>
  +
  +				   <defaults>
  +				      <datasource>java:/MySqlDS</datasource>
  +				      <!-- optional since 4.0 <datasource-mapping>Hypersonic SQL</datasource-mapping> -->
  +							<datasource>mySQL</datasource-mapping>
  +				   </defaults>
  +				</jbosscmp-jdbc>
   	</programlisting>
  +			Although the <literal>datasource-mapping</literal> is optional, it is nice to know the type of the datasource, as this ties directly back to the type-mapping of the datasource.
  +		</para>
  +		<para>For a full set of defautl datasource mappings look in <literal>jboss-4.2.0.CR1/server/default/conf/standardjbosscmp-jdbc.xml</literal>. In that file you can look for the <literal>mySQL</literal> type mapping.
  +		</para>
  +		<para>
  +			If you need to change any of the type mappings for mySQL you can put your own custom <literal>jbosscmp-jdbc.xml</literal> file right in your META-INF directory of your EJB JAR with the <literal>ejb-jar.xml</literal> and </literal>jboss.xml</literal> deployment descriptor files. Then you need to add a <literal>-Doptonal.dd=mysql</literal> to your <literal>ant</literal> build commands. When you've done that, your application will now be talking to MySQL. Now when you look at the tables for your MySQL database, you should see some tables that your application deployment created. You can see the tables in a MySQL database by typeing <literal>show tables;</literal>.
  +		</para>
  +	</section>
  +	
   </appendix>
  \ No newline at end of file
  
  
  



More information about the jboss-cvs-commits mailing list