use of org.hibernate.eclipse.jdt.ui.internal.jpa.common.RefEntityInfo in project jbosstools-hibernate by jbosstools.
the class ResolveAmbiguous method findMappedRefEntityInfo.
protected RefEntityInfo findMappedRefEntityInfo(RefEntityInfo rei) {
if (rei.mappedBy == null) {
return null;
}
String fullyQualifiedName2 = rei.fullyQualifiedName;
EntityInfo entryInfo2 = data.getEntities().get(fullyQualifiedName2);
RefEntityInfo refEntityInfo = entryInfo2.getFieldIdRefEntityInfo(rei.mappedBy);
return refEntityInfo;
}
use of org.hibernate.eclipse.jdt.ui.internal.jpa.common.RefEntityInfo in project jbosstools-hibernate by jbosstools.
the class ProcessEntityInfo method visit.
@SuppressWarnings("unchecked")
public boolean visit(MethodDeclaration node) {
if (entityInfo == null) {
return false;
}
if (annotationStyle != AnnotStyle.GETTERS) {
return true;
}
if (node.getName().getFullyQualifiedName().compareTo(entityInfo.getName()) == 0 || node.isConstructor()) {
// this is constructor declaration
return true;
}
// -) is it setter?
if (// $NON-NLS-1$
node.getName().getIdentifier().startsWith("set") && node.parameters().size() == 1) {
// setter - do not process it
return true;
}
// +) is it getter?
if (!(// $NON-NLS-1$
node.getName().getIdentifier().startsWith("get") || // $NON-NLS-1$
node.getName().getIdentifier().startsWith("is")) || node.parameters().size() > 0) {
// not the getter - do not process it
return true;
}
Type type = node.getReturnType2();
if (type == null) {
return true;
}
String returnIdentifier = CollectEntityInfo.getReturnIdentifier(node);
if (type.isSimpleType() || type.isPrimitiveType()) {
if (entityInfo.isAddGeneratedValueFlag()) {
String primaryIdName = entityInfo.getPrimaryIdName();
boolean addGeneratedValueMarker = false;
if (primaryIdName.equals(returnIdentifier)) {
addGeneratedValueMarker = true;
}
if (addGeneratedValueMarker) {
MarkerAnnotation matd = rewriter.getAST().newMarkerAnnotation();
matd.setTypeName(rewriter.getAST().newSimpleName(JPAConst.ANNOTATION_GENERATED_VALUE));
ListRewrite lrw = rewriter.getListRewrite(node, MethodDeclaration.MODIFIERS2_PROPERTY);
lrw.insertFirst(matd, null);
}
}
if (entityInfo.isAddPrimaryIdFlag()) {
String primaryIdName = entityInfo.getPrimaryIdName();
boolean addIdMarker = false;
if (primaryIdName.equals(returnIdentifier)) {
addIdMarker = true;
}
if (addIdMarker) {
MarkerAnnotation matd = rewriter.getAST().newMarkerAnnotation();
matd.setTypeName(rewriter.getAST().newSimpleName(JPAConst.ANNOTATION_ID));
ListRewrite lrw = rewriter.getListRewrite(node, MethodDeclaration.MODIFIERS2_PROPERTY);
lrw.insertFirst(matd, null);
}
}
if (enableOptLock && entityInfo.isAddVersionFlag() && !entityInfo.hasVersionAnnotation()) {
boolean addVersionMarker = false;
if ("version".equals(returnIdentifier)) {
// $NON-NLS-1$
addVersionMarker = true;
}
if (addVersionMarker) {
MarkerAnnotation matd = rewriter.getAST().newMarkerAnnotation();
matd.setTypeName(rewriter.getAST().newSimpleName(JPAConst.ANNOTATION_VERSION));
ListRewrite lrw = rewriter.getListRewrite(node, MethodDeclaration.MODIFIERS2_PROPERTY);
lrw.insertFirst(matd, null);
}
}
}
if (type.isSimpleType() && (AllEntitiesProcessor.columnLength != defaultStrLength)) {
SimpleType simpleType = (SimpleType) type;
String typeName = simpleType.getName().getFullyQualifiedName();
if ("java.lang.String".equals(typeName) || "String".equals(typeName)) {
// $NON-NLS-1$ //$NON-NLS-2$
String fieldId = returnIdentifier;
RefColumnInfo rci = entityInfo.getRefColumnInfo(fieldId);
if (rci == null || !rci.isExist()) {
// if there is no @Column annotation - create new @Column annotation
// with user defined default value length
NormalAnnotation natd = rewriter.getAST().newNormalAnnotation();
natd.setTypeName(rewriter.getAST().newSimpleName(JPAConst.ANNOTATION_COLUMN));
ListRewrite lrw = rewriter.getListRewrite(node, MethodDeclaration.MODIFIERS2_PROPERTY);
lrw.insertFirst(natd, null);
MemberValuePair mvp = rewriter.getAST().newMemberValuePair();
// $NON-NLS-1$
mvp.setName(rewriter.getAST().newSimpleName("length"));
NumberLiteral nl = rewriter.getAST().newNumberLiteral(String.valueOf(defaultStrLength));
mvp.setValue(nl);
natd.values().add(mvp);
}
}
}
if (type.isSimpleType() || type.isParameterizedType() || type.isArrayType()) {
// $NON-NLS-1$
String fieldId = "";
RefType refType = RefType.UNDEF;
boolean annotated = false;
// $NON-NLS-1$
String fullyQualifiedName2 = "";
fieldId = returnIdentifier;
refType = entityInfo.getFieldIdRelValue(fieldId);
annotated = entityInfo.getFieldIdAnnotatedValue(fieldId);
fullyQualifiedName2 = entityInfo.getFieldIdFQNameValue(fieldId);
Set<RefFieldInfo> setRFI = entityInfo.getRefFieldInfoSet(fullyQualifiedName2);
if (!annotated && setRFI != null && isSimilarType(type, fullyQualifiedName2)) {
RefEntityInfo rei = entityInfo.getFieldIdRefEntityInfo(fieldId);
// either side may be the owning side
if (setRFI.size() > 1 && refType != RefType.MANY2ONE) {
if (rei.mappedBy == null || rei.mappedBy == "") {
// $NON-NLS-1$
addSimpleMarkerAnnotation(node, JPAConst.getRefType(refType));
} else {
// give to the user information about selected mapping
addComplexNormalAnnotation(node, JPAConst.getRefType(refType), rei);
}
} else if (refType == RefType.MANY2ONE || refType == RefType.ENUMERATED || rei.mappedBy == null || rei.mappedBy == "") {
// $NON-NLS-1$
addSimpleMarkerAnnotation(node, JPAConst.getRefType(refType));
} else {
// in case of bidirectional OneToOne - mark both sides with mappedBy -
// user should select the right decision
addComplexNormalAnnotation(node, JPAConst.getRefType(refType), rei);
}
}
}
return true;
}
use of org.hibernate.eclipse.jdt.ui.internal.jpa.common.RefEntityInfo in project jbosstools-hibernate by jbosstools.
the class ProcessEntityInfo method visit.
@SuppressWarnings("unchecked")
public boolean visit(FieldDeclaration node) {
if (entityInfo == null) {
return false;
}
if (annotationStyle != AnnotStyle.FIELDS) {
return true;
}
Type type = node.getType();
if (type == null) {
return true;
}
if (type.isSimpleType() || type.isPrimitiveType()) {
if (entityInfo.isAddGeneratedValueFlag()) {
String primaryIdName = entityInfo.getPrimaryIdName();
Iterator<VariableDeclarationFragment> itVarNames = node.fragments().iterator();
boolean addGeneratedValueMarker = false;
while (itVarNames.hasNext()) {
VariableDeclarationFragment var = itVarNames.next();
String name = var.getName().getIdentifier();
if (primaryIdName.equals(name)) {
addGeneratedValueMarker = true;
break;
}
}
if (addGeneratedValueMarker) {
MarkerAnnotation matd = rewriter.getAST().newMarkerAnnotation();
matd.setTypeName(rewriter.getAST().newSimpleName(JPAConst.ANNOTATION_GENERATED_VALUE));
ListRewrite lrw = rewriter.getListRewrite(node, FieldDeclaration.MODIFIERS2_PROPERTY);
lrw.insertFirst(matd, null);
}
}
if (entityInfo.isAddPrimaryIdFlag()) {
String primaryIdName = entityInfo.getPrimaryIdName();
Iterator<VariableDeclarationFragment> itVarNames = node.fragments().iterator();
boolean addIdMarker = false;
while (itVarNames.hasNext()) {
VariableDeclarationFragment var = itVarNames.next();
String name = var.getName().getIdentifier();
if (primaryIdName.equals(name)) {
addIdMarker = true;
break;
}
}
if (addIdMarker) {
MarkerAnnotation matd = rewriter.getAST().newMarkerAnnotation();
matd.setTypeName(rewriter.getAST().newSimpleName(JPAConst.ANNOTATION_ID));
ListRewrite lrw = rewriter.getListRewrite(node, FieldDeclaration.MODIFIERS2_PROPERTY);
lrw.insertFirst(matd, null);
}
}
if (enableOptLock && entityInfo.isAddVersionFlag() && !entityInfo.hasVersionAnnotation()) {
Iterator<VariableDeclarationFragment> itVarNames = node.fragments().iterator();
boolean addVersionMarker = false;
while (itVarNames.hasNext()) {
VariableDeclarationFragment var = itVarNames.next();
String name = var.getName().getIdentifier();
if ("version".equals(name)) {
// $NON-NLS-1$
addVersionMarker = true;
break;
}
}
if (addVersionMarker) {
MarkerAnnotation matd = rewriter.getAST().newMarkerAnnotation();
matd.setTypeName(rewriter.getAST().newSimpleName(JPAConst.ANNOTATION_VERSION));
ListRewrite lrw = rewriter.getListRewrite(node, FieldDeclaration.MODIFIERS2_PROPERTY);
lrw.insertFirst(matd, null);
}
}
}
if (type.isSimpleType() && (AllEntitiesProcessor.columnLength != defaultStrLength)) {
SimpleType simpleType = (SimpleType) type;
String typeName = simpleType.getName().getFullyQualifiedName();
if ("java.lang.String".equals(typeName) || "String".equals(typeName)) {
// $NON-NLS-1$ //$NON-NLS-2$
String fieldId = null;
Iterator<VariableDeclarationFragment> itVarNames = node.fragments().iterator();
while (itVarNames.hasNext()) {
VariableDeclarationFragment var = itVarNames.next();
fieldId = var.getName().getIdentifier();
if (fieldId != null) {
break;
}
}
RefColumnInfo rci = entityInfo.getRefColumnInfo(fieldId);
if (rci == null || !rci.isExist()) {
// if there is no @Column annotation - create new @Column annotation
// with user defined default value length
NormalAnnotation natd = rewriter.getAST().newNormalAnnotation();
natd.setTypeName(rewriter.getAST().newSimpleName(JPAConst.ANNOTATION_COLUMN));
ListRewrite lrw = rewriter.getListRewrite(node, FieldDeclaration.MODIFIERS2_PROPERTY);
lrw.insertFirst(natd, null);
MemberValuePair mvp = rewriter.getAST().newMemberValuePair();
// $NON-NLS-1$
mvp.setName(rewriter.getAST().newSimpleName("length"));
NumberLiteral nl = rewriter.getAST().newNumberLiteral(String.valueOf(defaultStrLength));
mvp.setValue(nl);
natd.values().add(mvp);
}
}
}
if (type.isSimpleType() || type.isParameterizedType() || type.isArrayType()) {
Iterator<VariableDeclarationFragment> itVarNames = node.fragments().iterator();
// $NON-NLS-1$
String fieldId = "";
RefType refType = RefType.UNDEF;
boolean annotated = false;
// $NON-NLS-1$
String fullyQualifiedName2 = "";
while (itVarNames.hasNext()) {
VariableDeclarationFragment var = itVarNames.next();
String name = var.getName().getIdentifier();
fieldId = name;
refType = entityInfo.getFieldIdRelValue(fieldId);
annotated = entityInfo.getFieldIdAnnotatedValue(fieldId);
fullyQualifiedName2 = entityInfo.getFieldIdFQNameValue(fieldId);
if (refType != RefType.UNDEF) {
break;
}
}
Set<RefFieldInfo> setRFI = entityInfo.getRefFieldInfoSet(fullyQualifiedName2);
if (!annotated && setRFI != null && isSimilarType(type, fullyQualifiedName2)) {
RefEntityInfo rei = entityInfo.getFieldIdRefEntityInfo(fieldId);
// either side may be the owning side
if (setRFI.size() > 1 && refType != RefType.MANY2ONE) {
if (rei.mappedBy == null || rei.mappedBy == "") {
// $NON-NLS-1$
addSimpleMarkerAnnotation(node, JPAConst.getRefType(refType));
} else {
// give to the user information about selected mapping
addComplexNormalAnnotation(node, JPAConst.getRefType(refType), rei);
}
} else if (refType == RefType.MANY2ONE || refType == RefType.ENUMERATED || rei.mappedBy == null || rei.mappedBy == "") {
// $NON-NLS-1$
addSimpleMarkerAnnotation(node, JPAConst.getRefType(refType));
} else {
// in case of bidirectional OneToOne - mark both sides with mappedBy -
// user should select the right decision
addComplexNormalAnnotation(node, JPAConst.getRefType(refType), rei);
}
}
}
return true;
}
use of org.hibernate.eclipse.jdt.ui.internal.jpa.common.RefEntityInfo in project jbosstools-hibernate by jbosstools.
the class ResolveAmbiguous method updateEditorOwner.
public void updateEditorOwner(TableItem item) {
// Clean up any previous editor control
Control oldEditorOwner = editorOwner.getEditor();
if (oldEditorOwner != null) {
oldEditorOwner.dispose();
}
RefEntityInfo rei = (RefEntityInfo) item.getData();
CCombo comboOwner = new CCombo(table, SWT.NONE);
comboOwner.setEditable(false);
Color bkgnd = table.getBackground();
comboOwner.setBackground(bkgnd);
comboOwner.add(Utils.ownerTypeToStr(OwnerType.YES));
comboOwner.add(Utils.ownerTypeToStr(OwnerType.NO));
comboOwner.setText(Utils.ownerTypeToStr(rei.owner));
comboOwner.addModifyListener(editorOwnerModifyListener);
editorOwner.setEditor(comboOwner, item, COLUMN_OWNER);
}
use of org.hibernate.eclipse.jdt.ui.internal.jpa.common.RefEntityInfo in project jbosstools-hibernate by jbosstools.
the class AllEntitiesInfoCollector method resolveRelations.
/**
* process all entities pairs iteratively:
* firstly process pairs with more information about and
* pairs with small information about - process in last order
*/
public void resolveRelations() {
Iterator<Map.Entry<String, EntityInfo>> it = null;
// resolve parent/child relations
// in the case if a child has a @MappedSuperclass parent with version property
// we shouldn't add version property to the child
it = mapCUs_Info.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<String, EntityInfo> entry = it.next();
EntityInfo entityInfo = entry.getValue();
String javaProjectName = entityInfo.getJavaProjectName();
String parentName = entityInfo.getFullyQualifiedParentName();
if (hasMappedSuperclassVersion(javaProjectName, parentName)) {
entityInfo.setAddVersionFlag(false);
} else {
entityInfo.setAddVersionFlag(true);
}
entityInfo.updateVersionImport(entityInfo.isAddVersionFlag());
}
//
// resolve connection relations
int fromVariableCounter = 0;
int fromMethodCounter = 0;
// generate RefFieldInfoMap (for simple process)
it = mapCUs_Info.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<String, EntityInfo> entry = it.next();
EntityInfo entryInfo = entry.getValue();
entryInfo.generateRefFieldInfoMap();
fromVariableCounter += entryInfo.getFromVariableCounter();
fromMethodCounter += entryInfo.getFromMethodCounter();
}
if (fromVariableCounter >= fromMethodCounter) {
annotationStylePreference = AnnotStyle.FIELDS;
} else {
annotationStylePreference = AnnotStyle.GETTERS;
}
// update relations
EntityProcessor ep = new EntityProcessor();
// 0)
// process the user prompts
IConnector promptsConnector = new IConnector() {
public boolean updateRelation() {
if (pi == null) {
return false;
}
if (pi.refEntityInfo == null || pi.refEntityInfo2 == null) {
return false;
}
// no user prompt
int hasPrompt = 0;
// - use it as prompting from the user
if ((pi.fieldId != null && pi.fieldId.equals(pi.refEntityInfo2.mappedBy))) {
hasPrompt |= 1;
}
if ((pi.fieldId2 != null && pi.fieldId2.equals(pi.refEntityInfo.mappedBy))) {
hasPrompt |= 2;
}
if (hasPrompt != 0) {
// remember: in case of incorrect user prompts - we proceed his suggestions
if (hasPrompt == 1) {
if (pi.refEntityInfo2.refType == RefType.ONE2ONE) {
pi.refEntityInfo.refType = RefType.ONE2ONE;
pi.refEntityInfo.mappedBy = pi.fieldId2;
pi.refEntityInfo2.refType = RefType.ONE2ONE;
pi.refEntityInfo2.mappedBy = pi.fieldId;
updateOwner(pi);
} else if (pi.refEntityInfo2.refType == RefType.ONE2MANY) {
pi.refEntityInfo.refType = RefType.MANY2ONE;
pi.refEntityInfo.mappedBy = pi.fieldId2;
pi.refEntityInfo2.refType = RefType.ONE2MANY;
pi.refEntityInfo2.mappedBy = pi.fieldId;
updateOwner(pi);
} else if (pi.refEntityInfo2.refType == RefType.MANY2ONE) {
pi.refEntityInfo.refType = RefType.ONE2MANY;
pi.refEntityInfo.mappedBy = pi.fieldId2;
pi.refEntityInfo2.refType = RefType.MANY2ONE;
pi.refEntityInfo2.mappedBy = pi.fieldId;
updateOwner(pi);
} else if (pi.refEntityInfo2.refType == RefType.MANY2MANY) {
pi.refEntityInfo.refType = RefType.MANY2MANY;
pi.refEntityInfo.mappedBy = pi.fieldId2;
pi.refEntityInfo2.refType = RefType.MANY2MANY;
pi.refEntityInfo2.mappedBy = pi.fieldId;
updateOwner(pi);
}
} else if (hasPrompt == 2) {
if (pi.refEntityInfo.refType == RefType.ONE2ONE) {
pi.refEntityInfo.refType = RefType.ONE2ONE;
pi.refEntityInfo.mappedBy = pi.fieldId;
pi.refEntityInfo2.refType = RefType.ONE2ONE;
pi.refEntityInfo2.mappedBy = pi.fieldId2;
updateOwner(pi);
} else if (pi.refEntityInfo.refType == RefType.ONE2MANY) {
pi.refEntityInfo.refType = RefType.ONE2MANY;
pi.refEntityInfo.mappedBy = pi.fieldId;
pi.refEntityInfo2.refType = RefType.MANY2ONE;
pi.refEntityInfo2.mappedBy = pi.fieldId2;
updateOwner(pi);
} else if (pi.refEntityInfo.refType == RefType.MANY2ONE) {
pi.refEntityInfo.refType = RefType.MANY2ONE;
pi.refEntityInfo.mappedBy = pi.fieldId;
pi.refEntityInfo2.refType = RefType.ONE2MANY;
pi.refEntityInfo2.mappedBy = pi.fieldId2;
updateOwner(pi);
} else if (pi.refEntityInfo.refType == RefType.MANY2MANY) {
pi.refEntityInfo.refType = RefType.MANY2MANY;
pi.refEntityInfo.mappedBy = pi.fieldId;
pi.refEntityInfo2.refType = RefType.MANY2MANY;
pi.refEntityInfo2.mappedBy = pi.fieldId2;
updateOwner(pi);
}
}
// and it is possible this is not correct info... so try to adjust it.
if (pi.refEntityInfo.refType == RefType.ONE2ONE) {
if (pi.refEntityInfo2.refType == RefType.ONE2ONE) {
pi.refEntityInfo.refType = RefType.ONE2ONE;
pi.refEntityInfo.mappedBy = pi.fieldId2;
pi.refEntityInfo2.refType = RefType.ONE2ONE;
pi.refEntityInfo2.mappedBy = pi.fieldId;
updateOwner(pi);
} else if (pi.refEntityInfo2.refType == RefType.ONE2MANY) {
pi.refEntityInfo.refType = RefType.MANY2ONE;
pi.refEntityInfo.mappedBy = pi.fieldId2;
pi.refEntityInfo2.refType = RefType.ONE2MANY;
pi.refEntityInfo2.mappedBy = pi.fieldId;
updateOwner(pi);
}
} else if (pi.refEntityInfo.refType == RefType.ONE2MANY) {
if (pi.refEntityInfo2.refType == RefType.ONE2ONE) {
pi.refEntityInfo.refType = RefType.ONE2MANY;
pi.refEntityInfo.mappedBy = pi.fieldId2;
pi.refEntityInfo2.refType = RefType.MANY2ONE;
pi.refEntityInfo2.mappedBy = pi.fieldId;
updateOwner(pi);
} else if (pi.refEntityInfo2.refType == RefType.ONE2MANY) {
pi.refEntityInfo.refType = RefType.MANY2MANY;
pi.refEntityInfo.mappedBy = pi.fieldId2;
pi.refEntityInfo2.refType = RefType.MANY2MANY;
pi.refEntityInfo2.mappedBy = pi.fieldId;
updateOwner(pi);
}
}
}
return true;
}
};
ep.setConnector(promptsConnector);
ep.enumEntityPairs();
// prefer other mapping type to ManyToMany, so
// 1)
// first - try to assign other relations
IConnector simpleRelConnector = new IConnector() {
public boolean updateRelation() {
if (pi == null) {
return false;
}
if (pi.refEntityInfo == null || pi.refEntityInfo2 == null) {
return false;
}
if (pi.refEntityInfo.mappedBy == null && pi.refEntityInfo2.mappedBy == null) {
if (pi.refEntityInfo.refType == RefType.ONE2ONE) {
if (pi.refEntityInfo2.refType == RefType.ONE2ONE) {
pi.refEntityInfo.refType = RefType.ONE2ONE;
pi.refEntityInfo.mappedBy = pi.fieldId2;
pi.refEntityInfo2.refType = RefType.ONE2ONE;
pi.refEntityInfo2.mappedBy = pi.fieldId;
updateOwner(pi);
} else if (pi.refEntityInfo2.refType == RefType.ONE2MANY) {
pi.refEntityInfo.refType = RefType.MANY2ONE;
pi.refEntityInfo.mappedBy = pi.fieldId2;
pi.refEntityInfo2.refType = RefType.ONE2MANY;
pi.refEntityInfo2.mappedBy = pi.fieldId;
updateOwner(pi);
}
} else if (pi.refEntityInfo.refType == RefType.ONE2MANY) {
if (pi.refEntityInfo2.refType == RefType.ONE2ONE) {
pi.refEntityInfo.refType = RefType.ONE2MANY;
pi.refEntityInfo.mappedBy = pi.fieldId2;
pi.refEntityInfo2.refType = RefType.MANY2ONE;
pi.refEntityInfo2.mappedBy = pi.fieldId;
updateOwner(pi);
} else if (pi.refEntityInfo2.refType == RefType.MANY2ONE) {
pi.refEntityInfo.refType = RefType.ONE2MANY;
pi.refEntityInfo.mappedBy = pi.fieldId2;
pi.refEntityInfo2.refType = RefType.MANY2ONE;
pi.refEntityInfo2.mappedBy = pi.fieldId;
updateOwner(pi);
}
} else if (pi.refEntityInfo.refType == RefType.MANY2ONE) {
if (pi.refEntityInfo2.refType == RefType.ONE2MANY) {
pi.refEntityInfo.refType = RefType.MANY2ONE;
pi.refEntityInfo.mappedBy = pi.fieldId2;
pi.refEntityInfo2.refType = RefType.ONE2MANY;
pi.refEntityInfo2.mappedBy = pi.fieldId;
updateOwner(pi);
} else if (pi.refEntityInfo2.refType == RefType.MANY2ONE) {
pi.refEntityInfo.refType = RefType.ONE2ONE;
pi.refEntityInfo.mappedBy = pi.fieldId2;
pi.refEntityInfo2.refType = RefType.ONE2ONE;
pi.refEntityInfo2.mappedBy = pi.fieldId;
updateOwner(pi);
}
}
}
return true;
}
};
ep.setConnector(simpleRelConnector);
ep.enumEntityPairs();
// 2)
// second - try to assign - ManyToMany
// remember - here prefer other mapping type to ManyToMany
IConnector m2mRelConnector = new IConnector() {
public boolean updateRelation() {
if (pi == null) {
return false;
}
if (pi.refEntityInfo == null || pi.refEntityInfo2 == null) {
return false;
}
if (pi.refEntityInfo.mappedBy == null && pi.refEntityInfo2.mappedBy == null) {
if (pi.refEntityInfo.refType == RefType.ONE2MANY) {
if (pi.refEntityInfo2.refType == RefType.ONE2MANY) {
if (pi.refEntityInfo2.mappedBy == null) {
pi.refEntityInfo.refType = RefType.MANY2MANY;
pi.refEntityInfo.mappedBy = pi.fieldId2;
pi.refEntityInfo2.refType = RefType.MANY2MANY;
pi.refEntityInfo2.mappedBy = pi.fieldId;
updateOwner(pi);
}
}
}
}
return true;
}
};
ep.setConnector(m2mRelConnector);
ep.enumEntityPairs();
// 3)
// third - try to assign - "single candidates"
EntitySingleCandidateResolver escr = new EntitySingleCandidateResolver();
escr.enumEntityPairs();
// update import flags
it = mapCUs_Info.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<String, EntityInfo> entry = it.next();
EntityInfo entryInfo = entry.getValue();
Iterator<Map.Entry<String, RefEntityInfo>> referencesIt = entryInfo.getReferences().entrySet().iterator();
boolean isOne2One = false;
boolean isOne2Many = false;
boolean isMany2One = false;
boolean isMany2Many = false;
boolean isEnumerated = false;
for (; referencesIt.hasNext(); ) {
Map.Entry<String, RefEntityInfo> entry2 = referencesIt.next();
RefEntityInfo refEntityInfo = entry2.getValue();
if (refEntityInfo != null) {
if (refEntityInfo.refType == RefType.ONE2ONE && !refEntityInfo.resolvedAnnotationName) {
isOne2One = true;
} else if (refEntityInfo.refType == RefType.ONE2MANY && !refEntityInfo.resolvedAnnotationName) {
isOne2Many = true;
} else if (refEntityInfo.refType == RefType.MANY2ONE && !refEntityInfo.resolvedAnnotationName) {
isMany2One = true;
} else if (refEntityInfo.refType == RefType.MANY2MANY && !refEntityInfo.resolvedAnnotationName) {
isMany2Many = true;
} else if (refEntityInfo.refType == RefType.ENUMERATED && !refEntityInfo.resolvedAnnotationName) {
isEnumerated = true;
}
}
}
if (isOne2One) {
entryInfo.addRequiredImport(JPAConst.IMPORT_ONE2ONE);
}
if (isOne2Many) {
entryInfo.addRequiredImport(JPAConst.IMPORT_ONE2MANY);
}
if (isMany2One) {
entryInfo.addRequiredImport(JPAConst.IMPORT_MANY2ONE);
}
if (isMany2Many) {
entryInfo.addRequiredImport(JPAConst.IMPORT_MANY2MANY);
}
if (isEnumerated) {
entryInfo.addRequiredImport(JPAConst.IMPORT_ENUMERATED);
}
}
// re-generate RefFieldInfoMap (for simple process)
it = mapCUs_Info.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<String, EntityInfo> entry = it.next();
EntityInfo entryInfo = entry.getValue();
entryInfo.generateRefFieldInfoMap();
}
// if the parent has primary id - child should not generate it
it = mapCUs_Info.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<String, EntityInfo> entry = it.next();
EntityInfo entryInfo = entry.getValue();
adjustParentId(entryInfo);
}
}
Aggregations