001/* 002 * Copyright (c) 2009 The openGion Project. 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, 013 * either express or implied. See the License for the specific language 014 * governing permissions and limitations under the License. 015 */ 016package org.opengion.plugin.table; 017 018/** 019 * TableFilter_INDEX_MYSQL は、TableUpda インターフェースを継承した、DBTableModel 処理用の 020 * 実装クラスです。とくに、MySQL用のインデックス作成スクリプトを作成します。 021 * 022 * ここでは、テーブル一覧の検索結果より、GF07 のインデックスカラム定義テーブルから 023 * 必要な情報を取得し、テーブル作成スクリプトを作成します。 024 * 出力ファイルは、テーブル名+"I.sql" という命名規則で作成します。 025 * 検索では、(SYSTEM_ID,TBLSYU,TABLE_NAME,NAME_JA,TABLESPACE_NAME,INITIAL_EXTENT,NEXT_EXTENT,COMMENTS) 026 * の項目を取得する必要があります。 027 * 028 * @og.rev 4.0.0.0 (2005/08/31) 新規作成 029 * 030 * @version 0.9.0 2000/10/17 031 * @author Kazuhiko Hasegawa 032 * @since JDK1.1, 033 */ 034public class TableFilter_INDEX_MYSQL extends TableFilter_INDEX { 035 //* このプログラムのVERSION文字列を設定します。 {@value} */ 036 private static final String VERSION = "5.6.9.2 (2013/10/18)" ; 037 038 /** 039 * 定義の最後の部分の処理を実行します。 040 * 041 * @param clmNo カラム番号配列 042 * @param data 1行分のデータ配列 043 * 044 * @return 定義の最後の部分 045 */ 046 @Override 047 protected String makeEndLine( final int[] clmNo,final String[] data ) { 048 return isXml ? EXEC_END_TAG : ";" ; 049 } 050 051 /** 052 * インデックス削除の構文を、作成します。 053 * 054 * @og.rev 5.6.9.2 (2013/10/18) 新規作成 055 * 056 * @param clmNo カラム番号配列 057 * @param data 1行分のデータ配列 058 * 059 * @return 作成された1行分の文字列 060 */ 061 @Override 062 protected String makeDropLine( final int[] clmNo,final String[] data ) { 063 String tableName = data[clmNo[TABLE_NAME]]; 064 String indexName = data[clmNo[INDEX_NAME]]; 065 // String idxtype = data[clmNo[INDTYPE]]; 066 067 StringBuilder buf = new StringBuilder(); 068 069 buf.append( CR ); // 先頭に、改行を入れておきます。 070 if( isXml ) { buf.append( EXEC_START_TAG ).append( CR ); } 071 072 // 0:プライマリキー , 1:ユニークキー 073 // if( "0".equals( idxtype ) || "1".equals( idxtype ) ) { 074 buf.append( "ALTER TABLE " ).append( tableName ).append( " DROP INDEX " ); 075 buf.append( indexName ); 076 // } 077 // 5.6.9.2 (2013/10/18) INDTYPE で、その他ではなく、2:通常 で判断する。 078 // else if( "2".equals( idxtype ) ) { // 2:通常 079 // buf.append( "DROP INDEX " ).append( indexName ).append( " ON " ).append( tableName ); 080 // } 081 // 一連の処理で、makeLineList ですでにエラーが出ているハズなので、ここでは出しません。 082 // else { 083 // String errMsg = "INDTYPE が、0,1,2 以外の値が使われています。INDTYPE=[" + idxtype + "]" 084 // + " TABLE_NAME=[" + tableName + "] INDEX_NAME=[" + indexName + "]" ; 085 // System.out.println( errMsg ); 086 // } 087 088 if( isXml ) { buf.append( CR ).append( EXEC_END_TAG ); } 089 else { buf.append( ";" ); } 090 091 return buf.toString(); 092 } 093 094 /** 095 * インデックスを作成するための文字列を返します。 096 * 但し、唯一、MySQLの場合、500バイト以上のカラムについては、TEXTで定義しており、 097 * この場合、インデックス化するバイト数(最大255)を指定する必要があります。 098 * このケースに対応するため、カラム名とバイト数を元に判定し、部分インデックスを 099 * 作成するための文字列を作成します。 100 * 101 * @og.rev 5.1.1.2 (2009/12/10) 102 * 103 * @param clm カラム名 104 * @param useLen カラムのバイト数 105 * 106 * @return インデックスカラムの文字列 107 */ 108 @Override 109 protected String makeIndexClmStr( final String clm, final String useLen ) { 110 int useLength = 0; 111 if( useLen != null && useLen.length() > 0 ) { 112 useLength = Integer.valueOf( useLen ); 113 } 114 return useLength > TableFilter_TABLE_MYSQL.CLM_MAX_SIZE ? clm + "(255)" : clm ; 115 } 116}