You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by aa...@apache.org on 2007/01/25 14:36:26 UTC
svn commit: r499785 - in
/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src:
main/java/org/apache/cayenne/conf/ main/java/org/apache/cayenne/map/
main/java/org/apache/cayenne/reflect/ main/java/org/apache/cayenne/tools/
test/java/org/apache/c...
Author: aadamchik
Date: Thu Jan 25 05:36:25 2007
New Revision: 499785
URL: http://svn.apache.org/viewvc?view=rev&rev=499785
Log:
A mix of issues:
CAY-740: MapLoader algorithm improvement (finished)
CAY-735: Embeddable class support in the org.apache.cayenne.map package and the Modeler (ObjEntity embedded support)
Added:
cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/EmbeddedAttribute.java
cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/testdo/embeddable/
cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/testdo/embeddable/EmbedEntity1.java
cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/testdo/embeddable/Embeddable1.java
cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/testdo/embeddable/auto/
cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/testdo/embeddable/auto/_EmbedEntity1.java
cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/testdo/embeddable/auto/_Embeddable1.java
cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/embeddable.map.xml
Modified:
cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/conf/RuntimeLoadDelegate.java
cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/Attribute.java
cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/DataMap.java
cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/EntityResolver.java
cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/MapLoader.java
cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/MappingNamespace.java
cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/ObjEntity.java
cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/reflect/PersistentDescriptorFactory.java
cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/tools/CayenneGeneratorUtil.java
cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/map/DbAttributeTest.java
cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/map/MapLoaderLoadTest.java
cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/map/MockMappingNamespace.java
cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/project/DataNodeFileTest.java
cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/cayenne.xml
Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/conf/RuntimeLoadDelegate.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/conf/RuntimeLoadDelegate.java?view=diff&rev=499785&r1=499784&r2=499785
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/conf/RuntimeLoadDelegate.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/conf/RuntimeLoadDelegate.java Thu Jan 25 05:36:25 2007
@@ -43,7 +43,7 @@
* @author Andrus Adamchik
*/
public class RuntimeLoadDelegate implements ConfigLoaderDelegate {
-
+
private static final Log logger = LogFactory.getLog(RuntimeLoadDelegate.class);
// TODO: andrus, 7/17/2006 - these variables, and project upgrade logic should be
@@ -57,6 +57,7 @@
protected ConfigStatus status;
protected Configuration config;
protected long startTime;
+ protected MapLoader mapLoader;
public RuntimeLoadDelegate(Configuration config, ConfigStatus status) {
@@ -172,6 +173,16 @@
}
}
+ protected MapLoader getMapLoader() {
+ // it is worth caching the map loader, as it precompiles some XML operations
+ // starting from release 3.0
+ if (mapLoader == null) {
+ mapLoader = new MapLoader();
+ }
+
+ return mapLoader;
+ }
+
/**
* Returns DataMap for the name and location information. If a DataMap is already
* loaded within a given domain, such loaded map is returned, otherwise the map is
@@ -200,7 +211,7 @@
}
try {
- DataMap map = new MapLoader().loadDataMap(new InputSource(mapIn));
+ DataMap map = getMapLoader().loadDataMap(new InputSource(mapIn));
logger.info("loaded <map name='"
+ mapName
Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/Attribute.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/Attribute.java?view=diff&rev=499785&r1=499784&r2=499785
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/Attribute.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/Attribute.java Thu Jan 25 05:36:25 2007
@@ -23,6 +23,7 @@
import java.io.Serializable;
import org.apache.cayenne.util.CayenneMapEntry;
+import org.apache.cayenne.util.XMLEncoder;
import org.apache.cayenne.util.XMLSerializable;
/**
@@ -48,6 +49,8 @@
public Attribute(String name) {
this.name = name;
}
+
+ public abstract void encodeAsXML(XMLEncoder encoder);
/**
* Returns parent entity that holds this attribute.
Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/DataMap.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/DataMap.java?view=diff&rev=499785&r1=499784&r2=499785
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/DataMap.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/DataMap.java Thu Jan 25 05:36:25 2007
@@ -24,9 +24,7 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
-import java.util.Comparator;
import java.util.Iterator;
-import java.util.List;
import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;
@@ -115,7 +113,7 @@
protected boolean clientSupported;
protected String defaultClientPackage;
- private List embeddables;
+ private SortedMap embeddablesMap;
private SortedMap objEntityMap;
private SortedMap dbEntityMap;
private SortedMap procedureMap;
@@ -136,7 +134,7 @@
}
public DataMap(String mapName, Map properties) {
- embeddables = new ArrayList();
+ embeddablesMap = new TreeMap();
objEntityMap = new TreeMap();
dbEntityMap = new TreeMap();
procedureMap = new TreeMap();
@@ -267,30 +265,8 @@
encoder.printProperty(DEFAULT_CLIENT_PACKAGE_PROPERTY, defaultClientPackage);
}
- // embeddables.... must sort explicitly.
- if (!embeddables.isEmpty()) {
-
- List sortedEmbeddables;
-
- if (embeddables.size() > 1) {
- sortedEmbeddables = new ArrayList(embeddables);
- Comparator embeddableComparator = new Comparator() {
-
- public int compare(Object o1, Object o2) {
- Embeddable e1 = (Embeddable) o1;
- Embeddable e2 = (Embeddable) o2;
- return Util.nullSafeCompare(true, e1.getClassName(), e2
- .getClassName());
- }
- };
- Collections.sort(sortedEmbeddables, embeddableComparator);
- }
- else {
- sortedEmbeddables = embeddables;
- }
-
- encoder.print(sortedEmbeddables);
- }
+ // embeddables
+ encoder.print(getEmbeddableMap());
// procedures
encoder.print(getProcedureMap());
@@ -492,7 +468,7 @@
* @since 3.0
*/
public void clearEmbeddables() {
- embeddables.clear();
+ embeddablesMap.clear();
}
/**
@@ -548,7 +524,26 @@
if (embeddable == null) {
throw new NullPointerException("Null embeddable");
}
- embeddables.add(embeddable);
+
+ if (embeddable.getClassName() == null) {
+ throw new NullPointerException(
+ "Attempt to add Embeddable with no class name.");
+ }
+
+ // TODO: change method signature to return replaced entity and make sure the
+ // Modeler handles it...
+ Object existing = embeddablesMap.get(embeddable.getClassName());
+ if (existing != null) {
+ if (existing == embeddable) {
+ return;
+ }
+ else {
+ throw new IllegalArgumentException("An attempt to override embeddable '"
+ + embeddable.getClassName());
+ }
+ }
+
+ embeddablesMap.put(embeddable.getClassName(), embeddable);
}
/**
@@ -609,12 +604,31 @@
}
/**
+ * @since 3.0
+ */
+ public Map getEmbeddableMap() {
+ return Collections.unmodifiableMap(embeddablesMap);
+ }
+
+ /**
* Returns a collection of {@link Embeddable} mappings stored in the DataMap.
*
* @since 3.0
*/
public Collection getEmbeddables() {
- return Collections.unmodifiableCollection(embeddables);
+ return Collections.unmodifiableCollection(embeddablesMap.values());
+ }
+
+ /**
+ * @since 3.0
+ */
+ public Embeddable getEmbeddable(String className) {
+ Embeddable e = (Embeddable) embeddablesMap.get(className);
+ if (e != null) {
+ return e;
+ }
+
+ return namespace != null ? namespace.getEmbeddable(className) : null;
}
/**
@@ -702,18 +716,13 @@
}
/**
- * Removes all {@link Embeddable} descriptors with matching class name.
+ * Removes an {@link Embeddable} descriptor with matching class name.
*
* @since 3.0
*/
public void removeEmbeddable(String className) {
- Iterator it = embeddables.iterator();
- while (it.hasNext()) {
- Embeddable e = (Embeddable) it.next();
- if (className.equals(e.getClassName())) {
- it.remove();
- }
- }
+ // TODO: andrus, 1/25/2007 - clean up references like removeDbEntity does.
+ embeddablesMap.remove(className);
}
/**
Added: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/EmbeddedAttribute.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/EmbeddedAttribute.java?view=auto&rev=499785
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/EmbeddedAttribute.java (added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/EmbeddedAttribute.java Thu Jan 25 05:36:25 2007
@@ -0,0 +1,166 @@
+/*****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ ****************************************************************/
+package org.apache.cayenne.map;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.cayenne.CayenneRuntimeException;
+import org.apache.cayenne.util.XMLEncoder;
+
+/**
+ * An attribute of the ObjEntity that maps to an embeddable class.
+ *
+ * @since 3.0
+ * @author Andrus Adamchik
+ */
+public class EmbeddedAttribute extends Attribute {
+
+ protected String type;
+ protected Map attributeOverrides;
+
+ public EmbeddedAttribute() {
+ attributeOverrides = new HashMap();
+ }
+
+ public EmbeddedAttribute(String name) {
+ this();
+ setName(name);
+ }
+
+ public EmbeddedAttribute(String name, String type, ObjEntity entity) {
+ this();
+ setName(name);
+ setType(type);
+ setEntity(entity);
+ }
+
+ public void encodeAsXML(XMLEncoder encoder) {
+ encoder.print("<embedded-attribute name=\"" + getName() + '\"');
+ if (getType() != null) {
+ encoder.print(" type=\"");
+ encoder.print(getType());
+ encoder.print('\"');
+ }
+
+ if (attributeOverrides.isEmpty()) {
+ encoder.println("/>");
+ return;
+ }
+
+ encoder.println('>');
+
+ encoder.indent(1);
+ Iterator it = attributeOverrides.entrySet().iterator();
+ while (it.hasNext()) {
+ Map.Entry e = (Map.Entry) it.next();
+ encoder.print("<embeddable-attribute-override name=\"");
+ encoder.print(e.getKey().toString());
+ encoder.print("\" db-attribute-path=\"");
+ encoder.print(e.getValue().toString());
+ encoder.println("\"/>");
+ }
+
+ encoder.indent(-1);
+ encoder.println("</embedded-attribute>");
+ }
+
+ public Map getAttributeOverrides() {
+ return Collections.unmodifiableMap(attributeOverrides);
+ }
+
+ public Embeddable getEmbeddable() {
+ if (type == null) {
+ return null;
+ }
+
+ return getNonNullNamespace().getEmbeddable(type);
+ }
+
+ /**
+ * Returns a Collection of ObjAttributes of an embedded object taking into account
+ * column name overrides.
+ */
+ public Collection getAttributes() {
+ Embeddable e = getEmbeddable();
+ if (e == null) {
+ return Collections.EMPTY_LIST;
+ }
+
+ Collection embeddableAttributes = e.getAttributes();
+ Collection objectAttributes = new ArrayList(embeddableAttributes.size());
+ Iterator it = embeddableAttributes.iterator();
+ while (it.hasNext()) {
+ EmbeddableAttribute ea = (EmbeddableAttribute) it.next();
+ String path = getName() + "." + ea.getName();
+ String dbPath = (String) attributeOverrides.get(ea.getName());
+ if (dbPath == null) {
+ dbPath = ea.getDbAttributeName();
+ }
+
+ ObjAttribute oa = new ObjAttribute(path, getType(), (ObjEntity) getEntity());
+ oa.setDbAttributeName(dbPath);
+ objectAttributes.add(oa);
+ }
+
+ return objectAttributes;
+ }
+
+ public void addAttributeOverride(String name, String dbAttributeName) {
+ attributeOverrides.put(name, dbAttributeName);
+ }
+
+ public void removeAttributeOverride(String name) {
+ attributeOverrides.remove(name);
+ }
+
+ /**
+ * Returns a type of this attribute that must be an {@link Embeddable} object.
+ */
+ public String getType() {
+ return type;
+ }
+
+ /**
+ * Sets a type of this attribute that must be an {@link Embeddable} object.
+ */
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ /**
+ * Returns guaranteed non-null MappingNamespace of this relationship. If it happens to
+ * be null, and exception is thrown. This method is intended for internal use by
+ * Relationship class.
+ */
+ final MappingNamespace getNonNullNamespace() {
+
+ if (entity == null) {
+ throw new CayenneRuntimeException("Embedded attribute '"
+ + getName()
+ + "' has no parent Entity.");
+ }
+
+ return entity.getNonNullNamespace();
+ }
+}
Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/EntityResolver.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/EntityResolver.java?view=diff&rev=499785&r1=499784&r2=499785
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/EntityResolver.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/EntityResolver.java Thu Jan 25 05:36:25 2007
@@ -57,6 +57,7 @@
protected boolean indexedByClass;
protected transient Map queryCache;
+ protected transient Map embeddableCache;
protected transient Map dbEntityCache;
protected transient Map objEntityCache;
protected transient Map procedureCache;
@@ -77,6 +78,7 @@
public EntityResolver() {
this.indexedByClass = true;
this.maps = new ArrayList();
+ this.embeddableCache = new HashMap();
this.queryCache = new HashMap();
this.dbEntityCache = new HashMap();
this.objEntityCache = new HashMap();
@@ -241,6 +243,22 @@
public Query getQuery(String name) {
return lookupQuery(name);
+ }
+
+ /**
+ * @since 3.0
+ */
+ public Embeddable getEmbeddable(String className) {
+ Embeddable result = (Embeddable) embeddableCache.get(className);
+
+ if (result == null) {
+ // reconstruct cache just in case some of the datamaps
+ // have changed and now contain the required information
+ constructCache();
+ result = (Embeddable) embeddableCache.get(className);
+ }
+
+ return result;
}
/**
Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/MapLoader.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/MapLoader.java?view=diff&rev=499785&r1=499784&r2=499785
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/MapLoader.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/MapLoader.java Thu Jan 25 05:36:25 2007
@@ -21,6 +21,7 @@
import java.io.IOException;
import java.io.InputStream;
+import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;
@@ -54,6 +55,27 @@
public static final String DATA_MAP_TAG = "data-map";
public static final String PROPERTY_TAG = "property";
+
+ /**
+ * @since 3.0
+ */
+ public static final String EMBEDDABLE_TAG = "embeddable";
+
+ /**
+ * @since 3.0
+ */
+ public static final String EMBEDDABLE_ATTRIBUTE_TAG = "embeddable-attribute";
+
+ /**
+ * @since 3.0
+ */
+ public static final String EMBEDDED_ATTRIBUTE_TAG = "embedded-attribute";
+
+ /**
+ * @since 3.0
+ */
+ public static final String EMBEDDABLE_ATTRIBUTE_OVERRIDE_TAG = "embeddable-attribute-override";
+
public static final String DB_ENTITY_TAG = "db-entity";
public static final String OBJ_ENTITY_TAG = "obj-entity";
public static final String DB_ATTRIBUTE_TAG = "db-attribute";
@@ -87,6 +109,8 @@
private DataMap dataMap;
private DbEntity dbEntity;
private ObjEntity objEntity;
+ private Embeddable embeddable;
+ private EmbeddedAttribute embeddedAttribute;
private DbRelationship dbRelationship;
private ObjRelationship objRelationship;
private DbAttribute attrib;
@@ -96,10 +120,303 @@
private String descending;
private String ignoreCase;
+ private Map startTagOpMap;
+ private Map endTagOpMap;
private String currentTag;
private StringBuffer charactersBuffer;
private Map mapProperties;
+ public MapLoader() {
+ // compile tag processors.
+ startTagOpMap = new HashMap(40);
+ endTagOpMap = new HashMap(40);
+
+ startTagOpMap.put(DB_ENTITY_TAG, new StartClosure() {
+
+ void execute(Attributes attributes) throws SAXException {
+ processStartDbEntity(attributes);
+ }
+ });
+
+ startTagOpMap.put(DB_ATTRIBUTE_TAG, new StartClosure() {
+
+ void execute(Attributes attributes) throws SAXException {
+ processStartDbAttribute(attributes);
+ }
+ });
+
+ startTagOpMap.put(DB_ATTRIBUTE_DERIVED_TAG, new StartClosure() {
+
+ void execute(Attributes attributes) throws SAXException {
+ processStartDerivedDbAttribute(attributes);
+ }
+ });
+
+ startTagOpMap.put(DB_ATTRIBUTE_REF_TAG, new StartClosure() {
+
+ void execute(Attributes attributes) throws SAXException {
+ processStartDbAttributeRef(attributes);
+ }
+ });
+
+ startTagOpMap.put(OBJ_ENTITY_TAG, new StartClosure() {
+
+ void execute(Attributes attributes) throws SAXException {
+ processStartObjEntity(attributes);
+ }
+ });
+
+ startTagOpMap.put(OBJ_ATTRIBUTE_TAG, new StartClosure() {
+
+ void execute(Attributes attributes) throws SAXException {
+ processStartObjAttribute(attributes);
+ }
+ });
+
+ startTagOpMap.put(EMBEDDABLE_TAG, new StartClosure() {
+
+ void execute(Attributes attributes) throws SAXException {
+ processStartEmbeddable(attributes);
+ }
+ });
+
+ startTagOpMap.put(EMBEDDABLE_ATTRIBUTE_TAG, new StartClosure() {
+
+ void execute(Attributes attributes) throws SAXException {
+ processStartEmbeddableAttribute(attributes);
+ }
+ });
+
+ startTagOpMap.put(EMBEDDABLE_ATTRIBUTE_OVERRIDE_TAG, new StartClosure() {
+
+ void execute(Attributes attributes) throws SAXException {
+ processStartEmbeddableAttributeOverride(attributes);
+ }
+ });
+
+ startTagOpMap.put(EMBEDDED_ATTRIBUTE_TAG, new StartClosure() {
+
+ void execute(Attributes attributes) throws SAXException {
+ processStartEmbeddedAttribute(attributes);
+ }
+ });
+
+ startTagOpMap.put(DB_RELATIONSHIP_TAG, new StartClosure() {
+
+ void execute(Attributes attributes) throws SAXException {
+ processStartDbRelationship(attributes);
+ }
+ });
+
+ startTagOpMap.put(DB_ATTRIBUTE_PAIR_TAG, new StartClosure() {
+
+ void execute(Attributes attributes) throws SAXException {
+ processStartDbAttributePair(attributes);
+ }
+ });
+
+ startTagOpMap.put(OBJ_RELATIONSHIP_TAG, new StartClosure() {
+
+ void execute(Attributes attributes) throws SAXException {
+ processStartObjRelationship(attributes);
+ }
+ });
+
+ startTagOpMap.put(DB_RELATIONSHIP_REF_TAG, new StartClosure() {
+
+ void execute(Attributes attributes) throws SAXException {
+ processStartDbRelationshipRef(attributes);
+ }
+ });
+
+ startTagOpMap.put(PROCEDURE_PARAMETER_TAG, new StartClosure() {
+
+ void execute(Attributes attributes) throws SAXException {
+ processStartProcedureParameter(attributes);
+ }
+ });
+
+ startTagOpMap.put(PROCEDURE_TAG, new StartClosure() {
+
+ void execute(Attributes attributes) throws SAXException {
+ processStartProcedure(attributes);
+ }
+ });
+
+ startTagOpMap.put(QUERY_TAG, new StartClosure() {
+
+ void execute(Attributes attributes) throws SAXException {
+ processStartQuery(attributes);
+ }
+ });
+
+ startTagOpMap.put(QUERY_SQL_TAG, new StartClosure() {
+
+ void execute(Attributes attributes) throws SAXException {
+ charactersBuffer = new StringBuffer();
+ processStartQuerySQL(attributes);
+ }
+ });
+
+ startTagOpMap.put(QUERY_ORDERING_TAG, new StartClosure() {
+
+ void execute(Attributes attributes) throws SAXException {
+ charactersBuffer = new StringBuffer();
+ processStartQueryOrdering(attributes);
+ }
+ });
+
+ startTagOpMap.put(DB_KEY_GENERATOR_TAG, new StartClosure() {
+
+ void execute(Attributes attributes) throws SAXException {
+ processStartDbKeyGenerator(attributes);
+ }
+ });
+
+ startTagOpMap.put(PROPERTY_TAG, new StartClosure() {
+
+ void execute(Attributes attributes) throws SAXException {
+ // properties can belong to query or DataMap
+ if (queryBuilder != null) {
+ processStartQueryProperty(attributes);
+ }
+ else {
+ processStartDataMapProperty(attributes);
+ }
+ }
+ });
+
+ StartClosure resetBuffer = new StartClosure() {
+
+ void execute(Attributes attributes) throws SAXException {
+ charactersBuffer = new StringBuffer();
+ }
+ };
+
+ startTagOpMap.put(QUERY_PREFETCH_TAG, resetBuffer);
+ startTagOpMap.put(QUERY_QUALIFIER_TAG, resetBuffer);
+ startTagOpMap.put(DB_GENERATOR_TYPE_TAG, resetBuffer);
+ startTagOpMap.put(DB_GENERATOR_NAME_TAG, resetBuffer);
+ startTagOpMap.put(DB_KEY_CACHE_SIZE_TAG, resetBuffer);
+
+ endTagOpMap.put(DATA_MAP_TAG, new EndClosure() {
+
+ void execute() throws SAXException {
+ processEndDataMap();
+ }
+ });
+ endTagOpMap.put(DB_ENTITY_TAG, new EndClosure() {
+
+ void execute() throws SAXException {
+ processEndDbEntity();
+ }
+ });
+ endTagOpMap.put(OBJ_ENTITY_TAG, new EndClosure() {
+
+ void execute() throws SAXException {
+ processEndObjEntity();
+ }
+ });
+ endTagOpMap.put(EMBEDDABLE_TAG, new EndClosure() {
+
+ void execute() throws SAXException {
+ processEndEmbeddable();
+ }
+ });
+ endTagOpMap.put(EMBEDDABLE_ATTRIBUTE_TAG, new EndClosure() {
+
+ void execute() throws SAXException {
+ processEndEmbeddedAttribute();
+ }
+ });
+
+ endTagOpMap.put(DB_ATTRIBUTE_TAG, new EndClosure() {
+
+ void execute() throws SAXException {
+ processEndDbAttribute();
+ }
+ });
+
+ endTagOpMap.put(DB_ATTRIBUTE_DERIVED_TAG, new EndClosure() {
+
+ void execute() throws SAXException {
+ processEndDbAttribute();
+ }
+ });
+ endTagOpMap.put(DB_RELATIONSHIP_TAG, new EndClosure() {
+
+ void execute() throws SAXException {
+ processEndDbRelationship();
+ }
+ });
+ endTagOpMap.put(OBJ_RELATIONSHIP_TAG, new EndClosure() {
+
+ void execute() throws SAXException {
+ processEndObjRelationship();
+ }
+ });
+ endTagOpMap.put(DB_GENERATOR_TYPE_TAG, new EndClosure() {
+
+ void execute() throws SAXException {
+ processEndDbGeneratorType();
+ }
+ });
+ endTagOpMap.put(DB_GENERATOR_NAME_TAG, new EndClosure() {
+
+ void execute() throws SAXException {
+ processEndDbGeneratorName();
+ }
+ });
+ endTagOpMap.put(DB_KEY_CACHE_SIZE_TAG, new EndClosure() {
+
+ void execute() throws SAXException {
+ processEndDbKeyCacheSize();
+ }
+ });
+ endTagOpMap.put(PROCEDURE_PARAMETER_TAG, new EndClosure() {
+
+ void execute() throws SAXException {
+ processEndProcedureParameter();
+ }
+ });
+ endTagOpMap.put(PROCEDURE_TAG, new EndClosure() {
+
+ void execute() throws SAXException {
+ processEndProcedure();
+ }
+ });
+ endTagOpMap.put(QUERY_TAG, new EndClosure() {
+
+ void execute() throws SAXException {
+ processEndQuery();
+ }
+ });
+ endTagOpMap.put(QUERY_SQL_TAG, new EndClosure() {
+
+ void execute() throws SAXException {
+ processEndQuerySQL();
+ }
+ });
+ endTagOpMap.put(QUERY_QUALIFIER_TAG, new EndClosure() {
+
+ void execute() throws SAXException {
+ processEndQualifier();
+ }
+ });
+ endTagOpMap.put(QUERY_ORDERING_TAG, new EndClosure() {
+
+ void execute() throws SAXException {
+ processEndQueryOrdering();
+ }
+ });
+ endTagOpMap.put(QUERY_PREFETCH_TAG, new EndClosure() {
+
+ void execute() throws SAXException {
+ processEndQueryPrefetch();
+ }
+ });
+ }
+
/**
* Loads a DataMap from XML input source.
*/
@@ -205,144 +522,57 @@
Attributes attributes) throws SAXException {
rememberCurrentTag(localName);
- if (localName.equals(DATA_MAP_TAG)) {
- }
- else if (localName.equals(DB_ENTITY_TAG)) {
- processStartDbEntity(attributes);
- }
- else if (localName.equals(DB_ATTRIBUTE_TAG)) {
- processStartDbAttribute(attributes);
- }
- else if (localName.equals(DB_ATTRIBUTE_DERIVED_TAG)) {
- processStartDerivedDbAttribute(attributes);
- }
- else if (localName.equals(DB_ATTRIBUTE_REF_TAG)) {
- processStartDbAttributeRef(attributes);
- }
- else if (localName.equals(OBJ_ENTITY_TAG)) {
- processStartObjEntity(attributes);
- }
- else if (localName.equals(OBJ_ATTRIBUTE_TAG)) {
- processStartObjAttribute(attributes);
- }
- else if (localName.equals(DB_RELATIONSHIP_TAG)) {
- processStartDbRelationship(attributes);
- }
- else if (localName.equals(DB_ATTRIBUTE_PAIR_TAG)) {
- processStartDbAttributePair(attributes);
- }
- else if (localName.equals(OBJ_RELATIONSHIP_TAG)) {
- processStartObjRelationship(attributes);
- }
- else if (localName.equals(DB_RELATIONSHIP_REF_TAG)) {
- processStartDbRelationshipRef(attributes);
- }
- else if (localName.equals(PROCEDURE_PARAMETER_TAG)) {
- processStartProcedureParameter(attributes);
- }
- else if (localName.equals(PROCEDURE_TAG)) {
- processStartProcedure(attributes);
- }
- else if (localName.equals(QUERY_TAG)) {
- processStartQuery(attributes);
- }
- else if (localName.equals(QUERY_SQL_TAG)) {
- charactersBuffer = new StringBuffer();
- processStartQuerySQL(attributes);
- }
- else if (localName.equals(QUERY_ORDERING_TAG)) {
- charactersBuffer = new StringBuffer();
- processStartQueryOrdering(attributes);
- }
- else if (localName.equals(QUERY_PREFETCH_TAG)) {
- charactersBuffer = new StringBuffer();
- }
- else if (localName.equals(QUERY_QUALIFIER_TAG)) {
- charactersBuffer = new StringBuffer();
- }
- else if (localName.equals(DB_KEY_GENERATOR_TAG)) {
- processStartDbKeyGenerator(attributes);
- }
- else if (localName.equals(DB_GENERATOR_TYPE_TAG)) {
- charactersBuffer = new StringBuffer();
- }
- else if (localName.equals(DB_GENERATOR_NAME_TAG)) {
- charactersBuffer = new StringBuffer();
- }
- else if (localName.equals(DB_KEY_CACHE_SIZE_TAG)) {
- charactersBuffer = new StringBuffer();
- }
- // properties can belong to query or DataMap
- else if (localName.equals(PROPERTY_TAG)) {
- if (queryBuilder != null) {
- processStartQueryProperty(attributes);
- }
- else {
- processStartDataMapProperty(attributes);
- }
+
+ StartClosure op = (StartClosure) startTagOpMap.get(localName);
+ if (op != null) {
+ op.execute(attributes);
}
}
- public void endElement(String namespaceURI, String local_name, String qName)
+ public void endElement(String namespaceURI, String localName, String qName)
throws SAXException {
- if (local_name.equals(DATA_MAP_TAG)) {
- processEndDataMap();
- }
- else if (local_name.equals(DB_ENTITY_TAG)) {
- processEndDbEntity();
- }
- else if (local_name.equals(OBJ_ENTITY_TAG)) {
- processEndObjEntity();
- }
- else if (local_name.equals(DB_ATTRIBUTE_TAG)) {
- processEndDbAttribute();
- }
- else if (local_name.equals(DB_ATTRIBUTE_DERIVED_TAG)) {
- processEndDbAttribute();
- }
- else if (local_name.equals(DB_RELATIONSHIP_TAG)) {
- processEndDbRelationship();
- }
- else if (local_name.equals(OBJ_RELATIONSHIP_TAG)) {
- processEndObjRelationship();
- }
- else if (local_name.equals(DB_KEY_GENERATOR_TAG)) {
- }
- else if (local_name.equals(DB_GENERATOR_TYPE_TAG)) {
- processEndDbGeneratorType();
- }
- else if (local_name.equals(DB_GENERATOR_NAME_TAG)) {
- processEndDbGeneratorName();
- }
- else if (local_name.equals(DB_KEY_CACHE_SIZE_TAG)) {
- processEndDbKeyCacheSize();
- }
- else if (local_name.equals(PROCEDURE_PARAMETER_TAG)) {
- processEndProcedureParameter();
- }
- else if (local_name.equals(PROCEDURE_TAG)) {
- processEndProcedure();
- }
- else if (local_name.equals(QUERY_TAG)) {
- processEndQuery();
- }
- else if (local_name.equals(QUERY_SQL_TAG)) {
- processEndQuerySQL();
- }
- else if (local_name.equals(QUERY_QUALIFIER_TAG)) {
- processEndQualifier();
- }
- else if (local_name.equals(QUERY_ORDERING_TAG)) {
- processEndQueryOrdering();
- }
- else if (local_name.equals(QUERY_PREFETCH_TAG)) {
- processEndQueryPrefetch();
+
+ EndClosure op = (EndClosure) endTagOpMap.get(localName);
+ if (op != null) {
+ op.execute();
}
resetCurrentTag();
charactersBuffer = null;
}
+ private void processStartEmbeddable(Attributes atts) {
+ embeddable = new Embeddable(atts.getValue("", "className"));
+ dataMap.addEmbeddable(embeddable);
+ }
+
+ private void processStartEmbeddableAttribute(Attributes atts) {
+ String name = atts.getValue("", "name");
+ String type = atts.getValue("", "type");
+ String dbName = atts.getValue("", "db-attribute-name");
+
+ EmbeddableAttribute ea = new EmbeddableAttribute(name);
+ ea.setType(type);
+ ea.setDbAttributeName(dbName);
+ embeddable.addAttribute(ea);
+ }
+
+ private void processStartEmbeddedAttribute(Attributes atts) {
+
+ String name = atts.getValue("", "name");
+ String type = atts.getValue("", "type");
+
+ embeddedAttribute = new EmbeddedAttribute(name);
+ embeddedAttribute.setType(type);
+ objEntity.addAttribute(embeddedAttribute);
+ }
+
+ private void processStartEmbeddableAttributeOverride(Attributes atts) {
+ String name = atts.getValue("", "name");
+ String dbName = atts.getValue("", "db-attribute-path");
+ embeddedAttribute.addAttributeOverride(name, dbName);
+ }
+
private void processStartDbEntity(Attributes atts) {
String name = atts.getValue("", "name");
String parentName = atts.getValue("", "parentName");
@@ -398,12 +628,12 @@
if (pseudoPrecision != null) {
attrib.setScale(Integer.parseInt(pseudoPrecision));
}
-
+
String precision = atts.getValue("", "attributePrecision");
if (precision != null) {
attrib.setAttributePrecision(Integer.parseInt(precision));
}
-
+
String scale = atts.getValue("", "scale");
if (scale != null) {
attrib.setScale(Integer.parseInt(scale));
@@ -428,23 +658,23 @@
if (length != null) {
attrib.setMaxLength(Integer.parseInt(length));
}
-
+
// this is an obsolete 1.2 'precision' attribute that really meant 'scale'
String pseudoPrecision = atts.getValue("", "precision");
if (pseudoPrecision != null) {
attrib.setScale(Integer.parseInt(pseudoPrecision));
}
-
+
String precision = atts.getValue("", "attributePrecision");
if (precision != null) {
attrib.setAttributePrecision(Integer.parseInt(precision));
}
-
+
String scale = atts.getValue("", "scale");
if (scale != null) {
attrib.setScale(Integer.parseInt(scale));
}
-
+
String temp = atts.getValue("", "isPrimaryKey");
if (temp != null && temp.equalsIgnoreCase(TRUE)) {
attrib.setPrimaryKey(true);
@@ -852,6 +1082,14 @@
objEntity = null;
}
+ private void processEndEmbeddable() {
+ embeddable = null;
+ }
+
+ private void processEndEmbeddedAttribute() {
+ embeddedAttribute = null;
+ }
+
private void processEndDbRelationship() {
dbRelationship = null;
}
@@ -901,5 +1139,15 @@
}
return name;
+ }
+
+ abstract class StartClosure {
+
+ abstract void execute(Attributes attributes) throws SAXException;
+ }
+
+ abstract class EndClosure {
+
+ abstract void execute() throws SAXException;
}
}
Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/MappingNamespace.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/MappingNamespace.java?view=diff&rev=499785&r1=499784&r2=499785
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/MappingNamespace.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/MappingNamespace.java Thu Jan 25 05:36:25 2007
@@ -24,54 +24,61 @@
import org.apache.cayenne.query.Query;
/**
- * Defines API of a container of DbEntities, ObjEntities, Procedures, Queries
- * and other mapping objects.
+ * Defines API of a container of DbEntities, ObjEntities, Procedures, Queries and other
+ * mapping objects.
*
* @since 1.1
* @author Andrus Adamchik
*/
public interface MappingNamespace {
+
+ /**
+ * Returns an {@link Embeddable} matching class name or null if such Embeddable is not
+ * mapped.
+ */
+ Embeddable getEmbeddable(String className);
+
/**
- * Returns DbEntity for a given name, or null if no
- * such DbEntity is found in the MappingNamespace.
+ * Returns DbEntity for a given name, or null if no such DbEntity is found in the
+ * MappingNamespace.
*/
- public DbEntity getDbEntity(String name);
+ DbEntity getDbEntity(String name);
/**
- * Returns ObjEntity for a given name, or null if no
- * such ObjEntity is found in the MappingNamespace.
+ * Returns ObjEntity for a given name, or null if no such ObjEntity is found in the
+ * MappingNamespace.
*/
- public ObjEntity getObjEntity(String name);
+ ObjEntity getObjEntity(String name);
/**
- * Returns Procedure for a given name, or null if no
- * such Procedure is found in the MappingNamespace.
+ * Returns Procedure for a given name, or null if no such Procedure is found in the
+ * MappingNamespace.
*/
- public Procedure getProcedure(String name);
+ Procedure getProcedure(String name);
/**
- * Returns Query for a given name, or null if no
- * such Query is found in the MappingNamespace.
+ * Returns Query for a given name, or null if no such Query is found in the
+ * MappingNamespace.
*/
- public Query getQuery(String name);
+ Query getQuery(String name);
/**
* Returns all DbEntities in the namespace.
*/
- public Collection getDbEntities();
+ Collection getDbEntities();
/**
* Returns all ObjEntities in the namespace.
*/
- public Collection getObjEntities();
+ Collection getObjEntities();
/**
* Returns all Procedures in the namespace.
*/
- public Collection getProcedures();
+ Collection getProcedures();
/**
* Returns all Queries in the namespace.
*/
- public Collection getQueries();
+ Collection getQueries();
}
Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/ObjEntity.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/ObjEntity.java?view=diff&rev=499785&r1=499784&r2=499785
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/ObjEntity.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/ObjEntity.java Thu Jan 25 05:36:25 2007
@@ -27,8 +27,6 @@
import java.util.SortedMap;
import java.util.TreeMap;
-import org.apache.commons.collections.Transformer;
-
import org.apache.cayenne.CayenneRuntimeException;
import org.apache.cayenne.exp.Expression;
import org.apache.cayenne.exp.ExpressionException;
@@ -42,6 +40,7 @@
import org.apache.cayenne.util.CayenneMapEntry;
import org.apache.cayenne.util.Util;
import org.apache.cayenne.util.XMLEncoder;
+import org.apache.commons.collections.Transformer;
/**
* ObjEntity is a mapping descriptor for a DataObject Java class. It contains the
Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/reflect/PersistentDescriptorFactory.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/reflect/PersistentDescriptorFactory.java?view=diff&rev=499785&r1=499784&r2=499785
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/reflect/PersistentDescriptorFactory.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/reflect/PersistentDescriptorFactory.java Thu Jan 25 05:36:25 2007
@@ -69,7 +69,14 @@
// only include this entity attributes and skip superclasses...
Iterator attributes = descriptor.getEntity().getDeclaredAttributes().iterator();
while (attributes.hasNext()) {
- createAttributeProperty(descriptor, (ObjAttribute) attributes.next());
+ Object attribute = attributes.next();
+
+ if (attribute instanceof ObjAttribute) {
+ createAttributeProperty(descriptor, (ObjAttribute) attribute);
+ }
+ else {
+ // TODO: andrus, 1/25/2007 - EmbeddedAttribute
+ }
}
// only include this entity relationships and skip superclasses...
Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/tools/CayenneGeneratorUtil.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/tools/CayenneGeneratorUtil.java?view=diff&rev=499785&r1=499784&r2=499785
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/tools/CayenneGeneratorUtil.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/tools/CayenneGeneratorUtil.java Thu Jan 25 05:36:25 2007
@@ -45,6 +45,7 @@
protected ILog logger;
+ protected MapLoader mapLoader;
protected File map;
protected File additionalMaps[];
protected DefaultClassGenerator generator;
@@ -55,7 +56,10 @@
/** Loads and returns a DataMap by File. */
public DataMap loadDataMap(File mapName) throws Exception {
InputSource in = new InputSource(mapName.toURL().toString());
- return new MapLoader().loadDataMap(in);
+ if(mapLoader == null) {
+ mapLoader = new MapLoader();
+ }
+ return mapLoader.loadDataMap(in);
}
/** Loads and returns DataMap based on <code>map</code> attribute. */
Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/map/DbAttributeTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/map/DbAttributeTest.java?view=diff&rev=499785&r1=499784&r2=499785
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/map/DbAttributeTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/map/DbAttributeTest.java Thu Jan 25 05:36:25 2007
@@ -22,13 +22,14 @@
import java.sql.Types;
import java.util.List;
+import junit.framework.TestCase;
+
import org.apache.cayenne.dba.TypesMapping;
-import org.apache.cayenne.unit.CayenneCase;
/**
* @author Andrus Adamchik
*/
-public class DbAttributeTest extends CayenneCase {
+public class DbAttributeTest extends TestCase {
public void testConstructor1() throws Exception {
DbAttribute a = new DbAttribute("abc");
Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/map/MapLoaderLoadTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/map/MapLoaderLoadTest.java?view=diff&rev=499785&r1=499784&r2=499785
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/map/MapLoaderLoadTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/map/MapLoaderLoadTest.java Thu Jan 25 05:36:25 2007
@@ -28,26 +28,56 @@
import org.apache.cayenne.query.Ordering;
import org.apache.cayenne.query.SQLTemplate;
import org.apache.cayenne.query.SelectQuery;
+import org.apache.cayenne.testdo.embeddable.Embeddable1;
import org.xml.sax.InputSource;
public class MapLoaderLoadTest extends TestCase {
- protected MapLoader mapLoader;
- private String testDataMap;
+ private InputSource getMapXml(String mapName) {
+ return new InputSource(getClass().getClassLoader().getResourceAsStream(mapName));
+ }
+
+ public void testLoadEmbeddableMap() throws Exception {
+ MapLoader mapLoader = new MapLoader();
+ DataMap map = mapLoader.loadDataMap(getMapXml("embeddable.map.xml"));
+ assertNotNull(map);
+
+ assertEquals(1, map.getEmbeddables().size());
+ Embeddable e = map.getEmbeddable(Embeddable1.class.getName());
+ assertNotNull(e);
+ assertEquals(Embeddable1.class.getName(), e.getClassName());
+
+ assertEquals(2, e.getAttributes().size());
+ EmbeddableAttribute ea1 = e.getAttribute("embedded10");
+ assertNotNull(ea1);
+ assertEquals("embedded10", ea1.getName());
+ assertEquals("java.lang.String", ea1.getType());
+ assertEquals("EMBEDDED10", ea1.getDbAttributeName());
+
+ EmbeddableAttribute ea2 = e.getAttribute("embedded20");
+ assertNotNull(ea2);
+ assertEquals("embedded20", ea2.getName());
+ assertEquals("java.lang.String", ea2.getType());
+ assertEquals("EMBEDDED20", ea2.getDbAttributeName());
+
+ ObjEntity oe = map.getObjEntity("EmbedEntity1");
+ assertNotNull(oe);
+ assertEquals(3, oe.getDeclaredAttributes().size());
- public void setUp() throws Exception {
- super.setUp();
+ EmbeddedAttribute oea1 = (EmbeddedAttribute) oe.getAttribute("embedded1");
+ assertNotNull(oea1);
+ assertEquals(Embeddable1.class.getName(), oea1.getType());
+ assertEquals(0, oea1.getAttributeOverrides().size());
- mapLoader = new MapLoader();
- testDataMap = getClass()
- .getClassLoader()
- .getResource("testmap.map.xml")
- .toExternalForm();
+ EmbeddedAttribute oea2 = (EmbeddedAttribute) oe.getAttribute("embedded2");
+ assertNotNull(oea2);
+ assertEquals(Embeddable1.class.getName(), oea2.getType());
+ assertEquals(2, oea2.getAttributeOverrides().size());
}
- public void testLoadDataMap() throws Exception {
- InputSource in = new InputSource(testDataMap);
- DataMap map = mapLoader.loadDataMap(in);
+ public void testLoadTestMap() throws Exception {
+ MapLoader mapLoader = new MapLoader();
+ DataMap map = mapLoader.loadDataMap(getMapXml("testmap.map.xml"));
assertNotNull(map);
// test procedures
Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/map/MockMappingNamespace.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/map/MockMappingNamespace.java?view=diff&rev=499785&r1=499784&r2=499785
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/map/MockMappingNamespace.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/map/MockMappingNamespace.java Thu Jan 25 05:36:25 2007
@@ -37,6 +37,10 @@
private Map objEntities = new HashMap();
private Map queries = new HashMap();
private Map procedures = new HashMap();
+
+ public Embeddable getEmbeddable(String className) {
+ return null;
+ }
public void addDbEntity(DbEntity entity) {
dbEntities.put(entity.getName(), entity);
Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/project/DataNodeFileTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/project/DataNodeFileTest.java?view=diff&rev=499785&r1=499784&r2=499785
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/project/DataNodeFileTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/project/DataNodeFileTest.java Thu Jan 25 05:36:25 2007
@@ -21,22 +21,20 @@
import java.io.File;
+import junit.framework.TestCase;
+
import org.apache.cayenne.access.DataNode;
-import org.apache.cayenne.unit.CayenneCase;
/**
* @author Andrus Adamchik
*/
-public class DataNodeFileTest extends CayenneCase {
+public class DataNodeFileTest extends TestCase {
+
protected DataNodeFile dnf;
protected DataNode node;
protected Project pr;
- /**
- * @see junit.framework.TestCase#setUp()
- */
protected void setUp() throws Exception {
- super.setUp();
pr = new TstProject(new File("xyz"));
node = new DataNode("n1");
dnf = new DataNodeFile(pr, node);
Added: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/testdo/embeddable/EmbedEntity1.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/testdo/embeddable/EmbedEntity1.java?view=auto&rev=499785
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/testdo/embeddable/EmbedEntity1.java (added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/testdo/embeddable/EmbedEntity1.java Thu Jan 25 05:36:25 2007
@@ -0,0 +1,10 @@
+package org.apache.cayenne.testdo.embeddable;
+
+import org.apache.cayenne.testdo.embeddable.auto._EmbedEntity1;
+
+public class EmbedEntity1 extends _EmbedEntity1 {
+
+}
+
+
+
Added: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/testdo/embeddable/Embeddable1.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/testdo/embeddable/Embeddable1.java?view=auto&rev=499785
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/testdo/embeddable/Embeddable1.java (added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/testdo/embeddable/Embeddable1.java Thu Jan 25 05:36:25 2007
@@ -0,0 +1,25 @@
+/*****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ ****************************************************************/
+package org.apache.cayenne.testdo.embeddable;
+
+import org.apache.cayenne.testdo.embeddable.auto._Embeddable1;
+
+public class Embeddable1 extends _Embeddable1 {
+
+}
Added: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/testdo/embeddable/auto/_EmbedEntity1.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/testdo/embeddable/auto/_EmbedEntity1.java?view=auto&rev=499785
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/testdo/embeddable/auto/_EmbedEntity1.java (added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/testdo/embeddable/auto/_EmbedEntity1.java Thu Jan 25 05:36:25 2007
@@ -0,0 +1,42 @@
+package org.apache.cayenne.testdo.embeddable.auto;
+
+import org.apache.cayenne.testdo.embeddable.Embeddable1;
+
+/** Class _EmbedEntity1 was generated by Cayenne.
+ * It is probably a good idea to avoid changing this class manually,
+ * since it may be overwritten next time code is regenerated.
+ * If you need to make any customizations, please use subclass.
+ */
+public class _EmbedEntity1 extends org.apache.cayenne.CayenneDataObject {
+
+ public static final String EMBEDDED1_PROPERTY = "embedded1";
+ public static final String EMBEDDED2_PROPERTY = "embedded2";
+ public static final String NAME_PROPERTY = "name";
+
+ public static final String ID_PK_COLUMN = "ID";
+
+ public void setEmbedded1(Embeddable1 e) {
+ writeProperty("embedded1", e);
+ }
+ public Embeddable1 getEmbedded1() {
+ return (Embeddable1)readProperty("embedded1");
+ }
+
+
+ public void setEmbedded2(Embeddable1 e) {
+ writeProperty("embedded2", e);
+ }
+ public Embeddable1 getEmbedded2() {
+ return (Embeddable1)readProperty("embedded2");
+ }
+
+
+ public void setName(String name) {
+ writeProperty("name", name);
+ }
+ public String getName() {
+ return (String)readProperty("name");
+ }
+
+
+}
Added: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/testdo/embeddable/auto/_Embeddable1.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/testdo/embeddable/auto/_Embeddable1.java?view=auto&rev=499785
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/testdo/embeddable/auto/_Embeddable1.java (added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/testdo/embeddable/auto/_Embeddable1.java Thu Jan 25 05:36:25 2007
@@ -0,0 +1,41 @@
+/*****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ ****************************************************************/
+package org.apache.cayenne.testdo.embeddable.auto;
+
+public class _Embeddable1 {
+
+ protected String embedded10;
+ protected String embedded20;
+
+ public String getEmbedded10() {
+ return embedded10;
+ }
+
+ public void setEmbedded10(String embedded10) {
+ this.embedded10 = embedded10;
+ }
+
+ public String getEmbedded20() {
+ return embedded20;
+ }
+
+ public void setEmbedded20(String embedded20) {
+ this.embedded20 = embedded20;
+ }
+}
Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/cayenne.xml
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/cayenne.xml?view=diff&rev=499785&r1=499784&r2=499785
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/cayenne.xml (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/cayenne.xml Thu Jan 25 05:36:25 2007
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<domains project-version="2.0">
<domain name="default">
+ <map name="embeddable" location="embeddable.map.xml"/>
<map name="generic" location="generic.map.xml"/>
<map name="locking" location="locking.map.xml"/>
<map name="map-db1" location="map-db1.map.xml"/>
Added: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/embeddable.map.xml
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/embeddable.map.xml?view=auto&rev=499785
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/embeddable.map.xml (added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/embeddable.map.xml Thu Jan 25 05:36:25 2007
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<data-map project-version="2.0">
+ <property name="defaultPackage" value="org.apache.cayenne.testdo.embeddable"/>
+ <embeddable className="org.apache.cayenne.testdo.embeddable.Embeddable1">
+ <embeddable-attribute name="embedded10" type="java.lang.String" db-attribute-name="EMBEDDED10"/>
+ <embeddable-attribute name="embedded20" type="java.lang.String" db-attribute-name="EMBEDDED20"/>
+ </embeddable>
+ <db-entity name="EMBED_ENTITY1">
+ <db-attribute name="EMBEDDED10" type="VARCHAR" length="100"/>
+ <db-attribute name="EMBEDDED20" type="VARCHAR" length="100"/>
+ <db-attribute name="EMBEDDED30" type="VARCHAR" length="100"/>
+ <db-attribute name="EMBEDDED40" type="VARCHAR" length="100"/>
+ <db-attribute name="ID" type="INTEGER" isPrimaryKey="true" isMandatory="true"/>
+ <db-attribute name="NAME" type="VARCHAR" length="100"/>
+ </db-entity>
+ <obj-entity name="EmbedEntity1" className="org.apache.cayenne.testdo.embeddable.EmbedEntity1" dbEntityName="EMBED_ENTITY1">
+ <embedded-attribute name="embedded1" type="org.apache.cayenne.testdo.embeddable.Embeddable1"/>
+ <embedded-attribute name="embedded2" type="org.apache.cayenne.testdo.embeddable.Embeddable1">
+ <embeddable-attribute-override name="embedded10" db-attribute-path="EMBEDDED30"/>
+ <embeddable-attribute-override name="embedded20" db-attribute-path="EMBEDDED40"/>
+ </embedded-attribute>
+ <obj-attribute name="name" type="java.lang.String" db-attribute-path="NAME"/>
+ </obj-entity>
+</data-map>