Commits

Micha Kops committed c552ee6

Java EE 6 bootstrapping/migration example added.

Comments (0)

Files changed (12)

 .project
 .settings
 .classpath
-target
+target
+derby.log
+run:
+	mvn3 package org.glassfish:maven-embedded-glassfish-plugin:3.1.1:run
+
+

infinitest.filters

+it.*
 	<groupId>com.hascode.tutorial</groupId>
 	<artifactId>flyway-migration-tutorial</artifactId>
 	<version>1.0.0</version>
+	<packaging>war</packaging>
 	<prerequisites>
 		<maven>3.0.4</maven>
 	</prerequisites>
 	<properties>
 		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
 		<h2.version>1.3.170</h2.version>
+		<flyway.version>2.1.1</flyway.version>
 	</properties>
 
 	<build>
 			<plugin>
 				<groupId>com.googlecode.flyway</groupId>
 				<artifactId>flyway-maven-plugin</artifactId>
-				<version>2.1.1</version>
+				<version>${flyway.version}</version>
 				<configuration>
 					<url>jdbc:h2:file:target/test_db</url>
 					<user>sa</user>
 					<target>1.7</target>
 				</configuration>
 			</plugin>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-war-plugin</artifactId>
+				<version>2.1.1</version>
+				<configuration>
+					<failOnMissingWebXml>false</failOnMissingWebXml>
+				</configuration>
+			</plugin>
+			<plugin>
+				<groupId>org.glassfish</groupId>
+				<artifactId>maven-embedded-glassfish-plugin</artifactId>
+				<version>3.1.2</version>
+				<configuration>
+					<goalPrefix>embedded-glassfish</goalPrefix>
+					<app>${basedir}/target/${project.artifactId}-${project.version}.war</app>
+					<autoDelete>true</autoDelete>
+					<port>8080</port>
+					<name>flyway-tutorial</name>
+					<configFile>src/test/resources/glassfish/domain.xml</configFile>
+				</configuration>
+				<executions>
+					<execution>
+						<id>start-glassfish</id>
+						<phase>pre-integration-test</phase>
+						<goals>
+							<goal>start</goal>
+						</goals>
+					</execution>
+					<execution>
+						<id>glassfish-deploy</id>
+						<phase>pre-integration-test</phase>
+						<goals>
+							<goal>deploy</goal>
+						</goals>
+					</execution>
+					<execution>
+						<id>glassfish-undeploy</id>
+						<phase>post-integration-test</phase>
+						<goals>
+							<goal>undeploy</goal>
+						</goals>
+					</execution>
+					<execution>
+						<id>stop-glassfish</id>
+						<phase>post-integration-test</phase>
+						<goals>
+							<goal>stop</goal>
+						</goals>
+					</execution>
+				</executions>
+			</plugin>
 		</plugins>
 	</build>
 	<dependencies>
 			<version>4.11</version>
 			<scope>test</scope>
 		</dependency>
+		<dependency>
+			<groupId>org.glassfish.main.extras</groupId>
+			<artifactId>glassfish-embedded-all</artifactId>
+			<version>3.1.2</version>
+			<scope>provided</scope>
+		</dependency>
+		<dependency>
+			<groupId>javax</groupId>
+			<artifactId>javaee-web-api</artifactId>
+			<version>6.0</version>
+			<scope>provided</scope>
+		</dependency>
+		<dependency>
+			<groupId>com.googlecode.flyway</groupId>
+			<artifactId>flyway-core</artifactId>
+			<version>${flyway.version}</version>
+		</dependency>
 	</dependencies>
 </project>

src/main/java/com/hascode/ejb/JeeDbMigrator.java

+package com.hascode.ejb;
+
+import java.util.logging.Logger;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.Resource;
+import javax.ejb.Singleton;
+import javax.ejb.Startup;
+import javax.sql.DataSource;
+
+import com.googlecode.flyway.core.Flyway;
+import com.googlecode.flyway.core.api.MigrationInfo;
+
+@Singleton
+@Startup
+public class JeeDbMigrator {
+	private final Logger log = Logger.getLogger(JeeDbMigrator.class.getName());
+
+	@Resource(name = "jdbc/__default")
+	private DataSource dataSource;
+
+	@PostConstruct
+	private void onStartup() {
+		Flyway flyway = new Flyway();
+		flyway.setSchemas("book_database");
+		flyway.setDataSource(dataSource);
+		flyway.setInitOnMigrate(true);
+		for (MigrationInfo i : flyway.info().all()) {
+			log.info("migrate task: " + i.getVersion() + " : "
+					+ i.getDescription() + " with query: " + i.getScript());
+		}
+	}
+}

src/main/resources/db/migration/V1__Create_book_table.sql

-CREATE TABLE Book (
-    id INT PRIMARY KEY,
-    title VARCHAR(200) NOT NULL
-);

src/main/resources/db/migration/V201304161230__Create_book_table.sql

+CREATE TABLE Book (
+    id INT PRIMARY KEY,
+    title VARCHAR(200) NOT NULL
+);

src/main/resources/db/migration/V201304171620__Insert_books.sql

+INSERT INTO Book (id, title) VALUES (0, 'The first book');
+INSERT INTO Book (id, title) VALUES (0, 'Another book');
+INSERT INTO Book (id, title) VALUES (0, 'The third book');

src/main/resources/db/migration/V201305011700__Alter_book_table_add_author.sql

+ALTER TABLE Book ADD author VARCHAR(200);

src/main/resources/db/migration/V2__Insert_books.sql

-INSERT INTO Book (id, title) VALUES (0, 'The first book');
-INSERT INTO Book (id, title) VALUES (0, 'Another book');
-INSERT INTO Book (id, title) VALUES (0, 'The third book');

src/main/resources/db/migration/V3__Alter_book_table_add_author.sql

-ALTER TABLE Book ADD author VARCHAR(200);

src/test/resources/glassfish/domain.xml

+<!-- DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. Copyright (c) 
+	2010 Oracle and/or its affiliates. All rights reserved. The contents of this 
+	file are subject to the terms of either the GNU General Public License Version 
+	2 only ("GPL") or the Common Development and Distribution License("CDDL") 
+	(collectively, the "License"). You may not use this file except in compliance 
+	with the License. You can obtain a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html 
+	or packager/legal/LICENSE.txt. See the License for the specific language 
+	governing permissions and limitations under the License. When distributing 
+	the software, include this License Header Notice in each file and include 
+	the License file at packager/legal/LICENSE.txt. GPL Classpath Exception: 
+	Oracle designates this particular file as subject to the "Classpath" exception 
+	as provided by Oracle in the GPL Version 2 section of the License file that 
+	accompanied this code. Modifications: If applicable, add the following below 
+	the License Header, with the fields enclosed by brackets [] replaced by your 
+	own identifying information: "Portions Copyright [year] [name of copyright 
+	owner]" Contributor(s): If you wish your version of this file to be governed 
+	by only the CDDL or only the GPL Version 2, indicate your decision by adding 
+	"[Contributor] elects to include this software in this distribution under 
+	the [CDDL or GPL Version 2] license." If you don't indicate a single choice 
+	of license, a recipient has the option to distribute your version of this 
+	file under either the CDDL, the GPL Version 2 or to extend the choice of 
+	license to its licensees as provided above. However, if you add GPL Version 
+	2 code and therefore, elected the GPL Version 2 license, then the option 
+	applies only if the new code is made subject to such option by the copyright 
+	holder. -->
+
+<domain log-root="${com.sun.aas.instanceRoot}/logs"
+	application-root="${com.sun.aas.instanceRoot}/applications" version="10.0">
+	<system-applications />
+	<applications />
+	<resources>
+		<jdbc-resource pool-name="__TimerPool" jndi-name="jdbc/__TimerPool"
+			object-type="system-admin" />
+		<jdbc-resource pool-name="DerbyPool" jndi-name="jdbc/__default" />
+		<jdbc-connection-pool name="__TimerPool"
+			datasource-classname="org.apache.derby.jdbc.EmbeddedXADataSource"
+			res-type="javax.sql.XADataSource">
+			<property value="${com.sun.aas.instanceRoot}/lib/databases/ejbtimer"
+				name="databaseName" />
+			<property value=";create=true" name="connectionAttributes" />
+		</jdbc-connection-pool>
+		<jdbc-connection-pool
+			is-isolation-level-guaranteed="false" name="DerbyPool"
+			datasource-classname="org.apache.derby.jdbc.EmbeddedDataSource"
+			res-type="javax.sql.DataSource">
+			<property name="databaseName"
+				value="${com.sun.aas.instanceRoot}/lib/databases/embedded_default" />
+			<property name="connectionAttributes" value=";create=true" />
+		</jdbc-connection-pool>
+	</resources>
+	<servers>
+		<server name="server" config-ref="server-config">
+			<resource-ref ref="jdbc/__TimerPool" />
+			<resource-ref ref="jdbc/__default" />
+		</server>
+	</servers>
+	<configs>
+		<config name="server-config">
+			<http-service>
+				<access-log rotation-interval-in-minutes="15"
+					rotation-suffix="yyyy-MM-dd" />
+				<virtual-server id="server" network-listeners="http-listener, https-listener" />
+			</http-service>
+			<iiop-service>
+				<orb use-thread-pool-ids="thread-pool-1" />
+				<iiop-listener address="0.0.0.0" port="3700" id="orb-listener-1" />
+				<iiop-listener security-enabled="true" address="0.0.0.0"
+					port="3820" id="SSL">
+					<ssl classname="com.sun.enterprise.security.ssl.GlassfishSSLImpl"
+						cert-nickname="s1as" />
+				</iiop-listener>
+				<iiop-listener security-enabled="true" address="0.0.0.0"
+					port="3920" id="SSL_MUTUALAUTH">
+					<ssl classname="com.sun.enterprise.security.ssl.GlassfishSSLImpl"
+						cert-nickname="s1as" client-auth-enabled="true" />
+				</iiop-listener>
+			</iiop-service>
+			<admin-service type="das-and-server"
+				system-jmx-connector-name="system">
+				<jmx-connector enabled="false" auth-realm-name="admin-realm"
+					security-enabled="false" address="0.0.0.0" port="8686" name="system" />
+				<das-config autodeploy-enabled="false"
+					dynamic-reload-enabled="true" deploy-xml-validation="full"
+					autodeploy-dir="${com.sun.aas.instanceRoot}/autodeploy" />
+				<property value="/admin" name="adminConsoleContextRoot" />
+				<property
+					value="${com.sun.aas.installRoot}/lib/install/applications/admingui.war"
+					name="adminConsoleDownloadLocation" />
+				<property value="${com.sun.aas.installRoot}/.." name="ipsRoot" />
+			</admin-service>
+			<connector-service shutdown-timeout-in-seconds="30">
+			</connector-service>
+			<ejb-container steady-pool-size="0" max-pool-size="32"
+				session-store="${com.sun.aas.instanceRoot}/session-store"
+				pool-resize-quantity="8">
+				<ejb-timer-service />
+			</ejb-container>
+			<mdb-container steady-pool-size="0" max-pool-size="32"
+				pool-resize-quantity="8">
+			</mdb-container>
+			<jms-service type="EMBEDDED" default-jms-host="default_JMS_host">
+				<jms-host name="default_JMS_host" host="localhost" port="7676"
+					admin-user-name="admin" admin-password="admin" lazy-init="false" />
+			</jms-service>
+			<log-service file="${com.sun.aas.instanceRoot}/logs/server.log"
+				log-rotation-limit-in-bytes="2000000">
+				<module-log-levels />
+			</log-service>
+			<security-service
+				activate-default-principal-to-role-mapping="true" jacc="simple">
+				<auth-realm classname="com.sun.enterprise.security.auth.realm.file.FileRealm"
+					name="admin-realm">
+					<property value="${com.sun.aas.instanceRoot}/config/admin-keyfile"
+						name="file" />
+					<property value="fileRealm" name="jaas-context" />
+				</auth-realm>
+				<auth-realm classname="com.sun.enterprise.security.auth.realm.file.FileRealm"
+					name="file">
+					<property value="${com.sun.aas.instanceRoot}/config/keyfile"
+						name="file" />
+					<property value="fileRealm" name="jaas-context" />
+				</auth-realm>
+				<auth-realm
+					classname="com.sun.enterprise.security.auth.realm.certificate.CertificateRealm"
+					name="certificate" />
+				<jacc-provider
+					policy-configuration-factory-provider="com.sun.enterprise.security.provider.PolicyConfigurationFactoryImpl"
+					policy-provider="com.sun.enterprise.security.provider.PolicyWrapper"
+					name="default">
+					<property value="${com.sun.aas.instanceRoot}/generated/policy"
+						name="repository" />
+				</jacc-provider>
+				<jacc-provider
+					policy-configuration-factory-provider="com.sun.enterprise.security.jacc.provider.SimplePolicyConfigurationFactory"
+					policy-provider="com.sun.enterprise.security.jacc.provider.SimplePolicyProvider"
+					name="simple" />
+				<audit-module classname="com.sun.enterprise.security.Audit"
+					name="default">
+					<property value="false" name="auditOn" />
+				</audit-module>
+				<message-security-config auth-layer="SOAP">
+					<provider-config provider-id="XWS_ClientProvider"
+						class-name="com.sun.xml.wss.provider.ClientSecurityAuthModule"
+						provider-type="client">
+						<request-policy auth-source="content" />
+						<response-policy auth-source="content" />
+						<property value="s1as" name="encryption.key.alias" />
+						<property value="s1as" name="signature.key.alias" />
+						<property value="false" name="dynamic.username.password" />
+						<property value="false" name="debug" />
+					</provider-config>
+					<provider-config provider-id="ClientProvider"
+						class-name="com.sun.xml.wss.provider.ClientSecurityAuthModule"
+						provider-type="client">
+						<request-policy auth-source="content" />
+						<response-policy auth-source="content" />
+						<property value="s1as" name="encryption.key.alias" />
+						<property value="s1as" name="signature.key.alias" />
+						<property value="false" name="dynamic.username.password" />
+						<property value="false" name="debug" />
+						<property
+							value="${com.sun.aas.instanceRoot}/config/wss-server-config-1.0.xml"
+							name="security.config" />
+					</provider-config>
+					<provider-config provider-id="XWS_ServerProvider"
+						class-name="com.sun.xml.wss.provider.ServerSecurityAuthModule"
+						provider-type="server">
+						<request-policy auth-source="content" />
+						<response-policy auth-source="content" />
+						<property value="s1as" name="encryption.key.alias" />
+						<property value="s1as" name="signature.key.alias" />
+						<property value="false" name="debug" />
+					</provider-config>
+					<provider-config provider-id="ServerProvider"
+						class-name="com.sun.xml.wss.provider.ServerSecurityAuthModule"
+						provider-type="server">
+						<request-policy auth-source="content" />
+						<response-policy auth-source="content" />
+						<property value="s1as" name="encryption.key.alias" />
+						<property value="s1as" name="signature.key.alias" />
+						<property value="false" name="debug" />
+						<property
+							value="${com.sun.aas.instanceRoot}/config/wss-server-config-1.0.xml"
+							name="security.config" />
+					</provider-config>
+				</message-security-config>
+				<property value="SHA-256" name="default-digest-algorithm" />
+			</security-service>
+			<monitoring-service>
+				<module-monitoring-levels />
+			</monitoring-service>
+			<transaction-service tx-log-dir="${com.sun.aas.instanceRoot}/logs">
+			</transaction-service>
+			<java-config>
+				<jvm-options>-Djavax.net.ssl.keyStore=${com.sun.aas.instanceRoot}/config/keystore.jks</jvm-options>
+				<jvm-options>-Djavax.net.ssl.trustStore=${com.sun.aas.instanceRoot}/config/cacerts.jks</jvm-options>
+				<jvm-options>-Dorg.glassfish.jms.InitializeOnDemand=true</jvm-options>
+			</java-config>
+			<network-config>
+				<protocols>
+					<protocol name="http-listener">
+						<http default-virtual-server="server" max-connections="250">
+							<file-cache enabled="false"></file-cache>
+						</http>
+					</protocol>
+					<protocol security-enabled="true" name="https-listener">
+						<http default-virtual-server="server" max-connections="250">
+							<file-cache enabled="false"></file-cache>
+						</http>
+						<ssl classname="com.sun.enterprise.security.ssl.GlassfishSSLImpl"
+							ssl3-enabled="false" cert-nickname="s1as"></ssl>
+					</protocol>
+				</protocols>
+				<network-listeners>
+					<network-listener port="0" protocol="http-listener"
+						transport="tcp" name="http-listener" thread-pool="http-thread-pool"
+						enabled="false" />
+					<network-listener port="0" protocol="https-listener"
+						transport="tcp" name="https-listener" thread-pool="http-thread-pool"
+						enabled="false" />
+				</network-listeners>
+				<transports>
+					<transport name="tcp"></transport>
+				</transports>
+			</network-config>
+			<thread-pools>
+				<thread-pool name="http-thread-pool" max-queue-size="4096"></thread-pool>
+				<thread-pool name="thread-pool-1" max-thread-pool-size="200" />
+			</thread-pools>
+		</config>
+	</configs>
+	<property name="administrative.domain.name" value="domain1" />
+</domain>