public virtual Net.Vpc.Upa.Expressions.Expression CreateFindImmediateChildrenExpression(string alias, object id) /* throws Net.Vpc.Upa.Exceptions.UPAException */ { System.Collections.Generic.IList <Net.Vpc.Upa.Field> parentFields = GetTreeRelationship().GetSourceRole().GetFields(); Net.Vpc.Upa.Expressions.Expression a = null; Net.Vpc.Upa.Key key = GetEntity().GetBuilder().IdToKey(id); for (int i = 0; i < (parentFields).Count; i++) { Net.Vpc.Upa.Field field = parentFields[i]; Net.Vpc.Upa.Expressions.Var v = new Net.Vpc.Upa.Expressions.Var(alias == null ? null : new Net.Vpc.Upa.Expressions.Var(alias), field.GetName()); Net.Vpc.Upa.Expressions.Expression e = (new Net.Vpc.Upa.Expressions.Equals(v, new Net.Vpc.Upa.Expressions.Literal(key.GetObjectAt(i), field.GetDataType()))); a = a == null ? ((Net.Vpc.Upa.Expressions.Expression)(e)) : new Net.Vpc.Upa.Expressions.And(a, e); } return(a); }
protected internal virtual void ValidateChildren(object key, Net.Vpc.Upa.Persistence.EntityExecutionContext executionContext) /* throws Net.Vpc.Upa.Exceptions.UPAException */ { Net.Vpc.Upa.Record r = GetEntity().CreateQueryBuilder().ByExpression(GetEntity().GetBuilder().IdToExpression(key, null)).SetFieldFilter(Net.Vpc.Upa.Filters.Fields.ByName(GetHierarchyPathField())).GetRecord(); System.Collections.Generic.IList <Net.Vpc.Upa.Field> lfs = GetTreeRelationship().GetSourceRole().GetFields(); Net.Vpc.Upa.Expressions.Concat concat = new Net.Vpc.Upa.Expressions.Concat(); concat.Add(new Net.Vpc.Upa.Expressions.Literal(r.GetString(GetHierarchyPathField()), GetEntity().GetField(GetHierarchyPathField()).GetDataType())); System.Collections.Generic.IList <Net.Vpc.Upa.Field> primaryFields = GetEntity().GetPrimaryFields(); foreach (Net.Vpc.Upa.Field f in primaryFields) { concat.Add(new Net.Vpc.Upa.Expressions.Literal(GetHierarchyPathSeparator())); Net.Vpc.Upa.Types.DataType t = f.GetDataType(); Net.Vpc.Upa.Expressions.Var var = new Net.Vpc.Upa.Expressions.Var(f.GetName()); Net.Vpc.Upa.Expressions.Expression svar = null; if (t is Net.Vpc.Upa.Types.StringType) { svar = var; } else if (t is Net.Vpc.Upa.Types.IntType) { svar = new Net.Vpc.Upa.Expressions.I2V(var); } else if (t is Net.Vpc.Upa.Types.LongType) { svar = new Net.Vpc.Upa.Expressions.I2V(var); } else if (t is Net.Vpc.Upa.Types.DoubleType) { svar = new Net.Vpc.Upa.Expressions.D2V(var); } else if (t is Net.Vpc.Upa.Types.FloatType) { svar = new Net.Vpc.Upa.Expressions.D2V(var); } else { throw new System.ArgumentException("Unsupported "); } concat.Add(svar); } Net.Vpc.Upa.Record s = GetEntity().GetBuilder().CreateRecord(); s.SetObject(GetHierarchyPathField(), concat); Net.Vpc.Upa.Expressions.Expression p = null; Net.Vpc.Upa.Relationship rel = GetTreeRelationship(); object[] kvalue = GetEntity().GetBuilder().IdToKey(key).GetValue(); for (int i = 0; i < rel.Size(); i++) { Net.Vpc.Upa.Field field = lfs[i]; Net.Vpc.Upa.Expressions.Expression e = (new Net.Vpc.Upa.Expressions.Equals(new Net.Vpc.Upa.Expressions.Var(field.GetName()), new Net.Vpc.Upa.Expressions.Literal(kvalue[i], field.GetDataType()))); p = p == null ? ((Net.Vpc.Upa.Expressions.Expression)(e)) : new Net.Vpc.Upa.Expressions.And(p, e); } GetEntity().UpdateCore(s, p, executionContext); System.Collections.Generic.IList <object> children = GetEntity().CreateQueryBuilder().ByExpression(p).GetIdList <K>(); foreach (object aChildren in children) { ValidateChildren(aChildren, executionContext); } }
public virtual Net.Vpc.Upa.Expressions.Expression RecordToExpression(Net.Vpc.Upa.Record record, string alias) /* throws Net.Vpc.Upa.Exceptions.UPAException */ { if (record == null) { return(null); } Net.Vpc.Upa.Expressions.Expression a = null; foreach (System.Collections.Generic.KeyValuePair <string, object> entry in record.EntrySet()) { string key = (entry).Key; object @value = (entry).Value; Net.Vpc.Upa.Field field = GetEntity().GetField(key); if (!field.IsUnspecifiedValue(@value)) { Net.Vpc.Upa.Expressions.Expression e = null; Net.Vpc.Upa.Expressions.Var p = new Net.Vpc.Upa.Expressions.Var(Net.Vpc.Upa.Impl.Util.StringUtils.IsNullOrEmpty(alias) ? GetEntity().GetName() : alias); switch (field.GetSearchOperator()) { case Net.Vpc.Upa.SearchOperator.DEFAULT: case Net.Vpc.Upa.SearchOperator.EQ: { if (field.GetDataType() is Net.Vpc.Upa.Types.ManyToOneType) { Net.Vpc.Upa.Types.ManyToOneType et = (Net.Vpc.Upa.Types.ManyToOneType)field.GetDataType(); Net.Vpc.Upa.Key foreignKey = et.GetRelationship().GetTargetRole().GetEntity().GetBuilder().ObjectToKey(@value); Net.Vpc.Upa.Expressions.Expression b = null; int i = 0; foreach (Net.Vpc.Upa.Field df in et.GetRelationship().GetSourceRole().GetFields()) { e = new Net.Vpc.Upa.Expressions.Equals(new Net.Vpc.Upa.Expressions.Var((Net.Vpc.Upa.Expressions.Var)p.Copy(), df.GetName()), Net.Vpc.Upa.Expressions.ExpressionFactory.ToLiteral(foreignKey.GetObjectAt(i))); b = b == null ? ((Net.Vpc.Upa.Expressions.Expression)(b)) : new Net.Vpc.Upa.Expressions.And(b, e); i++; } } else { e = new Net.Vpc.Upa.Expressions.Equals(new Net.Vpc.Upa.Expressions.Var(p, key), Net.Vpc.Upa.Expressions.ExpressionFactory.ToLiteral(@value)); } break; } case Net.Vpc.Upa.SearchOperator.NE: { e = new Net.Vpc.Upa.Expressions.Different(new Net.Vpc.Upa.Expressions.Var(p, key), Net.Vpc.Upa.Expressions.ExpressionFactory.ToLiteral(@value)); break; } case Net.Vpc.Upa.SearchOperator.GT: { e = new Net.Vpc.Upa.Expressions.GreaterThan(new Net.Vpc.Upa.Expressions.Var(p, key), Net.Vpc.Upa.Expressions.ExpressionFactory.ToLiteral(@value)); break; } case Net.Vpc.Upa.SearchOperator.GTE: { e = new Net.Vpc.Upa.Expressions.GreaterEqualThan(new Net.Vpc.Upa.Expressions.Var(p, key), Net.Vpc.Upa.Expressions.ExpressionFactory.ToLiteral(@value)); break; } case Net.Vpc.Upa.SearchOperator.LT: { e = new Net.Vpc.Upa.Expressions.LessThan(new Net.Vpc.Upa.Expressions.Var(p, key), Net.Vpc.Upa.Expressions.ExpressionFactory.ToLiteral(@value)); break; } case Net.Vpc.Upa.SearchOperator.LTE: { e = new Net.Vpc.Upa.Expressions.LessEqualThan(new Net.Vpc.Upa.Expressions.Var(p, key), Net.Vpc.Upa.Expressions.ExpressionFactory.ToLiteral(@value)); break; } case Net.Vpc.Upa.SearchOperator.CONTAINS: { e = new Net.Vpc.Upa.Expressions.Like(new Net.Vpc.Upa.Expressions.Var(p, key), Net.Vpc.Upa.Expressions.ExpressionFactory.ToLiteral("%" + @value + "%")); break; } case Net.Vpc.Upa.SearchOperator.STARTS_WITH: { e = new Net.Vpc.Upa.Expressions.Like(new Net.Vpc.Upa.Expressions.Var(p, key), Net.Vpc.Upa.Expressions.ExpressionFactory.ToLiteral(@value + "%")); break; } case Net.Vpc.Upa.SearchOperator.ENDS_WITH: { e = new Net.Vpc.Upa.Expressions.Like(new Net.Vpc.Upa.Expressions.Var(p, key), Net.Vpc.Upa.Expressions.ExpressionFactory.ToLiteral("%" + @value)); break; } } if (e != null) { a = a == null ? ((Net.Vpc.Upa.Expressions.Expression)(e)) : new Net.Vpc.Upa.Expressions.And(a, e); } } } return(a); }
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 override bool Accept(Net.Vpc.Upa.Field f) /* throws Net.Vpc.Upa.Exceptions.UPAException */ { return(f.GetModifiers().Contains(Net.Vpc.Upa.FieldModifier.PERSIST) && !f.GetModifiers().Contains(Net.Vpc.Upa.FieldModifier.ID) && !f.GetDataType().IsNullable()); }
protected internal virtual object GenerateValue(Net.Vpc.Upa.Field field) { try { Net.Vpc.Upa.Types.StringType dataType = (Net.Vpc.Upa.Types.StringType)field.GetDataType(); string goodChars = null; foreach (Net.Vpc.Upa.Types.TypeValueValidator valueValidator in dataType.GetValueValidators()) { if (valueValidator is Net.Vpc.Upa.Types.StringTypeCharValidator) { Net.Vpc.Upa.Types.StringTypeCharValidator s = (Net.Vpc.Upa.Types.StringTypeCharValidator)valueValidator; if (s.IsPositive()) { goodChars = s.GetChars(); break; } } } if (goodChars == null) { goodChars = Net.Vpc.Upa.Impl.Util.IdentifierUtils.ALPHA_NUM_CHARS; } //prefer alphabetic at start //prefer alphanumeric at end //prefer no successive ponctuation // if too match difiicult (>100) do any thing System.Text.StringBuilder alpha = new System.Text.StringBuilder(); System.Text.StringBuilder num = new System.Text.StringBuilder(); System.Text.StringBuilder ponct = new System.Text.StringBuilder(); for (int i = 0; i < (goodChars).Length; i++) { char c = goodChars[i]; if (char.IsLetter(c)) { alpha.Append(c); } else if (char.IsDigit(c)) { num.Append(c); } else { ponct.Append(c); } } for (int i = 0; i < 100; i++) { string k = Net.Vpc.Upa.Impl.Util.IdentifierUtils.GenerateID(dataType.GetMin(), dataType.GetMax(), alpha.ToString(), goodChars, alpha.ToString() + num.ToString()); bool ok = true; for (int j = 1; j < (k).Length - 2; j++) { if (ponct.ToString().IndexOf(k[j]) >= 0 && ponct.ToString().IndexOf(k[j + 1]) >= 0) { ok = false; break; } } if (ok) { return(k); } } return(Net.Vpc.Upa.Impl.Util.IdentifierUtils.GenerateID(dataType.GetMin(), dataType.GetMax(), goodChars, goodChars, goodChars)); } catch (Net.Vpc.Upa.Types.ConstraintsException e) { return(null); } }
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 ComposedToFlatFieldPersister(Net.Vpc.Upa.Field field) { this.field = field; Net.Vpc.Upa.Types.ManyToOneType t = (Net.Vpc.Upa.Types.ManyToOneType)field.GetDataType(); Net.Vpc.Upa.Entity master = t.GetRelationship().GetTargetRole().GetEntity(); Net.Vpc.Upa.RelationshipRole detailRole = t.GetRelationship().GetSourceRole(); flatFields = detailRole.GetFields(); relationshipTargetConverter = master.GetBuilder(); }
public virtual Net.Vpc.Upa.Impl.Util.EntityBeanAttribute GetAttrAdapter(string field) { Net.Vpc.Upa.Impl.Util.EntityBeanAttribute r = Net.Vpc.Upa.Impl.FwkConvertUtils.GetMapValue <string, Net.Vpc.Upa.Impl.Util.EntityBeanAttribute>(fields, field); if (r != null) { return(r); } Net.Vpc.Upa.Field f = entity.GetField(field); Net.Vpc.Upa.PropertyAccessType propertyAccessType = f.GetPropertyAccessType(); if (propertyAccessType == default(Net.Vpc.Upa.PropertyAccessType)) { propertyAccessType = Net.Vpc.Upa.PropertyAccessType.PROPERTY; } if (propertyAccessType == Net.Vpc.Upa.PropertyAccessType.FIELD) { System.Reflection.FieldInfo ff = Net.Vpc.Upa.Impl.Util.PlatformUtils.FindField(entity.GetEntityType(), f.GetName(), Net.Vpc.Upa.Impl.Util.BeanFieldFilter.INSTANCE); if (ff != null) { r = new Net.Vpc.Upa.Impl.Util.EntityBeanFieldAttribute(this, ff, entity.GetEntityType()); fields[field] = r; } } else { Net.Vpc.Upa.Impl.Util.EntityBeanGetterSetterAttribute a = new Net.Vpc.Upa.Impl.Util.EntityBeanGetterSetterAttribute(this, field, f.GetDataType().GetPlatformType(), entity.GetEntityType()); if (a.IsValid()) { r = a; fields[field] = r; } } return(r); }
public virtual void CommitModelChanged() /* throws Net.Vpc.Upa.Exceptions.UPAException */ { Net.Vpc.Upa.Entity sourceEntity = GetSourceRole().GetEntity(); Net.Vpc.Upa.Entity targetEntity = GetTargetRole().GetEntity(); if (sourceEntity == null || targetEntity == null) { throw new Net.Vpc.Upa.Exceptions.UPAException("InvalidRelationDefinition"); } if (!sourceEntity.GetUserExcludeModifiers().Contains(Net.Vpc.Upa.EntityModifier.VALIDATE_PERSIST)) { sourceEntity.GetModifiers().Add(Net.Vpc.Upa.EntityModifier.VALIDATE_PERSIST); } if (!sourceEntity.GetUserExcludeModifiers().Contains(Net.Vpc.Upa.EntityModifier.VALIDATE_UPDATE)) { sourceEntity.GetModifiers().Add(Net.Vpc.Upa.EntityModifier.VALIDATE_UPDATE); } System.Collections.Generic.IList <Net.Vpc.Upa.Field> sourceFieldsList = sourceRole.GetFields(); Net.Vpc.Upa.Field[] sourceFields = sourceFieldsList.ToArray(); Net.Vpc.Upa.KeyType keyType = new Net.Vpc.Upa.KeyType(targetEntity, filter, false); SetDataType(keyType); tuningMaxInline = GetPersistenceUnit().GetProperties().GetInt((typeof(Net.Vpc.Upa.Relationship)).FullName + ".maxInline", 10); System.Collections.Generic.IList <Net.Vpc.Upa.Field> targetFieldsList = targetEntity.GetPrimaryFields(); Net.Vpc.Upa.Field[] targetFields = targetFieldsList.ToArray(); ; // some checks if (sourceFields.Length == 0) { throw new System.ArgumentException("No source fields are specified"); } if (targetFields.Length == 0) { throw new System.ArgumentException("Target Entity " + targetEntity.GetName() + " has no primary fields"); } if (sourceFields.Length != targetFields.Length) { throw new System.ArgumentException("source fields and target fields have not the same count"); } sourceEntity.AddDependencyOnEntity(targetEntity.GetName()); if (dataType == null) { dataType = targetEntity.GetDataType(); } if (dataType.IsNullable() != nullable) { Net.Vpc.Upa.Types.DataType trCloned = (Net.Vpc.Upa.Types.DataType)dataType.Copy(); trCloned.SetNullable(nullable); dataType = trCloned; } this.sourceToTargetKeyMap = new System.Collections.Generic.Dictionary <string, string>(sourceFields.Length); this.targetToSourceKeyMap = new System.Collections.Generic.Dictionary <string, string>(sourceFields.Length); // if ((theSourceTable instanceof View)) // this.type = 0; for (int i = 0; i < sourceFields.Length; i++) { if (sourceFields[i].GetModifiers().Contains(Net.Vpc.Upa.FieldModifier.TRANSIENT) && this.relationType != Net.Vpc.Upa.RelationshipType.TRANSIENT) { //Log. System.err.println("Type should be VIEW for " + getName()); this.relationType = Net.Vpc.Upa.RelationshipType.TRANSIENT; } else if (sourceFields[i].GetUpdateFormula() != null && this.relationType != Net.Vpc.Upa.RelationshipType.TRANSIENT && this.relationType != Net.Vpc.Upa.RelationshipType.SHADOW_ASSOCIATION) { // Log. System.err.println("Type should be either VIEW or SHADOW for " + name); this.relationType = Net.Vpc.Upa.RelationshipType.SHADOW_ASSOCIATION; } this.sourceToTargetKeyMap[sourceFields[i].GetName()] = targetFields[i].GetName(); this.targetToSourceKeyMap[targetFields[i].GetName()] = sourceFields[i].GetName(); // targetFields[i].addManyToOneRelation(this); ((Net.Vpc.Upa.Impl.AbstractField)sourceFields[i]).SetEffectiveModifiers(sourceFields[i].GetModifiers().Add(Net.Vpc.Upa.FieldModifier.FOREIGN)); ((Net.Vpc.Upa.Impl.AbstractField)targetFields[i]).SetEffectiveModifiers(targetFields[i].GetModifiers().Add(Net.Vpc.Upa.FieldModifier.REFERENCED)); // if (sourceFields[i].getTitle() == null) { // sourceFields[i].setTitle(targetFields[i].getTitle()); // } if (sourceFields[i].GetDataType() == null) { Net.Vpc.Upa.Types.DataType tr = targetFields[i].GetDataType(); if (tr.IsNullable() == nullable) { sourceFields[i].SetDataType(tr); } else { Net.Vpc.Upa.Types.DataType trCloned = (Net.Vpc.Upa.Types.DataType)tr.Copy(); trCloned.SetNullable(nullable); sourceFields[i].SetDataType(trCloned); } } } if (GetSourceRole().GetEntityField() != null) { Net.Vpc.Upa.Field sourceEntityField = GetSourceRole().GetEntityField(); Net.Vpc.Upa.Types.DataType dt = sourceEntityField.GetDataType(); if (dt is Net.Vpc.Upa.Types.ManyToOneType) { Net.Vpc.Upa.Types.ManyToOneType edt = (Net.Vpc.Upa.Types.ManyToOneType)dt; edt.SetRelationship(this); } } if (GetTargetRole().GetEntityField() != null) { Net.Vpc.Upa.Field targetEntityField = GetTargetRole().GetEntityField(); Net.Vpc.Upa.Types.DataType dt = targetEntityField.GetDataType(); if (dt is Net.Vpc.Upa.Types.ManyToOneType) { Net.Vpc.Upa.Types.ManyToOneType edt = (Net.Vpc.Upa.Types.ManyToOneType)dt; edt.SetRelationship(this); } } this.sourceToTargetKeyMap = Net.Vpc.Upa.Impl.Util.PlatformUtils.UnmodifiableMap <string, string>(sourceToTargetKeyMap); this.targetToSourceKeyMap = Net.Vpc.Upa.Impl.Util.PlatformUtils.UnmodifiableMap <string, string>(targetToSourceKeyMap); SetI18NString(new Net.Vpc.Upa.Types.I18NString("Relationship").Append(GetName())); SetTitle(GetI18NString().Append(".title")); SetDescription(GetI18NString().Append(".desc")); System.Text.StringBuilder preferredPersistenceName = new System.Text.StringBuilder((GetName()).Length); for (int i = 0; i < (GetName()).Length; i++) { if (Net.Vpc.Upa.Expressions.ExpressionHelper.IsIdentifierPart(GetName()[i])) { preferredPersistenceName.Append(GetName()[i]); } else { preferredPersistenceName.Append('_'); } } SetPersistenceName(preferredPersistenceName.ToString()); if (GetRelationshipType() == Net.Vpc.Upa.RelationshipType.COMPOSITION) { ((Net.Vpc.Upa.Impl.DefaultEntity)sourceEntity).SetCompositionRelationship(this); } targetRole.SetFields(targetFields); Net.Vpc.Upa.Impl.Util.UPAUtils.Prepare(GetPersistenceUnit(), targetRole, this.GetName() + "_" + targetRole.GetRelationshipRoleType()); Net.Vpc.Upa.Impl.Util.UPAUtils.Prepare(GetPersistenceUnit(), sourceRole, this.GetName() + "_" + sourceRole.GetRelationshipRoleType()); if ((((GetTargetRole().GetEntity().GetExtensionDefinitions <Net.Vpc.Upa.Extensions.ViewEntityExtensionDefinition>(typeof(Net.Vpc.Upa.Extensions.ViewEntityExtensionDefinition))).Count > 0) || ((GetSourceRole().GetEntity().GetExtensionDefinitions <Net.Vpc.Upa.Extensions.ViewEntityExtensionDefinition>(typeof(Net.Vpc.Upa.Extensions.ViewEntityExtensionDefinition))).Count > 0)) && relationType != Net.Vpc.Upa.RelationshipType.TRANSIENT) { throw new System.ArgumentException(this + " : Relationship Type must be TYPE_VIEW"); } if (((GetTargetRole().GetEntity().GetShield().IsTransient()) || (GetSourceRole().GetEntity().GetShield().IsTransient())) && relationType != Net.Vpc.Upa.RelationshipType.TRANSIENT) { throw new System.ArgumentException(this + " : Relationship Type must be TYPE_VIEW"); } Net.Vpc.Upa.FlagSet <Net.Vpc.Upa.FieldModifier> modifierstoRemove = Net.Vpc.Upa.FlagSets.OfType <Net.Vpc.Upa.FieldModifier>().AddAll(Net.Vpc.Upa.FieldModifier.PERSIST, Net.Vpc.Upa.FieldModifier.PERSIST_DEFAULT, Net.Vpc.Upa.FieldModifier.PERSIST_FORMULA, Net.Vpc.Upa.FieldModifier.PERSIST_SEQUENCE, Net.Vpc.Upa.FieldModifier.UPDATE, Net.Vpc.Upa.FieldModifier.UPDATE_DEFAULT, Net.Vpc.Upa.FieldModifier.UPDATE_FORMULA, Net.Vpc.Upa.FieldModifier.UPDATE_SEQUENCE); switch (GetSourceRole().GetRelationshipUpdateType()) { case Net.Vpc.Upa.RelationshipUpdateType.FLAT: { Net.Vpc.Upa.Field f = GetSourceRole().GetEntityField(); if (f != null) { ((Net.Vpc.Upa.Impl.AbstractField)f).SetEffectiveModifiers(f.GetModifiers().RemoveAll(modifierstoRemove)); } break; } case Net.Vpc.Upa.RelationshipUpdateType.COMPOSED: { System.Collections.Generic.IList <Net.Vpc.Upa.Field> fields = GetSourceRole().GetFields(); if (fields != null) { foreach (Net.Vpc.Upa.Field f in fields) { ((Net.Vpc.Upa.Impl.AbstractField)f).SetEffectiveModifiers(f.GetModifiers().RemoveAll(modifierstoRemove)); } } break; } } }
public virtual int Update(Net.Vpc.Upa.Entity entity, Net.Vpc.Upa.Persistence.EntityExecutionContext context, Net.Vpc.Upa.Record updates, Net.Vpc.Upa.Expressions.Expression condition) /* throws Net.Vpc.Upa.Exceptions.UPAException */ { Net.Vpc.Upa.Expressions.Update u = new Net.Vpc.Upa.Expressions.Update().Entity(entity.GetName()); foreach (string fieldName in updates.KeySet()) { Net.Vpc.Upa.Field f = entity.FindField(fieldName); if (f != null && Net.Vpc.Upa.Impl.Util.Filters.Fields2.UPDATE.Accept(f)) { object @value = updates.GetObject <T>(fieldName); if ((f.GetDataType() is Net.Vpc.Upa.Types.ManyToOneType)) { Net.Vpc.Upa.Types.ManyToOneType e = (Net.Vpc.Upa.Types.ManyToOneType)f.GetDataType(); if (e.IsUpdatable()) { Net.Vpc.Upa.Entity masterEntity = context.GetPersistenceUnit().GetEntity(e.GetTargetEntityName()); Net.Vpc.Upa.EntityBuilder mbuilder = masterEntity.GetBuilder(); if (@value is Net.Vpc.Upa.Expressions.Expression) { Net.Vpc.Upa.Expressions.Expression evalue; System.Collections.Generic.IList <Net.Vpc.Upa.Field> sfields = e.GetRelationship().GetSourceRole().GetFields(); System.Collections.Generic.IList <Net.Vpc.Upa.Field> tfields = e.GetRelationship().GetTargetRole().GetFields(); for (int i = 0; i < (sfields).Count; i++) { Net.Vpc.Upa.Field fk = sfields[i]; Net.Vpc.Upa.Field fid = tfields[i]; evalue = ((Net.Vpc.Upa.Expressions.Expression)@value).Copy(); evalue = context.GetPersistenceUnit().GetExpressionManager().ParseExpression(evalue); if (evalue is Net.Vpc.Upa.Expressions.Select) { Net.Vpc.Upa.Expressions.Select svalue = (Net.Vpc.Upa.Expressions.Select)evalue; if (svalue.CountFields() != 1) { throw new System.Exception("Invalid Expression " + svalue + " as formula for field " + f.GetAbsoluteName()); } if (svalue.GetField(0).GetExpression() is Net.Vpc.Upa.Expressions.Var) { svalue.GetField(0).SetExpression(new Net.Vpc.Upa.Expressions.Var((Net.Vpc.Upa.Expressions.Var)svalue.GetField(0).GetExpression(), fid.GetName())); } else { throw new System.Exception("Invalid Expression " + svalue + " as formula for field " + f.GetAbsoluteName()); } } else if (evalue is Net.Vpc.Upa.Expressions.Var) { evalue = (new Net.Vpc.Upa.Expressions.Var((Net.Vpc.Upa.Expressions.Var)evalue, fk.GetName())); } else if (evalue is Net.Vpc.Upa.Expressions.Param) { } else if (evalue is Net.Vpc.Upa.Expressions.Literal) { } else { throw new System.Exception("Invalid Expression " + evalue + " as formula for field " + f.GetAbsoluteName()); } u.Set(fk.GetName(), evalue); } } else { Net.Vpc.Upa.Key k = null; if (@value is Net.Vpc.Upa.Record) { k = mbuilder.RecordToKey((Net.Vpc.Upa.Record)@value); } else { k = mbuilder.ObjectToKey(@value); } int x = 0; foreach (Net.Vpc.Upa.Field fk in e.GetRelationship().GetSourceRole().GetFields()) { u.Set(fk.GetName(), new Net.Vpc.Upa.Expressions.Param(fk.GetName(), k == null ? null : k.GetObjectAt(x))); x++; } } } } else { Net.Vpc.Upa.Expressions.Expression expression = (@value is Net.Vpc.Upa.Expressions.Expression) ? ((Net.Vpc.Upa.Expressions.Expression)((Net.Vpc.Upa.Expressions.Expression)@value)) : new Net.Vpc.Upa.Expressions.Param(null, @value); u.Set(fieldName, expression); } } } u.Where(condition); return(context.GetPersistenceStore().CreateQuery(u, context).ExecuteNonQuery()); }
public override bool Accept(Net.Vpc.Upa.Field f) { return(type.IsAssignableFrom(f.GetDataType().GetType())); }
public override bool Accept(Net.Vpc.Upa.Field f) /* throws Net.Vpc.Upa.Exceptions.UPAException */ { return(type.IsAssignableFrom(f.GetDataType().GetType())); }