001/* 002 * (C) Copyright 2006-2011 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Florent Guillaume 018 */ 019package org.nuxeo.ecm.core.storage.sql.jdbc.db; 020 021import java.io.Serializable; 022import java.util.Collection; 023import java.util.List; 024 025import org.nuxeo.ecm.core.storage.sql.ColumnType; 026import org.nuxeo.ecm.core.storage.sql.Model; 027import org.nuxeo.ecm.core.storage.sql.jdbc.dialect.Dialect; 028 029/** 030 * A SQL table. 031 */ 032public interface Table extends Serializable { 033 034 enum IndexType { 035 /** Fulltext index, may be on several columns. */ 036 FULLTEXT, 037 /** Unique index. */ 038 UNIQUE, 039 /** Non primary index but the main one for this table. */ 040 MAIN_NON_PRIMARY 041 } 042 043 boolean isAlias(); 044 045 Table getRealTable(); 046 047 Dialect getDialect(); 048 049 String getKey(); 050 051 String getPhysicalName(); 052 053 String getQuotedName(); 054 055 String getQuotedSuffixedName(String suffix); 056 057 Column getColumn(String name); 058 059 Column getPrimaryColumn(); 060 061 Collection<Column> getColumns(); 062 063 /** 064 * Adds a {@link Column} to the table. 065 */ 066 Column addColumn(String name, ColumnType type, String key, Model model); 067 068 /** 069 * Adds an index on one or several columns. 070 * 071 * @param columnNames the column names 072 */ 073 void addIndex(String... columnNames); 074 075 /** 076 * Adds an index of the given name and type on one or several columns. 077 * 078 * @param indexName the index name 079 * @param indexType the index type 080 * @param columnNames the column names 081 */ 082 void addIndex(String indexName, IndexType indexType, String... columnNames); 083 084 /** 085 * Checks if the table has some fulltext indexes. 086 * 087 * @return {@code true} if the table has some fulltext indexes 088 */ 089 boolean hasFulltextIndex(); 090 091 /** 092 * Computes the SQL statement to create the table. 093 * 094 * @return the SQL create string. 095 */ 096 String getCreateSql(); 097 098 /** 099 * Computes the SQL statement to alter a table and add a column to it. 100 * 101 * @param column the column to add 102 * @return the SQL alter table string 103 */ 104 String getAddColumnSql(Column column); 105 106 /** 107 * Computes the SQL statements to finish creating the table, usually some ALTER TABLE statements to add constraints 108 * or indexes. 109 * 110 * @return the SQL strings 111 */ 112 List<String> getPostCreateSqls(Model model); 113 114 /** 115 * Computes the SQL statements to finish adding a column, usually some ALTER TABLE statements to add constraints or 116 * indexes. 117 * 118 * @return the SQL strings 119 */ 120 List<String> getPostAddSqls(Column column, Model model); 121 122 /** 123 * Computes the SQL statement to drop the table. 124 * <p> 125 * TODO drop constraints and indexes 126 * 127 * @return the SQL drop string. 128 */ 129 String getDropSql(); 130 131}