From fc66b8a964f2dbdfda18b853e252445aee84f379 Mon Sep 17 00:00:00 2001 From: Emmanuel Bernard Date: Tue, 5 Jan 2010 09:45:30 +0000 Subject: [PATCH] Extract Schema helper methods git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@18407 1b8cb986-b30d-0410-93ca-fae66ebed9b2 --- .../override/AttributeOverrideTest.java | 16 +------ .../org/hibernate/test/util/SchemaUtil.java | 42 +++++++++++++++++++ 2 files changed, 44 insertions(+), 14 deletions(-) create mode 100644 annotations/src/test/java/org/hibernate/test/util/SchemaUtil.java diff --git a/annotations/src/test/java/org/hibernate/test/annotations/override/AttributeOverrideTest.java b/annotations/src/test/java/org/hibernate/test/annotations/override/AttributeOverrideTest.java index d86baf452a..98f4d6da44 100644 --- a/annotations/src/test/java/org/hibernate/test/annotations/override/AttributeOverrideTest.java +++ b/annotations/src/test/java/org/hibernate/test/annotations/override/AttributeOverrideTest.java @@ -3,6 +3,7 @@ package org.hibernate.test.annotations.override; import java.util.Iterator; import org.hibernate.test.annotations.TestCase; +import org.hibernate.test.util.SchemaUtil; import org.hibernate.metadata.CollectionMetadata; import org.hibernate.engine.SessionFactoryImplementor; import org.hibernate.persister.collection.CollectionPersister; @@ -34,20 +35,7 @@ public class AttributeOverrideTest extends TestCase { } public boolean isColumnPresent(String tableName, String columnName) { - final Iterator tables = ( Iterator
) getCfg().getTableMappings(); - while (tables.hasNext()) { - Table table = tables.next(); - if (tableName.equals( table.getName() ) ) { - Iterator columns = (Iterator) table.getColumnIterator(); - while ( columns.hasNext() ) { - Column column = columns.next(); - if ( columnName.equals( column.getName() ) ) { - return true; - } - } - } - } - return false; + return SchemaUtil.isColumnPresent( tableName, columnName, getCfg() ); } protected Class[] getMappings() { diff --git a/annotations/src/test/java/org/hibernate/test/util/SchemaUtil.java b/annotations/src/test/java/org/hibernate/test/util/SchemaUtil.java new file mode 100644 index 0000000000..e14c09673d --- /dev/null +++ b/annotations/src/test/java/org/hibernate/test/util/SchemaUtil.java @@ -0,0 +1,42 @@ +package org.hibernate.test.util; + +import java.util.Iterator; + +import org.hibernate.mapping.Table; +import org.hibernate.mapping.Column; +import org.hibernate.cfg.Configuration; + +/** + * Check that the Hibernate metamodel contains some database objects + * + * @author Emmanuel Bernard + */ +public abstract class SchemaUtil { + public static boolean isColumnPresent(String tableName, String columnName, Configuration cfg) { + final Iterator
tables = ( Iterator
) cfg.getTableMappings(); + while (tables.hasNext()) { + Table table = tables.next(); + if (tableName.equals( table.getName() ) ) { + Iterator columns = (Iterator) table.getColumnIterator(); + while ( columns.hasNext() ) { + Column column = columns.next(); + if ( columnName.equals( column.getName() ) ) { + return true; + } + } + } + } + return false; + } + + public static boolean isTablePresent(String tableName, Configuration cfg) { + final Iterator
tables = ( Iterator
) cfg.getTableMappings(); + while (tables.hasNext()) { + Table table = tables.next(); + if (tableName.equals( table.getName() ) ) { + return true; + } + } + return false; + } +}