|
Lines 27-36
Link Here
|
| 27 |
import java.util.Locale; |
27 |
import java.util.Locale; |
| 28 |
import java.util.Properties; |
28 |
import java.util.Properties; |
| 29 |
import java.util.Set; |
29 |
import java.util.Set; |
|
|
30 |
|
| 30 |
import org.eclipse.core.resources.IProject; |
31 |
import org.eclipse.core.resources.IProject; |
| 31 |
import org.eclipse.core.resources.IResource; |
32 |
import org.eclipse.core.resources.IResource; |
| 32 |
import org.eclipse.core.runtime.CoreException; |
33 |
import org.eclipse.core.runtime.CoreException; |
| 33 |
import org.eclipse.core.runtime.NullProgressMonitor; |
34 |
import org.eclipse.core.runtime.NullProgressMonitor; |
|
|
35 |
import org.eclipse.emf.transaction.RecordingCommand; |
| 36 |
import org.eclipse.emf.transaction.TransactionalEditingDomain; |
| 34 |
import org.eclipse.graphiti.features.IFeatureProvider; |
37 |
import org.eclipse.graphiti.features.IFeatureProvider; |
| 35 |
import org.eclipse.graphiti.features.context.IRemoveContext; |
38 |
import org.eclipse.graphiti.features.context.IRemoveContext; |
| 36 |
import org.eclipse.graphiti.features.context.impl.AddConnectionContext; |
39 |
import org.eclipse.graphiti.features.context.impl.AddConnectionContext; |
|
Lines 39-48
Link Here
|
| 39 |
import org.eclipse.graphiti.mm.pictograms.ContainerShape; |
42 |
import org.eclipse.graphiti.mm.pictograms.ContainerShape; |
| 40 |
import org.eclipse.graphiti.mm.pictograms.Shape; |
43 |
import org.eclipse.graphiti.mm.pictograms.Shape; |
| 41 |
import org.eclipse.graphiti.services.Graphiti; |
44 |
import org.eclipse.graphiti.services.Graphiti; |
|
|
45 |
import org.eclipse.graphiti.util.IColorConstant; |
| 42 |
import org.eclipse.jdt.core.ICompilationUnit; |
46 |
import org.eclipse.jdt.core.ICompilationUnit; |
| 43 |
import org.eclipse.jdt.core.IField; |
47 |
import org.eclipse.jdt.core.IField; |
| 44 |
import org.eclipse.jdt.core.IImportDeclaration; |
48 |
import org.eclipse.jdt.core.IImportDeclaration; |
| 45 |
import org.eclipse.jdt.core.IMethod; |
49 |
import org.eclipse.jdt.core.IMethod; |
|
|
50 |
import org.eclipse.jdt.core.IPackageDeclaration; |
| 46 |
import org.eclipse.jdt.core.IType; |
51 |
import org.eclipse.jdt.core.IType; |
| 47 |
import org.eclipse.jdt.core.JavaModelException; |
52 |
import org.eclipse.jdt.core.JavaModelException; |
| 48 |
import org.eclipse.jdt.core.dom.CompilationUnit; |
53 |
import org.eclipse.jdt.core.dom.CompilationUnit; |
|
Lines 68-73
Link Here
|
| 68 |
import org.eclipse.jpt.jpa.core.context.java.JavaAttributeMapping; |
73 |
import org.eclipse.jpt.jpa.core.context.java.JavaAttributeMapping; |
| 69 |
import org.eclipse.jpt.jpa.core.context.java.JavaEntity; |
74 |
import org.eclipse.jpt.jpa.core.context.java.JavaEntity; |
| 70 |
import org.eclipse.jpt.jpa.core.context.java.JavaManyToManyMapping; |
75 |
import org.eclipse.jpt.jpa.core.context.java.JavaManyToManyMapping; |
|
|
76 |
import org.eclipse.jpt.jpa.core.context.java.JavaMappedSuperclass; |
| 71 |
import org.eclipse.jpt.jpa.core.context.java.JavaOneToManyMapping; |
77 |
import org.eclipse.jpt.jpa.core.context.java.JavaOneToManyMapping; |
| 72 |
import org.eclipse.jpt.jpa.core.context.java.JavaOneToOneMapping; |
78 |
import org.eclipse.jpt.jpa.core.context.java.JavaOneToOneMapping; |
| 73 |
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentAttribute; |
79 |
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentAttribute; |
|
Lines 77-84
Link Here
|
| 77 |
import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnit; |
83 |
import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnit; |
| 78 |
import org.eclipse.jpt.jpa.core.resource.java.AttributeOverrideAnnotation; |
84 |
import org.eclipse.jpt.jpa.core.resource.java.AttributeOverrideAnnotation; |
| 79 |
import org.eclipse.jpt.jpa.core.resource.java.ColumnAnnotation; |
85 |
import org.eclipse.jpt.jpa.core.resource.java.ColumnAnnotation; |
| 80 |
import org.eclipse.jpt.jpa.core.resource.java.EmbeddedIdAnnotation; |
|
|
| 81 |
import org.eclipse.jpt.jpa.core.resource.java.IdAnnotation; |
| 82 |
import org.eclipse.jpt.jpa.core.resource.java.IdClassAnnotation; |
86 |
import org.eclipse.jpt.jpa.core.resource.java.IdClassAnnotation; |
| 83 |
import org.eclipse.jpt.jpa.core.resource.java.JoinColumnAnnotation; |
87 |
import org.eclipse.jpt.jpa.core.resource.java.JoinColumnAnnotation; |
| 84 |
import org.eclipse.jpt.jpa.core.resource.java.ManyToManyAnnotation; |
88 |
import org.eclipse.jpt.jpa.core.resource.java.ManyToManyAnnotation; |
|
Lines 89-104
Link Here
|
| 89 |
import org.eclipse.jpt.jpa.core.resource.java.RelationshipMappingAnnotation; |
93 |
import org.eclipse.jpt.jpa.core.resource.java.RelationshipMappingAnnotation; |
| 90 |
import org.eclipse.jpt.jpa.core.resource.java.TableAnnotation; |
94 |
import org.eclipse.jpt.jpa.core.resource.java.TableAnnotation; |
| 91 |
import org.eclipse.jpt.jpadiagrameditor.ui.internal.JPADiagramEditorPlugin; |
95 |
import org.eclipse.jpt.jpadiagrameditor.ui.internal.JPADiagramEditorPlugin; |
|
|
96 |
import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.AddInheritedEntityFeature; |
| 92 |
import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.AddRelationFeature; |
97 |
import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.AddRelationFeature; |
| 93 |
import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.RemoveRelationFeature; |
98 |
import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.RemoveRelationFeature; |
| 94 |
import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.UpdateAttributeFeature; |
99 |
import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.UpdateAttributeFeature; |
| 95 |
import org.eclipse.jpt.jpadiagrameditor.ui.internal.i18n.JPAEditorMessages; |
100 |
import org.eclipse.jpt.jpadiagrameditor.ui.internal.i18n.JPAEditorMessages; |
| 96 |
import org.eclipse.jpt.jpadiagrameditor.ui.internal.propertypage.JPADiagramPropertyPage; |
101 |
import org.eclipse.jpt.jpadiagrameditor.ui.internal.propertypage.JPADiagramPropertyPage; |
| 97 |
import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider; |
102 |
import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider; |
| 98 |
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.BidirectionalRelation; |
103 |
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IBidirectionalRelation; |
| 99 |
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IRelation; |
104 |
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IRelation; |
| 100 |
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IRelation.RelDir; |
105 |
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IRelation.RelDir; |
| 101 |
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IRelation.RelType; |
106 |
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IRelation.RelType; |
|
|
107 |
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IsARelation; |
| 102 |
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.ManyToManyBiDirRelation; |
108 |
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.ManyToManyBiDirRelation; |
| 103 |
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.ManyToManyUniDirRelation; |
109 |
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.ManyToManyUniDirRelation; |
| 104 |
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.ManyToOneBiDirRelation; |
110 |
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.ManyToOneBiDirRelation; |
|
Lines 129-134
Link Here
|
| 129 |
return INSTANCE; |
135 |
return INSTANCE; |
| 130 |
} |
136 |
} |
| 131 |
|
137 |
|
|
|
138 |
public void rearrangeIsARelations(IJPAEditorFeatureProvider fp) { |
| 139 |
Collection<IsARelation> isARels = produceAllMissingIsARelations(fp); |
| 140 |
addIsARelations(fp, isARels); |
| 141 |
fp.removeAllRedundantIsARelations(); |
| 142 |
} |
| 143 |
|
| 144 |
public void rearrangeIsARelationsInTransaction(final IJPAEditorFeatureProvider fp) { |
| 145 |
final Collection<IsARelation> isARels = produceAllMissingIsARelations(fp); |
| 146 |
if (!fp.existRedundantIsARelations() && (isARels.size() == 0)) |
| 147 |
return; |
| 148 |
TransactionalEditingDomain ted = fp.getTransactionalEditingDomain(); |
| 149 |
RecordingCommand rc = new RecordingCommand(ted) { |
| 150 |
protected void doExecute() { |
| 151 |
addIsARelations(fp, isARels); |
| 152 |
fp.removeAllRedundantIsARelations(); |
| 153 |
} |
| 154 |
}; |
| 155 |
ted.getCommandStack().execute(rc); |
| 156 |
} |
| 157 |
|
| 158 |
|
| 159 |
public Collection<IsARelation> produceAllMissingIsARelations(IJPAEditorFeatureProvider fp) { |
| 160 |
Collection<JavaPersistentType> persistentTypes = fp.getPersistentTypes(); |
| 161 |
Collection<IsARelation> res = new HashSet<IsARelation>(); |
| 162 |
Iterator<JavaPersistentType> it = persistentTypes.iterator(); |
| 163 |
HashSet<IsARelation> allExistingIsARelations = fp.getAllExistingIsARelations(); |
| 164 |
while (it.hasNext()) { |
| 165 |
JavaPersistentType jpt = it.next(); |
| 166 |
JavaPersistentType superclass = fp.getFirstSuperclassBelongingToTheDiagram(jpt); |
| 167 |
if (superclass == null) |
| 168 |
continue; |
| 169 |
IsARelation newRel = new IsARelation(jpt, superclass); |
| 170 |
if (!allExistingIsARelations.contains(newRel)) |
| 171 |
res.add(newRel); |
| 172 |
} |
| 173 |
return res; |
| 174 |
} |
| 175 |
|
| 132 |
public void addOneToOneUnidirectionalRelation(IFeatureProvider fp, JavaPersistentType jpt, |
176 |
public void addOneToOneUnidirectionalRelation(IFeatureProvider fp, JavaPersistentType jpt, |
| 133 |
JavaPersistentAttribute attribute) { |
177 |
JavaPersistentAttribute attribute) { |
| 134 |
addOneToOneRelation(fp, jpt, attribute, null, null, |
178 |
addOneToOneRelation(fp, jpt, attribute, null, null, |
|
Lines 445-451
Link Here
|
| 445 |
IJPAEditorFeatureProvider fp) { |
489 |
IJPAEditorFeatureProvider fp) { |
| 446 |
ICompilationUnit cu = fp.getCompilationUnit(jpt); |
490 |
ICompilationUnit cu = fp.getCompilationUnit(jpt); |
| 447 |
try { |
491 |
try { |
| 448 |
JpaProject jpaProject = jpt.getJpaProject(); |
|
|
| 449 |
JPAEditorUtil.discardWorkingCopy(cu); |
492 |
JPAEditorUtil.discardWorkingCopy(cu); |
| 450 |
cu.delete(true, new NullProgressMonitor()); |
493 |
cu.delete(true, new NullProgressMonitor()); |
| 451 |
return true; |
494 |
return true; |
|
Lines 514-522
Link Here
|
| 514 |
JavaResourceType jrpt = convertJPTToJRT(jpt); |
557 |
JavaResourceType jrpt = convertJPTToJRT(jpt); |
| 515 |
if (jrpt == null) |
558 |
if (jrpt == null) |
| 516 |
return false; |
559 |
return false; |
| 517 |
JavaEntity mapping = (JavaEntity) jpt.getMapping(); |
560 |
JavaTypeMapping jtm = jpt.getMapping(); |
| 518 |
if (mapping != null) |
561 |
if (jtm == null) |
|
|
562 |
return false; |
| 563 |
if (jtm instanceof JavaEntity) { |
| 564 |
JavaEntity mapping = (JavaEntity)jtm; |
| 519 |
return (mapping.getSpecifiedName() != null); |
565 |
return (mapping.getSpecifiedName() != null); |
|
|
566 |
} |
| 520 |
return false; |
567 |
return false; |
| 521 |
} |
568 |
} |
| 522 |
|
569 |
|
|
Lines 551-569
Link Here
|
| 551 |
} |
598 |
} |
| 552 |
*/ |
599 |
*/ |
| 553 |
|
600 |
|
|
|
601 |
public boolean hasEntityOrMappedSuperclassAnnotation(JavaPersistentType jpt) { |
| 602 |
return hasEntityAnnotation(jpt) || hasMappedSuperclassAnnotation(jpt); |
| 603 |
} |
| 604 |
|
| 554 |
public boolean hasEntityAnnotation(JavaPersistentType jpt) { |
605 |
public boolean hasEntityAnnotation(JavaPersistentType jpt) { |
| 555 |
return (jpt.getMapping() instanceof JavaEntity); |
606 |
return (jpt.getMappingKey() == MappingKeys.ENTITY_TYPE_MAPPING_KEY); |
| 556 |
} |
607 |
} |
| 557 |
|
608 |
|
|
|
609 |
public boolean hasMappedSuperclassAnnotation(JavaPersistentType jpt) { |
| 610 |
return (jpt.getMappingKey() == MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY); |
| 611 |
} |
| 612 |
|
| 558 |
public String getSpecifiedEntityName(JavaPersistentType jpt){ |
613 |
public String getSpecifiedEntityName(JavaPersistentType jpt){ |
| 559 |
JavaEntity gje = (JavaEntity) jpt.getMapping(); |
614 |
JavaTypeMapping jtm = jpt.getMapping(); |
|
|
615 |
if (jtm instanceof JavaEntity) { |
| 616 |
JavaEntity gje = (JavaEntity)jtm; |
| 560 |
return gje.getSpecifiedName(); |
617 |
return gje.getSpecifiedName(); |
| 561 |
} |
618 |
} |
|
|
619 |
JavaMappedSuperclass jms = (JavaMappedSuperclass)jtm; |
| 620 |
return jms.getName(); |
| 621 |
} |
| 562 |
|
622 |
|
| 563 |
public void renameEntity(JavaPersistentType jpt, String newName) { |
623 |
public void renameEntity(JavaPersistentType jpt, String newName) { |
| 564 |
JavaEntity gje = (JavaEntity)jpt.getMapping(); |
624 |
JavaTypeMapping jtm = jpt.getMapping(); |
|
|
625 |
if (jtm instanceof JavaEntity) { |
| 626 |
JavaEntity gje = (JavaEntity)jtm; |
| 565 |
gje.setSpecifiedName(newName); |
627 |
gje.setSpecifiedName(newName); |
| 566 |
} |
628 |
} |
|
|
629 |
} |
| 567 |
|
630 |
|
| 568 |
public JavaPersistentAttribute addAttribute(IJPAEditorFeatureProvider fp, JavaPersistentType jpt, |
631 |
public JavaPersistentAttribute addAttribute(IJPAEditorFeatureProvider fp, JavaPersistentType jpt, |
| 569 |
JavaPersistentType attributeType, String attributeName, |
632 |
JavaPersistentType attributeType, String attributeName, |
|
Lines 1478-1484
Link Here
|
| 1478 |
IRelation rel = fp.getRelationRelatedToAttribute(oldAt); |
1541 |
IRelation rel = fp.getRelationRelatedToAttribute(oldAt); |
| 1479 |
String inverseJPAName = null; |
1542 |
String inverseJPAName = null; |
| 1480 |
JavaPersistentType inverseJPT = null; |
1543 |
JavaPersistentType inverseJPT = null; |
| 1481 |
if (BidirectionalRelation.class.isInstance(rel)) { |
1544 |
if (IBidirectionalRelation.class.isInstance(rel)) { |
| 1482 |
inverseJPT = rel.getInverse(); |
1545 |
inverseJPT = rel.getInverse(); |
| 1483 |
if (inverseJPT != oldAt.getParent()) { |
1546 |
if (inverseJPT != oldAt.getParent()) { |
| 1484 |
pu = JpaArtifactFactory.INSTANCE.getPersistenceUnit(jpt); |
1547 |
pu = JpaArtifactFactory.INSTANCE.getPersistenceUnit(jpt); |
|
Lines 1832-1838
Link Here
|
| 1832 |
return res; |
1895 |
return res; |
| 1833 |
} |
1896 |
} |
| 1834 |
|
1897 |
|
| 1835 |
private BidirectionalRelation produceBiDirRelation(JavaPersistentType jpt, |
1898 |
private IBidirectionalRelation produceBiDirRelation(JavaPersistentType jpt, |
| 1836 |
JavaPersistentAttribute at, Annotation an, |
1899 |
JavaPersistentAttribute at, Annotation an, |
| 1837 |
JavaPersistentType relJPT, JavaPersistentAttribute relAt, |
1900 |
JavaPersistentType relJPT, JavaPersistentAttribute relAt, |
| 1838 |
Annotation relAn, IJPAEditorFeatureProvider fp) { |
1901 |
Annotation relAn, IJPAEditorFeatureProvider fp) { |
|
Lines 1876-1882
Link Here
|
| 1876 |
} |
1939 |
} |
| 1877 |
} |
1940 |
} |
| 1878 |
|
1941 |
|
| 1879 |
BidirectionalRelation res = null; |
1942 |
IBidirectionalRelation res = null; |
| 1880 |
if (annotationName.equals(JPAEditorConstants.ANNOTATION_ONE_TO_ONE)) { |
1943 |
if (annotationName.equals(JPAEditorConstants.ANNOTATION_ONE_TO_ONE)) { |
| 1881 |
if (!fp.doesRelationExist(jpt, relJPT, ownerAttrName, RelType.ONE_TO_ONE, |
1944 |
if (!fp.doesRelationExist(jpt, relJPT, ownerAttrName, RelType.ONE_TO_ONE, |
| 1882 |
RelDir.BI)) |
1945 |
RelDir.BI)) |
|
Lines 2167-2172
Link Here
|
| 2167 |
Iterator<Connection> iter = Graphiti.getPeService().getAllConnections(cs).iterator(); |
2230 |
Iterator<Connection> iter = Graphiti.getPeService().getAllConnections(cs).iterator(); |
| 2168 |
while (iter.hasNext()) { |
2231 |
while (iter.hasNext()) { |
| 2169 |
Connection conn = iter.next(); |
2232 |
Connection conn = iter.next(); |
|
|
2233 |
String v = Graphiti.getPeService().getPropertyValue(conn, IsARelation.IS_A_CONNECTION_PROP_KEY); |
| 2234 |
if (Boolean.TRUE.toString().equals(v)) |
| 2235 |
continue; |
| 2170 |
IRemoveContext ctx = new RemoveContext(conn); |
2236 |
IRemoveContext ctx = new RemoveContext(conn); |
| 2171 |
ctxs.add(ctx); |
2237 |
ctxs.add(ctx); |
| 2172 |
} |
2238 |
} |
|
Lines 2200-2205
Link Here
|
| 2200 |
} |
2266 |
} |
| 2201 |
} |
2267 |
} |
| 2202 |
|
2268 |
|
|
|
2269 |
public void addIsARelations(IJPAEditorFeatureProvider fp, |
| 2270 |
Collection<IsARelation> rels) { |
| 2271 |
Iterator<IsARelation> it = rels.iterator(); |
| 2272 |
while (it.hasNext()) { |
| 2273 |
IsARelation rel = it.next(); |
| 2274 |
addNewIsARelation(fp, rel); |
| 2275 |
} |
| 2276 |
} |
| 2277 |
|
| 2203 |
private void addNewRelation(IJPAEditorFeatureProvider fp, IRelation rel) { |
2278 |
private void addNewRelation(IJPAEditorFeatureProvider fp, IRelation rel) { |
| 2204 |
AddConnectionContext ctx = new AddConnectionContext(JPAEditorUtil |
2279 |
AddConnectionContext ctx = new AddConnectionContext(JPAEditorUtil |
| 2205 |
.getAnchor(rel.getOwner(), fp), JPAEditorUtil.getAnchor(rel |
2280 |
.getAnchor(rel.getOwner(), fp), JPAEditorUtil.getAnchor(rel |
|
Lines 2212-2217
Link Here
|
| 2212 |
ft.add(ctx); |
2287 |
ft.add(ctx); |
| 2213 |
} |
2288 |
} |
| 2214 |
|
2289 |
|
|
|
2290 |
private void addNewIsARelation(IJPAEditorFeatureProvider fp, IsARelation rel) { |
| 2291 |
AddConnectionContext ctx = new AddConnectionContext(JPAEditorUtil |
| 2292 |
.getAnchor(rel.getSubclass(), fp), JPAEditorUtil.getAnchor(rel.getSuperclass(), fp)); |
| 2293 |
ctx.setNewObject(rel); |
| 2294 |
ctx.setTargetContainer(fp.getDiagramTypeProvider().getDiagram()); |
| 2295 |
refreshEntityModel(fp, rel.getSubclass()); |
| 2296 |
refreshEntityModel(fp, rel.getSuperclass()); |
| 2297 |
AddInheritedEntityFeature ft = new AddInheritedEntityFeature(fp); |
| 2298 |
ft.add(ctx); |
| 2299 |
} |
| 2300 |
|
| 2215 |
private String getRelTypeName(RelationshipMappingAnnotation an, |
2301 |
private String getRelTypeName(RelationshipMappingAnnotation an, |
| 2216 |
JavaResourceAttribute jra) { |
2302 |
JavaResourceAttribute jra) { |
| 2217 |
String relTypeName = null; |
2303 |
String relTypeName = null; |
|
Lines 2252-2269
Link Here
|
| 2252 |
return res.toArray(ret); |
2338 |
return res.toArray(ret); |
| 2253 |
} |
2339 |
} |
| 2254 |
|
2340 |
|
| 2255 |
public boolean isId(JavaPersistentAttribute jpa) { |
2341 |
// returns true even if the primary key is inherited |
|
|
2342 |
public boolean hasOrInheritsPrimaryKey(JavaPersistentType jpt) { |
| 2343 |
Iterable<ReadOnlyPersistentAttribute> attributes = jpt.getAllAttributes(); |
| 2344 |
Iterator<ReadOnlyPersistentAttribute> it = attributes.iterator(); |
| 2345 |
while (it.hasNext()) { |
| 2346 |
ReadOnlyPersistentAttribute at = it.next(); |
| 2347 |
if (isId(at)) |
| 2348 |
return true; |
| 2349 |
} |
| 2350 |
return false; |
| 2351 |
} |
| 2352 |
|
| 2353 |
public boolean hasPrimaryKey(JavaPersistentType jpt) { |
| 2354 |
for (JavaPersistentAttribute at : jpt.getAttributes()) |
| 2355 |
if (isId(at)) return true; |
| 2356 |
return false; |
| 2357 |
} |
| 2358 |
|
| 2359 |
|
| 2360 |
public boolean isId(ReadOnlyPersistentAttribute jpa) { |
| 2256 |
return isSimpleId(jpa) || isEmbeddedId(jpa); |
2361 |
return isSimpleId(jpa) || isEmbeddedId(jpa); |
| 2257 |
} |
2362 |
} |
| 2258 |
|
2363 |
|
| 2259 |
public boolean isSimpleId(JavaPersistentAttribute jpa) { |
2364 |
public boolean isSimpleId(ReadOnlyPersistentAttribute jpa) { |
| 2260 |
IdAnnotation an = (IdAnnotation)jpa.getResourceAttribute().getAnnotation(IdAnnotation.ANNOTATION_NAME); |
2365 |
return (jpa.getMappingKey() == MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); |
| 2261 |
return (an != null); |
|
|
| 2262 |
} |
2366 |
} |
| 2263 |
|
2367 |
|
| 2264 |
public boolean isEmbeddedId(JavaPersistentAttribute jpa) { |
2368 |
public boolean isEmbeddedId(ReadOnlyPersistentAttribute jpa) { |
| 2265 |
EmbeddedIdAnnotation an = (EmbeddedIdAnnotation)jpa.getResourceAttribute().getAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME); |
2369 |
return (jpa.getMappingKey() == MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY); |
| 2266 |
return (an != null); |
|
|
| 2267 |
} |
2370 |
} |
| 2268 |
|
2371 |
|
| 2269 |
public String getColumnName(JavaPersistentAttribute jpa) { |
2372 |
public String getColumnName(JavaPersistentAttribute jpa) { |
|
Lines 2278-2282
Link Here
|
| 2278 |
return columnName; |
2381 |
return columnName; |
| 2279 |
} |
2382 |
} |
| 2280 |
|
2383 |
|
|
|
2384 |
public IColorConstant getForeground(JPAEditorConstants.DIAGRAM_OBJECT_TYPE dot) { |
| 2385 |
IColorConstant foreground = dot.equals(JPAEditorConstants.DIAGRAM_OBJECT_TYPE.MappedSupeclass) ? |
| 2386 |
JPAEditorConstants.MAPPED_SUPERCLASS_BORDER_COLOR: |
| 2387 |
JPAEditorConstants.ENTITY_BORDER_COLOR; |
| 2388 |
return foreground; |
| 2389 |
} |
| 2281 |
|
2390 |
|
|
|
2391 |
public IColorConstant getBackground(JPAEditorConstants.DIAGRAM_OBJECT_TYPE dot) { |
| 2392 |
IColorConstant background = dot.equals(JPAEditorConstants.DIAGRAM_OBJECT_TYPE.MappedSupeclass) ? |
| 2393 |
JPAEditorConstants.MAPPED_SUPERCLASS_BACKGROUND: |
| 2394 |
JPAEditorConstants.ENTITY_BACKGROUND; |
| 2395 |
return background; |
| 2396 |
} |
| 2397 |
|
| 2398 |
public String getRenderingStyle(JPAEditorConstants.DIAGRAM_OBJECT_TYPE dot) { |
| 2399 |
String renderingStyle = dot.equals(JPAEditorConstants.DIAGRAM_OBJECT_TYPE.MappedSupeclass) ? |
| 2400 |
IJPAEditorPredefinedRenderingStyle.GREEN_WHITE_GLOSS_ID : |
| 2401 |
IJPAEditorPredefinedRenderingStyle.BLUE_WHITE_GLOSS_ID; |
| 2402 |
return renderingStyle; |
| 2403 |
} |
| 2404 |
|
| 2405 |
public JPAEditorConstants.DIAGRAM_OBJECT_TYPE determineDiagramObjectType(JavaPersistentType jpt) { |
| 2406 |
if (this.hasEntityAnnotation(jpt)) { |
| 2407 |
return JPAEditorConstants.DIAGRAM_OBJECT_TYPE.Entity; |
| 2408 |
} else if (this.hasMappedSuperclassAnnotation(jpt)) { |
| 2409 |
return JPAEditorConstants.DIAGRAM_OBJECT_TYPE.MappedSupeclass; |
| 2410 |
} |
| 2411 |
throw new IllegalArgumentException(); |
| 2412 |
} |
| 2413 |
|
| 2414 |
public String generateIdName(JavaPersistentType jpt) { |
| 2415 |
String name = "id"; //$NON-NLS-1$ |
| 2416 |
String genName = name; |
| 2417 |
for (int i = 0; i < 10000000; i++) { |
| 2418 |
if (!hasAttributeNamed(jpt, genName)) |
| 2419 |
return genName; |
| 2420 |
genName = name + "_" + i; //$NON-NLS-1$ |
| 2421 |
} |
| 2422 |
return genName; |
| 2423 |
} |
| 2424 |
|
| 2425 |
|
| 2426 |
private boolean hasAttributeNamed(JavaPersistentType jpt, String name) { |
| 2427 |
Iterable<String> hier = jpt.getAllAttributeNames(); |
| 2428 |
Iterator<String> it = hier.iterator(); |
| 2429 |
while (it.hasNext()) { |
| 2430 |
String atName = it.next(); |
| 2431 |
if (name.equals(atName)) |
| 2432 |
return true; |
| 2433 |
} |
| 2434 |
return false; |
| 2435 |
} |
| 2436 |
|
| 2437 |
public String getMappedSuperclassPackageDeclaration(JavaPersistentType jpt) throws JavaModelException { |
| 2438 |
String packageName = null; |
| 2439 |
IPackageDeclaration[] packages = JPAEditorUtil.getCompilationUnit(jpt) |
| 2440 |
.getPackageDeclarations(); |
| 2441 |
if (packages.length > 0) { |
| 2442 |
IPackageDeclaration packageDecl = packages[0]; |
| 2443 |
packageName = packageDecl.getElementName(); |
| 2444 |
} |
| 2445 |
return packageName; |
| 2446 |
} |
| 2447 |
|
| 2448 |
|
| 2282 |
} |
2449 |
} |