Esempio n. 1
0
 /**
  * Thread Safe retrieval of UPAContext
  *
  * @return current UPAContext
  */
 public static Net.Vpc.Upa.UPAContext GetContext() /* throws Net.Vpc.Upa.Exceptions.UPAException */
 {
     Net.Vpc.Upa.UPAContextProvider contextProvider = null;
     Net.Vpc.Upa.UPAContext         context         = contextProvider.GetContext();
     //Double Checking Lock will/should work here because we are not about to instantiate the object,
     //this is the responsibility of the contextProvider
     if (context == null)
     {
         lock (typeof(Net.Vpc.Upa.UPAContext)) {
             context = contextProvider.GetContext();
             if (context == null)
             {
                 Net.Vpc.Upa.ObjectFactory bootstrapFactory = GetBootstrapFactory();
                 context = bootstrapFactory.CreateObject <Net.Vpc.Upa.UPAContext>(typeof(Net.Vpc.Upa.UPAContext));
                 context.Start(bootstrapFactory);
                 contextProvider.SetContext(context);
             }
         }
     }
     return(context);
 }
Esempio n. 2
0
 public virtual T CreateObject <T>(System.Type type, string name)
 {
     System.Type best = map.Get(type);
     if (best == null || !type.IsAssignableFrom(best))
     {
         if (parentFactory != null)
         {
             return(parentFactory.CreateObject <T>(type, name));
         }
         if (Net.Vpc.Upa.Impl.Util.PlatformUtils.IsAbstract(type) || Net.Vpc.Upa.Impl.Util.PlatformUtils.IsInterface(type))
         {
             throw new System.Exception((type).Name);
         }
         best = type;
     }
     try {
         return((T)(T)System.Activator.CreateInstance(best));
     } catch (System.Exception e) {
         throw new System.Exception("RuntimeException", e);
     }
 }
Esempio n. 3
0
 public override Net.Vpc.Upa.Record CreateRecord()
 {
     return(objectFactory.CreateObject <Net.Vpc.Upa.Record>(typeof(Net.Vpc.Upa.Record)));
 }
 public virtual T CreateObject <T>(System.Type type, string name)
 {
     return(baseFactory.CreateObject <T>(type, name));
 }
 public override T Parse(Net.Vpc.Upa.Persistence.QueryResult result) /* throws Net.Vpc.Upa.Exceptions.UPAException */
 {
     System.Collections.Generic.IDictionary <string, object> groupValues = new System.Collections.Generic.Dictionary <string, object>();
     Net.Vpc.Upa.Impl.Persistence.Result.ResultColumn[]      values      = new Net.Vpc.Upa.Impl.Persistence.Result.ResultColumn[(metaData.GetFields()).Count];
     for (int i = 0; i < values.Length; i++)
     {
         values[i] = new Net.Vpc.Upa.Impl.Persistence.Result.ResultColumn();
     }
     foreach (Net.Vpc.Upa.Impl.Persistence.Result.TypeInfo typeInfo in typeInfos)
     {
         typeInfo.entityObject = null;
         typeInfo.entityRecord = null;
         typeInfo.entityResult = null;
     }
     foreach (Net.Vpc.Upa.Impl.Persistence.Result.TypeInfo typeInfo in typeInfos)
     {
         if (typeInfo.entity == null)
         {
             foreach (Net.Vpc.Upa.Impl.Persistence.Result.FieldInfo f in typeInfo.allFields)
             {
                 object fieldValue = result.Read <T>(f.dbIndex);
                 groupValues[f.nativeField.GetFullBinding()] = fieldValue;
                 groupValues[f.nativeField.GetExprString()]  = fieldValue;
                 UpdateRow(values, f, f.nativeField.GetExprString(), fieldValue);
             }
         }
         else if (typeInfo.leadPrimaryField == null)
         {
             if (typeInfo.record)
             {
                 object             entityObject = null;
                 Net.Vpc.Upa.Record entityRecord = typeInfo.entityFactory == null ? ((Net.Vpc.Upa.Record)(ofactory.CreateObject <Net.Vpc.Upa.Record>(typeof(Net.Vpc.Upa.Record)))) : typeInfo.entityFactory.CreateRecord();
                 typeInfo.entityObject = entityObject;
                 typeInfo.entityRecord = entityRecord;
                 typeInfo.entityResult = entityRecord;
             }
             else
             {
                 object             entityObject = typeInfo.entityFactory.CreateObject <R>();
                 Net.Vpc.Upa.Record entityRecord = typeInfo.entityConverter.ObjectToRecord(entityObject, true);
                 typeInfo.entityObject = entityObject;
                 typeInfo.entityRecord = entityRecord;
                 typeInfo.entityResult = entityObject;
             }
             groupValues[typeInfo.binding] = typeInfo.entityResult;
             UpdateRow(values, typeInfo, typeInfo.binding, typeInfo.entityResult);
             foreach (Net.Vpc.Upa.Impl.Persistence.Result.FieldInfo f in typeInfo.allFields)
             {
                 object fieldValue = result.Read <T>(f.dbIndex);
                 groupValues[f.nativeField.GetFullBinding()] = fieldValue;
                 typeInfo.entityRecord.SetObject(f.name, fieldValue);
                 UpdateRow(values, f, f.nativeField.GetExprString(), fieldValue);
             }
         }
         else
         {
             object leadPK = result.Read <T>(typeInfo.leadPrimaryField.dbIndex);
             if (leadPK != null)
             {
                 //create new instances
                 if (typeInfo.record)
                 {
                     typeInfo.entityRecord = typeInfo.entityFactory == null ? ((Net.Vpc.Upa.Record)(ofactory.CreateObject <Net.Vpc.Upa.Record>(typeof(Net.Vpc.Upa.Record)))) : typeInfo.entityFactory.CreateRecord();
                     typeInfo.entityResult = typeInfo.entityRecord;
                 }
                 else
                 {
                     object             entityObject = typeInfo.entityFactory.CreateObject <R>();
                     Net.Vpc.Upa.Record entityRecord = typeInfo.entityConverter.ObjectToRecord(entityObject, true);
                     typeInfo.entityObject = entityObject;
                     typeInfo.entityRecord = entityRecord;
                     typeInfo.entityResult = entityObject;
                 }
                 groupValues[typeInfo.binding] = typeInfo.entityResult;
                 UpdateRow(values, typeInfo, typeInfo.binding, typeInfo.entityResult);
                 foreach (Net.Vpc.Upa.Impl.Persistence.Result.FieldInfo f in typeInfo.allFields)
                 {
                     object fieldValue = result.Read <T>(f.dbIndex);
                     groupValues[f.nativeField.GetFullBinding()] = fieldValue;
                     UpdateRow(values, f, f.nativeField.GetExprString(), fieldValue);
                     typeInfo.entityRecord.SetObject(f.name, fieldValue);
                 }
                 if (loadManyToOneRelations)
                 {
                     foreach (Net.Vpc.Upa.Relationship relationship in typeInfo.manyToOneRelations)
                     {
                         object extractedId = relationship.ExtractIdByForeignFields(typeInfo.entityRecord);
                         if (extractedId != null)
                         {
                             object @value = loader.LoadObject(relationship.GetTargetEntity(), extractedId, relationAsRecord, loaderContext);
                             typeInfo.entityRecord.SetObject(relationship.GetSourceRole().GetEntityField().GetName(), @value);
                             groupValues[typeInfo.binding + "." + relationship.GetSourceRole().GetEntityField().GetName()] = @value;
                         }
                     }
                 }
             }
             else
             {
                 typeInfo.entityObject = null;
                 typeInfo.entityRecord = null;
             }
         }
     }
     foreach (Net.Vpc.Upa.Impl.Persistence.Result.TypeInfo typeInfo in typeInfos)
     {
         if (typeInfo.parentBinding != null)
         {
             Net.Vpc.Upa.Impl.Persistence.Result.TypeInfo pp = Net.Vpc.Upa.Impl.FwkConvertUtils.GetMapValue <string, Net.Vpc.Upa.Impl.Persistence.Result.TypeInfo>(bindingToTypeInfos, typeInfo.parentBinding);
             if (pp == null)
             {
             }
             else if (pp.entityRecord != null)
             {
                 pp.entityRecord.SetObject(typeInfo.bindingName, typeInfo.entityResult);
             }
         }
     }
     if (updatable)
     {
         foreach (Net.Vpc.Upa.Impl.Persistence.Result.TypeInfo typeInfo in typeInfos)
         {
             if (typeInfo.record)
             {
                 Net.Vpc.Upa.Impl.Persistence.Result.QueryResultUpdaterPropertyChangeListener li = new Net.Vpc.Upa.Impl.Persistence.Result.QueryResultUpdaterPropertyChangeListener(typeInfo, result);
                 typeInfo.entityRecord.AddPropertyChangeListener(li);
             }
             else
             {
                 typeInfo.entityUpdatable      = Net.Vpc.Upa.Impl.Util.PlatformUtils.CreateObjectInterceptor <object>(typeInfo.entityType, new Net.Vpc.Upa.Impl.Persistence.Result.UpdatableObjectInterceptor(typeInfo, typeInfo.entityObject, result));
                 groupValues[typeInfo.binding] = typeInfo.entityUpdatable;
                 int index = typeInfo.allFields[0].nativeField.GetIndex();
                 if (values[index].GetValue() == typeInfo.entityType)
                 {
                     values[index].SetValue(typeInfo.entityUpdatable);
                 }
             }
         }
     }
     return((T)this.resultBuilder.CreateResult(values, metaData));
 }
 internal virtual void ParseEntityType(Net.Vpc.Upa.Impl.Config.Annotationparser.EntityInfo entityInfo, System.Type type, bool parseFields, bool parseModifiers, bool parseExtensions, Net.Vpc.Upa.ObjectFactory factory)
 {
     Net.Vpc.Upa.Config.Decoration ue = repo.GetTypeDecoration(type, typeof(Net.Vpc.Upa.Config.Entity));
     entityInfo.idType = Net.Vpc.Upa.Impl.Config.Annotationparser.AnnotationParserUtils.ValidClass(ue == null ? null : ue.GetType("idType"), entityInfo.idType, typeof(object));
     if (ue != null && !ue.GetType("entityType").Equals(typeof(void)))
     {
         entityInfo.entityType.SetBetterValue(ue.GetType("entityType"), ue.GetConfig().GetOrder());
     }
     entityInfo.name      = Net.Vpc.Upa.Impl.Config.Annotationparser.AnnotationParserUtils.ValidStr(Net.Vpc.Upa.Impl.Config.Annotationparser.AnnotationParserUtils.ValidStr(ue == null ? null : ue.GetString("name"), entityInfo.name), (type).Name);
     entityInfo.shortName = Net.Vpc.Upa.Impl.Config.Annotationparser.AnnotationParserUtils.ValidStr(ue == null ? null : ue.GetString("shortName"), entityInfo.shortName);
     if (parseModifiers && ue != null)
     {
         System.Collections.Generic.List <Net.Vpc.Upa.EntityModifier> all = new System.Collections.Generic.List <Net.Vpc.Upa.EntityModifier>();
         foreach (Net.Vpc.Upa.Config.DecorationValue v in ue.GetArray("modifiers"))
         {
             Net.Vpc.Upa.Impl.Config.Decorations.DecorationPrimitiveValue pv = (Net.Vpc.Upa.Impl.Config.Decorations.DecorationPrimitiveValue)v;
             all.Add(Net.Vpc.Upa.Impl.Util.PlatformUtils.Convert <Net.Vpc.Upa.EntityModifier>(pv.GetValue(), typeof(Net.Vpc.Upa.EntityModifier)));
         }
         entityInfo.AddModifiers(all);
         all = new System.Collections.Generic.List <Net.Vpc.Upa.EntityModifier>();
         foreach (Net.Vpc.Upa.Config.DecorationValue v in ue.GetArray("excludeModifiers"))
         {
             Net.Vpc.Upa.Impl.Config.Decorations.DecorationPrimitiveValue pv = (Net.Vpc.Upa.Impl.Config.Decorations.DecorationPrimitiveValue)v;
             all.Add(Net.Vpc.Upa.Impl.Util.PlatformUtils.Convert <Net.Vpc.Upa.EntityModifier>(pv.GetValue(), typeof(Net.Vpc.Upa.EntityModifier)));
         }
         entityInfo.AddExcludeModifiers(all);
     }
     if (ue != null && ue.GetString("path") != null && (ue.GetString("path")).Length > 0)
     {
         entityInfo.path.SetBetterValue(ue.GetString("path"), ue.GetConfig().GetOrder());
     }
     if (ue != null && ue.GetString("listOrder") != null && (ue.GetString("listOrder")).Length > 0)
     {
         entityInfo.listOrder.SetBetterValue(ue.GetString("listOrder"), ue.GetConfig().GetOrder());
     }
     if (ue != null && ue.GetString("archivingOrder") != null && (ue.GetString("archivingOrder")).Length > 0)
     {
         entityInfo.archivingOrder.SetBetterValue(ue.GetString("archivingOrder"), ue.GetConfig().GetOrder());
     }
     Net.Vpc.Upa.Config.Decoration path = (Net.Vpc.Upa.Config.Decoration)repo.GetTypeDecoration(type, typeof(Net.Vpc.Upa.Config.Path));
     if (path != null)
     {
         if ((path.GetString("value")).Length > 0)
         {
             entityInfo.path.SetBetterValue(path.GetString("value"), path.GetConfig().GetOrder());
         }
         if (path.GetInt("position") != System.Int32.MinValue)
         {
             entityInfo.pathPosition.SetBetterValue(path.GetInt("position"), path.GetConfig().GetOrder());
         }
     }
     foreach (Net.Vpc.Upa.Config.Decoration indexAnn in FindIndexAnnotation(type))
     {
         //net.vpc.upa.config.Index
         System.Collections.Generic.IList <string> rr = new System.Collections.Generic.List <string>();
         Net.Vpc.Upa.Impl.FwkConvertUtils.ListAddRange(rr, new System.Collections.Generic.List <string>(indexAnn.GetPrimitiveArray <string>("fields", typeof(string))));
         entityInfo.AddIndex(indexAnn.GetString("name"), rr, indexAnn.GetBoolean("unique"), indexAnn.GetConfig().GetOrder());
     }
     //        net.vpc.upa.config.Sequence gue = (net.vpc.upa.config.Sequence) type.getAnnotation(Sequence.class);
     //        if (gue != null) {
     //            if (privateInfo.generatedIdInfo == null) {
     //                privateInfo.generatedIdInfo = new SequenceInfo();
     //            }
     //            privateInfo.generatedIdInfo.merge(gue);
     //        }
     if (parseFields)
     {
         System.Collections.Generic.IList <Net.Vpc.Upa.Impl.Config.Annotationparser.FieldInfo> fieldInfos = new System.Collections.Generic.List <Net.Vpc.Upa.Impl.Config.Annotationparser.FieldInfo>();
         if (!typeof(Net.Vpc.Upa.Record).IsAssignableFrom(type))
         {
             System.Type c = type;
             while (c != null)
             {
                 System.Collections.Generic.IList <Net.Vpc.Upa.Impl.Config.Annotationparser.FieldInfo> cfields = new System.Collections.Generic.List <Net.Vpc.Upa.Impl.Config.Annotationparser.FieldInfo>();
                 foreach (System.Reflection.FieldInfo field in c.GetFields(System.Reflection.BindingFlags.Default))
                 {
                     if (AcceptField(field))
                     {
                         string fieldName = GetFieldName(field);
                         Net.Vpc.Upa.Config.Decoration ignored = repo.GetFieldDecoration(field, typeof(Net.Vpc.Upa.Config.Ignore));
                         if (ignored != null)
                         {
                             Net.Vpc.Upa.Impl.Config.Annotationparser.FieldInfo oldValue = Net.Vpc.Upa.Impl.FwkConvertUtils.GetMapValue <string, Net.Vpc.Upa.Impl.Config.Annotationparser.FieldInfo>(entityInfo.fieldsMap, fieldName);
                             if (oldValue != null)
                             {
                                 oldValue.valid = false;
                             }
                         }
                         else
                         {
                             Net.Vpc.Upa.Impl.Config.Annotationparser.FieldInfo oldValue = Net.Vpc.Upa.Impl.FwkConvertUtils.GetMapValue <string, Net.Vpc.Upa.Impl.Config.Annotationparser.FieldInfo>(entityInfo.fieldsMap, fieldName);
                             if (oldValue == null)
                             {
                                 oldValue = new Net.Vpc.Upa.Impl.Config.Annotationparser.FieldInfo(fieldName, entityInfo, repo);
                                 cfields.Add(oldValue);
                             }
                             oldValue.RegisterField(field);
                         }
                     }
                 }
                 Net.Vpc.Upa.Impl.FwkConvertUtils.ListInsertRange(fieldInfos, 0, cfields);
                 c = (c).BaseType;
             }
         }
         foreach (Net.Vpc.Upa.Impl.Config.Annotationparser.FieldInfo fieldInfo in fieldInfos)
         {
             string name = fieldInfo.name;
             Net.Vpc.Upa.Impl.Config.Annotationparser.FieldInfo old = Net.Vpc.Upa.Impl.FwkConvertUtils.GetMapValue <string, Net.Vpc.Upa.Impl.Config.Annotationparser.FieldInfo>(entityInfo.fieldsMap, name);
             if (old != null)
             {
                 throw new System.ArgumentException("Should never happen");
             }
             entityInfo.fieldsMap[name] = fieldInfo;
         }
     }
     if (parseExtensions)
     {
         Net.Vpc.Upa.Config.Decoration unionEntity = repo.GetTypeDecoration(type, typeof(Net.Vpc.Upa.Config.UnionEntity));
         if (unionEntity != null)
         {
             if (unionEntity.GetType("spec").Equals(typeof(Net.Vpc.Upa.Extensions.UnionEntityExtensionDefinition)))
             {
                 string discriminator = unionEntity.GetString("discriminator");
                 //                    String[] fields = unionEntity.fields();
                 //                    UnionEntityEntry[] entities = unionEntity.entities();
                 Net.Vpc.Upa.Config.DecorationValue[]      entities  = unionEntity.GetArray("entities");
                 System.Collections.Generic.IList <string> _entities = new System.Collections.Generic.List <string>();
                 System.Collections.Generic.IList <string> _fields   = new System.Collections.Generic.List <string>();
                 Net.Vpc.Upa.Impl.FwkConvertUtils.ListAddRange(_fields, new System.Collections.Generic.List <string>(unionEntity.GetPrimitiveArray <string>("fields", typeof(string))));
                 string     _entityFieldName = discriminator;
                 string[][] _mapping         = (string[][])Net.Vpc.Upa.Impl.FwkConvertUtils.CreateMultiArray(typeof(string), entities.Length, (_fields).Count);
                 int        ientity          = 0;
                 foreach (Net.Vpc.Upa.Config.DecorationValue entity0 in entities)
                 {
                     Net.Vpc.Upa.Config.Decoration entity = (Net.Vpc.Upa.Config.Decoration)entity0;
                     //UnionEntityEntry
                     _entities.Add(entity.GetString("entity"));
                     int ifield = 0;
                     foreach (string field in _fields)
                     {
                         string   f       = null;
                         string[] efields = entity.GetPrimitiveArray <string>("fields", typeof(string));
                         if (ifield < efields.Length)
                         {
                             f = efields[ifield];
                         }
                         if (f == null)
                         {
                             f = field;
                         }
                         _mapping[ientity][ifield] = f;
                         ifield++;
                     }
                     ientity++;
                 }
                 entityInfo.specs.Add(new Net.Vpc.Upa.Extensions.DefaultUnionEntityExtensionDefinition(new Net.Vpc.Upa.Extensions.UnionQueryInfo(_entities, _fields, _entityFieldName, _mapping)));
             }
             else
             {
                 entityInfo.specs.Add((Net.Vpc.Upa.Extensions.EntityExtensionDefinition)factory.CreateObject <T>(unionEntity.GetType("spec")));
             }
         }
         Net.Vpc.Upa.Config.Decoration view = (Net.Vpc.Upa.Config.Decoration)repo.GetTypeDecoration(type, typeof(Net.Vpc.Upa.Config.View));
         if (view != null)
         {
             System.Type spec = view.GetType("spec");
             if (spec.Equals(typeof(Net.Vpc.Upa.Extensions.ViewEntityExtensionDefinition)))
             {
                 throw new System.ArgumentException("Unsupported");
             }
             else
             {
                 entityInfo.specs.Add(factory.CreateObject <Net.Vpc.Upa.Extensions.ViewEntityExtensionDefinition>(spec));
             }
         }
     }
 }
Esempio n. 7
0
 public override Net.Vpc.Upa.Record CreateRecord()
 {
     return((Net.Vpc.Upa.Record)objectFactory.CreateObject <object>(recordType));
 }
Esempio n. 8
0
 public virtual Net.Vpc.Upa.Persistence.PersistenceStore CreatePersistenceStore(Net.Vpc.Upa.Persistence.ConnectionProfile connectionProfile, Net.Vpc.Upa.ObjectFactory factory, Net.Vpc.Upa.Properties parameters)
 {
     return(factory.CreateObject <Net.Vpc.Upa.Persistence.PersistenceStore>(GetDialectPersistenceUnitManager(connectionProfile.GetDatabaseProduct())));
 }