mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-16 16:15:06 +00:00
HHH-3216 : ParameterParser + escaped function call syntax
git-svn-id: https://svn.jboss.org/repos/hibernate/core/branches/Branch_3_2@15239 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
parent
92e4a0413f
commit
9c37f6ad83
@ -370,4 +370,8 @@ public boolean supportsEmptyInList() {
|
||||
public boolean supportsLobValueChangePropogation() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean doesReadCommittedCauseWritersToBlockReaders() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Middleware LLC.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*
|
||||
*/
|
||||
package org.hibernate.test.engine.query;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.hibernate.engine.query.ParameterParser;
|
||||
|
||||
/**
|
||||
* Unit tests of the ParameterParser class
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class ParameterParserTest extends TestCase {
|
||||
public void testEscapeCallRecognition() {
|
||||
assertTrue( ParameterParser.startsWithEscapeCallTemplate( "{ ? = call abc(?) }" ) );
|
||||
assertFalse( ParameterParser.startsWithEscapeCallTemplate( "from User u where u.userName = ? and u.userType = 'call'" ) );
|
||||
}
|
||||
}
|
@ -125,7 +125,12 @@ public void testComponentNullnessChecks() {
|
||||
assertEquals( 1, results.size() );
|
||||
results = s.createQuery( "from Human where name is not null" ).list();
|
||||
assertEquals( 3, results.size() );
|
||||
s.createQuery( "from Human where ? is null" ).setParameter( 0, null ).list();
|
||||
String query =
|
||||
getDialect() instanceof DB2Dialect ?
|
||||
"from Human where cast(? as string) is null" :
|
||||
"from Human where ? is null"
|
||||
;
|
||||
s.createQuery( query ).setParameter( 0, null ).list();
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
|
||||
@ -202,13 +207,29 @@ public void testExpressionWithParamInFunction() {
|
||||
s.beginTransaction();
|
||||
s.createQuery( "from Animal a where abs(a.bodyWeight-:param) < 2.0" ).setLong( "param", 1 ).list();
|
||||
s.createQuery( "from Animal a where abs(:param - a.bodyWeight) < 2.0" ).setLong( "param", 1 ).list();
|
||||
if ( ! ( getDialect() instanceof HSQLDialect ) ) {
|
||||
// HSQLDB does not like the abs(? - ?) syntax...
|
||||
if ( ( getDialect() instanceof HSQLDialect ) || ( getDialect() instanceof DB2Dialect ) ) {
|
||||
// HSQLDB and DB2 don't like the abs(? - ?) syntax. bit work if at least one parameter is typed...
|
||||
s.createQuery( "from Animal where abs(cast(:x as long) - :y) < 2.0" ).setLong( "x", 1 ).setLong( "y", 1 ).list();
|
||||
s.createQuery( "from Animal where abs(:x - cast(:y as long)) < 2.0" ).setLong( "x", 1 ).setLong( "y", 1 ).list();
|
||||
s.createQuery( "from Animal where abs(cast(:x as long) - cast(:y as long)) < 2.0" ).setLong( "x", 1 ).setLong( "y", 1 ).list();
|
||||
}
|
||||
else {
|
||||
s.createQuery( "from Animal where abs(:x - :y) < 2.0" ).setLong( "x", 1 ).setLong( "y", 1 ).list();
|
||||
}
|
||||
s.createQuery( "from Animal where lower(upper(:foo)) like 'f%'" ).setString( "foo", "foo" ).list();
|
||||
|
||||
if ( getDialect() instanceof DB2Dialect ) {
|
||||
s.createQuery( "from Animal where lower(upper(cast(:foo as string))) like 'f%'" ).setString( "foo", "foo" ).list();
|
||||
}
|
||||
else {
|
||||
s.createQuery( "from Animal where lower(upper(:foo)) like 'f%'" ).setString( "foo", "foo" ).list();
|
||||
}
|
||||
s.createQuery( "from Animal a where abs(abs(a.bodyWeight - 1.0 + :param) * abs(length('ffobar')-3)) = 3.0" ).setLong( "param", 1 ).list();
|
||||
s.createQuery( "from Animal where lower(upper('foo') || upper(:bar)) like 'f%'" ).setString( "bar", "xyz" ).list();
|
||||
if ( getDialect() instanceof DB2Dialect ) {
|
||||
s.createQuery( "from Animal where lower(upper('foo') || upper(cast(:bar as string))) like 'f%'" ).setString( "bar", "xyz" ).list();
|
||||
}
|
||||
else {
|
||||
s.createQuery( "from Animal where lower(upper('foo') || upper(:bar)) like 'f%'" ).setString( "bar", "xyz" ).list();
|
||||
}
|
||||
if ( ! ( getDialect() instanceof PostgreSQLDialect || getDialect() instanceof MySQLDialect ) ) {
|
||||
s.createQuery( "from Animal where abs(cast(1 as float) - cast(:param as float)) = 1.0" ).setLong( "param", 1 ).list();
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ public static Test suite() {
|
||||
return new TestSuite( InstrumentTest.class );
|
||||
}
|
||||
|
||||
public void testDirtyCheck() {
|
||||
public void testDirtyCheck() throws Exception {
|
||||
execute( new TestDirtyCheckExecutable() );
|
||||
}
|
||||
|
||||
@ -43,31 +43,31 @@ public void testLazy() throws Exception {
|
||||
execute( new TestLazyExecutable() );
|
||||
}
|
||||
|
||||
public void testLazyManyToOne() {
|
||||
public void testLazyManyToOne() throws Exception {
|
||||
execute( new TestLazyManyToOneExecutable() );
|
||||
}
|
||||
|
||||
public void testSetFieldInterceptor() {
|
||||
public void testSetFieldInterceptor() throws Exception {
|
||||
execute( new TestInjectFieldInterceptorExecutable() );
|
||||
}
|
||||
|
||||
public void testPropertyInitialized() {
|
||||
public void testPropertyInitialized() throws Exception {
|
||||
execute( new TestIsPropertyInitializedExecutable() );
|
||||
}
|
||||
|
||||
public void testManyToOneProxy() {
|
||||
public void testManyToOneProxy() throws Exception {
|
||||
execute( new TestManyToOneProxyExecutable() );
|
||||
}
|
||||
|
||||
public void testLazyPropertyCustomTypeExecutable() {
|
||||
public void testLazyPropertyCustomTypeExecutable() throws Exception {
|
||||
execute( new TestLazyPropertyCustomTypeExecutable() );
|
||||
}
|
||||
|
||||
public void testSharedPKOneToOne() {
|
||||
public void testSharedPKOneToOne() throws Exception {
|
||||
execute( new TestSharedPKOneToOneExecutable() );
|
||||
}
|
||||
|
||||
private void execute(Executable executable) {
|
||||
private void execute(Executable executable) throws Exception {
|
||||
executable.prepare();
|
||||
try {
|
||||
executable.execute();
|
||||
|
@ -5,6 +5,6 @@
|
||||
*/
|
||||
public interface Executable {
|
||||
public void prepare();
|
||||
public void execute();
|
||||
public void execute() throws Exception;
|
||||
public void complete();
|
||||
}
|
||||
|
@ -19,39 +19,63 @@ protected String[] getResources() {
|
||||
return new String[] { "org/hibernate/test/instrument/domain/Problematic.hbm.xml" };
|
||||
}
|
||||
|
||||
public void execute() {
|
||||
public void execute() throws Exception {
|
||||
Session s = getFactory().openSession();
|
||||
s.beginTransaction();
|
||||
Problematic p = new Problematic();
|
||||
p.setName( "whatever" );
|
||||
p.setBytes( new byte[] { 1, 0, 1, 1, 0 } );
|
||||
s.save( p );
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
try {
|
||||
s.beginTransaction();
|
||||
p.setName( "whatever" );
|
||||
p.setBytes( new byte[] { 1, 0, 1, 1, 0 } );
|
||||
s.save( p );
|
||||
s.getTransaction().commit();
|
||||
} catch (Exception e) {
|
||||
s.getTransaction().rollback();
|
||||
throw e;
|
||||
} finally {
|
||||
s.close();
|
||||
}
|
||||
|
||||
// this access should be ok because p1 is not a lazy proxy
|
||||
s = getFactory().openSession();
|
||||
s.beginTransaction();
|
||||
Problematic p1 = (Problematic) s.get( Problematic.class, p.getId() );
|
||||
Assert.assertTrue( FieldInterceptionHelper.isInstrumented( p1 ) );
|
||||
p1.getRepresentation();
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
try {
|
||||
s.beginTransaction();
|
||||
Problematic p1 = (Problematic) s.get( Problematic.class, p.getId() );
|
||||
Assert.assertTrue( FieldInterceptionHelper.isInstrumented( p1 ) );
|
||||
p1.getRepresentation();
|
||||
s.getTransaction().commit();
|
||||
} catch (Exception e) {
|
||||
s.getTransaction().rollback();
|
||||
throw e;
|
||||
} finally {
|
||||
s.close();
|
||||
}
|
||||
|
||||
s = getFactory().openSession();
|
||||
s.beginTransaction();
|
||||
p1 = (Problematic) s.createQuery( "from Problematic" ).setReadOnly(true ).list().get( 0 );
|
||||
p1.getRepresentation();
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
try {
|
||||
s.beginTransaction();
|
||||
Problematic p1 = (Problematic) s.createQuery( "from Problematic" ).setReadOnly(true ).list().get( 0 );
|
||||
p1.getRepresentation();
|
||||
s.getTransaction().commit();
|
||||
} catch (Exception e) {
|
||||
s.getTransaction().rollback();
|
||||
throw e;
|
||||
} finally {
|
||||
s.close();
|
||||
}
|
||||
|
||||
s = getFactory().openSession();
|
||||
s.beginTransaction();
|
||||
p1 = (Problematic) s.load( Problematic.class, p.getId() );
|
||||
Assert.assertFalse( FieldInterceptionHelper.isInstrumented( p1 ) );
|
||||
p1.setRepresentation( p.getRepresentation() );
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
try {
|
||||
s.beginTransaction();
|
||||
Problematic p1 = (Problematic) s.load( Problematic.class, p.getId() );
|
||||
Assert.assertFalse( FieldInterceptionHelper.isInstrumented( p1 ) );
|
||||
p1.setRepresentation( p.getRepresentation() );
|
||||
s.getTransaction().commit();
|
||||
} catch (Exception e) {
|
||||
s.getTransaction().rollback();
|
||||
throw e;
|
||||
} finally {
|
||||
s.close();
|
||||
}
|
||||
}
|
||||
|
||||
protected void cleanup() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user