@Test public void testParseCreateTablePrimaryKeyConstraintWithOrder() throws Exception { for (String order : new String[]{"asc", "desc"}) { String s = "create table core.entity_history_archive (id CHAR(15), name VARCHAR(150), constraint pk primary key (id ${o}, name ${o}))".replace("${o}", order); CreateTableStatement stmt = (CreateTableStatement)new SQLParser((s)).parseStatement(); PrimaryKeyConstraint pkConstraint = stmt.getPrimaryKeyConstraint(); List<Pair<ColumnName,SortOrder>> columns = pkConstraint.getColumnNames(); assertEquals(2, columns.size()); for (Pair<ColumnName,SortOrder> pair : columns) { assertEquals(SortOrder.fromDDLValue(order), pkConstraint.getColumnWithSortOrder(pair.getFirst()).getSecond()); } } }
public PrimaryKeyConstraint primaryKey(String name, List<ColumnDefInPkConstraint> columnDefs) { return new PrimaryKeyConstraint(name, columnDefs); }
private static boolean isPkColumn(PrimaryKeyConstraint pkConstraint, ColumnDef colDef) { return colDef.isPK() || (pkConstraint != null && pkConstraint.contains(colDef.getColumnDefName())); }
boolean isRowTimestamp = def.isRowTimestamp(); if (pkConstraint != null) { Pair<ColumnName, SortOrder> pkSortOrder = pkConstraint.getColumnWithSortOrder(columnDefName); if (pkSortOrder != null) { isPK = true; sortOrder = pkSortOrder.getSecond(); isRowTimestamp = pkConstraint.isColumnRowTimestamp(columnDefName); if (def.isPK() && !pkConstraint.getColumnNames().isEmpty() ) { throw new SQLExceptionInfo.Builder(SQLExceptionCode.PRIMARY_KEY_ALREADY_EXISTS) .setColumnName(columnName).build().buildException(); if (isPK && !addingToPK && pkConstraint.getColumnNames().size() <= 1) { if (def.isNull() && def.isNullSet()) { throw new SQLExceptionInfo.Builder(SQLExceptionCode.SINGLE_PK_MAY_NOT_BE_NULL)
Iterator<Pair<ColumnName,SortOrder>> pkColumnsIterator = Collections.emptyIterator(); if (pkConstraint != null) { pkColumnsNames = pkConstraint.getColumnNames(); pkColumnsIterator = pkColumnsNames.iterator(); pkName = pkConstraint.getName(); if (pkConstraint.getNumColumnsWithRowTimestamp() > 0 && transactionProvider != null) { throw new SQLExceptionInfo.Builder(SQLExceptionCode.CANNOT_CREATE_TXN_TABLE_WITH_ROW_TIMESTAMP) .setSchemaName(schemaName).setTableName(tableName)
if (tableType == VIEW && (pkConstraint.getNumColumnsWithRowTimestamp() > 0 || colDef.isRowTimestamp())) { throw new SQLExceptionInfo.Builder(SQLExceptionCode.ROWTIMESTAMP_NOT_ALLOWED_ON_VIEW) .setColumnName(columnDefName.getColumnName()).build().buildException(); boolean isColumnDeclaredRowTimestamp = colDef.isRowTimestamp() || pkConstraint.isColumnRowTimestamp(columnDefName); if (isColumnDeclaredRowTimestamp) { boolean isColumnPartOfPk = colDef.isPK() || pkConstraint.contains(columnDefName);
.buildException(); if (this.isRowTimestamp() || ( pkConstraint != null && pkConstraint.isColumnRowTimestamp(this.getColumnDefName()))) { throw new SQLExceptionInfo.Builder( SQLExceptionCode.CANNOT_CREATE_DEFAULT_ROWTIMESTAMP)
boolean isRowTimestamp = def.isRowTimestamp(); if (pkConstraint != null) { Pair<ColumnName, SortOrder> pkSortOrder = pkConstraint.getColumnWithSortOrder(columnDefName); if (pkSortOrder != null) { isPK = true; sortOrder = pkSortOrder.getSecond(); isRowTimestamp = pkConstraint.isColumnRowTimestamp(columnDefName); if (def.isPK() && !pkConstraint.getColumnNames().isEmpty() ) { throw new SQLExceptionInfo.Builder(SQLExceptionCode.PRIMARY_KEY_ALREADY_EXISTS) .setColumnName(columnName).build().buildException(); if (isPK && !addingToPK && pkConstraint.getColumnNames().size() <= 1) { if (def.isNull() && def.isNullSet()) { throw new SQLExceptionInfo.Builder(SQLExceptionCode.SINGLE_PK_MAY_NOT_BE_NULL)
Iterator<Pair<ColumnName,SortOrder>> pkColumnsIterator = Collections.emptyIterator(); if (pkConstraint != null) { pkColumnsNames = pkConstraint.getColumnNames(); pkColumnsIterator = pkColumnsNames.iterator(); pkName = pkConstraint.getName(); if (pkConstraint.getNumColumnsWithRowTimestamp() > 0 && transactionProvider != null) { throw new SQLExceptionInfo.Builder(SQLExceptionCode.CANNOT_CREATE_TXN_TABLE_WITH_ROW_TIMESTAMP) .setSchemaName(schemaName).setTableName(tableName)
if (tableType == VIEW && (pkConstraint.getNumColumnsWithRowTimestamp() > 0 || colDef.isRowTimestamp())) { throw new SQLExceptionInfo.Builder(SQLExceptionCode.ROWTIMESTAMP_NOT_ALLOWED_ON_VIEW) .setColumnName(columnDefName.getColumnName()).build().buildException(); boolean isColumnDeclaredRowTimestamp = colDef.isRowTimestamp() || pkConstraint.isColumnRowTimestamp(columnDefName); if (isColumnDeclaredRowTimestamp) { boolean isColumnPartOfPk = colDef.isPK() || pkConstraint.contains(columnDefName);
.buildException(); if (this.isRowTimestamp() || ( pkConstraint != null && pkConstraint.isColumnRowTimestamp(this.getColumnDefName()))) { throw new SQLExceptionInfo.Builder( SQLExceptionCode.CANNOT_CREATE_DEFAULT_ROWTIMESTAMP)
boolean isRowTimestamp = def.isRowTimestamp(); if (pkConstraint != null) { Pair<ColumnName, SortOrder> pkSortOrder = pkConstraint.getColumnWithSortOrder(columnDefName); if (pkSortOrder != null) { isPK = true; sortOrder = pkSortOrder.getSecond(); isRowTimestamp = pkConstraint.isColumnRowTimestamp(columnDefName); if (def.isPK() && !pkConstraint.getColumnNames().isEmpty() ) { throw new SQLExceptionInfo.Builder(SQLExceptionCode.PRIMARY_KEY_ALREADY_EXISTS) .setColumnName(columnName).build().buildException(); if (isPK && !addingToPK && pkConstraint.getColumnNames().size() <= 1) { if (def.isNull() && def.isNullSet()) { throw new SQLExceptionInfo.Builder(SQLExceptionCode.SINGLE_PK_MAY_NOT_BE_NULL)
Iterator<Pair<ColumnName,SortOrder>> pkColumnsIterator = Collections.emptyIterator(); if (pkConstraint != null) { pkColumnsNames = pkConstraint.getColumnNames(); pkColumnsIterator = pkColumnsNames.iterator(); pkName = pkConstraint.getName(); if (pkConstraint.getNumColumnsWithRowTimestamp() > 0 && transactionProvider != null) { throw new SQLExceptionInfo.Builder(SQLExceptionCode.CANNOT_CREATE_TXN_TABLE_WITH_ROW_TIMESTAMP) .setSchemaName(schemaName).setTableName(tableName)
if (tableType == VIEW && (pkConstraint.getNumColumnsWithRowTimestamp() > 0 || colDef.isRowTimestamp())) { throw new SQLExceptionInfo.Builder(SQLExceptionCode.ROWTIMESTAMP_NOT_ALLOWED_ON_VIEW) .setColumnName(columnDefName.getColumnName()).build().buildException(); boolean isColumnDeclaredRowTimestamp = colDef.isRowTimestamp() || pkConstraint.isColumnRowTimestamp(columnDefName); if (isColumnDeclaredRowTimestamp) { boolean isColumnPartOfPk = colDef.isPK() || pkConstraint.contains(columnDefName);
private static boolean isPkColumn(PrimaryKeyConstraint pkConstraint, ColumnDef colDef) { return colDef.isPK() || (pkConstraint != null && pkConstraint.contains(colDef.getColumnDefName())); }
public PrimaryKeyConstraint primaryKey(String name, List<ColumnDefInPkConstraint> columnDefs) { return new PrimaryKeyConstraint(name, columnDefs); }
.buildException(); if (this.isRowTimestamp() || ( pkConstraint != null && pkConstraint.isColumnRowTimestamp(this.getColumnDefName()))) { throw new SQLExceptionInfo.Builder( SQLExceptionCode.CANNOT_CREATE_DEFAULT_ROWTIMESTAMP)
private static boolean isPkColumn(PrimaryKeyConstraint pkConstraint, ColumnDef colDef) { return colDef.isPK() || (pkConstraint != null && pkConstraint.contains(colDef.getColumnDefName())); }
public PrimaryKeyConstraint primaryKey(String name, List<ColumnDefInPkConstraint> columnDefs) { return new PrimaryKeyConstraint(name, columnDefs); }
if (pkConstraint.contains(columnDef.getColumnDefName())) { columnDef.setIsPK(true);