Hibernate SVN: r18034 - beanvalidation/tck/trunk/src/main/assembly and 3 other directories.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-11-24 11:12:57 -0500 (Tue, 24 Nov 2009)
New Revision: 18034
Added:
beanvalidation/tck/trunk/src/main/docbook/en-US/sigtest.xml
Modified:
beanvalidation/tck/trunk/changelog.txt
beanvalidation/tck/trunk/pom.xml
beanvalidation/tck/trunk/src/main/assembly/assembly.xml
beanvalidation/tck/trunk/src/main/docbook/en-US/installation.xml
beanvalidation/tck/trunk/src/main/docbook/en-US/part-execution.xml
beanvalidation/tck/trunk/src/main/docbook/en-US/reporting.xml
beanvalidation/tck/trunk/src/main/resources/validation-api.sig
validator/trunk/hibernate-validator-tck-runner/pom.xml
Log:
BVTCK-4
Added sigtest file
Udated the documentation and assembly
Modified: beanvalidation/tck/trunk/changelog.txt
===================================================================
--- beanvalidation/tck/trunk/changelog.txt 2009-11-24 15:36:49 UTC (rev 18033)
+++ beanvalidation/tck/trunk/changelog.txt 2009-11-24 16:12:57 UTC (rev 18034)
@@ -6,6 +6,9 @@
1.0.2.GA
----------------------
+** Task
+ * [BVTCK-3] - Create release notes for the distribution package
+ * [BVTCK-4] - Add signature test file to TCK distribution package
1.0.1.GA (28-10-2009)
Modified: beanvalidation/tck/trunk/pom.xml
===================================================================
--- beanvalidation/tck/trunk/pom.xml 2009-11-24 15:36:49 UTC (rev 18033)
+++ beanvalidation/tck/trunk/pom.xml 2009-11-24 16:12:57 UTC (rev 18034)
@@ -1,5 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.hibernate.jsr303.tck</groupId>
<artifactId>jsr303-tck</artifactId>
@@ -55,23 +57,23 @@
<groupId>org.jboss.test-harness</groupId>
<artifactId>jboss-test-harness-api</artifactId>
<version>1.0.0</version>
- <exclusions>
- <exclusion>
- <groupId>log4j</groupId>
- <artifactId>log4j</artifactId>
- </exclusion>
- </exclusions>
+ <exclusions>
+ <exclusion>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ </exclusion>
+ </exclusions>
</dependency>
<dependency>
<groupId>org.jboss.test-harness</groupId>
<artifactId>jboss-test-harness</artifactId>
<version>1.0.0</version>
- <exclusions>
- <exclusion>
- <groupId>log4j</groupId>
- <artifactId>log4j</artifactId>
- </exclusion>
- </exclusions>
+ <exclusions>
+ <exclusion>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ </exclusion>
+ </exclusions>
</dependency>
</dependencies>
@@ -85,7 +87,48 @@
</extension>
</extensions>
<plugins>
- <plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.0.2</version>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <configuration>
+ <archive>
+ <manifest>
+ <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
+ <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
+ </manifest>
+ </archive>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-enforcer-plugin</artifactId>
+ <version>1.0-alpha-4</version>
+ <executions>
+ <execution>
+ <id>enforce</id>
+ <goals>
+ <goal>enforce</goal>
+ </goals>
+ <configuration>
+ <rules>
+ <requireMavenVersion>
+ <version>2.0.9</version>
+ </requireMavenVersion>
+ </rules>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
<groupId>org.jboss.maven.plugins</groupId>
<artifactId>maven-jdocbook-plugin</artifactId>
<version>2.2.0</version>
@@ -221,7 +264,9 @@
<configuration>
<allowTimestampedSnapshots>true</allowTimestampedSnapshots>
<remoteTagging>true</remoteTagging>
- <goals>deploy org.jboss.maven.plugins:maven-jdocbook-plugin:2.2.0:resources org.jboss.maven.plugins:maven-jdocbook-plugin:2.2.0:generate assembly:assembly</goals>
+ <goals>deploy org.jboss.maven.plugins:maven-jdocbook-plugin:2.2.0:resources
+ org.jboss.maven.plugins:maven-jdocbook-plugin:2.2.0:generate assembly:assembly
+ </goals>
</configuration>
</plugin>
<plugin>
@@ -234,61 +279,16 @@
</configuration>
</plugin>
</plugins>
- <pluginManagement>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- <version>2.0.2</version>
- <configuration>
- <source>1.5</source>
- <target>1.5</target>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-jar-plugin</artifactId>
- <configuration>
- <archive>
- <manifest>
- <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
- <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
- </manifest>
- </archive>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-enforcer-plugin</artifactId>
- <version>1.0-alpha-4</version>
- <executions>
- <execution>
- <id>enforce</id>
- <goals>
- <goal>enforce</goal>
- </goals>
- <configuration>
- <rules>
- <requireMavenVersion>
- <version>2.0.9</version>
- </requireMavenVersion>
- </rules>
- </configuration>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </pluginManagement>
</build>
<ciManagement>
<system>Hudson</system>
- <url />
+ <url/>
</ciManagement>
<issueManagement>
<system>JIRA</system>
- <url>http://opensource.atlassian.com/projects/hibernate/browse/HV</url>
+ <url>http://opensource.atlassian.com/projects/hibernate/browse/BVTCK</url>
</issueManagement>
<inceptionYear>2008</inceptionYear>
@@ -302,7 +302,8 @@
<scm>
<connection>scm:svn:http://anonsvn.jboss.org/repos/hibernate/beanvalidation/tck/trunk</connection>
- <developerConnection>scm:svn:https://svn.jboss.org/repos/hibernate/beanvalidation/tck/trunk</developerConnection>
+ <developerConnection>scm:svn:https://svn.jboss.org/repos/hibernate/beanvalidation/tck/trunk
+ </developerConnection>
</scm>
<distributionManagement>
@@ -343,18 +344,19 @@
<executions>
<execution>
<id>process_annotations</id>
- <phase>process-test-resources</phase>
+ <phase>process-resources</phase>
<configuration>
<tasks>
- <javac srcdir="src/main/java" destdir="/target/classes" failonerror="false" excludes="test/**">
- <compilerarg value="-proc:only" />
- <compilerarg value="-AauditXml=${basedir}/src/main/resources/tck-audit.xml" />
+ <javac srcdir="${basedir}/src/main/java"
+ destdir="${basedir}/target/classes"
+ failonerror="true">
+ <compilerarg value="-proc:only"/>
+ <compilerarg value="-AauditXml=${basedir}/src/main/resources/tck-audit.xml"/>
<classpath>
- <path refid="maven.test.classpath" />
+ <path refid="maven.compile.classpath"/>
</classpath>
</javac>
</tasks>
- <sourceRoot>generate</sourceRoot>
</configuration>
<goals>
<goal>run</goal>
Modified: beanvalidation/tck/trunk/src/main/assembly/assembly.xml
===================================================================
--- beanvalidation/tck/trunk/src/main/assembly/assembly.xml 2009-11-24 15:36:49 UTC (rev 18033)
+++ beanvalidation/tck/trunk/src/main/assembly/assembly.xml 2009-11-24 16:12:57 UTC (rev 18034)
@@ -18,7 +18,7 @@
<fileSets>
<fileSet>
<directory>target</directory>
- <outputDirectory/>
+ <outputDirectory>artifacts</outputDirectory>
<excludes>
<exclude>*-javadoc.jar</exclude>
<exclude>*-sources.jar</exclude>
@@ -47,21 +47,17 @@
</fileSet>
<fileSet>
<directory>${project.basedir}/src/main/resources</directory>
- <outputDirectory>/</outputDirectory>
+ <outputDirectory>/artifacts</outputDirectory>
<includes>
+ <include>tck-audit.xml</include>
<include>tck-tests.xml</include>
+ <include>validation-api.sig</include>
+ <include>readme.txt</include>
</includes>
</fileSet>
<fileSet>
- <directory>${project.basedir}/src/main/resources</directory>
- <outputDirectory>/</outputDirectory>
- <includes>
- <include>tck-audit.xml</include>
- </includes>
- </fileSet>
- <fileSet>
<directory>${project.basedir}/target</directory>
- <outputDirectory>/</outputDirectory>
+ <outputDirectory>/artifacts</outputDirectory>
<includes>
<include>coverage.html</include>
</includes>
Modified: beanvalidation/tck/trunk/src/main/docbook/en-US/installation.xml
===================================================================
--- beanvalidation/tck/trunk/src/main/docbook/en-US/installation.xml 2009-11-24 15:36:49 UTC (rev 18033)
+++ beanvalidation/tck/trunk/src/main/docbook/en-US/installation.xml 2009-11-24 16:12:57 UTC (rev 18034)
@@ -71,7 +71,7 @@
source into a subfolder ri. This will allow you to run the TCK against
Hibernate Validator.</para>
- <programlisting>svn co http://anonsvn.jboss.org/repos/hibernate/validator/tags/v4_0_1_GA ri</programlisting>
+ <programlisting>svn co http://anonsvn.jboss.org/repos/hibernate/validator/tags/v4_0_2_GA ri</programlisting>
<para>If you have downloaded the Hibernate Validator distribution, extract
it into a sibling folder named hibernate-validator. The resulting folder
Modified: beanvalidation/tck/trunk/src/main/docbook/en-US/part-execution.xml
===================================================================
--- beanvalidation/tck/trunk/src/main/docbook/en-US/part-execution.xml 2009-11-24 15:36:49 UTC (rev 18033)
+++ beanvalidation/tck/trunk/src/main/docbook/en-US/part-execution.xml 2009-11-24 16:12:57 UTC (rev 18034)
@@ -6,11 +6,14 @@
<partintro>
<para>In this part you learn how to execute the Bean Validation TCK on the
- Bean validation reference implementation (Hibernate Validator). First, you
- are walked through the steps necessary to execute the test suite on
- Hibernate Validator. Then you discover how to modify the TCK runner to
- execute the test suite on your own implementation. </para>
+ Bean validation reference implementation (Hibernate Validator). You are
+ walked through the steps necessary to execute the test suite against
+ Hibernate Validator and you discover how to modify the TCK runner to
+ execute the test suite against your own implementation. First, however,
+ you learn how to pass the Signature Test.</para>
</partintro>
+ <xi:include href="sigtest.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
+
<xi:include href="executing.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
</part>
Modified: beanvalidation/tck/trunk/src/main/docbook/en-US/reporting.xml
===================================================================
--- beanvalidation/tck/trunk/src/main/docbook/en-US/reporting.xml 2009-11-24 15:36:49 UTC (rev 18033)
+++ beanvalidation/tck/trunk/src/main/docbook/en-US/reporting.xml 2009-11-24 16:12:57 UTC (rev 18034)
@@ -20,7 +20,7 @@
<para><emphasis role="bold">Assertion Breadth
Coverage</emphasis></para>
- <para>The BEan Validation TCK provides at least 100% coverage of
+ <para>The Bean Validation TCK provides at least 100% coverage of
identified assertions with test cases.</para>
</listitem>
@@ -42,12 +42,6 @@
</listitem>
<listitem>
- <para><emphasis role="bold">Method Coverage</emphasis></para>
-
- <para>TODO</para>
- </listitem>
-
- <listitem>
<para><emphasis role="bold">API Signature Coverage</emphasis></para>
<para>The Bean Validation TCK covers 100% of all API public methods
@@ -309,8 +303,8 @@
<para>The test suite detail report is very useful, but it borderlines
on complex. As an alternative, you can have a look at the emailable
report, which is a single HTML document that shows much of the same
- information as the test suite detail report in a more compact layout.
- </para>
+ information as the test suite detail report in a more compact
+ layout.</para>
</section>
</section>
</section>
Added: beanvalidation/tck/trunk/src/main/docbook/en-US/sigtest.xml
===================================================================
--- beanvalidation/tck/trunk/src/main/docbook/en-US/sigtest.xml (rev 0)
+++ beanvalidation/tck/trunk/src/main/docbook/en-US/sigtest.xml 2009-11-24 16:12:57 UTC (rev 18034)
@@ -0,0 +1,97 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
+"http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
+<chapter id="sigtest">
+ <title>Running the Signature Test</title>
+
+ <para>One of the requirements of an implementation passing the TCK is for it
+ to pass the Bean Validation signature test. This section describes how the
+ signature file is generated and how to run it against your
+ implementation.</para>
+
+ <section>
+ <title>Obtaining the sigtest tool</title>
+
+ <para>You can obtain the Sigtest tool (at the time of writing the TCK uses
+ version 2.1) from the Sigtest home page at <ulink
+ url="https://sigtest.dev.java.net/"></ulink>. The user guide can be found
+ at <ulink
+ url="http://java.sun.com/javame/sigtest/docs/sigtest2.1_usersguide.pdf"></ulink>.
+ The downloadable package contains the jar files used in the commands
+ below.</para>
+ </section>
+
+ <section>
+ <title>Creating the signature file</title>
+
+ <para>The TCK package contains the file
+ <filename>validation-api.sig</filename> (in the
+ <filename>artifacts</filename> directory) which was created using the
+ following command:</para>
+
+ <programlisting>java -jar sigtestdev.jar Setup -classpath %JAVA_HOME%/jre/lib/rt.jar:lib/validation-api-1.0.0.GA.jar -package javax.validation -filename validation-api.sig</programlisting>
+
+ <para>In order to pass the Bean Validation TCK you have to make sure that
+ your API passes the signature tests against
+ <filename>validation-api.sig.</filename></para>
+ </section>
+
+ <section>
+ <title>Running the signature test</title>
+
+ <para>To run the signature test use:</para>
+
+ <programlisting>java -jar sigtest.jar Test -classpath %JAVA_HOME%/jre/lib/rt.jar:lib/validation-api-1.0.0.GA.jar -static -package javax.validation -filename validation-api.sig</programlisting>
+
+ <para>In order to run against your own Bean Validation API replace
+ validation-api-1.0.0.GA.jar with your own API jar. You should get the
+ message <literal>"STATUS:Passed."</literal>.</para>
+ </section>
+
+ <section>
+ <title>Forcing a signature test failure</title>
+
+ <para>Just for fun (and to confirm that the signature test is working
+ correctly), you can try the following:</para>
+
+ <para>1) Edit validation-api.sig</para>
+
+ <para>2) Modify one of the class signatures - in the following example we
+ change one of the constructors for <literal>ValidationException</literal>
+ - here's the original:</para>
+
+ <programlisting>CLSS public javax.validation.ValidationException
+cons public ValidationException()
+cons public ValidationException(java.lang.String)
+cons public ValidationException(java.lang.String,java.lang.Throwable)
+cons public ValidationException(java.lang.Throwable)
+supr java.lang.RuntimeException</programlisting>
+
+ <para>Let's change the default (empty) constructor parameter to one with a
+ <literal>java.lang.Integer</literal>parameter instead:</para>
+
+ <programlisting>CLSS public javax.validation.ValidationException
+cons public ValidationException(java.lang.Integer)
+cons public ValidationException(java.lang.String)
+cons public ValidationException(java.lang.String,java.lang.Throwable)
+cons public ValidationException(java.lang.Throwable)
+supr java.lang.RuntimeException</programlisting>
+
+ <para>3) Now when we run the signature test using the above command, we
+ should get the following errors:</para>
+
+ <programlisting>Missing Constructors
+--------------------
+
+javax.validation.ValidationException: constructor public javax.validation.ValidationException.ValidationException(java.lang.Integer)
+
+Added Constructors
+------------------
+
+javax.validation.ValidationException: constructor public javax.validation.ValidationException.ValidationException()
+
+
+STATUS:Failed.2 errors
+</programlisting>
+ </section>
+</chapter>
Modified: beanvalidation/tck/trunk/src/main/resources/validation-api.sig
===================================================================
--- beanvalidation/tck/trunk/src/main/resources/validation-api.sig 2009-11-24 15:36:49 UTC (rev 18033)
+++ beanvalidation/tck/trunk/src/main/resources/validation-api.sig 2009-11-24 16:12:57 UTC (rev 18034)
@@ -11,6 +11,7 @@
intf java.io.Serializable
intf java.lang.Comparable<{java.lang.Enum%0}>
meth protected final java.lang.Object clone() throws java.lang.CloneNotSupportedException
+meth protected final void finalize()
meth public final boolean equals(java.lang.Object)
meth public final int compareTo({java.lang.Enum%0})
meth public final int hashCode()
Modified: validator/trunk/hibernate-validator-tck-runner/pom.xml
===================================================================
--- validator/trunk/hibernate-validator-tck-runner/pom.xml 2009-11-24 15:36:49 UTC (rev 18033)
+++ validator/trunk/hibernate-validator-tck-runner/pom.xml 2009-11-24 16:12:57 UTC (rev 18034)
@@ -32,7 +32,7 @@
<dependency>
<groupId>org.hibernate.jsr303.tck</groupId>
<artifactId>jsr303-tck</artifactId>
- <version>1.0.1.GA</version>
+ <version>1.0.2-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.jboss.test-harness</groupId>
15 years
Hibernate SVN: r18033 - core/trunk/documentation/envers/src/main/docbook/en-US/content.
by hibernate-commits@lists.jboss.org
Author: adamw
Date: 2009-11-24 10:36:49 -0500 (Tue, 24 Nov 2009)
New Revision: 18033
Modified:
core/trunk/documentation/envers/src/main/docbook/en-US/content/revisionlog.xml
Log:
HHH-4540:
- updating docs
Modified: core/trunk/documentation/envers/src/main/docbook/en-US/content/revisionlog.xml
===================================================================
--- core/trunk/documentation/envers/src/main/docbook/en-US/content/revisionlog.xml 2009-11-24 15:21:10 UTC (rev 18032)
+++ core/trunk/documentation/envers/src/main/docbook/en-US/content/revisionlog.xml 2009-11-24 15:36:49 UTC (rev 18033)
@@ -49,7 +49,7 @@
</listitem>
<listitem>
<para>
- a long-valued property, annotated with <literal>@RevisionTimestamp</literal>. Value of
+ a long- or j.u.Date- valued property, annotated with <literal>@RevisionTimestamp</literal>. Value of
this property will be automatically set by Envers.
</para>
</listitem>
@@ -61,6 +61,14 @@
</para>
<para>
+ When using a <literal>Date</literal>, instead of a <literal>long/Long</literal> for the revision timestamp,
+ take care not to use a mapping of the property which will loose precision (for example, using
+ <literal>@Temporal(DATE)</literal> is wrong, as it doesn't store the time information, so many of your
+ revisions will appear to happen at exactly the same time). A good choice is a
+ <literal>@Temporal(TIMESTAMP)</literal>.
+ </para>
+
+ <para>
To fill the entity with additional data, you'll need to implement the
<literal>org.jboss.envers.RevisionListener</literal> interface. Its newRevision method will
be called when a new revision is created, before persisting the revision entity.
15 years
Hibernate SVN: r18032 - in core/trunk/envers/src: main/java/org/hibernate/envers/reader and 3 other directories.
by hibernate-commits@lists.jboss.org
Author: adamw
Date: 2009-11-24 10:21:10 -0500 (Tue, 24 Nov 2009)
New Revision: 18032
Added:
core/trunk/envers/src/test/java/org/hibernate/envers/test/entities/reventity/CustomDateRevEntity.java
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/reventity/CustomDate.java
Modified:
core/trunk/envers/src/main/java/org/hibernate/envers/configuration/RevisionInfoConfiguration.java
core/trunk/envers/src/main/java/org/hibernate/envers/reader/AuditReaderImpl.java
core/trunk/envers/src/main/java/org/hibernate/envers/revisioninfo/DefaultRevisionInfoGenerator.java
core/trunk/envers/src/main/java/org/hibernate/envers/revisioninfo/RevisionInfoQueryCreator.java
Log:
HHH-4540:
- applying patch from Nicolas Roug?\195?\169
- the revision timestamp can now be a j.u.Date or a j.s.Date, and be mapped to a Date in the DB
- test
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/configuration/RevisionInfoConfiguration.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/configuration/RevisionInfoConfiguration.java 2009-11-24 09:44:21 UTC (rev 18031)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/configuration/RevisionInfoConfiguration.java 2009-11-24 15:21:10 UTC (rev 18032)
@@ -23,6 +23,7 @@
*/
package org.hibernate.envers.configuration;
+import java.util.Date;
import java.util.Iterator;
import org.dom4j.Document;
@@ -45,6 +46,8 @@
import org.hibernate.annotations.common.reflection.ReflectionManager;
import org.hibernate.cfg.Configuration;
import org.hibernate.mapping.PersistentClass;
+import org.hibernate.type.LongType;
+import org.hibernate.type.Type;
/**
* @author Adam Warski (adam at warski dot org)
@@ -53,7 +56,7 @@
private String revisionInfoEntityName;
private PropertyData revisionInfoIdData;
private PropertyData revisionInfoTimestampData;
- private String revisionInfoTimestampType;
+ private Type revisionInfoTimestampType;
private String revisionPropType;
@@ -61,7 +64,7 @@
revisionInfoEntityName = "org.hibernate.envers.DefaultRevisionEntity";
revisionInfoIdData = new PropertyData("id", "id", "field", null);
revisionInfoTimestampData = new PropertyData("timestamp", "timestamp", "field", null);
- revisionInfoTimestampType = "long";
+ revisionInfoTimestampType = new LongType();
revisionPropType = "integer";
}
@@ -79,7 +82,7 @@
MetadataTools.addColumn(idProperty, "REV", null, 0, 0, null);
Element timestampProperty = MetadataTools.addProperty(class_mapping, revisionInfoTimestampData.getName(),
- revisionInfoTimestampType, true, false);
+ revisionInfoTimestampType.getName(), true, false);
MetadataTools.addColumn(timestampProperty, "REVTSTMP", null, 0, 0, null);
return document;
@@ -131,12 +134,14 @@
XClass revisionTimestampClass = property.getType();
if (reflectionManager.equals(revisionTimestampClass, Long.class) ||
- reflectionManager.equals(revisionTimestampClass, Long.TYPE)) {
+ reflectionManager.equals(revisionTimestampClass, Long.TYPE) ||
+ reflectionManager.equals(revisionTimestampClass, Date.class) ||
+ reflectionManager.equals(revisionTimestampClass, java.sql.Date.class)) {
revisionInfoTimestampData = new PropertyData(property.getName(), property.getName(), accessType, null);
revisionTimestampFound.set();
} else {
throw new MappingException("The field annotated with @RevisionTimestamp must be of type " +
- "long or Long");
+ "long, Long, java.util.Date or java.sql.Date");
}
}
}
@@ -203,8 +208,9 @@
revisionInfoEntityName = pc.getEntityName();
revisionInfoClass = pc.getMappedClass();
+ revisionInfoTimestampType = pc.getProperty(revisionInfoTimestampData.getName()).getType();
revisionInfoGenerator = new DefaultRevisionInfoGenerator(revisionInfoEntityName, revisionInfoClass,
- revisionEntity.value(), revisionInfoTimestampData);
+ revisionEntity.value(), revisionInfoTimestampData, isTimestampAsDate());
}
}
@@ -214,17 +220,22 @@
if (revisionInfoGenerator == null) {
revisionInfoClass = DefaultRevisionEntity.class;
revisionInfoGenerator = new DefaultRevisionInfoGenerator(revisionInfoEntityName, revisionInfoClass,
- RevisionListener.class, revisionInfoTimestampData);
+ RevisionListener.class, revisionInfoTimestampData, isTimestampAsDate());
revisionInfoXmlMapping = generateDefaultRevisionInfoXmlMapping();
}
return new RevisionInfoConfigurationResult(
revisionInfoGenerator, revisionInfoXmlMapping,
new RevisionInfoQueryCreator(revisionInfoEntityName, revisionInfoIdData.getName(),
- revisionInfoTimestampData.getName()),
+ revisionInfoTimestampData.getName(), isTimestampAsDate()),
generateRevisionInfoRelationMapping(),
new RevisionInfoNumberReader(revisionInfoClass, revisionInfoIdData), revisionInfoEntityName);
}
+
+ private boolean isTimestampAsDate() {
+ String typename = revisionInfoTimestampType.getName();
+ return "date".equals(typename) || "time".equals(typename) || "timestamp".equals(typename);
+ }
}
class RevisionInfoConfigurationResult {
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/reader/AuditReaderImpl.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/reader/AuditReaderImpl.java 2009-11-24 09:44:21 UTC (rev 18031)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/reader/AuditReaderImpl.java 2009-11-24 15:21:10 UTC (rev 18032)
@@ -141,12 +141,13 @@
Query query = verCfg.getRevisionInfoQueryCreator().getRevisionDateQuery(session, revision);
try {
- Long timestamp = (Long) query.uniqueResult();
- if (timestamp == null) {
+ Object timestampObject = query.uniqueResult();
+ if (timestampObject == null) {
throw new RevisionDoesNotExistException(revision);
}
- return new Date(timestamp);
+ // The timestamp object is either a date or a long
+ return timestampObject instanceof Date ? (Date) timestampObject : new Date((Long) timestampObject);
} catch (NonUniqueResultException e) {
throw new AuditException(e);
}
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/revisioninfo/DefaultRevisionInfoGenerator.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/revisioninfo/DefaultRevisionInfoGenerator.java 2009-11-24 09:44:21 UTC (rev 18031)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/revisioninfo/DefaultRevisionInfoGenerator.java 2009-11-24 15:21:10 UTC (rev 18032)
@@ -23,12 +23,13 @@
*/
package org.hibernate.envers.revisioninfo;
+import java.util.Date;
+
+import org.hibernate.MappingException;
+import org.hibernate.Session;
import org.hibernate.envers.RevisionListener;
import org.hibernate.envers.entities.PropertyData;
import org.hibernate.envers.tools.reflection.ReflectionTools;
-
-import org.hibernate.MappingException;
-import org.hibernate.Session;
import org.hibernate.property.Setter;
/**
@@ -38,13 +39,16 @@
private final String revisionInfoEntityName;
private final RevisionListener listener;
private final Setter revisionTimestampSetter;
+ private final boolean timestampAsDate;
private final Class<?> revisionInfoClass;
public DefaultRevisionInfoGenerator(String revisionInfoEntityName, Class<?> revisionInfoClass,
Class<? extends RevisionListener> listenerClass,
- PropertyData revisionInfoTimestampData) {
+ PropertyData revisionInfoTimestampData,
+ boolean timestampAsDate) {
this.revisionInfoEntityName = revisionInfoEntityName;
this.revisionInfoClass = revisionInfoClass;
+ this.timestampAsDate = timestampAsDate;
revisionTimestampSetter = ReflectionTools.getSetter(revisionInfoClass, revisionInfoTimestampData);
@@ -75,7 +79,8 @@
throw new RuntimeException(e);
}
- revisionTimestampSetter.set(revisionInfo, System.currentTimeMillis(), null);
+ long timestamp = System.currentTimeMillis();
+ revisionTimestampSetter.set(revisionInfo, timestampAsDate ? new Date(timestamp) : timestamp, null);
if (listener != null) {
listener.newRevision(revisionInfo);
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/revisioninfo/RevisionInfoQueryCreator.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/revisioninfo/RevisionInfoQueryCreator.java 2009-11-24 09:44:21 UTC (rev 18031)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/revisioninfo/RevisionInfoQueryCreator.java 2009-11-24 15:21:10 UTC (rev 18032)
@@ -35,9 +35,12 @@
private final String revisionDateQuery;
private final String revisionNumberForDateQuery;
private final String revisionQuery;
+ private final boolean timestampAsDate;
public RevisionInfoQueryCreator(String revisionInfoEntityName, String revisionInfoIdName,
- String revisionInfoTimestampName) {
+ String revisionInfoTimestampName, boolean timestampAsDate) {
+ this.timestampAsDate = timestampAsDate;
+
revisionDateQuery = new StringBuilder()
.append("select rev.").append(revisionInfoTimestampName)
.append(" from ").append(revisionInfoEntityName)
@@ -62,7 +65,7 @@
}
public Query getRevisionNumberForDateQuery(Session session, Date date) {
- return session.createQuery(revisionNumberForDateQuery).setParameter("_revision_date", date.getTime());
+ return session.createQuery(revisionNumberForDateQuery).setParameter("_revision_date", timestampAsDate ? date : date.getTime());
}
public Query getRevisionQuery(Session session, Number revision) {
Copied: core/trunk/envers/src/test/java/org/hibernate/envers/test/entities/reventity/CustomDateRevEntity.java (from rev 18023, core/trunk/envers/src/test/java/org/hibernate/envers/test/entities/reventity/CustomRevEntity.java)
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/entities/reventity/CustomDateRevEntity.java (rev 0)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/entities/reventity/CustomDateRevEntity.java 2009-11-24 15:21:10 UTC (rev 18032)
@@ -0,0 +1,86 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.envers.test.entities.reventity;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+
+import org.hibernate.envers.RevisionEntity;
+import org.hibernate.envers.RevisionNumber;
+import org.hibernate.envers.RevisionTimestamp;
+
+import java.util.Date;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+@Entity
+@RevisionEntity
+public class CustomDateRevEntity {
+ @Id
+ @GeneratedValue
+ @RevisionNumber
+ private int customId;
+
+ @RevisionTimestamp
+ private Date dateTimestamp;
+
+ public int getCustomId() {
+ return customId;
+ }
+
+ public void setCustomId(int customId) {
+ this.customId = customId;
+ }
+
+ public Date getDateTimestamp() {
+ return dateTimestamp;
+ }
+
+ public void setDateTimestamp(Date dateTimestamp) {
+ this.dateTimestamp = dateTimestamp;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ CustomDateRevEntity that = (CustomDateRevEntity) o;
+
+ if (customId != that.customId) return false;
+ if (dateTimestamp != null ? !dateTimestamp.equals(that.dateTimestamp) : that.dateTimestamp != null)
+ return false;
+
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ int result = customId;
+ result = 31 * result + (dateTimestamp != null ? dateTimestamp.hashCode() : 0);
+ return result;
+ }
+}
\ No newline at end of file
Copied: core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/reventity/CustomDate.java (from rev 18023, core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/reventity/Custom.java)
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/reventity/CustomDate.java (rev 0)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/reventity/CustomDate.java 2009-11-24 15:21:10 UTC (rev 18032)
@@ -0,0 +1,135 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.envers.test.integration.reventity;
+
+import java.util.Arrays;
+import java.util.Date;
+import javax.persistence.EntityManager;
+
+import org.hibernate.envers.AuditReader;
+import org.hibernate.envers.exception.RevisionDoesNotExistException;
+import org.hibernate.envers.test.AbstractEntityTest;
+import org.hibernate.envers.test.entities.StrTestEntity;
+import org.hibernate.envers.test.entities.reventity.CustomDateRevEntity;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import org.hibernate.ejb.Ejb3Configuration;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class CustomDate extends AbstractEntityTest {
+ private Integer id;
+ private long timestamp1;
+ private long timestamp2;
+ private long timestamp3;
+
+ public void configure(Ejb3Configuration cfg) {
+ cfg.addAnnotatedClass(StrTestEntity.class);
+ cfg.addAnnotatedClass(CustomDateRevEntity.class);
+ }
+
+ @BeforeClass(dependsOnMethods = "init")
+ public void initData() throws InterruptedException {
+ timestamp1 = System.currentTimeMillis();
+
+ Thread.sleep(100);
+
+ // Revision 1
+ EntityManager em = getEntityManager();
+ em.getTransaction().begin();
+ StrTestEntity te = new StrTestEntity("x");
+ em.persist(te);
+ id = te.getId();
+ em.getTransaction().commit();
+
+ timestamp2 = System.currentTimeMillis();
+
+ Thread.sleep(100);
+
+ // Revision 2
+ em.getTransaction().begin();
+ te = em.find(StrTestEntity.class, id);
+ te.setStr("y");
+ em.getTransaction().commit();
+
+ timestamp3 = System.currentTimeMillis();
+ }
+
+ @Test(expectedExceptions = RevisionDoesNotExistException.class)
+ public void testTimestamps1() {
+ getAuditReader().getRevisionNumberForDate(new Date(timestamp1));
+ }
+
+ @Test
+ public void testTimestamps() {
+ assert getAuditReader().getRevisionNumberForDate(new Date(timestamp2)).intValue() == 1;
+ assert getAuditReader().getRevisionNumberForDate(new Date(timestamp3)).intValue() == 2;
+ }
+
+ @Test
+ public void testDatesForRevisions() {
+ AuditReader vr = getAuditReader();
+ assert vr.getRevisionNumberForDate(vr.getRevisionDate(1)).intValue() == 1;
+ assert vr.getRevisionNumberForDate(vr.getRevisionDate(2)).intValue() == 2;
+ }
+
+ @Test
+ public void testRevisionsForDates() {
+ AuditReader vr = getAuditReader();
+
+ assert vr.getRevisionDate(vr.getRevisionNumberForDate(new Date(timestamp2))).getTime() <= timestamp2;
+ assert vr.getRevisionDate(vr.getRevisionNumberForDate(new Date(timestamp2)).intValue()+1).getTime() > timestamp2;
+
+ assert vr.getRevisionDate(vr.getRevisionNumberForDate(new Date(timestamp3))).getTime() <= timestamp3;
+ }
+
+ @Test
+ public void testFindRevision() {
+ AuditReader vr = getAuditReader();
+
+ long rev1Timestamp = vr.findRevision(CustomDateRevEntity.class, 1).getDateTimestamp().getTime();
+ assert rev1Timestamp > timestamp1;
+ assert rev1Timestamp <= timestamp2;
+
+ long rev2Timestamp = vr.findRevision(CustomDateRevEntity.class, 2).getDateTimestamp().getTime();
+ assert rev2Timestamp > timestamp2;
+ assert rev2Timestamp <= timestamp3;
+ }
+
+ @Test
+ public void testRevisionsCounts() {
+ assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(StrTestEntity.class, id));
+ }
+
+ @Test
+ public void testHistoryOfId1() {
+ StrTestEntity ver1 = new StrTestEntity("x", id);
+ StrTestEntity ver2 = new StrTestEntity("y", id);
+
+ assert getAuditReader().find(StrTestEntity.class, id, 1).equals(ver1);
+ assert getAuditReader().find(StrTestEntity.class, id, 2).equals(ver2);
+ }
+}
\ No newline at end of file
15 years
Hibernate SVN: r18031 - validator/trunk/hibernate-validator-annotation-processor.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-11-24 04:44:21 -0500 (Tue, 24 Nov 2009)
New Revision: 18031
Modified:
validator/trunk/hibernate-validator-annotation-processor/pom.xml
Log:
HV-269 disabled annotation processing for the aactual processor build
Modified: validator/trunk/hibernate-validator-annotation-processor/pom.xml
===================================================================
--- validator/trunk/hibernate-validator-annotation-processor/pom.xml 2009-11-24 09:41:24 UTC (rev 18030)
+++ validator/trunk/hibernate-validator-annotation-processor/pom.xml 2009-11-24 09:44:21 UTC (rev 18031)
@@ -10,6 +10,17 @@
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator-annotation-processor</artifactId>
<name>Hibernate Validator Annotation Processor</name>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <compilerArgument>-proc:none</compilerArgument>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
15 years
Hibernate SVN: r18030 - core/trunk/parent.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2009-11-24 04:41:24 -0500 (Tue, 24 Nov 2009)
New Revision: 18030
Modified:
core/trunk/parent/pom.xml
Log:
Add H2 profile
Modified: core/trunk/parent/pom.xml
===================================================================
--- core/trunk/parent/pom.xml 2009-11-24 09:39:08 UTC (rev 18029)
+++ core/trunk/parent/pom.xml 2009-11-24 09:41:24 UTC (rev 18030)
@@ -512,9 +512,31 @@
<jdbc.url>jdbc:hsqldb:.</jdbc.url>
<jdbc.user>sa</jdbc.user>
<jdbc.pass/>
- <jdbc.isolation/>
+ <jdbc.isolation/>
</properties>
</profile>
+
+ <profile>
+ <id>h2</id>
+ <activation>
+ <activeByDefault>false</activeByDefault>
+ </activation>
+ <dependencies>
+ <dependency>
+ <groupId>com.h2database</groupId>
+ <artifactId>h2</artifactId>
+ <version>1.2.124</version>
+ </dependency>
+ </dependencies>
+ <properties>
+ <db.dialect>org.hibernate.dialect.H2Dialect</db.dialect>
+ <jdbc.driver>org.h2.Driver</jdbc.driver>
+ <jdbc.url>jdbc:h2:mem:db1</jdbc.url>
+ <jdbc.user>sa</jdbc.user>
+ <jdbc.pass/>
+ <jdbc.isolation/>
+ </properties>
+ </profile>
<!--
###################################################################
Profiles naming db instances in the Red Hat QA/QE lab
15 years
Hibernate SVN: r18029 - in core/trunk: entitymanager/src/test/java/org/hibernate/ejb/test and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2009-11-24 04:39:08 -0500 (Tue, 24 Nov 2009)
New Revision: 18029
Added:
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/query/
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/query/ComponentJoinsTest.java
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/query/QueryTest.java
Removed:
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/QueryTest.java
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/ql/
Modified:
core/trunk/core/src/main/java/org/hibernate/engine/query/ParameterMetadata.java
Log:
HHH-4604 IllegalArgumentException should be raised when an ordinal parameter is not present in the query
Modified: core/trunk/core/src/main/java/org/hibernate/engine/query/ParameterMetadata.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/engine/query/ParameterMetadata.java 2009-11-24 09:19:47 UTC (rev 18028)
+++ core/trunk/core/src/main/java/org/hibernate/engine/query/ParameterMetadata.java 2009-11-24 09:39:08 UTC (rev 18029)
@@ -76,7 +76,9 @@
public OrdinalParameterDescriptor getOrdinalParameterDescriptor(int position) {
if ( position < 1 || position > ordinalDescriptors.length ) {
- throw new IndexOutOfBoundsException( "Remember that ordinal parameters are 1-based!" );
+ String error = "Position beyond number of declared ordinal parameters. " +
+ "Remember that ordinal parameters are 1-based! Position: " + position;
+ throw new QueryParameterException( error );
}
return ordinalDescriptors[position - 1];
}
Deleted: core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/QueryTest.java
===================================================================
--- core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/QueryTest.java 2009-11-24 09:19:47 UTC (rev 18028)
+++ core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/QueryTest.java 2009-11-24 09:39:08 UTC (rev 18029)
@@ -1,414 +0,0 @@
-//$Id$
-package org.hibernate.ejb.test;
-
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import javax.persistence.EntityManager;
-import javax.persistence.Query;
-import javax.persistence.TemporalType;
-
-import org.hibernate.Hibernate;
-
-
-/**
- * @author Emmanuel Bernard
- */
-public class QueryTest extends TestCase {
-
- public void testPagedQuery() throws Exception {
- EntityManager em = getOrCreateEntityManager();
- em.getTransaction().begin();
- Item item = new Item( "Mouse", "Micro$oft mouse" );
- em.persist( item );
- item = new Item( "Computer", "Apple II" );
- em.persist( item );
- Query q = em.createQuery( "select i from " + Item.class.getName() + " i where i.name like :itemName" );
- q.setParameter( "itemName", "%" );
- q.setMaxResults( 1 );
- q.getSingleResult();
- q = em.createQuery( "select i from Item i where i.name like :itemName" );
- q.setParameter( "itemName", "%" );
- q.setFirstResult( 1 );
- q.setMaxResults( 1 );
- em.getTransaction().rollback();
- em.close();
- }
-
- public void testAggregationReturnType() throws Exception {
- EntityManager em = getOrCreateEntityManager();
- em.getTransaction().begin();
- Item item = new Item( "Mouse", "Micro$oft mouse" );
- em.persist( item );
- item = new Item( "Computer", "Apple II" );
- em.persist( item );
- Query q = em.createQuery( "select count(i) from Item i where i.name like :itemName" );
- q.setParameter( "itemName", "%" );
- assertTrue( q.getSingleResult() instanceof Long );
- em.getTransaction().rollback();
- em.close();
- }
-
- public void testParameterList() throws Exception {
- final Item item = new Item( "Mouse", "Micro$oft mouse" );
- final Item item2 = new Item( "Computer", "D�ll computer" );
-
- EntityManager em = getOrCreateEntityManager();
- em.getTransaction().begin();
- em.persist( item );
- em.persist( item2 );
- assertTrue( em.contains( item ) );
- em.getTransaction().commit();
-
- em.getTransaction().begin();
- Query q = em.createQuery( "select item from Item item where item.name in (:names)" );
- //test hint in value and string
- q.setHint( "org.hibernate.fetchSize", 10 );
- q.setHint( "org.hibernate.fetchSize", "10" );
- List params = new ArrayList();
- params.add( item.getName() );
- params.add( item2.getName() );
- q.setParameter( "names", params );
- List result = q.getResultList();
- assertNotNull( result );
- assertEquals( 2, result.size() );
-
- q = em.createQuery( "select item from Item item where item.name in ( ?1 )" );
- params = new ArrayList();
- params.add( item.getName() );
- params.add( item2.getName() );
- q.setParameter( "1", params );
- result = q.getResultList();
- assertNotNull( result );
- assertEquals( 2, result.size() );
- em.remove( result.get( 0 ) );
- em.remove( result.get( 1 ) );
- em.getTransaction().commit();
-
- em.close();
- }
-
-// public void testDistinct() throws Exception {
-// Item item = new Item("Mouse", "Micro_oft mouse");
-// Distributor fnac = new Distributor();
-// fnac.setName("Fnac");
-// item.addDistributor(fnac);
-// Distributor auchan = new Distributor();
-// auchan.setName("Auchan");
-// item.addDistributor(auchan);
-//
-// EntityManager em = getOrCreateEntityManager();
-// em.getTransaction().begin();
-// em.persist(fnac);
-// em.persist(auchan);
-// em.persist(item);
-// em.getTransaction().commit();
-//
-// em.getTransaction().begin();
-// Query q = em.createQuery("select distinct item from Item item join fetch item.distributors");
-// List result = q.getResultList();
-// assertNotNull(result);
-// assertEquals( 1, result.size() );
-// item = (Item) result.get(0);
-// item.getDistributors().clear();
-// em.flush();
-// int deleted = em.createQuery("delete from Item").executeUpdate();
-// assertEquals( 1, deleted );
-// deleted = em.createQuery("delete from Distributor").executeUpdate();
-// assertEquals( 2, deleted );
-// em.getTransaction().commit();
-//
-// em.close();
-// }
-
- public void testEscapeCharacter() throws Exception {
- final Item item = new Item( "Mouse", "Micro_oft mouse" );
- final Item item2 = new Item( "Computer", "D�ll computer" );
-
- EntityManager em = getOrCreateEntityManager();
- em.getTransaction().begin();
- em.persist( item );
- em.persist( item2 );
- assertTrue( em.contains( item ) );
- em.getTransaction().commit();
-
- em.getTransaction().begin();
- Query q = em.createQuery( "select item from Item item where item.descr like 'Microk_oft mouse' escape 'k' " );
- List result = q.getResultList();
- assertNotNull( result );
- assertEquals( 1, result.size() );
- int deleted = em.createQuery( "delete from Item" ).executeUpdate();
- assertEquals( 2, deleted );
- em.getTransaction().commit();
-
- em.close();
- }
-
- public void testNativeQueryByEntity() {
-
- Item item = new Item( "Mouse", "Micro$oft mouse" );
-
- EntityManager em = getOrCreateEntityManager();
- em.getTransaction().begin();
- em.persist( item );
- assertTrue( em.contains( item ) );
- em.getTransaction().commit();
-
- em.getTransaction().begin();
- item = (Item) em.createNativeQuery( "select * from Item", Item.class ).getSingleResult();
- assertNotNull( item );
- assertEquals( "Micro$oft mouse", item.getDescr() );
- em.remove( item );
- em.getTransaction().commit();
-
- em.close();
-
- }
-
- public void testNativeQueryByResultSet() {
-
- Item item = new Item( "Mouse", "Micro$oft mouse" );
-
- EntityManager em = getOrCreateEntityManager();
- em.getTransaction().begin();
- em.persist( item );
- assertTrue( em.contains( item ) );
- em.getTransaction().commit();
-
- em.getTransaction().begin();
- item = (Item) em.createNativeQuery( "select name as itemname, descr as itemdescription from Item", "getItem" )
- .getSingleResult();
- assertNotNull( item );
- assertEquals( "Micro$oft mouse", item.getDescr() );
- em.remove( item );
- em.getTransaction().commit();
-
- em.close();
-
- }
-
- public void testExplicitPositionalParameter() throws Exception {
- EntityManager em = getOrCreateEntityManager();
- em.getTransaction().begin();
- Wallet w = new Wallet();
- w.setBrand( "Lacoste" );
- w.setModel( "Minimic" );
- w.setSerial( "0100202002" );
- em.persist( w );
- em.getTransaction().commit();
- em.getTransaction().begin();
- Query query = em.createQuery( "select w from " + Wallet.class.getName() + " w where w.brand in (?1)" );
- List brands = new ArrayList();
- brands.add( "Lacoste" );
- query.setParameter( 1, brands );
- w = (Wallet) query.getSingleResult();
- assertNotNull( w );
- query = em.createQuery( "select w from " + Wallet.class.getName() + " w where w.marketEntrance = ?1" );
- query.setParameter( 1, new Date(), TemporalType.DATE );
- //assertNull( query.getSingleResult() );
- assertEquals( 0, query.getResultList().size() );
- em.remove( w );
- em.getTransaction().commit();
- em.close();
- }
-
- public void testPositionalParameterForms() throws Exception {
- EntityManager em = getOrCreateEntityManager();
- em.getTransaction().begin();
- Wallet w = new Wallet();
- w.setBrand( "Lacoste" );
- w.setModel( "Minimic" );
- w.setSerial( "0100202002" );
- em.persist( w );
- em.getTransaction().commit();
-
- em.getTransaction().begin();
- // first using jpa-style positional parameter
- Query query = em.createQuery( "select w from Wallet w where w.brand = ?1" );
- query.setParameter( 1, "Lacoste" );
- w = (Wallet) query.getSingleResult();
- assertNotNull( w );
-
- // next using jpa-style positional parameter, but as a name (which is how Hibernate core treats these
- query = em.createQuery( "select w from Wallet w where w.brand = ?1" );
- query.setParameter( "1", "Lacoste" );
- w = (Wallet) query.getSingleResult();
- assertNotNull( w );
-
- // finally using hql-style positional parameter
- query = em.createQuery( "select w from Wallet w where w.brand = ?" );
- query.setParameter( 1, "Lacoste" );
- w = (Wallet) query.getSingleResult();
- assertNotNull( w );
-
- em.remove( w );
- em.getTransaction().commit();
- em.close();
- }
-
- public void testNativeQuestionMarkParameter() throws Exception {
- EntityManager em = getOrCreateEntityManager();
- em.getTransaction().begin();
- Wallet w = new Wallet();
- w.setBrand( "Lacoste" );
- w.setModel( "Minimic" );
- w.setSerial( "0100202002" );
- em.persist( w );
- em.getTransaction().commit();
- em.getTransaction().begin();
- Query query = em.createNativeQuery( "select * from Wallet w where w.brand = ?", Wallet.class );
- query.setParameter( 1, "Lacoste" );
- w = (Wallet) query.getSingleResult();
- assertNotNull( w );
- em.remove( w );
- em.getTransaction().commit();
- em.close();
- }
-
- public void testNativeQueryWithPositionalParameter() {
-
- Item item = new Item( "Mouse", "Micro$oft mouse" );
-
- EntityManager em = getOrCreateEntityManager();
- em.getTransaction().begin();
- em.persist( item );
- assertTrue( em.contains( item ) );
- em.getTransaction().commit();
-
- em.getTransaction().begin();
- Query query = em.createNativeQuery( "select * from Item where name = ?1", Item.class );
- query.setParameter( 1, "Mouse" );
- item = (Item) query.getSingleResult();
- assertNotNull( item );
- assertEquals( "Micro$oft mouse", item.getDescr() );
- query = em.createNativeQuery( "select * from Item where name = ?", Item.class );
- query.setParameter( 1, "Mouse" );
- item = (Item) query.getSingleResult();
- assertNotNull( item );
- assertEquals( "Micro$oft mouse", item.getDescr() );
- em.remove( item );
- em.getTransaction().commit();
-
- em.close();
-
- }
-
- public void testDistinct() throws Exception {
- EntityManager em = getOrCreateEntityManager();
- em.getTransaction().begin();
- em.createQuery( "delete Item" ).executeUpdate();
- em.createQuery( "delete Distributor" ).executeUpdate();
- Distributor d1 = new Distributor();
- d1.setName( "Fnac" );
- Distributor d2 = new Distributor();
- d2.setName( "Darty" );
- Item item = new Item( "Mouse", "Micro$oft mouse" );
- item.getDistributors().add( d1 );
- item.getDistributors().add( d2 );
- em.persist( d1 );
- em.persist( d2 );
- em.persist( item );
- em.flush();
- em.clear();
- Query q = em.createQuery( "select distinct i from Item i left join fetch i.distributors" );
- item = (Item) q.getSingleResult()
- ;
- //assertEquals( 1, distinctResult.size() );
- //item = (Item) distinctResult.get( 0 );
- assertTrue( Hibernate.isInitialized( item.getDistributors() ) );
- assertEquals( 2, item.getDistributors().size() );
- em.getTransaction().rollback();
- em.close();
- }
-
- public void testIsNull() throws Exception {
- EntityManager em = getOrCreateEntityManager();
- em.getTransaction().begin();
- Distributor d1 = new Distributor();
- d1.setName( "Fnac" );
- Distributor d2 = new Distributor();
- d2.setName( "Darty" );
- Item item = new Item( "Mouse", null );
- Item item2 = new Item( "Mouse2", "dd" );
- item.getDistributors().add( d1 );
- item.getDistributors().add( d2 );
- em.persist( d1 );
- em.persist( d2 );
- em.persist( item );
- em.persist( item2 );
- em.flush();
- em.clear();
- Query q = em.createQuery(
- "select i from Item i where i.descr = :descr or (i.descr is null and cast(:descr as string) is null)"
- );
- //Query q = em.createQuery( "select i from Item i where (i.descr is null and :descr is null) or (i.descr = :descr");
- q.setParameter( "descr", "dd" );
- List result = q.getResultList();
- assertEquals( 1, result.size() );
- q.setParameter( "descr", null );
- result = q.getResultList();
- assertEquals( 1, result.size() );
- //item = (Item) distinctResult.get( 0 );
-
- em.getTransaction().rollback();
- em.close();
- }
-
- public void testUpdateQuery() {
-
- Item item = new Item( "Mouse", "Micro$oft mouse" );
-
- EntityManager em = getOrCreateEntityManager();
- em.getTransaction().begin();
- em.persist( item );
- assertTrue( em.contains( item ) );
-
- em.flush();
- em.clear();
-
- assertEquals(
- 1, em.createNativeQuery(
- "update Item set descr = 'Logitech Mouse' where name = 'Mouse'"
- ).executeUpdate()
- );
- item = em.find( Item.class, item.getName() );
- assertEquals( "Logitech Mouse", item.getDescr() );
- em.remove( item );
- em.getTransaction().rollback();
-
- em.close();
-
- }
-
- public void testUnavailableNamedQuery() throws Exception {
- Item item = new Item( "Mouse", "Micro$oft mouse" );
-
- EntityManager em = getOrCreateEntityManager();
- em.getTransaction().begin();
- em.persist( item );
- try {
- em.createNamedQuery( "wrong name" );
- fail("Wrong named query should raise an exception");
- }
- catch (IllegalArgumentException e) {
- //success
- }
- em.getTransaction().commit();
-
- em.clear();
-
- em.getTransaction().begin();
- em.remove( em.find( Item.class, item.getName() ) );
- em.getTransaction().commit();
- em.close();
-
- }
-
- public Class[] getAnnotatedClasses() {
- return new Class[]{
- Item.class,
- Distributor.class,
- Wallet.class
- };
- }
-}
Copied: core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/query/ComponentJoinsTest.java (from rev 18027, core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/ql/ComponentJoinsTest.java)
===================================================================
--- core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/query/ComponentJoinsTest.java (rev 0)
+++ core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/query/ComponentJoinsTest.java 2009-11-24 09:39:08 UTC (rev 18029)
@@ -0,0 +1,57 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009 by Red Hat Inc and/or its affiliates or by
+ * third-party contributors as indicated by either @author tags or express
+ * copyright attribution statements applied by the authors. All
+ * third-party contributions are distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA\
+ */
+package org.hibernate.ejb.test.query;
+
+import javax.persistence.EntityManager;
+
+import org.hibernate.ejb.test.TestCase;
+import org.hibernate.ejb.criteria.components.Client;
+
+/**
+ * Tests related to specifying joins on components (embedded values).
+ *
+ * @author Steve Ebersole
+ */
+public class ComponentJoinsTest extends TestCase {
+ public Class[] getAnnotatedClasses() {
+ return new Class[] { Client.class };
+ }
+
+ public void testComponentJoins() {
+ // Just checking proper query construction and syntax checking via database query parser...
+ EntityManager em = getOrCreateEntityManager();
+ em.getTransaction().begin();
+ // use it in WHERE
+ em.createQuery( "select c from Client c join c.name as n where n.lastName like '%'" ).getResultList();
+ // use it in SELECT
+ em.createQuery( "select n.lastName from Client c join c.name as n" ).getResultList();
+ em.createQuery( "select n from Client c join c.name as n" ).getResultList();
+ // use it in ORDER BY
+ em.createQuery( "select n from Client c join c.name as n order by n.lastName" ).getResultList();
+ em.createQuery( "select n from Client c join c.name as n order by c" ).getResultList();
+ em.createQuery( "select n from Client c join c.name as n order by n" ).getResultList();
+ em.getTransaction().commit();
+ em.close();
+ }
+}
Copied: core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/query/QueryTest.java (from rev 18027, core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/QueryTest.java)
===================================================================
--- core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/query/QueryTest.java (rev 0)
+++ core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/query/QueryTest.java 2009-11-24 09:39:08 UTC (rev 18029)
@@ -0,0 +1,445 @@
+//$Id$
+package org.hibernate.ejb.test.query;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import javax.persistence.EntityManager;
+import javax.persistence.Query;
+import javax.persistence.TemporalType;
+
+import org.hibernate.Hibernate;
+import org.hibernate.ejb.test.TestCase;
+import org.hibernate.ejb.test.Item;
+import org.hibernate.ejb.test.Wallet;
+import org.hibernate.ejb.test.Distributor;
+
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class QueryTest extends TestCase {
+
+ public void testPagedQuery() throws Exception {
+ EntityManager em = getOrCreateEntityManager();
+ em.getTransaction().begin();
+ Item item = new Item( "Mouse", "Micro$oft mouse" );
+ em.persist( item );
+ item = new Item( "Computer", "Apple II" );
+ em.persist( item );
+ Query q = em.createQuery( "select i from " + Item.class.getName() + " i where i.name like :itemName" );
+ q.setParameter( "itemName", "%" );
+ q.setMaxResults( 1 );
+ q.getSingleResult();
+ q = em.createQuery( "select i from Item i where i.name like :itemName" );
+ q.setParameter( "itemName", "%" );
+ q.setFirstResult( 1 );
+ q.setMaxResults( 1 );
+ em.getTransaction().rollback();
+ em.close();
+ }
+
+ public void testAggregationReturnType() throws Exception {
+ EntityManager em = getOrCreateEntityManager();
+ em.getTransaction().begin();
+ Item item = new Item( "Mouse", "Micro$oft mouse" );
+ em.persist( item );
+ item = new Item( "Computer", "Apple II" );
+ em.persist( item );
+ Query q = em.createQuery( "select count(i) from Item i where i.name like :itemName" );
+ q.setParameter( "itemName", "%" );
+ assertTrue( q.getSingleResult() instanceof Long );
+ em.getTransaction().rollback();
+ em.close();
+ }
+
+ public void testParameterList() throws Exception {
+ final Item item = new Item( "Mouse", "Micro$oft mouse" );
+ final Item item2 = new Item( "Computer", "D�ll computer" );
+
+ EntityManager em = getOrCreateEntityManager();
+ em.getTransaction().begin();
+ em.persist( item );
+ em.persist( item2 );
+ assertTrue( em.contains( item ) );
+ em.getTransaction().commit();
+
+ em.getTransaction().begin();
+ Query q = em.createQuery( "select item from Item item where item.name in (:names)" );
+ //test hint in value and string
+ q.setHint( "org.hibernate.fetchSize", 10 );
+ q.setHint( "org.hibernate.fetchSize", "10" );
+ List params = new ArrayList();
+ params.add( item.getName() );
+ params.add( item2.getName() );
+ q.setParameter( "names", params );
+ List result = q.getResultList();
+ assertNotNull( result );
+ assertEquals( 2, result.size() );
+
+ q = em.createQuery( "select item from Item item where item.name in ( ?1 )" );
+ params = new ArrayList();
+ params.add( item.getName() );
+ params.add( item2.getName() );
+ q.setParameter( "1", params );
+ result = q.getResultList();
+ assertNotNull( result );
+ assertEquals( 2, result.size() );
+ em.remove( result.get( 0 ) );
+ em.remove( result.get( 1 ) );
+ em.getTransaction().commit();
+
+ em.close();
+ }
+
+// public void testDistinct() throws Exception {
+// Item item = new Item("Mouse", "Micro_oft mouse");
+// Distributor fnac = new Distributor();
+// fnac.setName("Fnac");
+// item.addDistributor(fnac);
+// Distributor auchan = new Distributor();
+// auchan.setName("Auchan");
+// item.addDistributor(auchan);
+//
+// EntityManager em = getOrCreateEntityManager();
+// em.getTransaction().begin();
+// em.persist(fnac);
+// em.persist(auchan);
+// em.persist(item);
+// em.getTransaction().commit();
+//
+// em.getTransaction().begin();
+// Query q = em.createQuery("select distinct item from Item item join fetch item.distributors");
+// List result = q.getResultList();
+// assertNotNull(result);
+// assertEquals( 1, result.size() );
+// item = (Item) result.get(0);
+// item.getDistributors().clear();
+// em.flush();
+// int deleted = em.createQuery("delete from Item").executeUpdate();
+// assertEquals( 1, deleted );
+// deleted = em.createQuery("delete from Distributor").executeUpdate();
+// assertEquals( 2, deleted );
+// em.getTransaction().commit();
+//
+// em.close();
+// }
+
+ public void testEscapeCharacter() throws Exception {
+ final Item item = new Item( "Mouse", "Micro_oft mouse" );
+ final Item item2 = new Item( "Computer", "D�ll computer" );
+
+ EntityManager em = getOrCreateEntityManager();
+ em.getTransaction().begin();
+ em.persist( item );
+ em.persist( item2 );
+ assertTrue( em.contains( item ) );
+ em.getTransaction().commit();
+
+ em.getTransaction().begin();
+ Query q = em.createQuery( "select item from Item item where item.descr like 'Microk_oft mouse' escape 'k' " );
+ List result = q.getResultList();
+ assertNotNull( result );
+ assertEquals( 1, result.size() );
+ int deleted = em.createQuery( "delete from Item" ).executeUpdate();
+ assertEquals( 2, deleted );
+ em.getTransaction().commit();
+
+ em.close();
+ }
+
+ public void testNativeQueryByEntity() {
+
+ Item item = new Item( "Mouse", "Micro$oft mouse" );
+
+ EntityManager em = getOrCreateEntityManager();
+ em.getTransaction().begin();
+ em.persist( item );
+ assertTrue( em.contains( item ) );
+ em.getTransaction().commit();
+
+ em.getTransaction().begin();
+ item = (Item) em.createNativeQuery( "select * from Item", Item.class ).getSingleResult();
+ assertNotNull( item );
+ assertEquals( "Micro$oft mouse", item.getDescr() );
+ em.remove( item );
+ em.getTransaction().commit();
+
+ em.close();
+
+ }
+
+ public void testNativeQueryByResultSet() {
+
+ Item item = new Item( "Mouse", "Micro$oft mouse" );
+
+ EntityManager em = getOrCreateEntityManager();
+ em.getTransaction().begin();
+ em.persist( item );
+ assertTrue( em.contains( item ) );
+ em.getTransaction().commit();
+
+ em.getTransaction().begin();
+ item = (Item) em.createNativeQuery( "select name as itemname, descr as itemdescription from Item", "getItem" )
+ .getSingleResult();
+ assertNotNull( item );
+ assertEquals( "Micro$oft mouse", item.getDescr() );
+ em.remove( item );
+ em.getTransaction().commit();
+
+ em.close();
+
+ }
+
+ public void testExplicitPositionalParameter() throws Exception {
+ EntityManager em = getOrCreateEntityManager();
+ em.getTransaction().begin();
+ Wallet w = new Wallet();
+ w.setBrand( "Lacoste" );
+ w.setModel( "Minimic" );
+ w.setSerial( "0100202002" );
+ em.persist( w );
+ em.getTransaction().commit();
+ em.getTransaction().begin();
+ Query query = em.createQuery( "select w from " + Wallet.class.getName() + " w where w.brand in (?1)" );
+ List brands = new ArrayList();
+ brands.add( "Lacoste" );
+ query.setParameter( 1, brands );
+ w = (Wallet) query.getSingleResult();
+ assertNotNull( w );
+ query = em.createQuery( "select w from " + Wallet.class.getName() + " w where w.marketEntrance = ?1" );
+ query.setParameter( 1, new Date(), TemporalType.DATE );
+ //assertNull( query.getSingleResult() );
+ assertEquals( 0, query.getResultList().size() );
+ em.remove( w );
+ em.getTransaction().commit();
+ em.close();
+ }
+
+ public void testPositionalParameterForms() throws Exception {
+ EntityManager em = getOrCreateEntityManager();
+ em.getTransaction().begin();
+ Wallet w = new Wallet();
+ w.setBrand( "Lacoste" );
+ w.setModel( "Minimic" );
+ w.setSerial( "0100202002" );
+ em.persist( w );
+ em.getTransaction().commit();
+
+ em.getTransaction().begin();
+ // first using jpa-style positional parameter
+ Query query = em.createQuery( "select w from Wallet w where w.brand = ?1" );
+ query.setParameter( 1, "Lacoste" );
+ w = (Wallet) query.getSingleResult();
+ assertNotNull( w );
+
+ // next using jpa-style positional parameter, but as a name (which is how Hibernate core treats these
+ query = em.createQuery( "select w from Wallet w where w.brand = ?1" );
+ query.setParameter( "1", "Lacoste" );
+ w = (Wallet) query.getSingleResult();
+ assertNotNull( w );
+
+ // finally using hql-style positional parameter
+ query = em.createQuery( "select w from Wallet w where w.brand = ?" );
+ query.setParameter( 1, "Lacoste" );
+ w = (Wallet) query.getSingleResult();
+ assertNotNull( w );
+
+ em.remove( w );
+ em.getTransaction().commit();
+ em.close();
+ }
+
+ public void testPositionalParameterWithUserError() throws Exception {
+ EntityManager em = getOrCreateEntityManager();
+ em.getTransaction().begin();
+ Wallet w = new Wallet();
+ w.setBrand( "Lacoste" );
+ w.setModel( "Minimic" );
+ w.setSerial( "0100202002" );
+ em.persist( w );
+ em.flush();
+
+
+ try {
+ Query query = em.createQuery( "select w from Wallet w where w.brand = ?1 and w.model = ?3" );
+ query.setParameter( 1, "Lacoste" );
+ query.setParameter( 2, "Expensive" );
+ query.getResultList();
+ fail("The query should fail due to a user error in parameters");
+ }
+ catch ( IllegalArgumentException e ) {
+ //success
+ }
+ finally {
+ em.getTransaction().rollback();
+ em.close();
+ }
+ }
+
+ public void testNativeQuestionMarkParameter() throws Exception {
+ EntityManager em = getOrCreateEntityManager();
+ em.getTransaction().begin();
+ Wallet w = new Wallet();
+ w.setBrand( "Lacoste" );
+ w.setModel( "Minimic" );
+ w.setSerial( "0100202002" );
+ em.persist( w );
+ em.getTransaction().commit();
+ em.getTransaction().begin();
+ Query query = em.createNativeQuery( "select * from Wallet w where w.brand = ?", Wallet.class );
+ query.setParameter( 1, "Lacoste" );
+ w = (Wallet) query.getSingleResult();
+ assertNotNull( w );
+ em.remove( w );
+ em.getTransaction().commit();
+ em.close();
+ }
+
+ public void testNativeQueryWithPositionalParameter() {
+
+ Item item = new Item( "Mouse", "Micro$oft mouse" );
+
+ EntityManager em = getOrCreateEntityManager();
+ em.getTransaction().begin();
+ em.persist( item );
+ assertTrue( em.contains( item ) );
+ em.getTransaction().commit();
+
+ em.getTransaction().begin();
+ Query query = em.createNativeQuery( "select * from Item where name = ?1", Item.class );
+ query.setParameter( 1, "Mouse" );
+ item = (Item) query.getSingleResult();
+ assertNotNull( item );
+ assertEquals( "Micro$oft mouse", item.getDescr() );
+ query = em.createNativeQuery( "select * from Item where name = ?", Item.class );
+ query.setParameter( 1, "Mouse" );
+ item = (Item) query.getSingleResult();
+ assertNotNull( item );
+ assertEquals( "Micro$oft mouse", item.getDescr() );
+ em.remove( item );
+ em.getTransaction().commit();
+
+ em.close();
+
+ }
+
+ public void testDistinct() throws Exception {
+ EntityManager em = getOrCreateEntityManager();
+ em.getTransaction().begin();
+ em.createQuery( "delete Item" ).executeUpdate();
+ em.createQuery( "delete Distributor" ).executeUpdate();
+ Distributor d1 = new Distributor();
+ d1.setName( "Fnac" );
+ Distributor d2 = new Distributor();
+ d2.setName( "Darty" );
+ Item item = new Item( "Mouse", "Micro$oft mouse" );
+ item.getDistributors().add( d1 );
+ item.getDistributors().add( d2 );
+ em.persist( d1 );
+ em.persist( d2 );
+ em.persist( item );
+ em.flush();
+ em.clear();
+ Query q = em.createQuery( "select distinct i from Item i left join fetch i.distributors" );
+ item = (Item) q.getSingleResult()
+ ;
+ //assertEquals( 1, distinctResult.size() );
+ //item = (Item) distinctResult.get( 0 );
+ assertTrue( Hibernate.isInitialized( item.getDistributors() ) );
+ assertEquals( 2, item.getDistributors().size() );
+ em.getTransaction().rollback();
+ em.close();
+ }
+
+ public void testIsNull() throws Exception {
+ EntityManager em = getOrCreateEntityManager();
+ em.getTransaction().begin();
+ Distributor d1 = new Distributor();
+ d1.setName( "Fnac" );
+ Distributor d2 = new Distributor();
+ d2.setName( "Darty" );
+ Item item = new Item( "Mouse", null );
+ Item item2 = new Item( "Mouse2", "dd" );
+ item.getDistributors().add( d1 );
+ item.getDistributors().add( d2 );
+ em.persist( d1 );
+ em.persist( d2 );
+ em.persist( item );
+ em.persist( item2 );
+ em.flush();
+ em.clear();
+ Query q = em.createQuery(
+ "select i from Item i where i.descr = :descr or (i.descr is null and cast(:descr as string) is null)"
+ );
+ //Query q = em.createQuery( "select i from Item i where (i.descr is null and :descr is null) or (i.descr = :descr");
+ q.setParameter( "descr", "dd" );
+ List result = q.getResultList();
+ assertEquals( 1, result.size() );
+ q.setParameter( "descr", null );
+ result = q.getResultList();
+ assertEquals( 1, result.size() );
+ //item = (Item) distinctResult.get( 0 );
+
+ em.getTransaction().rollback();
+ em.close();
+ }
+
+ public void testUpdateQuery() {
+
+ Item item = new Item( "Mouse", "Micro$oft mouse" );
+
+ EntityManager em = getOrCreateEntityManager();
+ em.getTransaction().begin();
+ em.persist( item );
+ assertTrue( em.contains( item ) );
+
+ em.flush();
+ em.clear();
+
+ assertEquals(
+ 1, em.createNativeQuery(
+ "update Item set descr = 'Logitech Mouse' where name = 'Mouse'"
+ ).executeUpdate()
+ );
+ item = em.find( Item.class, item.getName() );
+ assertEquals( "Logitech Mouse", item.getDescr() );
+ em.remove( item );
+ em.getTransaction().rollback();
+
+ em.close();
+
+ }
+
+ public void testUnavailableNamedQuery() throws Exception {
+ Item item = new Item( "Mouse", "Micro$oft mouse" );
+
+ EntityManager em = getOrCreateEntityManager();
+ em.getTransaction().begin();
+ em.persist( item );
+ try {
+ em.createNamedQuery( "wrong name" );
+ fail("Wrong named query should raise an exception");
+ }
+ catch (IllegalArgumentException e) {
+ //success
+ }
+ em.getTransaction().commit();
+
+ em.clear();
+
+ em.getTransaction().begin();
+ em.remove( em.find( Item.class, item.getName() ) );
+ em.getTransaction().commit();
+ em.close();
+
+ }
+
+ public Class[] getAnnotatedClasses() {
+ return new Class[]{
+ Item.class,
+ Distributor.class,
+ Wallet.class
+ };
+ }
+}
Property changes on: core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/query/QueryTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
15 years
Hibernate SVN: r18028 - core/trunk/envers/src/main/java/org/hibernate/envers/synchronization.
by hibernate-commits@lists.jboss.org
Author: adamw
Date: 2009-11-24 04:19:47 -0500 (Tue, 24 Nov 2009)
New Revision: 18028
Modified:
core/trunk/envers/src/main/java/org/hibernate/envers/synchronization/AuditSync.java
Log:
Not swallowing exceptions in some cases when a tx is rolled back by Envers
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/synchronization/AuditSync.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/synchronization/AuditSync.java 2009-11-23 18:34:56 UTC (rev 18027)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/synchronization/AuditSync.java 2009-11-24 09:19:47 UTC (rev 18028)
@@ -168,8 +168,15 @@
}
} catch (RuntimeException e) {
// Rolling back the transaction in case of any exceptions
- session.getTransaction().rollback();
- throw e;
+ //noinspection finally
+ try {
+ if (session.getTransaction().isActive()) {
+ session.getTransaction().rollback();
+ }
+ } finally {
+ //noinspection ThrowFromFinallyBlock
+ throw e;
+ }
}
}
15 years
Hibernate SVN: r18027 - core/trunk/core/src/main/java/org/hibernate/criterion.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2009-11-23 13:34:56 -0500 (Mon, 23 Nov 2009)
New Revision: 18027
Modified:
core/trunk/core/src/main/java/org/hibernate/criterion/InExpression.java
Log:
HHH-3164 HHH-1575 InExpression was populating parameters in the wrong order.
Modified: core/trunk/core/src/main/java/org/hibernate/criterion/InExpression.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/criterion/InExpression.java 2009-11-23 18:08:09 UTC (rev 18026)
+++ core/trunk/core/src/main/java/org/hibernate/criterion/InExpression.java 2009-11-23 18:34:56 UTC (rev 18027)
@@ -70,8 +70,8 @@
if ( type.isComponentType() ) {
AbstractComponentType actype = (AbstractComponentType) type;
Type[] types = actype.getSubtypes();
- for ( int i=0; i<types.length; i++ ) {
- for ( int j=0; j<values.length; j++ ) {
+ for ( int j=0; j<values.length; j++ ) {
+ for ( int i=0; i<types.length; i++ ) {
Object subval = values[j]==null ?
null :
actype.getPropertyValues( values[j], EntityMode.POJO )[i];
15 years
Hibernate SVN: r18026 - core/trunk/annotations/src/test/java/org/hibernate/test/annotations/cid.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2009-11-23 13:08:09 -0500 (Mon, 23 Nov 2009)
New Revision: 18026
Added:
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/cid/SomeEntity.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/cid/SomeEntityId.java
Modified:
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/cid/CompositeIdTest.java
Log:
HHH-3164 add test
Modified: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/cid/CompositeIdTest.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/cid/CompositeIdTest.java 2009-11-23 15:51:56 UTC (rev 18025)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/cid/CompositeIdTest.java 2009-11-23 18:08:09 UTC (rev 18026)
@@ -3,11 +3,17 @@
import java.util.Date;
import java.util.List;
+import java.util.ArrayList;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
+import org.hibernate.Criteria;
+import org.hibernate.dialect.HSQLDialect;
+import org.hibernate.criterion.Disjunction;
+import org.hibernate.criterion.Restrictions;
import org.hibernate.test.annotations.TestCase;
+import org.hibernate.test.annotations.SkipForDialect;
/**
* test some composite id functionalities
@@ -248,6 +254,62 @@
s.close();
}
+ @SkipForDialect(value=org.hibernate.dialect.HSQLDialect.class,
+ comment = "HSQLDB does not support ((..., ...),(..., ...))")
+ public void testQueryInAndComposite() {
+
+ Session s = openSession( );
+ Transaction transaction = s.beginTransaction();
+
+ SomeEntity someEntity = new SomeEntity();
+ someEntity.setId( new SomeEntityId( ) );
+ someEntity.getId().setId( 1 );
+ someEntity.getId().setVersion( 11 );
+ someEntity.setProp( "aa" );
+ s.persist( someEntity );
+ someEntity = new SomeEntity();
+ someEntity.setId( new SomeEntityId( ) );
+ someEntity.getId().setId( 1 );
+ someEntity.getId().setVersion( 12 );
+ someEntity.setProp( "bb" );
+ s.persist( someEntity );
+ someEntity = new SomeEntity();
+ someEntity.setId( new SomeEntityId( ) );
+ someEntity.getId().setId( 10 );
+ someEntity.getId().setVersion( 21 );
+ someEntity.setProp( "cc1" );
+ s.persist( someEntity );
+ someEntity = new SomeEntity();
+ someEntity.setId( new SomeEntityId( ) );
+ someEntity.getId().setId( 10 );
+ someEntity.getId().setVersion( 22 );
+ someEntity.setProp( "cc2" );
+ s.persist( someEntity );
+ someEntity = new SomeEntity();
+ someEntity.setId( new SomeEntityId( ) );
+ someEntity.getId().setId( 10 );
+ someEntity.getId().setVersion( 23 );
+ someEntity.setProp( "cc3" );
+ s.persist( someEntity );
+
+ s.flush();
+
+ List ids = new ArrayList<SomeEntityId>(2);
+ ids.add( new SomeEntityId(1,12) );
+ ids.add( new SomeEntityId(10,23) );
+
+ Criteria criteria = s.createCriteria( SomeEntity.class );
+ Disjunction disjunction = Restrictions.disjunction();
+
+ disjunction.add( Restrictions.in( "id", ids ) );
+ criteria.add( disjunction );
+
+ List list = criteria.list();
+ assertEquals( 2, list.size() );
+ transaction.rollback();
+ s.close();
+ }
+
protected Class[] getMappings() {
return new Class[] {
Parent.class,
@@ -264,7 +326,8 @@
LittleGenius.class,
A.class,
B.class,
- C.class
+ C.class,
+ SomeEntity.class
};
}
}
Added: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/cid/SomeEntity.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/cid/SomeEntity.java (rev 0)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/cid/SomeEntity.java 2009-11-23 18:08:09 UTC (rev 18026)
@@ -0,0 +1,49 @@
+package org.hibernate.test.annotations.cid;
+
+import java.io.Serializable;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Basic;
+
+/**
+ * @author bartek
+ */
+@Entity
+public class SomeEntity
+ implements Serializable {
+
+ @Id
+ private SomeEntityId id;
+
+ @Basic
+ private String prop;
+
+ /**
+ * @return the id
+ */
+ public SomeEntityId getId() {
+ return id;
+ }
+
+ /**
+ * @param id the id to set
+ */
+ public void setId(SomeEntityId id) {
+ this.id = id;
+ }
+
+ /**
+ * @return the prop
+ */
+ public String getProp() {
+ return prop;
+ }
+
+ /**
+ * @param prop the prop to set
+ */
+ public void setProp(String prop) {
+ this.prop = prop;
+ }
+
+}
Added: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/cid/SomeEntityId.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/cid/SomeEntityId.java (rev 0)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/cid/SomeEntityId.java 2009-11-23 18:08:09 UTC (rev 18026)
@@ -0,0 +1,78 @@
+package org.hibernate.test.annotations.cid;
+
+import java.io.Serializable;
+import javax.persistence.Embeddable;
+
+import org.hibernate.annotations.*;
+
+/**
+ * @author bartek
+ */
+@Embeddable
+public class SomeEntityId implements Serializable {
+ private Integer id;
+
+ private Integer version;
+
+ @org.hibernate.annotations.Parent
+ private SomeEntity parent;
+
+ /**
+ *
+ */
+ public SomeEntityId() {
+ super();
+ }
+
+ /**
+ * @param i
+ * @param j
+ */
+ public SomeEntityId(int id, int version) {
+ super();
+ this.id = id;
+ this.version = version;
+ }
+
+ /**
+ * @return the id
+ */
+ public int getId() {
+ return id;
+ }
+
+ /**
+ * @param id the id to set
+ */
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ /**
+ * @return the version
+ */
+ public int getVersion() {
+ return version;
+ }
+
+ /**
+ * @param version the version to set
+ */
+ public void setVersion(int version) {
+ this.version = version;
+ }
+
+ /**
+ * @return the parent
+ */
+ public SomeEntity getParent() {
+ return parent;
+ }
+
+ /**
+ * @param parent the parent to set
+ */
+ public void setParent(SomeEntity parent) {
+ this.parent = parent;
+ }
+}
15 years
Hibernate SVN: r18025 - in core/branches/envers-hibernate-3.3: src/main/java/org/hibernate/envers/configuration/metadata and 9 other directories.
by hibernate-commits@lists.jboss.org
Author: adamw
Date: 2009-11-23 10:51:56 -0500 (Mon, 23 Nov 2009)
New Revision: 18025
Added:
core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/integration/serialization/
core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/integration/serialization/SerializingCollection.java
Removed:
core/branches/envers-hibernate-3.3/src/main/java/org/jboss/envers/
core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/integration/serialization/SerializingCollection.java
Modified:
core/branches/envers-hibernate-3.3/pom.xml
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/reader/AnnotationsMetadataReader.java
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/reader/AuditedPropertiesReader.java
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entities/mapper/relation/lazy/proxy/CollectionProxy.java
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entities/mapper/relation/lazy/proxy/ListProxy.java
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entities/mapper/relation/lazy/proxy/SetProxy.java
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entities/mapper/relation/lazy/proxy/SortedSetProxy.java
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/exception/AuditException.java
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/exception/NotAuditedException.java
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/exception/RevisionDoesNotExistException.java
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/reader/AuditReaderImpl.java
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/reader/AuditReaderImplementor.java
core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/entities/onetomany/CollectionRefEdEntity.java
core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/entities/onetomany/CollectionRefIngEntity.java
core/branches/envers-hibernate-3.3/src/test/resources/testng.xml
Log:
svn merge -r 17587:18024 https://svn.jboss.org/repos/hibernate/core/trunk/envers .
Modified: core/branches/envers-hibernate-3.3/pom.xml
===================================================================
--- core/branches/envers-hibernate-3.3/pom.xml 2009-11-23 15:43:31 UTC (rev 18024)
+++ core/branches/envers-hibernate-3.3/pom.xml 2009-11-23 15:51:56 UTC (rev 18025)
@@ -7,7 +7,7 @@
<parent>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-parent</artifactId>
- <version>3.5.0.Beta-1</version>
+ <version>3.5.0-SNAPSHOT</version>
</parent>
<groupId>org.jboss.envers</groupId>
@@ -16,7 +16,7 @@
<name>Envers</name>
<description>Support for entity auditing</description>
- <version>1.2.1-hibernate-3.3</version>
+ <version>1.2.1-hibernate-3.3-SNAPSHOT</version>
<build>
<plugins>
Modified: core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java
===================================================================
--- core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java 2009-11-23 15:43:31 UTC (rev 18024)
+++ core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java 2009-11-23 15:51:56 UTC (rev 18025)
@@ -305,7 +305,14 @@
// Getting the property mapper of the parent - when mapping properties, they need to be included
String parentEntityName = pc.getSuperclass().getEntityName();
- ExtendedPropertyMapper parentPropertyMapper = entitiesConfigurations.get(parentEntityName).getPropertyMapper();
+
+ EntityConfiguration parentConfiguration = entitiesConfigurations.get(parentEntityName);
+ if (parentConfiguration == null) {
+ throw new MappingException("Entity '" + pc.getEntityName() + "' is audited, but its superclass: '" +
+ parentEntityName + "' is not.");
+ }
+
+ ExtendedPropertyMapper parentPropertyMapper = parentConfiguration.getPropertyMapper();
ExtendedPropertyMapper propertyMapper = new SubclassPropertyMapper(new MultiPropertyMapper(), parentPropertyMapper);
return Triple.make(class_mapping, propertyMapper, parentEntityName);
Modified: core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/reader/AnnotationsMetadataReader.java
===================================================================
--- core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/reader/AnnotationsMetadataReader.java 2009-11-23 15:43:31 UTC (rev 18024)
+++ core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/reader/AnnotationsMetadataReader.java 2009-11-23 15:51:56 UTC (rev 18025)
@@ -36,7 +36,6 @@
import org.hibernate.annotations.common.reflection.XClass;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Property;
-import org.jboss.envers.*;
/**
* A helper class to read versioning meta-data from annotations on a persistent class.
@@ -69,12 +68,7 @@
if (defaultAudited != null) {
return defaultAudited.modStore();
} else {
- Versioned defaultVersioned = clazz.getAnnotation(Versioned.class);
- if (defaultVersioned != null) {
- return ModificationStore.FULL;
- } else {
- return null;
- }
+ return null;
}
}
Modified: core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/reader/AuditedPropertiesReader.java
===================================================================
--- core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/reader/AuditedPropertiesReader.java 2009-11-23 15:43:31 UTC (rev 18024)
+++ core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/reader/AuditedPropertiesReader.java 2009-11-23 15:51:56 UTC (rev 18025)
@@ -26,7 +26,6 @@
import org.hibernate.mapping.Property;
import org.hibernate.mapping.Value;
import org.hibernate.MappingException;
-import org.jboss.envers.Versioned;
/**
* Reads persistent properties form a
@@ -157,12 +156,9 @@
// Checking if this property is explicitly audited or if all properties are.
Audited aud = property.getAnnotation(Audited.class);
- Versioned ver = property.getAnnotation(Versioned.class);
if (aud != null) {
propertyData.setStore(aud.modStore());
propertyData.setRelationTargetAuditMode(aud.targetAuditMode());
- } else if (ver != null) {
- propertyData.setStore(ModificationStore.FULL);
} else {
if (defaultStore != null) {
propertyData.setStore(defaultStore);
Modified: core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entities/mapper/relation/lazy/proxy/CollectionProxy.java
===================================================================
--- core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entities/mapper/relation/lazy/proxy/CollectionProxy.java 2009-11-23 15:43:31 UTC (rev 18024)
+++ core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entities/mapper/relation/lazy/proxy/CollectionProxy.java 2009-11-23 15:51:56 UTC (rev 18025)
@@ -23,6 +23,7 @@
*/
package org.hibernate.envers.entities.mapper.relation.lazy.proxy;
+import java.io.Serializable;
import java.util.Collection;
import java.util.Iterator;
@@ -31,8 +32,10 @@
/**
* @author Adam Warski (adam at warski dot org)
*/
-public abstract class CollectionProxy<U, T extends Collection<U>> implements Collection<U> {
- private org.hibernate.envers.entities.mapper.relation.lazy.initializor.Initializor<T> initializor;
+public abstract class CollectionProxy<U, T extends Collection<U>> implements Collection<U>, Serializable {
+ private static final long serialVersionUID = 8698249863871832402L;
+
+ private transient org.hibernate.envers.entities.mapper.relation.lazy.initializor.Initializor<T> initializor;
protected T delegate;
protected CollectionProxy() {
Modified: core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entities/mapper/relation/lazy/proxy/ListProxy.java
===================================================================
--- core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entities/mapper/relation/lazy/proxy/ListProxy.java 2009-11-23 15:43:31 UTC (rev 18024)
+++ core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entities/mapper/relation/lazy/proxy/ListProxy.java 2009-11-23 15:51:56 UTC (rev 18025)
@@ -33,7 +33,7 @@
/**
* @author Adam Warski (adam at warski dot org)
*/
-public class ListProxy<U> extends CollectionProxy<U, List<U>> implements List<U>, Serializable {
+public class ListProxy<U> extends CollectionProxy<U, List<U>> implements List<U> {
private static final long serialVersionUID = -5479232938279790987L;
public ListProxy() {
Modified: core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entities/mapper/relation/lazy/proxy/SetProxy.java
===================================================================
--- core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entities/mapper/relation/lazy/proxy/SetProxy.java 2009-11-23 15:43:31 UTC (rev 18024)
+++ core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entities/mapper/relation/lazy/proxy/SetProxy.java 2009-11-23 15:51:56 UTC (rev 18025)
@@ -29,7 +29,7 @@
/**
* @author Adam Warski (adam at warski dot org)
*/
-public class SetProxy<U> extends CollectionProxy<U, Set<U>> implements Set<U>, Serializable {
+public class SetProxy<U> extends CollectionProxy<U, Set<U>> implements Set<U> {
private static final long serialVersionUID = 131464133074137701L;
public SetProxy() {
Modified: core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entities/mapper/relation/lazy/proxy/SortedSetProxy.java
===================================================================
--- core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entities/mapper/relation/lazy/proxy/SortedSetProxy.java 2009-11-23 15:43:31 UTC (rev 18024)
+++ core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entities/mapper/relation/lazy/proxy/SortedSetProxy.java 2009-11-23 15:51:56 UTC (rev 18025)
@@ -25,12 +25,11 @@
import java.util.Comparator;
import java.util.SortedSet;
-import java.io.Serializable;
/**
* @author Adam Warski (adam at warski dot org)
*/
-public class SortedSetProxy<U> extends CollectionProxy<U, SortedSet<U>> implements SortedSet<U>, Serializable {
+public class SortedSetProxy<U> extends CollectionProxy<U, SortedSet<U>> implements SortedSet<U> {
private static final long serialVersionUID = 2092884107178125905L;
public SortedSetProxy() {
@@ -69,4 +68,4 @@
checkInit();
return delegate.last();
}
-}
\ No newline at end of file
+}
Modified: core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/exception/AuditException.java
===================================================================
--- core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/exception/AuditException.java 2009-11-23 15:43:31 UTC (rev 18024)
+++ core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/exception/AuditException.java 2009-11-23 15:51:56 UTC (rev 18025)
@@ -23,13 +23,15 @@
*/
package org.hibernate.envers.exception;
-import org.jboss.envers.exception.VersionsException;
+import org.hibernate.HibernateException;
/**
* @author Adam Warski (adam at warski dot org)
*/
-public class AuditException extends VersionsException {
- public AuditException(String message) {
+public class AuditException extends HibernateException {
+ private static final long serialVersionUID = 4306480965630972168L;
+
+ public AuditException(String message) {
super(message);
}
Modified: core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/exception/NotAuditedException.java
===================================================================
--- core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/exception/NotAuditedException.java 2009-11-23 15:43:31 UTC (rev 18024)
+++ core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/exception/NotAuditedException.java 2009-11-23 15:51:56 UTC (rev 18025)
@@ -23,13 +23,20 @@
*/
package org.hibernate.envers.exception;
-import org.jboss.envers.exception.NotVersionedException;
-
/**
* @author Adam Warski (adam at warski dot org)
*/
-public class NotAuditedException extends NotVersionedException {
- public NotAuditedException(String entityName, String message) {
- super(entityName, message);
+public class NotAuditedException extends AuditException {
+ private static final long serialVersionUID = 4809674577449455510L;
+
+ private final String entityName;
+
+ public NotAuditedException(String entityName, String message) {
+ super(message);
+ this.entityName = entityName;
}
+
+ public String getEntityName() {
+ return entityName;
+ }
}
Modified: core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/exception/RevisionDoesNotExistException.java
===================================================================
--- core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/exception/RevisionDoesNotExistException.java 2009-11-23 15:43:31 UTC (rev 18024)
+++ core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/exception/RevisionDoesNotExistException.java 2009-11-23 15:51:56 UTC (rev 18025)
@@ -28,12 +28,27 @@
/**
* @author Adam Warski (adam at warski dot org)
*/
-public class RevisionDoesNotExistException extends org.jboss.envers.exception.RevisionDoesNotExistException {
- public RevisionDoesNotExistException(Number revision) {
- super(revision);
+public class RevisionDoesNotExistException extends AuditException {
+ private static final long serialVersionUID = -6417768274074962282L;
+
+ private Number revision;
+ private Date date;
+
+ public RevisionDoesNotExistException(Number revision) {
+ super("Revision " + revision + " does not exist.");
+ this.revision = revision;
}
public RevisionDoesNotExistException(Date date) {
- super(date);
+ super("There is no revision before or at " + date + ".");
+ this.date = date;
}
+
+ public Number getRevision() {
+ return revision;
+ }
+
+ public Date getDate() {
+ return date;
+ }
}
Modified: core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/reader/AuditReaderImpl.java
===================================================================
--- core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/reader/AuditReaderImpl.java 2009-11-23 15:43:31 UTC (rev 18024)
+++ core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/reader/AuditReaderImpl.java 2009-11-23 15:51:56 UTC (rev 18025)
@@ -32,6 +32,7 @@
import org.hibernate.envers.exception.RevisionDoesNotExistException;
import org.hibernate.envers.exception.AuditException;
import org.hibernate.envers.query.AuditEntity;
+import org.hibernate.envers.query.AuditQueryCreator;
import static org.hibernate.envers.tools.ArgumentsTools.checkNotNull;
import static org.hibernate.envers.tools.ArgumentsTools.checkPositive;
import org.hibernate.envers.synchronization.AuditSync;
@@ -41,7 +42,6 @@
import org.hibernate.Session;
import org.hibernate.event.EventSource;
import org.hibernate.engine.SessionImplementor;
-import org.jboss.envers.query.VersionsQueryCreator;
/**
* @author Adam Warski (adam at warski dot org)
@@ -205,7 +205,7 @@
return (T) auditSync.getCurrentRevisionData(session, persist);
}
- public VersionsQueryCreator createQuery() {
- return new VersionsQueryCreator(verCfg, this);
+ public AuditQueryCreator createQuery() {
+ return new AuditQueryCreator(verCfg, this);
}
}
Modified: core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/reader/AuditReaderImplementor.java
===================================================================
--- core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/reader/AuditReaderImplementor.java 2009-11-23 15:43:31 UTC (rev 18024)
+++ core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/reader/AuditReaderImplementor.java 2009-11-23 15:51:56 UTC (rev 18025)
@@ -27,13 +27,12 @@
import org.hibernate.Session;
import org.hibernate.engine.SessionImplementor;
-import org.jboss.envers.VersionsReader;
/**
* An interface exposed by a VersionsReader to library-facing classes.
* @author Adam Warski (adam at warski dot org)
*/
-public interface AuditReaderImplementor extends AuditReader, VersionsReader {
+public interface AuditReaderImplementor extends AuditReader {
SessionImplementor getSessionImplementor();
Session getSession();
FirstLevelCache getFirstLevelCache();
Modified: core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/entities/onetomany/CollectionRefEdEntity.java
===================================================================
--- core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/entities/onetomany/CollectionRefEdEntity.java 2009-11-23 15:43:31 UTC (rev 18024)
+++ core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/entities/onetomany/CollectionRefEdEntity.java 2009-11-23 15:51:56 UTC (rev 18025)
@@ -24,6 +24,7 @@
package org.hibernate.envers.test.entities.onetomany;
import java.util.Collection;
+import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.OneToMany;
@@ -35,7 +36,9 @@
* @author Adam Warski (adam at warski dot org)
*/
@Entity
-public class CollectionRefEdEntity {
+public class CollectionRefEdEntity implements Serializable {
+ private static final long serialVersionUID = -1694020123633796683L;
+
@Id
private Integer id;
@@ -46,7 +49,7 @@
@OneToMany(mappedBy="reference")
private Collection<CollectionRefIngEntity> reffering;
- public CollectionRefEdEntity() {
+ public CollectionRefEdEntity() {
}
public CollectionRefEdEntity(Integer id, String data) {
Modified: core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/entities/onetomany/CollectionRefIngEntity.java
===================================================================
--- core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/entities/onetomany/CollectionRefIngEntity.java 2009-11-23 15:43:31 UTC (rev 18024)
+++ core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/entities/onetomany/CollectionRefIngEntity.java 2009-11-23 15:51:56 UTC (rev 18025)
@@ -29,12 +29,16 @@
import org.hibernate.envers.Audited;
+import java.io.Serializable;
+
/**
* ReferencIng entity
* @author Adam Warski (adam at warski dot org)
*/
@Entity
-public class CollectionRefIngEntity {
+public class CollectionRefIngEntity implements Serializable {
+ private static final long serialVersionUID = -9019967223928425707L;
+
@Id
private Integer id;
@@ -45,7 +49,7 @@
@ManyToOne
private CollectionRefEdEntity reference;
- public CollectionRefIngEntity() { }
+ public CollectionRefIngEntity() { }
public CollectionRefIngEntity(Integer id, String data, CollectionRefEdEntity reference) {
this.id = id;
Copied: core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/integration/serialization (from rev 18024, core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/serialization)
Deleted: core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/integration/serialization/SerializingCollection.java
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/serialization/SerializingCollection.java 2009-11-23 15:43:31 UTC (rev 18024)
+++ core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/integration/serialization/SerializingCollection.java 2009-11-23 15:51:56 UTC (rev 18025)
@@ -1,110 +0,0 @@
-/*
- * Hibernate, Relational Persistence for Idiomatic Java
- *
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
- * indicated by the @author tags or express copyright attribution
- * statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
- *
- * This copyrighted material is made available to anyone wishing to use, modify,
- * copy, or redistribute it subject to the terms and conditions of the GNU
- * Lesser General Public License, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
- * for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this distribution; if not, write to:
- * Free Software Foundation, Inc.
- * 51 Franklin Street, Fifth Floor
- * Boston, MA 02110-1301 USA
- */
-package org.hibernate.envers.test.integration.serialization;
-
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Set;
-import java.io.ByteArrayOutputStream;
-import java.io.ObjectOutputStream;
-import java.io.ByteArrayInputStream;
-import java.io.ObjectInputStream;
-import java.io.IOException;
-import javax.persistence.EntityManager;
-
-import org.hibernate.envers.test.AbstractEntityTest;
-import org.hibernate.envers.test.entities.onetomany.CollectionRefEdEntity;
-import org.hibernate.envers.test.entities.onetomany.CollectionRefIngEntity;
-import org.testng.annotations.BeforeClass;
-import org.testng.annotations.Test;
-
-import org.hibernate.ejb.Ejb3Configuration;
-
-/**
- * @author Adam Warski (adam at warski dot org)
- */
-public class SerializingCollection extends AbstractEntityTest {
- private Integer ed1_id;
- private Integer ing1_id;
-
- public void configure(Ejb3Configuration cfg) {
- cfg.addAnnotatedClass(CollectionRefEdEntity.class);
- cfg.addAnnotatedClass(CollectionRefIngEntity.class);
- }
-
- @BeforeClass(dependsOnMethods = "init")
- public void initData() {
- EntityManager em = getEntityManager();
-
- CollectionRefEdEntity ed1 = new CollectionRefEdEntity(1, "data_ed_1");
-
- CollectionRefIngEntity ing1 = new CollectionRefIngEntity(3, "data_ing_1", ed1);
-
- // Revision 1
- em.getTransaction().begin();
-
- em.persist(ed1);
- em.persist(ing1);
-
- em.getTransaction().commit();
-
- //
-
- ed1_id = ed1.getId();
- ing1_id = ing1.getId();
- }
-
- @Test
- public void testDetach()throws Exception {
- CollectionRefIngEntity ing1 = getEntityManager().find(CollectionRefIngEntity.class, ing1_id);
- CollectionRefEdEntity rev1 = getAuditReader().find(CollectionRefEdEntity.class, ed1_id, 1);
-
- // First forcing loading of the collection
- assert rev1.getReffering().size() == 1;
-
- // Now serializing and de-serializing the
- rev1 = serializeDeserialize(rev1);
-
- // And checking the colleciton again
- assert rev1.getReffering().contains(ing1);
- assert rev1.getReffering().size() == 1;
-
- }
-
- @SuppressWarnings({"unchecked"})
- public static <T> T serializeDeserialize(T o) throws Exception {
- if (o == null) return null;
-
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- ObjectOutputStream oos = new ObjectOutputStream(baos);
- oos.writeObject(o);
- byte[] buffer = baos.toByteArray();
- baos.close();
-
- ByteArrayInputStream bais = new ByteArrayInputStream(buffer);
- ObjectInputStream ois = new ObjectInputStream(bais);
- return (T) ois.readObject();
- }
-}
Copied: core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/integration/serialization/SerializingCollection.java (from rev 18024, core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/serialization/SerializingCollection.java)
===================================================================
--- core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/integration/serialization/SerializingCollection.java (rev 0)
+++ core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/integration/serialization/SerializingCollection.java 2009-11-23 15:51:56 UTC (rev 18025)
@@ -0,0 +1,110 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.envers.test.integration.serialization;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectOutputStream;
+import java.io.ByteArrayInputStream;
+import java.io.ObjectInputStream;
+import java.io.IOException;
+import javax.persistence.EntityManager;
+
+import org.hibernate.envers.test.AbstractEntityTest;
+import org.hibernate.envers.test.entities.onetomany.CollectionRefEdEntity;
+import org.hibernate.envers.test.entities.onetomany.CollectionRefIngEntity;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import org.hibernate.ejb.Ejb3Configuration;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class SerializingCollection extends AbstractEntityTest {
+ private Integer ed1_id;
+ private Integer ing1_id;
+
+ public void configure(Ejb3Configuration cfg) {
+ cfg.addAnnotatedClass(CollectionRefEdEntity.class);
+ cfg.addAnnotatedClass(CollectionRefIngEntity.class);
+ }
+
+ @BeforeClass(dependsOnMethods = "init")
+ public void initData() {
+ EntityManager em = getEntityManager();
+
+ CollectionRefEdEntity ed1 = new CollectionRefEdEntity(1, "data_ed_1");
+
+ CollectionRefIngEntity ing1 = new CollectionRefIngEntity(3, "data_ing_1", ed1);
+
+ // Revision 1
+ em.getTransaction().begin();
+
+ em.persist(ed1);
+ em.persist(ing1);
+
+ em.getTransaction().commit();
+
+ //
+
+ ed1_id = ed1.getId();
+ ing1_id = ing1.getId();
+ }
+
+ @Test
+ public void testDetach()throws Exception {
+ CollectionRefIngEntity ing1 = getEntityManager().find(CollectionRefIngEntity.class, ing1_id);
+ CollectionRefEdEntity rev1 = getAuditReader().find(CollectionRefEdEntity.class, ed1_id, 1);
+
+ // First forcing loading of the collection
+ assert rev1.getReffering().size() == 1;
+
+ // Now serializing and de-serializing the
+ rev1 = serializeDeserialize(rev1);
+
+ // And checking the colleciton again
+ assert rev1.getReffering().contains(ing1);
+ assert rev1.getReffering().size() == 1;
+
+ }
+
+ @SuppressWarnings({"unchecked"})
+ public static <T> T serializeDeserialize(T o) throws Exception {
+ if (o == null) return null;
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectOutputStream oos = new ObjectOutputStream(baos);
+ oos.writeObject(o);
+ byte[] buffer = baos.toByteArray();
+ baos.close();
+
+ ByteArrayInputStream bais = new ByteArrayInputStream(buffer);
+ ObjectInputStream ois = new ObjectInputStream(bais);
+ return (T) ois.readObject();
+ }
+}
Modified: core/branches/envers-hibernate-3.3/src/test/resources/testng.xml
===================================================================
--- core/branches/envers-hibernate-3.3/src/test/resources/testng.xml 2009-11-23 15:43:31 UTC (rev 18024)
+++ core/branches/envers-hibernate-3.3/src/test/resources/testng.xml 2009-11-23 15:51:56 UTC (rev 18025)
@@ -54,6 +54,7 @@
<package name="org.hibernate.envers.test.integration.sameids" />
<package name="org.hibernate.envers.test.integration.secondary" />
<package name="org.hibernate.envers.test.integration.secondary.ids" />
+ <package name="org.hibernate.envers.test.integration.serialization" />
<package name="org.hibernate.envers.test.integration.superclass" />
</packages>
</test>
15 years