Categories
Software and Tools

The definitive (I hope!) guide to switching JBoss from Hypersonic to MySQL

Hi folks,

A real techie post today. I’ve just spent most of an afternoon trying to track down a complete list of steps for changing your default data source in JBoss 4.0.4.GA from Hypersonic to MySQL. I’ve had to visit at least a couple dozen forum posts, but have only found the 5 linked in the steps below to be useful in answering my question.

However, none of those 5 had the entire answer, which leads me to the reason for this post. I hope it can help other people out!

  1. (From OnJava.com): With your MySQL driver jarfile downloaded and added to your classpath, copy it to the [jboss-location]/server/default/lib directory.
  2. Changes to the /server/default/deploy directory:
    1. Remove [jboss-location]/server/default/deploy/hsqldb-ds.xml (or move to a location outside of your jboss directory)
    2. (From OnJava.com and EPFL): copy [jboss-location]/docs/examples/jca/mysql-ds.xml to this location. Modify the <local-tx-datasource> element inside the mysql-ds.xml configuration file to match the following (Note there are some parts below which you will have to change!):
      <local-tx-datasource>
      <jndi-name>DefaultDS</jndi-name>
      <connection-url>jdbc:mysql://your-hostname:your-port/your-database-name</connection-url>
      <driver-class>com.mysql.jdbc.Driver</driver-class>
      <user-name>your-user</user-name>
      <password>your-pass</password>
      <security-domain>MySqlDbRealm</security-domain>
      <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-che\cker-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 n\ewer 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>
  3. Next we have to change and replace some files in [jboss-location]/server/default/conf:
    1. (From OnJava.com, Experts’ Exchange and EPFL): In standardjaws.xml change the following two elements, and leave the rest in place:
      <datasource>java:/DefaultDS</datasource>
      <type-mapping>mySQL</type-mapping>
    2. (From OnJava.com, Experts’ Exchange and EPFL): In standardjbosscmp-jdbc.xml change the following, not necessarily contiguous, elements only, leaving the rest in place:
      <datasource>java:/DefaultDS</datasource>
      <datasource-mapping>mySQL</datasource-mapping>
      <fk-constraint>true</fk-constraint>
    3. (From OnJava.com and EPFL): Introduce the following set of tags (ADDING, not replacing anything!) into login-config.xml:
      <application-policy name = "MySqlDbRealm">
      <authentication>
      <login-module code = "org.jboss.resource.security.ConfiguredIdentityLoginModule" flag = "required">
      <module-option name = "principal">your-user</module-option>
      <module-option name = "userName">your-user</module-option>
      <module-option name ="password">your-pass</module-option>
      <module-option name = "managedConnectionFactoryName">jboss.jca:service=LocalTxCM,name=DefaultDS</module-option>
      </login-module>
      </authentication>
      </application-policy>
  4. Next we have to change and replace some files in [jboss-location]/server/default/deploy/jms:
    1. (From OnJava.com and EPFL): Replace file hsql-jdbc2-service.xml by file [jboss-location]/docs/examples/jms/mysql-jdbc2-service.xml, and change the one mention of MySqlDS to DefaultDS
    2. (From Experts’ Exchange): Rename hsqldb-jdbc-state-service.xml to mysql-jdbc-state-service.xml. NO modifications within this file are required!

That’s all, folks! Let me know if I’ve gotten something wrong.

A full list of all the threads that helped me:

Categories
SOC Software and Tools

Visiting with Enigma

Last week I got to see, touch, and hear about an Enigma machine. It was a really amazing experience. I meant to write about it then, but a variety of things (including having to decompile a variety of .class files because IntelliJ, which up until now was a picture-perfect IDE, emptied the corresponding .java files) came up. A very good post on the same experience can be found in Dan Swan’s blog, so I won’t duplicate that work here.

Suffice it to say it stuck in my head, especially since I had recently read Cryptonomicon (Neal Stephenson). Simon Singh was recommended as author for a very good non-fiction codebreaking history book. Another recommended book in this area is Jack Copeland’s Colossus, on the Colossus machine, which was not used for breaking Enigma, but rather for breaking a completely different cipher from the Lorenz SZ 40/42 cipher machine.

p.s. Yes, I had a backup of my java files, but no, they were a couple of days old and therefore it was quicker to decompile using jad.

Categories
Software and Tools

++C

I couldn’t resist posting on the topic of C++ for-loops, as described by this wonderfully irreverent Reg Developer article. I shall leave you to read it, rather than summarizing it in detail here, but as a quick one-liner, it goes into the argument of incrementing counters versus incrementing iterators, and then in a final touch, touches on using algorithms over iterators.

As someone who came to C++ via the unintuitive path of Java -> C -> C++ (my coursework was more “advanced”, if I won’t get torn to pieces saying that, than the coding required in my first job), good ol’ i++ was one of my best friends. Admittedly, using other aspects of “pure” C++ were not problematic: I loved lording the use of templates in vectors, lists etc. over the Java folks. No casting in and out of Object for me! Shame Java had to go and sort out their language to allow that: no lording has happened recently.

Back to the subject at hand. I have to agree with the author of the Reg article, and say that about 90% of the time I try to “be good” and use an algorithm instead of for loops, I end up writing my own functors. (Ok ok – so the first few times I wrote a functor because I thought it was fun, not because it was neccessary – I still can count that in the percentages, can’t I?)

In short: looping algorithms – more fun than they look, but a guilty pleasure as I still cannot quite justify them for the simpler cases. But then the answer is never almost never “all or nothing” programming choices. (I’m sure there’s a completely “all or nothing” choice out there, enjoying its role as the exception that proves the rule.) As a biologist and a programmer (read “bioinformatician”, which is just too tough to say), I find I like this result, in keeping with the biologist’s perspective: the messy answers are the best ones.