Merge remote-tracking branch 'upstream/main' into wip/6.0

This commit is contained in:
Andrea Boriero 2021-03-22 12:26:31 +01:00
commit 96d103215c
73 changed files with 1382 additions and 501 deletions

View File

@ -9,11 +9,11 @@ name: Hibernate ORM build
on:
push:
branches:
- 'master'
- 'main'
- 'wip/6.0'
pull_request:
branches:
- 'master'
- 'main'
- 'wip/6.0'
jobs:
build:

View File

@ -62,8 +62,8 @@ although this is more of a mnemonic strategy than a hard-and-fast rule - but doi
_If there is not already a JIRA issue covering the work you want to do, create one._
Assuming you will be working from the master branch and working
on the JIRA HHH-123 : `git checkout -b HHH-123 master`
Assuming you will be working from the `main` branch and working
on the JIRA HHH-123 : `git checkout -b HHH-123 main`
## Code

View File

@ -8,7 +8,7 @@ It also provides an implementation of the JPA specification, which is the standa
This is the repository of its source code: see [Hibernate.org](http://hibernate.org/orm/) for additional information.
[![Build Status](http://ci.hibernate.org/job/hibernate-orm-master-h2-main/badge/icon)](http://ci.hibernate.org/job/hibernate-orm-master-h2-main/)
[![Build Status](http://ci.hibernate.org/job/hibernate-orm-main-h2-main/badge/icon)](http://ci.hibernate.org/job/hibernate-orm-main-h2-main/)
[![Language grade: Java](https://img.shields.io/lgtm/grade/java/g/hibernate/hibernate-orm.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/hibernate/hibernate-orm/context:java)

View File

@ -205,7 +205,7 @@ hana() {
--ulimit nofile=1048576:1048576 \
--sysctl kernel.shmmax=1073741824 \
--sysctl net.ipv4.ip_local_port_range='40000 60999' \
--sysctl kernel.shmmni=524288 \
--sysctl kernel.shmmni=4096 \
--sysctl kernel.shmall=8388608 \
-v $temp_dir:/config \
store/saplabs/hanaexpress:2.00.045.00.20200121.1 \
@ -230,6 +230,12 @@ cockroachdb() {
sleep 10
OUTPUT=$(docker logs cockroach)
done
echo "Enabling experimental box2d operators"
docker exec -it cockroach bash -c "cat <<EOF | ./cockroach sql --insecure
SET CLUSTER SETTING sql.spatial.experimental_box2d_comparison_operators.enabled = on;
quit
EOF
"
echo "Cockroachdb successfully started"
}

View File

@ -86,42 +86,42 @@ relevant section.
:no: icon:times[role="red"]
[[spatial-configuration-dialect-features]]
.Hibernate Spatial dialect function support
[cols=",,,,,,," |options="header",]
[cols=",,,,,,,," |options="header",]
|================================
|Function | Description | PostgresSQL | Oracle 10g/11g | MySQL | SQLServer | GeoDB (H2) | DB2
|Basic functions on Geometry | | | | | | |
|`int dimension(Geometry)` | SFS §2.1.1.1 | {yes} | {yes} | {yes} | {yes} | {yes} | {yes}
|`String geometrytype(Geometry)` | SFS §2.1.1.1 | {yes} | {yes} | {yes} | {yes} | {yes} | {yes}
|`int srid(Geometry)` | SFS §2.1.1.1 | {yes} | {yes} | {yes} | {yes} | {yes} | {yes}
|`Geometry envelope(Geometry)` | SFS §2.1.1.1 | {yes} | {yes} | {yes} | {yes} | {yes} | {yes}
|`String astext(Geometry)` | SFS §2.1.1.1 | {yes} | {yes} | {yes} | {yes} | {yes} | {yes}
|`byte[] asbinary(Geometry)` | SFS §2.1.1.1 | {yes} | {yes} | {yes} | {yes} | {yes} | {yes}
|`boolean isempty(Geometry)` | SFS §2.1.1.1 | {yes} | {yes} | {yes} | {yes} | {yes} | {yes}
|`boolean issimple(Geometry)` | SFS §2.1.1.1 | {yes} | {yes} | {yes} | {yes} | {yes} | {yes}
|`Geometry boundary(Geometry)` | SFS §2.1.1.1 | {yes} | {yes} | {no} | {yes} | {yes} | {yes}
|Functions for testing Spatial Relations between geometric objects | | | | | | |
|`boolean equals(Geometry, Geometry)` | SFS §2.1.1.2 | {yes} | {yes} | {yes} | {yes} | {yes} | {yes}
|`boolean disjoint(Geometry, Geometry)` | SFS §2.1.1.2 | {yes} | {yes} | {yes} | {yes} | {yes} | {yes}
|`boolean intersects(Geometry, Geometry)` | SFS §2.1.1.2 | {yes} | {yes} | {yes} | {yes} | {yes} | {yes}
|`boolean touches(Geometry, Geometry)` | SFS §2.1.1.2 | {yes} | {yes} | {yes} | {yes} | {yes} | {yes}
|`boolean crosses(Geometry, Geometry)` | SFS §2.1.1.2 | {yes} | {yes} | {yes} | {yes} | {yes} | {yes}
|`boolean within(Geometry, Geometry)` | SFS §2.1.1.2 | {yes} | {yes} | {yes} | {yes} | {yes} | {yes}
|`boolean contains(Geometry, Geometry)` | SFS §2.1.1.2 | {yes} | {yes} | {yes} | {yes} | {yes} | {yes}
|`boolean overlaps(Geometry, Geometry)` | SFS §2.1.1.2 | {yes} | {yes} | {yes} | {yes} | {yes} | {yes}
|`boolean relate(Geometry, Geometry, String)` | SFS §2.1.1.2 | {yes} | {yes} | {no} | {yes} | {yes} | {yes}
|Functions that support Spatial Analysis | | | | | | |
|`double distance(Geometry, Geometry)` | SFS §2.1.1.3 | {yes} | {yes} | {no} | {yes} | {yes} | {yes}
|`Geometry buffer(Geometry, double)` | SFS §2.1.1.3 | {yes} | {yes} | {no} | {yes} | {yes} | {yes}
|`Geometry convexhull(Geometry)` | SFS §2.1.1.3 | {yes} | {yes} | {no} | {yes} | {yes} | {yes}^(1)^
|`Geometry intersection(Geometry, Geometry)` | SFS §2.1.1.3 | {yes} | {yes} | {no} | {yes} | {yes} | {yes}^(1)^
|`Geometry geomunion(Geometry, Geometry)` | SFS §2.1.1.3 (renamed from union) | {yes} | {yes} | {no} | {yes} | {yes} | {yes}^(1)^
|`Geometry difference(Geometry, Geometry)` | SFS §2.1.1.3 | {yes} | {yes} | {no} | {yes} | {yes} | {yes}^(1)^
|`Geometry symdifference(Geometry, Geometry)` | SFS §2.1.1.3 | {yes} | {yes} | {no} | {yes} | {yes} | {yes}^(1)^
|Common non-SFS functions | | | | | | |
|`boolean dwithin(Geometry, Geometry, double)` | Returns true if the geometries are within the specified distance of one another | {yes} | {yes} | {no} | {no} | {yes} | {yes}
|`Geometry transform(Geometry, int)` | Returns a new geometry with its coordinates transformed to the SRID referenced by the integer parameter | {yes} | {yes} | {no} | {no} | {no} | {no}
|Spatial aggregate Functions | | | | | | |
|`Geometry extent(Geometry)` | Returns a bounding box that bounds the set of returned geometries | {yes} | {yes} | {no} | {no} | {no} | {no}
|Function | Description | PostgresSQL | Oracle 10g/11g | MySQL | SQLServer | GeoDB (H2) | DB2 | CockroachDB
|Basic functions on Geometry | | | | | | | |
|`int dimension(Geometry)` | SFS §2.1.1.1 | {yes} | {yes} | {yes} | {yes} | {yes} | {yes} | {yes}
|`String geometrytype(Geometry)` | SFS §2.1.1.1 | {yes} | {yes} | {yes} | {yes} | {yes} | {yes} | {yes}
|`int srid(Geometry)` | SFS §2.1.1.1 | {yes} | {yes} | {yes} | {yes} | {yes} | {yes} | {yes}
|`Geometry envelope(Geometry)` | SFS §2.1.1.1 | {yes} | {yes} | {yes} | {yes} | {yes} | {yes} | {yes}
|`String astext(Geometry)` | SFS §2.1.1.1 | {yes} | {yes} | {yes} | {yes} | {yes} | {yes} | {yes}
|`byte[] asbinary(Geometry)` | SFS §2.1.1.1 | {yes} | {yes} | {yes} | {yes} | {yes} | {yes} | {yes}
|`boolean isempty(Geometry)` | SFS §2.1.1.1 | {yes} | {yes} | {yes} | {yes} | {yes} | {yes} | {yes}
|`boolean issimple(Geometry)` | SFS §2.1.1.1 | {yes} | {yes} | {yes} | {yes} | {yes} | {yes} | {yes}
|`Geometry boundary(Geometry)` | SFS §2.1.1.1 | {yes} | {yes} | {no} | {yes} | {yes} | {yes} | {yes}
|Functions for testing Spatial Relations between geometric objects | | | | | | | |
|`boolean equals(Geometry, Geometry)` | SFS §2.1.1.2 | {yes} | {yes} | {yes} | {yes} | {yes} | {yes} | {yes}
|`boolean disjoint(Geometry, Geometry)` | SFS §2.1.1.2 | {yes} | {yes} | {yes} | {yes} | {yes} | {yes} | {yes}
|`boolean intersects(Geometry, Geometry)` | SFS §2.1.1.2 | {yes} | {yes} | {yes} | {yes} | {yes} | {yes} | {yes}
|`boolean touches(Geometry, Geometry)` | SFS §2.1.1.2 | {yes} | {yes} | {yes} | {yes} | {yes} | {yes} | {yes}
|`boolean crosses(Geometry, Geometry)` | SFS §2.1.1.2 | {yes} | {yes} | {yes} | {yes} | {yes} | {yes} | {yes}
|`boolean within(Geometry, Geometry)` | SFS §2.1.1.2 | {yes} | {yes} | {yes} | {yes} | {yes} | {yes} | {yes}
|`boolean contains(Geometry, Geometry)` | SFS §2.1.1.2 | {yes} | {yes} | {yes} | {yes} | {yes} | {yes} | {yes}
|`boolean overlaps(Geometry, Geometry)` | SFS §2.1.1.2 | {yes} | {yes} | {yes} | {yes} | {yes} | {yes} | {yes}
|`boolean relate(Geometry, Geometry, String)` | SFS §2.1.1.2 | {yes} | {yes} | {no} | {yes} | {yes} | {yes} | {yes}
|Functions that support Spatial Analysis | | | | | | | |
|`double distance(Geometry, Geometry)` | SFS §2.1.1.3 | {yes} | {yes} | {no} | {yes} | {yes} | {yes} | {yes}
|`Geometry buffer(Geometry, double)` | SFS §2.1.1.3 | {yes} | {yes} | {no} | {yes} | {yes} | {yes} | {yes}
|`Geometry convexhull(Geometry)` | SFS §2.1.1.3 | {yes} | {yes} | {no} | {yes} | {yes} | {yes}^(1)^ | {no}
|`Geometry intersection(Geometry, Geometry)` | SFS §2.1.1.3 | {yes} | {yes} | {no} | {yes} | {yes} | {yes}^(1)^ | {yes}
|`Geometry geomunion(Geometry, Geometry)` | SFS §2.1.1.3 (renamed from union) | {yes} | {yes} | {no} | {yes} | {yes} | {yes}^(1)^ | {yes}
|`Geometry difference(Geometry, Geometry)` | SFS §2.1.1.3 | {yes} | {yes} | {no} | {yes} | {yes} | {yes}^(1)^ | {yes}
|`Geometry symdifference(Geometry, Geometry)` | SFS §2.1.1.3 | {yes} | {yes} | {no} | {yes} | {yes} | {yes}^(1)^ | {yes}
|Common non-SFS functions | | | | | | | |
|`boolean dwithin(Geometry, Geometry, double)` | Returns true if the geometries are within the specified distance of one another | {yes} | {yes} | {no} | {no} | {yes} | {yes} | {yes}
|`Geometry transform(Geometry, int)` | Returns a new geometry with its coordinates transformed to the SRID referenced by the integer parameter | {yes} | {yes} | {no} | {no} | {no} | {no} | {yes}
|Spatial aggregate Functions | | | | | | | |
|`Geometry extent(Geometry)` | Returns a bounding box that bounds the set of returned geometries | {yes} | {yes} | {no} | {no} | {no} | {no} | {yes}
|================================
^(1)^ Argument Geometries need to have the same dimensionality.
@ -191,6 +191,14 @@ The dialect `SqlServer2008Dialect` supports the `GEOMETRY` type in SQL Server 20
The `GEOGRAPHY` type is not currently supported.
====
CockroachDB::
The dialect `CockroachDB202SpatialDialect` support the `GEOMETRY` type in CockroachDB v20.2 and later.
[NOTE]
====
The `GEOGRAPHY` type is not currently supported.
====
GeoDB (H2)::
The `GeoDBDialect` supports the GeoDB a spatial extension of the H2 in-memory database.
[NOTE]

View File

@ -228,6 +228,15 @@ ext {
// Disable prepared statement caching due to https://www.postgresql.org/message-id/CAEcMXhmmRd4-%2BNQbnjDT26XNdUoXdmntV9zdr8%3DTu8PL9aVCYg%40mail.gmail.com
'jdbc.url' : 'jdbc:postgresql://localhost:26257/defaultdb?sslmode=disable&preparedStatementCacheQueries=0'
],
cockroachdb_spatial : [
'db.dialect' : 'org.hibernate.spatial.dialect.cockroachdb.CockroachDB202SpatialDialect',
// CockroachDB uses the same pgwire protocol as PostgreSQL, so the driver is the same.
'jdbc.driver': 'org.postgresql.Driver',
'jdbc.user' : 'root',
'jdbc.pass' : '',
// Disable prepared statement caching due to https://www.postgresql.org/message-id/CAEcMXhmmRd4-%2BNQbnjDT26XNdUoXdmntV9zdr8%3DTu8PL9aVCYg%40mail.gmail.com
'jdbc.url' : 'jdbc:postgresql://localhost:26257/defaultdb?sslmode=disable&preparedStatementCacheQueries=0'
]
]
}

View File

@ -32,7 +32,7 @@ ext {
assertjVersion = '3.14.0'
geolatteVersion = '1.6.1'
geolatteVersion = '1.8.0'
shrinkwrapVersion = '1.2.6'
shrinkwrapDescriptorsVersion = '2.0.0'

View File

@ -1641,7 +1641,7 @@ public interface CoreMessageLogger extends BasicLogger {
)
void applyingExplicitDiscriminatorColumnForJoined(String className, String overrideSetting);
// 458-466 reserved for use by master (ORM 5.0.0)
// 458-466 reserved for use by main branch (ORM 5.0.0)
@LogMessage(level = DEBUG)
@Message(value = "Creating pooled optimizer (lo) with [incrementSize=%s; returnClass=%s]", id = 467)

View File

@ -1433,7 +1433,7 @@ public abstract class AbstractProducedQuery<R> implements QueryImplementor<R> {
return new StreamDecorator<>(
StreamSupport.stream( spliterator, false ),
scrollableResults::close
iterator::close
);
}

View File

@ -41,15 +41,13 @@ import org.hibernate.Incubating;
public class DoubleStreamDecorator implements DoubleStream {
private final DoubleStream delegate;
private Runnable closeHandler;
private final Runnable closeHandler;
public DoubleStreamDecorator(
DoubleStream delegate,
Runnable closeHandler) {
this.delegate = delegate;
this.closeHandler = closeHandler;
this.delegate.onClose( closeHandler );
this.delegate = delegate.onClose( closeHandler );
}
@Override
@ -292,7 +290,7 @@ public class DoubleStreamDecorator implements DoubleStream {
@Override
public DoubleStream onClose(Runnable closeHandler) {
this.closeHandler = closeHandler;
this.delegate.onClose( closeHandler );
return this;
}

View File

@ -42,15 +42,13 @@ import org.hibernate.Incubating;
public class IntStreamDecorator implements IntStream {
private final IntStream delegate;
private Runnable closeHandler;
private final Runnable closeHandler;
public IntStreamDecorator(
IntStream delegate,
Runnable closeHandler) {
this.delegate = delegate;
this.closeHandler = closeHandler;
this.delegate.onClose( closeHandler );
this.delegate = delegate.onClose( closeHandler );
}
@Override
@ -307,7 +305,7 @@ public class IntStreamDecorator implements IntStream {
@Override
public IntStream onClose(Runnable closeHandler) {
this.closeHandler = closeHandler;
this.delegate.onClose( closeHandler );
return this;
}

View File

@ -42,15 +42,13 @@ import org.hibernate.Incubating;
public class LongStreamDecorator implements LongStream {
private final LongStream delegate;
private Runnable closeHandler;
private final Runnable closeHandler;
public LongStreamDecorator(
LongStream delegate,
Runnable closeHandler) {
this.delegate = delegate;
this.closeHandler = closeHandler;
this.delegate.onClose( closeHandler );
this.delegate = delegate.onClose( closeHandler );
}
@Override
@ -226,21 +224,21 @@ public class LongStreamDecorator implements LongStream {
@Override
public boolean anyMatch(LongPredicate predicate) {
boolean result = delegate.anyMatch(predicate);
boolean result = delegate.anyMatch( predicate );
close();
return result;
}
@Override
public boolean allMatch(LongPredicate predicate) {
boolean result = delegate.allMatch(predicate);
boolean result = delegate.allMatch( predicate );
close();
return result;
}
@Override
public boolean noneMatch(LongPredicate predicate) {
boolean result = delegate.noneMatch(predicate);
boolean result = delegate.noneMatch( predicate );
close();
return result;
}
@ -300,7 +298,7 @@ public class LongStreamDecorator implements LongStream {
@Override
public LongStream onClose(Runnable closeHandler) {
this.closeHandler = closeHandler;
this.delegate.onClose( closeHandler );
return this;
}

View File

@ -46,15 +46,13 @@ import org.hibernate.internal.util.ReflectHelper;
public class StreamDecorator<R> implements Stream<R> {
private final Stream<R> delegate;
private Runnable closeHandler;
private final Runnable closeHandler;
public StreamDecorator(
Stream<R> delegate,
Runnable closeHandler) {
this.delegate = delegate;
this.closeHandler = closeHandler;
this.delegate.onClose( closeHandler );
this.delegate = delegate.onClose( closeHandler );
}
@Override
@ -301,7 +299,7 @@ public class StreamDecorator<R> implements Stream<R> {
@Override
public Stream<R> onClose(Runnable closeHandler) {
this.closeHandler = closeHandler;
this.delegate.onClose( closeHandler );
return this;
}

View File

@ -26,7 +26,7 @@ public class FormalLastName {
@Embedded
private LastName lastName;
private String designation; /* Mr/Mrs/Master */
private String designation; /* Mr/Mrs */
public Integer getId() {
return id;

View File

@ -21,7 +21,7 @@ public class AnnotatedFormWithBeanValidationNotNullTest extends BaseUnitTestCase
@TestForIssue( jiraKey = "HHH-8167" )
public void testAnnotatedFormWithBeanValidationNotNull() {
Configuration cfg = new Configuration();
cfg.addAnnotatedClass( AnnotatedMaster.class ).addAnnotatedClass( AnnotatedDetail.class );
cfg.addAnnotatedClass( AnnotatedRoot.class ).addAnnotatedClass( AnnotatedDetail.class );
cfg.buildSessionFactory().close();
}
}

View File

@ -22,7 +22,7 @@ import org.hibernate.annotations.JoinFormula;
* @author Steve Ebersole
*/
@Entity
public class AnnotatedMaster {
public class AnnotatedRoot {
@Id
private Integer id;
private String name;

View File

@ -14,7 +14,7 @@ import java.io.Serializable;
*/
public class Detail implements Serializable {
private Long id;
private Master master;
private Root root;
private int version;
private String details;
private boolean currentVersion;
@ -37,11 +37,11 @@ public class Detail implements Serializable {
public void setId(Long id) {
this.id = id;
}
public Master getMaster() {
return master;
public Root getRoot() {
return root;
}
public void setMaster(Master master) {
this.master = master;
public void setRoot(Root root) {
this.root = root;
}
public int getVersion() {
return version;

View File

@ -24,27 +24,27 @@ import static org.junit.Assert.assertTrue;
*/
public class FormulaJoinTest extends BaseCoreFunctionalTestCase {
public String[] getMappings() {
return new String[] { "formulajoin/Master.hbm.xml" };
return new String[] { "formulajoin/Root.hbm.xml" };
}
@Test
public void testFormulaJoin() {
Session s = openSession();
Transaction tx = s.beginTransaction();
Master master = new Master();
master.setName("master 1");
Root root = new Root();
root.setName("root 1");
Detail current = new Detail();
current.setCurrentVersion(true);
current.setVersion(2);
current.setDetails("details of master 1 blah blah");
current.setMaster(master);
master.setDetail(current);
current.setDetails("details of root 1 blah blah");
current.setRoot( root );
root.setDetail(current);
Detail past = new Detail();
past.setCurrentVersion(false);
past.setVersion(1);
past.setDetails("old details of master 1 yada yada");
past.setMaster(master);
s.persist(master);
past.setDetails("old details of root 1 yada yada");
past.setRoot( root );
s.persist( root );
s.persist(past);
s.persist(current);
tx.commit();
@ -54,42 +54,42 @@ public class FormulaJoinTest extends BaseCoreFunctionalTestCase {
s = openSession();
tx = s.beginTransaction();
List l = s.createQuery("from Master m left join m.detail d").list();
List l = s.createQuery("from Root m left join m.detail d").list();
assertEquals( l.size(), 1 );
tx.commit();
s.close();
s = openSession();
tx = s.beginTransaction();
l = s.createQuery("from Master m left join fetch m.detail").list();
l = s.createQuery("from Root m left join fetch m.detail").list();
assertEquals( l.size(), 1 );
Master m = (Master) l.get(0);
assertEquals( "master 1", m.getDetail().getMaster().getName() );
assertTrue( m==m.getDetail().getMaster() );
Root m = (Root) l.get(0);
assertEquals( "root 1", m.getDetail().getRoot().getName() );
assertTrue( m==m.getDetail().getRoot() );
tx.commit();
s.close();
s = openSession();
tx = s.beginTransaction();
l = s.createQuery("from Master m join fetch m.detail").list();
l = s.createQuery("from Root m join fetch m.detail").list();
assertEquals( l.size(), 1 );
tx.commit();
s.close();
s = openSession();
tx = s.beginTransaction();
l = s.createQuery("from Detail d join fetch d.currentMaster.master").list();
l = s.createQuery("from Detail d join fetch d.currentRoot.root").list();
assertEquals( l.size(), 2 );
tx.commit();
s.close();
s = openSession();
tx = s.beginTransaction();
l = s.createQuery("from Detail d join fetch d.currentMaster.master m join fetch m.detail").list();
l = s.createQuery("from Detail d join fetch d.currentRoot.root m join fetch m.detail").list();
assertEquals( l.size(), 2 );
s.createQuery("delete from Detail").executeUpdate();
s.createQuery("delete from Master").executeUpdate();
s.createQuery("delete from Root").executeUpdate();
tx.commit();
s.close();

View File

@ -18,7 +18,7 @@
<hibernate-mapping package="org.hibernate.test.formulajoin">
<class name="Master" table="t_masters">
<class name="Root" table="t_roots">
<id name="id">
<generator class="increment"/>
@ -30,7 +30,7 @@
update="false"/>
<many-to-one name="detail"
property-ref="currentMaster"
property-ref="currentRoot"
insert="false"
update="false">
<column name="id"/>
@ -53,13 +53,13 @@
<property name="version" update="false">
<column name="version"
not-null="true"
unique-key="masterVersion"/>
unique-key="rootVersion"/>
</property>
<properties name="currentMaster">
<many-to-one name="master">
<column name="cur_master"
unique-key="masterVersion"
<properties name="currentRoot">
<many-to-one name="root">
<column name="cur_root"
unique-key="rootVersion"
not-null="true"/>
</many-to-one>
<property name="currentVersion"

View File

@ -4,15 +4,14 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
//$Id: Master.java 4602 2004-09-26 11:42:47Z oneovthafew $
package org.hibernate.test.formulajoin;
import java.io.Serializable;
/**
* @author Gavin King
*/
public class Master implements Serializable {
public class Root implements Serializable {
private Long id;
private String name;
private Detail detail;

View File

@ -21,45 +21,45 @@ public class DeleteQuerySubqueryReferencingTargetPropertyTest extends BaseEntity
@Override
protected Class<?>[] getAnnotatedClasses() {
return new Class<?>[] { Master.class, Detail.class };
return new Class<?>[] { Root.class, Detail.class };
}
@Test
public void testSubQueryReferencingTargetProperty() {
// prepare
doInJPA( this::entityManagerFactory, entityManager -> {
Master m1 = new Master();
Root m1 = new Root();
entityManager.persist( m1 );
Detail d11 = new Detail( m1 );
entityManager.persist( d11 );
Detail d12 = new Detail( m1 );
entityManager.persist( d12 );
Master m2 = new Master();
Root m2 = new Root();
entityManager.persist( m2 );
} );
doInJPA( this::entityManagerFactory, entityManager -> {
// depending on the generated ids above this delete removes all masters or nothing
// removal of all masters results in foreign key constraint violation
// removal of nothing is incorrect since 2nd master does not have any details
// depending on the generated ids above this delete removes all Roots or nothing
// removal of all Roots results in foreign key constraint violation
// removal of nothing is incorrect since 2nd Root does not have any details
// DO NOT CHANGE this query: it used to trigger a very specific bug caused
// by the alias not being added to the generated query
String d = "delete from Master m where not exists (select d from Detail d where d.master=m)";
String d = "delete from Root m where not exists (select d from Detail d where d.root=m)";
Query del = entityManager.createQuery( d );
del.executeUpdate();
// so check for exactly one master after deletion
// so check for exactly one Root after deletion
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery<Master> query = builder.createQuery( Master.class );
query.select( query.from( Master.class ) );
CriteriaQuery<Root> query = builder.createQuery( Root.class );
query.select( query.from( Root.class ) );
Assert.assertEquals( 1, entityManager.createQuery( query ).getResultList().size() );
} );
}
@Entity(name = "Master")
public static class Master {
@Entity(name = "Root")
public static class Root {
@Id
@GeneratedValue
private Integer id;
@ -72,10 +72,10 @@ public class DeleteQuerySubqueryReferencingTargetPropertyTest extends BaseEntity
private Integer id;
@ManyToOne(optional = false)
private Master master;
private Root root;
public Detail(Master master) {
this.master = master;
public Detail(Root root) {
this.root = root;
}
}
}

View File

@ -19,14 +19,14 @@ public class UpdateJoinedSubclassCorrelationTest extends BaseEntityManagerFuncti
@Override
protected Class<?>[] getAnnotatedClasses() {
return new Class<?>[] { Master.class, SubMaster.class, Detail.class };
return new Class<?>[] { Root.class, SubRoot.class, Detail.class };
}
@Test
public void testJoinedSubclassUpdateWithCorrelation() {
// prepare
doInJPA( this::entityManagerFactory, entityManager -> {
Master m1 = new SubMaster( 1, null );
Root m1 = new SubRoot( 1, null );
entityManager.persist( m1 );
Detail d11 = new Detail( 10, m1 );
entityManager.persist( d11 );
@ -35,40 +35,40 @@ public class UpdateJoinedSubclassCorrelationTest extends BaseEntityManagerFuncti
doInJPA( this::entityManagerFactory, entityManager -> {
// DO NOT CHANGE this query: it used to trigger a very specific bug caused
// by the root table alias being added to the generated subquery instead of the table name
String u = "update SubMaster m set name = (select 'test' from Detail d where d.master = m)";
String u = "update SubRoot m set name = (select 'test' from Detail d where d.root = m)";
Query updateQuery = entityManager.createQuery( u );
updateQuery.executeUpdate();
// so check if the name of the SubMaster has been correctly updated
// so check if the name of the SubRoot has been correctly updated
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery<Master> query = builder.createQuery( Master.class );
query.select( query.from( Master.class ) );
List<Master> masters = entityManager.createQuery( query ).getResultList();
Assert.assertEquals( 1, masters.size() );
Assert.assertEquals( "test", ((SubMaster) masters.get(0)).name );
CriteriaQuery<Root> query = builder.createQuery( Root.class );
query.select( query.from( Root.class ) );
List<Root> roots = entityManager.createQuery( query ).getResultList();
Assert.assertEquals( 1, roots.size() );
Assert.assertEquals( "test", ((SubRoot) roots.get(0)).name );
} );
}
@Inheritance(strategy = JOINED)
@Entity(name = "Master")
public static abstract class Master {
@Entity(name = "Root")
public static abstract class Root {
@Id
private Integer id;
public Master() { }
public Root() { }
public Master( Integer id ) {
public Root(Integer id ) {
this.id = id;
}
}
@Entity(name = "SubMaster")
public static class SubMaster extends Master {
@Entity(name = "SubRoot")
public static class SubRoot extends Root {
private String name;
public SubMaster() { }
public SubRoot() { }
public SubMaster( Integer id, String name ) {
public SubRoot(Integer id, String name ) {
super(id);
this.name = name;
}
@ -80,11 +80,11 @@ public class UpdateJoinedSubclassCorrelationTest extends BaseEntityManagerFuncti
private Integer id;
@ManyToOne(optional = false)
private Master master;
private Root root;
public Detail( Integer id, Master master ) {
public Detail( Integer id, Root root) {
this.id = id;
this.master = master;
this.root = root;
}
}
}

View File

@ -11,7 +11,7 @@
<hibernate-mapping default-lazy="false">
<class name="org.hibernate.test.legacy.ComponentNotNullMaster"> <!-- discriminator-value="A"> -->
<class name="org.hibernate.test.legacy.ComponentNotNullRoot"> <!-- discriminator-value="A"> -->
<id name="id" column="container_id">
<generator class="native" />
</id>
@ -28,10 +28,10 @@
</component>
</component>
<list name="components" lazy="true" table="CompNotNullMaster_Comps">
<list name="components" lazy="true" table="CompNotNullRoot_Comps">
<key column = "container_id"/>
<index column = "list_index"/>
<composite-element class="org.hibernate.test.legacy.ComponentNotNullMaster$ContainerInnerClass">
<composite-element class="org.hibernate.test.legacy.ComponentNotNullRoot$ContainerInnerClass">
<property name="name"/>
<property name="count" column="count_"/>
<many-to-one name="simple" not-null="true" cascade="save-update"/>
@ -40,15 +40,15 @@
</composite-element>
</list>
<list name="componentsImplicit" lazy="true" table="CompNotNullMaster_CompsImpl">
<list name="componentsImplicit" lazy="true" table="CompNotNullRoot_CompsImpl">
<key column = "container_id"/>
<index column = "list_index3"/>
<composite-element class="org.hibernate.test.legacy.ComponentNotNullMaster$ContainerInnerClass">
<composite-element class="org.hibernate.test.legacy.ComponentNotNullRoot$ContainerInnerClass">
<property name="name"/>
<property name="count" column="count_"/>
<many-to-one name="simple" cascade="save-update"/>
<many-to-one name="one" cascade="save-update"/>
<nested-composite-element name="nested" class="org.hibernate.test.legacy.ComponentNotNullMaster$ContainerInnerClass">
<nested-composite-element name="nested" class="org.hibernate.test.legacy.ComponentNotNullRoot$ContainerInnerClass">
<property name="nestedproperty" not-null="true"/>
</nested-composite-element>
</composite-element>

View File

@ -4,9 +4,8 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
//$Id: ComponentNotNullMaster.java 4599 2004-09-26 05:18:27Z oneovthafew $
package org.hibernate.test.legacy;
import java.util.List;
/**
@ -14,7 +13,7 @@ import java.util.List;
*
* @author Emmanuel Bernard
*/
public class ComponentNotNullMaster {
public class ComponentNotNullRoot {
private int id;
private String test;

View File

@ -13,7 +13,7 @@ import java.util.Set;
public class Detail implements Serializable {
private Master master;
private Root root;
private int i;
private Set details = new HashSet();
private int x;
@ -25,12 +25,12 @@ public class Detail implements Serializable {
this.x = x;
}
public Master getMaster() {
return master;
public Root getRoot() {
return root;
}
public void setMaster(Master master) {
this.master = master;
public void setRoot(Root root) {
this.root = root;
}
public int getI() {

View File

@ -47,7 +47,7 @@
<class name="org.hibernate.test.legacy.Outer" table="CID_OUT">
<composite-id name="id">
<key-many-to-one name="master">
<key-many-to-one name="root">
<column length="10" name="AKEY"/>
<column length="10" name="BKEY"/>
<column length="10" name="ONE"/>

View File

@ -34,9 +34,9 @@ public class Middle implements Serializable {
if (this == o) return true;
if (!(o instanceof Middle)) return false;
final Middle cidMaster = (Middle) o;
final Middle cidMiddle = (Middle) o;
if (id != null ? !id.equals(cidMaster.id) : cidMaster.id != null) return false;
if (id != null ? !id.equals(cidMiddle.id) : cidMiddle.id != null) return false;
return true;
}

View File

@ -43,11 +43,11 @@ public class MiddleKey implements Serializable {
if (this == o) return true;
if (!(o instanceof MiddleKey)) return false;
final MiddleKey cidMasterID = (MiddleKey) o;
final MiddleKey cidMiddleKey = (MiddleKey) o;
if (one != null ? !one.equals(cidMasterID.one) : cidMasterID.one != null) return false;
if (sup != null ? !sup.equals(cidMasterID.sup) : cidMasterID.sup != null) return false;
if (two != null ? !two.equals(cidMasterID.two) : cidMasterID.two != null) return false;
if (one != null ? !one.equals(cidMiddleKey.one) : cidMiddleKey.one != null) return false;
if (sup != null ? !sup.equals(cidMiddleKey.sup) : cidMiddleKey.sup != null) return false;
if (two != null ? !two.equals(cidMiddleKey.two) : cidMiddleKey.two != null) return false;
return true;
}

View File

@ -11,15 +11,15 @@ import java.io.Serializable;
* @author Stefano Travelli
*/
public class OuterKey implements Serializable {
private Middle master;
private Middle root;
private String detailId;
public Middle getMaster() {
return master;
public Middle getRoot() {
return root;
}
public void setMaster(Middle master) {
this.master = master;
public void setRoot(Middle root) {
this.root = root;
}
public String getDetailId() {
@ -37,14 +37,14 @@ public class OuterKey implements Serializable {
final OuterKey cidDetailID = (OuterKey) o;
if (detailId != null ? !detailId.equals(cidDetailID.detailId) : cidDetailID.detailId != null) return false;
if (master != null ? !master.equals(cidDetailID.master) : cidDetailID.master != null) return false;
if ( root != null ? !root.equals(cidDetailID.root ) : cidDetailID.root != null) return false;
return true;
}
public int hashCode() {
int result;
result = (master != null ? master.hashCode() : 0);
result = ( root != null ? root.hashCode() : 0);
result = 29 * result + (detailId != null ? detailId.hashCode() : 0);
return result;
}

View File

@ -4,9 +4,8 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
//$Id: Master.java 4599 2004-09-26 05:18:27Z oneovthafew $
package org.hibernate.test.legacy;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Collection;
@ -14,21 +13,21 @@ import java.util.Date;
import java.util.HashSet;
import java.util.Set;
public class Master implements Serializable, Named {
public class Root implements Serializable, Named {
private Long id;
private Master otherMaster;
private Root otherRoot;
private Set details = new HashSet();
private Set moreDetails = new HashSet();
private Set incoming = new HashSet();
private Set outgoing = new HashSet();
private String name="master";
private String name="root";
private Date stamp;
private int version;
private BigDecimal bigDecimal = new BigDecimal("1234.123");
private int x;
private Collection allDetails;
public Master() {
public Root() {
}
public Long getId() {
@ -63,19 +62,19 @@ public class Master implements Serializable, Named {
details.remove(d);
}
public void addIncoming(Master m) {
public void addIncoming(Root m) {
incoming.add(m);
}
public void removeIncoming(Master m) {
public void removeIncoming(Root m) {
incoming.remove(m);
}
public void addOutgoing(Master m) {
public void addOutgoing(Root m) {
outgoing.add(m);
}
public void removeOutgoing(Master m) {
public void removeOutgoing(Root m) {
outgoing.remove(m);
}
@ -130,15 +129,15 @@ public class Master implements Serializable, Named {
/**
* @return
*/
public Master getOtherMaster() {
return otherMaster;
public Root getOtherRoot() {
return otherRoot;
}
/**
* @param master
* @param root
*/
public void setOtherMaster(Master master) {
otherMaster = master;
public void setOtherRoot(Root root) {
otherRoot = root;
}
/**

View File

@ -11,9 +11,9 @@
<hibernate-mapping default-lazy="false">
<class name="org.hibernate.test.legacy.Master" table="`master`">
<class name="org.hibernate.test.legacy.Root" table="`root`">
<meta attribute="foo">foo</meta>
<id name="id" column="master_key_column" type="long">
<id name="id" column="root_key_column" type="long">
<generator class="native"/>
</id>
<version name="version" access="field"/>
@ -26,24 +26,24 @@
<property name="x"/>
<property name="bigDecimal" column="big_dec" precision="7" scale="3"/>
<set name="details" inverse="true" lazy="true" order-by="i asc">
<key column="master_key"/>
<key column="root_key"/>
<one-to-many class="org.hibernate.test.legacy.Detail"/>
</set>
<set name="moreDetails" cascade="all" lazy="true" order-by="i desc">
<key column="more_master_key"/>
<key column="more_root_key"/>
<one-to-many class="org.hibernate.test.legacy.Detail"/>
</set>
<set name="incoming" lazy="true" table="mtm">
<key foreign-key="AA" column="outgoingabcdef"/>
<many-to-many class="org.hibernate.test.legacy.Master" foreign-key="BB">
<many-to-many class="org.hibernate.test.legacy.Root" foreign-key="BB">
<column name="incomingabcdef" index="IBB"/>
</many-to-many>
</set>
<set name="outgoing" lazy="true" table="mtm" inverse="true">
<key column="incomingabcdef"/>
<many-to-many class="org.hibernate.test.legacy.Master" column="outgoingabcdef"/>
<many-to-many class="org.hibernate.test.legacy.Root" column="outgoingabcdef"/>
</set>
<many-to-one name="otherMaster"/>
<many-to-one name="otherRoot"/>
<!--query-list name="allDetails" query-ref="all_details"/-->
</class>
@ -57,8 +57,8 @@
<property name="i">
<column name="i" unique-key="uk" not-null="true"/>
</property>
<many-to-one name="master" foreign-key="CC"> <!--not-null="true"-->
<column name="master_key" unique-key="uk" not-null="true"/>
<many-to-one name="root" foreign-key="CC"> <!--not-null="true"-->
<column name="root_key" unique-key="uk" not-null="true"/>
</many-to-one>
<!-- <cache timeout="10000" type="readwrite"/> -->
<set name="subDetails" lazy="true" cascade="all">

View File

@ -6,6 +6,7 @@
*/
package org.hibernate.test.stream.basic;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Stream;
import javax.persistence.Entity;
import javax.persistence.Id;
@ -25,6 +26,7 @@ import org.junit.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.hibernate.testing.junit4.ExtraAssertions.assertTyping;
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
@ -123,6 +125,53 @@ public class BasicStreamTest extends BaseNonConfigCoreFunctionalTestCase {
} );
}
@Test
public void basicStreamTestWithExplicitOnClose() {
Session session = openSession();
session.getTransaction().begin();
AtomicInteger onCloseCount = new AtomicInteger();
// mainly we want to make sure that closing the Stream releases the ScrollableResults too
assertThat( ( (SessionImplementor) session ).getJdbcCoordinator()
.getLogicalConnection()
.getResourceRegistry()
.hasRegisteredResources(), is( false ) );
assertThat( onCloseCount.get(), equalTo( 0 ) );
final Stream<MyEntity> stream = session.createQuery( "from MyEntity", MyEntity.class ).stream().onClose(
onCloseCount::incrementAndGet );
assertThat( ( (SessionImplementor) session ).getJdbcCoordinator()
.getLogicalConnection()
.getResourceRegistry()
.hasRegisteredResources(), is( true ) );
assertThat( onCloseCount.get(), equalTo( 0 ) );
stream.forEach( System.out::println );
assertThat( ( (SessionImplementor) session ).getJdbcCoordinator()
.getLogicalConnection()
.getResourceRegistry()
.hasRegisteredResources(), is( false ) );
assertThat( onCloseCount.get(), equalTo( 1 ) );
stream.close();
assertThat( ( (SessionImplementor) session ).getJdbcCoordinator()
.getLogicalConnection()
.getResourceRegistry()
.hasRegisteredResources(), is( false ) );
assertThat( onCloseCount.get(), equalTo( 1 ) );
session.getTransaction().commit();
session.close();
}
@Entity(name = "MyEntity")
@Table(name="MyEntity")
public static class MyEntity {

View File

@ -8,7 +8,12 @@ package org.hibernate.test.stream.basic;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@ -28,6 +33,7 @@ import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hibernate.testing.junit4.ExtraAssertions.assertTyping;
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
import static org.junit.Assert.assertEquals;
@ -78,8 +84,8 @@ public class JpaStreamTest extends BaseNonConfigCoreFunctionalTestCase {
}
@Test
@TestForIssue( jiraKey = "HHH-13872")
@RequiresDialect(H2Dialect.class)
@TestForIssue( jiraKey = {"HHH-13872", "HHH-14449"})
public void testStreamCloseOnTerminalOperation() {
doInHibernate( this::sessionFactory, session -> {
session.createQuery( "delete from MyEntity" ).executeUpdate();
@ -92,10 +98,116 @@ public class JpaStreamTest extends BaseNonConfigCoreFunctionalTestCase {
}
} );
Runnable noOp = () -> {
// do nothing
};
// run without onClose callbacks
this.runTerminalOperationTests(noOp, Collections.emptyList(), noOp, false, false);
AtomicInteger onClose1Count = new AtomicInteger();
AtomicInteger onClose2Count = new AtomicInteger();
AtomicInteger onClose3Count = new AtomicInteger();
// run with chained onClose callbacks
this.runTerminalOperationTests(
() -> {
// prepare
onClose1Count.set( 0 );
onClose2Count.set( 0 );
onClose3Count.set( 0 );
},
Arrays.asList(
onClose1Count::incrementAndGet, // onClose1 logic
onClose2Count::incrementAndGet, // onClose2 logic
onClose3Count::incrementAndGet // onClose3 logic
),
() -> {
// assertion
assertThat( onClose1Count ).hasValue( 1 );
assertThat( onClose2Count ).hasValue( 1 );
assertThat( onClose3Count ).hasValue( 1 );
},
false, // no flatMap before onClose
false // no flatMap after onClose
);
this.runTerminalOperationTests(
() -> {
// prepare
onClose1Count.set( 0 );
onClose2Count.set( 0 );
onClose3Count.set( 0 );
},
Arrays.asList(
onClose1Count::incrementAndGet, // onClose1 logic
onClose2Count::incrementAndGet, // onClose2 logic
onClose3Count::incrementAndGet // onClose3 logic
),
() -> {
// assertion
assertThat( onClose1Count ).hasValue( 1 );
assertThat( onClose2Count ).hasValue( 1 );
assertThat( onClose3Count ).hasValue( 1 );
},
true, // run a flatMap operation before onClose
false // no flatMap after onClose
);
this.runTerminalOperationTests(
() -> {
// prepare
onClose1Count.set( 0 );
onClose2Count.set( 0 );
onClose3Count.set( 0 );
},
Arrays.asList(
onClose1Count::incrementAndGet, // onClose1 logic
onClose2Count::incrementAndGet, // onClose2 logic
onClose3Count::incrementAndGet // onClose3 logic
),
() -> {
// assertion
assertThat( onClose1Count ).hasValue( 1 );
assertThat( onClose2Count ).hasValue( 1 );
assertThat( onClose3Count ).hasValue( 1 );
},
false, // no flatMap before onClose
true // run a flatMap operation after onClose
);
this.runTerminalOperationTests(
() -> {
// prepare
onClose1Count.set( 0 );
onClose2Count.set( 0 );
onClose3Count.set( 0 );
},
Arrays.asList(
onClose1Count::incrementAndGet, // onClose1 logic
onClose2Count::incrementAndGet, // onClose2 logic
onClose3Count::incrementAndGet // onClose3 logic
),
() -> {
// assertion
assertThat( onClose1Count ).hasValue( 1 );
assertThat( onClose2Count ).hasValue( 1 );
assertThat( onClose3Count ).hasValue( 1 );
},
true, // run a flatMap operation before onClose
true // run a flatMap operation after onClose
);
}
private void runTerminalOperationTests(
Runnable prepare, List<Runnable> onCloseCallbacks, Runnable onCloseAssertion,
boolean flatMapBefore, boolean flatMapAfter) {
// collect as list
doInHibernate( this::sessionFactory, session -> {
Stream<MyEntity> stream = session
.createQuery( "SELECT me FROM MyEntity me" )
.getResultStream();
Stream<MyEntity> stream = getMyEntityStream(prepare, session, onCloseCallbacks, flatMapBefore, flatMapAfter);
ResourceRegistry resourceRegistry = resourceRegistry(session);
assertTrue( resourceRegistry.hasRegisteredResources() );
@ -104,12 +216,90 @@ public class JpaStreamTest extends BaseNonConfigCoreFunctionalTestCase {
assertEquals(10, entities.size());
assertFalse( resourceRegistry.hasRegisteredResources() );
onCloseAssertion.run();
} );
// forEach (TestCase based on attachment EntityManagerIllustrationTest.java in HHH-14449)
doInHibernate( this::sessionFactory, session -> {
Stream<MyEntity> stream = session
.createQuery( "SELECT me FROM MyEntity me" )
.getResultStream();
Stream<MyEntity> stream = getMyEntityStream(prepare, session, onCloseCallbacks, flatMapBefore, flatMapAfter);
ResourceRegistry resourceRegistry = resourceRegistry(session);
assertTrue( resourceRegistry.hasRegisteredResources() );
AtomicInteger count = new AtomicInteger();
stream.forEach(myEntity -> count.incrementAndGet());
assertEquals(10, count.get());
assertFalse( resourceRegistry.hasRegisteredResources() );
onCloseAssertion.run();
} );
// filter (always true) + forEach (TestCase based on attachment EntityManagerIllustrationTest.java in HHH-14449)
doInHibernate( this::sessionFactory, session -> {
Stream<MyEntity> stream = getMyEntityStream(prepare, session, onCloseCallbacks, flatMapBefore, flatMapAfter);
ResourceRegistry resourceRegistry = resourceRegistry(session);
assertTrue( resourceRegistry.hasRegisteredResources() );
AtomicInteger count = new AtomicInteger();
stream.filter(Objects::nonNull).forEach(myEntity -> count.incrementAndGet());
assertEquals(10, count.get());
assertFalse( resourceRegistry.hasRegisteredResources() );
onCloseAssertion.run();
} );
// filter (partially true) + forEach (TestCase based on attachment EntityManagerIllustrationTest.java in HHH-14449)
doInHibernate( this::sessionFactory, session -> {
Stream<MyEntity> stream = getMyEntityStream(prepare, session, onCloseCallbacks, flatMapBefore, flatMapAfter);
ResourceRegistry resourceRegistry = resourceRegistry(session);
assertTrue( resourceRegistry.hasRegisteredResources() );
AtomicInteger count = new AtomicInteger();
stream.filter(entity -> entity.getId() % 2 == 0).forEach(myEntity -> count.incrementAndGet());
assertEquals(5, count.get());
assertFalse( resourceRegistry.hasRegisteredResources() );
onCloseAssertion.run();
} );
// multiple chained operations (TestCase based on attachment EntityManagerIllustrationTest.java in HHH-14449)
doInHibernate( this::sessionFactory, session -> {
Stream<MyEntity> stream = getMyEntityStream(prepare, session, onCloseCallbacks, flatMapBefore, flatMapAfter);
ResourceRegistry resourceRegistry = resourceRegistry(session);
assertTrue( resourceRegistry.hasRegisteredResources() );
AtomicInteger count = new AtomicInteger();
stream
.filter(Objects::nonNull)
.map(Optional::of)
.filter(Optional::isPresent)
.map(Optional::get)
.forEach(myEntity -> count.incrementAndGet());
assertEquals(10, count.get());
assertFalse( resourceRegistry.hasRegisteredResources() );
onCloseAssertion.run();
} );
// mapToInt
doInHibernate( this::sessionFactory, session -> {
Stream<MyEntity> stream = getMyEntityStream(prepare, session, onCloseCallbacks, flatMapBefore, flatMapAfter);
ResourceRegistry resourceRegistry = resourceRegistry(session);
assertTrue( resourceRegistry.hasRegisteredResources() );
@ -118,12 +308,13 @@ public class JpaStreamTest extends BaseNonConfigCoreFunctionalTestCase {
assertEquals(55, sum);
assertFalse( resourceRegistry.hasRegisteredResources() );
onCloseAssertion.run();
} );
// mapToLong
doInHibernate( this::sessionFactory, session -> {
Stream<MyEntity> stream = session
.createQuery( "SELECT me FROM MyEntity me" )
.getResultStream();
Stream<MyEntity> stream = getMyEntityStream(prepare, session, onCloseCallbacks, flatMapBefore, flatMapAfter);
ResourceRegistry resourceRegistry = resourceRegistry(session);
assertTrue( resourceRegistry.hasRegisteredResources() );
@ -132,12 +323,13 @@ public class JpaStreamTest extends BaseNonConfigCoreFunctionalTestCase {
assertEquals(10, result);
assertFalse( resourceRegistry.hasRegisteredResources() );
onCloseAssertion.run();
} );
// mapToDouble
doInHibernate( this::sessionFactory, session -> {
Stream<MyEntity> stream = session
.createQuery( "SELECT me FROM MyEntity me" )
.getResultStream();
Stream<MyEntity> stream = getMyEntityStream(prepare, session, onCloseCallbacks, flatMapBefore, flatMapAfter);
ResourceRegistry resourceRegistry = resourceRegistry(session);
assertTrue( resourceRegistry.hasRegisteredResources() );
@ -146,14 +338,14 @@ public class JpaStreamTest extends BaseNonConfigCoreFunctionalTestCase {
assertEquals(1, result, 0.1);
assertFalse( resourceRegistry.hasRegisteredResources() );
onCloseAssertion.run();
} );
//Test call close explicitly
doInHibernate( this::sessionFactory, session -> {
try (Stream<Long> stream = session
.createQuery( "SELECT me.id FROM MyEntity me" )
.getResultStream()) {
try (Stream<Long> stream = getLongStream(prepare, session, onCloseCallbacks, flatMapBefore, flatMapAfter)) {
ResourceRegistry resourceRegistry = resourceRegistry( session );
assertTrue( resourceRegistry.hasRegisteredResources() );
@ -164,6 +356,8 @@ public class JpaStreamTest extends BaseNonConfigCoreFunctionalTestCase {
assertEquals( 10, result[4] );
assertFalse( resourceRegistry.hasRegisteredResources() );
onCloseAssertion.run();
}
} );
@ -172,9 +366,7 @@ public class JpaStreamTest extends BaseNonConfigCoreFunctionalTestCase {
Method takeWhileMethod = ReflectHelper.getMethod( Stream.class, "takeWhile", Predicate.class );
if ( takeWhileMethod != null ) {
try (Stream<Long> stream = session
.createQuery( "SELECT me.id FROM MyEntity me" )
.getResultStream()) {
try (Stream<Long> stream = getLongStream(prepare, session, onCloseCallbacks, flatMapBefore, flatMapAfter)) {
ResourceRegistry resourceRegistry = resourceRegistry( session );
assertTrue( resourceRegistry.hasRegisteredResources() );
@ -191,6 +383,8 @@ public class JpaStreamTest extends BaseNonConfigCoreFunctionalTestCase {
assertTrue( result.contains( 5 ) );
assertFalse( resourceRegistry.hasRegisteredResources() );
onCloseAssertion.run();
}
catch (IllegalAccessException | InvocationTargetException e) {
fail( "Could not execute takeWhile because of " + e.getMessage() );
@ -202,9 +396,7 @@ public class JpaStreamTest extends BaseNonConfigCoreFunctionalTestCase {
Method dropWhileMethod = ReflectHelper.getMethod( Stream.class, "dropWhile", Predicate.class );
if ( dropWhileMethod != null ) {
try (Stream<Long> stream = session
.createQuery( "SELECT me.id FROM MyEntity me" )
.getResultStream()) {
try (Stream<Long> stream = getLongStream(prepare, session, onCloseCallbacks, flatMapBefore, flatMapAfter)) {
ResourceRegistry resourceRegistry = resourceRegistry( session );
assertTrue( resourceRegistry.hasRegisteredResources() );
@ -221,6 +413,8 @@ public class JpaStreamTest extends BaseNonConfigCoreFunctionalTestCase {
assertTrue( result.contains( 10 ) );
assertFalse( resourceRegistry.hasRegisteredResources() );
onCloseAssertion.run();
}
catch (IllegalAccessException | InvocationTargetException e) {
fail( "Could not execute takeWhile because of " + e.getMessage() );
@ -229,6 +423,62 @@ public class JpaStreamTest extends BaseNonConfigCoreFunctionalTestCase {
} );
}
private static Stream<MyEntity> getMyEntityStream(
Runnable prepare,
Session session,
List<Runnable> onCloseCallbacks,
boolean flatMapBefore,
boolean flatMapAfter) {
return getStream(
prepare,
session,
"SELECT me FROM MyEntity me",
onCloseCallbacks,
flatMapBefore,
flatMapAfter
);
}
private static Stream<Long> getLongStream(
Runnable prepare,
Session session,
List<Runnable> onCloseCallbacks,
boolean flatMapBefore,
boolean flatMapAfter) {
return getStream(
prepare,
session,
"SELECT me.id FROM MyEntity me",
onCloseCallbacks,
flatMapBefore,
flatMapAfter
);
}
@SuppressWarnings("unchecked")
private static <T> Stream<T> getStream(
Runnable prepare, Session session, String queryString,
List<Runnable> onCloseCallbacks, boolean flatMapBefore, boolean flatMapAfter) {
prepare.run();
Stream<T> stream = session.createQuery( queryString ).getResultStream();
if ( flatMapBefore ) {
stream = stream.flatMap( Stream::of );
}
for ( Runnable callback : onCloseCallbacks ) {
stream = stream.onClose( callback );
}
if ( flatMapAfter ) {
stream = stream.flatMap( Stream::of );
}
return stream;
}
private ResourceRegistry resourceRegistry(Session session) {
SharedSessionContractImplementor sharedSessionContractImplementor = (SharedSessionContractImplementor) session;
JdbcCoordinator jdbcCoordinator = sharedSessionContractImplementor.getJdbcCoordinator();

View File

@ -676,16 +676,16 @@ public class HqlParserTest {
parse( "from fo in class org.hibernate.test.Fo where fo.id.string like 'an instance of fo'" );
parse( "from org.hibernate.test.Inner" );
parse( "from org.hibernate.test.Outer o where o.id.detailId = ?" );
parse( "from org.hibernate.test.Outer o where o.id.master.id.sup.dudu is not null" );
parse( "from org.hibernate.test.Outer o where o.id.master.id.sup.id.akey is not null" );
parse( "select o.id.master.id.sup.dudu from org.hibernate.test.Outer o where o.id.master.id.sup.dudu is not null" );
parse( "select o.id.master.id.sup.id.akey from org.hibernate.test.Outer o where o.id.master.id.sup.id.akey is not null" );
parse( "from org.hibernate.test.Outer o where o.id.master.bla = ''" );
parse( "from org.hibernate.test.Outer o where o.id.master.id.one = ''" );
parse( "from org.hibernate.test.Inner inn where inn.id.bkey is not null and inn.backOut.id.master.id.sup.id.akey > 'a'" );
parse( "from org.hibernate.test.Outer as o left join o.id.master m left join m.id.sup where o.bubu is not null" );
parse( "from org.hibernate.test.Outer as o left join o.id.master.id.sup s where o.bubu is not null" );
parse( "from org.hibernate.test.Outer as o left join o.id.master m left join o.id.master.id.sup s where o.bubu is not null" );
parse( "from org.hibernate.test.Outer o where o.id.main.id.sup.dudu is not null" );
parse( "from org.hibernate.test.Outer o where o.id.main.id.sup.id.akey is not null" );
parse( "select o.id.main.id.sup.dudu from org.hibernate.test.Outer o where o.id.main.id.sup.dudu is not null" );
parse( "select o.id.main.id.sup.id.akey from org.hibernate.test.Outer o where o.id.main.id.sup.id.akey is not null" );
parse( "from org.hibernate.test.Outer o where o.id.main.bla = ''" );
parse( "from org.hibernate.test.Outer o where o.id.main.id.one = ''" );
parse( "from org.hibernate.test.Inner inn where inn.id.bkey is not null and inn.backOut.id.main.id.sup.id.akey > 'a'" );
parse( "from org.hibernate.test.Outer as o left join o.id.main m left join m.id.sup where o.bubu is not null" );
parse( "from org.hibernate.test.Outer as o left join o.id.main.id.sup s where o.bubu is not null" );
parse( "from org.hibernate.test.Outer as o left join o.id.main m left join o.id.main.id.sup s where o.bubu is not null" );
parse( "select fum1.fo from fum1 in class org.hibernate.test.Fum where fum1.fo.fum is not null" );
parse( "from fum1 in class org.hibernate.test.Fum where fum1.fo.fum is not null order by fum1.fo.fum" );
parse( "select elements(fum1.friends) from fum1 in class org.hibernate.test.Fum" );
@ -696,7 +696,7 @@ public class HqlParserTest {
parse( "from org.hibernate.test.Up up order by up.id2 asc" );
parse( "from org.hibernate.test.Down down" );
parse( "from org.hibernate.test.Up up" );
parse( "from m in class org.hibernate.test.Master" );
parse( "from m in class org.hibernate.test.Root" );
parse( "from s in class org.hibernate.test.Several" );
parse( "from s in class org.hibernate.test.Single" );
parse( "\n" +
@ -915,11 +915,11 @@ public class HqlParserTest {
parse( "from bar in class org.hibernate.test.Bar, foo in elements(bar.baz.fooSet)" );
parse( "from one in class org.hibernate.test.One, many in elements(one.manies) where one.id = 1 and many.id = 1" );
parse( "from org.hibernate.test.Inner _inner join _inner.middles middle" );
parse( "FROM m IN CLASS org.hibernate.test.Master WHERE NOT EXISTS ( FROM d IN elements(m.details) WHERE NOT d.i=5 )" );
parse( "FROM m IN CLASS org.hibernate.test.Master WHERE NOT 5 IN ( SELECT d.i FROM d IN elements(m.details) )" );
parse( "SELECT m FROM m IN CLASS org.hibernate.test.Master, d IN elements(m.details) WHERE d.i=5" );
parse( "SELECT m FROM m IN CLASS org.hibernate.test.Master, d IN elements(m.details) WHERE d.i=5" );
parse( "SELECT m.id FROM m IN CLASS org.hibernate.test.Master, d IN elements(m.details) WHERE d.i=5" );
parse( "FROM m IN CLASS org.hibernate.test.Root WHERE NOT EXISTS ( FROM d IN elements(m.details) WHERE NOT d.i=5 )" );
parse( "FROM m IN CLASS org.hibernate.test.Root WHERE NOT 5 IN ( SELECT d.i FROM d IN elements(m.details) )" );
parse( "SELECT m FROM m IN CLASS org.hibernate.test.Root, d IN elements(m.details) WHERE d.i=5" );
parse( "SELECT m FROM m IN CLASS org.hibernate.test.Root, d IN elements(m.details) WHERE d.i=5" );
parse( "SELECT m.id FROM m IN CLASS org.hibernate.test.Root, d IN elements(m.details) WHERE d.i=5" );
// I'm not sure about these... [jsd]
// parse("select bar.string, foo.string from bar in class org.hibernate.test.Bar inner join bar.baz as baz inner join elements(baz.fooSet) as foo where baz.name = 'name'");
// parse("select bar.string, foo.string from bar in class org.hibernate.test.Bar, bar.baz as baz, elements(baz.fooSet) as foo where baz.name = 'name'");

View File

@ -26,7 +26,7 @@ public class ComponentNotNullTest extends LegacyTestCase {
@Override
public String[] getMappings() {
return new String[] {
"legacy/ComponentNotNullMaster.hbm.xml",
"legacy/ComponentNotNullRoot.hbm.xml",
"legacy/One.hbm.xml",
"legacy/Many.hbm.xml",
"legacy/Simple.hbm.xml" };
@ -45,16 +45,16 @@ public class ComponentNotNullTest extends LegacyTestCase {
//
Session s = openSession();
Transaction t = s.beginTransaction();
ComponentNotNullMaster master = new ComponentNotNullMaster();
ComponentNotNullRoot root = new ComponentNotNullRoot();
ComponentNotNull nullable = new ComponentNotNull();
ComponentNotNull supercomp = new ComponentNotNull();
ComponentNotNull subcomp = new ComponentNotNull();
master.setNullable(nullable);
root.setNullable(nullable);
subcomp.setProp1Subcomp("test");
supercomp.setSubcomp(subcomp);
master.setSupercomp(supercomp);
s.save(master);
root.setSupercomp(supercomp);
s.save(root);
t.commit();
s.close();
@ -63,20 +63,20 @@ public class ComponentNotNullTest extends LegacyTestCase {
s = openSession();
t = s.beginTransaction();
master = new ComponentNotNullMaster();
root = new ComponentNotNullRoot();
nullable = new ComponentNotNull();
supercomp = new ComponentNotNull();
subcomp = new ComponentNotNull();
master.setNullable(nullable);
root.setNullable(nullable);
// do not set property
//subcomp.setProp1Subcomp("test");
supercomp.setSubcomp(subcomp);
master.setSupercomp(supercomp);
root.setSupercomp(supercomp);
try {
s.save(master);
s.save(root);
t.commit();
fail("Inserting not-null null property should fail");
} catch (PropertyValueException e) {
@ -90,20 +90,20 @@ public class ComponentNotNullTest extends LegacyTestCase {
s = openSession();
t = s.beginTransaction();
master = new ComponentNotNullMaster();
root = new ComponentNotNullRoot();
nullable = new ComponentNotNull();
supercomp = new ComponentNotNull();
subcomp = new ComponentNotNull();
master.setNullable(nullable);
// do not set supercomp for master
root.setNullable(nullable);
// do not set supercomp for root
//subcomp.setProp1Subcomp("test");
//supercomp.setSubcomp(subcomp);
//master.setSupercomp(supercomp);
//root.setSupercomp(supercomp);
try {
s.save(master);
s.save(root);
t.commit();
fail("Inserting not-null null property should fail");
} catch (PropertyValueException e) {
@ -118,23 +118,23 @@ public class ComponentNotNullTest extends LegacyTestCase {
//composite-element nullable
Session s = openSession();
Transaction t = s.beginTransaction();
ComponentNotNullMaster master = new ComponentNotNullMaster();
ComponentNotNullRoot root = new ComponentNotNullRoot();
ComponentNotNull nullable = new ComponentNotNull();
ComponentNotNull supercomp = new ComponentNotNull();
ComponentNotNull subcomp = new ComponentNotNull();
master.setNullable(nullable);
root.setNullable(nullable);
subcomp.setProp1Subcomp("test");
supercomp.setSubcomp(subcomp);
master.setSupercomp(supercomp);
root.setSupercomp(supercomp);
master.setComponents(new ArrayList());
ComponentNotNullMaster.ContainerInnerClass cc =
new ComponentNotNullMaster.ContainerInnerClass();
master.getComponents().add(cc);
root.setComponents(new ArrayList());
ComponentNotNullRoot.ContainerInnerClass cc =
new ComponentNotNullRoot.ContainerInnerClass();
root.getComponents().add(cc);
try {
s.save(master);
s.save(root);
t.commit();
fail("Inserting not-null many-to-one should fail");
} catch (PropertyValueException e) {
@ -148,26 +148,26 @@ public class ComponentNotNullTest extends LegacyTestCase {
s = openSession();
t = s.beginTransaction();
master = new ComponentNotNullMaster();
root = new ComponentNotNullRoot();
nullable = new ComponentNotNull();
supercomp = new ComponentNotNull();
subcomp = new ComponentNotNull();
master.setNullable(nullable);
root.setNullable(nullable);
subcomp.setProp1Subcomp("test");
supercomp.setSubcomp(subcomp);
master.setSupercomp(supercomp);
root.setSupercomp(supercomp);
master.setComponentsImplicit(new ArrayList());
ComponentNotNullMaster.ContainerInnerClass nestedCc =
new ComponentNotNullMaster.ContainerInnerClass();
root.setComponentsImplicit(new ArrayList());
ComponentNotNullRoot.ContainerInnerClass nestedCc =
new ComponentNotNullRoot.ContainerInnerClass();
cc =
new ComponentNotNullMaster.ContainerInnerClass();
new ComponentNotNullRoot.ContainerInnerClass();
cc.setNested(nestedCc);
master.getComponentsImplicit().add(cc);
root.getComponentsImplicit().add(cc);
try {
s.save(master);
s.save(root);
t.commit();
fail("Inserting not-null null property should fail");
} catch (PropertyValueException e) {
@ -181,26 +181,26 @@ public class ComponentNotNullTest extends LegacyTestCase {
s = openSession();
t = s.beginTransaction();
master = new ComponentNotNullMaster();
root = new ComponentNotNullRoot();
nullable = new ComponentNotNull();
supercomp = new ComponentNotNull();
subcomp = new ComponentNotNull();
master.setNullable(nullable);
root.setNullable(nullable);
subcomp.setProp1Subcomp("test");
supercomp.setSubcomp(subcomp);
master.setSupercomp(supercomp);
root.setSupercomp(supercomp);
master.setComponentsImplicit(new ArrayList());
root.setComponentsImplicit(new ArrayList());
nestedCc =
new ComponentNotNullMaster.ContainerInnerClass();
new ComponentNotNullRoot.ContainerInnerClass();
cc =
new ComponentNotNullMaster.ContainerInnerClass();
new ComponentNotNullRoot.ContainerInnerClass();
cc.setNested(nestedCc);
nestedCc.setNestedproperty("test");
master.getComponentsImplicit().add(cc);
root.getComponentsImplicit().add(cc);
s.save(master);
s.save(root);
t.commit();
s.close();
}

View File

@ -15,7 +15,7 @@ public class DetailSuperclass {
private long id;
private List<Master> masters;
private List<Root> roots;
public DetailSuperclass() {
@ -29,12 +29,12 @@ public class DetailSuperclass {
this.id = id;
}
public List<Master> getMasters() {
return masters;
public List<Root> getRoots() {
return roots;
}
public void setMasters(List<Master> masters) {
this.masters = masters;
public void setRoots(List<Root> roots) {
this.roots = roots;
}
}

View File

@ -30,7 +30,7 @@ public class ManyToManyInverseToSuperclassTest extends BaseEnversJPAFunctionalTe
public void initData() {
EntityManager em = getEntityManager();
Master m1 = new Master();
Root m1 = new Root();
DetailSubclass det1 = new DetailSubclass2();
// Revision 1
@ -38,66 +38,24 @@ public class ManyToManyInverseToSuperclassTest extends BaseEnversJPAFunctionalTe
det1.setStr2( "detail 1" );
m1.setStr( "master" );
m1.setStr( "root" );
m1.setItems( new ArrayList<DetailSubclass>() );
m1.getItems().add( det1 );
det1.setMasters( new ArrayList<Master>() );
det1.getMasters().add( m1 );
det1.setRoots( new ArrayList<Root>() );
det1.getRoots().add( m1 );
em.persist( m1 );
em.getTransaction().commit();
m1_id = m1.getId();
// Revision 2
// em.getTransaction().begin();
//
// m1 = em.find(Master.class, m1_id);
//
// det2.setStr2("detail 2");
// det2.setParent(m1);
// m1.getItems().add(det2);
// em.getTransaction().commit();
//
// // Revision 3
// em.getTransaction().begin();
//
// m1 = em.find(Master.class, m1_id);
// m1.setStr("new master");
//
// det1 = m1.getItems().get(0);
// det1.setStr2("new detail");
// DetailSubclass det3 = new DetailSubclass2();
// det3.setStr2("detail 3");
// det3.setParent(m1);
//
// m1.getItems().get(1).setParent(null);
// // m1.getItems().remove(1);
// m1.getItems().add(det3);
//
// em.persist(m1);
// em.getTransaction().commit();
//
// // Revision 4
// em.getTransaction().begin();
//
// m1 = em.find(Master.class, m1_id);
//
// det1 = m1.getItems().get(0);
// det1.setParent(null);
// // m1.getItems().remove(det1);
//
// em.persist(m1);
// em.getTransaction().commit();
}
@Test
public void testHistoryExists() {
Master rev1_1 = getAuditReader().find( Master.class, m1_id, 1 );
Master rev1_2 = getAuditReader().find( Master.class, m1_id, 2 );
Master rev1_3 = getAuditReader().find( Master.class, m1_id, 3 );
Master rev1_4 = getAuditReader().find( Master.class, m1_id, 4 );
Root rev1_1 = getAuditReader().find( Root.class, m1_id, 1 );
Root rev1_2 = getAuditReader().find( Root.class, m1_id, 2 );
Root rev1_3 = getAuditReader().find( Root.class, m1_id, 3 );
Root rev1_4 = getAuditReader().find( Root.class, m1_id, 4 );
assert (rev1_1 != null);
assert (rev1_2 != null);

View File

@ -11,7 +11,7 @@ import java.util.List;
import org.hibernate.envers.Audited;
@Audited
public class Master {
public class Root {
private long id;
@ -19,7 +19,7 @@ public class Master {
private List<DetailSubclass> items;
public Master() {
public Root() {
}

View File

@ -48,16 +48,16 @@ public class ManyToOneNotInsertable extends BaseEnversJPAFunctionalTestCase {
// Rev 2
em.getTransaction().begin();
ManyToOneNotInsertableEntity master = new ManyToOneNotInsertableEntity( mto_id1, type_id1, type1 );
em.persist( master );
ManyToOneNotInsertableEntity entity = new ManyToOneNotInsertableEntity( mto_id1, type_id1, type1 );
em.persist( entity );
em.getTransaction().commit();
// Rev 2
em.getTransaction().begin();
master = em.find( ManyToOneNotInsertableEntity.class, mto_id1 );
master.setNumber( type_id2 );
entity = em.find( ManyToOneNotInsertableEntity.class, mto_id1 );
entity.setNumber( type_id2 );
em.getTransaction().commit();
}

View File

@ -13,7 +13,7 @@ public class DetailSuperclass {
private long id;
private Master parent;
private Root parent;
public DetailSuperclass() {
@ -27,11 +27,11 @@ public class DetailSuperclass {
this.id = id;
}
public Master getParent() {
public Root getParent() {
return parent;
}
public void setParent(Master parent) {
public void setParent(Root parent) {
this.parent = parent;
}

View File

@ -32,7 +32,7 @@ public class OneToManyInverseToSuperclassTest extends BaseEnversJPAFunctionalTes
public void initData() {
EntityManager em = getEntityManager();
Master m1 = new Master();
Root m1 = new Root();
DetailSubclass det1 = new DetailSubclass2();
DetailSubclass det2 = new DetailSubclass2();
@ -41,7 +41,7 @@ public class OneToManyInverseToSuperclassTest extends BaseEnversJPAFunctionalTes
det1.setStr2( "detail 1" );
m1.setStr( "master" );
m1.setStr( "root" );
m1.setItems( new ArrayList<DetailSubclass>() );
m1.getItems().add( det1 );
det1.setParent( m1 );
@ -53,7 +53,7 @@ public class OneToManyInverseToSuperclassTest extends BaseEnversJPAFunctionalTes
// Revision 2
em.getTransaction().begin();
m1 = em.find( Master.class, m1_id );
m1 = em.find( Root.class, m1_id );
det2.setStr2( "detail 2" );
det2.setParent( m1 );
@ -63,8 +63,8 @@ public class OneToManyInverseToSuperclassTest extends BaseEnversJPAFunctionalTes
// Revision 3
em.getTransaction().begin();
m1 = em.find( Master.class, m1_id );
m1.setStr( "new master" );
m1 = em.find( Root.class, m1_id );
m1.setStr( "new root" );
det1 = m1.getItems().get( 0 );
det1.setStr2( "new detail" );
@ -82,7 +82,7 @@ public class OneToManyInverseToSuperclassTest extends BaseEnversJPAFunctionalTes
// Revision 4
em.getTransaction().begin();
m1 = em.find( Master.class, m1_id );
m1 = em.find( Root.class, m1_id );
det1 = m1.getItems().get( 0 );
det1.setParent( null );
@ -95,10 +95,10 @@ public class OneToManyInverseToSuperclassTest extends BaseEnversJPAFunctionalTes
@Test
public void testHistoryExists() {
Master rev1_1 = getAuditReader().find( Master.class, m1_id, 1 );
Master rev1_2 = getAuditReader().find( Master.class, m1_id, 2 );
Master rev1_3 = getAuditReader().find( Master.class, m1_id, 3 );
Master rev1_4 = getAuditReader().find( Master.class, m1_id, 4 );
Root rev1_1 = getAuditReader().find( Root.class, m1_id, 1 );
Root rev1_2 = getAuditReader().find( Root.class, m1_id, 2 );
Root rev1_3 = getAuditReader().find( Root.class, m1_id, 3 );
Root rev1_4 = getAuditReader().find( Root.class, m1_id, 4 );
assert (rev1_1 != null);
assert (rev1_2 != null);

View File

@ -11,7 +11,7 @@ import java.util.List;
import org.hibernate.envers.Audited;
@Audited
public class Master {
public class Root {
private long id;
@ -19,7 +19,7 @@ public class Master {
private List<DetailSubclass> items;
public Master() {
public Root() {
}

View File

@ -9,8 +9,8 @@
<hibernate-mapping>
<class
name="org.hibernate.envers.test.integration.manytomany.inverseToSuperclass.Master"
table="HIB_MASTER_ENTITY">
name="org.hibernate.envers.test.integration.manytomany.inverseToSuperclass.Root"
table="HIB_ROOT_ENTITY">
<id name="id" column="ID" type="long">
<generator class="increment" />
@ -19,8 +19,8 @@
<property name="str" column="STR" />
<bag name="items" lazy="true" cascade="all" access="property" inverse="true"
table="HIB_MASTER_DETAIL">
<key column="ID_MASTER" />
table="HIB_ROOT_DETAIL">
<key column="ID_ROOT" />
<many-to-many
class="org.hibernate.envers.test.integration.manytomany.inverseToSuperclass.DetailSubclass2"
column="ID_DETAIL" />
@ -36,11 +36,11 @@
</id>
<discriminator column="DISCRIMINATOR" type="string" />
<bag name="masters" lazy="true" access="property" table="HIB_MASTER_DETAIL">
<bag name="roots" lazy="true" access="property" table="HIB_ROOT_DETAIL">
<key column="ID_DETAIL" />
<many-to-many
class="org.hibernate.envers.test.integration.manytomany.inverseToSuperclass.Master"
column="ID_MASTER" />
class="org.hibernate.envers.test.integration.manytomany.inverseToSuperclass.Root"
column="ID_ROOT" />
</bag>
<subclass

View File

@ -9,8 +9,8 @@
<hibernate-mapping>
<class
name="org.hibernate.envers.test.integration.onetomany.inverseToSuperclass.Master"
table="HIB_MASTER_ENTITY">
name="org.hibernate.envers.test.integration.onetomany.inverseToSuperclass.Root"
table="HIB_ROOT_ENTITY">
<id name="id" column="ID" type="long">
<generator class="increment" />
@ -20,7 +20,7 @@
<bag name="items" lazy="true" cascade="all" access="property"
inverse="true">
<key column="ID_MASTER" />
<key column="ID_ROOT" />
<one-to-many
class="org.hibernate.envers.test.integration.onetomany.inverseToSuperclass.DetailSubclass2" />
</bag>
@ -35,8 +35,8 @@
</id>
<discriminator column="DISCRIMINATOR" type="string" />
<many-to-one name="parent" column="ID_MASTER"
class="org.hibernate.envers.test.integration.onetomany.inverseToSuperclass.Master" />
<many-to-one name="parent" column="ID_ROOT"
class="org.hibernate.envers.test.integration.onetomany.inverseToSuperclass.Root" />
<subclass
name="org.hibernate.envers.test.integration.onetomany.inverseToSuperclass.DetailSubclass"

View File

@ -0,0 +1,45 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.spatial.dialect.cockroachdb;
import java.util.Map;
import org.hibernate.boot.model.TypeContributions;
import org.hibernate.dialect.CockroachDB201Dialect;
import org.hibernate.dialect.function.SQLFunction;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.spatial.dialect.postgis.PGGeometryTypeDescriptor;
/**
* An @{code SpatialDialect} for CockroachDB 20.2 and later. CockroachDB's spatial features where introduced in
* that version.
*/
public class CockroachDB202SpatialDialect extends CockroachDB201Dialect implements CockroachSpatialDialectTrait {
public CockroachDB202SpatialDialect() {
super();
registerColumnType(
PGGeometryTypeDescriptor.INSTANCE_WKB_2.getSqlType(),
"GEOMETRY"
);
for ( Map.Entry<String, SQLFunction> entry : functionsToRegister() ) {
registerFunction( entry.getKey(), entry.getValue() );
}
}
@Override
public void contributeTypes(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
super.contributeTypes(
typeContributions,
serviceRegistry
);
delegateContributeTypes( typeContributions, serviceRegistry );
}
}

View File

@ -0,0 +1,46 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.spatial.dialect.cockroachdb;
import org.hibernate.boot.model.TypeContributions;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.spatial.GeolatteGeometryJavaTypeDescriptor;
import org.hibernate.spatial.GeolatteGeometryType;
import org.hibernate.spatial.JTSGeometryJavaTypeDescriptor;
import org.hibernate.spatial.JTSGeometryType;
import org.hibernate.spatial.SpatialDialect;
import org.hibernate.spatial.dialect.postgis.PGGeometryTypeDescriptor;
import org.hibernate.spatial.dialect.postgis.PostgisFunctions;
import org.hibernate.spatial.dialect.postgis.PostgisSupport;
public class CockroachDBSpatialSupport extends PostgisSupport implements SpatialDialect {
CockroachDBSpatialSupport() {
super( new CockroachDBSpatialFunctions() );
}
@Override
public void contributeTypes(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
typeContributions.contributeType( new GeolatteGeometryType( PGGeometryTypeDescriptor.INSTANCE_WKB_2 ) );
typeContributions.contributeType( new JTSGeometryType( PGGeometryTypeDescriptor.INSTANCE_WKB_2 ) );
typeContributions.contributeJavaTypeDescriptor( GeolatteGeometryJavaTypeDescriptor.INSTANCE );
typeContributions.contributeJavaTypeDescriptor( JTSGeometryJavaTypeDescriptor.INSTANCE );
}
}
class CockroachDBSpatialFunctions extends PostgisFunctions {
CockroachDBSpatialFunctions() {
super();
this.functionMap.remove( "geomunion" );
}
}

View File

@ -0,0 +1,77 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.spatial.dialect.cockroachdb;
import org.hibernate.boot.model.TypeContributions;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.spatial.SpatialDialect;
import org.hibernate.spatial.SpatialFunction;
import org.hibernate.spatial.dialect.SpatialFunctionsRegistry;
public interface CockroachSpatialDialectTrait extends SpatialDialect {
CockroachDBSpatialSupport DELEGATE = new CockroachDBSpatialSupport();
default SpatialFunctionsRegistry functionsToRegister() {
return DELEGATE.functionsToRegister();
}
default String getSpatialRelateSQL(String columnName, int spatialRelation) {
return DELEGATE.getSpatialRelateSQL( columnName, spatialRelation );
}
default void delegateContributeTypes(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
DELEGATE.contributeTypes( typeContributions, serviceRegistry );
}
/**
* Returns the SQL fragment for the SQL WHERE-expression when parsing
* <code>org.hibernate.spatial.criterion.SpatialFilterExpression</code>s
* into prepared statements.
*
* @param columnName The name of the geometry-typed column to which the filter is
* be applied
*
* @return Rhe SQL fragment for the {@code SpatialFilterExpression}
*/
default String getSpatialFilterExpression(String columnName) {
return DELEGATE.getSpatialFilterExpression( columnName );
}
@Override
default String getSpatialAggregateSQL(String columnName, int aggregation) {
return DELEGATE.getSpatialAggregateSQL( columnName, aggregation );
}
@Override
default String getDWithinSQL(String columnName) {
return DELEGATE.getDWithinSQL( columnName );
}
@Override
default String getHavingSridSQL(String columnName) {
return DELEGATE.getHavingSridSQL( columnName );
}
@Override
default String getIsEmptySQL(String columnName, boolean isEmpty) {
return DELEGATE.getIsEmptySQL( columnName, isEmpty );
}
@Override
default boolean supportsFiltering() {
return DELEGATE.supportsFiltering();
}
@Override
default boolean supports(SpatialFunction function) {
return DELEGATE.supports( function );
}
}

View File

@ -0,0 +1,13 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
/**
* {@code SpatialDialect}s for CockroachDB
*/
package org.hibernate.spatial.dialect.cockroachdb;

View File

@ -39,12 +39,18 @@ import org.postgresql.util.PGobject;
public class PGGeometryTypeDescriptor implements SqlTypeDescriptor {
/**
* An instance of this class
*/
public static final PGGeometryTypeDescriptor INSTANCE = new PGGeometryTypeDescriptor();
final private Wkb.Dialect wkbDialect;
public static Geometry<?> toGeometry(Object object) {
// Type descriptor instance using EWKB v1 (postgis versions < 2.2.2)
public static final PGGeometryTypeDescriptor INSTANCE_WKB_1 = new PGGeometryTypeDescriptor( Wkb.Dialect.POSTGIS_EWKB_1);
// Type descriptor instance using EWKB v2 (postgis versions >= 2.2.2, see: https://trac.osgeo.org/postgis/ticket/3181)
public static final PGGeometryTypeDescriptor INSTANCE_WKB_2 = new PGGeometryTypeDescriptor(Wkb.Dialect.POSTGIS_EWKB_2);
private PGGeometryTypeDescriptor(Wkb.Dialect dialect) {
wkbDialect = dialect;
}
public Geometry<?> toGeometry(Object object) {
if ( object == null ) {
return null;
}
@ -55,9 +61,8 @@ public class PGGeometryTypeDescriptor implements SqlTypeDescriptor {
if ( pgValue.startsWith( "00" ) || pgValue.startsWith( "01" ) ) {
//we have a WKB because this pgValue starts with the bit-order byte
buffer = ByteBuffer.from( pgValue );
final WkbDecoder decoder = Wkb.newDecoder( Wkb.Dialect.POSTGIS_EWKB_1 );
final WkbDecoder decoder = Wkb.newDecoder( wkbDialect );
return decoder.decode( buffer );
}
else {
return parseWkt( pgValue );

View File

@ -0,0 +1,128 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.spatial.dialect.postgis;
import org.hibernate.spatial.SpatialDialect;
import org.hibernate.spatial.SpatialFunction;
import org.hibernate.spatial.dialect.SpatialFunctionsRegistry;
interface PGSpatialDialectTrait extends SpatialDialect {
PostgisSupport support = new PostgisSupport();
default SpatialFunctionsRegistry functionsToRegister() {
return support.functionsToRegister();
}
/**
* Returns the SQL fragment for the SQL WHERE-clause when parsing
* <code>org.hibernatespatial.criterion.SpatialRelateExpression</code>s
* into prepared statements.
* <p/>
*
* @param columnName The name of the geometry-typed column to which the relation is
* applied
* @param spatialRelation The type of spatial relation (as defined in
* <code>SpatialRelation</code>).
*
* @return SQL fragment {@code SpatialRelateExpression}
*/
@Override
default String getSpatialRelateSQL(String columnName, int spatialRelation) {
return support.getSpatialRelateSQL( columnName, spatialRelation );
}
/**
* Returns the SQL fragment for the SQL WHERE-expression when parsing
* <code>org.hibernate.spatial.criterion.SpatialFilterExpression</code>s
* into prepared statements.
*
* @param columnName The name of the geometry-typed column to which the filter is
* be applied
*
* @return Rhe SQL fragment for the {@code SpatialFilterExpression}
*/
@Override
default String getSpatialFilterExpression(String columnName) {
return support.getSpatialFilterExpression( columnName );
}
/**
* Returns the SQL fragment for the specfied Spatial aggregate expression.
*
* @param columnName The name of the Geometry property
* @param aggregation The type of <code>SpatialAggregate</code>
*
* @return The SQL fragment for the projection
*/
@Override
default String getSpatialAggregateSQL(String columnName, int aggregation) {
return support.getSpatialAggregateSQL( columnName, aggregation );
}
/**
* Returns The SQL fragment when parsing a <code>DWithinExpression</code>.
*
* @param columnName The geometry column to test against
*
* @return The SQL fragment when parsing a <code>DWithinExpression</code>.
*/
@Override
default String getDWithinSQL(String columnName) {
return support.getDWithinSQL( columnName );
}
/**
* Returns the SQL fragment when parsing a <code>HavingSridExpression</code>.
*
* @param columnName The geometry column to test against
*
* @return The SQL fragment for a <code>HavingSridExpression</code>.
*/
@Override
default String getHavingSridSQL(String columnName) {
return support.getHavingSridSQL( columnName );
}
/**
* Returns the SQL fragment when parsing a <code>IsEmptyExpression</code> or
* <code>IsNotEmpty</code> expression.
*
* @param columnName The geometry column
* @param isEmpty Whether the geometry is tested for empty or non-empty
*
* @return The SQL fragment for the isempty function
*/
@Override
default String getIsEmptySQL(String columnName, boolean isEmpty) {
return support.getIsEmptySQL( columnName, isEmpty );
}
/**
* Returns true if this <code>SpatialDialect</code> supports a specific filtering function.
* <p> This is intended to signal DB-support for fast window queries, or MBR-overlap queries.</p>
*
* @return True if filtering is supported
*/
@Override
default boolean supportsFiltering() {
return support.supportsFiltering();
}
/**
* Does this dialect supports the specified <code>SpatialFunction</code>.
*
* @param function <code>SpatialFunction</code>
*
* @return True if this <code>SpatialDialect</code> supports the spatial function specified by the function parameter.
*/
@Override
default boolean supports(SpatialFunction function) {
return support.supports( function );
}
}

View File

@ -24,9 +24,9 @@ import org.hibernate.type.Type;
* <p>
* Created by Karel Maesen, Geovise BVBA on 29/10/16.
*/
class PostgisFunctions extends SpatialFunctionsRegistry {
public class PostgisFunctions extends SpatialFunctionsRegistry {
PostgisFunctions() {
public PostgisFunctions() {
put(
"dimension", new StandardSQLFunction(

View File

@ -23,7 +23,7 @@ public class PostgisNoSQLMM extends PostgisDialect {
public PostgisNoSQLMM() {
registerColumnType(
PGGeometryTypeDescriptor.INSTANCE.getSqlType(),
PGGeometryTypeDescriptor.INSTANCE_WKB_1.getSqlType(),
"GEOMETRY"
);

View File

@ -0,0 +1,39 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.spatial.dialect.postgis;
import java.util.Map;
import org.hibernate.boot.model.TypeContributions;
import org.hibernate.dialect.PostgreSQL10Dialect;
import org.hibernate.dialect.function.SQLFunction;
import org.hibernate.service.ServiceRegistry;
public class PostgisPG10Dialect extends PostgreSQL10Dialect implements PGSpatialDialectTrait {
public PostgisPG10Dialect() {
super();
registerColumnType(
PGGeometryTypeDescriptor.INSTANCE_WKB_1.getSqlType(),
"GEOMETRY"
);
for ( Map.Entry<String, SQLFunction> entry : functionsToRegister() ) {
registerFunction( entry.getKey(), entry.getValue() );
}
}
@Override
public void contributeTypes(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
super.contributeTypes(
typeContributions,
serviceRegistry
);
support.contributeTypes( typeContributions, serviceRegistry );
}
}

View File

@ -31,7 +31,7 @@ public class PostgisPG82Dialect extends PostgreSQL82Dialect implements SpatialDi
public PostgisPG82Dialect() {
super();
registerColumnType(
PGGeometryTypeDescriptor.INSTANCE.getSqlType(),
PGGeometryTypeDescriptor.INSTANCE_WKB_1.getSqlType(),
"GEOMETRY"
);
for ( Map.Entry<String, SQLFunction> entry : support.functionsToRegister() ) {

View File

@ -31,7 +31,7 @@ public class PostgisPG91Dialect extends PostgreSQL91Dialect implements SpatialDi
public PostgisPG91Dialect() {
super();
registerColumnType(
PGGeometryTypeDescriptor.INSTANCE.getSqlType(),
PGGeometryTypeDescriptor.INSTANCE_WKB_1.getSqlType(),
"GEOMETRY"
);
for ( Map.Entry<String, SQLFunction> entry : support.functionsToRegister() ) {

View File

@ -31,7 +31,7 @@ public class PostgisPG92Dialect extends PostgreSQL92Dialect implements SpatialDi
public PostgisPG92Dialect() {
super();
registerColumnType(
PGGeometryTypeDescriptor.INSTANCE.getSqlType(),
PGGeometryTypeDescriptor.INSTANCE_WKB_1.getSqlType(),
"GEOMETRY"
);
for ( Map.Entry<String, SQLFunction> entry : support.functionsToRegister() ) {

View File

@ -31,7 +31,7 @@ public class PostgisPG93Dialect extends PostgreSQL93Dialect implements SpatialDi
public PostgisPG93Dialect() {
super();
registerColumnType(
PGGeometryTypeDescriptor.INSTANCE.getSqlType(),
PGGeometryTypeDescriptor.INSTANCE_WKB_1.getSqlType(),
"GEOMETRY"
);
for ( Map.Entry<String, SQLFunction> entry : support.functionsToRegister() ) {

View File

@ -31,7 +31,7 @@ public class PostgisPG94Dialect extends PostgreSQL94Dialect implements SpatialDi
public PostgisPG94Dialect() {
super();
registerColumnType(
PGGeometryTypeDescriptor.INSTANCE.getSqlType(),
PGGeometryTypeDescriptor.INSTANCE_WKB_1.getSqlType(),
"GEOMETRY"
);
for ( Map.Entry<String, SQLFunction> entry : support.functionsToRegister() ) {

View File

@ -12,17 +12,12 @@ import org.hibernate.boot.model.TypeContributions;
import org.hibernate.dialect.PostgreSQL95Dialect;
import org.hibernate.dialect.function.SQLFunction;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.spatial.SpatialDialect;
import org.hibernate.spatial.SpatialFunction;
/**
* Extends the {@code PostgreSQL95Dialect} to add support for the Postgis spatial types, functions and operators .
* Created by Karel Maesen, Geovise BVBA on 01/11/16.
*/
public class PostgisPG95Dialect extends PostgreSQL95Dialect implements SpatialDialect {
transient private PostgisSupport support = new PostgisSupport();
public class PostgisPG95Dialect extends PostgreSQL95Dialect implements PGSpatialDialectTrait {
/**
* Creates an instance
@ -30,10 +25,10 @@ public class PostgisPG95Dialect extends PostgreSQL95Dialect implements SpatialDi
public PostgisPG95Dialect() {
super();
registerColumnType(
PGGeometryTypeDescriptor.INSTANCE.getSqlType(),
PGGeometryTypeDescriptor.INSTANCE_WKB_1.getSqlType(),
"GEOMETRY"
);
for ( Map.Entry<String, SQLFunction> entry : support.functionsToRegister() ) {
for ( Map.Entry<String, SQLFunction> entry : functionsToRegister() ) {
registerFunction( entry.getKey(), entry.getValue() );
}
}
@ -47,110 +42,4 @@ public class PostgisPG95Dialect extends PostgreSQL95Dialect implements SpatialDi
support.contributeTypes( typeContributions, serviceRegistry );
}
/**
* Returns the SQL fragment for the SQL WHERE-clause when parsing
* <code>org.hibernatespatial.criterion.SpatialRelateExpression</code>s
* into prepared statements.
* <p/>
*
* @param columnName The name of the geometry-typed column to which the relation is
* applied
* @param spatialRelation The type of spatial relation (as defined in
* <code>SpatialRelation</code>).
*
* @return SQL fragment {@code SpatialRelateExpression}
*/
@Override
public String getSpatialRelateSQL(String columnName, int spatialRelation) {
return support.getSpatialRelateSQL( columnName, spatialRelation );
}
/**
* Returns the SQL fragment for the SQL WHERE-expression when parsing
* <code>org.hibernate.spatial.criterion.SpatialFilterExpression</code>s
* into prepared statements.
*
* @param columnName The name of the geometry-typed column to which the filter is
* be applied
*
* @return Rhe SQL fragment for the {@code SpatialFilterExpression}
*/
@Override
public String getSpatialFilterExpression(String columnName) {
return support.getSpatialFilterExpression( columnName );
}
/**
* Returns the SQL fragment for the specfied Spatial aggregate expression.
*
* @param columnName The name of the Geometry property
* @param aggregation The type of <code>SpatialAggregate</code>
*
* @return The SQL fragment for the projection
*/
@Override
public String getSpatialAggregateSQL(String columnName, int aggregation) {
return support.getSpatialAggregateSQL( columnName, aggregation );
}
/**
* Returns The SQL fragment when parsing a <code>DWithinExpression</code>.
*
* @param columnName The geometry column to test against
*
* @return The SQL fragment when parsing a <code>DWithinExpression</code>.
*/
@Override
public String getDWithinSQL(String columnName) {
return support.getDWithinSQL( columnName );
}
/**
* Returns the SQL fragment when parsing a <code>HavingSridExpression</code>.
*
* @param columnName The geometry column to test against
*
* @return The SQL fragment for a <code>HavingSridExpression</code>.
*/
@Override
public String getHavingSridSQL(String columnName) {
return support.getHavingSridSQL( columnName );
}
/**
* Returns the SQL fragment when parsing a <code>IsEmptyExpression</code> or
* <code>IsNotEmpty</code> expression.
*
* @param columnName The geometry column
* @param isEmpty Whether the geometry is tested for empty or non-empty
*
* @return The SQL fragment for the isempty function
*/
@Override
public String getIsEmptySQL(String columnName, boolean isEmpty) {
return support.getIsEmptySQL( columnName, isEmpty );
}
/**
* Returns true if this <code>SpatialDialect</code> supports a specific filtering function.
* <p> This is intended to signal DB-support for fast window queries, or MBR-overlap queries.</p>
*
* @return True if filtering is supported
*/
@Override
public boolean supportsFiltering() {
return support.supportsFiltering();
}
/**
* Does this dialect supports the specified <code>SpatialFunction</code>.
*
* @param function <code>SpatialFunction</code>
*
* @return True if this <code>SpatialDialect</code> supports the spatial function specified by the function parameter.
*/
@Override
public boolean supports(SpatialFunction function) {
return support.supports( function );
}
}

View File

@ -31,7 +31,7 @@ public class PostgisPG9Dialect extends PostgreSQL9Dialect implements SpatialDial
public PostgisPG9Dialect() {
super();
registerColumnType(
PGGeometryTypeDescriptor.INSTANCE.getSqlType(),
PGGeometryTypeDescriptor.INSTANCE_WKB_1.getSqlType(),
"GEOMETRY"
);
for ( Map.Entry<String, SQLFunction> entry : support.functionsToRegister() ) {

View File

@ -18,24 +18,32 @@ import org.hibernate.spatial.SpatialAggregate;
import org.hibernate.spatial.SpatialDialect;
import org.hibernate.spatial.SpatialFunction;
import org.hibernate.spatial.SpatialRelation;
import org.hibernate.spatial.dialect.SpatialFunctionsRegistry;
/**
* Created by Karel Maesen, Geovise BVBA on 29/10/16.
*/
public class PostgisSupport implements SpatialDialect, Serializable {
private final SpatialFunctionsRegistry postgisFunctions;
private PostgisFunctions postgisFunctions = new PostgisFunctions();
public PostgisSupport(SpatialFunctionsRegistry functions) {
postgisFunctions = functions;
}
void contributeTypes(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
typeContributions.contributeType( new GeolatteGeometryType( PGGeometryTypeDescriptor.INSTANCE ) );
typeContributions.contributeType( new JTSGeometryType( PGGeometryTypeDescriptor.INSTANCE ) );
public PostgisSupport() {
postgisFunctions = new PostgisFunctions();
}
public void contributeTypes(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
typeContributions.contributeType( new GeolatteGeometryType( PGGeometryTypeDescriptor.INSTANCE_WKB_1 ) );
typeContributions.contributeType( new JTSGeometryType( PGGeometryTypeDescriptor.INSTANCE_WKB_1 ) );
typeContributions.contributeJavaTypeDescriptor( GeolatteGeometryJavaTypeDescriptor.INSTANCE );
typeContributions.contributeJavaTypeDescriptor( JTSGeometryJavaTypeDescriptor.INSTANCE );
}
public PostgisFunctions functionsToRegister() {
public SpatialFunctionsRegistry functionsToRegister() {
return postgisFunctions;
}

View File

@ -69,7 +69,7 @@ public class PostgisUnmarshalTest {
public void testCase(String pgValue, Geometry<?> expected) throws SQLException {
PGobject pgo = new PGobject();
pgo.setValue( pgValue );
Geometry<?> received = PGGeometryTypeDescriptor.toGeometry( pgo );
Geometry<?> received = PGGeometryTypeDescriptor.INSTANCE_WKB_1.toGeometry( pgo );
assertEquals( String.format( "Failure on %s", pgValue ), expected, received );
}

View File

@ -522,7 +522,7 @@ public class TestSpatialFunctions extends SpatialFunctionalTestCase {
}
public void convexhull(String pckg) throws SQLException {
if ( !isSupportedByDialect( SpatialFunction.convexhull ) ) {
if ( !isSupportedByDialect( SpatialFunction.convexhull ) || !isSupportedByDialect( SpatialFunction.geomunion )) {
return;
}
Map<Integer, Geometry> dbexpected = expectationsFactory.getConvexHull( expectationsFactory.getTestPolygon() );

View File

@ -7,9 +7,11 @@
package org.hibernate.spatial.testing;
import org.hibernate.dialect.CockroachDB192Dialect;
import org.hibernate.dialect.Dialect;
import org.hibernate.dialect.PostgreSQL82Dialect;
import org.hibernate.spatial.SpatialDialect;
import org.hibernate.spatial.testing.dialects.cockroachdb.CockroachDBTestSupport;
import org.hibernate.spatial.testing.dialects.db2.DB2TestSupport;
import org.hibernate.spatial.testing.dialects.h2geodb.GeoDBTestSupport;
import org.hibernate.spatial.testing.dialects.hana.HANATestSupport;
@ -42,6 +44,11 @@ public class TestSupportFactories {
//this test works because all postgis dialects ultimately derive of the Postgresql82Dialect
return PostgisTestSupport.class;
}
if ( ( dialect instanceof SpatialDialect ) && CockroachDB192Dialect.class.isAssignableFrom( dialect.getClass() ) ){
return CockroachDBTestSupport.class;
}
if ( "org.hibernate.spatial.dialect.h2geodb.GeoDBDialect".equals( canonicalName ) ) {
return GeoDBTestSupport.class;
}

View File

@ -0,0 +1,28 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.spatial.testing.dialects.cockroachdb;
import org.hibernate.spatial.dialect.postgis.PGGeometryTypeDescriptor;
import org.hibernate.spatial.testing.DataSourceUtils;
import org.hibernate.spatial.testing.dialects.postgis.PostgisExpectationsFactory;
import org.geolatte.geom.jts.JTS;
import org.locationtech.jts.geom.Geometry;
public class CockroachDBExpectationsFactory extends PostgisExpectationsFactory {
public CockroachDBExpectationsFactory(DataSourceUtils utils) {
super( utils );
}
@Override
protected Geometry decode(Object object) {
org.geolatte.geom.Geometry<?> geometry = PGGeometryTypeDescriptor.INSTANCE_WKB_2.toGeometry( object );
return JTS.to( geometry );
}
}

View File

@ -0,0 +1,45 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.spatial.testing.dialects.cockroachdb;
import org.hibernate.spatial.integration.TestGeolatteSpatialPredicates;
import org.hibernate.spatial.integration.TestJTSSpatialPredicates;
import org.hibernate.spatial.integration.TestSpatialFunctions;
import org.hibernate.spatial.integration.TestSpatialRestrictions;
import org.hibernate.spatial.testing.AbstractExpectationsFactory;
import org.hibernate.spatial.testing.DataSourceUtils;
import org.hibernate.spatial.testing.SQLExpressionTemplate;
import org.hibernate.spatial.testing.TestData;
import org.hibernate.spatial.testing.TestSupport;
import org.hibernate.spatial.testing.dialects.postgis.PostgisExpressionTemplate;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
public class CockroachDBTestSupport extends TestSupport {
@Override
public TestData createTestData(BaseCoreFunctionalTestCase testcase) {
Class<? extends BaseCoreFunctionalTestCase> testcaseClass = testcase.getClass();
if ( ( testcaseClass == TestSpatialFunctions.class ) ||
( testcaseClass == TestSpatialRestrictions.class ) ||
( testcaseClass == TestJTSSpatialPredicates.class ) ||
( testcaseClass == TestGeolatteSpatialPredicates.class ) ) {
return TestData.fromFile( "cockroachdb/functions-test.xml" );
}
return TestData.fromFile( "cockroachdb/test-data-set.xml" );
}
@Override
public AbstractExpectationsFactory createExpectationsFactory(DataSourceUtils dataSourceUtils) {
return new CockroachDBExpectationsFactory( dataSourceUtils );
}
@Override
public SQLExpressionTemplate getSQLExpressionTemplate() {
return new PostgisExpressionTemplate();
}
}

View File

@ -238,10 +238,9 @@ public class PostgisExpectationsFactory extends AbstractExpectationsFactory {
);
}
//remove redundancy with toGeometry function in PGGeometryTypeDescriptor
@Override
protected Geometry decode(Object object) {
org.geolatte.geom.Geometry geometry = PGGeometryTypeDescriptor.toGeometry( object );
org.geolatte.geom.Geometry geometry = PGGeometryTypeDescriptor.INSTANCE_WKB_1.toGeometry( object );
return JTS.to( geometry );
}

View File

@ -0,0 +1,64 @@
<!--
~ Hibernate, Relational Persistence for Idiomatic Java
~
~ License: GNU Lesser General Public License (LGPL), version 2.1 or later.
~ See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
-->
<TestData>
<!-- points -->
<Element>
<id>1</id>
<type>POINT</type>
<wkt>SRID=4326;POINT(10 5)</wkt>
</Element>
<Element>
<id>2</id>
<type>POINT</type>
<wkt>SRID=4326;POINT(79 79)</wkt>
</Element>
<Element>
<id>3</id>
<type>POINT</type>
<wkt>SRID=4326;POINT(50 50)</wkt>
</Element>
<Element>
<id>4</id>
<type>POINT</type>
<wkt>SRID=4326;POINT(10 20)</wkt>
</Element>
<Element>
<id>5</id>
<type>POINT</type>
<wkt>SRID=4326;POINT(-4 -5)</wkt>
</Element>
<Element>
<id>6</id>
<type>LINESTRING</type>
<wkt>SRID=4326;LINESTRING(10.0 5.0, 20.0 15.0)</wkt>
</Element>
<Element>
<id>9</id>
<type>MULTILINESTRING</type>
<wkt>SRID=4326;MULTILINESTRING((10.0 5.0, 20.0 15.0, 30.3 22.4, 10 30.0), (40.0 20.0, 42.0 18.0, 43.0 16.0, 40
14.0))
</wkt>
</Element>
<Element>
<id>10</id>
<type>POLYGON</type>
<wkt>SRID=4326;POLYGON( (0 0, 0 10, 10 10, 10 0, 0 0) )</wkt>
</Element>
<Element>
<id>11</id>
<type>MULTIPOLYGON</type>
<wkt>SRID=4326;MULTIPOLYGON( ((10 20, 30 40, 44 50, 10 20)), ((15 10, 12 14, 13 13, 15 10)) )</wkt>
</Element>
</TestData>

View File

@ -0,0 +1,213 @@
<!--
~ Hibernate, Relational Persistence for Idiomatic Java
~
~ License: GNU Lesser General Public License (LGPL), version 2.1 or later.
~ See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
-->
<TestData>
<Element>
<id>1</id>
<type>POINT</type>
<wkt>POINT(10 5)</wkt>
</Element>
<Element>
<id>2</id>
<type>POINT</type>
<wkt>SRID=4326;POINT(52.25 2.53)</wkt>
</Element>
<Element>
<id>3</id>
<type>POINT</type>
<wkt>SRID=31370;POINT(150000 200000)</wkt>
</Element>
<Element>
<id>4</id>
<type>LINESTRING</type>
<wkt>SRID=4326;LINESTRING(10.0 5.0, 20.0 15.0)</wkt>
</Element>
<Element>
<id>5</id>
<type>LINESTRING</type>
<wkt>SRID=4326;LINESTRING(10.0 5.0, 20.0 15.0, 30.3 22.4, 10 30.0)</wkt>
</Element>
<Element>
<id>6</id>
<type>MULTILINESTRING</type>
<wkt>SRID=4326;MULTILINESTRING((10.0 5.0, 20.0 15.0),( 25.0 30.0, 30.0 20.0))</wkt>
</Element>
<Element>
<id>7</id>
<type>MULTILINESTRING</type>
<wkt>SRID=4326;MULTILINESTRING((10.0 5.0, 20.0 15.0, 30.3 22.4, 10 30.0), (40.0 20.0, 42.0 18.0, 43.0 16.0, 40
14.0))
</wkt>
</Element>
<Element>
<id>8</id>
<type>POLYGON</type>
<wkt>SRID=4326;POLYGON( (0 0, 0 10, 10 10, 10 0, 0 0) )</wkt>
</Element>
<Element>
<id>9</id>
<type>POLYGON</type>
<wkt>SRID=4326;POLYGON( (0 0, 0 10, 10 10, 10 0, 0 0), (2 2, 2 5, 5 5,5 2, 2 2))</wkt>
</Element>
<Element>
<id>10</id>
<type>POLYGON</type>
<wkt>SRID=4326;POLYGON( (110 110, 110 120, 120 120, 120 110, 110 110) )</wkt>
</Element>
<Element>
<id>11</id>
<type>MULTIPOLYGON</type>
<wkt>SRID=4326;MULTIPOLYGON( ((10 20, 30 40, 44 50, 10 20)), ((105 100, 120 140, 130 134, 105 100)) )</wkt>
</Element>
<Element>
<id>12</id>
<type>MULTIPOLYGON</type>
<wkt>SRID=4326;MULTIPOLYGON(( (0 0, 0 50, 50 50, 50 0, 0 0), (10 10, 10 20, 20 20, 20 10, 10 10) ),((105 100,
120 140, 130
134, 105 100)) )
</wkt>
</Element>
<Element>
<id>13</id>
<type>MULTIPOINT</type>
<wkt>SRID=4326;MULTIPOINT(21 2, 25 5, 30 3)</wkt>
</Element>
<Element>
<id>14</id>
<type>MULTIPOINT</type>
<wkt>SRID=4326;MULTIPOINT(21 2)</wkt>
</Element>
<Element>
<id>15</id>
<type>GEOMETRYCOLLECTION</type>
<wkt>SRID=4326;GEOMETRYCOLLECTION(POINT(4 0), LINESTRING(4 2, 5 3))</wkt>
</Element>
<Element>
<id>16</id>
<type>GEOMETRYCOLLECTION</type>
<wkt>SRID=4326;GEOMETRYCOLLECTION(POINT(4 0), LINESTRING(4 2, 5 3), POLYGON((0 0, 3 0, 3 3,0 3, 0 0)))</wkt>
</Element>
<Element>
<id>17</id>
<type>GEOMETRYCOLLECTION</type>
<wkt>SRID=4326;GEOMETRYCOLLECTION(POINT(4 0), LINESTRING(4 2, 5 3), POLYGON((0 0, 3 0, 3 3,0 3, 0 0),(1 1, 2 1,
2 2, 1 2,
1 1)))
</wkt>
</Element>
<Element>
<id>18</id>
<type>GEOMETRYCOLLECTION</type>
<wkt>SRID=4326;GEOMETRYCOLLECTION( MULTIPOINT(21 2, 25 5, 30 3), MULTIPOLYGON( ((10 20, 30 40, 44 50, 10 20)),
((105 100,
120 140, 130 134, 105 100)) ), MULTILINESTRING((10.0 5.0, 20.0 15.0),( 25.0 30.0, 30.0 20.0)))
</wkt>
</Element>
<Element>
<id>19</id>
<type>GEOMETRYCOLLECTION</type>
<wkt>SRID=4326;GEOMETRYCOLLECTION(POINT(4 0), POINT EMPTY, LINESTRING(4 2, 5 3))</wkt>
</Element>
<Element>
<id>20</id>
<type>GEOMETRYCOLLECTION</type>
<wkt>SRID=4326;GEOMETRYCOLLECTION(POINT(4 0), LINESTRING EMPTY, LINESTRING(4 2, 5 3))</wkt>
</Element>
<Element>
<id>21</id>
<type>GEOMETRYCOLLECTION</type>
<wkt>SRID=4326;GEOMETRYCOLLECTION(POINT(4 0), GEOMETRYCOLLECTION EMPTY, LINESTRING(4 2, 5 3))</wkt>
</Element>
<Element>
<id>22</id>
<type>GEOMETRYCOLLECTION</type>
<wkt>SRID=4326;GEOMETRYCOLLECTION(POINT(4 0), POLYGON EMPTY, LINESTRING(4 2, 5 3))</wkt>
</Element>
<Element>
<id>23</id>
<type>GEOMETRYCOLLECTION</type>
<wkt>SRID=4326;GEOMETRYCOLLECTION(POINT(4 0), MULTILINESTRING EMPTY, LINESTRING(4 2, 5 3))</wkt>
</Element>
<Element>
<id>24</id>
<type>GEOMETRYCOLLECTION</type>
<wkt>SRID=4326;GEOMETRYCOLLECTION(POINT(4 0), MULTIPOINT EMPTY, LINESTRING(4 2, 5 3))</wkt>
</Element>
<Element>
<id>25</id>
<type>GEOMETRYCOLLECTION</type>
<wkt>SRID=4326;GEOMETRYCOLLECTION(POINT(4 0), MULTIPOLYGON EMPTY, LINESTRING(4 2, 5 3))</wkt>
</Element>
<Element>
<id>26</id>
<type>POINT</type>
<wkt>POINT EMPTY</wkt>
</Element>
<Element>
<id>27</id>
<type>LINESTRING</type>
<wkt>LINESTRING EMPTY</wkt>
</Element>
<Element>
<id>28</id>
<type>POLYGON</type>
<wkt>POLYGON EMPTY</wkt>
</Element>
<Element>
<id>29</id>
<type>MULTIPOINT</type>
<wkt>MULTIPOINT EMPTY</wkt>
</Element>
<Element>
<id>30</id>
<type>MULTILINESTRING</type>
<wkt>MULTILINESTRING EMPTY</wkt>
</Element>
<Element>
<id>31</id>
<type>MULTIPOLYGON</type>
<wkt>MULTIPOLYGON EMPTY</wkt>
</Element>
<Element>
<id>32</id>
<type>GEOMETRYCOLLECTION</type>
<wkt>GEOMETRYCOLLECTION EMPTY</wkt>
</Element>
</TestData>

View File

@ -31,6 +31,12 @@
<property name="message" value="Line has leading space characters; indentation should be performed with tabs only." />
</module>
<module name="Regexp">
<property name="format" value="/^(master|slave)$/"/>
<property name="illegalPattern" value="true"/>
<property name="message" value="Conscious Language (use of terms 'master' or 'slave' not allowed)"/>
</module>
<module name="MissingDeprecated" />
<module name="MissingOverride" />

View File

@ -15,7 +15,7 @@ There are a number of tenants that make up a good test case as opposed to a poor
== Test templates
The Hibernate team maintains a set of "test templates" intended to help developers write tests. These test templates are maintained in GitHub @ https://github.com/hibernate/hibernate-test-case-templates/tree/master/orm[hibernate-test-case-templates]
The Hibernate team maintains a set of "test templates" intended to help developers write tests. These test templates are maintained in GitHub @ https://github.com/hibernate/hibernate-test-case-templates/tree/main/orm[hibernate-test-case-templates]
* If you want to use the Hibernate native API, you should follow the instructions from http://in.relation.to/2015/06/26/hibernate-test-case-templates/[this article].
* If you want to use JPA, you should use the JPA templates that were detailed in http://in.relation.to/2016/01/14/hibernate-jpa-test-case-template/[this article].

View File

@ -86,7 +86,7 @@ public class AccessTypeTest extends CompilationTest {
@TestForIssue(jiraKey = " METAGEN-81")
public void testAccessTypeForEmbeddableDeterminedByIdAnnotationInRootEntity() {
assertPresenceOfFieldInMetamodelFor(
Hotel.class, "webmaster",
Hotel.class, "webDomainExpert",
"Access type should be inherited position of the @Id field annotation in the root entity"
);
}

View File

@ -16,13 +16,13 @@ import javax.persistence.OneToOne;
public class Hotel {
@OneToOne
private User webmaster;
private User webDomainExpert;
public User getWebmaster() {
return webmaster;
public User getWebDomainExpert() {
return webDomainExpert;
}
public void setWebmaster(User webmaster) {
this.webmaster = webmaster;
public void setWebDomainExpert(User webDomainExpert) {
this.webDomainExpert = webDomainExpert;
}
}