Extract Schema helper methods
git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@18407 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
parent
19f9443b6e
commit
fc66b8a964
|
@ -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<Table> tables = ( Iterator<Table> ) getCfg().getTableMappings();
|
||||
while (tables.hasNext()) {
|
||||
Table table = tables.next();
|
||||
if (tableName.equals( table.getName() ) ) {
|
||||
Iterator<Column> columns = (Iterator<Column>) 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() {
|
||||
|
|
|
@ -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<Table> tables = ( Iterator<Table> ) cfg.getTableMappings();
|
||||
while (tables.hasNext()) {
|
||||
Table table = tables.next();
|
||||
if (tableName.equals( table.getName() ) ) {
|
||||
Iterator<Column> columns = (Iterator<Column>) 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<Table> tables = ( Iterator<Table> ) cfg.getTableMappings();
|
||||
while (tables.hasNext()) {
|
||||
Table table = tables.next();
|
||||
if (tableName.equals( table.getName() ) ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue