Ejemplo n.º 1
0
 public EntityBeanFactory(Net.Vpc.Upa.Entity entity, Net.Vpc.Upa.ObjectFactory objectFactory)
 {
     this.entity        = entity;
     this.nfo           = entity.GetBeanType();
     this.objectFactory = objectFactory;
     System.Collections.Generic.IList <Net.Vpc.Upa.Field> fields = entity.GetFields();
 }
Ejemplo n.º 2
0
 public virtual void Update()
 {
     System.Collections.Generic.ISet <string> visited = new System.Collections.Generic.HashSet <string>();
     persistSequenceGeneratorFields.Clear();
     updateSequenceGeneratorFields.Clear();
     insertExpressions.Clear();
     updateExpressions.Clear();
     System.Collections.Generic.IList <Net.Vpc.Upa.Field> fields1 = entity.GetFields();
     foreach (Net.Vpc.Upa.Field field in fields1)
     {
         visited.Remove(field.GetName());
         Net.Vpc.Upa.Impl.Persistence.FieldPersistenceInfo fieldPersistenceInfo = Net.Vpc.Upa.Impl.FwkConvertUtils.GetMapValue <string, Net.Vpc.Upa.Impl.Persistence.FieldPersistenceInfo>(fields, field.GetName());
         if (fieldPersistenceInfo == null)
         {
             fieldPersistenceInfo    = new Net.Vpc.Upa.Impl.Persistence.FieldPersistenceInfo();
             fields[field.GetName()] = fieldPersistenceInfo;
         }
         fieldPersistenceInfo.field            = field;
         fieldPersistenceInfo.persistenceStore = persistenceStore;
         fieldPersistenceInfo.Synchronize();
         if (fieldPersistenceInfo.persistFieldPersister != null)
         {
             persistSequenceGeneratorFields.Add(fieldPersistenceInfo);
         }
         if (fieldPersistenceInfo.updateFieldPersister != null)
         {
             updateSequenceGeneratorFields.Add(fieldPersistenceInfo);
         }
         if (fieldPersistenceInfo.insertExpression != null)
         {
             insertExpressions.Add(fieldPersistenceInfo);
         }
         if (fieldPersistenceInfo.updateExpression != null)
         {
             updateExpressions.Add(fieldPersistenceInfo);
         }
         if (field.GetDataType() is Net.Vpc.Upa.Types.ManyToOneType)
         {
             ((Net.Vpc.Upa.Impl.AbstractField)field).SetFieldPersister(new Net.Vpc.Upa.Impl.EntityTypeFieldPersister());
         }
         else if (Net.Vpc.Upa.Impl.Util.UPAUtils.IsPasswordTransform(Net.Vpc.Upa.Impl.Util.UPAUtils.GetTypeTransformOrIdentity(field)))
         {
             ((Net.Vpc.Upa.Impl.AbstractField)field).SetFieldPersister(new Net.Vpc.Upa.Impl.Transform.PasswordTypeFieldPersister());
         }
         else
         {
             ((Net.Vpc.Upa.Impl.AbstractField)field).SetFieldPersister(new Net.Vpc.Upa.Impl.SimpleFieldPersister());
         }
     }
     foreach (string r in visited)
     {
         fields.Remove(r);
     }
 }
Ejemplo n.º 3
0
 public virtual System.Collections.Generic.ISet <string> GetPropertyNames()
 {
     if (propertyNames == null)
     {
         System.Collections.Generic.HashSet <string> t = new System.Collections.Generic.HashSet <string>();
         foreach (Net.Vpc.Upa.Field f in entity.GetFields())
         {
             t.Add(f.GetName());
         }
         propertyNames = t;
     }
     return(new System.Collections.Generic.HashSet <string>(propertyNames));
 }
Ejemplo n.º 4
0
        public virtual Net.Vpc.Upa.Record CreateInitializedRecord()
        {
            object o = CreateObject <R>();

            Net.Vpc.Upa.Record r = CreateRecord();
            r.SetAll(ObjectToRecord(o, false));
            foreach (Net.Vpc.Upa.Field field in entity.GetFields())
            {
                if (field.IsId() && (field.GetModifiers().Contains(Net.Vpc.Upa.FieldModifier.PERSIST_FORMULA) || field.GetModifiers().Contains(Net.Vpc.Upa.FieldModifier.PERSIST_SEQUENCE)))
                {
                    r.Remove(field.GetName());
                }
                else
                {
                    object df = field.GetDefaultValue();
                    if (df != null)
                    {
                        r.SetObject(field.GetName(), df);
                    }
                }
            }
            return(r);
        }
Ejemplo n.º 5
0
 public EntityBeanType(Net.Vpc.Upa.Entity entity)
 {
     this.platformBeanType = Net.Vpc.Upa.Impl.Util.PlatformBeanTypeRepository.GetInstance().GetBeanType(entity.GetEntityType());
     this.entity           = entity;
     try {
         //entity.GetEntityType().GetConstructor().SetAccessible(true);
     } catch (System.Exception e) {
         throw new System.ArgumentException("Unable to resolve default constructor for type " + entity.GetEntityType() + " (entity " + entity.GetName() + ")", e);
     }
     foreach (Net.Vpc.Upa.Field field in entity.GetFields())
     {
         GetAttrAdapter(field.GetName());
     }
 }
Ejemplo n.º 6
0
        private Net.Vpc.Upa.Query Build()
        {
            //        if (query == null) {
            string entityName = entity.GetName();

            Net.Vpc.Upa.Expressions.Select s = (new Net.Vpc.Upa.Expressions.Select()).From(entityName, entityAlias);
            if (GetFieldFilter() != null)
            {
                foreach (Net.Vpc.Upa.Field field in entity.GetFields(GetFieldFilter()))
                {
                    if (field != null)
                    {
                        s.Field(new Net.Vpc.Upa.Expressions.Var(field.GetName()), field.GetName());
                    }
                }
            }
            Net.Vpc.Upa.Expressions.Expression criteria = null;
            if (GetId() != null)
            {
                Net.Vpc.Upa.Expressions.Expression e = entity.GetBuilder().IdToExpression(GetId(), entityName);
                criteria = criteria == null ? ((Net.Vpc.Upa.Expressions.Expression)(e)) : new Net.Vpc.Upa.Expressions.And(criteria, e);
            }
            if (GetKey() != null)
            {
                Net.Vpc.Upa.Expressions.Expression e = (entity.GetBuilder().IdToExpression(entity.GetBuilder().KeyToId(GetKey()), entityName));
                criteria = criteria == null ? ((Net.Vpc.Upa.Expressions.Expression)(e)) : new Net.Vpc.Upa.Expressions.And(criteria, e);
            }
            if (GetPrototype() != null)
            {
                Net.Vpc.Upa.Expressions.Expression e = entity.GetBuilder().ObjectToExpression(GetPrototype(), true, entityName);
                criteria = criteria == null ? ((Net.Vpc.Upa.Expressions.Expression)(e)) : new Net.Vpc.Upa.Expressions.And(criteria, e);
            }
            if (GetRecordPrototype() != null)
            {
                Net.Vpc.Upa.Expressions.Expression e = (entity.GetBuilder().RecordToExpression(GetRecordPrototype(), entityName));
                criteria = criteria == null ? ((Net.Vpc.Upa.Expressions.Expression)(e)) : new Net.Vpc.Upa.Expressions.And(criteria, e);
            }
            if (GetExpression() != null)
            {
                Net.Vpc.Upa.Expressions.Expression e = GetExpression();
                criteria = criteria == null ? ((Net.Vpc.Upa.Expressions.Expression)(e)) : new Net.Vpc.Upa.Expressions.And(criteria, e);
            }
            s.SetWhere(criteria);
            s.OrderBy(GetOrder());
            query = entity.CreateQuery(s);
            foreach (System.Collections.Generic.KeyValuePair <string, object> e in new System.Collections.Generic.HashSet <System.Collections.Generic.KeyValuePair <string, object> >(paramsByName))
            {
                query.SetParameter((e).Key, (e).Value);
            }
            foreach (System.Collections.Generic.KeyValuePair <int?, object> e in new System.Collections.Generic.HashSet <System.Collections.Generic.KeyValuePair <int?, object> >(paramsByIndex))
            {
                query.SetParameter(((e).Key).Value, (e).Value);
            }
            query.SetUpdatable(this.IsUpdatable());
            if (hints != null)
            {
                foreach (System.Collections.Generic.KeyValuePair <string, object> h in new System.Collections.Generic.HashSet <System.Collections.Generic.KeyValuePair <string, object> >(hints))
                {
                    query.SetHint((h).Key, (h).Value);
                }
            }
            //        }
            return(query);
        }
 protected internal virtual System.Collections.Generic.IList <Net.Vpc.Upa.Persistence.ResultField> CreateResultFields(Net.Vpc.Upa.Expressions.Expression expression, string alias, Net.Vpc.Upa.Filters.FieldFilter fieldFilter, System.Collections.Generic.IList <Net.Vpc.Upa.Expressions.QueryStatement> context)
 {
     expression = expressionManager.ParseExpression(expression);
     System.Collections.Generic.IList <Net.Vpc.Upa.Persistence.ResultField> results = new System.Collections.Generic.List <Net.Vpc.Upa.Persistence.ResultField>();
     if (expression is Net.Vpc.Upa.Expressions.Var)
     {
         Net.Vpc.Upa.Expressions.Var        v      = (Net.Vpc.Upa.Expressions.Var)expression;
         Net.Vpc.Upa.Expressions.Expression parent = v.GetApplier();
         if (parent != null)
         {
             System.Collections.Generic.IList <Net.Vpc.Upa.Persistence.ResultField> parentResults = CreateResultFields(parent, null, fieldFilter, context);
             int size = (parentResults).Count;
             foreach (Net.Vpc.Upa.Persistence.ResultField p in parentResults)
             {
                 if (size > 1)
                 {
                     v = (Net.Vpc.Upa.Expressions.Var)v.Copy();
                 }
                 if (p.GetExpression() != parent)
                 {
                     //change parent
                     v.SetApplier((Net.Vpc.Upa.Expressions.Var)p.GetExpression());
                 }
                 if (p.GetEntity() != null)
                 {
                     if (v.GetName().Equals("*"))
                     {
                         foreach (Net.Vpc.Upa.Field field in p.GetEntity().GetFields(fieldFilter))
                         {
                             results.Add(new Net.Vpc.Upa.Impl.Persistence.DefaultResultField(v, alias, field.GetDataType(), field, null));
                         }
                     }
                     else
                     {
                         Net.Vpc.Upa.Field field = p.GetEntity().GetField(v.GetName());
                         results.Add(new Net.Vpc.Upa.Impl.Persistence.DefaultResultField(v, alias, field.GetDataType(), field, null));
                     }
                 }
                 else if (p.GetField() != null)
                 {
                     if (p.GetField().GetDataType() is Net.Vpc.Upa.Types.ManyToOneType)
                     {
                         Net.Vpc.Upa.Entity entity = ((Net.Vpc.Upa.Types.ManyToOneType)p.GetField().GetDataType()).GetTargetEntity();
                         if (v.GetName().Equals("*"))
                         {
                             foreach (Net.Vpc.Upa.Field field in entity.GetFields(fieldFilter))
                             {
                                 results.Add(new Net.Vpc.Upa.Impl.Persistence.DefaultResultField(v, alias, field.GetDataType(), field, null));
                             }
                         }
                         else
                         {
                             Net.Vpc.Upa.Field field = entity.GetField(v.GetName());
                             results.Add(new Net.Vpc.Upa.Impl.Persistence.DefaultResultField(v, alias, field.GetDataType(), field, null));
                         }
                     }
                     else
                     {
                         results.Add(new Net.Vpc.Upa.Impl.Persistence.DefaultResultField(v, alias, Net.Vpc.Upa.Types.TypesFactory.OBJECT, null, null));
                     }
                 }
                 else
                 {
                     results.Add(new Net.Vpc.Upa.Impl.Persistence.DefaultResultField(v, alias, Net.Vpc.Upa.Types.TypesFactory.OBJECT, null, null));
                 }
             }
         }
         else
         {
             string name = v.GetName();
             System.Collections.Generic.IDictionary <string, Net.Vpc.Upa.Expressions.NameOrQuery> declarations = FindDeclarations(context);
             Net.Vpc.Upa.Expressions.NameOrQuery r = Net.Vpc.Upa.Impl.FwkConvertUtils.GetMapValue <string, Net.Vpc.Upa.Expressions.NameOrQuery>(declarations, name);
             if (r != null)
             {
                 if (r is Net.Vpc.Upa.Expressions.EntityName)
                 {
                     Net.Vpc.Upa.Entity entity = pu.GetEntity(((Net.Vpc.Upa.Expressions.EntityName)r).GetName());
                     results.Add(new Net.Vpc.Upa.Impl.Persistence.DefaultResultField(v, alias, entity.GetDataType(), null, entity));
                 }
                 else
                 {
                     results.Add(new Net.Vpc.Upa.Impl.Persistence.DefaultResultField(v, alias, Net.Vpc.Upa.Types.TypesFactory.OBJECT, null, null));
                 }
             }
             else
             {
                 if ("*".Equals(name))
                 {
                     foreach (System.Collections.Generic.KeyValuePair <string, Net.Vpc.Upa.Expressions.NameOrQuery> entry in new System.Collections.Generic.HashSet <System.Collections.Generic.KeyValuePair <string, Net.Vpc.Upa.Expressions.NameOrQuery> >(declarations))
                     {
                         r = (entry).Value;
                         if (r is Net.Vpc.Upa.Expressions.EntityName)
                         {
                             Net.Vpc.Upa.Entity entity = pu.GetEntity(((Net.Vpc.Upa.Expressions.EntityName)r).GetName());
                             Net.Vpc.Upa.Field  field  = entity.FindField(name);
                             results.Add(new Net.Vpc.Upa.Impl.Persistence.DefaultResultField(v, alias, field.GetDataType(), field, null));
                             break;
                         }
                     }
                 }
                 else
                 {
                     Net.Vpc.Upa.Field field = null;
                     foreach (System.Collections.Generic.KeyValuePair <string, Net.Vpc.Upa.Expressions.NameOrQuery> entry in new System.Collections.Generic.HashSet <System.Collections.Generic.KeyValuePair <string, Net.Vpc.Upa.Expressions.NameOrQuery> >(declarations))
                     {
                         r = (entry).Value;
                         if (r is Net.Vpc.Upa.Expressions.EntityName)
                         {
                             Net.Vpc.Upa.Entity entity = pu.GetEntity(((Net.Vpc.Upa.Expressions.EntityName)r).GetName());
                             field = entity.FindField(name);
                             break;
                         }
                     }
                     if (field != null)
                     {
                         results.Add(new Net.Vpc.Upa.Impl.Persistence.DefaultResultField(v, alias, field.GetDataType(), field, null));
                     }
                     else
                     {
                         results.Add(new Net.Vpc.Upa.Impl.Persistence.DefaultResultField(v, alias, Net.Vpc.Upa.Types.TypesFactory.OBJECT, null, null));
                     }
                 }
             }
         }
         return(results);
     }
     results.Add(new Net.Vpc.Upa.Impl.Persistence.DefaultResultField(expression, alias, Net.Vpc.Upa.Types.TypesFactory.OBJECT, null, null));
     return(results);
 }
Ejemplo n.º 8
0
 public virtual void CommitModelChanges()
 {
     System.Collections.Generic.List <Net.Vpc.Upa.Field> fields = new System.Collections.Generic.List <Net.Vpc.Upa.Field>(entity.GetFields(Net.Vpc.Upa.Filters.Fields.ByName(fieldNames)));
     this.fields = fields.ToArray();
 }