~akiban-technologies/akiban-server/trunk

« back to all changes in this revision

Viewing changes to src/main/java/com/akiban/server/service/dxl/BasicDDLFunctions.java

merge nwilliams: Change SERIAL back to BY DEFAULT, fix div by zero on maximum range cycling sequence and underlying support for ALTER SEQUENCE.

https://code.launchpad.net/~nwilliams/akiban-server/sequence-fix-and-tweak/+merge/177031

Show diffs side-by-side

added added

removed removed

Lines of Context:
733
733
    }
734
734
 
735
735
    @Override
 
736
    public void alterSequence(Session session, TableName sequenceName, Sequence newDefinition)
 
737
    {
 
738
        logger.trace("altering sequence {}", sequenceName);
 
739
 
 
740
        // Lock the table, if any, that this sequence is an identity generator for
 
741
        // Note: If/when we have expression DEFAULT values, they will need checked too.
 
742
        List<Integer> tableIDs = new ArrayList<>();
 
743
        txnService.beginTransaction(session);
 
744
        try {
 
745
            AkibanInformationSchema ais = getAIS(session);
 
746
            Sequence s = ais.getSequence(sequenceName);
 
747
            if(s != null) {
 
748
                for(UserTable table : ais.getUserTables().values()) {
 
749
                    for(Column column : table.getColumnsIncludingInternal()) {
 
750
                        if(column.getIdentityGenerator() == s) {
 
751
                            tableIDs.add(table.getTableId());
 
752
                        }
 
753
                    }
 
754
                }
 
755
            }
 
756
            // else: throw below
 
757
            txnService.commitTransaction(session);
 
758
        } finally {
 
759
            txnService.rollbackTransactionIfOpen(session);
 
760
        }
 
761
 
 
762
        lockTables(session, tableIDs);
 
763
        txnService.beginTransaction(session);
 
764
        try {
 
765
            AkibanInformationSchema ais = getAIS(session);
 
766
            Sequence oldSeq = ais.getSequence(sequenceName);
 
767
            if(oldSeq == null) {
 
768
                throw new NoSuchSequenceException(sequenceName);
 
769
            }
 
770
            schemaManager().alterSequence(session, sequenceName, newDefinition);
 
771
 
 
772
            // Remove old tree
 
773
            store().deleteSequences(session, Collections.singleton(oldSeq));
 
774
 
 
775
            txnService.commitTransaction(session);
 
776
        } finally {
 
777
            txnService.rollbackTransactionIfOpen(session);
 
778
        }
 
779
    }
 
780
 
 
781
    @Override
736
782
    public void dropSchema(Session session, String schemaName)
737
783
    {
738
784
        logger.trace("dropping schema {}", schemaName);