예제 #1
0
        public IDifferenceObject Compare(InfoBase target, InfoBase source)
        {
            IDifferenceObject root = new DifferenceObject(null, target, DifferenceType.None);

            CompareLists <Namespace>(root, target.Namespaces.ToList(), source.Namespaces.ToList());
            return(root);
        }
예제 #2
0
        static InfoBase()
        {
            QueryService service = new QueryService(MetadataPersistentContext.Current.ConnectionString);
            string       sql     = "SELECT [key] FROM [metadata].[infobases] WHERE [key] = CAST(0x00000000000000000000000000000000 AS uniqueidentifier);";
            object       key     = service.ExecuteScalar(sql);

            Metadata = new InfoBase((Guid)key, PersistentState.Virtual);
            Metadata.Load();
        }
예제 #3
0
            public static Entity GetEntity(InfoBase infoBase, int typeCode)
            {
                Entity entity = null;

                IPersistentContext context = MetadataPersistentContext.Current;

                using (SqlConnection connection = new SqlConnection(context.ConnectionString))
                    using (SqlCommand command = connection.CreateCommand())
                    {
                        connection.Open();
                        command.CommandType = CommandType.Text;

                        command.Parameters.AddWithValue("InfoBase", infoBase.identity);
                        command.Parameters.AddWithValue("TypeCode", typeCode);

                        command.CommandText =
                            @"WITH
                            namespaces ([owner], [key]) AS
                            (
	                            SELECT [owner], [key] FROM [metadata].[namespaces] WHERE [owner] = @InfoBase
	                            UNION ALL
	                            SELECT n.[owner], n.[key] FROM [metadata].[namespaces] AS n
	                            INNER JOIN
		                            namespaces AS anchor
	                            ON anchor.[key] = n.[owner]
                            )
                        SELECT
	                        e.[key]
                        FROM
	                        [metadata].[entities] AS e
	                        INNER JOIN namespaces AS n
	                        ON e.[namespace] = n.[key]
                        WHERE
	                        e.[code] = @TypeCode;"    ;

                        using (SqlDataReader reader = command.ExecuteReader())
                        {
                            if (reader.Read())
                            {
                                entity = context.Factory.New <Entity>(reader.GetGuid(0));
                            }
                        }
                    }
                return(entity);
            }
예제 #4
0
            void IDataMapper.Select(IPersistent entity)
            {
                InfoBase e = (InfoBase)entity;

                bool ok = false;

                using (SqlConnection connection = new SqlConnection(ConnectionString))
                {
                    connection.Open();

                    SqlCommand command = connection.CreateCommand();
                    command.CommandType = CommandType.Text;
                    command.CommandText = SelectCommandText;

                    SqlParameter parameter = new SqlParameter("key", SqlDbType.UniqueIdentifier)
                    {
                        Direction = ParameterDirection.Input,
                        Value     = e.identity
                    };
                    command.Parameters.Add(parameter);

                    SqlDataReader reader = command.ExecuteReader();

                    if (reader.Read())
                    {
                        e.name     = (string)reader[0];
                        e.server   = (string)reader[1];
                        e.database = (string)reader[2];
                        e.username = (string)reader[3];
                        e.password = (string)reader[4];
                        e.version  = (byte[])reader[5];
                        ok         = true;
                    }

                    reader.Close(); connection.Close();
                }

                if (!ok)
                {
                    throw new ApplicationException("Error executing select command.");
                }
            }
예제 #5
0
            void IDataMapper.Delete(IPersistent entity)
            {
                InfoBase e = (InfoBase)entity;

                bool ok = false;

                using (SqlConnection connection = new SqlConnection(ConnectionString))
                {
                    connection.Open();

                    SqlCommand command = connection.CreateCommand();
                    command.CommandType = CommandType.Text;
                    command.CommandText = DeleteCommandText;

                    SqlParameter parameter = null;

                    parameter           = new SqlParameter("key", SqlDbType.UniqueIdentifier);
                    parameter.Direction = ParameterDirection.Input;
                    parameter.Value     = e.identity;
                    command.Parameters.Add(parameter);

                    parameter           = new SqlParameter("version", SqlDbType.Timestamp);
                    parameter.Direction = ParameterDirection.Input;
                    parameter.Value     = e.version;
                    command.Parameters.Add(parameter);

                    SqlDataReader reader = command.ExecuteReader();

                    if (reader.Read())
                    {
                        ok = (int)reader[0] > 0;
                    }

                    reader.Close(); connection.Close();
                }

                if (!ok)
                {
                    throw new ApplicationException("Error executing delete command.");
                }
            }
예제 #6
0
        public void CreateMetaModel()
        {
            IMetadataService service  = new MetadataService();
            InfoBase         metadata = service.GetSystemInfoBase();

            Namespace root = new Namespace()
            {
                Owner = metadata,
                Name  = "MetaModel"
            };

            root.Save();

            Entity infoBase  = CreateInfoBase(root);
            Entity nameSpace = CreateNamespace(root, infoBase);
            Entity entity    = CreateEntity(root, nameSpace);
            Entity property  = CreateProperty(root, entity);
            Entity table     = CreateTable(root, entity);

            CreateField(root, table, property);
            CreateRelation(root, property, entity);
            CreateRequest(root, nameSpace, entity);
        }
예제 #7
0
        }                                                                   // for complex types - type code is stored in the database

        public ValueTranslator(InfoBase metadata, int targetTypeCode) : this(metadata)
        {
            _code = targetTypeCode;
        }
예제 #8
0
 public ValueTranslator(InfoBase metadata)
 {
     _metadata = metadata;
 }                                                                   // for complex types - type code is stored in the database
예제 #9
0
            void IDataMapper.Insert(IPersistent entity)
            {
                InfoBase e = (InfoBase)entity;

                bool ok = false;

                using (SqlConnection connection = new SqlConnection(ConnectionString))
                {
                    connection.Open();

                    SqlCommand command = connection.CreateCommand();
                    command.CommandType = CommandType.Text;
                    command.CommandText = InsertCommandText;

                    SqlParameter parameter = null;

                    parameter           = new SqlParameter("key", SqlDbType.UniqueIdentifier);
                    parameter.Direction = ParameterDirection.Input;
                    parameter.Value     = e.identity;
                    command.Parameters.Add(parameter);

                    parameter           = new SqlParameter("name", SqlDbType.NVarChar);
                    parameter.Direction = ParameterDirection.Input;
                    parameter.Value     = e.name;
                    command.Parameters.Add(parameter);

                    parameter           = new SqlParameter("server", SqlDbType.NVarChar);
                    parameter.Direction = ParameterDirection.Input;
                    parameter.Value     = e.server;
                    command.Parameters.Add(parameter);

                    parameter           = new SqlParameter("database", SqlDbType.NVarChar);
                    parameter.Direction = ParameterDirection.Input;
                    parameter.Value     = e.database;
                    command.Parameters.Add(parameter);

                    parameter           = new SqlParameter("username", SqlDbType.NVarChar);
                    parameter.Direction = ParameterDirection.Input;
                    parameter.Value     = e.username;
                    command.Parameters.Add(parameter);

                    parameter           = new SqlParameter("password", SqlDbType.NVarChar);
                    parameter.Direction = ParameterDirection.Input;
                    parameter.Value     = e.password;
                    command.Parameters.Add(parameter);

                    SqlDataReader reader = command.ExecuteReader();

                    if (reader.Read())
                    {
                        e.version = (byte[])reader[0]; ok = true;
                    }

                    reader.Close(); connection.Close();
                }

                if (!ok)
                {
                    throw new ApplicationException("Error executing insert command.");
                }
            }
예제 #10
0
            void IDataMapper.Update(IPersistent entity)
            {
                InfoBase e = (InfoBase)entity;

                bool ok = false; int rows_affected = 0;

                using (SqlConnection connection = new SqlConnection(ConnectionString))
                {
                    connection.Open();

                    SqlCommand command = connection.CreateCommand();
                    command.CommandType = CommandType.Text;
                    command.CommandText = UpdateCommandText;

                    SqlParameter parameter = null;

                    parameter           = new SqlParameter("key", SqlDbType.UniqueIdentifier);
                    parameter.Direction = ParameterDirection.Input;
                    parameter.Value     = e.identity;
                    command.Parameters.Add(parameter);

                    parameter           = new SqlParameter("version", SqlDbType.Timestamp);
                    parameter.Direction = ParameterDirection.Input;
                    parameter.Value     = e.version;
                    command.Parameters.Add(parameter);

                    parameter           = new SqlParameter("name", SqlDbType.NVarChar);
                    parameter.Direction = ParameterDirection.Input;
                    parameter.Value     = e.name;
                    command.Parameters.Add(parameter);

                    parameter           = new SqlParameter("server", SqlDbType.NVarChar);
                    parameter.Direction = ParameterDirection.Input;
                    parameter.Value     = e.server;
                    command.Parameters.Add(parameter);

                    parameter           = new SqlParameter("database", SqlDbType.NVarChar);
                    parameter.Direction = ParameterDirection.Input;
                    parameter.Value     = e.database;
                    command.Parameters.Add(parameter);

                    parameter           = new SqlParameter("username", SqlDbType.NVarChar);
                    parameter.Direction = ParameterDirection.Input;
                    parameter.Value     = e.username;
                    command.Parameters.Add(parameter);

                    parameter           = new SqlParameter("password", SqlDbType.NVarChar);
                    parameter.Direction = ParameterDirection.Input;
                    parameter.Value     = e.password;
                    command.Parameters.Add(parameter);

                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        if (reader.Read())
                        {
                            rows_affected = reader.GetInt32(0);
                            e.version     = (byte[])reader[1];
                            if (rows_affected == 0)
                            {
                                e.state = PersistentState.Changed;
                            }
                            else
                            {
                                ok = true;
                            }
                        }
                        else
                        {
                            e.state = PersistentState.Deleted;
                        }
                    }
                }

                if (!ok)
                {
                    throw new OptimisticConcurrencyException(e.state.ToString());
                }
            }