示例#1
0
        void IProviderExtend.DeleteTable(MetaTable metaTable)
        {
            var OracleSqlBuilder = new OracleSqlBuilder(this);
            var commands         = OracleSqlBuilder.GetDropTableCommands(metaTable);

            foreach (var command in commands)
            {
                services.Context.ExecuteCommand(command);
            }
        }
示例#2
0
        void IProviderExtend.CreateForeignKeys(MetaTable metaTable)
        {
            //var metaTable = services.Model.GetTable(metaTable);
            var sqlBuilder = new OracleSqlBuilder(this);
            var commands   = sqlBuilder.GetCreateForeignKeyCommands(metaTable);

            foreach (var command in commands)
            {
                services.Context.ExecuteCommand(command);
            }
        }
示例#3
0
        public void Can_BuildTargetSql()
        {
            var input  = GetJsonFile <DatabaseJobManifest>(_inputRoot, "database.manifest.xepdb1.json");
            var tables = input.manifest.tables;
            var expectedResultFiles = new List <string> {
                "xepdb1.target.person.json", "xepdb1.target.product.json"
            };

            var target = new OracleSqlBuilder();

            for (int i = 0; i < tables.Length; i++)
            {
                var result         = target.BuildTargetSql(tables[i]);
                var expectedResult = GetJsonFile <TargetSql>(_outputRoot, expectedResultFiles[i]);
                result.Should().BeEquivalentTo(expectedResult);
            }
        }
示例#4
0
        public void CreateDatabase()
        {
            if (DatabaseExists())
            {
                throw SqlClient.Error.CreateDatabaseFailedBecauseSqlCEDatabaseAlreadyExists(dbName);
            }
            if (string.IsNullOrEmpty(dbName))
            {
                throw Error.ArgumentNull("Database Name");
            }

            var conn = conManager.UseConnection(this);



            var transaction      = conn.BeginTransaction();
            var OracleSqlBuilder = new OracleSqlBuilder(this);

            try
            {
                Execute(conn, transaction, OracleSqlBuilder.GetCreateDatabaseCommand(dbName, passowrd));
                var commandText = "GRANT DBA TO " + dbName;
                Execute(conn, transaction, commandText);
            }
            catch (Exception)
            {
                transaction.Rollback();
                throw;
            }
            finally
            {
                conManager.ReleaseConnection(this);
            }

            var str = string.Format("Data Source={0};User ID={1};Password={2}", conn.DataSource, dbName, passowrd);
            var oracleConnection = new OracleConnection(str);

            oracleConnection.Open();
            var oracleTransaction = oracleConnection.BeginTransaction();

            //var OracleSqlBuilder = new OracleSqlBuilder(this);
            try
            {
                MetaModel model = services.Model;
                foreach (MetaTable table in model.GetTables())
                {
                    var commands = OracleSqlBuilder.GetCreateTableCommands(table);
                    foreach (var command in commands)
                    {
                        Execute(oracleConnection, oracleTransaction, command);
                    }
                }

                foreach (MetaTable table in model.GetTables())
                {
                    foreach (string commandText in OracleSqlBuilder.GetCreateForeignKeyCommands(table))
                    {
                        if (!string.IsNullOrEmpty(commandText))
                        {
                            Execute(oracleConnection, oracleTransaction, commandText);
                        }
                    }
                }

                oracleTransaction.Commit();
            }
            catch
            {
                oracleTransaction.Rollback();
                throw;
            }
            finally
            {
                conManager.ReleaseConnection(this);
            }
        }