[hibernate-commits] Hibernate SVN: r18011 - in sandbox/trunk/new-metadata: src/main/java/org/hibernate/metadata/java and 2 other directories.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Thu Nov 19 14:45:41 EST 2009


Author: steve.ebersole at jboss.com
Date: 2009-11-19 14:45:41 -0500 (Thu, 19 Nov 2009)
New Revision: 18011

Added:
   sandbox/trunk/new-metadata/src/main/java/org/hibernate/metadata/java/AbstractAttributeContainer.java
   sandbox/trunk/new-metadata/src/main/java/org/hibernate/metadata/java/Component.java
   sandbox/trunk/new-metadata/src/main/java/org/hibernate/metadata/java/Hierarchical.java
   sandbox/trunk/new-metadata/src/main/java/org/hibernate/metadata/java/PluralAttribute.java
   sandbox/trunk/new-metadata/src/main/java/org/hibernate/metadata/java/SingularAttribute.java
   sandbox/trunk/new-metadata/src/main/java/org/hibernate/metadata/java/Superclass.java
   sandbox/trunk/new-metadata/src/main/java/org/hibernate/metadata/mapping/SingularAssociationAttributeMapping.java
   sandbox/trunk/new-metadata/src/main/java/org/hibernate/metadata/mapping/SingularBasicAttributeMapping.java
Modified:
   sandbox/trunk/new-metadata/build.gradle
   sandbox/trunk/new-metadata/src/main/java/org/hibernate/metadata/java/Attribute.java
   sandbox/trunk/new-metadata/src/main/java/org/hibernate/metadata/java/Entity.java
   sandbox/trunk/new-metadata/src/main/java/org/hibernate/metadata/java/package.html
   sandbox/trunk/new-metadata/src/test/java/org/hibernate/metadata/schema/ObjectNameTests.java
Log:
tad more work on this

Modified: sandbox/trunk/new-metadata/build.gradle
===================================================================
--- sandbox/trunk/new-metadata/build.gradle	2009-11-19 16:34:07 UTC (rev 18010)
+++ sandbox/trunk/new-metadata/build.gradle	2009-11-19 19:45:41 UTC (rev 18011)
@@ -12,7 +12,7 @@
 version = '1.0.0-SNAPSHOT'
 
 dependencies {
-    hibernateVersion = '3.3.2.GA'
+    hibernateVersion = '3.5.0-Beta-2'
     slf4jVersion = '1.5.8'
     jtaVersion = '1.1'
     javassistVersion = '3.9.0.GA'

Added: sandbox/trunk/new-metadata/src/main/java/org/hibernate/metadata/java/AbstractAttributeContainer.java
===================================================================
--- sandbox/trunk/new-metadata/src/main/java/org/hibernate/metadata/java/AbstractAttributeContainer.java	                        (rev 0)
+++ sandbox/trunk/new-metadata/src/main/java/org/hibernate/metadata/java/AbstractAttributeContainer.java	2009-11-19 19:45:41 UTC (rev 18011)
@@ -0,0 +1,73 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009 by Red Hat Inc and/or its affiliates or by
+ * third-party contributors as indicated by either @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.java;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedHashSet;
+import java.util.Set;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public abstract class AbstractAttributeContainer implements AttributeContainer {
+	private final Class javaType;
+	private LinkedHashSet attributeSet = new LinkedHashSet();
+	private HashMap attributeMap = new HashMap();
+
+	protected AbstractAttributeContainer(Class javaType) {
+		this.javaType = javaType;
+	}
+
+	/**
+	 * {@inheritDoc}
+	 */
+	public Class getJavaType() {
+		return javaType;
+	}
+
+	/**
+	 * {@inheritDoc}
+	 */
+	public Set getAttributes() {
+		return Collections.unmodifiableSet( attributeSet );
+	}
+
+	/**
+	 * {@inheritDoc}
+	 */
+	public Attribute getAttribute(String name) {
+		return (Attribute) attributeMap.get( name );
+	}
+
+	public void addAttribute(Attribute attribute) {
+		// todo : how to best "secure" this?
+		if ( attributeMap.put( attribute.getName(), attribute ) != null ) {
+			throw new IllegalArgumentException( "Attrtibute with name [" + attribute.getName() + "] already registered" );
+		}
+		attributeSet.add( attribute );
+	}
+}

Modified: sandbox/trunk/new-metadata/src/main/java/org/hibernate/metadata/java/Attribute.java
===================================================================
--- sandbox/trunk/new-metadata/src/main/java/org/hibernate/metadata/java/Attribute.java	2009-11-19 16:34:07 UTC (rev 18010)
+++ sandbox/trunk/new-metadata/src/main/java/org/hibernate/metadata/java/Attribute.java	2009-11-19 19:45:41 UTC (rev 18011)
@@ -23,12 +23,40 @@
  */
 package org.hibernate.metadata.java;
 
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
 /**
- * TODO : javadoc
+ * Most basic contract of an attribute
  *
  * @author Steve Ebersole
  */
 public interface Attribute {
+	/**
+	 * Retrieve the attribute name.
+	 *
+	 * @return The attribute name.
+	 */
 	public String getName();
+
+	/**
+	 * Retrieve the declaring container for this attribute (entity/component).
+	 *
+	 * @return The attribute container.
+	 */
 	public AttributeContainer getAttributeContainer();
+
+	/**
+	 * Is this attribute singular (i.e. castable to {@link SingularAttribute})?  The other alternative
+	 * is {@link PluralAttribute}).
+	 *
+	 * @return True if the castable to {@link SingularAttribute}; false if castable to {@link PluralAttribute}).
+	 */
+	public boolean isSingular();
+
+	public Field getField();
+
+	public Method getGetterMethod();
+
+	public Method getSetterMethod();
 }

Added: sandbox/trunk/new-metadata/src/main/java/org/hibernate/metadata/java/Component.java
===================================================================
--- sandbox/trunk/new-metadata/src/main/java/org/hibernate/metadata/java/Component.java	                        (rev 0)
+++ sandbox/trunk/new-metadata/src/main/java/org/hibernate/metadata/java/Component.java	2009-11-19 19:45:41 UTC (rev 18011)
@@ -0,0 +1,48 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009 by Red Hat Inc and/or its affiliates or by
+ * third-party contributors as indicated by either @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.java;
+
+/**
+ * TODO : javadoc
+ * <p/>
+ * NOTE : Components are not currently really hierarchical.  But that is a feature I want to add.
+ *
+ * @author Steve Ebersole
+ */
+public class Component extends AbstractAttributeContainer implements Hierarchical {
+	private final Hierarchical superType;
+
+	public Component(Class javaType, Hierarchical superType) {
+		super( javaType );
+		this.superType = superType;
+	}
+
+	public Hierarchical getSuperTye() {
+		return superType;
+	}
+
+	public TypeNature getNature() {
+		return TypeNature.COMPONENT;
+	}
+}

Modified: sandbox/trunk/new-metadata/src/main/java/org/hibernate/metadata/java/Entity.java
===================================================================
--- sandbox/trunk/new-metadata/src/main/java/org/hibernate/metadata/java/Entity.java	2009-11-19 16:34:07 UTC (rev 18010)
+++ sandbox/trunk/new-metadata/src/main/java/org/hibernate/metadata/java/Entity.java	2009-11-19 19:45:41 UTC (rev 18011)
@@ -28,5 +28,19 @@
  *
  * @author Steve Ebersole
  */
-public class Entity {
+public class Entity extends AbstractAttributeContainer implements Hierarchical {
+	private final Hierarchical superType;
+
+	public Entity(Class javaType, Hierarchical superType) {
+		super( javaType );
+		this.superType = superType;
+	}
+
+	public Hierarchical getSuperTye() {
+		return superType;
+	}
+
+	public TypeNature getNature() {
+		return TypeNature.ENTITY;
+	}
 }

Added: sandbox/trunk/new-metadata/src/main/java/org/hibernate/metadata/java/Hierarchical.java
===================================================================
--- sandbox/trunk/new-metadata/src/main/java/org/hibernate/metadata/java/Hierarchical.java	                        (rev 0)
+++ sandbox/trunk/new-metadata/src/main/java/org/hibernate/metadata/java/Hierarchical.java	2009-11-19 19:45:41 UTC (rev 18011)
@@ -0,0 +1,33 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009 by Red Hat Inc and/or its affiliates or by
+ * third-party contributors as indicated by either @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.java;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public interface Hierarchical extends AttributeContainer {
+	public Hierarchical getSuperTye();
+}

Added: sandbox/trunk/new-metadata/src/main/java/org/hibernate/metadata/java/PluralAttribute.java
===================================================================
--- sandbox/trunk/new-metadata/src/main/java/org/hibernate/metadata/java/PluralAttribute.java	                        (rev 0)
+++ sandbox/trunk/new-metadata/src/main/java/org/hibernate/metadata/java/PluralAttribute.java	2009-11-19 19:45:41 UTC (rev 18011)
@@ -0,0 +1,34 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009 by Red Hat Inc and/or its affiliates or by
+ * third-party contributors as indicated by either @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.java;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public interface PluralAttribute {
+	public Class getCollectionJavaType();
+	public Class getCollectionElementType();
+}

Added: sandbox/trunk/new-metadata/src/main/java/org/hibernate/metadata/java/SingularAttribute.java
===================================================================
--- sandbox/trunk/new-metadata/src/main/java/org/hibernate/metadata/java/SingularAttribute.java	                        (rev 0)
+++ sandbox/trunk/new-metadata/src/main/java/org/hibernate/metadata/java/SingularAttribute.java	2009-11-19 19:45:41 UTC (rev 18011)
@@ -0,0 +1,33 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009 by Red Hat Inc and/or its affiliates or by
+ * third-party contributors as indicated by either @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.java;
+
+/**
+ * A single valued (non-collection) attribute
+ *
+ * @author Steve Ebersole
+ */
+public interface SingularAttribute extends Attribute {
+	public Type getSingularAttributeType();
+}

Added: sandbox/trunk/new-metadata/src/main/java/org/hibernate/metadata/java/Superclass.java
===================================================================
--- sandbox/trunk/new-metadata/src/main/java/org/hibernate/metadata/java/Superclass.java	                        (rev 0)
+++ sandbox/trunk/new-metadata/src/main/java/org/hibernate/metadata/java/Superclass.java	2009-11-19 19:45:41 UTC (rev 18011)
@@ -0,0 +1,46 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009 by Red Hat Inc and/or its affiliates or by
+ * third-party contributors as indicated by either @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.java;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class Superclass extends AbstractAttributeContainer implements Hierarchical {
+	private final Hierarchical superType;
+
+	public Superclass(Class javaType, Hierarchical superType) {
+		super( javaType );
+		this.superType = superType;
+	}
+
+	public Hierarchical getSuperTye() {
+		return superType;
+	}
+
+	public TypeNature getNature() {
+		return TypeNature.SUPERCLASS;
+	}
+}

Modified: sandbox/trunk/new-metadata/src/main/java/org/hibernate/metadata/java/package.html
===================================================================
--- sandbox/trunk/new-metadata/src/main/java/org/hibernate/metadata/java/package.html	2009-11-19 16:34:07 UTC (rev 18010)
+++ sandbox/trunk/new-metadata/src/main/java/org/hibernate/metadata/java/package.html	2009-11-19 19:45:41 UTC (rev 18011)
@@ -25,7 +25,9 @@
 <html>
 <body>
 <p>
-    This package defines metadata modeling of a Java domain model.
+    This package defines metadata modeling of a Java domain model.  Specifically note that
+    this package does not in any way attempt to encapsulate data modeling information such
+    cardinality.
 </p>
 </body>
 </html>

Added: sandbox/trunk/new-metadata/src/main/java/org/hibernate/metadata/mapping/SingularAssociationAttributeMapping.java
===================================================================
--- sandbox/trunk/new-metadata/src/main/java/org/hibernate/metadata/mapping/SingularAssociationAttributeMapping.java	                        (rev 0)
+++ sandbox/trunk/new-metadata/src/main/java/org/hibernate/metadata/mapping/SingularAssociationAttributeMapping.java	2009-11-19 19:45:41 UTC (rev 18011)
@@ -0,0 +1,86 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009 by Red Hat Inc and/or its affiliates or by
+ * third-party contributors as indicated by either @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.mapping;
+
+import org.hibernate.metadata.java.Attribute;
+import org.hibernate.metadata.java.SingularAttribute;
+import org.hibernate.metadata.schema.ForeignKey;
+import org.hibernate.metadata.schema.Value;
+
+/**
+ * Defines the mapping of <tt>one-to-one</tt> or <tt>many-to-one</tt> association.
+ *
+ * @author Steve Ebersole
+ */
+public class SingularAssociationAttributeMapping implements AttributeMapping {
+	public static class Cardinality {
+		public static final Cardinality ONE_TO_ONE = new Cardinality( "1-1" );
+		public static final Cardinality MANY_TO_ONE = new Cardinality( "m-1" );
+
+		private final String name;
+
+		private Cardinality(String name) {
+			this.name = name;
+		}
+
+		public String getName() {
+			return name;
+		}
+	}
+
+	private final SingularAttribute attribute;
+	private final ForeignKey foreignKey;
+	private final Cardinality cardinality;
+
+	public SingularAssociationAttributeMapping(
+			SingularAttribute attribute,
+			ForeignKey foreignKey,
+			Cardinality cardinality) {
+		this.attribute = attribute;
+		this.foreignKey = foreignKey;
+		this.cardinality = cardinality;
+	}
+
+	/**
+	 * {@inheritDoc}
+	 */
+	public Attribute getAttribute() {
+		return attribute;
+	}
+
+	/**
+	 * {@inheritDoc}
+	 */
+	public Value[] getColumns() {
+		return (Value[]) getForeignKey().getSourceColumns().toArray( new Value[getForeignKey().getSourceColumns().size()] );
+	}
+
+	public ForeignKey getForeignKey() {
+		return foreignKey;
+	}
+
+	public Cardinality getCardinality() {
+		return cardinality;
+	}
+}

Added: sandbox/trunk/new-metadata/src/main/java/org/hibernate/metadata/mapping/SingularBasicAttributeMapping.java
===================================================================
--- sandbox/trunk/new-metadata/src/main/java/org/hibernate/metadata/mapping/SingularBasicAttributeMapping.java	                        (rev 0)
+++ sandbox/trunk/new-metadata/src/main/java/org/hibernate/metadata/mapping/SingularBasicAttributeMapping.java	2009-11-19 19:45:41 UTC (rev 18011)
@@ -0,0 +1,51 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009 by Red Hat Inc and/or its affiliates or by
+ * third-party contributors as indicated by either @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.mapping;
+
+import org.hibernate.metadata.java.Attribute;
+import org.hibernate.metadata.java.SingularAttribute;
+import org.hibernate.metadata.schema.Value;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class SingularBasicAttributeMapping implements AttributeMapping {
+	private final SingularAttribute attribute;
+	private final Value[] columns;
+
+	public SingularBasicAttributeMapping(SingularAttribute attribute, Value[] columns) {
+		this.attribute = attribute;
+		this.columns = columns;
+	}
+
+	public Attribute getAttribute() {
+		return attribute;
+	}
+
+	public Value[] getColumns() {
+		return columns;
+	}
+}

Modified: sandbox/trunk/new-metadata/src/test/java/org/hibernate/metadata/schema/ObjectNameTests.java
===================================================================
--- sandbox/trunk/new-metadata/src/test/java/org/hibernate/metadata/schema/ObjectNameTests.java	2009-11-19 16:34:07 UTC (rev 18010)
+++ sandbox/trunk/new-metadata/src/test/java/org/hibernate/metadata/schema/ObjectNameTests.java	2009-11-19 19:45:41 UTC (rev 18011)
@@ -50,5 +50,7 @@
 	public void testIdentifierBuilding() {
 		ObjectName on = new ObjectName( "schema", "catalog", "name" );
 		assertEquals( "schema.catalog.name", on.getIdentifier() );
+		on = new ObjectName( "schema", null, "name" );
+		assertEquals( "schema.name", on.getIdentifier() );
 	}
 }



More information about the hibernate-commits mailing list