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 }