Example #1
0
        public void AddSequence(DbSequenceInfo sequence)
        {
            var oldSeq = _sequences.FirstOrDefault(s => s.FullName == sequence.FullName);

            Util.Check(oldSeq == null, "Duplicate sequence in DbModel: {0}", sequence.FullName);
            _sequences.Add(sequence);
        }
Example #2
0
 private void BuildSequences()
 {
     if (!_driver.Supports(DbFeatures.Sequences))
     {
         return;
     }
     foreach (var m in _entityModel.App.Modules)
     {
         foreach (var seq in m.Sequences)
         {
             var dbSeqInfo = new DbSequenceInfo(this._dbModel, seq);
             _dbModel.Sequences.Add(dbSeqInfo);
         }
     }
 }//method
Example #3
0
 public virtual DbCommandInfo BuildSqlSequenceGetNextCommand(DbSequenceInfo sequence)
 {
     return null;
 }
Example #4
0
 public override DbCommandInfo BuildSqlSequenceGetNextCommand(DbSequenceInfo sequence)
 {
     const string SqlTemplate = "SELECT NEXT VALUE FOR {0};";
       //Load by primary key
       var cmdName = sequence.Name + "_GetNextValue";
       var cmdInfo = new DbCommandInfo(DbModel, sequence.Schema, cmdName, null, null);
       cmdInfo.Sql = string.Format(SqlTemplate, sequence.FullName);
       cmdInfo.ExecutionType = DbExecutionType.Scalar;
       return cmdInfo;
 }
Example #5
0
 public override void BuildSequenceDropSql(DbObjectChange change, DbSequenceInfo sequence)
 {
     // PG creates sequences for identity columns, these should not be dropped explicitly; we do sequence drop after table drop, so we add check for existense
       change.AddScript(DbScriptType.SequenceDrop, "DROP SEQUENCE IF EXISTS {0}", sequence.FullName);
 }
Example #6
0
 public override void BuildSequenceAddSql(DbObjectChange change, DbSequenceInfo sequence)
 {
     var start = (sequence.StartValue < 1) ? 1 : sequence.StartValue;
       const string sqlTemplate = "CREATE Sequence {0} START WITH {1} INCREMENT BY {2};";
       change.AddScript(DbScriptType.SequenceAdd, sqlTemplate, sequence.FullName,  start, sequence.Increment);
 }
Example #7
0
 private void BuildSequences()
 {
     if (!_driver.Supports(DbFeatures.Sequences))
     return;
       foreach(var m in _entityModel.App.Modules)
     foreach (var seq in m.Sequences) {
       var dbSeqInfo = new DbSequenceInfo(this._dbModel, seq);
       dbSeqInfo.GetNextValueCommand = _dbSqlBuilder.BuildSqlSequenceGetNextCommand(dbSeqInfo);
       _dbModel.Sequences.Add(dbSeqInfo);
     }
 }
Example #8
0
 public void AddSequence(DbSequenceInfo sequence)
 {
     Util.Check(!_dbObjectsByName.ContainsKey(sequence.FullName), "Duplicate sequence in DbModel: {0}", sequence.FullName);
     _sequences.Add(sequence);
     _dbObjectsByName[sequence.FullName] = sequence;
 }
Example #9
0
 public virtual void BuildSequenceDropSql(DbObjectChange change, DbSequenceInfo sequence)
 {
     change.AddScript(DbScriptType.SequenceDrop, "DROP SEQUENCE {0}", sequence.FullName);
 }
Example #10
0
 public virtual void BuildSequenceAddSql(DbObjectChange change, DbSequenceInfo sequence)
 {
 }
Example #11
0
 public override void BuildSequenceAddSql(DbObjectChange change, DbSequenceInfo sequence)
 {
     const string sqlCreateTemplate = "CREATE Sequence {0} AS {1} START WITH {2} INCREMENT BY {3};";
       const string sqlGrantTemplate = "Grant  UPDATE on {0} to {1};";
       change.AddScript(DbScriptType.SequenceAdd, sqlCreateTemplate, sequence.FullName, sequence.DbType.SqlTypeSpec,
       sequence.StartValue, sequence.Increment);
       //Grant permission to UPDATE
       var updateRole = this.Settings.GrantExecWriteToRole;
       if (!string.IsNullOrWhiteSpace(updateRole))
     change.AddScript(DbScriptType.Grant, sqlGrantTemplate, sequence.FullName, updateRole);
 }
Example #12
0
 public override DbCommandInfo BuildSqlSequenceGetNextCommand(DbSequenceInfo sequence)
 {
     const string SqlTemplate = "SELECT nextval('{0}.\"{1}\"');"; //note sequence name in double quotes inside single-quote argument
       //Load by primary key
       var cmdName = sequence.Name + "_GetNextValue";
       var cmdInfo = new DbCommandInfo(DbModel, sequence.Schema, cmdName, null, null);
       cmdInfo.Sql = string.Format(SqlTemplate, sequence.Schema, sequence.Name);
       cmdInfo.ExecutionType = DbExecutionType.Scalar;
       return cmdInfo;
 }
Example #13
0
 protected virtual void LoadSequences()
 {
     if (!Settings.Driver.Supports(DbFeatures.Sequences))
     return;
       var data = GetSequences();
       foreach(DataRow row in data.Rows) {
     var schema = row.GetAsString("SEQUENCE_SCHEMA");
     var name = row.GetAsString("SEQUENCE_NAME");
     var dataType = row.GetAsString("DATA_TYPE");
     var startValue = row.GetAsLong("START_VALUE");
     var incr = row.GetAsInt("INCREMENT");
     //find type def
     var typeDef = Driver.TypeRegistry.FindVendorDbTypeInfo(dataType);
     var typeSpec = typeDef.FormatTypeSpec(0, 0, 0);
     var typeInfo = new DbTypeInfo(typeDef, dataType, false, 0, 0, 0, typeDef.DefaultColumnInit);
     // add sequence
     var seq = new DbSequenceInfo(this.Model, name, schema, typeInfo, startValue, incr);
     Model.AddSequence(seq);
       }
 }