1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
/**
* <copyright> Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others All rights
* reserved. This program and the accompanying materials are made available under the terms of the
* Eclipse Public License v1.0 which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html Contributors: Martin Taal
* </copyright> $Id: ManyExternalReferenceMapper.java,v 1.1 2008/12/16 20:40:29 mtaal Exp $
*/
package org.eclipse.emf.teneo.hibernate.mapper;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.eclipse.emf.teneo.annotations.pamodel.PAnnotatedEReference;
import org.eclipse.emf.teneo.annotations.pannotation.JoinColumn;
import org.eclipse.emf.teneo.annotations.pannotation.JoinTable;
import org.eclipse.emf.teneo.annotations.pannotation.OneToMany;
import org.eclipse.emf.teneo.extension.ExtensionPoint;
import org.eclipse.emf.teneo.hibernate.hbmodel.HbAnnotatedEReference;
import org.eclipse.emf.teneo.hibernate.hbmodel.HbAnnotatedETypeElement;
import org.eclipse.emf.teneo.simpledom.Element;
/**
* Maps ereference with isMany is true which should be stored as an URI.
*
* @author <a href="mailto:mtaal at elver.org">Martin Taal</a>
*/
public class ManyExternalReferenceMapper extends AbstractAssociationMapper implements
ExtensionPoint {
private static final Log log = LogFactory.getLog(ManyExternalReferenceMapper.class);
/**
* Process a many=true EReference with URI attribute.
*/
public void processManyReference(PAnnotatedEReference paReference) {
if (log.isDebugEnabled()) {
log.debug("Generating many valued attribute mapping for " + paReference);
}
final HbAnnotatedEReference hbReference = (HbAnnotatedEReference) paReference;
final Element collElement = addCollectionElement(paReference);
final Element keyElement = collElement.addElement("key");
final JoinTable jt = getJoinTable(paReference);
final List<JoinColumn> jcs = paReference.getJoinColumns() == null ? new ArrayList<JoinColumn>()
: paReference.getJoinColumns();
final OneToMany otm = paReference.getOneToMany();
if (jt != null) {
addJoinTable(hbReference, collElement, keyElement, jt);
addKeyColumns(hbReference, keyElement, jcs);
} else {
// TODO should we also add joinColumns annotation?
addKeyColumns(hbReference, keyElement, jcs);
}
if (otm.isIndexed() && hbReference.getHbIdBag() == null) {
addListIndex(collElement, paReference);
}
addFetchType(collElement, otm.getFetch());
addCascadesForMany(collElement,
getCascades(hbReference.getHbCascade(), otm.getCascade(), false));
addElementElement(collElement, paReference, getColumns(paReference), otm.getTargetEntity());
addAccessor(collElement);
mapFilter(collElement, ((HbAnnotatedETypeElement) hbReference).getFilter());
}
}
|