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.hayabusa.db;
017
018 import org.opengion.hayabusa.common.HybsSystemException;
019 import org.opengion.fukurou.util.StringUtil;
020
021 import java.sql.SQLData;
022 import java.sql.SQLInput;
023 import java.sql.SQLOutput;
024 import java.sql.SQLException;
025
026 /**
027 * QLData インターフェースを継承した ユーザー変数の受け渡し用オブジェクトですã?
028 * 登録されてã�?‚‹属æ?æƒ??は、セãƒ?ƒˆメソãƒ?ƒ‰をé?してã€??番に設定されますã?
029 *
030 * @og.group ?¤?¢/Shell制御
031 *
032 * @version 4.0
033 * @author Kazuhiko Hasegawa
034 * @since JDK5.0,
035 */
036 public class DBUserArg implements SQLData {
037 private String sql_type ;
038
039 private final String[] names;
040 private String[] values;
041
042 /**
043 * すべての属æ?æƒ??を指定して、新しい DBUserArg オブジェクトを作æ?しますã?
044 *
045 * @og.rev 3.3.3.1 (2003/07/18) ?¤?¢登録時ã?後ろスペã?スを削除するã€?
046 * @og.rev 3.5.6.0 (2004/06/18) å†?ƒ¨に取り込み時に、キー配å?はã€?arraycopy を行うã€?
047 *
048 * @param type ãƒ??タベã?スタイプ文字å?
049 * @param nms キー配å?
050 * @param vals 属æ?配å?
051 */
052 public DBUserArg( final String type,final String[] nms,final String[] vals ) {
053 if( nms == null ) {
054 String errMsg = "引数のキー配å?ã�?null ですã?" ;
055 throw new HybsSystemException( errMsg );
056 }
057
058 int size = nms.length;
059 names = new String[size];
060 System.arraycopy( nms,0,names,0,size );
061
062 sql_type = type;
063 values = StringUtil.rTrims( vals );
064 }
065
066 /**
067 * 属æ?配å?æƒ??を取得しますã?
068 *
069 * @og.rev 3.5.6.0 (2004/06/18) 取り出し時にå†?ƒ¨配å?ã‚?clone して返しますã?
070 * @og.rev 3.6.0.0 (2004/09/22) 属æ?配å?ã�?null の場合ã?、エラー
071 *
072 * @return 属æ?配å?
073 */
074 public String[] getValues() {
075 if( values != null ) {
076 return values.clone();
077 }
078
079 String errMsg = "属æ?配å?がã?初期化されてã�?�¾せんã€?;
080 throw new HybsSystemException( errMsg );
081 }
082
083 // ============================================================
084 // implements SQLData
085 // ============================================================
086
087 /**
088 * ?³?±?¬タイプã?æ–?—å?を返しますã?
089 *
090 * @return ?³?±?¬タイプã?æ–?—å?
091 * @throws SQLException ※ こã?実è£?�‹らã? SQLException は、throw されませんã€?
092 */
093 public String getSQLTypeName() throws SQLException {
094 return sql_type;
095 }
096
097 /**
098 * ãƒ??タベã?スå†?ƒ¨よりå†?ƒ¨属æ?を取得し、オブジェクトを構築しますã?
099 *
100 * @param stream ストリーãƒ?
101 * @param typeName ?³?±?¬タイプã?æ–?—å?
102 * @throws SQLException ãƒ??タベã?スアクセスエラー
103 */
104 public void readSQL( final SQLInput stream, final String typeName ) throws SQLException {
105 sql_type = typeName;
106
107 values = new String[names.length];
108 for( int i=0; i<names.length; i++ ) {
109 values[i] = stream.readString();
110 }
111 }
112
113 /**
114 * ãƒ??タベã?スå†?ƒ¨にå†?ƒ¨属æ?を設定しますã?
115 *
116 * @param stream ストリーãƒ?
117 * @throws SQLException ãƒ??タベã?スアクセスエラー
118 */
119 public void writeSQL( final SQLOutput stream ) throws SQLException {
120 for( int i=0; i<names.length; i++ ) {
121 stream.writeString( values[i] );
122 }
123 }
124 }