31.07.2013 Views

MySQL Cluster Tutorial - cdn.oreillystatic.com

MySQL Cluster Tutorial - cdn.oreillystatic.com

MySQL Cluster Tutorial - cdn.oreillystatic.com

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Compiling and running the <strong>Cluster</strong>J tutorial code<br />

cd /usr/local/clusterj_example_wp_7_1_2a<br />

javac -classpath /usr/local/mysql/share/mysql/java/clusterj-api.jar:. Main.java<br />

Employee.java<br />

java -classpath /usr/local/mysql/share/mysql/java/clusterj.jar:. -<br />

Djava.library.path=/usr/local/mysql/lib Main<br />

OpenJPA/<strong>Cluster</strong>JPA <strong>Tutorial</strong><br />

JPA/OpenJPA/<strong>Cluster</strong>JPA can be used within or outside a container (i.e. it can be used<br />

with J2EE or J2SE) – for simplicity, this tutorial does not use a container (i.e. it is written<br />

using J2SE).<br />

Before being able to run any <strong>Cluster</strong>JPA code, you first need to download and install<br />

OpenJPA from http://openjpa.apache.org/ - this tutorial uses OpenJPA 1.2.1. Simply<br />

extract the contents of the binary tar ball to the host you want to run your application on;<br />

for this tutorial, I use /usr/local/openjpa.<br />

Additionally, <strong>Cluster</strong>JPA must sometimes use JDBC to satisfy certain queries and so<br />

“JDBC Driver for <strong>MySQL</strong> (Connector/J)” should also be installed – this can be<br />

downloaded from http://dev.mysql.<strong>com</strong>/downloads/connector/j/ Again, simply extract<br />

the contents of the tar ball, for this tutorial the files are stored in /usr/local/connectorj and<br />

version 5.1.12 is used.<br />

If the <strong>Cluster</strong>J tutorial has already been run on this <strong>MySQL</strong> <strong>Cluster</strong> database then drop the<br />

tables from the cluster so that you can observe them being created automatically – though<br />

in a real application, you may prefer to create them manually.<br />

A configuration file is required to indicate how persistence is to be handled for the<br />

application. Create a new directory called META-INF in the application source directory<br />

and within there create a file called persistence.xml:<br />

<br />

<br />

<br />

org.apache.openjpa.persistence.PersistenceProviderImpl<br />

<br />

Employee<br />

Department<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

Copyright © 2010, Oracle and/or its affiliates. All rights reserved. 61/81

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!