View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *     http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  package org.apache.shardingsphere.sql.parser.sql.common.statement.ddl;
19  
20  import lombok.Getter;
21  import lombok.Setter;
22  import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.column.alter.AddColumnDefinitionSegment;
23  import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.column.alter.ChangeColumnDefinitionSegment;
24  import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.column.alter.DropColumnDefinitionSegment;
25  import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.column.alter.ModifyColumnDefinitionSegment;
26  import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.column.alter.RenameColumnSegment;
27  import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.constraint.alter.AddConstraintDefinitionSegment;
28  import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.constraint.alter.DropConstraintDefinitionSegment;
29  import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.constraint.alter.ModifyConstraintDefinitionSegment;
30  import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.constraint.alter.ValidateConstraintDefinitionSegment;
31  import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.index.DropIndexDefinitionSegment;
32  import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.index.RenameIndexDefinitionSegment;
33  import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.table.ConvertTableDefinitionSegment;
34  import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment;
35  import org.apache.shardingsphere.sql.parser.sql.common.statement.AbstractSQLStatement;
36  
37  import java.util.Collection;
38  import java.util.LinkedList;
39  import java.util.Optional;
40  
41  /**
42   * Alter table statement.
43   */
44  @Getter
45  @Setter
46  public abstract class AlterTableStatement extends AbstractSQLStatement implements DDLStatement {
47      
48      private SimpleTableSegment table;
49      
50      private SimpleTableSegment renameTable;
51      
52      private ConvertTableDefinitionSegment convertTableDefinition;
53      
54      private final Collection<AddColumnDefinitionSegment> addColumnDefinitions = new LinkedList<>();
55      
56      private final Collection<ModifyColumnDefinitionSegment> modifyColumnDefinitions = new LinkedList<>();
57      
58      private final Collection<ChangeColumnDefinitionSegment> changeColumnDefinitions = new LinkedList<>();
59      
60      private final Collection<DropColumnDefinitionSegment> dropColumnDefinitions = new LinkedList<>();
61      
62      private final Collection<AddConstraintDefinitionSegment> addConstraintDefinitions = new LinkedList<>();
63      
64      private final Collection<ValidateConstraintDefinitionSegment> validateConstraintDefinitions = new LinkedList<>();
65      
66      private final Collection<ModifyConstraintDefinitionSegment> modifyConstraintDefinitions = new LinkedList<>();
67      
68      private final Collection<DropConstraintDefinitionSegment> dropConstraintDefinitions = new LinkedList<>();
69      
70      private final Collection<DropIndexDefinitionSegment> dropIndexDefinitions = new LinkedList<>();
71      
72      private final Collection<RenameColumnSegment> renameColumnDefinitions = new LinkedList<>();
73      
74      private final Collection<RenameIndexDefinitionSegment> renameIndexDefinitions = new LinkedList<>();
75      
76      /**
77       * Get rename table.
78       *
79       * @return rename table
80       */
81      public Optional<SimpleTableSegment> getRenameTable() {
82          return Optional.ofNullable(renameTable);
83      }
84      
85      /**
86       * Get convert table definition.
87       *
88       * @return convert table definition
89       */
90      public Optional<ConvertTableDefinitionSegment> getConvertTableDefinition() {
91          return Optional.ofNullable(convertTableDefinition);
92      }
93  }