[hibernate-commits] Hibernate SVN: r20201 - sandbox/trunk/new-metadata/src/main/java/org/hibernate/metadata/schema.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Thu Aug 19 22:07:26 EDT 2010


Author: steve.ebersole at jboss.com
Date: 2010-08-19 22:07:25 -0400 (Thu, 19 Aug 2010)
New Revision: 20201

Added:
   sandbox/trunk/new-metadata/src/main/java/org/hibernate/metadata/schema/Identifier.java
Modified:
   sandbox/trunk/new-metadata/src/main/java/org/hibernate/metadata/schema/AbstractValueContainer.java
   sandbox/trunk/new-metadata/src/main/java/org/hibernate/metadata/schema/Column.java
   sandbox/trunk/new-metadata/src/main/java/org/hibernate/metadata/schema/ObjectName.java
   sandbox/trunk/new-metadata/src/main/java/org/hibernate/metadata/schema/ValueContainer.java
Log:
make column name an identifier as well

Modified: sandbox/trunk/new-metadata/src/main/java/org/hibernate/metadata/schema/AbstractValueContainer.java
===================================================================
--- sandbox/trunk/new-metadata/src/main/java/org/hibernate/metadata/schema/AbstractValueContainer.java	2010-08-20 01:01:03 UTC (rev 20200)
+++ sandbox/trunk/new-metadata/src/main/java/org/hibernate/metadata/schema/AbstractValueContainer.java	2010-08-20 02:07:25 UTC (rev 20201)
@@ -42,7 +42,11 @@
 	}
 
 	public Column createColumn(String name) {
-		final Column column = new Column( this, name );
+		return createColumn( Identifier.toIdentifier( name ) );
+	}
+
+	public Column createColumn(Identifier identifier) {
+		final Column column = new Column( this, identifier );
 		values.add( column );
 		return column;
 	}

Modified: sandbox/trunk/new-metadata/src/main/java/org/hibernate/metadata/schema/Column.java
===================================================================
--- sandbox/trunk/new-metadata/src/main/java/org/hibernate/metadata/schema/Column.java	2010-08-20 01:01:03 UTC (rev 20200)
+++ sandbox/trunk/new-metadata/src/main/java/org/hibernate/metadata/schema/Column.java	2010-08-20 02:07:25 UTC (rev 20201)
@@ -29,14 +29,14 @@
  * @author Steve Ebersole
  */
 public class Column extends AbstractColumn implements Value {
-	private final String name;
+	private final Identifier name;
 
-	protected Column(ValueContainer table, String name) {
+	protected Column(ValueContainer table, Identifier name) {
 		super( table );
 		this.name = name;
 	}
 
-	public String getName() {
+	public Identifier getName() {
 		return name;
 	}
 

Added: sandbox/trunk/new-metadata/src/main/java/org/hibernate/metadata/schema/Identifier.java
===================================================================
--- sandbox/trunk/new-metadata/src/main/java/org/hibernate/metadata/schema/Identifier.java	                        (rev 0)
+++ sandbox/trunk/new-metadata/src/main/java/org/hibernate/metadata/schema/Identifier.java	2010-08-20 02:07:25 UTC (rev 20201)
@@ -0,0 +1,87 @@
+/*
+ * 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.metadata.schema;
+
+import org.hibernate.util.StringHelper;
+
+/**
+ * Models an identifier (name).
+ *
+ * @author Steve Ebersole
+ */
+public class Identifier {
+	private final String name;
+	private final boolean isQuoted;
+
+	public static Identifier toIdentifier(String name) {
+		if ( name == null ) {
+			return null;
+		}
+		final String trimmedName = name.trim();
+		return new Identifier( trimmedName, trimmedName.startsWith( "`" ) && trimmedName.endsWith( "`" ) );
+	}
+
+	public Identifier(String name, boolean quoted) {
+		if ( StringHelper.isEmpty( name ) ) {
+			throw new IllegalNameException( "Identifier text/name cannot be null" );
+		}
+		this.name = name;
+		isQuoted = quoted;
+	}
+
+	public String getName() {
+		return name;
+	}
+
+	public boolean isQuoted() {
+		return isQuoted;
+	}
+
+	@Override
+	public String toString() {
+		return isQuoted
+				? '`' + getName() + '`'
+				: getName();
+	}
+
+	@Override
+	public boolean equals(Object o) {
+		if ( this == o ) {
+			return true;
+		}
+		if ( o == null || getClass() != o.getClass() ) {
+			return false;
+		}
+
+		Identifier that = (Identifier) o;
+
+		return isQuoted == that.isQuoted
+				&& name.equals( that.name );
+	}
+
+	@Override
+	public int hashCode() {
+		return name.hashCode();
+	}
+}

Modified: sandbox/trunk/new-metadata/src/main/java/org/hibernate/metadata/schema/ObjectName.java
===================================================================
--- sandbox/trunk/new-metadata/src/main/java/org/hibernate/metadata/schema/ObjectName.java	2010-08-20 01:01:03 UTC (rev 20200)
+++ sandbox/trunk/new-metadata/src/main/java/org/hibernate/metadata/schema/ObjectName.java	2010-08-20 02:07:25 UTC (rev 20201)
@@ -23,62 +23,12 @@
  */
 package org.hibernate.metadata.schema;
 
-import org.hibernate.util.StringHelper;
-
 /**
  * Models the qualified name of a database object.
  *
  * @author Steve Ebersole
  */
 public class ObjectName {
-	public static class Identifier {
-		private final String name;
-		private final boolean isQuoted;
-
-		public Identifier(String name, boolean quoted) {
-			if ( StringHelper.isEmpty( name ) ) {
-				throw new IllegalNameException( "Identifier text/name cannot be null" );
-			}
-			this.name = name;
-			isQuoted = quoted;
-		}
-
-		public String getName() {
-			return name;
-		}
-
-		public boolean isQuoted() {
-			return isQuoted;
-		}
-
-		@Override
-		public String toString() {
-			return isQuoted
-					? '`' + getName() + '`'
-					: getName();
-		}
-
-		@Override
-		public boolean equals(Object o) {
-			if ( this == o ) {
-				return true;
-			}
-			if ( o == null || getClass() != o.getClass() ) {
-				return false;
-			}
-
-			Identifier that = (Identifier) o;
-
-			return isQuoted == that.isQuoted
-					&& name.equals( that.name );
-		}
-
-		@Override
-		public int hashCode() {
-			return name.hashCode();
-		}
-	}
-
 	private final Identifier schema;
 	private final Identifier catalog;
 	private final Identifier name;
@@ -91,17 +41,13 @@
 	}
 
 	public ObjectName(String schemaName, String catalogName, String name) {
-		this( toIdentifier( schemaName ), toIdentifier( catalogName ), toIdentifier( name ) );
+		this(
+				Identifier.toIdentifier( schemaName ),
+				Identifier.toIdentifier( catalogName ),
+				Identifier.toIdentifier( name )
+		);
 	}
 
-	public static Identifier toIdentifier(String name) {
-		if ( name == null ) {
-			return null;
-		}
-		final String trimmedName = name.trim();
-		return new Identifier( trimmedName, trimmedName.startsWith( "`" ) && trimmedName.endsWith( "`" ) );
-	}
-
 	/**
 	 * Creates a qualified name reference.
 	 *

Modified: sandbox/trunk/new-metadata/src/main/java/org/hibernate/metadata/schema/ValueContainer.java
===================================================================
--- sandbox/trunk/new-metadata/src/main/java/org/hibernate/metadata/schema/ValueContainer.java	2010-08-20 01:01:03 UTC (rev 20200)
+++ sandbox/trunk/new-metadata/src/main/java/org/hibernate/metadata/schema/ValueContainer.java	2010-08-20 02:07:25 UTC (rev 20201)
@@ -55,7 +55,7 @@
 	public String toLoggableString();
 
 	/**
-	 * Factory method for creating a {@link Column} associated with this container.
+	 * Factory method for creating a {@link Column} associated with this container using its name
 	 *
 	 * @param name The column name
 	 *
@@ -64,6 +64,15 @@
 	public Column createColumn(String name);
 
 	/**
+	 * Factory method for creating a {@link Column} associated with this container using its identifier
+	 *
+	 * @param name The column identifier
+	 *
+	 * @return The generated column
+	 */
+	public Column createColumn(Identifier name);
+
+	/**
 	 * Factory method for creating a {@link DerivedValue} associated with this container.
 	 *
 	 * @param fragment The value expression



More information about the hibernate-commits mailing list