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: on:
push: push:
branches: branches:
- 'master' - 'main'
- 'wip/6.0' - 'wip/6.0'
pull_request: pull_request:
branches: branches:
- 'master' - 'main'
- 'wip/6.0' - 'wip/6.0'
jobs: jobs:
build: 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._ _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 Assuming you will be working from the `main` branch and working
on the JIRA HHH-123 : `git checkout -b HHH-123 master` on the JIRA HHH-123 : `git checkout -b HHH-123 main`
## Code ## 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. 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) [![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 \ --ulimit nofile=1048576:1048576 \
--sysctl kernel.shmmax=1073741824 \ --sysctl kernel.shmmax=1073741824 \
--sysctl net.ipv4.ip_local_port_range='40000 60999' \ --sysctl net.ipv4.ip_local_port_range='40000 60999' \
--sysctl kernel.shmmni=524288 \ --sysctl kernel.shmmni=4096 \
--sysctl kernel.shmall=8388608 \ --sysctl kernel.shmall=8388608 \
-v $temp_dir:/config \ -v $temp_dir:/config \
store/saplabs/hanaexpress:2.00.045.00.20200121.1 \ store/saplabs/hanaexpress:2.00.045.00.20200121.1 \
@ -230,6 +230,12 @@ cockroachdb() {
sleep 10 sleep 10
OUTPUT=$(docker logs cockroach) OUTPUT=$(docker logs cockroach)
done 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" echo "Cockroachdb successfully started"
} }

View File

@ -86,42 +86,42 @@ relevant section.
:no: icon:times[role="red"] :no: icon:times[role="red"]
[[spatial-configuration-dialect-features]] [[spatial-configuration-dialect-features]]
.Hibernate Spatial dialect function support .Hibernate Spatial dialect function support
[cols=",,,,,,," |options="header",] [cols=",,,,,,,," |options="header",]
|================================ |================================
|Function | Description | PostgresSQL | Oracle 10g/11g | MySQL | SQLServer | GeoDB (H2) | DB2 |Function | Description | PostgresSQL | Oracle 10g/11g | MySQL | SQLServer | GeoDB (H2) | DB2 | CockroachDB
|Basic functions on Geometry | | | | | | | |Basic functions on Geometry | | | | | | | |
|`int dimension(Geometry)` | SFS §2.1.1.1 | {yes} | {yes} | {yes} | {yes} | {yes} | {yes} |`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} |`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} |`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} |`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} |`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} |`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} |`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} |`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} |`Geometry boundary(Geometry)` | SFS §2.1.1.1 | {yes} | {yes} | {no} | {yes} | {yes} | {yes} | {yes}
|Functions for testing Spatial Relations between geometric objects | | | | | | | |Functions for testing Spatial Relations between geometric objects | | | | | | | |
|`boolean equals(Geometry, Geometry)` | SFS §2.1.1.2 | {yes} | {yes} | {yes} | {yes} | {yes} | {yes} |`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} |`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} |`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} |`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} |`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} |`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} |`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} |`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} |`boolean relate(Geometry, Geometry, String)` | SFS §2.1.1.2 | {yes} | {yes} | {no} | {yes} | {yes} | {yes} | {yes}
|Functions that support Spatial Analysis | | | | | | | |Functions that support Spatial Analysis | | | | | | | |
|`double distance(Geometry, Geometry)` | SFS §2.1.1.3 | {yes} | {yes} | {no} | {yes} | {yes} | {yes} |`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} |`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)^ |`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)^ |`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)^ |`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)^ |`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)^ |`Geometry symdifference(Geometry, Geometry)` | SFS §2.1.1.3 | {yes} | {yes} | {no} | {yes} | {yes} | {yes}^(1)^ | {yes}
|Common non-SFS functions | | | | | | | |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} |`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} |`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 | | | | | | | |Spatial aggregate Functions | | | | | | | |
|`Geometry extent(Geometry)` | Returns a bounding box that bounds the set of returned geometries | {yes} | {yes} | {no} | {no} | {no} | {no} |`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. ^(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. 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):: GeoDB (H2)::
The `GeoDBDialect` supports the GeoDB a spatial extension of the H2 in-memory database. The `GeoDBDialect` supports the GeoDB a spatial extension of the H2 in-memory database.
[NOTE] [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 // 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' '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' assertjVersion = '3.14.0'
geolatteVersion = '1.6.1' geolatteVersion = '1.8.0'
shrinkwrapVersion = '1.2.6' shrinkwrapVersion = '1.2.6'
shrinkwrapDescriptorsVersion = '2.0.0' shrinkwrapDescriptorsVersion = '2.0.0'

View File

@ -1641,7 +1641,7 @@ public interface CoreMessageLogger extends BasicLogger {
) )
void applyingExplicitDiscriminatorColumnForJoined(String className, String overrideSetting); 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) @LogMessage(level = DEBUG)
@Message(value = "Creating pooled optimizer (lo) with [incrementSize=%s; returnClass=%s]", id = 467) @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<>( return new StreamDecorator<>(
StreamSupport.stream( spliterator, false ), StreamSupport.stream( spliterator, false ),
scrollableResults::close iterator::close
); );
} }

View File

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

View File

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

View File

@ -42,15 +42,13 @@ import org.hibernate.Incubating;
public class LongStreamDecorator implements LongStream { public class LongStreamDecorator implements LongStream {
private final LongStream delegate; private final LongStream delegate;
private final Runnable closeHandler;
private Runnable closeHandler;
public LongStreamDecorator( public LongStreamDecorator(
LongStream delegate, LongStream delegate,
Runnable closeHandler) { Runnable closeHandler) {
this.delegate = delegate;
this.closeHandler = closeHandler; this.closeHandler = closeHandler;
this.delegate.onClose( closeHandler ); this.delegate = delegate.onClose( closeHandler );
} }
@Override @Override
@ -300,7 +298,7 @@ public class LongStreamDecorator implements LongStream {
@Override @Override
public LongStream onClose(Runnable closeHandler) { public LongStream onClose(Runnable closeHandler) {
this.closeHandler = closeHandler; this.delegate.onClose( closeHandler );
return this; return this;
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -4,15 +4,14 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. * 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>. * 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; package org.hibernate.test.formulajoin;
import java.io.Serializable; import java.io.Serializable;
/** /**
* @author Gavin King * @author Gavin King
*/ */
public class Master implements Serializable { public class Root implements Serializable {
private Long id; private Long id;
private String name; private String name;
private Detail detail; private Detail detail;

View File

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

View File

@ -19,14 +19,14 @@ public class UpdateJoinedSubclassCorrelationTest extends BaseEntityManagerFuncti
@Override @Override
protected Class<?>[] getAnnotatedClasses() { protected Class<?>[] getAnnotatedClasses() {
return new Class<?>[] { Master.class, SubMaster.class, Detail.class }; return new Class<?>[] { Root.class, SubRoot.class, Detail.class };
} }
@Test @Test
public void testJoinedSubclassUpdateWithCorrelation() { public void testJoinedSubclassUpdateWithCorrelation() {
// prepare // prepare
doInJPA( this::entityManagerFactory, entityManager -> { doInJPA( this::entityManagerFactory, entityManager -> {
Master m1 = new SubMaster( 1, null ); Root m1 = new SubRoot( 1, null );
entityManager.persist( m1 ); entityManager.persist( m1 );
Detail d11 = new Detail( 10, m1 ); Detail d11 = new Detail( 10, m1 );
entityManager.persist( d11 ); entityManager.persist( d11 );
@ -35,40 +35,40 @@ public class UpdateJoinedSubclassCorrelationTest extends BaseEntityManagerFuncti
doInJPA( this::entityManagerFactory, entityManager -> { doInJPA( this::entityManagerFactory, entityManager -> {
// DO NOT CHANGE this query: it used to trigger a very specific bug caused // 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 // 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 ); Query updateQuery = entityManager.createQuery( u );
updateQuery.executeUpdate(); 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(); CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery<Master> query = builder.createQuery( Master.class ); CriteriaQuery<Root> query = builder.createQuery( Root.class );
query.select( query.from( Master.class ) ); query.select( query.from( Root.class ) );
List<Master> masters = entityManager.createQuery( query ).getResultList(); List<Root> roots = entityManager.createQuery( query ).getResultList();
Assert.assertEquals( 1, masters.size() ); Assert.assertEquals( 1, roots.size() );
Assert.assertEquals( "test", ((SubMaster) masters.get(0)).name ); Assert.assertEquals( "test", ((SubRoot) roots.get(0)).name );
} ); } );
} }
@Inheritance(strategy = JOINED) @Inheritance(strategy = JOINED)
@Entity(name = "Master") @Entity(name = "Root")
public static abstract class Master { public static abstract class Root {
@Id @Id
private Integer id; private Integer id;
public Master() { } public Root() { }
public Master( Integer id ) { public Root(Integer id ) {
this.id = id; this.id = id;
} }
} }
@Entity(name = "SubMaster") @Entity(name = "SubRoot")
public static class SubMaster extends Master { public static class SubRoot extends Root {
private String name; private String name;
public SubMaster() { } public SubRoot() { }
public SubMaster( Integer id, String name ) { public SubRoot(Integer id, String name ) {
super(id); super(id);
this.name = name; this.name = name;
} }
@ -80,11 +80,11 @@ public class UpdateJoinedSubclassCorrelationTest extends BaseEntityManagerFuncti
private Integer id; private Integer id;
@ManyToOne(optional = false) @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.id = id;
this.master = master; this.root = root;
} }
} }
} }

View File

@ -11,7 +11,7 @@
<hibernate-mapping default-lazy="false"> <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"> <id name="id" column="container_id">
<generator class="native" /> <generator class="native" />
</id> </id>
@ -28,10 +28,10 @@
</component> </component>
</component> </component>
<list name="components" lazy="true" table="CompNotNullMaster_Comps"> <list name="components" lazy="true" table="CompNotNullRoot_Comps">
<key column = "container_id"/> <key column = "container_id"/>
<index column = "list_index"/> <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="name"/>
<property name="count" column="count_"/> <property name="count" column="count_"/>
<many-to-one name="simple" not-null="true" cascade="save-update"/> <many-to-one name="simple" not-null="true" cascade="save-update"/>
@ -40,15 +40,15 @@
</composite-element> </composite-element>
</list> </list>
<list name="componentsImplicit" lazy="true" table="CompNotNullMaster_CompsImpl"> <list name="componentsImplicit" lazy="true" table="CompNotNullRoot_CompsImpl">
<key column = "container_id"/> <key column = "container_id"/>
<index column = "list_index3"/> <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="name"/>
<property name="count" column="count_"/> <property name="count" column="count_"/>
<many-to-one name="simple" cascade="save-update"/> <many-to-one name="simple" cascade="save-update"/>
<many-to-one name="one" 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"/> <property name="nestedproperty" not-null="true"/>
</nested-composite-element> </nested-composite-element>
</composite-element> </composite-element>

View File

@ -4,9 +4,8 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. * 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>. * 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; package org.hibernate.test.legacy;
import java.util.List; import java.util.List;
/** /**
@ -14,7 +13,7 @@ import java.util.List;
* *
* @author Emmanuel Bernard * @author Emmanuel Bernard
*/ */
public class ComponentNotNullMaster { public class ComponentNotNullRoot {
private int id; private int id;
private String test; private String test;

View File

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

View File

@ -47,7 +47,7 @@
<class name="org.hibernate.test.legacy.Outer" table="CID_OUT"> <class name="org.hibernate.test.legacy.Outer" table="CID_OUT">
<composite-id name="id"> <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="AKEY"/>
<column length="10" name="BKEY"/> <column length="10" name="BKEY"/>
<column length="10" name="ONE"/> <column length="10" name="ONE"/>

View File

@ -34,9 +34,9 @@ public class Middle implements Serializable {
if (this == o) return true; if (this == o) return true;
if (!(o instanceof Middle)) return false; 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; return true;
} }

View File

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

View File

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

View File

@ -4,9 +4,8 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. * 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>. * 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; package org.hibernate.test.legacy;
import java.io.Serializable; import java.io.Serializable;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.Collection; import java.util.Collection;
@ -14,21 +13,21 @@ import java.util.Date;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
public class Master implements Serializable, Named { public class Root implements Serializable, Named {
private Long id; private Long id;
private Master otherMaster; private Root otherRoot;
private Set details = new HashSet(); private Set details = new HashSet();
private Set moreDetails = new HashSet(); private Set moreDetails = new HashSet();
private Set incoming = new HashSet(); private Set incoming = new HashSet();
private Set outgoing = new HashSet(); private Set outgoing = new HashSet();
private String name="master"; private String name="root";
private Date stamp; private Date stamp;
private int version; private int version;
private BigDecimal bigDecimal = new BigDecimal("1234.123"); private BigDecimal bigDecimal = new BigDecimal("1234.123");
private int x; private int x;
private Collection allDetails; private Collection allDetails;
public Master() { public Root() {
} }
public Long getId() { public Long getId() {
@ -63,19 +62,19 @@ public class Master implements Serializable, Named {
details.remove(d); details.remove(d);
} }
public void addIncoming(Master m) { public void addIncoming(Root m) {
incoming.add(m); incoming.add(m);
} }
public void removeIncoming(Master m) { public void removeIncoming(Root m) {
incoming.remove(m); incoming.remove(m);
} }
public void addOutgoing(Master m) { public void addOutgoing(Root m) {
outgoing.add(m); outgoing.add(m);
} }
public void removeOutgoing(Master m) { public void removeOutgoing(Root m) {
outgoing.remove(m); outgoing.remove(m);
} }
@ -130,15 +129,15 @@ public class Master implements Serializable, Named {
/** /**
* @return * @return
*/ */
public Master getOtherMaster() { public Root getOtherRoot() {
return otherMaster; return otherRoot;
} }
/** /**
* @param master * @param root
*/ */
public void setOtherMaster(Master master) { public void setOtherRoot(Root root) {
otherMaster = master; otherRoot = root;
} }
/** /**

View File

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

View File

@ -6,6 +6,7 @@
*/ */
package org.hibernate.test.stream.basic; package org.hibernate.test.stream.basic;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Stream; import java.util.stream.Stream;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.Id; import javax.persistence.Id;
@ -25,6 +26,7 @@ import org.junit.Test;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is; 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.junit4.ExtraAssertions.assertTyping;
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate; 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") @Entity(name = "MyEntity")
@Table(name="MyEntity") @Table(name="MyEntity")
public static class 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.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Collections;
import java.util.List; 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.function.Predicate;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
@ -28,6 +33,7 @@ import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase; import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
import org.junit.Test; 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.junit4.ExtraAssertions.assertTyping;
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate; import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
@ -78,8 +84,8 @@ public class JpaStreamTest extends BaseNonConfigCoreFunctionalTestCase {
} }
@Test @Test
@TestForIssue( jiraKey = "HHH-13872")
@RequiresDialect(H2Dialect.class) @RequiresDialect(H2Dialect.class)
@TestForIssue( jiraKey = {"HHH-13872", "HHH-14449"})
public void testStreamCloseOnTerminalOperation() { public void testStreamCloseOnTerminalOperation() {
doInHibernate( this::sessionFactory, session -> { doInHibernate( this::sessionFactory, session -> {
session.createQuery( "delete from MyEntity" ).executeUpdate(); 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 -> { doInHibernate( this::sessionFactory, session -> {
Stream<MyEntity> stream = session Stream<MyEntity> stream = getMyEntityStream(prepare, session, onCloseCallbacks, flatMapBefore, flatMapAfter);
.createQuery( "SELECT me FROM MyEntity me" )
.getResultStream();
ResourceRegistry resourceRegistry = resourceRegistry(session); ResourceRegistry resourceRegistry = resourceRegistry(session);
assertTrue( resourceRegistry.hasRegisteredResources() ); assertTrue( resourceRegistry.hasRegisteredResources() );
@ -104,12 +216,90 @@ public class JpaStreamTest extends BaseNonConfigCoreFunctionalTestCase {
assertEquals(10, entities.size()); assertEquals(10, entities.size());
assertFalse( resourceRegistry.hasRegisteredResources() ); assertFalse( resourceRegistry.hasRegisteredResources() );
onCloseAssertion.run();
} ); } );
// forEach (TestCase based on attachment EntityManagerIllustrationTest.java in HHH-14449)
doInHibernate( this::sessionFactory, session -> { doInHibernate( this::sessionFactory, session -> {
Stream<MyEntity> stream = session Stream<MyEntity> stream = getMyEntityStream(prepare, session, onCloseCallbacks, flatMapBefore, flatMapAfter);
.createQuery( "SELECT me FROM MyEntity me" )
.getResultStream(); 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); ResourceRegistry resourceRegistry = resourceRegistry(session);
assertTrue( resourceRegistry.hasRegisteredResources() ); assertTrue( resourceRegistry.hasRegisteredResources() );
@ -118,12 +308,13 @@ public class JpaStreamTest extends BaseNonConfigCoreFunctionalTestCase {
assertEquals(55, sum); assertEquals(55, sum);
assertFalse( resourceRegistry.hasRegisteredResources() ); assertFalse( resourceRegistry.hasRegisteredResources() );
onCloseAssertion.run();
} ); } );
// mapToLong
doInHibernate( this::sessionFactory, session -> { doInHibernate( this::sessionFactory, session -> {
Stream<MyEntity> stream = session Stream<MyEntity> stream = getMyEntityStream(prepare, session, onCloseCallbacks, flatMapBefore, flatMapAfter);
.createQuery( "SELECT me FROM MyEntity me" )
.getResultStream();
ResourceRegistry resourceRegistry = resourceRegistry(session); ResourceRegistry resourceRegistry = resourceRegistry(session);
assertTrue( resourceRegistry.hasRegisteredResources() ); assertTrue( resourceRegistry.hasRegisteredResources() );
@ -132,12 +323,13 @@ public class JpaStreamTest extends BaseNonConfigCoreFunctionalTestCase {
assertEquals(10, result); assertEquals(10, result);
assertFalse( resourceRegistry.hasRegisteredResources() ); assertFalse( resourceRegistry.hasRegisteredResources() );
onCloseAssertion.run();
} ); } );
// mapToDouble
doInHibernate( this::sessionFactory, session -> { doInHibernate( this::sessionFactory, session -> {
Stream<MyEntity> stream = session Stream<MyEntity> stream = getMyEntityStream(prepare, session, onCloseCallbacks, flatMapBefore, flatMapAfter);
.createQuery( "SELECT me FROM MyEntity me" )
.getResultStream();
ResourceRegistry resourceRegistry = resourceRegistry(session); ResourceRegistry resourceRegistry = resourceRegistry(session);
assertTrue( resourceRegistry.hasRegisteredResources() ); assertTrue( resourceRegistry.hasRegisteredResources() );
@ -146,14 +338,14 @@ public class JpaStreamTest extends BaseNonConfigCoreFunctionalTestCase {
assertEquals(1, result, 0.1); assertEquals(1, result, 0.1);
assertFalse( resourceRegistry.hasRegisteredResources() ); assertFalse( resourceRegistry.hasRegisteredResources() );
onCloseAssertion.run();
} ); } );
//Test call close explicitly //Test call close explicitly
doInHibernate( this::sessionFactory, session -> { doInHibernate( this::sessionFactory, session -> {
try (Stream<Long> stream = session try (Stream<Long> stream = getLongStream(prepare, session, onCloseCallbacks, flatMapBefore, flatMapAfter)) {
.createQuery( "SELECT me.id FROM MyEntity me" )
.getResultStream()) {
ResourceRegistry resourceRegistry = resourceRegistry( session ); ResourceRegistry resourceRegistry = resourceRegistry( session );
assertTrue( resourceRegistry.hasRegisteredResources() ); assertTrue( resourceRegistry.hasRegisteredResources() );
@ -164,6 +356,8 @@ public class JpaStreamTest extends BaseNonConfigCoreFunctionalTestCase {
assertEquals( 10, result[4] ); assertEquals( 10, result[4] );
assertFalse( resourceRegistry.hasRegisteredResources() ); assertFalse( resourceRegistry.hasRegisteredResources() );
onCloseAssertion.run();
} }
} ); } );
@ -172,9 +366,7 @@ public class JpaStreamTest extends BaseNonConfigCoreFunctionalTestCase {
Method takeWhileMethod = ReflectHelper.getMethod( Stream.class, "takeWhile", Predicate.class ); Method takeWhileMethod = ReflectHelper.getMethod( Stream.class, "takeWhile", Predicate.class );
if ( takeWhileMethod != null ) { if ( takeWhileMethod != null ) {
try (Stream<Long> stream = session try (Stream<Long> stream = getLongStream(prepare, session, onCloseCallbacks, flatMapBefore, flatMapAfter)) {
.createQuery( "SELECT me.id FROM MyEntity me" )
.getResultStream()) {
ResourceRegistry resourceRegistry = resourceRegistry( session ); ResourceRegistry resourceRegistry = resourceRegistry( session );
assertTrue( resourceRegistry.hasRegisteredResources() ); assertTrue( resourceRegistry.hasRegisteredResources() );
@ -191,6 +383,8 @@ public class JpaStreamTest extends BaseNonConfigCoreFunctionalTestCase {
assertTrue( result.contains( 5 ) ); assertTrue( result.contains( 5 ) );
assertFalse( resourceRegistry.hasRegisteredResources() ); assertFalse( resourceRegistry.hasRegisteredResources() );
onCloseAssertion.run();
} }
catch (IllegalAccessException | InvocationTargetException e) { catch (IllegalAccessException | InvocationTargetException e) {
fail( "Could not execute takeWhile because of " + e.getMessage() ); 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 ); Method dropWhileMethod = ReflectHelper.getMethod( Stream.class, "dropWhile", Predicate.class );
if ( dropWhileMethod != null ) { if ( dropWhileMethod != null ) {
try (Stream<Long> stream = session try (Stream<Long> stream = getLongStream(prepare, session, onCloseCallbacks, flatMapBefore, flatMapAfter)) {
.createQuery( "SELECT me.id FROM MyEntity me" )
.getResultStream()) {
ResourceRegistry resourceRegistry = resourceRegistry( session ); ResourceRegistry resourceRegistry = resourceRegistry( session );
assertTrue( resourceRegistry.hasRegisteredResources() ); assertTrue( resourceRegistry.hasRegisteredResources() );
@ -221,6 +413,8 @@ public class JpaStreamTest extends BaseNonConfigCoreFunctionalTestCase {
assertTrue( result.contains( 10 ) ); assertTrue( result.contains( 10 ) );
assertFalse( resourceRegistry.hasRegisteredResources() ); assertFalse( resourceRegistry.hasRegisteredResources() );
onCloseAssertion.run();
} }
catch (IllegalAccessException | InvocationTargetException e) { catch (IllegalAccessException | InvocationTargetException e) {
fail( "Could not execute takeWhile because of " + e.getMessage() ); 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) { private ResourceRegistry resourceRegistry(Session session) {
SharedSessionContractImplementor sharedSessionContractImplementor = (SharedSessionContractImplementor) session; SharedSessionContractImplementor sharedSessionContractImplementor = (SharedSessionContractImplementor) session;
JdbcCoordinator jdbcCoordinator = sharedSessionContractImplementor.getJdbcCoordinator(); 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 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.Inner" );
parse( "from org.hibernate.test.Outer o where o.id.detailId = ?" ); 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.main.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( "from org.hibernate.test.Outer o where o.id.main.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.main.id.sup.dudu from org.hibernate.test.Outer o where o.id.main.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( "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.master.bla = ''" ); parse( "from org.hibernate.test.Outer o where o.id.main.bla = ''" );
parse( "from org.hibernate.test.Outer o where o.id.master.id.one = ''" ); 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.master.id.sup.id.akey > 'a'" ); 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.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.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.master.id.sup s 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.master m 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.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( "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( "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" ); 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.Up up order by up.id2 asc" );
parse( "from org.hibernate.test.Down down" ); parse( "from org.hibernate.test.Down down" );
parse( "from org.hibernate.test.Up up" ); 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.Several" );
parse( "from s in class org.hibernate.test.Single" ); parse( "from s in class org.hibernate.test.Single" );
parse( "\n" + 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 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 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 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.Root 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( "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.Master, 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 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.Root, 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( "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] // 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 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'"); // 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 @Override
public String[] getMappings() { public String[] getMappings() {
return new String[] { return new String[] {
"legacy/ComponentNotNullMaster.hbm.xml", "legacy/ComponentNotNullRoot.hbm.xml",
"legacy/One.hbm.xml", "legacy/One.hbm.xml",
"legacy/Many.hbm.xml", "legacy/Many.hbm.xml",
"legacy/Simple.hbm.xml" }; "legacy/Simple.hbm.xml" };
@ -45,16 +45,16 @@ public class ComponentNotNullTest extends LegacyTestCase {
// //
Session s = openSession(); Session s = openSession();
Transaction t = s.beginTransaction(); Transaction t = s.beginTransaction();
ComponentNotNullMaster master = new ComponentNotNullMaster(); ComponentNotNullRoot root = new ComponentNotNullRoot();
ComponentNotNull nullable = new ComponentNotNull(); ComponentNotNull nullable = new ComponentNotNull();
ComponentNotNull supercomp = new ComponentNotNull(); ComponentNotNull supercomp = new ComponentNotNull();
ComponentNotNull subcomp = new ComponentNotNull(); ComponentNotNull subcomp = new ComponentNotNull();
master.setNullable(nullable); root.setNullable(nullable);
subcomp.setProp1Subcomp("test"); subcomp.setProp1Subcomp("test");
supercomp.setSubcomp(subcomp); supercomp.setSubcomp(subcomp);
master.setSupercomp(supercomp); root.setSupercomp(supercomp);
s.save(master); s.save(root);
t.commit(); t.commit();
s.close(); s.close();
@ -63,20 +63,20 @@ public class ComponentNotNullTest extends LegacyTestCase {
s = openSession(); s = openSession();
t = s.beginTransaction(); t = s.beginTransaction();
master = new ComponentNotNullMaster(); root = new ComponentNotNullRoot();
nullable = new ComponentNotNull(); nullable = new ComponentNotNull();
supercomp = new ComponentNotNull(); supercomp = new ComponentNotNull();
subcomp = new ComponentNotNull(); subcomp = new ComponentNotNull();
master.setNullable(nullable); root.setNullable(nullable);
// do not set property // do not set property
//subcomp.setProp1Subcomp("test"); //subcomp.setProp1Subcomp("test");
supercomp.setSubcomp(subcomp); supercomp.setSubcomp(subcomp);
master.setSupercomp(supercomp); root.setSupercomp(supercomp);
try { try {
s.save(master); s.save(root);
t.commit(); t.commit();
fail("Inserting not-null null property should fail"); fail("Inserting not-null null property should fail");
} catch (PropertyValueException e) { } catch (PropertyValueException e) {
@ -90,20 +90,20 @@ public class ComponentNotNullTest extends LegacyTestCase {
s = openSession(); s = openSession();
t = s.beginTransaction(); t = s.beginTransaction();
master = new ComponentNotNullMaster(); root = new ComponentNotNullRoot();
nullable = new ComponentNotNull(); nullable = new ComponentNotNull();
supercomp = new ComponentNotNull(); supercomp = new ComponentNotNull();
subcomp = new ComponentNotNull(); subcomp = new ComponentNotNull();
master.setNullable(nullable); root.setNullable(nullable);
// do not set supercomp for master // do not set supercomp for root
//subcomp.setProp1Subcomp("test"); //subcomp.setProp1Subcomp("test");
//supercomp.setSubcomp(subcomp); //supercomp.setSubcomp(subcomp);
//master.setSupercomp(supercomp); //root.setSupercomp(supercomp);
try { try {
s.save(master); s.save(root);
t.commit(); t.commit();
fail("Inserting not-null null property should fail"); fail("Inserting not-null null property should fail");
} catch (PropertyValueException e) { } catch (PropertyValueException e) {
@ -118,23 +118,23 @@ public class ComponentNotNullTest extends LegacyTestCase {
//composite-element nullable //composite-element nullable
Session s = openSession(); Session s = openSession();
Transaction t = s.beginTransaction(); Transaction t = s.beginTransaction();
ComponentNotNullMaster master = new ComponentNotNullMaster(); ComponentNotNullRoot root = new ComponentNotNullRoot();
ComponentNotNull nullable = new ComponentNotNull(); ComponentNotNull nullable = new ComponentNotNull();
ComponentNotNull supercomp = new ComponentNotNull(); ComponentNotNull supercomp = new ComponentNotNull();
ComponentNotNull subcomp = new ComponentNotNull(); ComponentNotNull subcomp = new ComponentNotNull();
master.setNullable(nullable); root.setNullable(nullable);
subcomp.setProp1Subcomp("test"); subcomp.setProp1Subcomp("test");
supercomp.setSubcomp(subcomp); supercomp.setSubcomp(subcomp);
master.setSupercomp(supercomp); root.setSupercomp(supercomp);
master.setComponents(new ArrayList()); root.setComponents(new ArrayList());
ComponentNotNullMaster.ContainerInnerClass cc = ComponentNotNullRoot.ContainerInnerClass cc =
new ComponentNotNullMaster.ContainerInnerClass(); new ComponentNotNullRoot.ContainerInnerClass();
master.getComponents().add(cc); root.getComponents().add(cc);
try { try {
s.save(master); s.save(root);
t.commit(); t.commit();
fail("Inserting not-null many-to-one should fail"); fail("Inserting not-null many-to-one should fail");
} catch (PropertyValueException e) { } catch (PropertyValueException e) {
@ -148,26 +148,26 @@ public class ComponentNotNullTest extends LegacyTestCase {
s = openSession(); s = openSession();
t = s.beginTransaction(); t = s.beginTransaction();
master = new ComponentNotNullMaster(); root = new ComponentNotNullRoot();
nullable = new ComponentNotNull(); nullable = new ComponentNotNull();
supercomp = new ComponentNotNull(); supercomp = new ComponentNotNull();
subcomp = new ComponentNotNull(); subcomp = new ComponentNotNull();
master.setNullable(nullable); root.setNullable(nullable);
subcomp.setProp1Subcomp("test"); subcomp.setProp1Subcomp("test");
supercomp.setSubcomp(subcomp); supercomp.setSubcomp(subcomp);
master.setSupercomp(supercomp); root.setSupercomp(supercomp);
master.setComponentsImplicit(new ArrayList()); root.setComponentsImplicit(new ArrayList());
ComponentNotNullMaster.ContainerInnerClass nestedCc = ComponentNotNullRoot.ContainerInnerClass nestedCc =
new ComponentNotNullMaster.ContainerInnerClass(); new ComponentNotNullRoot.ContainerInnerClass();
cc = cc =
new ComponentNotNullMaster.ContainerInnerClass(); new ComponentNotNullRoot.ContainerInnerClass();
cc.setNested(nestedCc); cc.setNested(nestedCc);
master.getComponentsImplicit().add(cc); root.getComponentsImplicit().add(cc);
try { try {
s.save(master); s.save(root);
t.commit(); t.commit();
fail("Inserting not-null null property should fail"); fail("Inserting not-null null property should fail");
} catch (PropertyValueException e) { } catch (PropertyValueException e) {
@ -181,26 +181,26 @@ public class ComponentNotNullTest extends LegacyTestCase {
s = openSession(); s = openSession();
t = s.beginTransaction(); t = s.beginTransaction();
master = new ComponentNotNullMaster(); root = new ComponentNotNullRoot();
nullable = new ComponentNotNull(); nullable = new ComponentNotNull();
supercomp = new ComponentNotNull(); supercomp = new ComponentNotNull();
subcomp = new ComponentNotNull(); subcomp = new ComponentNotNull();
master.setNullable(nullable); root.setNullable(nullable);
subcomp.setProp1Subcomp("test"); subcomp.setProp1Subcomp("test");
supercomp.setSubcomp(subcomp); supercomp.setSubcomp(subcomp);
master.setSupercomp(supercomp); root.setSupercomp(supercomp);
master.setComponentsImplicit(new ArrayList()); root.setComponentsImplicit(new ArrayList());
nestedCc = nestedCc =
new ComponentNotNullMaster.ContainerInnerClass(); new ComponentNotNullRoot.ContainerInnerClass();
cc = cc =
new ComponentNotNullMaster.ContainerInnerClass(); new ComponentNotNullRoot.ContainerInnerClass();
cc.setNested(nestedCc); cc.setNested(nestedCc);
nestedCc.setNestedproperty("test"); nestedCc.setNestedproperty("test");
master.getComponentsImplicit().add(cc); root.getComponentsImplicit().add(cc);
s.save(master); s.save(root);
t.commit(); t.commit();
s.close(); s.close();
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -9,8 +9,8 @@
<hibernate-mapping> <hibernate-mapping>
<class <class
name="org.hibernate.envers.test.integration.onetomany.inverseToSuperclass.Master" name="org.hibernate.envers.test.integration.onetomany.inverseToSuperclass.Root"
table="HIB_MASTER_ENTITY"> table="HIB_ROOT_ENTITY">
<id name="id" column="ID" type="long"> <id name="id" column="ID" type="long">
<generator class="increment" /> <generator class="increment" />
@ -20,7 +20,7 @@
<bag name="items" lazy="true" cascade="all" access="property" <bag name="items" lazy="true" cascade="all" access="property"
inverse="true"> inverse="true">
<key column="ID_MASTER" /> <key column="ID_ROOT" />
<one-to-many <one-to-many
class="org.hibernate.envers.test.integration.onetomany.inverseToSuperclass.DetailSubclass2" /> class="org.hibernate.envers.test.integration.onetomany.inverseToSuperclass.DetailSubclass2" />
</bag> </bag>
@ -35,8 +35,8 @@
</id> </id>
<discriminator column="DISCRIMINATOR" type="string" /> <discriminator column="DISCRIMINATOR" type="string" />
<many-to-one name="parent" column="ID_MASTER" <many-to-one name="parent" column="ID_ROOT"
class="org.hibernate.envers.test.integration.onetomany.inverseToSuperclass.Master" /> class="org.hibernate.envers.test.integration.onetomany.inverseToSuperclass.Root" />
<subclass <subclass
name="org.hibernate.envers.test.integration.onetomany.inverseToSuperclass.DetailSubclass" 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 { public class PGGeometryTypeDescriptor implements SqlTypeDescriptor {
/** final private Wkb.Dialect wkbDialect;
* An instance of this class
*/
public static final PGGeometryTypeDescriptor INSTANCE = new PGGeometryTypeDescriptor();
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 ) { if ( object == null ) {
return null; return null;
} }
@ -55,9 +61,8 @@ public class PGGeometryTypeDescriptor implements SqlTypeDescriptor {
if ( pgValue.startsWith( "00" ) || pgValue.startsWith( "01" ) ) { if ( pgValue.startsWith( "00" ) || pgValue.startsWith( "01" ) ) {
//we have a WKB because this pgValue starts with the bit-order byte //we have a WKB because this pgValue starts with the bit-order byte
buffer = ByteBuffer.from( pgValue ); buffer = ByteBuffer.from( pgValue );
final WkbDecoder decoder = Wkb.newDecoder( Wkb.Dialect.POSTGIS_EWKB_1 ); final WkbDecoder decoder = Wkb.newDecoder( wkbDialect );
return decoder.decode( buffer ); return decoder.decode( buffer );
} }
else { else {
return parseWkt( pgValue ); 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> * <p>
* Created by Karel Maesen, Geovise BVBA on 29/10/16. * Created by Karel Maesen, Geovise BVBA on 29/10/16.
*/ */
class PostgisFunctions extends SpatialFunctionsRegistry { public class PostgisFunctions extends SpatialFunctionsRegistry {
PostgisFunctions() { public PostgisFunctions() {
put( put(
"dimension", new StandardSQLFunction( "dimension", new StandardSQLFunction(

View File

@ -23,7 +23,7 @@ public class PostgisNoSQLMM extends PostgisDialect {
public PostgisNoSQLMM() { public PostgisNoSQLMM() {
registerColumnType( registerColumnType(
PGGeometryTypeDescriptor.INSTANCE.getSqlType(), PGGeometryTypeDescriptor.INSTANCE_WKB_1.getSqlType(),
"GEOMETRY" "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() { public PostgisPG82Dialect() {
super(); super();
registerColumnType( registerColumnType(
PGGeometryTypeDescriptor.INSTANCE.getSqlType(), PGGeometryTypeDescriptor.INSTANCE_WKB_1.getSqlType(),
"GEOMETRY" "GEOMETRY"
); );
for ( Map.Entry<String, SQLFunction> entry : support.functionsToRegister() ) { for ( Map.Entry<String, SQLFunction> entry : support.functionsToRegister() ) {

View File

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

View File

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

View File

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

View File

@ -31,7 +31,7 @@ public class PostgisPG94Dialect extends PostgreSQL94Dialect implements SpatialDi
public PostgisPG94Dialect() { public PostgisPG94Dialect() {
super(); super();
registerColumnType( registerColumnType(
PGGeometryTypeDescriptor.INSTANCE.getSqlType(), PGGeometryTypeDescriptor.INSTANCE_WKB_1.getSqlType(),
"GEOMETRY" "GEOMETRY"
); );
for ( Map.Entry<String, SQLFunction> entry : support.functionsToRegister() ) { 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.PostgreSQL95Dialect;
import org.hibernate.dialect.function.SQLFunction; import org.hibernate.dialect.function.SQLFunction;
import org.hibernate.service.ServiceRegistry; 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 . * 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. * Created by Karel Maesen, Geovise BVBA on 01/11/16.
*/ */
public class PostgisPG95Dialect extends PostgreSQL95Dialect implements SpatialDialect { public class PostgisPG95Dialect extends PostgreSQL95Dialect implements PGSpatialDialectTrait {
transient private PostgisSupport support = new PostgisSupport();
/** /**
* Creates an instance * Creates an instance
@ -30,10 +25,10 @@ public class PostgisPG95Dialect extends PostgreSQL95Dialect implements SpatialDi
public PostgisPG95Dialect() { public PostgisPG95Dialect() {
super(); super();
registerColumnType( registerColumnType(
PGGeometryTypeDescriptor.INSTANCE.getSqlType(), PGGeometryTypeDescriptor.INSTANCE_WKB_1.getSqlType(),
"GEOMETRY" "GEOMETRY"
); );
for ( Map.Entry<String, SQLFunction> entry : support.functionsToRegister() ) { for ( Map.Entry<String, SQLFunction> entry : functionsToRegister() ) {
registerFunction( entry.getKey(), entry.getValue() ); registerFunction( entry.getKey(), entry.getValue() );
} }
} }
@ -47,110 +42,4 @@ public class PostgisPG95Dialect extends PostgreSQL95Dialect implements SpatialDi
support.contributeTypes( typeContributions, serviceRegistry ); 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() { public PostgisPG9Dialect() {
super(); super();
registerColumnType( registerColumnType(
PGGeometryTypeDescriptor.INSTANCE.getSqlType(), PGGeometryTypeDescriptor.INSTANCE_WKB_1.getSqlType(),
"GEOMETRY" "GEOMETRY"
); );
for ( Map.Entry<String, SQLFunction> entry : support.functionsToRegister() ) { 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.SpatialDialect;
import org.hibernate.spatial.SpatialFunction; import org.hibernate.spatial.SpatialFunction;
import org.hibernate.spatial.SpatialRelation; import org.hibernate.spatial.SpatialRelation;
import org.hibernate.spatial.dialect.SpatialFunctionsRegistry;
/** /**
* Created by Karel Maesen, Geovise BVBA on 29/10/16. * Created by Karel Maesen, Geovise BVBA on 29/10/16.
*/ */
public class PostgisSupport implements SpatialDialect, Serializable { 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) { public PostgisSupport() {
typeContributions.contributeType( new GeolatteGeometryType( PGGeometryTypeDescriptor.INSTANCE ) ); postgisFunctions = new PostgisFunctions();
typeContributions.contributeType( new JTSGeometryType( PGGeometryTypeDescriptor.INSTANCE ) ); }
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( GeolatteGeometryJavaTypeDescriptor.INSTANCE );
typeContributions.contributeJavaTypeDescriptor( JTSGeometryJavaTypeDescriptor.INSTANCE ); typeContributions.contributeJavaTypeDescriptor( JTSGeometryJavaTypeDescriptor.INSTANCE );
} }
public PostgisFunctions functionsToRegister() { public SpatialFunctionsRegistry functionsToRegister() {
return postgisFunctions; return postgisFunctions;
} }

View File

@ -69,7 +69,7 @@ public class PostgisUnmarshalTest {
public void testCase(String pgValue, Geometry<?> expected) throws SQLException { public void testCase(String pgValue, Geometry<?> expected) throws SQLException {
PGobject pgo = new PGobject(); PGobject pgo = new PGobject();
pgo.setValue( pgValue ); 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 ); 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 { public void convexhull(String pckg) throws SQLException {
if ( !isSupportedByDialect( SpatialFunction.convexhull ) ) { if ( !isSupportedByDialect( SpatialFunction.convexhull ) || !isSupportedByDialect( SpatialFunction.geomunion )) {
return; return;
} }
Map<Integer, Geometry> dbexpected = expectationsFactory.getConvexHull( expectationsFactory.getTestPolygon() ); Map<Integer, Geometry> dbexpected = expectationsFactory.getConvexHull( expectationsFactory.getTestPolygon() );

View File

@ -7,9 +7,11 @@
package org.hibernate.spatial.testing; package org.hibernate.spatial.testing;
import org.hibernate.dialect.CockroachDB192Dialect;
import org.hibernate.dialect.Dialect; import org.hibernate.dialect.Dialect;
import org.hibernate.dialect.PostgreSQL82Dialect; import org.hibernate.dialect.PostgreSQL82Dialect;
import org.hibernate.spatial.SpatialDialect; 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.db2.DB2TestSupport;
import org.hibernate.spatial.testing.dialects.h2geodb.GeoDBTestSupport; import org.hibernate.spatial.testing.dialects.h2geodb.GeoDBTestSupport;
import org.hibernate.spatial.testing.dialects.hana.HANATestSupport; 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 //this test works because all postgis dialects ultimately derive of the Postgresql82Dialect
return PostgisTestSupport.class; return PostgisTestSupport.class;
} }
if ( ( dialect instanceof SpatialDialect ) && CockroachDB192Dialect.class.isAssignableFrom( dialect.getClass() ) ){
return CockroachDBTestSupport.class;
}
if ( "org.hibernate.spatial.dialect.h2geodb.GeoDBDialect".equals( canonicalName ) ) { if ( "org.hibernate.spatial.dialect.h2geodb.GeoDBDialect".equals( canonicalName ) ) {
return GeoDBTestSupport.class; 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 @Override
protected Geometry decode(Object object) { 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 ); 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." /> <property name="message" value="Line has leading space characters; indentation should be performed with tabs only." />
</module> </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="MissingDeprecated" />
<module name="MissingOverride" /> <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 == 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 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]. * 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") @TestForIssue(jiraKey = " METAGEN-81")
public void testAccessTypeForEmbeddableDeterminedByIdAnnotationInRootEntity() { public void testAccessTypeForEmbeddableDeterminedByIdAnnotationInRootEntity() {
assertPresenceOfFieldInMetamodelFor( assertPresenceOfFieldInMetamodelFor(
Hotel.class, "webmaster", Hotel.class, "webDomainExpert",
"Access type should be inherited position of the @Id field annotation in the root entity" "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 { public class Hotel {
@OneToOne @OneToOne
private User webmaster; private User webDomainExpert;
public User getWebmaster() { public User getWebDomainExpert() {
return webmaster; return webDomainExpert;
} }
public void setWebmaster(User webmaster) { public void setWebDomainExpert(User webDomainExpert) {
this.webmaster = webmaster; this.webDomainExpert = webDomainExpert;
} }
} }