Exemplo n.º 1
0
        public Attribute(Entity owner, XmlNode node)
            : base(owner, node)
        {
            isDeclared = true;
            typeName   = new QualName(node, "typeSchema", "type", owner.Schema);
            SetType();
            if (attrType is ScalarType)
            {
                typeDefinition = new TypeDefinition(node, (attrType as ScalarType).TypeDefinition);
            }
            else
            {
                typeDefinition = new TypeDefinition(node);
            }

            persistence = new Persistence(this, node);

            primaryId       = Utils.Xml.GetAttrValue(node, "primaryid", primaryId);
            uniqueId        = Utils.Xml.GetAttrValue(node, "uniqueid", uniqueId);
            readOnly        = Utils.Xml.GetAttrValue(node, "readonly", readOnly);
            isAutoincrement = Utils.Xml.GetAttrValue(node, "autoincrement", isAutoincrement);
            hasMaxValue     = Utils.Xml.IsAttrExists(node, "maxValue");
            maxValue        = Utils.Xml.GetAttrValue(node, "maxValue", maxValue);

            generatorName = new QualName(node, "generatorSchema", "generator", owner.Schema);
            if (!generatorName.IsEmpty && Model.Generators.GetByName(generatorName.FullName) == null)
            {
                throw new GlException("Generator \"{0}\" not found. {1}", generatorName, this);
            }
        }
Exemplo n.º 2
0
        public Entity(Model model, XmlNode node) : base(model, node)
        {
            Init();

            supertypeName = new QualName(node, "supertypeSchema", "supertype", this.Schema);
            if (!supertypeName.IsEmpty)
            {
                Type t = Model.Types.FindType(supertypeName);
                if (t == null)
                {
                    throw new GlException("Supertype \"{0}\" not found. Entity: {1}", supertypeName.FullName, FullName);
                }
                supertype = (t as EntityType).Entity;
            }

            Model.Generators.AddList(this, Model.QueryNode(node, "./{0}:Generator"));

            persistence = new Persistence(this, node);
            if (!Persistence.SchemaDefined)
            {
                this.Persistence.Schema = Model.DefaultPersistentSchema;
                this.Persistence.LockSchema();
            }
            attributes  = new EntityAttributes(this, node);
            constraints = new EntityConstraints(this, node);

            this.EventHandlers = new EntityEventHandlers(this, node);
            this.Operations    = new EntityOperations(this, node);

            Model.PhysicalModel.Indexes.AddList(this, Model.QueryNode(node, "./{0}:Index"));
        }
Exemplo n.º 3
0
        public Type FindType(QualName typeName)
        {
            Type t = Model.Types.GetByName(typeName.FullName);

            if (t == null)
            {
                t = Model.Types.GetByName(QualName.MakeFullName(Const.EmptyName, typeName.Name));
            }
            if (t == null)
            {
                // Try to find by name
                int typesCount = 0;
                foreach (Type t2 in this)
                {
                    if (t2.Name.Equals(typeName.Name))
                    {
                        t = t2;
                        typesCount++;
                    }
                }
                if (typesCount > 1)
                {
                    throw new GlException("Ambigous type name \"{0}\". You should specify schema", typeName.Name);
                }
            }
            return(t);
        }
Exemplo n.º 4
0
        public PrimaryId(Entity owner, XmlNode constraintNode)
            : base(owner, constraintNode)
        {
            QualName qn = new QualName(constraintNode, "generatorSchema", "generator", owner.Schema);

            generator = Model.Generators.GetByName(qn.FullName);
            Init();
        }
Exemplo n.º 5
0
        private void Init(Model model, XmlNode node)
        {
            QualName qn = new QualName(node, Model.DefaultSchema);

            schema = qn.Schema;
            if (schema == Const.EmptyName)
            {
                throw new GlException("Both schema attribute and model default schema are not defined. Element: {0}", this);
            }
        }
Exemplo n.º 6
0
 public override string ToString()
 {
     return(String.Format("{0} ({1}-{2}): <{3}>--{4}--<{5}>",
                          GetType().Name,
                          Name,
                          Name2,
                          QualName.MakeFullName(schema, entityName),
                          CardinalityToString(cardinality),
                          QualName.MakeFullName(schema2, entityName2)));
 }
Exemplo n.º 7
0
        public Entity GetEntity(string name, string message)
        {
            QualName qname  = new QualName(name, Model.DefaultSchema);
            Entity   entity = Model.Entities.GetByName(qname.FullName, false);

            if (entity == null)
            {
                throw new GlException("{0}. Name: {1}", message, qname.FullName);
            }
            return(entity);
        }
Exemplo n.º 8
0
        private Entity UpdateEntity(string entSchema, string entName)
        {
            Entity result = Model.Entities.GetByName(QualName.MakeFullName(entSchema, entName));

            if (result == null)
            {
                throw new GlException("Specified entity not found: {0}. {1}",
                                      QualName.MakeFullName(entSchema, entName),
                                      this);
            }
            return(result);
        }
Exemplo n.º 9
0
        private void Init(XmlNode node)
        {
            definedInModel = true;
            Init();
            this.name = QualName.ExtractName(Utils.Xml.GetAttrValue(node, "name", Const.EmptyName));
            XmlNodeList docNodes = Model.QueryNode(node, "./{0}:Doc");

            if (docNodes.Count != 0)
            {
                doc = new Doc(this, docNodes[0]);
            }
            this.SpellHintParams = new SpellHintParams(this, Model.QueryNode(node, "./{0}:SpellHintParam"));
        }
Exemplo n.º 10
0
        public void ImplicitlyCreatedMetaobjectsTest()
        {
            GenieLamp lamp  = InitializationTest.LoadTestProject("TestProject.xml");
            Model     model = lamp.Model;

            Entity storeDoc = model.Entities.GetByName(QualName.MakeFullName(model.DefaultSchema, "StoreDoc"));

            Assert.IsNotNull(storeDoc, "Entity not exists");
            Generator gen = model.Generators.GetByName(QualName.MakeFullName(storeDoc.Schema, Generator.DefaultName(storeDoc)));

            Assert.IsNotNull(gen, "Implicit generator");
            Assert.AreEqual("SEQ_STORE_DOC", gen.Persistence.Name, "Implicit generator persistence name");
            Assert.AreEqual(Int32.MaxValue, gen.MaxValue, "Max value");
        }
Exemplo n.º 11
0
 public Attribute(Entity owner, Attribute source)
     : base(owner)
 {
     this.name      = source.name;
     this.typeName  = new QualName(source.TypeName);
     attrType       = source.Type;
     readOnly       = source.ReadOnly;
     typeDefinition = new TypeDefinition(source.TypeDefinition);
     persistence    = new Persistence(this,
                                      source.Persistence.Persisted,
                                      this.Entity.Persistence.SchemaDefined,
                                      this.Entity.Persistence.Schema,
                                      source.Persistence.NameDefined,
                                      source.Persistence.Name,
                                      false,
                                      Const.EmptyName);
 }
Exemplo n.º 12
0
 public Attribute(Entity owner, string name, ScalarType type)
     : base(owner)
 {
     this.name       = name;
     this.isDeclared = false;
     this.typeName   = new QualName(type.FullName, owner.Schema);
     attrType        = type;
     typeDefinition  = new TypeDefinition(type.TypeDefinition);
     persistence     = new Persistence(this,
                                       true,
                                       false,
                                       owner.Persistence.Schema,
                                       false,
                                       name,
                                       false,
                                       Const.EmptyName);
 }
Exemplo n.º 13
0
        public EntityOperationParam(EntityOperation owner, XmlNode node)
            : base(owner, node)
        {
            typeName  = new QualName(Utils.Xml.GetAttrValue(node, "type"), owner.Model.DefaultSchema);
            this.Type = Model.Types.FindType(typeName);
            if (this.Type == null)
            {
                throw new GlException("Type \"{0}\" not found. Entity: {1}. Operation: {2}",
                                      typeName, owner.Owner.FullName, owner.Name);
            }
            this.IsRaw = bool.Parse(Utils.Xml.GetAttrValue(node, "raw"));
            this.IsRef = bool.Parse(Utils.Xml.GetAttrValue(node, "ref"));
            this.IsOut = bool.Parse(Utils.Xml.GetAttrValue(node, "out"));

            this.TypeDefinition = new TypeDefinition(node);
            if (!this.TypeDefinition.HasRequired)
            {
                this.TypeDefinition.Required = true;
            }
        }
Exemplo n.º 14
0
 public void AddList(Entity owner, XmlNodeList indexNodes)
 {
     foreach (XmlNode indexNode in indexNodes)
     {
         if (owner == null)
         {
             if (!Utils.Xml.IsAttrExists(indexNode, "entityName"))
             {
                 throw new GlException("Index must specify 'entityName' attribute when defined out of entity");
             }
             QualName entityName = new QualName(indexNode, "entitySchema", "entityName", Model.DefaultSchema);
             //Utils.Xml.GetAttrValue(indexNode, "entityName", Const.EmptyName);
             owner = Model.Entities.GetByName(entityName.FullName);
             if (owner == null)
             {
                 throw new GlException("Index was specified for non existing entity '{0}'", entityName);
             }
         }
         Index index = new Index(owner, indexNode);
         Add(index);
     }
 }
Exemplo n.º 15
0
        public void IndexesTest()
        {
            GenieLamp lamp  = InitializationTest.LoadTestProject("TestProject.xml");
            Model     model = lamp.Model;

            Entity en = model.Entities.GetByName(QualName.MakeFullName(model.DefaultSchema, "StoreDoc"));

            Assert.IsNotNull(en, "Entity not exists");
            int  indexCount        = 0;
            bool hasCompositeIndex = false;

            foreach (Index ix in model.PhysicalModel.Indexes.GetByEntity(en))
            {
                if (ix.DefinedInModel)
                {
                    Assert.IsTrue(ix.Generate, "Index should be generated");
                    indexCount++;
                    if (ix.Columns.Count == 1)
                    {
                        if (ix.Columns[0].Attribute.Name == "RefNum")
                        {
                            Assert.IsTrue(ix.Unique, "Index should be unique");
                            Assert.AreEqual(ColumnOrder.Desc, ix.Columns[0].Order);
                        }
                        else if (ix.Columns[0].Attribute.Name == "Name")
                        {
                            Assert.IsFalse(ix.Unique, "Index should be not unique");
                            Assert.AreEqual(ColumnOrder.Asc, ix.Columns[0].Order);
                        }
                    }
                    else if (ix.Columns.Count > 1)
                    {
                        hasCompositeIndex = true;
                    }
                }
            }
            Assert.AreEqual(3, indexCount, "Invalid index count");
            Assert.IsTrue(hasCompositeIndex, "Composite index absent");
        }
Exemplo n.º 16
0
        public Relation(Model owner, XmlNode node) : base(owner, node)
        {
            QualName name = new QualName(node, "schema", "entity", Model.DefaultSchema);

            this.schema     = name.Schema;
            this.entityName = name.Name;
            QualName name2 = new QualName(node, "schema2", "entity2", Model.DefaultSchema);

            this.schema2     = name2.Schema;
            this.entityName2 = name2.Name;
            this.name2       = Utils.Xml.GetAttrValue(node, "name2", Const.EmptyName);
            this.required    = Utils.Xml.GetAttrValue(node, "required", this.required);
            this.navigate    = Utils.Xml.GetAttrValue(node, "navigate", this.navigate);
            this.navigate2   = Utils.Xml.GetAttrValue(node, "navigate2", this.navigate2);
            this.cardinality = ParseCardinality(Utils.Xml.GetAttrValue(node, "cardinality"));
            this.cascade     = ParseRelationCascade(Utils.Xml.GetAttrValue(node, "cascade"));
            Init();
            this.persistence  = new Persistence(this, node);
            this.attrMatch    = new RelationAttributesMatch(this, node);
            this.foreignKey   = Model.PhysicalModel.ForeignKeys.CreateForeignKey(this);
            this.hasIndexName = Utils.Xml.IsAttrExists(node, "indexName");
            this.indexName    = Utils.Xml.GetAttrValue(node, "indexName", this.indexName);
        }
Exemplo n.º 17
0
        public void ConstraintIndexPersistentNameTest()
        {
            GenieLamp lamp  = InitializationTest.LoadTestProject("TestProject.xml");
            Model     model = lamp.Model;

            Entity en = model.Entities.GetByName(QualName.MakeFullName(model.DefaultSchema, "ProductType"));

            Assert.IsNotNull(en, "ProductType entity not exists");
            UniqueId u = null;

            foreach (UniqueId u2 in en.Constraints.UniqueIds)
            {
                if (u2.Attributes.Count == 1 && u2.Attributes[0].Name == "Code")
                {
                    u = u2;
                    break;
                }
            }
            Assert.IsNotNull(u, "Constraint not found");
            Assert.IsTrue(u.Persistence.NameDefined, "Constraint does not have index name");
            Assert.AreEqual("IX_CUSTOM_PRODUCT_TYPE", u.Persistence.Name, "Constraint index name was changed");
            Assert.IsNotNull(u.Index, "Relation does not have index");
            Assert.AreEqual(u.Persistence.Name, u.Index.Name, "Relation persistent name was changed");
        }
Exemplo n.º 18
0
 public string GetClassName_QueryParams(bool fullName)
 {
     return(QualName.MakeFullName(fullName ? this.QueriesNamespace : Const.EmptyName, ClassName_QueryParams));
 }
Exemplo n.º 19
0
 public string GetClassName_SortOrder(bool fullName)
 {
     return(QualName.MakeFullName(fullName ? this.QueriesNamespace : Const.EmptyName, ClassName_SortOrder));
 }
Exemplo n.º 20
0
 public MetaObject(MetaObject owner, string name)
     : this(owner)
 {
     this.name = QualName.ExtractName(name);
     Init();
 }
Exemplo n.º 21
0
 protected override string GetFullName()
 {
     return(QualName.MakeFullName(schema, name));
 }
Exemplo n.º 22
0
 public MetaObject(Model model, string name)
     : this(model)
 {
     this.name = QualName.ExtractName(name);
     Init();
 }