6.0 Final tasks - general test_legacy dir clean-up
Drop test that where either copied over or had corresponding tests - leaves just the "bulkid" tests
This commit is contained in:
parent
f9fa2e6e53
commit
f0e7b2160b
|
@ -1,109 +0,0 @@
|
||||||
/*
|
|
||||||
* 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.test.hql;
|
|
||||||
|
|
||||||
import jakarta.persistence.Embeddable;
|
|
||||||
import jakarta.persistence.Embedded;
|
|
||||||
import jakarta.persistence.Entity;
|
|
||||||
import jakarta.persistence.Id;
|
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
|
|
||||||
import org.hibernate.Filter;
|
|
||||||
import org.hibernate.SessionFactory;
|
|
||||||
import org.hibernate.cfg.AvailableSettings;
|
|
||||||
import org.hibernate.cfg.Configuration;
|
|
||||||
import org.hibernate.dialect.H2Dialect;
|
|
||||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
|
||||||
|
|
||||||
import org.junit.After;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import org.hibernate.testing.TestForIssue;
|
|
||||||
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Steve Ebersole
|
|
||||||
*/
|
|
||||||
@TestForIssue( jiraKey = "HHH-7757" )
|
|
||||||
public class TupleSupportTest extends BaseUnitTestCase {
|
|
||||||
@Entity( name = "TheEntity" )
|
|
||||||
public static class TheEntity {
|
|
||||||
@Id
|
|
||||||
private Long id;
|
|
||||||
@Embedded
|
|
||||||
private TheComposite compositeValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Embeddable
|
|
||||||
public static class TheComposite {
|
|
||||||
private String thing1;
|
|
||||||
private String thing2;
|
|
||||||
|
|
||||||
public TheComposite() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public TheComposite(String thing1, String thing2) {
|
|
||||||
this.thing1 = thing1;
|
|
||||||
this.thing2 = thing2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private SessionFactory sessionFactory;
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void buildSessionFactory() {
|
|
||||||
Configuration cfg = new Configuration()
|
|
||||||
.addAnnotatedClass( TheEntity.class );
|
|
||||||
cfg.getProperties().put( AvailableSettings.DIALECT, NoTupleSupportDialect.class.getName() );
|
|
||||||
cfg.getProperties().put( AvailableSettings.HBM2DDL_AUTO, "create-drop" );
|
|
||||||
sessionFactory = cfg.buildSessionFactory();
|
|
||||||
}
|
|
||||||
|
|
||||||
@After
|
|
||||||
public void releaseSessionFactory() {
|
|
||||||
sessionFactory.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testImplicitTupleNotEquals() {
|
|
||||||
final String hql = "from TheEntity e where e.compositeValue <> :p1";
|
|
||||||
HQLQueryPlan queryPlan = ( (SessionFactoryImplementor) sessionFactory ).getQueryInterpretationCache()
|
|
||||||
.getHQLQueryPlan( hql, false, Collections.<String,Filter>emptyMap() );
|
|
||||||
|
|
||||||
assertEquals( 1, queryPlan.getSqlStrings().length );
|
|
||||||
System.out.println( " SQL : " + queryPlan.getSqlStrings()[0] );
|
|
||||||
assertTrue( queryPlan.getSqlStrings()[0].contains( "<>" ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testImplicitTupleNotInList() {
|
|
||||||
final String hql = "from TheEntity e where e.compositeValue not in (:p1,:p2)";
|
|
||||||
HQLQueryPlan queryPlan = ( (SessionFactoryImplementor) sessionFactory ).getQueryInterpretationCache()
|
|
||||||
.getHQLQueryPlan( hql, false, Collections.<String,Filter>emptyMap() );
|
|
||||||
|
|
||||||
assertEquals( 1, queryPlan.getSqlStrings().length );
|
|
||||||
System.out.println( " SQL : " + queryPlan.getSqlStrings()[0] );
|
|
||||||
assertTrue( queryPlan.getSqlStrings()[0].contains( "<>" ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class NoTupleSupportDialect extends H2Dialect {
|
|
||||||
@Override
|
|
||||||
public boolean supportsRowValueConstructorSyntax() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean supportsRowValueConstructorSyntaxInInList() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,59 +0,0 @@
|
||||||
/*
|
|
||||||
* 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.orm.test.pagination;
|
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.regex.Matcher;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
import org.hibernate.Session;
|
|
||||||
|
|
||||||
import org.hibernate.testing.DialectChecks;
|
|
||||||
import org.hibernate.testing.RequiresDialectFeature;
|
|
||||||
import org.hibernate.testing.TestForIssue;
|
|
||||||
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import static java.lang.String.format;
|
|
||||||
import static org.junit.Assert.fail;
|
|
||||||
|
|
||||||
public class LimitWithExpreesionAndFetchJoinTest extends BaseNonConfigCoreFunctionalTestCase {
|
|
||||||
/**
|
|
||||||
* @author Piotr Findeisen
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
@TestForIssue( jiraKey = "HHH-951" )
|
|
||||||
@RequiresDialectFeature(
|
|
||||||
value = DialectChecks.SupportLimitCheck.class,
|
|
||||||
comment = "Dialect does not support limit"
|
|
||||||
)
|
|
||||||
public void testLimitWithExpreesionAndFetchJoin() {
|
|
||||||
Session session = openSession();
|
|
||||||
session.beginTransaction();
|
|
||||||
|
|
||||||
String hql = "SELECT b, 1 FROM DataMetaPoint b inner join fetch b.dataPoint dp";
|
|
||||||
session.createQuery(hql)
|
|
||||||
.setMaxResults(3)
|
|
||||||
// This should not fail
|
|
||||||
.list();
|
|
||||||
|
|
||||||
HQLQueryPlan queryPlan = new HQLQueryPlan( hql, false, Collections.EMPTY_MAP, sessionFactory());
|
|
||||||
String sqlQuery = queryPlan.getTranslators()[0]
|
|
||||||
.collectSqlStrings().get(0);
|
|
||||||
|
|
||||||
session.getTransaction().commit();
|
|
||||||
session.close();
|
|
||||||
|
|
||||||
Matcher matcher = Pattern.compile(
|
|
||||||
"(?is)\\b(?<column>\\w+\\.\\w+)\\s+as\\s+(?<alias>\\w+)\\b.*\\k<column>\\s+as\\s+\\k<alias>")
|
|
||||||
.matcher(sqlQuery);
|
|
||||||
if (matcher.find()) {
|
|
||||||
fail(format("Column %s mapped to alias %s twice in generated SQL: %s", matcher.group("column"),
|
|
||||||
matcher.group("alias"), sqlQuery));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,427 +0,0 @@
|
||||||
/*
|
|
||||||
* 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.test.readonly;
|
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import org.hibernate.Hibernate;
|
|
||||||
import org.hibernate.Session;
|
|
||||||
import org.hibernate.Transaction;
|
|
||||||
import org.hibernate.engine.spi.SessionImplementor;
|
|
||||||
import org.hibernate.proxy.HibernateProxy;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.assertFalse;
|
|
||||||
import static org.junit.Assert.assertNotNull;
|
|
||||||
import static org.junit.Assert.assertNotSame;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Andrea Boriero
|
|
||||||
*/
|
|
||||||
public class ReadOnlySessionLazyNonLazyFilterTest extends AbstractReadOnlyTest {
|
|
||||||
@Override
|
|
||||||
public String[] getMappings() {
|
|
||||||
return new String[] { "readonly/DataPoint.hbm.xml" };
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@SuppressWarnings( {"unchecked"})
|
|
||||||
public void testDefaultReadOnlyWithModifiableFilterCollectionEntities() {
|
|
||||||
Container cOrig = createContainer();
|
|
||||||
Set expectedInitializedObjects = new HashSet(
|
|
||||||
Arrays.asList(
|
|
||||||
cOrig,
|
|
||||||
cOrig.getNoProxyInfo(),
|
|
||||||
cOrig.getProxyInfo(),
|
|
||||||
cOrig.getNonLazyInfo(),
|
|
||||||
cOrig.getNoProxyOwner(),
|
|
||||||
cOrig.getProxyOwner(),
|
|
||||||
cOrig.getNonLazyOwner(),
|
|
||||||
cOrig.getLazyDataPoints().iterator().next(),
|
|
||||||
cOrig.getNonLazyJoinDataPoints().iterator().next(),
|
|
||||||
cOrig.getNonLazySelectDataPoints().iterator().next()
|
|
||||||
)
|
|
||||||
);
|
|
||||||
Set expectedReadOnlyObjects = new HashSet();
|
|
||||||
|
|
||||||
Session s = openSession();
|
|
||||||
assertFalse( s.isDefaultReadOnly() );
|
|
||||||
Transaction t = s.beginTransaction();
|
|
||||||
s.save( cOrig );
|
|
||||||
checkContainer( cOrig, expectedInitializedObjects, expectedReadOnlyObjects, s );
|
|
||||||
s.setDefaultReadOnly( true );
|
|
||||||
assertTrue( s.isDefaultReadOnly() );
|
|
||||||
checkContainer( cOrig, expectedInitializedObjects, expectedReadOnlyObjects, s );
|
|
||||||
t.commit();
|
|
||||||
s.close();
|
|
||||||
|
|
||||||
s = openSession();
|
|
||||||
t = s.beginTransaction();
|
|
||||||
s.setDefaultReadOnly( true );
|
|
||||||
assertTrue( s.isDefaultReadOnly() );
|
|
||||||
Container c = ( Container ) s.get( Container.class, cOrig.getId() );
|
|
||||||
assertNotSame( cOrig, c );
|
|
||||||
expectedInitializedObjects = new HashSet(
|
|
||||||
Arrays.asList(
|
|
||||||
c,
|
|
||||||
c.getNonLazyInfo(),
|
|
||||||
c.getNoProxyOwner(),
|
|
||||||
c.getProxyOwner(),
|
|
||||||
c.getNonLazyOwner(),
|
|
||||||
c.getNonLazyJoinDataPoints().iterator().next(),
|
|
||||||
c.getNonLazySelectDataPoints().iterator().next()
|
|
||||||
)
|
|
||||||
);
|
|
||||||
expectedReadOnlyObjects = new HashSet(
|
|
||||||
Arrays.asList(
|
|
||||||
c,
|
|
||||||
c.getNoProxyInfo(),
|
|
||||||
c.getProxyInfo(),
|
|
||||||
c.getNonLazyInfo(),
|
|
||||||
c.getNoProxyOwner(),
|
|
||||||
c.getProxyOwner(),
|
|
||||||
c.getNonLazyOwner(),
|
|
||||||
//c.getLazyDataPoints(),
|
|
||||||
c.getNonLazyJoinDataPoints().iterator().next(),
|
|
||||||
c.getNonLazySelectDataPoints().iterator().next()
|
|
||||||
)
|
|
||||||
);
|
|
||||||
List list = s.createFilter( c.getLazyDataPoints(), "" )
|
|
||||||
.setMaxResults(1)
|
|
||||||
.setReadOnly( false )
|
|
||||||
.list();
|
|
||||||
assertEquals( 1, list.size() );
|
|
||||||
assertFalse( s.isReadOnly( list.get( 0 ) ) );
|
|
||||||
list = s.createFilter( c.getNonLazyJoinDataPoints(), "" )
|
|
||||||
.setMaxResults(1)
|
|
||||||
.setReadOnly( false )
|
|
||||||
.list();
|
|
||||||
assertEquals( 1, list.size() );
|
|
||||||
assertTrue( s.isReadOnly( list.get( 0 ) ) );
|
|
||||||
list = s.createFilter( c.getNonLazySelectDataPoints(), "" )
|
|
||||||
.setMaxResults(1)
|
|
||||||
.setReadOnly( false )
|
|
||||||
.list();
|
|
||||||
assertEquals( 1, list.size() );
|
|
||||||
assertTrue( s.isReadOnly( list.get( 0 ) ) );
|
|
||||||
t.commit();
|
|
||||||
s.close();
|
|
||||||
s = openSession();
|
|
||||||
t = s.beginTransaction();
|
|
||||||
s.createQuery("delete from DataPoint").executeUpdate();
|
|
||||||
s.createQuery("delete from Container").executeUpdate();
|
|
||||||
s.createQuery("delete from Info").executeUpdate();
|
|
||||||
s.createQuery("delete from Owner").executeUpdate();
|
|
||||||
t.commit();
|
|
||||||
s.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings( {"unchecked"})
|
|
||||||
@Test
|
|
||||||
public void testDefaultModifiableWithReadOnlyFilterCollectionEntities() {
|
|
||||||
Container cOrig = createContainer();
|
|
||||||
Set expectedInitializedObjects = new HashSet(
|
|
||||||
Arrays.asList(
|
|
||||||
cOrig,
|
|
||||||
cOrig.getNoProxyInfo(),
|
|
||||||
cOrig.getProxyInfo(),
|
|
||||||
cOrig.getNonLazyInfo(),
|
|
||||||
cOrig.getNoProxyOwner(),
|
|
||||||
cOrig.getProxyOwner(),
|
|
||||||
cOrig.getNonLazyOwner(),
|
|
||||||
cOrig.getLazyDataPoints().iterator().next(),
|
|
||||||
cOrig.getNonLazyJoinDataPoints().iterator().next(),
|
|
||||||
cOrig.getNonLazySelectDataPoints().iterator().next()
|
|
||||||
)
|
|
||||||
);
|
|
||||||
Set expectedReadOnlyObjects = new HashSet();
|
|
||||||
|
|
||||||
Session s = openSession();
|
|
||||||
assertFalse( s.isDefaultReadOnly() );
|
|
||||||
Transaction t = s.beginTransaction();
|
|
||||||
s.save( cOrig );
|
|
||||||
checkContainer( cOrig, expectedInitializedObjects, expectedReadOnlyObjects, s );
|
|
||||||
s.setDefaultReadOnly( true );
|
|
||||||
assertTrue( s.isDefaultReadOnly() );
|
|
||||||
checkContainer( cOrig, expectedInitializedObjects, expectedReadOnlyObjects, s );
|
|
||||||
t.commit();
|
|
||||||
s.close();
|
|
||||||
|
|
||||||
s = openSession();
|
|
||||||
t = s.beginTransaction();
|
|
||||||
assertFalse( s.isDefaultReadOnly() );
|
|
||||||
Container c = ( Container ) s.get( Container.class, cOrig.getId() );
|
|
||||||
assertNotSame( cOrig, c );
|
|
||||||
expectedInitializedObjects = new HashSet(
|
|
||||||
Arrays.asList(
|
|
||||||
c,
|
|
||||||
c.getNonLazyInfo(),
|
|
||||||
c.getNoProxyOwner(),
|
|
||||||
c.getProxyOwner(),
|
|
||||||
c.getNonLazyOwner(),
|
|
||||||
c.getNonLazyJoinDataPoints().iterator().next(),
|
|
||||||
c.getNonLazySelectDataPoints().iterator().next()
|
|
||||||
)
|
|
||||||
);
|
|
||||||
expectedReadOnlyObjects = new HashSet();
|
|
||||||
List list = s.createFilter( c.getLazyDataPoints(), "" )
|
|
||||||
.setMaxResults(1)
|
|
||||||
.setReadOnly( true )
|
|
||||||
.list();
|
|
||||||
assertEquals( 1, list.size() );
|
|
||||||
assertTrue( s.isReadOnly( list.get( 0 ) ) );
|
|
||||||
list = s.createFilter( c.getNonLazyJoinDataPoints(), "" )
|
|
||||||
.setMaxResults(1)
|
|
||||||
.setReadOnly( true )
|
|
||||||
.list();
|
|
||||||
assertEquals( 1, list.size() );
|
|
||||||
assertFalse( s.isReadOnly( list.get( 0 ) ) );
|
|
||||||
list = s.createFilter( c.getNonLazySelectDataPoints(), "" )
|
|
||||||
.setMaxResults(1)
|
|
||||||
.setReadOnly( true )
|
|
||||||
.list();
|
|
||||||
assertEquals( 1, list.size() );
|
|
||||||
assertFalse( s.isReadOnly( list.get( 0 ) ) );
|
|
||||||
t.commit();
|
|
||||||
s.close();
|
|
||||||
s = openSession();
|
|
||||||
t = s.beginTransaction();
|
|
||||||
s.createQuery("delete from DataPoint").executeUpdate();
|
|
||||||
s.createQuery("delete from Container").executeUpdate();
|
|
||||||
s.createQuery("delete from Info").executeUpdate();
|
|
||||||
s.createQuery("delete from Owner").executeUpdate();
|
|
||||||
t.commit();
|
|
||||||
s.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings( {"unchecked"})
|
|
||||||
@Test
|
|
||||||
public void testDefaultReadOnlyWithFilterCollectionEntities() {
|
|
||||||
Container cOrig = createContainer();
|
|
||||||
Set expectedInitializedObjects = new HashSet(
|
|
||||||
Arrays.asList(
|
|
||||||
cOrig,
|
|
||||||
cOrig.getNoProxyInfo(),
|
|
||||||
cOrig.getProxyInfo(),
|
|
||||||
cOrig.getNonLazyInfo(),
|
|
||||||
cOrig.getNoProxyOwner(),
|
|
||||||
cOrig.getProxyOwner(),
|
|
||||||
cOrig.getNonLazyOwner(),
|
|
||||||
cOrig.getLazyDataPoints().iterator().next(),
|
|
||||||
cOrig.getNonLazyJoinDataPoints().iterator().next(),
|
|
||||||
cOrig.getNonLazySelectDataPoints().iterator().next()
|
|
||||||
)
|
|
||||||
);
|
|
||||||
Set expectedReadOnlyObjects = new HashSet();
|
|
||||||
|
|
||||||
Session s = openSession();
|
|
||||||
assertFalse( s.isDefaultReadOnly() );
|
|
||||||
Transaction t = s.beginTransaction();
|
|
||||||
s.save( cOrig );
|
|
||||||
checkContainer( cOrig, expectedInitializedObjects, expectedReadOnlyObjects, s );
|
|
||||||
s.setDefaultReadOnly( true );
|
|
||||||
assertTrue( s.isDefaultReadOnly() );
|
|
||||||
checkContainer( cOrig, expectedInitializedObjects, expectedReadOnlyObjects, s );
|
|
||||||
t.commit();
|
|
||||||
s.close();
|
|
||||||
|
|
||||||
s = openSession();
|
|
||||||
t = s.beginTransaction();
|
|
||||||
s.setDefaultReadOnly( true );
|
|
||||||
assertTrue( s.isDefaultReadOnly() );
|
|
||||||
Container c = ( Container ) s.get( Container.class, cOrig.getId() );
|
|
||||||
assertNotSame( cOrig, c );
|
|
||||||
expectedInitializedObjects = new HashSet(
|
|
||||||
Arrays.asList(
|
|
||||||
c,
|
|
||||||
c.getNonLazyInfo(),
|
|
||||||
c.getNoProxyOwner(),
|
|
||||||
c.getProxyOwner(),
|
|
||||||
c.getNonLazyOwner(),
|
|
||||||
c.getNonLazyJoinDataPoints().iterator().next(),
|
|
||||||
c.getNonLazySelectDataPoints().iterator().next()
|
|
||||||
)
|
|
||||||
);
|
|
||||||
expectedReadOnlyObjects = new HashSet(
|
|
||||||
Arrays.asList(
|
|
||||||
c,
|
|
||||||
c.getNoProxyInfo(),
|
|
||||||
c.getProxyInfo(),
|
|
||||||
c.getNonLazyInfo(),
|
|
||||||
c.getNoProxyOwner(),
|
|
||||||
c.getProxyOwner(),
|
|
||||||
c.getNonLazyOwner(),
|
|
||||||
//c.getLazyDataPoints(),
|
|
||||||
c.getNonLazyJoinDataPoints().iterator().next(),
|
|
||||||
c.getNonLazySelectDataPoints().iterator().next()
|
|
||||||
)
|
|
||||||
);
|
|
||||||
List list = s.createFilter( c.getLazyDataPoints(), "" )
|
|
||||||
.setMaxResults( 1 )
|
|
||||||
.list();
|
|
||||||
assertEquals( 1, list.size() );
|
|
||||||
assertTrue( s.isReadOnly( list.get( 0 ) ) );
|
|
||||||
list = s.createFilter( c.getNonLazyJoinDataPoints(), "" )
|
|
||||||
.setMaxResults( 1 )
|
|
||||||
.list();
|
|
||||||
assertEquals( 1, list.size() );
|
|
||||||
assertTrue( s.isReadOnly( list.get( 0 ) ) );
|
|
||||||
list = s.createFilter( c.getNonLazySelectDataPoints(), "" )
|
|
||||||
.setMaxResults( 1 )
|
|
||||||
.list();
|
|
||||||
assertEquals( 1, list.size() );
|
|
||||||
assertTrue( s.isReadOnly( list.get( 0 ) ) );
|
|
||||||
t.commit();
|
|
||||||
s.close();
|
|
||||||
s = openSession();
|
|
||||||
t = s.beginTransaction();
|
|
||||||
s.createQuery("delete from DataPoint").executeUpdate();
|
|
||||||
s.createQuery("delete from Container").executeUpdate();
|
|
||||||
s.createQuery("delete from Info").executeUpdate();
|
|
||||||
s.createQuery("delete from Owner").executeUpdate();
|
|
||||||
t.commit();
|
|
||||||
s.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings( {"unchecked"})
|
|
||||||
@Test
|
|
||||||
public void testDefaultModifiableWithFilterCollectionEntities() {
|
|
||||||
Container cOrig = createContainer();
|
|
||||||
Set expectedInitializedObjects = new HashSet(
|
|
||||||
Arrays.asList(
|
|
||||||
cOrig,
|
|
||||||
cOrig.getNoProxyInfo(),
|
|
||||||
cOrig.getProxyInfo(),
|
|
||||||
cOrig.getNonLazyInfo(),
|
|
||||||
cOrig.getNoProxyOwner(),
|
|
||||||
cOrig.getProxyOwner(),
|
|
||||||
cOrig.getNonLazyOwner(),
|
|
||||||
cOrig.getLazyDataPoints().iterator().next(),
|
|
||||||
cOrig.getNonLazyJoinDataPoints().iterator().next(),
|
|
||||||
cOrig.getNonLazySelectDataPoints().iterator().next()
|
|
||||||
)
|
|
||||||
);
|
|
||||||
Set expectedReadOnlyObjects = new HashSet();
|
|
||||||
|
|
||||||
Session s = openSession();
|
|
||||||
assertFalse( s.isDefaultReadOnly() );
|
|
||||||
Transaction t = s.beginTransaction();
|
|
||||||
s.save( cOrig );
|
|
||||||
checkContainer( cOrig, expectedInitializedObjects, expectedReadOnlyObjects, s );
|
|
||||||
s.setDefaultReadOnly( true );
|
|
||||||
assertTrue( s.isDefaultReadOnly() );
|
|
||||||
checkContainer( cOrig, expectedInitializedObjects, expectedReadOnlyObjects, s );
|
|
||||||
t.commit();
|
|
||||||
s.close();
|
|
||||||
|
|
||||||
s = openSession();
|
|
||||||
t = s.beginTransaction();
|
|
||||||
assertFalse( s.isDefaultReadOnly() );
|
|
||||||
Container c = ( Container ) s.get( Container.class, cOrig.getId() );
|
|
||||||
assertNotSame( cOrig, c );
|
|
||||||
expectedInitializedObjects = new HashSet(
|
|
||||||
Arrays.asList(
|
|
||||||
c,
|
|
||||||
c.getNonLazyInfo(),
|
|
||||||
c.getNoProxyOwner(),
|
|
||||||
c.getProxyOwner(),
|
|
||||||
c.getNonLazyOwner(),
|
|
||||||
c.getNonLazyJoinDataPoints().iterator().next(),
|
|
||||||
c.getNonLazySelectDataPoints().iterator().next()
|
|
||||||
)
|
|
||||||
);
|
|
||||||
expectedReadOnlyObjects = new HashSet();
|
|
||||||
List list = s.createFilter( c.getLazyDataPoints(), "" )
|
|
||||||
.setMaxResults( 1 )
|
|
||||||
.list();
|
|
||||||
assertEquals( 1, list.size() );
|
|
||||||
assertFalse( s.isReadOnly( list.get( 0 ) ) );
|
|
||||||
list = s.createFilter( c.getNonLazyJoinDataPoints(), "" )
|
|
||||||
.setMaxResults( 1 )
|
|
||||||
.list();
|
|
||||||
assertEquals( 1, list.size() );
|
|
||||||
assertFalse( s.isReadOnly( list.get( 0 ) ) );
|
|
||||||
list = s.createFilter( c.getNonLazySelectDataPoints(), "" )
|
|
||||||
.setMaxResults( 1 )
|
|
||||||
.list();
|
|
||||||
assertEquals( 1, list.size() );
|
|
||||||
assertFalse( s.isReadOnly( list.get( 0 ) ) );
|
|
||||||
t.commit();
|
|
||||||
s.close();
|
|
||||||
s = openSession();
|
|
||||||
t = s.beginTransaction();
|
|
||||||
s.createQuery("delete from DataPoint").executeUpdate();
|
|
||||||
s.createQuery("delete from Container").executeUpdate();
|
|
||||||
s.createQuery("delete from Info").executeUpdate();
|
|
||||||
s.createQuery("delete from Owner").executeUpdate();
|
|
||||||
t.commit();
|
|
||||||
s.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
private Container createContainer() {
|
|
||||||
Container c = new Container( "container" );
|
|
||||||
c.setNoProxyInfo( new Info( "no-proxy info" ) );
|
|
||||||
c.setProxyInfo( new Info( "proxy info" ) );
|
|
||||||
c.setNonLazyInfo( new Info( "non-lazy info" ) );
|
|
||||||
c.setNoProxyOwner( new Owner( "no-proxy owner" ) );
|
|
||||||
c.setProxyOwner( new Owner( "proxy owner" ) );
|
|
||||||
c.setNonLazyOwner( new Owner( "non-lazy owner" ) );
|
|
||||||
c.getLazyDataPoints().add( new DataPoint( new BigDecimal( 1 ), new BigDecimal( 1 ), "lazy data point" ) );
|
|
||||||
c.getNonLazyJoinDataPoints().add( new DataPoint( new BigDecimal( 2 ), new BigDecimal( 2 ), "non-lazy join data point" ) );
|
|
||||||
c.getNonLazySelectDataPoints().add( new DataPoint( new BigDecimal( 3 ), new BigDecimal( 3 ), "non-lazy select data point" ) );
|
|
||||||
return c;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void checkContainer(Container c, Set expectedInitializedObjects, Set expectedReadOnlyObjects, Session s) {
|
|
||||||
checkObject( c, expectedInitializedObjects, expectedReadOnlyObjects, s );
|
|
||||||
if ( ! expectedInitializedObjects.contains( c ) ) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
checkObject( c.getNoProxyInfo(), expectedInitializedObjects, expectedReadOnlyObjects, s);
|
|
||||||
checkObject( c.getProxyInfo(), expectedInitializedObjects, expectedReadOnlyObjects, s);
|
|
||||||
checkObject( c.getNonLazyInfo(), expectedInitializedObjects, expectedReadOnlyObjects, s );
|
|
||||||
checkObject( c.getNoProxyOwner(), expectedInitializedObjects, expectedReadOnlyObjects, s );
|
|
||||||
checkObject( c.getProxyOwner(), expectedInitializedObjects, expectedReadOnlyObjects, s );
|
|
||||||
checkObject( c.getNonLazyOwner(), expectedInitializedObjects, expectedReadOnlyObjects, s );
|
|
||||||
if ( Hibernate.isInitialized( c.getLazyDataPoints() ) ) {
|
|
||||||
for ( Iterator it=c.getLazyDataPoints().iterator(); it.hasNext(); ) {
|
|
||||||
checkObject( it.next(), expectedInitializedObjects, expectedReadOnlyObjects, s );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for ( Iterator it=c.getNonLazyJoinDataPoints().iterator(); it.hasNext(); ) {
|
|
||||||
checkObject( it.next(), expectedInitializedObjects, expectedReadOnlyObjects, s );
|
|
||||||
}
|
|
||||||
for ( Iterator it=c.getNonLazySelectDataPoints().iterator(); it.hasNext(); ) {
|
|
||||||
checkObject( it.next(), expectedInitializedObjects, expectedReadOnlyObjects, s );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void checkObject(Object entityOrProxy, Set expectedInitializedObjects, Set expectedReadOnlyObjects, Session s) {
|
|
||||||
boolean isExpectedToBeInitialized = expectedInitializedObjects.contains( entityOrProxy );
|
|
||||||
boolean isExpectedToBeReadOnly = expectedReadOnlyObjects.contains( entityOrProxy );
|
|
||||||
SessionImplementor si = (SessionImplementor) s;
|
|
||||||
assertEquals( isExpectedToBeInitialized, Hibernate.isInitialized( entityOrProxy ) );
|
|
||||||
assertEquals( isExpectedToBeReadOnly, s.isReadOnly( entityOrProxy ) );
|
|
||||||
if ( Hibernate.isInitialized( entityOrProxy ) ) {
|
|
||||||
Object entity = ( entityOrProxy instanceof HibernateProxy ?
|
|
||||||
( ( HibernateProxy ) entityOrProxy ).getHibernateLazyInitializer().getImplementation( si ) :
|
|
||||||
entityOrProxy
|
|
||||||
);
|
|
||||||
assertNotNull( entity );
|
|
||||||
assertEquals( isExpectedToBeReadOnly, s.isReadOnly( entity ));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,344 +0,0 @@
|
||||||
/*
|
|
||||||
* 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.test.readonly;
|
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.hibernate.CacheMode;
|
|
||||||
import org.hibernate.Session;
|
|
||||||
import org.hibernate.Transaction;
|
|
||||||
import org.hibernate.query.Query;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.assertFalse;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Andrea Boriero
|
|
||||||
*/
|
|
||||||
public class ReadOnlySessionQueryIteratorTest extends AbstractReadOnlyTest {
|
|
||||||
@Override
|
|
||||||
public String[] getMappings() {
|
|
||||||
return new String[] { "readonly/DataPoint.hbm.xml", "readonly/TextHolder.hbm.xml" };
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testReadOnlySessionDefaultQueryIterate() {
|
|
||||||
Session s = openSession();
|
|
||||||
s.setCacheMode( CacheMode.IGNORE );
|
|
||||||
Transaction t = s.beginTransaction();
|
|
||||||
for ( int i = 0; i < 100; i++ ) {
|
|
||||||
DataPoint dp = new DataPoint();
|
|
||||||
dp.setX( new BigDecimal( i * 0.1d ).setScale( 19, BigDecimal.ROUND_DOWN ) );
|
|
||||||
dp.setY( new BigDecimal( Math.cos( dp.getX().doubleValue() ) ).setScale( 19, BigDecimal.ROUND_DOWN ) );
|
|
||||||
s.save( dp );
|
|
||||||
}
|
|
||||||
t.commit();
|
|
||||||
s.close();
|
|
||||||
|
|
||||||
s = openSession();
|
|
||||||
s.setCacheMode( CacheMode.IGNORE );
|
|
||||||
t = s.beginTransaction();
|
|
||||||
s.setDefaultReadOnly( true );
|
|
||||||
int i = 0;
|
|
||||||
Iterator it = s.createQuery( "from DataPoint dp order by dp.x asc" )
|
|
||||||
.iterate();
|
|
||||||
s.setDefaultReadOnly( false );
|
|
||||||
while ( it.hasNext() ) {
|
|
||||||
DataPoint dp = (DataPoint) it.next();
|
|
||||||
if ( ++i == 50 ) {
|
|
||||||
s.setReadOnly( dp, false );
|
|
||||||
}
|
|
||||||
dp.setDescription( "done!" );
|
|
||||||
}
|
|
||||||
t.commit();
|
|
||||||
s.clear();
|
|
||||||
t = s.beginTransaction();
|
|
||||||
List single = s.createQuery( "from DataPoint where description='done!'" ).list();
|
|
||||||
assertEquals( 1, single.size() );
|
|
||||||
s.createQuery( "delete from DataPoint" ).executeUpdate();
|
|
||||||
t.commit();
|
|
||||||
s.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testReadOnlySessionModifiableQueryIterate() {
|
|
||||||
Session s = openSession();
|
|
||||||
s.setCacheMode(CacheMode.IGNORE);
|
|
||||||
Transaction t = s.beginTransaction();
|
|
||||||
for ( int i=0; i<100; i++ ) {
|
|
||||||
DataPoint dp = new DataPoint();
|
|
||||||
dp.setX( new BigDecimal(i * 0.1d).setScale(19, BigDecimal.ROUND_DOWN) );
|
|
||||||
dp.setY( new BigDecimal( Math.cos( dp.getX().doubleValue() ) ).setScale(19, BigDecimal.ROUND_DOWN) );
|
|
||||||
s.save(dp);
|
|
||||||
}
|
|
||||||
t.commit();
|
|
||||||
s.close();
|
|
||||||
|
|
||||||
s = openSession();
|
|
||||||
s.setCacheMode(CacheMode.IGNORE);
|
|
||||||
t = s.beginTransaction();
|
|
||||||
s.setDefaultReadOnly( true );
|
|
||||||
int i = 0;
|
|
||||||
Iterator it = s.createQuery("from DataPoint dp order by dp.x asc")
|
|
||||||
.setReadOnly( false )
|
|
||||||
.iterate();
|
|
||||||
while ( it.hasNext() ) {
|
|
||||||
DataPoint dp = (DataPoint) it.next();
|
|
||||||
if (++i==50) {
|
|
||||||
s.setReadOnly(dp, true);
|
|
||||||
}
|
|
||||||
dp.setDescription("done!");
|
|
||||||
}
|
|
||||||
t.commit();
|
|
||||||
s.clear();
|
|
||||||
t = s.beginTransaction();
|
|
||||||
List list = s.createQuery("from DataPoint where description='done!'").list();
|
|
||||||
assertEquals( 99, list.size() );
|
|
||||||
s.createQuery("delete from DataPoint").executeUpdate();
|
|
||||||
t.commit();
|
|
||||||
s.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testModifiableSessionReadOnlyQueryIterate() {
|
|
||||||
Session s = openSession();
|
|
||||||
s.setCacheMode(CacheMode.IGNORE);
|
|
||||||
Transaction t = s.beginTransaction();
|
|
||||||
for ( int i=0; i<100; i++ ) {
|
|
||||||
DataPoint dp = new DataPoint();
|
|
||||||
dp.setX( new BigDecimal(i * 0.1d).setScale(19, BigDecimal.ROUND_DOWN) );
|
|
||||||
dp.setY( new BigDecimal( Math.cos( dp.getX().doubleValue() ) ).setScale(19, BigDecimal.ROUND_DOWN) );
|
|
||||||
s.save(dp);
|
|
||||||
}
|
|
||||||
t.commit();
|
|
||||||
s.close();
|
|
||||||
|
|
||||||
s = openSession();
|
|
||||||
s.setCacheMode(CacheMode.IGNORE);
|
|
||||||
t = s.beginTransaction();
|
|
||||||
assertFalse( s.isDefaultReadOnly() );
|
|
||||||
int i = 0;
|
|
||||||
Iterator it = s.createQuery("from DataPoint dp order by dp.x asc")
|
|
||||||
.setReadOnly( true )
|
|
||||||
.iterate();
|
|
||||||
while ( it.hasNext() ) {
|
|
||||||
DataPoint dp = (DataPoint) it.next();
|
|
||||||
if (++i==50) {
|
|
||||||
s.setReadOnly(dp, false);
|
|
||||||
}
|
|
||||||
dp.setDescription("done!");
|
|
||||||
}
|
|
||||||
t.commit();
|
|
||||||
s.clear();
|
|
||||||
t = s.beginTransaction();
|
|
||||||
List single = s.createQuery("from DataPoint where description='done!'").list();
|
|
||||||
assertEquals( 1, single.size() );
|
|
||||||
s.createQuery("delete from DataPoint").executeUpdate();
|
|
||||||
t.commit();
|
|
||||||
s.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testModifiableSessionDefaultQueryReadOnlySessionIterate() {
|
|
||||||
Session s = openSession();
|
|
||||||
s.setCacheMode(CacheMode.IGNORE);
|
|
||||||
Transaction t = s.beginTransaction();
|
|
||||||
for ( int i=0; i<100; i++ ) {
|
|
||||||
DataPoint dp = new DataPoint();
|
|
||||||
dp.setX( new BigDecimal(i * 0.1d).setScale(19, BigDecimal.ROUND_DOWN) );
|
|
||||||
dp.setY( new BigDecimal( Math.cos( dp.getX().doubleValue() ) ).setScale(19, BigDecimal.ROUND_DOWN) );
|
|
||||||
s.save(dp);
|
|
||||||
}
|
|
||||||
t.commit();
|
|
||||||
s.close();
|
|
||||||
|
|
||||||
s = openSession();
|
|
||||||
s.setCacheMode(CacheMode.IGNORE);
|
|
||||||
t = s.beginTransaction();
|
|
||||||
s.setDefaultReadOnly( false );
|
|
||||||
int i = 0;
|
|
||||||
Query query = s.createQuery( "from DataPoint dp order by dp.x asc");
|
|
||||||
s.setDefaultReadOnly( true );
|
|
||||||
Iterator it = query.iterate();
|
|
||||||
s.setDefaultReadOnly( false );
|
|
||||||
while ( it.hasNext() ) {
|
|
||||||
DataPoint dp = (DataPoint) it.next();
|
|
||||||
if (++i==50) {
|
|
||||||
s.setReadOnly(dp, false);
|
|
||||||
}
|
|
||||||
dp.setDescription("done!");
|
|
||||||
}
|
|
||||||
t.commit();
|
|
||||||
s.clear();
|
|
||||||
t = s.beginTransaction();
|
|
||||||
List single = s.createQuery("from DataPoint where description='done!'").list();
|
|
||||||
assertEquals( 1, single.size() );
|
|
||||||
s.createQuery("delete from DataPoint").executeUpdate();
|
|
||||||
t.commit();
|
|
||||||
s.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testQueryReadOnlyIterate() {
|
|
||||||
Session s = openSession();
|
|
||||||
s.setCacheMode(CacheMode.IGNORE);
|
|
||||||
Transaction t = s.beginTransaction();
|
|
||||||
DataPoint dp = null;
|
|
||||||
for ( int i=0; i<100; i++ ) {
|
|
||||||
dp = new DataPoint();
|
|
||||||
dp.setX( new BigDecimal(i * 0.1d).setScale(19, BigDecimal.ROUND_DOWN) );
|
|
||||||
dp.setY( new BigDecimal( Math.cos( dp.getX().doubleValue() ) ).setScale(19, BigDecimal.ROUND_DOWN) );
|
|
||||||
s.save(dp);
|
|
||||||
}
|
|
||||||
t.commit();
|
|
||||||
s.close();
|
|
||||||
|
|
||||||
s = openSession();
|
|
||||||
s.setCacheMode(CacheMode.IGNORE);
|
|
||||||
t = s.beginTransaction();
|
|
||||||
s.setDefaultReadOnly( false );
|
|
||||||
int i = 0;
|
|
||||||
Query query = s.createQuery("from DataPoint dp order by dp.x asc");
|
|
||||||
assertFalse( query.isReadOnly() );
|
|
||||||
s.setDefaultReadOnly( true );
|
|
||||||
assertTrue( query.isReadOnly() );
|
|
||||||
s.setDefaultReadOnly( false );
|
|
||||||
assertFalse( query.isReadOnly() );
|
|
||||||
query.setReadOnly( true );
|
|
||||||
assertTrue( query.isReadOnly() );
|
|
||||||
s.setDefaultReadOnly( true );
|
|
||||||
assertTrue( query.isReadOnly() );
|
|
||||||
s.setDefaultReadOnly( false );
|
|
||||||
assertTrue( query.isReadOnly() );
|
|
||||||
query.setReadOnly( false );
|
|
||||||
assertFalse( query.isReadOnly() );
|
|
||||||
s.setDefaultReadOnly( true );
|
|
||||||
assertFalse( query.isReadOnly() );
|
|
||||||
query.setReadOnly( true );
|
|
||||||
assertTrue( query.isReadOnly() );
|
|
||||||
s.setDefaultReadOnly( false );
|
|
||||||
assertFalse( s.isDefaultReadOnly() );
|
|
||||||
Iterator it = query.iterate();
|
|
||||||
assertTrue( query.isReadOnly() );
|
|
||||||
DataPoint dpLast = ( DataPoint ) s.get( DataPoint.class, dp.getId() );
|
|
||||||
assertFalse( s.isReadOnly( dpLast ) );
|
|
||||||
query.setReadOnly( false );
|
|
||||||
assertFalse( query.isReadOnly() );
|
|
||||||
int nExpectedChanges = 0;
|
|
||||||
assertFalse( s.isDefaultReadOnly() );
|
|
||||||
while ( it.hasNext() ) {
|
|
||||||
assertFalse( s.isDefaultReadOnly() );
|
|
||||||
dp = (DataPoint) it.next();
|
|
||||||
assertFalse( s.isDefaultReadOnly() );
|
|
||||||
if ( dp.getId() == dpLast.getId() ) {
|
|
||||||
//dpLast existed in the session before executing the read-only query
|
|
||||||
assertFalse( s.isReadOnly( dp ) );
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
assertTrue( s.isReadOnly( dp ) );
|
|
||||||
}
|
|
||||||
if (++i==50) {
|
|
||||||
s.setReadOnly(dp, false);
|
|
||||||
nExpectedChanges = ( dp == dpLast ? 1 : 2 );
|
|
||||||
}
|
|
||||||
dp.setDescription("done!");
|
|
||||||
}
|
|
||||||
assertFalse( s.isDefaultReadOnly() );
|
|
||||||
t.commit();
|
|
||||||
s.clear();
|
|
||||||
t = s.beginTransaction();
|
|
||||||
List list = s.createQuery("from DataPoint where description='done!'").list();
|
|
||||||
assertEquals( nExpectedChanges, list.size() );
|
|
||||||
s.createQuery("delete from DataPoint").executeUpdate();
|
|
||||||
t.commit();
|
|
||||||
s.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testQueryModifiableIterate() {
|
|
||||||
Session s = openSession();
|
|
||||||
s.setCacheMode(CacheMode.IGNORE);
|
|
||||||
Transaction t = s.beginTransaction();
|
|
||||||
DataPoint dp = null;
|
|
||||||
for ( int i=0; i<100; i++ ) {
|
|
||||||
dp = new DataPoint();
|
|
||||||
dp.setX( new BigDecimal(i * 0.1d).setScale(19, BigDecimal.ROUND_DOWN) );
|
|
||||||
dp.setY( new BigDecimal( Math.cos( dp.getX().doubleValue() ) ).setScale(19, BigDecimal.ROUND_DOWN) );
|
|
||||||
s.save(dp);
|
|
||||||
}
|
|
||||||
t.commit();
|
|
||||||
s.close();
|
|
||||||
|
|
||||||
s = openSession();
|
|
||||||
s.setCacheMode(CacheMode.IGNORE);
|
|
||||||
t = s.beginTransaction();
|
|
||||||
s.setDefaultReadOnly( true );
|
|
||||||
int i = 0;
|
|
||||||
Query query = s.createQuery("from DataPoint dp order by dp.x asc");
|
|
||||||
assertTrue( query.isReadOnly() );
|
|
||||||
s.setDefaultReadOnly( false );
|
|
||||||
assertFalse( query.isReadOnly() );
|
|
||||||
s.setDefaultReadOnly( true );
|
|
||||||
assertTrue( query.isReadOnly() );
|
|
||||||
query.setReadOnly( false );
|
|
||||||
assertFalse( query.isReadOnly() );
|
|
||||||
s.setDefaultReadOnly( false );
|
|
||||||
assertFalse( query.isReadOnly() );
|
|
||||||
s.setDefaultReadOnly( true );
|
|
||||||
assertFalse( query.isReadOnly() );
|
|
||||||
query.setReadOnly( true );
|
|
||||||
assertTrue( query.isReadOnly() );
|
|
||||||
s.setDefaultReadOnly( false );
|
|
||||||
assertTrue( query.isReadOnly() );
|
|
||||||
query.setReadOnly( false );
|
|
||||||
assertFalse( query.isReadOnly() );
|
|
||||||
s.setDefaultReadOnly( true );
|
|
||||||
assertTrue( s.isDefaultReadOnly() );
|
|
||||||
Iterator it = query.iterate();
|
|
||||||
assertFalse( query.isReadOnly() );
|
|
||||||
DataPoint dpLast = ( DataPoint ) s.get( DataPoint.class, dp.getId() );
|
|
||||||
assertTrue( s.isReadOnly( dpLast ) );
|
|
||||||
query.setReadOnly( true );
|
|
||||||
assertTrue( query.isReadOnly() );
|
|
||||||
int nExpectedChanges = 0;
|
|
||||||
assertTrue( s.isDefaultReadOnly() );
|
|
||||||
while ( it.hasNext() ) {
|
|
||||||
assertTrue( s.isDefaultReadOnly() );
|
|
||||||
dp = (DataPoint) it.next();
|
|
||||||
assertTrue( s.isDefaultReadOnly() );
|
|
||||||
if ( dp.getId() == dpLast.getId() ) {
|
|
||||||
//dpLast existed in the session before executing the read-only query
|
|
||||||
assertTrue( s.isReadOnly( dp ) );
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
assertFalse( s.isReadOnly( dp ) );
|
|
||||||
}
|
|
||||||
if (++i==50) {
|
|
||||||
s.setReadOnly(dp, true);
|
|
||||||
nExpectedChanges = ( dp == dpLast ? 99 : 98 );
|
|
||||||
}
|
|
||||||
dp.setDescription("done!");
|
|
||||||
}
|
|
||||||
assertTrue( s.isDefaultReadOnly() );
|
|
||||||
t.commit();
|
|
||||||
s.clear();
|
|
||||||
t = s.beginTransaction();
|
|
||||||
List list = s.createQuery("from DataPoint where description='done!'").list();
|
|
||||||
assertEquals( nExpectedChanges, list.size() );
|
|
||||||
s.createQuery("delete from DataPoint").executeUpdate();
|
|
||||||
t.commit();
|
|
||||||
s.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,191 +0,0 @@
|
||||||
/*
|
|
||||||
* 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.test.reattachment;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.assertFalse;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import org.hibernate.Hibernate;
|
|
||||||
import org.hibernate.Session;
|
|
||||||
import org.hibernate.proxy.HibernateProxy;
|
|
||||||
|
|
||||||
import org.hibernate.testing.TestForIssue;
|
|
||||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test of proxy reattachment semantics
|
|
||||||
*
|
|
||||||
* @author Steve Ebersole
|
|
||||||
*/
|
|
||||||
public class ProxyReattachmentTest extends BaseCoreFunctionalTestCase {
|
|
||||||
public String[] getMappings() {
|
|
||||||
return new String[] { "reattachment/Mappings.hbm.xml" };
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings( {"unchecked"})
|
|
||||||
public void testIterateWithClearTopOfLoop() {
|
|
||||||
Session s = openSession();
|
|
||||||
s.beginTransaction();
|
|
||||||
Set parents = new HashSet();
|
|
||||||
for (int i=0; i<5; i++) {
|
|
||||||
Parent p = new Parent( String.valueOf( i ) );
|
|
||||||
Child child = new Child( "child" + i );
|
|
||||||
child.setParent( p );
|
|
||||||
p.getChildren().add( child );
|
|
||||||
s.save( p );
|
|
||||||
parents.add(p);
|
|
||||||
}
|
|
||||||
s.getTransaction().commit();
|
|
||||||
s.close();
|
|
||||||
|
|
||||||
s = openSession();
|
|
||||||
s.beginTransaction();
|
|
||||||
int i = 0;
|
|
||||||
for ( Iterator it = session.createQuery( "from Parent p " ).iterate(); it.hasNext(); ) {
|
|
||||||
i++;
|
|
||||||
if (i % 2 == 0) {
|
|
||||||
s.flush();
|
|
||||||
s.clear();
|
|
||||||
}
|
|
||||||
Parent p = (Parent) it.next();
|
|
||||||
|
|
||||||
assertEquals( 1, p.getChildren().size() );
|
|
||||||
}
|
|
||||||
s.getTransaction().commit();
|
|
||||||
s.close();
|
|
||||||
|
|
||||||
s = openSession();
|
|
||||||
s.beginTransaction();
|
|
||||||
for ( Object parent : parents ) {
|
|
||||||
s.delete( parent );
|
|
||||||
}
|
|
||||||
s.getTransaction().commit();
|
|
||||||
s.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@SuppressWarnings( {"unchecked"})
|
|
||||||
public void testIterateWithClearBottomOfLoop() {
|
|
||||||
Session s = openSession();
|
|
||||||
s.beginTransaction();
|
|
||||||
Set parents = new HashSet();
|
|
||||||
for (int i=0; i<5; i++) {
|
|
||||||
Parent p = new Parent( String.valueOf( i ) );
|
|
||||||
Child child = new Child( "child" + i );
|
|
||||||
child.setParent( p );
|
|
||||||
p.getChildren().add( child );
|
|
||||||
s.save( p );
|
|
||||||
parents.add(p);
|
|
||||||
}
|
|
||||||
s.getTransaction().commit();
|
|
||||||
s.close();
|
|
||||||
|
|
||||||
s = openSession();
|
|
||||||
s.beginTransaction();
|
|
||||||
int i = 0;
|
|
||||||
for (Iterator it = session.createQuery( "from Parent p " ).iterate(); it.hasNext(); ) {
|
|
||||||
Parent p = (Parent) it.next();
|
|
||||||
assertEquals( 1, p.getChildren().size() );
|
|
||||||
i++;
|
|
||||||
if (i % 2 == 0) {
|
|
||||||
s.flush();
|
|
||||||
s.clear();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
s.getTransaction().commit();
|
|
||||||
s.close();
|
|
||||||
|
|
||||||
s = openSession();
|
|
||||||
s.beginTransaction();
|
|
||||||
for ( Object parent : parents ) {
|
|
||||||
s.delete( parent );
|
|
||||||
}
|
|
||||||
s.getTransaction().commit();
|
|
||||||
s.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@SuppressWarnings( {"unchecked"})
|
|
||||||
public void testIterateWithEvictTopOfLoop() {
|
|
||||||
Session s = openSession();
|
|
||||||
s.beginTransaction();
|
|
||||||
Set parents = new HashSet();
|
|
||||||
for (int i=0; i<5; i++) {
|
|
||||||
Parent p = new Parent( String.valueOf( i + 100 ) );
|
|
||||||
Child child = new Child( "child" + i );
|
|
||||||
child.setParent( p );
|
|
||||||
p.getChildren().add( child );
|
|
||||||
s.save( p );
|
|
||||||
parents.add(p);
|
|
||||||
}
|
|
||||||
s.getTransaction().commit();
|
|
||||||
s.close();
|
|
||||||
|
|
||||||
s = openSession();
|
|
||||||
s.beginTransaction();
|
|
||||||
Parent p = null;
|
|
||||||
for (Iterator it = session.createQuery( "from Parent" ).iterate(); it.hasNext(); ) {
|
|
||||||
if ( p != null) { s.evict(p); }
|
|
||||||
p = (Parent) it.next();
|
|
||||||
assertEquals( 1, p.getChildren().size() );
|
|
||||||
}
|
|
||||||
s.getTransaction().commit();
|
|
||||||
s.close();
|
|
||||||
|
|
||||||
s = openSession();
|
|
||||||
s.beginTransaction();
|
|
||||||
for ( Object parent : parents ) {
|
|
||||||
s.delete( parent );
|
|
||||||
}
|
|
||||||
s.getTransaction().commit();
|
|
||||||
s.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@SuppressWarnings( {"unchecked"})
|
|
||||||
public void testIterateWithEvictBottomOfLoop() {
|
|
||||||
Session s = openSession();
|
|
||||||
s.beginTransaction();
|
|
||||||
Set parents = new HashSet();
|
|
||||||
for (int i=0; i<5; i++) {
|
|
||||||
Parent p = new Parent( String.valueOf( i + 100 ) );
|
|
||||||
Child child = new Child( "child" + i );
|
|
||||||
child.setParent( p );
|
|
||||||
p.getChildren().add( child );
|
|
||||||
s.save( p );
|
|
||||||
parents.add(p);
|
|
||||||
}
|
|
||||||
s.getTransaction().commit();
|
|
||||||
s.close();
|
|
||||||
|
|
||||||
s = openSession();
|
|
||||||
s.beginTransaction();
|
|
||||||
for (Iterator it = s.createQuery( "from Parent" ).iterate(); it.hasNext(); ) {
|
|
||||||
Parent p = (Parent) it.next();
|
|
||||||
assertEquals( 1, p.getChildren().size() );
|
|
||||||
s.evict(p);
|
|
||||||
}
|
|
||||||
s.getTransaction().commit();
|
|
||||||
s.close();
|
|
||||||
|
|
||||||
s = openSession();
|
|
||||||
s.beginTransaction();
|
|
||||||
for ( Object parent : parents ) {
|
|
||||||
s.delete( parent );
|
|
||||||
}
|
|
||||||
s.getTransaction().commit();
|
|
||||||
s.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in New Issue