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     */
016    package org.opengion.plugin.column;
017    
018    import org.opengion.fukurou.util.StringUtil;
019    import org.opengion.hayabusa.db.AbstractDBType;
020    
021    /**
022     * DATA_DEFAULT カラãƒ?�§、å?容の整合æ?を整えますã?
023     *
024     * DATA_DEFAULT(初期値)カラãƒ??、データベã?ス上に設定されてã�?�¾すがã€?
025     * DB定義スクリプトã‚??ãƒ??タベã?スの種類によって、本来å¿?¦�な形式で
026     * 取得できなã�?�¨きがありますã?
027     * ここでは、å?期å?の後ろに コメントがある場合ã?、削除しã?
028     * ãƒ??タそã?もã?に、シングルクオートをはずしますã?
029     * 定義æƒ??出力時には、カラãƒ??属æ?(数字型、文字型)
030     * またã?postgreSQL 対応としてã€?:属æ?æƒ??がå?るã?で、削除しますã?
031     * シーケンス使用時にもã?nextval がè?動的にセãƒ?ƒˆさえばすがã€?
032     * 削除しますã?
033     *
034     * こã?クラスは、valueAction メソãƒ?ƒ‰で、action="VALSET" でのみ
035     * 動作しますã?
036     *
037     * @og.group ãƒ??タ属æ?
038     * @og.rev 5.1.3.0 (2010/02/01) 新規作æ?
039     *
040     * @version  4.0
041     * @author       Kazuhiko Hasegawa
042     * @since    JDK5.0,
043     */
044    public class DBType_DD extends AbstractDBType {
045            //* こã?プログラãƒ??VERSIONæ–?­—å?を設定しますã?       {@value} */
046            private static final String VERSION = "5.1.3.0 (2010/02/01)" ;
047    
048            /**
049             * action でæŒ?®šされたコマンドを実行して、å?の変換を行いますã?
050             * oldValue(旧ãƒ??タ)は、å?のDBTableModelに設定されてã�?�Ÿ値ですã?通常はã€?
051             * こã?値を使用してカラãƒ?¯Žに変換を行いますã?newValue(新ãƒ??タ)は、引数で
052             * æŒ?®šされた新しい値ですã?こã?値には、パラメータを指定して変換方法を
053             * 制御することも可能ですã?
054             * æŒ?®šã?アクションがカラãƒ?�§処ç�?�§きなã�??合ã?、エラーになりますã?
055             *
056             * @og.rev 5.1.3.0 (2010/02/01) 新規追åŠ?
057             *
058             * @param   action アクションコマンãƒ?
059             * @param   oldValue 入力データ(旧ãƒ??タ)
060             * @param   newValue 入力データ(新ãƒ??タ)
061             *
062             * @return      実行後ã?ãƒ??タ
063             */
064            @Override
065            public String valueAction( final String action,final String oldValue,final String newValue ) {
066                    if( "VALSET".equals( action ) ) {
067                            String val = StringUtil.rTrim( oldValue ) ;
068    
069                            if( val != null && val.length() > 0 ) {
070                                    // 共通:シングルクオートã?ずし
071                                    int pos1 = val.indexOf( "'",1 );
072                                    if( pos1 > 1 ) { val = val.substring( 1,pos1 ); }
073                                    // 共通:å?期å?に /* */ コメントが入ることがあるã?で、削除
074                                    int pos2 = val.indexOf( "/*" );
075                                    if( pos2 > 0 ) { val = val.substring( 0,pos2 ); }
076    
077                                    // postgreSQL 対応:属æ?æƒ??がå?るã?で、削除
078                                    int pos3 = val.indexOf( "::" );
079                                    if( pos3 > 0 ) { val = val.substring( 0,pos3 ); }
080                                    // postgreSQL 対応:属æ?æƒ??がå?るã?で、削除
081                                    // ??oldValue で判断してã�?‚‹のは、val は、å?に色ã€?�¨åŠ?·¥してã�?‚‹為
082                                    if( oldValue.startsWith( "nextval" ) ) { val = ""; }
083                            }
084    
085                            return val ;
086                    }
087                    else {
088                            return super.valueAction( action,oldValue,newValue ) ;
089                    }
090            }
091    }