Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Apress committed Oct 14, 2016
0 parents commit 4988e39
Show file tree
Hide file tree
Showing 1,125 changed files with 35,220 additions and 0 deletions.
Binary file added 9781430219569.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
50 changes: 50 additions & 0 deletions GettingStarted.txt
@@ -0,0 +1,50 @@

These examples assume that you have installed Java SE 6 and Apache ant.

Java SE 6 is available for download at http://java.sun.com/javase/downloads/index.jsp.
Apache ant is available for download at http://ant.apache.org.

1. Assume the examples have been downloaded and unzipped to <EXAMPLES_HOME>.

2. Edit <EXAMPLES_HOME>/config/setenv.bat to point to your JDK 1.6 ant 1.7.1 installation
directories if JAVA_HOME and ANT_HOME have not been set in your environment.

3. Download and install Glassfish V3 from http://glassfish.dev.java.net.
We recommend installing the Glassfish V3 Web Profile (only a couple of demos, 3-3 and 3-7 will not run).

4. Edit <EXAMPLES_HOME>/config/common.properties and set:

EXAMPLES_HOME - the folder in which the examples were unzipped
SERVER_HOME - the folder in which Glassfish was installed

NOTE: Make sure you use a forward slash separator ('/') not a backward slash ('\')

5. Start Glassfish and the Derby database by invoking the startservers.bat script
in <EXAMPLES_HOME>/bin.

6. Open <EXAMPLES_HOME>/examples/examplesHome.html to get started.

For each server-based example:

1. Run deploy.bat before running the example
2. Run undeploy.bat when finished with the example

The client-based examples have a run.bat script. They assume the database is
already runnning, as in sep 5.

Notes:

A. The first time you start the Glassfish server it will appear to hang at the
Felix intro. It should be faster every time after that.

B. Derby seems to take a long time dropping non-existent tables, so the first time
deploying each of the tests it will take a little longer to execute the run_sql target.
You will also see the DROP TABLE commands fail. It's expected.

C. Example 12 in Ch 4 will not run on Derby because Derby does not support sequences.

D. A few of the tests in Ch 5 do not run correctly due to obscure Map support bugs in EclipseLink.
Installing a later version of EclipseLink into Glassfish might be necessary to get past these.

E. If you plan on taking the demos and changing them for fun, and you get an exception that
an entity class is an "unknown entity type", you may need to bounce (stop and restart) the server.
27 changes: 27 additions & 0 deletions LICENSE.txt
@@ -0,0 +1,27 @@
Freeware License, some rights reserved

Copyright (c) 2010 Mike Keith, Merrick Schincariol, and Jeremy Keith

Permission is hereby granted, free of charge, to anyone obtaining a copy
of this software and associated documentation files (the "Software"),
to work with the Software within the limits of freeware distribution and fair use.
This includes the rights to use, copy, and modify the Software for personal use.
Users are also allowed and encouraged to submit corrections and modifications
to the Software for the benefit of other users.

It is not allowed to reuse, modify, or redistribute the Software for
commercial use in any way, or for a user�s educational materials such as books
or blog articles without prior permission from the copyright holder.

The above copyright notice and this permission notice need to be included
in all copies or substantial portions of the software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS OR APRESS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.


15 changes: 15 additions & 0 deletions README.md
@@ -0,0 +1,15 @@
#Apress Source Code

This repository accompanies [*Pro JPA 2*](http://www.apress.com/9781430219569) by Mike Keith, Merrick Schincariol, and Jeremy Keith (Apress, 2010).

![Cover image](9781430219569.jpg)

Download the files as a zip using the green button, or clone the repository to your machine using Git.

##Releases

Release v1.0 corresponds to the code in the published book, without corrections or updates.

##Contributions

See the file Contributing.md for more information on how you can contribute to this repository.
6 changes: 6 additions & 0 deletions bin/bounceAppServer.bat
@@ -0,0 +1,6 @@
call ../config/setenv

call %ANT_HOME%/bin/ant -f ../config/common.xml stop_server
call %ANT_HOME%/bin/ant -f ../config/common.xml start_server

pause
7 changes: 7 additions & 0 deletions bin/startservers.bat
@@ -0,0 +1,7 @@
call ../config/setenv

call %ANT_HOME%/bin/ant -f ../config/common.xml start_db
call %ANT_HOME%/bin/ant -f ../config/common.xml start_server


pause
6 changes: 6 additions & 0 deletions bin/stopservers.bat
@@ -0,0 +1,6 @@
call ../config/setenv

call %ANT_HOME%/bin/ant -f ../config/common.xml stop_server
call %ANT_HOME%/bin/ant -f ../config/common.xml stop_db

pause
7 changes: 7 additions & 0 deletions config/ant.bat
@@ -0,0 +1,7 @@
@echo off
rem === Called from each example 3 levels down ===

call ../../../config/setenv.bat

call %ANT_HOME%/bin/ant %1

43 changes: 43 additions & 0 deletions config/common.properties
@@ -0,0 +1,43 @@

##################################################
# Installation properties
##################################################

EXAMPLES_HOME=EXAMPLES_HOME_property_not_set_yet
SERVER_HOME=SERVER_HOME_property_not_set_yet

##################################################
# Glassfish properties
##################################################

ADMIN_USER=admin

PASSWORD_PREFIX=
PASSWORD_FILE=

# Uncomment out the following 2 lines if GlassFish was installed with an
# admin password, and enter the password in the password.txt file.
#PASSWORD_PREFIX=--passwordfile
#PASSWORD_FILE="${EXAMPLES_HOME}/config/password.txt"

##################################################
# Derby Database properties
##################################################

DERBY_INSTALL=${SERVER_HOME}/javadb
DERBY_PORT=1527
DERBY_HOST=localhost
DERBY_USER=APP
DERBY_PWD=APP
DERBY_SYSTEM_HOME=${EXAMPLES_HOME}/database
DERBY_CLASSPATH=${DERBY_INSTALL}/lib/derby.jar;${DERBY_INSTALL}/lib/derbynet.jar;${DERBY_INSTALL}/lib/derbyclient.jar;${DERBY_INSTALL}/lib/derbytools.jar

##################################################
# Additional library properties
##################################################

ECLIPSELINK_CLASSPATH=${SERVER_HOME}/glassfish/modules/javax.persistence.jar;${SERVER_HOME}/glassfish/modules/org.eclipse.persistence.oracle.jar;${SERVER_HOME}/glassfish/modules/org.eclipse.persistence.core.jar;${SERVER_HOME}/glassfish/modules/org.eclipse.persistence.jpa.jar;${SERVER_HOME}/glassfish/modules/org.eclipse.persistence.asm.jar;${SERVER_HOME}/glassfish/modules/org.eclipse.persistence.antlr.jar;${SERVER_HOME}/glassfish/modules/org.eclipse.persistence.jpa.modelgen.jar;
SPRING_CLASSPATH=${EXAMPLES_HOME}/lib/spring.jar;${EXAMPLES_HOME}/lib/commons-logging.jar
J2EE_CLASSPATH=${SERVER_HOME}/glassfish/lib/javaee.jar
JPA_CLASSPATH=${SERVER_HOME}/glassfish/modules/javax.persistence.jar
CLIENT_CLASSPATH=${ECLIPSELINK_CLASSPATH};${J2EE_CLASSPATH};${DERBY_CLASSPATH}
197 changes: 197 additions & 0 deletions config/common.xml
@@ -0,0 +1,197 @@
<?xml version="1.0" encoding="iso-8859-1"?>

<project name="common">
<property file="common.properties"/>

<target name="clean">
<delete dir="build"/>
<delete dir="dist"/>
</target>

<target name="setup">
<mkdir dir="build/model"/>
<mkdir dir="build/client"/>
<mkdir dir="build/test"/>
<mkdir dir="build/servlet/WEB-INF/classes"/>
<mkdir dir="dist"/>
<mkdir dir="dist/lib"/>
<available property="modelSrcExists" file="src/model" />
<available property="servletSrcExists" file="src/servlet" />
</target>


<target name="build_ear_without_war" depends="setup,build_jar">
<copy todir="dist/ear/META-INF" failonerror="false">
<fileset file="etc/META-INF/application.xml"/>
</copy>
<jar jarfile="dist/${example_name}.ear" update="yes">
<fileset file="dist/${example_name}.jar"/>
<fileset dir="dist/ear"/>

</jar>
</target>

<target name="build_jar" depends="setup" if="modelSrcExists">
<copy todir="build/model" failonerror="false">
<fileset dir="etc/persistence"/>
</copy>
<javac srcdir="src/model" destdir="build/model" debug="on">
<classpath>
<pathelement path="${CLIENT_CLASSPATH}" />
<pathelement path="build/model" />
</classpath>
</javac>
<jar jarfile="dist/lib/${example_name}.jar" update="true">
<fileset dir="build/model"/>
</jar>
</target>

<target name="build_war" depends="setup,build_jar" if="servletSrcExists">
<javac srcdir="src/servlet" destdir="build/servlet" debug="on">
<classpath>
<pathelement path="${CLIENT_CLASSPATH}" />
<pathelement location="dist/lib/${example_name}.jar" />
</classpath>
</javac>
<war destfile="dist/${example_name}.war" webxml="etc/web/WEB-INF/web.xml" update="true">
<classes dir="build/servlet"/>
<lib dir="dist/lib"/>
<fileset dir="etc/web" excludesFile="etc/web/WEB-INF/web.xml"/>
</war>
</target>

<!-- This target is for an application-managed EE project where there is no persistence injection on a session bean
(injection is on a servlet) -->
<target name="build_jar_without_persistence" depends="setup" if="modelSrcExists">
<javac srcdir="src/model" destdir="build/model" debug="on">
<classpath>
<pathelement path="${CLIENT_CLASSPATH}" />
</classpath>
</javac>
<jar jarfile="dist/lib/${example_name}.jar" update="true">
<fileset dir="build/model"/>
</jar>
</target>

<!-- This target is for an application-managed EE project where there is no persistence injection on a session bean
(injection is on a servlet) -->
<target name="build_with_persistence_in_war" depends="build_war_with_persistence"/>
<target name="build_war_with_persistence" depends="setup,build_jar_without_persistence" if="servletSrcExists">
<javac srcdir="src/servlet" destdir="build/servlet" debug="on">
<classpath>
<pathelement path="${CLIENT_CLASSPATH}" />
<pathelement location="dist/lib/${example_name}.jar" />
</classpath>
</javac>
<copy todir="build/servlet" failonerror="false">
<fileset dir="etc/persistence"/>
</copy>
<war destfile="dist/${example_name}.war" webxml="etc/web/WEB-INF/web.xml" update="true">
<classes dir="build/servlet"/>
<lib dir="dist/lib"/>
<fileset dir="etc/web" excludesFile="etc/web/WEB-INF/web.xml"/>
</war>
</target>

<target name="build_tests" depends="setup,build_jar">
<javac srcdir="src/test" destdir="build/test" debug="on">
<classpath>
<pathelement path="${J2EE_CLASSPATH}" />
<pathelement path="${SPRING_CLASSPATH}" />
<pathelement location="dist/${example_name}.jar" />
</classpath>
</javac>
</target>


<target name="start_server">
<exec executable="${SERVER_HOME}/bin/asadmin" failonerror="true" vmlauncher="false">
<arg line="start-domain --verbose=true domain1"/>
</exec>
</target>

<target name="stop_server" >
<exec executable="${SERVER_HOME}/bin/asadmin" failonerror="true" vmlauncher="false">
<arg line="stop-domain domain1"/>
</exec>
</target>

<target name="start_db" >
<java classname="org.apache.derby.drda.NetworkServerControl"
classpath="${DERBY_CLASSPATH}"
spawn="true"
fork="true">
<arg line="start -h ${DERBY_HOST} -p ${DERBY_PORT}"/>
<sysproperty key="derby.system.home" value="${DERBY_SYSTEM_HOME}"/>
</java>
</target>

<target name="stop_db" >
<java classname="org.apache.derby.drda.NetworkServerControl"
classpath="${DERBY_CLASSPATH}"
fork="true">
<arg line="shutdown -h ${DERBY_HOST} -p ${DERBY_PORT}"/>
<sysproperty key="derby.system.home" value="${DERBY_SYSTEM_HOME}"/>
</java>
</target>

<target name="run_sql">
<sql driver="org.apache.derby.jdbc.ClientDriver"
url="jdbc:derby://${DERBY_HOST}:${DERBY_PORT}/${DB_NAME};create=true"
userid="${DERBY_USER}"
password="${DERBY_PWD}"
src="etc/sql/db.sql"
onerror="continue">
<classpath>
<pathelement path="${DERBY_CLASSPATH}"/>
</classpath>
</sql>
</target>

<target name="deploy_war">
<echo message=" --user ${ADMIN_USER} ${PASSWORD_PREFIX} ${PASSWORD_FILE} deploy dist/${example_name}.war"/>
<exec executable="${SERVER_HOME}/bin/asadmin" failonerror="true" vmlauncher="false">
<arg line=" --user ${ADMIN_USER} ${PASSWORD_PREFIX} ${PASSWORD_FILE} deploy dist/${example_name}.war"/>
</exec>
</target>

<target name="undeploy_war">
<exec executable="${SERVER_HOME}/bin/asadmin" failonerror="true" vmlauncher="false">
<arg line=" --user ${ADMIN_USER} ${PASSWORD_PREFIX} ${PASSWORD_FILE} undeploy ${example_name}"/>
</exec>
</target>

<target name="create_datasource">
<exec executable="${SERVER_HOME}/bin/asadmin" failonerror="true" vmlauncher="false">
<arg line=" --user ${ADMIN_USER} ${PASSWORD_PREFIX} ${PASSWORD_FILE} create-jdbc-connection-pool
--datasourceclassname org.apache.derby.jdbc.ClientXADataSource
--restype javax.sql.XADataSource --property portNumber=${DERBY_PORT}:password=${DERBY_PWD}:user=${DERBY_USER}:serverName=${DERBY_HOST}:databaseName=${DB_NAME}:connectionAttributes=\;create\=true ${DB_NAME}" />
</exec>
<exec executable="${SERVER_HOME}/bin/asadmin" failonerror="true" vmlauncher="false">
<arg line=" --user ${ADMIN_USER} ${PASSWORD_PREFIX} ${PASSWORD_FILE} create-jdbc-resource
--connectionpoolid ${DB_NAME} jdbc/${DB_NAME}" />
</exec>
</target>

<!-- disable auto ddl creation on derby for composite ID attributes using EmbeddedId and IdClass - db.sql creates are significant here-->
<target name="create_datasource_no_ddl_create">
<exec executable="${SERVER_HOME}/bin/asadmin" failonerror="true" vmlauncher="false">
<arg line=" --user ${ADMIN_USER} ${PASSWORD_PREFIX} ${PASSWORD_FILE} create-jdbc-connection-pool
--datasourceclassname org.apache.derby.jdbc.ClientXADataSource
--restype javax.sql.XADataSource --property portNumber=${DERBY_PORT}:password=${DERBY_PWD}:user=${DERBY_USER}:serverName=${DERBY_HOST}:databaseName=${DB_NAME}:connectionAttributes=\;create\=false ${DB_NAME}" />
</exec>
<exec executable="${SERVER_HOME}/bin/asadmin" failonerror="true" vmlauncher="false">
<arg line=" --user ${ADMIN_USER} ${PASSWORD_PREFIX} ${PASSWORD_FILE} create-jdbc-resource
--connectionpoolid ${DB_NAME} jdbc/${DB_NAME}" />
</exec>
</target>

<target name="remove_datasource">
<exec executable="${SERVER_HOME}/bin/asadmin" failonerror="true" vmlauncher="false">
<arg line=" --user ${ADMIN_USER} ${PASSWORD_PREFIX} ${PASSWORD_FILE} delete-jdbc-resource jdbc/${DB_NAME}" />
</exec>
<exec executable="${SERVER_HOME}/bin/asadmin" failonerror="true" vmlauncher="false">
<arg line=" --user ${ADMIN_USER} ${PASSWORD_PREFIX} ${PASSWORD_FILE} delete-jdbc-connection-pool ${DB_NAME}" />
</exec>
</target>
</project>
1 change: 1 addition & 0 deletions config/password.txt
@@ -0,0 +1 @@
AS_ADMIN_PASSWORD=adminadmin
13 changes: 13 additions & 0 deletions config/setenv.bat
@@ -0,0 +1,13 @@
@echo off
rem === If these are not already set in your environment then uncomment and set these
rem === two to the directory appropriate to your environment.
rem
rem JAVA_HOME=
rem ANT_HOME=
rem
set ANT_HOME=c:\ant\apache-ant-1.7.1

if "%JAVA_HOME%"=="" echo "Need to set JAVA_HOME environment variable in <EXAMPLES_HOME>\config\setEnv.bat"
if "%ANT_HOME%"=="" echo "Need to set ANT_HOME environment variable in <EXAMPLES_HOME>\config\setEnv.bat"


0 comments on commit 4988e39

Please sign in to comment.