private bool Build(bool throwErrors) { if (sourceEntity == null) { if (relationDescriptor.GetSourceEntity() != null) { if (persistenceUnit.ContainsEntity(relationDescriptor.GetSourceEntity())) { sourceEntity = persistenceUnit.GetEntity(relationDescriptor.GetSourceEntity()); } } } if (sourceEntity == null) { if (relationDescriptor.GetSourceEntityType() != null) { if (persistenceUnit.ContainsEntity(relationDescriptor.GetSourceEntityType())) { sourceEntity = persistenceUnit.GetEntity(relationDescriptor.GetSourceEntityType()); } } } if (targetEntity == null) { if (relationDescriptor.GetTargetEntity() != null) { if (persistenceUnit.ContainsEntity(relationDescriptor.GetTargetEntity())) { targetEntity = persistenceUnit.GetEntity(relationDescriptor.GetTargetEntity()); } } } if (targetEntity == null) { if (relationDescriptor.GetTargetEntityType() != null) { if (persistenceUnit.ContainsEntity(relationDescriptor.GetTargetEntityType())) { targetEntity = persistenceUnit.GetEntity(relationDescriptor.GetTargetEntityType()); } } } if (sourceEntity == null) { if (throwErrors) { throw new Net.Vpc.Upa.Exceptions.UPAException("InvalidRelationEntityNotFound", relationDescriptor.GetSourceEntityType()); } else { return(false); } } if (targetEntity == null) { if (throwErrors) { throw new Net.Vpc.Upa.Exceptions.UPAException("InvalidRelationEntityNotFound", relationDescriptor.GetTargetEntityType()); } else { return(false); } } sourceUpdateType = Net.Vpc.Upa.RelationshipUpdateType.FLAT; sourceFieldNames = new System.Collections.Generic.List <string>(); if (relationDescriptor.GetBaseField() == null) { Net.Vpc.Upa.Impl.FwkConvertUtils.ListAddRange(sourceFieldNames, new System.Collections.Generic.List <string>(relationDescriptor.GetSourceFields())); if (relationDescriptor.GetMappedTo() != null && relationDescriptor.GetMappedTo().Length > 0) { if (relationDescriptor.GetMappedTo().Length > 1) { throw new System.ArgumentException("mappedTo cannot only apply to single Entity Field"); } manyToOneField = sourceEntity.GetField(relationDescriptor.GetMappedTo()[0]); } } else { Net.Vpc.Upa.Field baseField = sourceEntity.GetField(relationDescriptor.GetBaseField()); Net.Vpc.Upa.Types.DataType baseFieldType = baseField.GetDataType(); if (baseFieldType is Net.Vpc.Upa.Types.ManyToOneType) { Net.Vpc.Upa.Types.ManyToOneType et = (Net.Vpc.Upa.Types.ManyToOneType)baseFieldType; if (et.GetTargetEntityName() == null || (et.GetTargetEntityName().Length == 0)) { et.SetTargetEntityName(targetEntity.GetName()); } sourceUpdateType = Net.Vpc.Upa.RelationshipUpdateType.COMPOSED; System.Collections.Generic.IList <Net.Vpc.Upa.Field> masterPK = targetEntity.GetPrimaryFields(); if (relationDescriptor.GetMappedTo() == null || relationDescriptor.GetMappedTo().Length == 0) { if ((masterPK.Count == 0)) { if (throwErrors) { throw new Net.Vpc.Upa.Exceptions.UPAException("PrimaryFieldsNotFoundException", targetEntity.GetName()); } else { return(false); } } else { foreach (Net.Vpc.Upa.Field masterField in masterPK) { string f = masterField.GetName(); if ((f).Length == 1) { f = f.ToUpper(); } else if ((f).Length > 1) { f = f.Substring(0, 1).ToUpper() + f.Substring(1); } string extraName = baseField.GetName() + f; sourceFieldNames.Add(extraName); } } } else { Net.Vpc.Upa.Impl.FwkConvertUtils.ListAddRange(sourceFieldNames, new System.Collections.Generic.List <string>(relationDescriptor.GetMappedTo())); } if ((sourceFieldNames).Count != (masterPK).Count) { if (throwErrors) { throw new System.ArgumentException("Incorrect parameters"); } else { return(false); } } if ((sourceFieldNames.Count == 0)) { if (throwErrors) { throw new System.ArgumentException("Incorrect parameters"); } else { return(false); } } for (int i = 0; i < (sourceFieldNames).Count; i++) { string extraName = sourceFieldNames[i]; Net.Vpc.Upa.Field idField = sourceEntity.FindField(extraName); if (idField == null) { Net.Vpc.Upa.Types.DataType dt = (Net.Vpc.Upa.Types.DataType)masterPK[i].GetDataType().Copy(); bool nullable = baseFieldType.IsNullable(); dt.SetNullable(nullable); idField = sourceEntity.AddField(extraName, "system", Net.Vpc.Upa.FlagSets.Of <E>(Net.Vpc.Upa.UserFieldModifier.SYSTEM), Net.Vpc.Upa.FlagSets.Of <E>(Net.Vpc.Upa.UserFieldModifier.UPDATE), null, dt, -1); idField.SetAccessLevel(Net.Vpc.Upa.AccessLevel.PRIVATE); } else { idField.SetUserExcludeModifiers(idField.GetUserExcludeModifiers().Add(Net.Vpc.Upa.UserFieldModifier.UPDATE)); } } manyToOneField = baseField; } else { sourceFieldNames.Add(baseField.GetName()); if (relationDescriptor.GetMappedTo() != null && relationDescriptor.GetMappedTo().Length > 0) { if (relationDescriptor.GetMappedTo().Length > 1) { throw new System.ArgumentException("mappedTo cannot only apply to single Entity Field"); } manyToOneField = sourceEntity.GetField(relationDescriptor.GetMappedTo()[0]); } } } nullable = true; //TODO FIX ME for (int i = 0; i < (sourceFieldNames).Count; i++) { Net.Vpc.Upa.Field slaveField = sourceEntity.GetField(sourceFieldNames[i]); Net.Vpc.Upa.Types.DataType dataType = slaveField.GetDataType(); if (dataType == null) { //inherit master DataType if ((targetEntity.GetPrimaryFields()).Count > i) { Net.Vpc.Upa.Types.DataType d = targetEntity.GetPrimaryFields()[i].GetDataType(); d = (Net.Vpc.Upa.Types.DataType)d.Copy(); d.SetNullable(nullable); slaveField.SetDataType(d); //reset transform! slaveField.SetTypeTransform(null); } else { throw new System.ArgumentException("Invalid Relation"); } } } filter = relationDescriptor.GetFilter(); // if (baseFieldType instanceof ManyToOneType) { // manyToOneField = baseField; // } else if (sourceFieldNames.size() == 1) { // DataType slaveType = slaveField.getDataType(); // if (slaveType instanceof ManyToOneType) { // manyToOneField = slaveField; // } // } return(true); }
public virtual void Synchronize() { if (field.GetDataType() is Net.Vpc.Upa.Types.ManyToOneType) { Net.Vpc.Upa.Types.ManyToOneType t = (Net.Vpc.Upa.Types.ManyToOneType)field.GetDataType(); Net.Vpc.Upa.Relationship relation = t.GetRelationship(); if (relation == null) { throw new Net.Vpc.Upa.Exceptions.UPAException("MissingRelationForField", field); } Net.Vpc.Upa.RelationshipRole detailRole = relation.GetSourceRole(); Net.Vpc.Upa.RelationshipUpdateType u = detailRole.GetRelationshipUpdateType(); if (u == Net.Vpc.Upa.RelationshipUpdateType.COMPOSED) { persistFieldPersister = new Net.Vpc.Upa.Impl.Persistence.ComposedToFlatFieldPersister(field); updateFieldPersister = new Net.Vpc.Upa.Impl.Persistence.ComposedToFlatFieldPersister(field); } persistFormulaPass = 0; updateFormulaPass = 0; postPersistFormula = false; postUpdateFormula = false; return; } Net.Vpc.Upa.Formula persistFormula = field.GetPersistFormula(); if (persistFormula != null) { if (persistFormula is Net.Vpc.Upa.Sequence) { persistFieldPersister = UpdateFieldPersister(persistFieldPersister, persistenceStore.CreatePersistSequenceGenerator(field)); persistFormulaPass = 0; postPersistFormula = false; } else if (persistFormula is Net.Vpc.Upa.ExpressionFormula) { Net.Vpc.Upa.Impl.Persistence.RebuildExpressionInfo re = RebuildExpression((Net.Vpc.Upa.ExpressionFormula)persistFormula); if (re.rebuiltFormula != null) { field.SetPersistFormula(re.rebuiltFormula); } bool complex = re.compiledExpression.FindFirstExpression <T>(Net.Vpc.Upa.Impl.Uql.Compiledfilters.CompiledExpressionHelper.THIS_VAR_FILTER) != default(T); persistFormulaPass = field.GetPersistFormulaOrder(); if (!complex && persistFormulaPass == 0) { insertExpression = re.expression; persistFieldPersister = UpdateFieldPersister(persistFieldPersister, new Net.Vpc.Upa.Impl.Persistence.ExpressionFieldPersister(field.GetName(), re.expression)); postPersistFormula = false; } else { postPersistFormula = true; } } else { postPersistFormula = true; } } else { postPersistFormula = false; } Net.Vpc.Upa.Formula updateFormula = field.GetUpdateFormula(); if (updateFormula != null) { if (updateFormula is Net.Vpc.Upa.Sequence) { updateFieldPersister = UpdateFieldPersister(updateFieldPersister, persistenceStore.CreateUpdateSequenceGenerator(field)); updateFormulaPass = 0; postUpdateFormula = false; } else if (updateFormula is Net.Vpc.Upa.ExpressionFormula) { Net.Vpc.Upa.Impl.Persistence.RebuildExpressionInfo re = RebuildExpression((Net.Vpc.Upa.ExpressionFormula)persistFormula); if (re.rebuiltFormula != null) { field.SetUpdateFormula(re.rebuiltFormula); } // List<DefaultCompiledExpression> complex = re.compiledExpression.findExpressionsList(CompiledExpressionHelper.THIS_VAR_FILTER); updateFormulaPass = field.GetUpdateFormulaOrder(); if (updateFormulaPass == 0) { updateExpression = re.expression; updateFieldPersister = UpdateFieldPersister(updateFieldPersister, new Net.Vpc.Upa.Impl.Persistence.ExpressionFieldPersister(field.GetName(), re.expression)); postUpdateFormula = false; } else { postUpdateFormula = true; } } else { postUpdateFormula = true; } } else { postUpdateFormula = true; } Net.Vpc.Upa.Formula selectFormula = field.GetSelectFormula(); if (selectFormula != null) { if (selectFormula is Net.Vpc.Upa.ExpressionFormula) { findtExpression = ((Net.Vpc.Upa.ExpressionFormula)selectFormula).GetExpression(); } else if (selectFormula is Net.Vpc.Upa.Sequence) { throw new System.ArgumentException("Sequences are not supported as Select Expressions"); } else if (updateFormula is Net.Vpc.Upa.CustomUpdaterFormula) { throw new System.ArgumentException("CustomUpdaterFormulas are not supported as Select Expressions"); } } }
public virtual void SetRelationshipUpdateType(Net.Vpc.Upa.RelationshipUpdateType relationUpdateType) { this.relationUpdateType = relationUpdateType; }