From 1d9f6201a06a01c6228b545f6544fbd18599a312 Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Fri, 12 Apr 2013 09:04:12 -0500 Subject: [PATCH] HHH-7841 - Redesign Loader --- .../FormulaNotSupportedException.java | 42 +++++++++++++++++++ .../internal/metadata/MetadataTools.java | 34 +++++++++++---- 2 files changed, 68 insertions(+), 8 deletions(-) create mode 100644 hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/FormulaNotSupportedException.java diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/FormulaNotSupportedException.java b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/FormulaNotSupportedException.java new file mode 100644 index 0000000000..3bbd6e4a6b --- /dev/null +++ b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/FormulaNotSupportedException.java @@ -0,0 +1,42 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2013, 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.envers.configuration.internal.metadata; + +import org.hibernate.HibernateException; + +/** + * Exception indicating that a formula mapping was encountered where it is not currently supported + * + * @author Steve Ebersole + */ +public class FormulaNotSupportedException extends HibernateException { + private static final String MSG = "Formula mappings (aside from @DiscriminatorValue) are currently not supported"; + + /** + * Constructs a FormulaNotSupportedException using a standard message + */ + public FormulaNotSupportedException() { + super( MSG ); + } +} diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/MetadataTools.java b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/MetadataTools.java index 4b2c1058d8..5bc51020c2 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/MetadataTools.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/MetadataTools.java @@ -32,6 +32,7 @@ import org.dom4j.Element; import org.hibernate.envers.internal.tools.StringTools; import org.hibernate.mapping.Column; import org.hibernate.mapping.Formula; +import org.hibernate.mapping.Selectable; /** * @author Adam Warski (adam at warski dot org) @@ -221,9 +222,13 @@ public class MetadataTools { return join_mapping; } - public static void addColumns(Element any_mapping, Iterator columns) { - while (columns.hasNext()) { - addColumn(any_mapping, columns.next()); + public static void addColumns(Element any_mapping, Iterator selectables) { + while ( selectables.hasNext() ) { + final Selectable selectable = (Selectable) selectables.next(); + if ( selectable.isFormula() ) { + throw new FormulaNotSupportedException(); + } + addColumn( any_mapping, (Column) selectable ); } } @@ -310,13 +315,26 @@ public class MetadataTools { /** * An iterator over column names. */ - public static abstract class ColumnNameIterator implements Iterator { } + public static abstract class ColumnNameIterator implements Iterator { + } - public static ColumnNameIterator getColumnNameIterator(final Iterator columnIterator) { + public static ColumnNameIterator getColumnNameIterator(final Iterator selectableIterator) { return new ColumnNameIterator() { - public boolean hasNext() { return columnIterator.hasNext(); } - public String next() { return columnIterator.next().getName(); } - public void remove() { columnIterator.remove(); } + public boolean hasNext() { + return selectableIterator.hasNext(); + } + + public String next() { + final Selectable next = selectableIterator.next(); + if ( next.isFormula() ) { + throw new FormulaNotSupportedException(); + } + return ( (Column) next ).getName(); + } + + public void remove() { + selectableIterator.remove(); + } }; }