git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@19406 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
Hardy Ferentschik 2010-05-07 15:13:09 +00:00
parent 1a8a602e3c
commit 12d44898a5
7 changed files with 142 additions and 15 deletions

View File

@ -1,10 +1,34 @@
//$Id$ //$Id$
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2010, Red Hat Inc. 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 Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.test.annotations.id.sequences; package org.hibernate.test.annotations.id.sequences;
import org.hibernate.Session; import org.hibernate.Session;
import org.hibernate.Transaction; import org.hibernate.Transaction;
import org.hibernate.cfg.AnnotationConfiguration; import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Configuration;
import org.hibernate.junit.DialectChecks;
import org.hibernate.junit.RequiresDialectFeature; import org.hibernate.junit.RequiresDialectFeature;
import org.hibernate.mapping.Column; import org.hibernate.mapping.Column;
import org.hibernate.test.annotations.TestCase; import org.hibernate.test.annotations.TestCase;
@ -30,7 +54,7 @@ import org.hibernate.test.annotations.id.sequences.entities.Tree;
* @author Emmanuel Bernard * @author Emmanuel Bernard
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@RequiresDialectFeature("supportsSequences") @RequiresDialectFeature(DialectChecks.SupportsSequences.class)
public class IdTest extends TestCase { public class IdTest extends TestCase {
public void testGenericGenerator() throws Exception { public void testGenericGenerator() throws Exception {
Session s = openSession(); Session s = openSession();

View File

@ -1,15 +1,39 @@
//$Id$ //$Id$
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2010, Red Hat Inc. 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 Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.test.annotations.lob; package org.hibernate.test.annotations.lob;
import org.hibernate.Session; import org.hibernate.Session;
import org.hibernate.Transaction; import org.hibernate.Transaction;
import org.hibernate.junit.DialectChecks;
import org.hibernate.junit.RequiresDialectFeature; import org.hibernate.junit.RequiresDialectFeature;
import org.hibernate.test.annotations.TestCase; import org.hibernate.test.annotations.TestCase;
/** /**
* @author Emmanuel Bernard * @author Emmanuel Bernard
*/ */
@RequiresDialectFeature("supportsExpectedLobUsagePattern") @RequiresDialectFeature(DialectChecks.SupportsExpectedLobUsagePattern.class)
public class LobTest extends TestCase { public class LobTest extends TestCase {
public void testSerializableToBlob() throws Exception { public void testSerializableToBlob() throws Exception {
Book book = new Book(); Book book = new Book();

View File

@ -1,9 +1,33 @@
// $Id$ // $Id$
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2010, Red Hat Inc. 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 Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.test.annotations.manytoone.referencedcolumnname; package org.hibernate.test.annotations.manytoone.referencedcolumnname;
import java.math.BigDecimal; import java.math.BigDecimal;
import org.hibernate.Session; import org.hibernate.Session;
import org.hibernate.junit.DialectChecks;
import org.hibernate.junit.RequiresDialectFeature; import org.hibernate.junit.RequiresDialectFeature;
import org.hibernate.test.annotations.TestCase; import org.hibernate.test.annotations.TestCase;
@ -11,7 +35,7 @@ import org.hibernate.test.annotations.TestCase;
* @author Emmanuel Bernard * @author Emmanuel Bernard
*/ */
public class ManyToOneReferencedColumnNameTest extends TestCase { public class ManyToOneReferencedColumnNameTest extends TestCase {
@RequiresDialectFeature("supportsIdentityColumns") @RequiresDialectFeature(DialectChecks.SupportsIdentityColumns.class)
public void testReoverableExceptionInFkOrdering() throws Exception { public void testReoverableExceptionInFkOrdering() throws Exception {
//SF should not blow up //SF should not blow up
Vendor v = new Vendor(); Vendor v = new Vendor();
@ -34,7 +58,6 @@ public class ManyToOneReferencedColumnNameTest extends TestCase {
s.flush(); s.flush();
s.getTransaction().rollback(); s.getTransaction().rollback();
s.close(); s.close();
} }
protected Class[] getAnnotatedClasses() { protected Class[] getAnnotatedClasses() {

View File

@ -2,6 +2,7 @@
package org.hibernate.test.annotations.xml.hbm; package org.hibernate.test.annotations.xml.hbm;
import org.hibernate.Session; import org.hibernate.Session;
import org.hibernate.junit.DialectChecks;
import org.hibernate.junit.RequiresDialectFeature; import org.hibernate.junit.RequiresDialectFeature;
import org.hibernate.test.annotations.TestCase; import org.hibernate.test.annotations.TestCase;
@ -10,7 +11,7 @@ import org.hibernate.test.annotations.TestCase;
*/ */
public class HbmWithIdentityTest extends TestCase { public class HbmWithIdentityTest extends TestCase {
@RequiresDialectFeature("supportsIdentityColumns") @RequiresDialectFeature(DialectChecks.SupportsIdentityColumns.class)
public void testManyToOneAndInterface() throws Exception { public void testManyToOneAndInterface() throws Exception {
Session s = openSession(); Session s = openSession();
s.getTransaction().begin(); s.getTransaction().begin();

View File

@ -0,0 +1,59 @@
// $Id$
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2010, Red Hat Inc. 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 Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.junit;
import org.hibernate.dialect.Dialect;
/**
* Container class for different implementation of the {@code DialectCheck} interface.
*
* @author Hardy Ferentschik
*/
abstract public class DialectChecks {
abstract public boolean include(Dialect dialect);
public static class SupportsSequences extends DialectChecks {
public boolean include(Dialect dialect) {
return dialect.supportsSequences();
}
}
public static class SupportsExpectedLobUsagePattern extends DialectChecks {
public boolean include(Dialect dialect) {
return dialect.supportsExpectedLobUsagePattern();
}
}
public static class SupportsIdentityColumns extends DialectChecks {
public boolean include(Dialect dialect) {
return dialect.supportsIdentityColumns();
}
}
}

View File

@ -1,3 +1,4 @@
// $Id$
/* /*
* Hibernate, Relational Persistence for Idiomatic Java * Hibernate, Relational Persistence for Idiomatic Java
* *
@ -40,5 +41,5 @@ public @interface RequiresDialectFeature {
/** /**
* @return The name of the dialect feature. * @return The name of the dialect feature.
*/ */
String value(); Class<? extends DialectChecks> value();
} }

View File

@ -38,6 +38,7 @@ import org.slf4j.LoggerFactory;
import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Configuration;
import org.hibernate.dialect.Dialect; import org.hibernate.dialect.Dialect;
import org.hibernate.jdbc.Work; import org.hibernate.jdbc.Work;
import org.hibernate.junit.DialectChecks;
import org.hibernate.junit.FailureExpected; import org.hibernate.junit.FailureExpected;
import org.hibernate.junit.RequiresDialect; import org.hibernate.junit.RequiresDialect;
import org.hibernate.junit.RequiresDialectFeature; import org.hibernate.junit.RequiresDialectFeature;
@ -192,15 +193,9 @@ public abstract class HibernateTestCase extends TestCase {
// then check against a dialect feature // then check against a dialect feature
RequiresDialectFeature requiresDialectFeatureAnn = locateAnnotation( RequiresDialectFeature.class, runMethod ); RequiresDialectFeature requiresDialectFeatureAnn = locateAnnotation( RequiresDialectFeature.class, runMethod );
if ( requiresDialectFeatureAnn != null ) { if ( requiresDialectFeatureAnn != null ) {
String feature = requiresDialectFeatureAnn.value(); Class<? extends DialectChecks> checkClass = requiresDialectFeatureAnn.value();
boolean skip = false; DialectChecks check = checkClass.newInstance();
try { boolean skip = check.include( dialect );
Method m = dialect.getClass().getMethod( feature );
skip = (Boolean) m.invoke( dialect );
}
catch ( NoSuchMethodException e ) {
fail( "Dialect does not have a method: " + feature );
}
if ( skip ) { if ( skip ) {
return buildSkip( dialect, null, null ); return buildSkip( dialect, null, null );
} }