Examples of ConstraintDefinitionNode


Examples of com.foundationdb.sql.parser.ConstraintDefinitionNode

                        fkDefNodes.add(fkNode);
                    }
                } break;

                case NodeTypes.CONSTRAINT_DEFINITION_NODE: {
                    ConstraintDefinitionNode cdn = (ConstraintDefinitionNode) node;
                    if(cdn.getConstraintType() == ConstraintType.DROP) {
                        String name = cdn.getName();
                        switch(cdn.getVerifyType()) {
                            case PRIMARY_KEY:
                                if(origTable.getPrimaryKey() == null) {
                                    skipOrThrow(context, cdn.getExistenceCheck(),
                                                null,
                                                new NoSuchConstraintException(origTable.getName(), Index.PRIMARY));
                                    name = null;
                                } else {
                                    name = origTable.getPrimaryKey().getIndex().getIndexName().getName();
                                }
                            break;
                            case DROP:
                                boolean found = false;
                                String indexName = indexNameForConstrainName(origTable, name);
                                if (indexName != null) {
                                    found = true;
                                    name = indexName;
                                } else if (origTable.getReferencingForeignKey(name) != null) {
                                    fkDefNodes.add(newFKDropNode(node, name, Boolean.FALSE));
                                    found = true;
                                } else if (origTable.getParentJoin() != null && origTable.getParentJoin().getName().equals(name)) {
                                    fkDefNodes.add(newFKDropNode(node, name, Boolean.TRUE));
                                    found = true;
                                    name = null;
                                }
                                if(!found) {
                                   skipOrThrow(context,
                                               cdn.getExistenceCheck(),
                                               null,
                                               new NoSuchConstraintException(origTable.getName(), name));
                                    name = null;
                                }
                                break;
                            case UNIQUE:
                                Index index = origTable.getIndex(name);
                                if(index == null || !index.isUnique()) {
                                    skipOrThrow(context,
                                                cdn.getExistenceCheck(),
                                                null,
                                                new NoSuchUniqueException(origTable.getName(), cdn.getName()));
                                    name = null;
                                }
                            break;
                            case CHECK:
                                throw new UnsupportedCheckConstraintException();
                        }
                        if (name != null) {
                            indexChanges.add(TableChange.createDrop(name));
                        }
                    } else if (cdn.getConstraintType() == ConstraintType.PRIMARY_KEY) {
                        if (origTable.getPrimaryKeyIncludingInternal().isAkibanPK())
                        {
                            columnChanges.add(TableChange.createDrop(Column.ROW_ID_NAME));
                            String indexName = origTable.getPrimaryKeyIncludingInternal().getIndex().getIndexName().getName();
                            indexChanges.add(TableChange.createDrop(indexName));
                        }
                        conDefNodes.add(cdn);
                    } else {
                        conDefNodes.add(cdn);
                    }
                } break;

                case NodeTypes.INDEX_DEFINITION_NODE:
                    IndexDefinitionNode idn = (IndexDefinitionNode)node;
                    if(idn.getJoinType() != null) {
                        throw new UnsupportedSQLException("ALTER ADD INDEX containing group index");
                    }
                    indexDefNodes.add(idn);
                    break;
                   
                case NodeTypes.AT_DROP_INDEX_NODE: {
                    AlterDropIndexNode dropIndexNode = (AlterDropIndexNode)node;
                    String name = dropIndexNode.getIndexName();
                    if(origTable.getIndex(name) == null) {
                        skipOrThrow(context, dropIndexNode.getExistenceCheck(), null, new NoSuchIndexException(name));
                    } else {
                        indexChanges.add(TableChange.createDrop(name));
                    }
                }
                break;

                case NodeTypes.AT_RENAME_NODE:
                    TableName newName = DDLHelper.convertName(defaultSchema,
                                                              ((AlterTableRenameNode)node).newName());
                    TableName oldName = origTable.getName();
                    ddl.renameTable(session, oldName, newName);
                    return ChangeLevel.METADATA;
                   
                case NodeTypes.AT_RENAME_COLUMN_NODE:
                    AlterTableRenameColumnNode alterRenameCol = (AlterTableRenameColumnNode) node;
                    String oldColName = alterRenameCol.getName();
                    String newColName = alterRenameCol.newName();
                    final Column oldCol = origTable.getColumn(oldColName);

                    if (oldCol == null) {
                        throw new NoSuchColumnException(oldColName);
                    }
                    columnChanges.add(TableChange.createModify(oldColName, newColName));
                break;

                default:
                    return null; // Something unsupported
            }
        }
       
        for (ForeignKey foreignKey : origTable.getForeignKeys()) {
            if (foreignKey.getReferencingTable() == origTable) {
                checkForeignKeyAlterColumns(columnChanges, foreignKey.getReferencingColumns(),
                                            foreignKey, origTable);
            }
            if (foreignKey.getReferencedTable() == origTable) {
                checkForeignKeyAlterColumns(columnChanges, foreignKey.getReferencedColumns(),
                                            foreignKey, origTable);
            }
        }

        final AkibanInformationSchema origAIS = origTable.getAIS();
        final Table tableCopy = copyTable(ddl.getAISCloner(), origTable, columnChanges);
        final AkibanInformationSchema aisCopy = tableCopy.getAIS();
        TableDDL.cloneReferencedTables(defaultSchema, ddl.getAISCloner(), origAIS, aisCopy, elements);
        final TypesTranslator typesTranslator = ddl.getTypesTranslator();
        final AISBuilder builder = new AISBuilder(aisCopy);
        builder.getNameGenerator().mergeAIS(origAIS);

        int pos = tableCopy.getColumnsIncludingInternal().size();
        for(ColumnDefinitionNode cdn : columnDefNodes) {
            if(cdn instanceof ModifyColumnNode) {
                ModifyColumnNode modNode = (ModifyColumnNode) cdn;
                handleModifyColumnNode(modNode, builder, tableCopy, typesTranslator);
            } else {
                TableDDL.addColumn(builder, typesTranslator, cdn, origTable.getName().getSchemaName(), origTable.getName().getTableName(), pos++);
            }
        }
        // Ensure that internal columns stay at the end
        // because there's a bunch of places that assume that they are
        // (e.g. they assume getColumns() have indexes (1...getColumns().size()))
        // If the original table had a primary key, the hidden pk is added a bit farther down
       
        for (Column origColumn : origTable.getColumnsIncludingInternal()) {
            if (origColumn.isInternalColumn()) {
                String newName = findNewName(columnChanges, origColumn.getName());
                if (newName != null) {
                    Column.create(tableCopy, origColumn, newName, pos++);
                }
            }
        }
        copyTableIndexes(origTable, tableCopy, columnChanges, indexChanges);

        IndexNameGenerator indexNamer = DefaultIndexNameGenerator.forTable(tableCopy);
        TableName newName = tableCopy.getName();
        for(ConstraintDefinitionNode cdn : conDefNodes) {
            assert cdn.getConstraintType() != ConstraintType.DROP : cdn;
            String name = TableDDL.addIndex(indexNamer, builder, cdn, newName.getSchemaName(), newName.getTableName(), context);
            indexChanges.add(TableChange.createAdd(name));
            // This is required as the addIndex() for a primary key constraint
            // *may* alter the NULL->NOT NULL status
            // of the columns in the primary key
View Full Code Here

Examples of org.apache.derby.impl.sql.compile.ConstraintDefinitionNode

    throw new Error("Missing return statement in function");
  }

  final public TableElementNode tableConstraintDefinition() throws ParseException, StandardException {
        Properties properties = null;
        ConstraintDefinitionNode tcdn;
        TableName               constraintName = null;
        //initialize following two booleans before handling table level constraints
        explicitNotNull = false;
        explicitNull = false;
    switch (jj_nt.kind) {
    case CONSTRAINT:
      constraintName = constraintNameDefinition();
      break;
    default:
      jj_la1[266] = jj_gen;
      ;
    }
    tcdn = tableConstraint(constraintName);
    switch (jj_nt.kind) {
    case DERBYDASHPROPERTIES:
      properties = propertyList(false);
      jj_consume_token(CHECK_PROPERTIES);
      break;
    default:
      jj_la1[267] = jj_gen;
      ;
    }
                if (properties != null)
                {
                        tcdn.setProperties(properties);
                }
                {if (true) return tcdn;}
    throw new Error("Missing return statement in function");
  }
View Full Code Here

Examples of org.apache.derby.impl.sql.compile.ConstraintDefinitionNode

                {if (true) return tcdn;}
    throw new Error("Missing return statement in function");
  }

  final public ConstraintDefinitionNode tableConstraint(TableName constraintName) throws ParseException, StandardException {
        ConstraintDefinitionNode tcdn;
    switch (jj_nt.kind) {
    case PRIMARY:
    case UNIQUE:
      tcdn = uniqueConstraintDefinition(constraintName);
                {if (true) return tcdn;}
View Full Code Here

Examples of org.apache.derby.impl.sql.compile.ConstraintDefinitionNode

  final public ConstraintDefinitionNode columnConstraint(TableName constraintName,
                                 DataTypeDescriptor dataTypeDescriptor,
                                 String columnName) throws ParseException, StandardException {
        int constraintType;
        Properties properties = null;
        ConstraintDefinitionNode tcdn;
        ResultColumnList refRcl = (ResultColumnList) nodeFactory.getNode(
                                                                                C_NodeTypes.RESULT_COLUMN_LIST,
                                                                                getContextManager());
        TableName referencedTable;
        int[] refActions = {StatementType.RA_NOACTION,
                            StatementType.RA_NOACTION} ;
    switch (jj_nt.kind) {
    case NOT:
      jj_consume_token(NOT);
      jj_consume_token(NULL);
                //if column is explicitly defined not nullable, set following flag
                explicitNotNull = true;
                //if both null and not null constraints are defined for a column,
                //throw an exception
                if (explicitNull)
                   {if (true) throw StandardException.newException(SQLState.LANG_ADDING_COLUMN_WITH_NULL_AND_NOT_NULL_CONSTRAINT, columnName);}
                dataTypeDescriptor.setNullability(false);
                {if (true) return null;}
      break;
    case PRIMARY:
    case UNIQUE:
      //pass the columnname as the second parameter. It will be used to throw an
              //exception if null constraint is defined for this column-level primary
              //key constraint
              constraintType = uniqueSpecification(dataTypeDescriptor,columnName);
      switch (jj_nt.kind) {
      case DERBYDASHPROPERTIES:
        properties = propertyList(false);
        jj_consume_token(CHECK_PROPERTIES);
        break;
      default:
        jj_la1[279] = jj_gen;
        ;
      }
                ResultColumnList uniqueColumnList =
                                                                                (ResultColumnList) nodeFactory.getNode(
                                                                                                C_NodeTypes.RESULT_COLUMN_LIST,
                                                                                                getContextManager());
                uniqueColumnList.addElement(
                        (ResultColumn) nodeFactory.getNode(
                                                        C_NodeTypes.RESULT_COLUMN,
                                                        columnName,
                                                        null,
                                                        getContextManager()));

                {if (true) return (ConstraintDefinitionNode) nodeFactory.getNode(
                                                C_NodeTypes.CONSTRAINT_DEFINITION_NODE,
                                                constraintName,
                                                ReuseFactory.getInteger(constraintType),
                                                uniqueColumnList,
                                                properties,
                                                null,
                                                null,
                                                getContextManager()
                                                );}
      break;
    case REFERENCES:
      referencedTable = referencesSpecification(refRcl, refActions);
      switch (jj_nt.kind) {
      case DERBYDASHPROPERTIES:
        properties = propertyList(false);
        jj_consume_token(CHECK_PROPERTIES);
        break;
      default:
        jj_la1[280] = jj_gen;
        ;
      }
                ResultColumnList fkRcl = (ResultColumnList) nodeFactory.getNode(
                                                                                        C_NodeTypes.RESULT_COLUMN_LIST,
                                                                                        getContextManager());
                fkRcl.addElement(
                                        (ResultColumn) nodeFactory.getNode(
                                                                        C_NodeTypes.RESULT_COLUMN,
                                                                        columnName,
                                                                        null,
                                                                        getContextManager())
                                );
                tcdn = (ConstraintDefinitionNode) nodeFactory.getNode(
                                                C_NodeTypes.FK_CONSTRAINT_DEFINITION_NODE,
                                                constraintName,
                                                referencedTable,
                                                fkRcl,
                                                refRcl,
                                                refActions,
                                                getContextManager());
                if (properties != null)
                {
                        tcdn.setProperties(properties);
                }
                {if (true) return tcdn;}
      break;
    case CHECK:
      tcdn = checkConstraintDefinition(constraintName, columnName);
View Full Code Here

Examples of org.apache.derby.impl.sql.compile.ConstraintDefinitionNode

    throw new Error("Missing return statement in function");
  }

  final public TableElementNode tableConstraintDefinition() throws ParseException, StandardException {
        Properties properties = null;
        ConstraintDefinitionNode tcdn;
        TableName               constraintName = null;
        //initialize following two booleans before handling table level constraints
        explicitNotNull = false;
        explicitNull = false;
    switch (jj_nt.kind) {
    case CONSTRAINT:
      constraintName = constraintNameDefinition();
      break;
    default:
      jj_la1[266] = jj_gen;
      ;
    }
    tcdn = tableConstraint(constraintName);
    switch (jj_nt.kind) {
    case DERBYDASHPROPERTIES:
      properties = propertyList(false);
      jj_consume_token(CHECK_PROPERTIES);
      break;
    default:
      jj_la1[267] = jj_gen;
      ;
    }
                if (properties != null)
                {
                        tcdn.setProperties(properties);
                }
                {if (true) return tcdn;}
    throw new Error("Missing return statement in function");
  }
View Full Code Here

Examples of org.apache.derby.impl.sql.compile.ConstraintDefinitionNode

                {if (true) return tcdn;}
    throw new Error("Missing return statement in function");
  }

  final public ConstraintDefinitionNode tableConstraint(TableName constraintName) throws ParseException, StandardException {
        ConstraintDefinitionNode tcdn;
    switch (jj_nt.kind) {
    case PRIMARY:
    case UNIQUE:
      tcdn = uniqueConstraintDefinition(constraintName);
                {if (true) return tcdn;}
View Full Code Here

Examples of org.apache.derby.impl.sql.compile.ConstraintDefinitionNode

  final public ConstraintDefinitionNode columnConstraint(TableName constraintName,
                                 DataTypeDescriptor dataTypeDescriptor,
                                 String columnName) throws ParseException, StandardException {
        int constraintType;
        Properties properties = null;
        ConstraintDefinitionNode tcdn;
        ResultColumnList refRcl = (ResultColumnList) nodeFactory.getNode(
                                                                                C_NodeTypes.RESULT_COLUMN_LIST,
                                                                                getContextManager());
        TableName referencedTable;
        int[] refActions = {StatementType.RA_NOACTION,
                            StatementType.RA_NOACTION} ;
    switch (jj_nt.kind) {
    case NOT:
      jj_consume_token(NOT);
      jj_consume_token(NULL);
                //if column is explicitly defined not nullable, set following flag
                explicitNotNull = true;
                //if both null and not null constraints are defined for a column,
                //throw an exception
                if (explicitNull)
                   {if (true) throw StandardException.newException(SQLState.LANG_ADDING_COLUMN_WITH_NULL_AND_NOT_NULL_CONSTRAINT, columnName);}
                dataTypeDescriptor.setNullability(false);
                {if (true) return null;}
      break;
    case PRIMARY:
    case UNIQUE:
      //pass the columnname as the second parameter. It will be used to throw an
              //exception if null constraint is defined for this column-level primary
              //key constraint
              constraintType = uniqueSpecification(dataTypeDescriptor,columnName);
      switch (jj_nt.kind) {
      case DERBYDASHPROPERTIES:
        properties = propertyList(false);
        jj_consume_token(CHECK_PROPERTIES);
        break;
      default:
        jj_la1[279] = jj_gen;
        ;
      }
                ResultColumnList uniqueColumnList =
                                                                                (ResultColumnList) nodeFactory.getNode(
                                                                                                C_NodeTypes.RESULT_COLUMN_LIST,
                                                                                                getContextManager());
                uniqueColumnList.addElement(
                        (ResultColumn) nodeFactory.getNode(
                                                        C_NodeTypes.RESULT_COLUMN,
                                                        columnName,
                                                        null,
                                                        getContextManager()));

                {if (true) return (ConstraintDefinitionNode) nodeFactory.getNode(
                                                C_NodeTypes.CONSTRAINT_DEFINITION_NODE,
                                                constraintName,
                                                ReuseFactory.getInteger(constraintType),
                                                uniqueColumnList,
                                                properties,
                                                null,
                                                null,
                                                getContextManager()
                                                );}
      break;
    case REFERENCES:
      referencedTable = referencesSpecification(refRcl, refActions);
      switch (jj_nt.kind) {
      case DERBYDASHPROPERTIES:
        properties = propertyList(false);
        jj_consume_token(CHECK_PROPERTIES);
        break;
      default:
        jj_la1[280] = jj_gen;
        ;
      }
                ResultColumnList fkRcl = (ResultColumnList) nodeFactory.getNode(
                                                                                        C_NodeTypes.RESULT_COLUMN_LIST,
                                                                                        getContextManager());
                fkRcl.addElement(
                                        (ResultColumn) nodeFactory.getNode(
                                                                        C_NodeTypes.RESULT_COLUMN,
                                                                        columnName,
                                                                        null,
                                                                        getContextManager())
                                );
                tcdn = (ConstraintDefinitionNode) nodeFactory.getNode(
                                                C_NodeTypes.FK_CONSTRAINT_DEFINITION_NODE,
                                                constraintName,
                                                referencedTable,
                                                fkRcl,
                                                refRcl,
                                                refActions,
                                                getContextManager());
                if (properties != null)
                {
                        tcdn.setProperties(properties);
                }
                {if (true) return tcdn;}
      break;
    case CHECK:
      tcdn = checkConstraintDefinition(constraintName, columnName);
View Full Code Here

Examples of org.apache.derby.impl.sql.compile.ConstraintDefinitionNode

    throw new Error("Missing return statement in function");
  }

  final public TableElementNode tableConstraintDefinition() throws ParseException, StandardException {
        Properties properties = null;
        ConstraintDefinitionNode tcdn;
        TableName               constraintName = null;
        //initialize following two booleans before handling table level constraints
        explicitNotNull = false;
        explicitNull = false;
    switch (jj_nt.kind) {
    case CONSTRAINT:
      constraintName = constraintNameDefinition();
      break;
    default:
      jj_la1[300] = jj_gen;
      ;
    }
    tcdn = tableConstraint(constraintName);
    switch (jj_nt.kind) {
    case DERBYDASHPROPERTIES:
      properties = propertyList(false);
      jj_consume_token(CHECK_PROPERTIES);
      break;
    default:
      jj_la1[301] = jj_gen;
      ;
    }
                if (properties != null)
                {
                        tcdn.setProperties(properties);
                }
                {if (true) return tcdn;}
    throw new Error("Missing return statement in function");
  }
View Full Code Here

Examples of org.apache.derby.impl.sql.compile.ConstraintDefinitionNode

                {if (true) return tcdn;}
    throw new Error("Missing return statement in function");
  }

  final public ConstraintDefinitionNode tableConstraint(TableName constraintName) throws ParseException, StandardException {
        ConstraintDefinitionNode tcdn;
    switch (jj_nt.kind) {
    case PRIMARY:
    case UNIQUE:
      tcdn = uniqueConstraintDefinition(constraintName);
                {if (true) return tcdn;}
View Full Code Here

Examples of org.apache.derby.impl.sql.compile.ConstraintDefinitionNode

  final public ConstraintDefinitionNode columnConstraint(TableName constraintName,
                                 DataTypeDescriptor[] dataTypeDescriptor,
                                 String columnName) throws ParseException, StandardException {
        int constraintType;
        Properties properties = null;
        ConstraintDefinitionNode tcdn;
        ResultColumnList refRcl = (ResultColumnList) nodeFactory.getNode(
                                                                                C_NodeTypes.RESULT_COLUMN_LIST,
                                                                                getContextManager());
        TableName referencedTable;
        int[] refActions = {StatementType.RA_NOACTION,
                            StatementType.RA_NOACTION} ;
    switch (jj_nt.kind) {
    case NOT:
      jj_consume_token(NOT);
      jj_consume_token(NULL);
                //if column is explicitly defined not nullable, set following flag
                explicitNotNull = true;
                //if both null and not null constraints are defined for a column,
                //throw an exception
                if (explicitNull)
                   {if (true) throw StandardException.newException(SQLState.LANG_ADDING_COLUMN_WITH_NULL_AND_NOT_NULL_CONSTRAINT, columnName);}

                // columns with generation clauses can omit the datatype
                if ( dataTypeDescriptor[0] == null ) { {if (true) throw StandardException.newException(SQLState.LANG_NOT_NULL_NEEDS_DATATYPE);} }

                dataTypeDescriptor[0] = dataTypeDescriptor[0].getNullabilityType(false);
                {if (true) return null;}
      break;
    case PRIMARY:
    case UNIQUE:
      //pass the columnname as the second parameter. It will be used to throw an
              //exception if null constraint is defined for this column-level primary
              //key constraint
              constraintType = uniqueSpecification(columnName);
      switch (jj_nt.kind) {
      case DERBYDASHPROPERTIES:
        properties = propertyList(false);
        jj_consume_token(CHECK_PROPERTIES);
        break;
      default:
        jj_la1[313] = jj_gen;
        ;
      }
                ResultColumnList uniqueColumnList =
                                                                                (ResultColumnList) nodeFactory.getNode(
                                                                                                C_NodeTypes.RESULT_COLUMN_LIST,
                                                                                                getContextManager());
                uniqueColumnList.addElement(
                        (ResultColumn) nodeFactory.getNode(
                                                        C_NodeTypes.RESULT_COLUMN,
                                                        columnName,
                                                        null,
                                                        getContextManager()));

                {if (true) return (ConstraintDefinitionNode) nodeFactory.getNode(
                                                C_NodeTypes.CONSTRAINT_DEFINITION_NODE,
                                                constraintName,
                                                ReuseFactory.getInteger(constraintType),
                                                uniqueColumnList,
                                                properties,
                                                null,
                                                null,
                                                getContextManager()
                                                );}
      break;
    case REFERENCES:
      referencedTable = referencesSpecification(refRcl, refActions);
      switch (jj_nt.kind) {
      case DERBYDASHPROPERTIES:
        properties = propertyList(false);
        jj_consume_token(CHECK_PROPERTIES);
        break;
      default:
        jj_la1[314] = jj_gen;
        ;
      }
                ResultColumnList fkRcl = (ResultColumnList) nodeFactory.getNode(
                                                                                        C_NodeTypes.RESULT_COLUMN_LIST,
                                                                                        getContextManager());
                fkRcl.addElement(
                                        (ResultColumn) nodeFactory.getNode(
                                                                        C_NodeTypes.RESULT_COLUMN,
                                                                        columnName,
                                                                        null,
                                                                        getContextManager())
                                );
                tcdn = (ConstraintDefinitionNode) nodeFactory.getNode(
                                                C_NodeTypes.FK_CONSTRAINT_DEFINITION_NODE,
                                                constraintName,
                                                referencedTable,
                                                fkRcl,
                                                refRcl,
                                                refActions,
                                                getContextManager());
                if (properties != null)
                {
                        tcdn.setProperties(properties);
                }
                {if (true) return tcdn;}
      break;
    case CHECK:
      tcdn = checkConstraintDefinition(constraintName, columnName);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.