Package org.apache.cayenne.dba.sqlserver

## Class SQLServerPkGenerator

- java.lang.Object
- - org.apache.cayenne.dba.JdbcPkGenerator
  - - org.apache.cayenne.dba.oracle.OraclePkGenerator
    - - org.apache.cayenne.dba.sqlserver.SQLServerPkGenerator

- All Implemented Interfaces:
    `PkGenerator`

      public class SQLServerPkGenerator
      extends OraclePkGenerator

  The default PK generator for MS SQL, which uses sequences to generate a PK for an integer key type and NEWID() for UNIQUEIDENTIFIER key type
  Since:
    4.1

- - ### Field Summary

    - ### Fields inherited from class org.apache.cayenne.dba.JdbcPkGenerator

      `adapter, DEFAULT_PK_CACHE_SIZE, pkCache, pkCacheSize, pkStartValue`

  - ### Constructor Summary

    Constructors
    Modifier | Constructor | Description
    --- | --- | ---
    `` | `SQLServerPkGenerator()` |
    `protected` | `SQLServerPkGenerator​(JdbcAdapter adapter)` |

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `List<String>` | `createAutoPkStatements​(List<DbEntity> dbEntities)` | Creates a list of CREATE SEQUENCE statements for the list of DbEntities.
    `protected String` | `createSequenceString​(DbEntity ent)` |
    `List<String>` | `dropAutoPkStatements​(List<DbEntity> dbEntities)` | Creates a list of DROP SEQUENCE statements for the list of DbEntities.
    `Object` | `generatePk​(DataNode node, DbAttribute pk)` | Generates a unique and non-repeating primary key for specified dbEntity.
    `protected String` | `getSequencePrefix()` |
    `protected String` | `guidPkFromDatabase​(DataNode node, DbEntity entity)` |
    `protected String` | `selectAllSequencesQuery()` |
    `protected String` | `selectNextValQuery​(String sequenceName)` |
    `protected String` | `sequenceName​(DbEntity entity)` | Returns expected primary key sequence name for a DbEntity.

    - ### Methods inherited from class org.apache.cayenne.dba.oracle.OraclePkGenerator

      `createAutoPk, dropAutoPk, dropSequenceString, getExistingSequences, longPkFromDatabase, pkCacheSize`

    - ### Methods inherited from class org.apache.cayenne.dba.JdbcPkGenerator

      `autoPkTableExists, dropAutoPkString, getAdapter, getPkCacheSize, pkCreateString, pkDeleteString, pkSelectString, pkTableCreateString, pkUpdateString, reset, runUpdate, setAdapter, setPkCacheSize`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### SQLServerPkGenerator

          public SQLServerPkGenerator()

    - #### SQLServerPkGenerator

          protected SQLServerPkGenerator​(JdbcAdapter adapter)

  - ### Method Detail

    - #### createSequenceString

          protected String createSequenceString​(DbEntity ent)

      Overrides:
        `createSequenceString` in class `OraclePkGenerator`

    - #### getSequencePrefix

          protected String getSequencePrefix()

      Overrides:
        `getSequencePrefix` in class `OraclePkGenerator`

    - #### selectNextValQuery

          protected String selectNextValQuery​(String sequenceName)

      Overrides:
        `selectNextValQuery` in class `OraclePkGenerator`

    - #### createAutoPkStatements

          public List<String> createAutoPkStatements​(List<DbEntity> dbEntities)

      Description copied from class: `OraclePkGenerator`
      Creates a list of CREATE SEQUENCE statements for the list of DbEntities.
      Specified by:
        `createAutoPkStatements` in interface `PkGenerator`
      Overrides:
        `createAutoPkStatements` in class `OraclePkGenerator`

    - #### dropAutoPkStatements

          public List<String> dropAutoPkStatements​(List<DbEntity> dbEntities)

      Description copied from class: `OraclePkGenerator`
      Creates a list of DROP SEQUENCE statements for the list of DbEntities.
      Specified by:
        `dropAutoPkStatements` in interface `PkGenerator`
      Overrides:
        `dropAutoPkStatements` in class `OraclePkGenerator`

    - #### generatePk

          public Object generatePk​(DataNode node,
                                   DbAttribute pk)
                            throws Exception

      Description copied from class: `JdbcPkGenerator`
      Generates a unique and non-repeating primary key for specified dbEntity.

      This implementation is naive since it does not lock the database rows when executing select and subsequent update. Adapter-specific implementations are more robust.

      Specified by:
        `generatePk` in interface `PkGenerator`
      Overrides:
        `generatePk` in class `JdbcPkGenerator`
      Throws:
        `Exception`

    - #### selectAllSequencesQuery

          protected String selectAllSequencesQuery()

      Overrides:
        `selectAllSequencesQuery` in class `OraclePkGenerator`

    - #### sequenceName

          protected String sequenceName​(DbEntity entity)

      Description copied from class: `OraclePkGenerator`
      Returns expected primary key sequence name for a DbEntity.
      Overrides:
        `sequenceName` in class `OraclePkGenerator`

    - #### guidPkFromDatabase

          protected String guidPkFromDatabase​(DataNode node,
                                              DbEntity entity)
                                       throws SQLException

      Throws:
        `SQLException`