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
018import java.util.Locale;                                                                                        // 7.2.9.4 (2020/11/20)
019
020import org.opengion.fukurou.system.OgBuilder ;                                          // 6.4.4.1 (2016/03/18)
021
022/**
023 * TableFilter_SEQUENCE_POSTGRES は、TableUpda インターフェースを継承した、DBTableModel 処理用の
024 * 実装クラスです。
025 *
026 * ここでは、シーケンス一覧の検索結果より、GF09 のシーケンス定義テーブルから
027 * 必要な情報を取得し、シーケンス作成スクリプトを作成します。
028 *
029 * この処理を実行するには、DBTableModelのカラムとして、
030 *  SEQNAME,INCREBY,STARTVAL,MINVAL,MAXVAL,FGCYCLE,SUCACHE
031 * が必要です。
032 *
033 * ※PostgreSQLに対して生成されるスクリプトでは、SUCACHEは無視されます。
034 *
035 * @og.rev 5.1.9.0 (2010/08/01) DB定義DB・シーケンス定義追加
036 * @og.rev 6.5.0.0 (2016/09/30) クラス名変更(TableFilter_SEQUENCE_POSGRE → TableFilter_SEQUENCE_POSTGRES)
037 *
038 * @version  6.5.0  2000/10/17
039 * @author   Kazuhiko Hasegawa
040 * @since    JDK1.8,
041 */
042public class TableFilter_SEQUENCE_POSTGRES extends TableFilter_SEQUENCE {
043        /** このプログラムのVERSION文字列を設定します。   {@value} */
044        private static final String VERSION = "6.5.0.0 (2016/09/30)" ;
045
046        /**
047         * デフォルトコンストラクター
048         *
049         * @og.rev 6.4.2.0 (2016/01/29) PMD refactoring. Each class should declare at least one constructor.
050         * @og.rev 6.5.0.0 (2016/09/30) クラス名変更(TableFilter_SEQUENCE_POSGRE → TableFilter_SEQUENCE_POSTGRES)
051         */
052        public TableFilter_SEQUENCE_POSTGRES() { super(); }             // これも、自動的に呼ばれるが、空のメソッドを作成すると警告されるので、明示的にしておきます。
053
054        /**
055         * ヘッダー部分の処理を実行します。
056         *
057         * @og.rev 5.10.25.0 (2020/10/02) 先頭にencodingを付加するために作成
058         *
059         * @param       clmNo   カラム番号配列
060         * @param       data    1行分のデータ配列
061         *
062         * @return      ヘッダー部分の文字列
063         */
064        @Override
065        protected String makeHeadLine( final int[] clmNo,final String[] data ) {
066                String str = isXml ? "" : "\\encoding UTF8;" + CR;
067                str += super.makeHeadLine( clmNo,data );
068                return str;
069        }
070
071        /**
072         * シーケンス作成の処理を実行します。
073         *
074         * @og.rev 6.0.2.3 (2014/10/10) isXml で、CR + EXEC_END_TAG のキャッシュ(execEndTag)を利用します。
075         * @og.rev 6.4.4.1 (2016/03/18) StringBuilderの代わりに、OgBuilderを使用する。
076         * @og.rev 5.10.25.0 (2020/10/02) スクリプトを小文字にしておく
077         *
078         * @param       clmNo   カラム番号配列
079         * @param       data    1行分のデータ配列
080         *
081         * @return      シーケンス作成
082         * @og.rtnNotNull
083         */
084        @Override
085        protected String makeLineList( final int[] clmNo,final String[] data ) {
086                return new OgBuilder()
087                                .appendIfCR( isXml , EXEC_START_TAG )
088                                .appendCR( "CREATE SEQUENCE "   , data[clmNo[SEQNAME]] )
089                                .append( "  INCREMENT "                 , data[clmNo[INCREBY]] )
090                                .append( " MINVALUE "                   , data[clmNo[MINVAL]]  )
091                                .append( " MAXVALUE "                   , data[clmNo[MAXVAL]]  )
092                                .append( " START "                              , data[clmNo[STARTVAL]] )
093                                .appendIf( "1".equals( data[clmNo[FGCYCLE]] ) , " CYCLE" )
094                                .append( execEndTag )
095//                              .toString();
096//                              .toString().toLowerCase();                                      // 5.10.25.0 (2020/10/02) 小文字化してしまう
097                                .toString().toLowerCase( Locale.JAPAN );        // 7.2.9.4 (2020/11/20) 5.10.25.0 (2020/10/02) 小文字化してしまう
098        }
099}