Can I create classes from schema/sql/and sql queries in mybatis? - orm

I am more a database person than OO (even that I can do). So, I have a database as sql strings, and a lot of queries (also of course the content). I do not, actually, want to "type that down" to an OO model (e.g. class Person int id get/set(int id) etc) - SQL is so quick instead of that. It is a client requirement to use ORM.
Is there a tool that can do that for me? (I would rather write my own parser to do that procedure than to "code" that all). Also, if mybatis can't do it, is there another ORM software that can do so? (any ORM software will do, actually, just that mybatis is said to be lightweight and sql-similar).

You can use Mybatis generator plugin pretty bit simple.
If you are using maven in your project here is basic plugin configuration
<pluginManagement>
<plugins>
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<versionRange>[1.3.2,)</versionRange>
<goals>
<goal>generate</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute />
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.2</version>
<configuration>
<configurationFile>${basedir}/src/main/resources/kp-mybatis-generator.xml</configurationFile>
<outputDirectory>${basedir}/src/main/java</outputDirectory>
<overwrite>true</overwrite>
</configuration>
<executions>
<execution>
<id>Generate MyBatis Artifacts</id>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
And the generator xml configuration
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE generatorConfiguration
PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
<generatorConfiguration>
<classPathEntry location="C:\down\ojdbc6.jar" />
<context id="kpOracleGens" targetRuntime="MyBatis3Simple">
<jdbcConnection driverClass="oracle.jdbc.driver.OracleDriver"
connectionURL="jdbc:oracle:thin:#localhost:1521:KPORACLE" userId="******"
password="******">
</jdbcConnection>
<javaModelGenerator targetPackage="com.kp.swasthik.db.domain"
targetProject="MAVEN">
<property name="enableSubPackages" value="false" />
<property name="trimStrings" value="false" />
</javaModelGenerator>
<sqlMapGenerator targetPackage="com.kp.swasthik.db.persistence"
targetProject="MAVEN">
<property name="enableSubPackages" value="false" />
</sqlMapGenerator>
<javaClientGenerator type="XMLMAPPER"
targetPackage="com.kp.swasthik.db.mapper" targetProject="MAVEN"
implementationPackage="com.kp.swasthik.db.service">
<property name="enableSubPackages" value="true" />
</javaClientGenerator>
<table tableName="%KPC%" catalog="*" schema="kprasad">
<property name="useActualColumnNames" value="true" />
</table>
<table tableName="FOO" catalog="*" schema="kprasad">
<property name="useActualColumnNames" value="true" />
</table>
</context>
</generatorConfiguration>

Related

Adding Information To JUnit Test Results via tycho-surefire-plugin

The test results of JUnit tests have a properties tag with a bunch of properties. What is logged seems to be at the discretion of each executor of the tests.
I want to process the XML files further, so it would be really nice to have the same keys each time. For maven-surefire-plugin that's pretty straightforward:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemPropertyVariables>
<propertyName>propertyValue1</propertyName>
</systemPropertyVariables>
</configuration>
</plugin>
This adds the line <property name="propertyName" value="propertyValue1"/> to the XML result file.
For the tycho-surefire-plugin, I tried the following:
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-surefire-plugin</artifactId>
<version>${tycho-version}</version>
<configuration>
<systemPropertyVariables>
<propertyName>propertyValue1</propertyName>
</systemPropertyVariables>
<systemProperties>
<property>
<name>propertyName</name>
<value>propertyValue2</value>
</property>
</systemProperties>
<argLine>-DpropertyName=propertyValue3</argLine>
</configuration>
</plugin>
...but neither of these values is printed inside the XML result.
How do I add information to the JUnit test results using tycho-surefire-plugin?
The documentation of the tycho-surefire-plugin states that you should use the <systemProperties> map:
<configuration>
<systemProperties>
<propertyName>propertyValue1</propertyName>
</systemProperties>
</configuration>
This will start the forked test JVM with -DpropertyName=propertyValue1.

org.jboss.arquillian.container.spi.ConfigurationException: jbossHome 'null' must exist

I'm getting
org.jboss.arquillian.container.spi.ConfigurationException: jbossHome 'null' must exist
when I try to run my Arquillian test from maven. What should I do?
You can also try to point the required property in arquillian.xml.
For instance in my arquillian.xml:
<?xml version="1.0" encoding="UTF-8"?>
<arquillian xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://jboss.org/schema/arquillian"
xsi:schemaLocation="http://jboss.org/schema/arquillian
http://jboss.org/schema/arquillian/arquillian_1_0.xsd">
<defaultProtocol type="Servlet 3.0" />
<container qualifier="jboss" default="true">
<configuration>
<property name="jbossHome">c:\dev\jboss-eap-6.3\</property>
<property name="serverConfig">standalone-test.xml</property>
<property name="javaVmArguments">-Xrunjdwp:transport=dt_socket,address=5505,server=y,suspend=n -Xmx1024m -XX:MaxPermSize=256m</property>
</configuration>
</container>
</arquillian>
You need to set the JBOSS_HOME environment variable pointing to your Jboss/EAP server before running your integration tests. You do it either from command line:
set JBOSS_HOME=c:\jboss-eap-6.4 (on Windows)
export JBOSS_HOME=/home/jboss-eap-6.4 (on Linux)
or set in your pom.xml file:
<build><plugins><plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<environmentVariables>
<JBOSS_HOME>c:\jboss-eap-6.4</JBOSS_HOME>
</environmentVariables>
</configuration>
</execution>
</executions>
</plugin></plugins></build>

eliminate maven dependency duplication

In my Maven build, I use the antrun plugin to invoke an ant task.
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>compile</phase>
<configuration>
<tasks>
<property name="plugin_classpath" refid="maven.plugin.classpath" />
<java classname="org.apache.tools.ant.launch.Launcher"
fork="true" failonerror="true">
<classpath>
<pathelement path="${plugin_classpath}" />
</classpath>
</java>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
<dependencies>
<!-- DEPENDENCIES FROM PROJECT DUPLICATED HERE -->
</dependencies>
</plugin>
I need to duplicate all the project dependencies in the section indicated, so that they are available to the ant task. Is there a way to avoid this duplication, by referring to the project's dependencies instead of copy-pasting them?
Here's how you can do it:
<property name="plugin_classpath" refid="maven.plugin.classpath" />
<property name="compile_classpath" refid="maven.compile.classpath" />
<java classname="org.apache.tools.ant.launch.Launcher"
fork="true" failonerror="true">
<classpath>
<pathelement path="${plugin_classpath}" />
<pathelement path="${compile_classpath}" />
</classpath>
</java>
Reference:
Maven Antrun Plugin > Referencing the Maven Classpaths

Ant, Maven and Jdeveloper SOA Extension

We are in the middle of a large Java EE project/programme. Up to this point, we've been using Eclipse and Maven for our development. The appserver we are targeting is WebLogic (Oracle, these days).
It has been decided we are going to start using Oracle Business Rules (Part of Oracle SOA Suite 11g). Development for Soa Suite is confined to JDeveloper. It has some nice ant scripts to build and deploy SOA Composites (which is how rules are packaged and deployed).
I have been tasked with getting these ant scripts to run from maven using antrun, and I've gotten some of the way, but not all...
My main question is: has anyone succeeded doing this? (Has anyone even attempted..? Can't really find anything googling...)
Below is the relevant part of my pom:
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<phase>compile</phase>
<configuration>
<target>
<property name="oracle.home" value="C:\Oracle\Middleware\jdeveloper"/>
<property name="oracle.soa.mgmt.home" value="C:\Oracle\Middleware\jdeveloper"/>
<property name="common.components.home" value="C:\Oracle\Middleware\oracle_common"/>
<property name="env.JAVA_HOME" value="${java.home}"/>
<property name="env.PWD" value="."/>
<ant antfile="${oracle.home}\bin\ant-sca-compile.xml"/>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
Maven is run from the project dir, outside the Oracle/Middleware tree. This almost works...
Actually, it gives the following result:
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building BilagorReglerSCA
[INFO] task-segment: [compile]
[INFO] ------------------------------------------------------------------------
[INFO] [resources:resources]
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO] [compiler:compile]
[INFO] Nothing to compile - all classes are up to date
[INFO] [antrun:run {execution: default}]
[INFO] Executing tasks
main:
scac:
Validating composite "C:\JDeveloper\mywork\BilagorReglerSCA\BilagorRegler\composite.xml"
[scac] oracle.fabric.common.wsdl.XSDException: Error loading schema from file:/C:/JDeveloper/mywork/BilagorReglerSCA/BilagorRegler/BilagorRegler_DecisionService.wsdl [Cause=Error in getting XML input stream: oramds:/soa/shared/rules/BpelProcess.xsd: oracle.mds.exception.MDSException: MDS-00054: Filen som ska laddas oramds:/soa/shared/rules/BpelProcess.xsd finns inte.]
[scac] at oracle.fabric.common.wsdl.SchemaBuilder.loadEmbeddedSchemas(SchemaBuilder.java:496)
[scac] at oracle.fabric.common.wsdl.SchemaBuilder.loadSchemasFromWSDL(SchemaBuilder.java:365)
...
The phrase "Filen som ska laddas oramds:/soa/shared/rules/BpelProcess.xsd finns inte." means the "file you are trying to load does not exist" (why does my client insist on installing Swedish language version of Windows, rather than international?).
ant-sca-compile.xml contains numerous import statements similar to this:
<fileset dir="${common.components.home}/modules">
...
<include name="oracle.mds_11.1.1/oramds.jar"/>
I assume oramds.jar is needed to process oramds-URL:s, which are used in the WSDS/XSD:s JDeveloper generates.
Any help appreciated...
OK, so I eventually got a chance to sit down with an ace Oracle consultant and get this to work.
This is what we came up with:
<properties>
<oracle.fmw.soa.home>C:/Oracle/Middleware</oracle.fmw.soa.home>
<!-- this is relative reference to JDK / Jrockit from ant-sca-compile|*.xml. For jdev it is ../../, for Soa Suite: TBD. -->
<env.JAVA_HOME>../../jdk160_24</env.JAVA_HOME>
<!-- For real server with Soa Suite installed use: Oracle_SOA1, for devenv use jdeveloper -->
<oracle.fmw.productName>jdeveloper</oracle.fmw.productName>
<antOutputDir>deploy</antOutputDir>
<mvnOutputDir>target</mvnOutputDir>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>sca-compile</id>
<phase>compile</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<property name="scac.input" value="${basedir}/composite.xml" />
<property name="scac.application.home" value="${basedir}/.." />
<property name="oracle.home" value="${oracle.fmw.soa.home}/${oracle.fmw.productName}" />
<ant
antfile="${oracle.fmw.soa.home}/${oracle.fmw.productName}/bin/ant-sca-compile.xml"
dir="${oracle.fmw.soa.home}/${oracle.fmw.productName}/bin/"
target="scac" />
</target>
</configuration>
</execution>
<execution>
<id>sca-package</id>
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target name="package">
<property name="build.compiler" value="extJavac" />
<property name="compositeName" value="${project.artifactId}" />
<property name="compositeDir" value="${basedir}" />
<property name="revision" value="${project.version}" />
<property name="scac.application.home" value="${basedir}/.." />
<property name="oracle.home" value="${oracle.fmw.soa.home}/${oracle.fmw.productName}" />
<property name="antOutputFile" value="sca_${project.artifactId}_rev${project.version}.jar" />
<property name="mvnOutputFile" value="${project.artifactId}-${project.version}.jar" />
<ant
antfile="${oracle.fmw.soa.home}/${oracle.fmw.productName}/bin/ant-sca-package.xml"
dir="${oracle.fmw.soa.home}/${oracle.fmw.productName}/bin"
target="package" />
<copy tofile="${mvnOutputDir}/${mvnOutputFile}" file="${antOutputDir}/${antOutputFile}" />
</target>
</configuration>
</execution>
<execution>
<id>sca-deploy</id>
<phase>deploy</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target name="deploy">
<property name="serverURL" value="${weblogic.serverURL}" />
<property name="user" value="${weblogic.user}" />
<property name="password" value="${weblogic.password}" />
<property name="sarLocation" value="${basedir}/deploy/sca_${project.artifactId}_rev${project.version}.jar" />
<property name="overwrite" value="true" />
<property name="forceDefault" value="true" />
<property name="partition" value="default" />
<property name="oracle.home" value="${oracle.fmw.soa.home}/${oracle.fmw.productName}" />
<ant
antfile="${oracle.fmw.soa.home}/${oracle.fmw.productName}/bin/ant-sca-deploy.xml"
dir="${oracle.fmw.soa.home}/${oracle.fmw.productName}/bin"
target="deploy" />
</target>
</configuration>
</execution>
<execution>
<id>sca-test</id>
<phase>deploy</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<property name="jndi.properties.input" value="${basedir}/sca-test.jndi.properties" />
<property name="scatest.input" value="scatestinput" />
<property name="scatest.format" value="junit" />
<property name="scatest.result" value="reports" />
<property name="oracle.home" value="${oracle.fmw.soa.home}/${oracle.fmw.productName}" />
<ant
antfile="${oracle.fmw.soa.home}/${oracle.fmw.productName}/bin/ant-sca-test.xml"
dir="${oracle.fmw.soa.home}/${oracle.fmw.productName}/bin"
target="test" />
</target>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Note, both different sets of properties and parameters to the ant-tag than what I was originally attempting with.
To run on a CI-server, you obviously need a local install of JDeveloper or SOA Suite. weblogic.serverURL, weblogic.user and weblogic.password needs to be set to your corresponding environment (I use profiles for local/dev/tst/etc...).
Other than that, it works like a charm...
I've not used Maven + Oracle SOA build scripts but generally when using any of the Oracle deployment tools (ADF, SOA, etc) you will need to have either an Oracle SOA Home or a JDev home (with the SCA extension) on the same machine that the build is running on. You'll need to set the Ant environment variables correctly e.g. oracle.home and common.components.home etc
Use ant-sca-package.xml (not ant-sca-compile.xml):
<ant antfile="ant-sca-package.xml" dir="${env.BEA_HOME}/jdeveloper/bin">
<property name="compositeDir" value="#{compositeDir}" />
<property name="compositeName" value="#{compositeName}" />
<property name="revision" value="${deploy.revision}" />
</ant>

hudson build a project using junit maven and HSQLDB in server mode

I have a project of persistence with spring and hibernate built with maven, I'm running the testing using Junit and a test database HSQLDB, when I do a test first initialize the database HSQLDB in server mode, is there some way to make hudson initializes the database, or with maven ?
I'd use DbUnit and the DbUnit Maven Plugin for that. You can use it to Clear database and insert a dataset before test phase and/or to setup data for each test cases (see the Getting Started for JUnit 3, see this blog post for example for JUnit 4).
Another option would be to use the SQL Maven Plugin. The examples section has a configuration that shows how to drop/create a database and schema, then populate it before the test phase, and drop the database after the test phase).
The later approach gives you less control on data setup between tests which is why I prefer DbUnit.
I add the folowing to pom.
<build>
<extensions>
<extension>
<groupId>hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>1.8.0.7</version>
</extension>
<extension>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.14</version>
</extension>
</extensions>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>hibernate3-maven-plugin</artifactId>
<version>2.0</version>
<configuration>
<components>
<component>
<name>hbm2java</name>
<implementation>annotationconfiguration</implementation>
<outputDirectory>/src/main/java</outputDirectory>
</component>
</components>
<componentProperties>
<jdk5>true</jdk5>
<export>false</export>
<drop>true</drop>
<outputfilename>schema.sql</outputfilename>
</componentProperties>
</configuration>
<executions>
<execution>
<id>generate-ddl</id>
<phase>process-classes</phase>
<goals>
<!--Genera Esquema-->
<goal>hbm2ddl</goal>
<!--Genera Clases -->
<!-- <goal>hbm2java</goal> -->
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>sql-maven-plugin</artifactId>
<version>1.0</version>
<executions>
<execution>
<id>create-schema</id>
<phase>process-test-resources</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<autocommit>true</autocommit>
<srcFiles>
<srcFile>target/hibernate3/sql/schema.sql</srcFile>
</srcFiles>
</configuration>
</execution>
<execution>
<id>drop-db-after-test</id>
<phase>test</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<autocommit>true</autocommit>
<sqlCommand>DROP SCHEMA public CASCADE</sqlCommand>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>1.8.0.7</version>
</dependency>
</dependencies>
<configuration>
<driver>org.hsqldb.jdbcDriver</driver>
<username>sa</username>
<password></password>
<url>jdbc:hsqldb:file:etc/out/test.db;shutdown=true</url>
<autocommit>true</autocommit>
<skip>${maven.test.skip}</skip>
</configuration>
</plugin>
</plugins>
</build>
and the folowing to my datasource:
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" lazy-init="true"
destroy-method="close">
<property name="driverClassName" value="org.hsqldb.jdbcDriver" />
<property name="url" value="jdbc:hsqldb:file:etc/out/test.db;shutdown=true" />
<property name="username" value="sa" />
<property name="password" value="" />
</bean>
We do that with Maven under Hudson, with a profile that triggers the maven-antrun-plugin in the process-test-resources phase. In our case the maven-antrun-plugin runs a Java class that generates the schema, but of course there are other options. It looks like this:
<profile>
<id>dev</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>generate-database-schema-new</id>
<phase>process-test-resources</phase>
<configuration>
<tasks>
...
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>