public virtual Net.Vpc.Upa.Record ObjectToRecord(object @object, System.Collections.Generic.ISet <string> fields, bool ignoreUnspecified, bool ensureIncludeIds) { Net.Vpc.Upa.Record r = CreateRecord(); Net.Vpc.Upa.Record allFieldsRecord = ObjectToRecord(@object, ignoreUnspecified); if (fields == null || (fields.Count == 0)) { r.SetAll(r); return(r); } else { foreach (string k in fields) { r.SetObject(k, allFieldsRecord.GetObject <T>(k)); } if (ensureIncludeIds) { foreach (Net.Vpc.Upa.Field o in GetEntity().GetPrimaryFields()) { string idname = o.GetName(); if (!r.IsSet(idname)) { r.SetObject(idname, allFieldsRecord.GetObject <T>(idname)); } } } return(r); } }
public virtual Net.Vpc.Upa.Record KeyToRecord(Net.Vpc.Upa.Key key) /* throws Net.Vpc.Upa.Exceptions.UPAException */ { if (key == null) { return(null); } Net.Vpc.Upa.Record ur = CreateRecord(); System.Collections.Generic.IList <Net.Vpc.Upa.Field> primaryFields = GetEntity().GetPrimaryFields(); if (key == null) { foreach (Net.Vpc.Upa.Field aF in primaryFields) { ur.SetObject(aF.GetName(), null); } } else { object[] uk = key.GetValue(); for (int i = 0; i < (primaryFields).Count; i++) { ur.SetObject(primaryFields[i].GetName(), uk[i]); } } return(ur); }
public virtual R IdToObject <R>(object id) /* throws Net.Vpc.Upa.Exceptions.UPAException */ { if (id == null) { return(default(R)); } Net.Vpc.Upa.Entity entity = GetEntity(); R r = CreateObject <R>(); Net.Vpc.Upa.Record ur = ObjectToRecord(r, true); System.Collections.Generic.IList <Net.Vpc.Upa.Field> primaryFields = entity.GetPrimaryFields(); if (id == null) { foreach (Net.Vpc.Upa.Field aF in primaryFields) { ur.SetObject(aF.GetName(), null); } } else { object[] uk = entity.GetBuilder().GetKey(id).GetValue(); for (int i = 0; i < (primaryFields).Count; i++) { ur.SetObject(primaryFields[i].GetName(), uk[i]); } } return(r); }
public override R RecordToObject <R>(Net.Vpc.Upa.Record record) { if (record is Net.Vpc.Upa.Impl.BeanAdapterRecord) { Net.Vpc.Upa.Impl.BeanAdapterRecord g = (Net.Vpc.Upa.Impl.BeanAdapterRecord)record; return((R)g.UserObject()); } object obj = CreateObject <R>(); Net.Vpc.Upa.Record ur = ObjectToRecord(obj, true); foreach (string k in record.KeySet()) { object o = record.GetObject <T>(k); if (o is Net.Vpc.Upa.Record) { Net.Vpc.Upa.Field f = entity.FindField(k); Net.Vpc.Upa.Types.DataType dt = f.GetDataType(); if (dt is Net.Vpc.Upa.Types.ManyToOneType) { Net.Vpc.Upa.Entity oe = ((Net.Vpc.Upa.Types.ManyToOneType)dt).GetRelationship().GetTargetEntity(); o = oe.GetBuilder().RecordToObject <R>((Net.Vpc.Upa.Record)o); } } ur.SetObject(k, o); } // ur.setAll(unstructuredRecord); return((R)obj); }
public virtual void PrepareFieldForPersist(Net.Vpc.Upa.Field field, object @value, Net.Vpc.Upa.Record userRecord, Net.Vpc.Upa.Record persistentRecord, Net.Vpc.Upa.Persistence.EntityExecutionContext executionContext, System.Collections.Generic.ISet <Net.Vpc.Upa.Field> persistNonNullable, System.Collections.Generic.ISet <Net.Vpc.Upa.Field> persistWithDefaultValue) /* throws Net.Vpc.Upa.Exceptions.UPAException */ { Net.Vpc.Upa.Types.ManyToOneType e = (Net.Vpc.Upa.Types.ManyToOneType)field.GetDataType(); if (e.IsUpdatable()) { Net.Vpc.Upa.Entity masterEntity = executionContext.GetPersistenceUnit().GetEntity(e.GetTargetEntityName()); Net.Vpc.Upa.Key k = null; if (@value is Net.Vpc.Upa.Record) { k = masterEntity.GetBuilder().RecordToKey((Net.Vpc.Upa.Record)@value); } else { k = masterEntity.GetBuilder().ObjectToKey(@value); } int x = 0; foreach (Net.Vpc.Upa.Field fk in e.GetRelationship().GetSourceRole().GetFields()) { persistNonNullable.Remove(fk); persistWithDefaultValue.Remove(fk); persistentRecord.SetObject(fk.GetName(), k == null ? null : k.GetObjectAt(x)); x++; } } }
public virtual void AfterPersist(Net.Vpc.Upa.Record record, Net.Vpc.Upa.Persistence.EntityExecutionContext context) { if (new System.Nullable <bool>(false).Equals(context.GetConnection().GetProperty(identityConstraintsEnabledProperty))) { return; } record.SetObject(field.GetName(), context.GetGeneratedValue(field.GetName()).GetValue()); }
public virtual void Inject(object instance, string property, object @value) { Net.Vpc.Upa.Record r = (Net.Vpc.Upa.Record)instance; if (entity.Contains(property)) { r.SetObject(property, @value); } }
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 void BeforePersist(Net.Vpc.Upa.Record record, Net.Vpc.Upa.Persistence.EntityExecutionContext context) /* throws Net.Vpc.Upa.Exceptions.UPAException */ { object o = record.GetObject <T>(field.GetName()); Net.Vpc.Upa.Key key = relationshipTargetConverter.ObjectToKey(o); if (key == null) { foreach (Net.Vpc.Upa.Field ff in flatFields) { record.SetObject(ff.GetName(), ff.GetUnspecifiedValueDecoded()); } } else { int i = 0; foreach (Net.Vpc.Upa.Field ff in flatFields) { record.SetObject(ff.GetName(), key.GetObjectAt(i)); i++; } } }
public virtual R CreateInitializedObject <R>() { object o = CreateObject <R>(); Net.Vpc.Upa.Record r = ObjectToRecord(o, false); foreach (Net.Vpc.Upa.Field field in entity.GetFields()) { object df = field.GetDefaultValue(); if (field.IsId() && (field.GetModifiers().Contains(Net.Vpc.Upa.FieldModifier.PERSIST_FORMULA) || field.GetModifiers().Contains(Net.Vpc.Upa.FieldModifier.PERSIST_SEQUENCE))) { } else if (df != null) { r.SetObject(field.GetName(), df); } } return(RecordToObject <R>(r)); }
public virtual void PrepareFieldForPersist(Net.Vpc.Upa.Field field, object @value, Net.Vpc.Upa.Record userRecord, Net.Vpc.Upa.Record persistentRecord, Net.Vpc.Upa.Persistence.EntityExecutionContext executionContext, System.Collections.Generic.ISet <Net.Vpc.Upa.Field> insertNonNullable, System.Collections.Generic.ISet <Net.Vpc.Upa.Field> insertWithDefaultValue) /* throws Net.Vpc.Upa.Exceptions.UPAException */ { object userValue = null; bool userValueFound = false; if (!(@value is Net.Vpc.Upa.Expressions.Expression)) { userValueFound = true; userValue = @value; } else if (@value is Net.Vpc.Upa.Expressions.Param) { object o = ((Net.Vpc.Upa.Expressions.Param)@value).GetValue(); // if (o instanceof String) { userValue = o; userValueFound = true; } else if (@value is Net.Vpc.Upa.Expressions.Literal) { object o = ((Net.Vpc.Upa.Expressions.Literal)@value).GetValue(); // if (o instanceof String) { userValue = o; userValueFound = true; } // } if (userValueFound) { Net.Vpc.Upa.Types.DataTypeTransform typeTransform = Net.Vpc.Upa.Impl.Util.UPAUtils.GetTypeTransformOrIdentity(field); Net.Vpc.Upa.Impl.Transform.PasswordDataTypeTransform t = Net.Vpc.Upa.Impl.Util.UPAUtils.FindPasswordTransform(typeTransform); object v = ConvertCypherValue(t.GetCipherValue(), field.GetDataType()); if (Net.Vpc.Upa.Impl.Util.UPAUtils.Equals(userValue, v)) { return; } //ignore insert userRecord.SetObject(field.GetName(), v); } else { log.TraceEvent(System.Diagnostics.TraceEventType.Error, 100, Net.Vpc.Upa.Impl.FwkConvertUtils.LogMessageExceptionFormatter("Inserting non user value to password, hashing will be ignored", null)); } Net.Vpc.Upa.Expressions.Expression valueExpression = (@value is Net.Vpc.Upa.Expressions.Expression) ? ((Net.Vpc.Upa.Expressions.Expression)((Net.Vpc.Upa.Expressions.Expression)@value)) : new Net.Vpc.Upa.Expressions.Param(field.GetName(), @value); persistentRecord.SetObject(field.GetName(), valueExpression); }
protected internal virtual int ValidateDefault(System.Collections.Generic.ICollection <Net.Vpc.Upa.Field> fields, Net.Vpc.Upa.Expressions.Expression expression) /* throws Net.Vpc.Upa.Exceptions.UPAException */ { // System.out.println("DEFAULT_VALIDATION = " + // validationPass.pass+" : "+ validationPass.fields); Net.Vpc.Upa.Record u = entity.GetBuilder().CreateRecord(); foreach (Net.Vpc.Upa.Field field in fields) { Net.Vpc.Upa.Expressions.Expression fieldExpression = GetFieldExpression(field, onPersist); Net.Vpc.Upa.Expressions.Expression validExpression = fieldExpression; if (forceExpressionTypeCasting || (fieldExpression is Net.Vpc.Upa.Expressions.Literal && ((Net.Vpc.Upa.Expressions.Literal)fieldExpression).GetValue() == null)) { validExpression = new Net.Vpc.Upa.Expressions.Cast(fieldExpression, field.GetDataType()); } u.SetObject(field.GetName(), validExpression); } try { return(entity.UpdateCore(u, expression, context)); } catch (Net.Vpc.Upa.Exceptions.UPAException ex) { // Log.bug(ex); // Select sb0 = new Select(); // for (Field f : fields) { // Expression fieldExpression = getFieldExpression(f, onPersist); // sb0.field(fieldExpression, f.getName() + "Expression"); // Expression validExpression = fieldExpression; // if (forceExpressionTypeCasting || (fieldExpression instanceof Literal && ((Literal) fieldExpression).getValue() == null)) { // validExpression = new Cast(fieldExpression, f.getDataType()); // } // sb0.field(validExpression, f.getName() + "CastExpression"); // } // sb0.from(entity.getName()); // sb0.setWhere(expression); // //// Log.bug("Values to update are : "); // for (Record ur : entity.createQuery(sb0).getRecordList()) { // for (Map.Entry<String, Object> entry : ur.toMap().entrySet()) { // //Log.bug(entry.getKey() + " : " + entry.getValue()); // } // } throw ex; } }
public virtual Net.Vpc.Upa.Record IdToRecord(object id) /* throws Net.Vpc.Upa.Exceptions.UPAException */ { if (id == null) { return(null); } Net.Vpc.Upa.Entity entity = GetEntity(); Net.Vpc.Upa.Record ur = CreateRecord(); System.Collections.Generic.IList <Net.Vpc.Upa.Field> primaryFields = entity.GetPrimaryFields(); // if (k == null) { // for (Field aF : primaryFields) { // ur.setObject(aF.getName(), null); // } // } else { object[] uk = entity.GetBuilder().GetKey(id).GetValue(); for (int i = 0; i < (primaryFields).Count; i++) { ur.SetObject(primaryFields[i].GetName(), uk[i]); } // } return(ur); }
public virtual void SetRecordId(Net.Vpc.Upa.Record record, object id) /* throws Net.Vpc.Upa.Exceptions.UPAException */ { System.Collections.Generic.IList <Net.Vpc.Upa.Field> f = GetEntity().GetPrimaryFields(); if (id == null) { foreach (Net.Vpc.Upa.Field aF in f) { record.Remove(aF.GetName()); } return; } object[] uk = IdToKey(id).GetValue(); if ((f).Count > 0) { if (uk.Length != (f).Count) { throw new System.Exception("key " + id + " could not denote for entity " + GetEntity().GetName() + " ; got " + uk.Length + " elements instread of " + (f).Count); } for (int i = 0; i < (f).Count; i++) { record.SetObject(f[i].GetName(), uk[i]); } } }
protected internal virtual int ValidateCustomFormula(System.Collections.Generic.ISet <Net.Vpc.Upa.Field> fields) /* throws Net.Vpc.Upa.Exceptions.UPAException */ { // if (monitor != null) { // if (monitor.isStopped()) { // return; // } // monitor.stepIn(keysToUpdate.size()); // } int x = 0; foreach (object aKeysToUpdate in GetKeysToUpdate()) { // if (monitor != null) { // if (monitor.isStopped()) { // return; // } // monitor.progress(String.valueOf(validationPass.pass), "Passe " // + (validationPass.pass + 1), null); // } // System.out.println("ITERATIVE_VALIDATION = " + // validationPass.pass+" : "+validationPass.fields+" : // "+keysToUpdate[r]); Net.Vpc.Upa.Record u = entity.GetBuilder().CreateRecord(); foreach (Net.Vpc.Upa.Field field in fields) { Net.Vpc.Upa.CustomFormula cf = (Net.Vpc.Upa.CustomFormula)(onPersist ? field.GetPersistFormula() : field.GetUpdateFormula()); object v = cf.GetValue(field, aKeysToUpdate, context); u.SetObject(field.GetName(), new Net.Vpc.Upa.Expressions.Cast(new Net.Vpc.Upa.Expressions.Param(null, v), field.GetDataType())); } x += entity.UpdateCore(u, entity.GetBuilder().IdToExpression(aKeysToUpdate, entity.GetName()), context); } // if (monitor != null) { // monitor.stepOut(); // } return(x); }
public virtual bool SetProperty(object o, string property, object @value) { Net.Vpc.Upa.Record r = (Net.Vpc.Upa.Record)o; r.SetObject(property, o); return(true); }
public virtual void BeforePersist(Net.Vpc.Upa.Record record, Net.Vpc.Upa.Persistence.EntityExecutionContext context) /* throws Net.Vpc.Upa.Exceptions.UPAException */ { record.SetObject(field, expression); }
public virtual void PrepareFieldForUpdate(Net.Vpc.Upa.Field field, object @value, Net.Vpc.Upa.Record userRecord, Net.Vpc.Upa.Record persistentRecord, Net.Vpc.Upa.Persistence.EntityExecutionContext executionContext) /* throws Net.Vpc.Upa.Exceptions.UPAException */ { persistentRecord.SetObject(field.GetName(), @value); }
public virtual void BeforePersist(Net.Vpc.Upa.Record record, Net.Vpc.Upa.Persistence.EntityExecutionContext context) /* throws Net.Vpc.Upa.Exceptions.UPAException */ { record.Remove(field.GetName()); record.SetObject(field.GetName(), GetNewValue(field, record, context)); }
public virtual void PrepareFieldForPersist(Net.Vpc.Upa.Field field, object @value, Net.Vpc.Upa.Record userRecord, Net.Vpc.Upa.Record persistentRecord, Net.Vpc.Upa.Persistence.EntityExecutionContext executionContext, System.Collections.Generic.ISet <Net.Vpc.Upa.Field> persistNonNullable, System.Collections.Generic.ISet <Net.Vpc.Upa.Field> persistWithDefaultValue) /* throws Net.Vpc.Upa.Exceptions.UPAException */ { Net.Vpc.Upa.Expressions.Expression valueExpression = (@value is Net.Vpc.Upa.Expressions.Expression) ? ((Net.Vpc.Upa.Expressions.Expression)((Net.Vpc.Upa.Expressions.Expression)@value)) : new Net.Vpc.Upa.Expressions.Param(field.GetName(), @value); persistentRecord.SetObject(field.GetName(), valueExpression); }