slick 3.3.3, oracle 11g, scala

36 Views Asked by At

I want to use slick.jdbc.OracleProfile to support the autoincremention of primary key with oracle 11g. I use slick version 3.3.3. I've noticed that in slick.jdbc.OracleProfile there is method that creates sequence and trigger :

def createSequenceAndTrigger(t: Table[_]): Iterable[String] = if(!autoIncrement) Nil else {
  val tab = quoteIdentifier(t.tableName)
  val seq = quoteIdentifier(if(sequenceName eq null) t.tableName+"__"+column.name+"_seq" else sequenceName)
  val trg = quoteIdentifier(if(triggerName eq null) t.tableName+"__"+column.name+"_trg" else triggerName)
  val col = quoteIdentifier(column.name)
  Seq(
    s"create sequence $seq start with 1 increment by 1",
    s"create or replace trigger $trg before insert on $tab referencing new as new for each row"+
      s" when (new.$col is null) begin select $seq.nextval into :new.$col from sys.dual; end;"
  )
}

I want to use the profile to support auto increment with oracle.

0

There are 0 best solutions below