Ejemplo n.º 1
0
        protected override ObjectId[] GetObjectIds()
        {
            this.first.Session.Flush();

            var statement = new AllorsExtentStatementRootSql(this);

            this.BuildSql(statement);

            if (statement.Sorter != null)
            {
                statement.Sorter.BuildOrder(this.Sorter, this.Session.Database.Mapping, statement);
            }

            var objects = new List <ObjectId>();

            using (var command = statement.CreateSQLiteCommand())
            {
                using (DbDataReader reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        var objectId = new ObjectIdLong(reader.GetInt64(0));
                        objects.Add(objectId);
                    }

                    reader.Close();
                }
            }

            return(objects.ToArray());
        }
Ejemplo n.º 2
0
        private void LoadCompositeRelations(XmlReader reader, IRelationType relationType)
        {
            while (reader.Read())
            {
                switch (reader.NodeType)
                {
                case XmlNodeType.Element:
                    if (reader.Name.Equals(Serialization.Relation))
                    {
                        var associationString = reader.GetAttribute(Serialization.Association);
                        var association       = new ObjectIdLong(long.Parse(associationString));

                        if (reader.IsEmptyElement)
                        {
                            this.OnRelationNotLoaded(relationType.Id, association.ToString(), null);
                        }
                        else
                        {
                            var value       = reader.ReadString();
                            var roleStrings = value.Split(Serialization.ObjectsSplitterCharArray);

                            if (relationType.RoleType.IsOne && roleStrings.Length > 1)
                            {
                                foreach (var roleString in roleStrings)
                                {
                                    this.OnRelationNotLoaded(relationType.Id, association.ToString(), roleString);
                                }
                            }

                            foreach (var roleString in roleStrings)
                            {
                                var role = new ObjectIdLong(long.Parse(roleString));
                                //this.OnRelationNotLoaded(relationType.Id, association.ToString(), r);

                                var cmdText = @"
INSERT INTO " + this.Mapping.GetTableName(relationType) + " (" + Mapping.ColumnNameForAssociation + "," + Mapping.ColumnNameForRole + @")
VALUES (" + Mapping.ParameterNameForAssociation + "," + Mapping.ParameterNameForRole + ")";

                                using (var command = this.CreateCommand(cmdText))
                                {
                                    command.Parameters.Add(Mapping.ParameterNameForAssociation, Mapping.DbTypeForId).Value = association.Value;
                                    command.Parameters.Add(Mapping.ParameterNameForRole, Mapping.DbTypeForId).Value        = role.Value;

                                    command.ExecuteNonQuery();
                                }
                            }
                        }
                    }

                    break;

                case XmlNodeType.EndElement:
                    return;
                }
            }
        }
Ejemplo n.º 3
0
        protected override ObjectId[] GetObjectIds()
        {
            if (this.strategy != null)
            {
                if (this.role != null)
                {
                    return(this.strategy.ExtentGetCompositeRoles(this.role));
                }

                return(this.strategy.ExtentGetCompositeAssociations(this.association));
            }

            if (!this.type.ExistClass)
            {
                return(ObjectId.EmptyObjectIds);
            }

            this.session.Flush();

            var statement = new AllorsExtentStatementRootSql(this);
            var objects   = new List <ObjectId>();

            this.BuildSql(statement);

            if (statement.Sorter != null)
            {
                statement.Sorter.BuildOrder(statement.Sorter, this.Mapping, statement);
            }

            using (var command = statement.CreateSQLiteCommand())
            {
                using (DbDataReader reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        var objectId = new ObjectIdLong(reader.GetInt64(0));
                        objects.Add(objectId);
                    }

                    reader.Close();
                }
            }

            return(objects.ToArray());
        }
Ejemplo n.º 4
0
        private void LoadObjects(XmlReader reader)
        {
            var metaObjectIdString = reader.GetAttribute(Serialization.Id);
            var metaObjectId       = new Guid(metaObjectIdString);

            var objectType = (IObjectType)this.ObjectFactory.MetaPopulation.Find(metaObjectId);

            if (!reader.IsEmptyElement)
            {
                var oidsString = reader.ReadString();
                var oids       = oidsString.Split(Serialization.ObjectsSplitterCharArray);

                for (var i = 0; i < oids.Length; i++)
                {
                    var objectArray = oids[i].Split(Serialization.ObjectSplitterCharArray);

                    var objectId = new ObjectIdLong(long.Parse(objectArray[0]));
                    var cacheId  = new ObjectVersionLong(objectArray[1]);

                    if (!(objectType is IClass))
                    {
                        this.OnObjectNotLoaded(metaObjectId, objectId.ToString());
                    }
                    else
                    {
                        // Objects
                        var cmdText = @"
INSERT INTO " + Mapping.TableNameForObjects + " (" + Mapping.ColumnNameForObject + "," + Mapping.ColumnNameForType + "," + Mapping.ColumnNameForCache + @")
VALUES (" + Mapping.ParameterNameForObject + "," + Mapping.ParameterNameForType + "," + Mapping.ParameterNameForCache + ")";

                        using (var command = this.CreateCommand(cmdText))
                        {
                            command.Parameters.Add(Mapping.ParameterNameForObject, Mapping.DbTypeForId).Value   = objectId.Value;
                            command.Parameters.Add(Mapping.ParameterNameForType, Mapping.DbTypeForType).Value   = objectType.Id;
                            command.Parameters.Add(Mapping.ParameterNameForCache, Mapping.DbTypeForCache).Value = cacheId.Value;

                            command.ExecuteNonQuery();
                        }
                    }
                }
            }
        }
Ejemplo n.º 5
0
        private void LoadUnitRelations(XmlReader reader, IRelationType relationType)
        {
            while (reader.Read())
            {
                switch (reader.NodeType)
                {
                case XmlNodeType.Element:
                    if (reader.Name.Equals(Serialization.Relation))
                    {
                        var associationString = reader.GetAttribute(Serialization.Association);
                        var association       = new ObjectIdLong(long.Parse(associationString));
                        if (reader.IsEmptyElement)
                        {
                            object role;

                            // OnRelationNotLoaded(relationType.Id, association.ToString(), String.Empty);
                            if (relationType.RoleType.ObjectType.Id == UnitIds.StringId)
                            {
                                role = string.Empty;
                            }
                            else if (relationType.RoleType.ObjectType.Id == UnitIds.BinaryId)
                            {
                                role = EmptyByteArray;
                            }
                            else
                            {
                                this.OnRelationNotLoaded(relationType.Id, association.ToString(), string.Empty);
                                continue;
                            }

                            var cmdText = @"
INSERT INTO " + this.Mapping.GetTableName(relationType) + " (" + Mapping.ColumnNameForAssociation + "," + Mapping.ColumnNameForRole + @")
VALUES (" + Mapping.ParameterNameForAssociation + "," + Mapping.ParameterNameForRole + ")";

                            using (var command = this.CreateCommand(cmdText))
                            {
                                command.Parameters.Add(Mapping.ParameterNameForAssociation, Mapping.DbTypeForId).Value = association.Value;
                                command.Parameters.Add(Mapping.ParameterNameForRole, Mapping.GetSqlDbType(relationType.RoleType)).Value = role;

                                command.ExecuteNonQuery();
                            }
                        }
                        else
                        {
                            var value = reader.ReadString();
                            try
                            {
                                // OnRelationNotLoaded(relationType.Id, association.ToString(), value);
                                var unitTypeTag = ((IUnit)relationType.RoleType.ObjectType).UnitTag;
                                var role        = Serialization.ReadString(value, unitTypeTag);

                                var cmdText = @"
INSERT INTO " + this.Mapping.GetTableName(relationType) + " (" + Mapping.ColumnNameForAssociation + "," + Mapping.ColumnNameForRole + @")
VALUES (" + Mapping.ParameterNameForAssociation + "," + Mapping.ParameterNameForRole + ")";

                                using (var command = this.CreateCommand(cmdText))
                                {
                                    command.Parameters.Add(Mapping.ParameterNameForAssociation, Mapping.DbTypeForId).Value = association.Value;
                                    command.Parameters.Add(Mapping.ParameterNameForRole, Mapping.GetSqlDbType(relationType.RoleType)).Value = role;

                                    command.ExecuteNonQuery();
                                }
                            }
                            catch
                            {
                                this.OnRelationNotLoaded(relationType.Id, association.ToString(), value);
                            }
                        }
                    }

                    break;

                case XmlNodeType.EndElement:
                    return;
                }
            }
        }
Ejemplo n.º 6
0
        protected override ObjectId[] GetObjectIds()
        {
            this.first.Session.Flush();

            var statement = new AllorsExtentStatementRootSql(this);

            this.BuildSql(statement);

            if (statement.Sorter != null)
            {
                statement.Sorter.BuildOrder(this.Sorter, this.Session.Database.Mapping, statement);
            }

            var objects = new List<ObjectId>();
            using (var command = statement.CreateSQLiteCommand())
            {
                using (DbDataReader reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        var objectId = new ObjectIdLong(reader.GetInt64(0));
                        objects.Add(objectId);
                    }

                    reader.Close();
                }
            }

            return objects.ToArray();
        }
Ejemplo n.º 7
0
        protected override ObjectId[] GetObjectIds()
        {
            if (this.strategy != null)
            {
                if (this.role != null)
                {
                    return this.strategy.ExtentGetCompositeRoles(this.role);
                }

                return this.strategy.ExtentGetCompositeAssociations(this.association);
            }

            if (!this.type.ExistClass)
            {
                return ObjectId.EmptyObjectIds;
            }

            this.session.Flush();

            var statement = new AllorsExtentStatementRootSql(this);
            var objects = new List<ObjectId>();

            this.BuildSql(statement);

            if (statement.Sorter != null)
            {
                statement.Sorter.BuildOrder(statement.Sorter, this.Mapping, statement);
            }

            using (var command = statement.CreateSQLiteCommand())
            {
                using (DbDataReader reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        var objectId = new ObjectIdLong(reader.GetInt64(0));
                        objects.Add(objectId);
                    }

                    reader.Close();
                }
            }

            return objects.ToArray();
        }
Ejemplo n.º 8
0
        private void LoadObjects(XmlReader reader)
        {
            var metaObjectIdString = reader.GetAttribute(Serialization.Id);
            var metaObjectId = new Guid(metaObjectIdString);

            var objectType = (IObjectType)this.ObjectFactory.MetaPopulation.Find(metaObjectId);

            if (!reader.IsEmptyElement)
            {
                var oidsString = reader.ReadString();
                var oids = oidsString.Split(Serialization.ObjectsSplitterCharArray);

                for (var i = 0; i < oids.Length; i++)
                {
                    var objectArray = oids[i].Split(Serialization.ObjectSplitterCharArray);

                    var objectId = new ObjectIdLong(long.Parse(objectArray[0]));
                    var cacheId = new ObjectVersionLong(objectArray[1]);

                    if (!(objectType is IClass))
                    {
                        this.OnObjectNotLoaded(metaObjectId, objectId.ToString());
                    }
                    else
                    {
                        // Objects
                        var cmdText = @"
            INSERT INTO " + this.SchemaName + "." + Mapping.TableNameForObjects + " (" + Mapping.ColumnNameForObject + "," + Mapping.ColumnNameForType + "," + Mapping.ColumnNameForCache + @")
            VALUES (" + Mapping.ParameterNameForObject + "," + Mapping.ParameterNameForType + "," + Mapping.ParameterNameForCache + ")";

                        using (var command = this.CreateCommand(cmdText))
                        {
                            command.Parameters.Add(Mapping.ParameterNameForObject, this.mapping.SqlDbTypeForObject).Value = objectId.Value;
                            command.Parameters.Add(Mapping.ParameterNameForType, Mapping.SqlDbTypeForType).Value = objectType.Id;
                            command.Parameters.Add(Mapping.ParameterNameForCache, Mapping.SqlDbTypeForCache).Value = cacheId.Value;

                            command.ExecuteNonQuery();
                        }
                    }
                }
            }
        }