jp.mosp.common.common
クラス BaseDao

java.lang.Object
  上位を拡張 jp.mosp.common.common.BaseDao
直系の既知のサブクラス:
CmCodeDao, CmUserDao, CtAccountDao

public abstract class BaseDao
extends Object

Daoの基本機能を提供する。

Statement取得やSQL実行等、DB操作関連メソッドを有する。


フィールドの概要
protected  String aspUserId
          ログインASPユーザーID。
protected  Properties cfg
          MosPアプリケーション設定(/WEB-INF/mosp.properties)。
protected  String cmd
          Command。
protected  int cnt
          各種更新SQL実行件数。
protected  Connection conn
          DBコネクション。
protected  int index
          パラメーターインデックス。
protected  String INSERT_DATE
          デフォルト列名(作成者)。
protected  String INSERT_USER
          デフォルト列名(作成日)。
protected  PreparedStatement ps
          各種SQL実行の際に利用するステートメント。
protected  ResultSet rs
          各種検索SQL実行結果。
protected  String UPDATE_DATE
          デフォルト列名(更新者)。
protected  String UPDATE_USER
          デフォルト列名(更新日)。
protected  String userId
          ログインユーザーID。
 
コンストラクタの概要
protected BaseDao()
          コンストラクタ。
protected BaseDao(Properties cfg, String cmd, CmAspUserDto aspUser, CmUserDto user, Connection conn)
          コンストラクタ。
 
メソッドの概要
protected  void chkDelete(int expectedCount)
          削除件数確認。
protected  void chkInsert(int expectedCount)
          挿入件数確認。
protected  void chkUpdate(int expectedCount)
          更新件数確認。
protected  void clearParams()
          パラメータ消去。
protected  void executeQuery()
          検索系SQL実行。
protected  void executeUpdate()
          更新系SQL実行。
protected  void executeUpdate(boolean needLog)
          更新系SQL実行(ログ出力制御付)。
protected  void executeUpdate(Class<?> cls, int size, int max, int idx)
          更新系SQLを実行する。
protected  String getAddConditionForKey(Class<?> cls)
          キーによる条件SQL取得(追加用)。
protected  String getConditionForKey(Class<?> cls)
          キーによる条件SQL取得。
protected  String getDeleteQuery(Class<?> cls)
          削除SQL取得。
protected  String getDesc()
          DESC SQL取得。
protected  String getForUpdate()
          FOR UPDATE SQL取得。
protected  String getInsertQuery(Class<?> cls)
          挿入SQL取得。
protected  String getInsertQuery(Class<?> cls, int size, int max)
          挿入SQLを取得する。
protected  String getLimit()
          LIMIT SQL取得。
protected  String getOffset()
          OFFSET SQL取得。
protected  String getOrderBy()
          ORDER BY SQL取得。
protected  String getOrderForKey(Class<?> cls)
          キーによるソートSQL取得。
protected  String getPageStatement(String sortKey, boolean isAscending)
          頁操作用SQL取得。
protected  int getRdbmsType()
          RDBMS種類を取得する。
protected  String getSelectCountQuery(Class<?> cls)
          件数検索SQLを取得する。
protected  String getSelectCountStatement()
          件数検索SQLを取得する。
protected  String getSelectQuery(Class<?> cls)
          全件検索SQL取得。
protected  String getSelectStatement(Class<?> cls)
          検索SQL取得。
protected  String getSelectStatement(Class<?> cls, boolean needTableName)
          検索SQL文を取得する。
protected  String getTable(Class<?> cls)
          テーブル名取得。
protected  String getTableDescriptionQuery(String tableName)
          テーブル定義取得SQLを取得する。
protected  String getUpdateQuery(Class<?> cls)
          更新SQL取得。
 void initDao(Properties cfg, String cmd, CmAspUserDto aspUser, CmUserDto user, Connection conn)
          DAO初期化。
protected  void mappingCommonInfo(BaseDto dto)
          共通情報取得。
protected  void prepareStatement(String sql)
          PreparedStatement取得。
protected  void releasePreparedStatement()
          PreparedStatement開放。
protected  void releaseResultSet()
          ResultSet開放。
protected  void setBinaryParam(int idx, InputStream param, int size)
          パラメータ設定(InputStream)。
protected  void setCommonParams(boolean isInsert)
          共通情報設定。
protected  void setDateParam(int idx, Date param)
          パラメータ設定(Date)。
protected  void setParam(int idx, Date param)
          パラメータ設定(Date)。
protected  void setParam(int idx, double param)
          パラメータ設定(double)。
protected  void setParam(int idx, float param)
          パラメータ設定(float)。
protected  void setParam(int idx, int param)
          パラメータ設定(int)。
protected  void setParam(int idx, long param)
          パラメータ設定(long)。
protected  void setParam(int idx, String param)
          パラメータ設定(String)。
 
クラス java.lang.Object から継承されたメソッド
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

フィールドの詳細

INSERT_DATE

protected String INSERT_DATE
デフォルト列名(作成者)。
setCommonParams(boolean)mappingCommonInfo(BaseDto)で用いられる。
不要な場合は、""(空文字列)を設定する。


INSERT_USER

protected String INSERT_USER
デフォルト列名(作成日)。
setCommonParams(boolean)mappingCommonInfo(BaseDto)で用いられる。
不要な場合は、""(空文字列)を設定する。


UPDATE_DATE

protected String UPDATE_DATE
デフォルト列名(更新者)。
setCommonParams(boolean)mappingCommonInfo(BaseDto)で用いられる。
不要な場合は、""(空文字列)を設定する。


UPDATE_USER

protected String UPDATE_USER
デフォルト列名(更新日)。
setCommonParams(boolean)mappingCommonInfo(BaseDto)で用いられる。
不要な場合は、""(空文字列)を設定する。


cfg

protected Properties cfg
MosPアプリケーション設定(/WEB-INF/mosp.properties)。


aspUserId

protected String aspUserId
ログインASPユーザーID。


userId

protected String userId
ログインユーザーID。


cmd

protected String cmd
Command。


conn

protected Connection conn
DBコネクション。


ps

protected PreparedStatement ps
各種SQL実行の際に利用するステートメント。


rs

protected ResultSet rs
各種検索SQL実行結果。


cnt

protected int cnt
各種更新SQL実行件数。


index

protected int index
パラメーターインデックス。

コンストラクタの詳細

BaseDao

protected BaseDao()
コンストラクタ。


BaseDao

protected BaseDao(Properties cfg,
                  String cmd,
                  CmAspUserDto aspUser,
                  CmUserDto user,
                  Connection conn)
コンストラクタ。
initDao(Properties, String, CmAspUserDto, CmUserDto, Connection) で初期化する。

パラメータ:
cfg - 設定ファイル
cmd - コマンド
aspUser - ASPユーザー
user - ユーザー
conn - DBコネクション
メソッドの詳細

initDao

public void initDao(Properties cfg,
                    String cmd,
                    CmAspUserDto aspUser,
                    CmUserDto user,
                    Connection conn)
DAO初期化。

パラメータ:
cfg - 設定ファイル
cmd - コマンド
aspUser - ASPユーザー
user - ユーザー
conn - DBコネクション

releaseResultSet

protected void releaseResultSet()
                         throws SQLException
ResultSet開放。

例外:
SQLException

prepareStatement

protected void prepareStatement(String sql)
                         throws SQLException
PreparedStatement取得。

パラメータ:
sql - 実行SQL
例外:
SQLException

releasePreparedStatement

protected void releasePreparedStatement()
                                 throws SQLException
PreparedStatement開放。

例外:
SQLException

setParam

protected void setParam(int idx,
                        String param)
                 throws SQLException
パラメータ設定(String)。

パラメータ:
idx - インデックス
param - パラメータ
例外:
SQLException

setParam

protected void setParam(int idx,
                        int param)
                 throws SQLException
パラメータ設定(int)。

パラメータ:
idx - インデックス
param - パラメータ
例外:
SQLException

setParam

protected void setParam(int idx,
                        long param)
                 throws SQLException
パラメータ設定(long)。

パラメータ:
idx - インデックス
param - パラメータ
例外:
SQLException

setParam

protected void setParam(int idx,
                        float param)
                 throws SQLException
パラメータ設定(float)。

パラメータ:
idx - インデックス
param - パラメータ
例外:
SQLException

setParam

protected void setParam(int idx,
                        double param)
                 throws SQLException
パラメータ設定(double)。

パラメータ:
idx - インデックス
param - パラメータ
例外:
SQLException

setBinaryParam

protected void setBinaryParam(int idx,
                              InputStream param,
                              int size)
                       throws SQLException
パラメータ設定(InputStream)。

パラメータ:
idx - インデックス
param - パラメータ
例外:
SQLException

setParam

protected void setParam(int idx,
                        Date param)
                 throws SQLException
パラメータ設定(Date)。
java.sql.Timestampとして設定する。

パラメータ:
idx - インデックス
param - パラメータ
例外:
SQLException

setDateParam

protected void setDateParam(int idx,
                            Date param)
                     throws SQLException
パラメータ設定(Date)。
java.sql.Date(年月日)として設定する。

パラメータ:
idx - インデックス
param - パラメータ
例外:
SQLException

clearParams

protected void clearParams()
                    throws SQLException
パラメータ消去。

例外:
SQLException

executeQuery

protected void executeQuery()
                     throws SQLException
検索系SQL実行。

例外:
SQLException

executeUpdate

protected void executeUpdate()
                      throws SQLException
更新系SQL実行。

例外:
SQLException

executeUpdate

protected void executeUpdate(boolean needLog)
                      throws SQLException
更新系SQL実行(ログ出力制御付)。

パラメータ:
needLog - ログ出力要否
例外:
SQLException

getSelectQuery

protected String getSelectQuery(Class<?> cls)
                         throws NoSuchFieldException,
                                IllegalAccessException
全件検索SQL取得。

パラメータ:
cls - Daoクラス
戻り値:
全件検索SQL文字列
例外:
NoSuchFieldException
IllegalAccessException

getSelectStatement

protected String getSelectStatement(Class<?> cls)
                             throws IllegalAccessException
検索SQL取得。

パラメータ:
cls - Daoクラス
戻り値:
全件検索SQL文字列
例外:
IllegalAccessException

getSelectStatement

protected String getSelectStatement(Class<?> cls,
                                    boolean needTableName)
                             throws IllegalAccessException,
                                    NoSuchFieldException
検索SQL文を取得する。

パラメータ:
cls - Daoクラス
戻り値:
全件検索SQL文字列
例外:
IllegalAccessException
NoSuchFieldException

getSelectCountQuery

protected String getSelectCountQuery(Class<?> cls)
                              throws IllegalAccessException,
                                     NoSuchFieldException
件数検索SQLを取得する。

パラメータ:
cls - Daoクラス
戻り値:
全件検索SQL文字列
例外:
IllegalAccessException
NoSuchFieldException

getSelectCountStatement

protected String getSelectCountStatement()
件数検索SQLを取得する。

戻り値:
件数検索SQL文字列(SELECT COUNT(*))

getInsertQuery

protected String getInsertQuery(Class<?> cls)
                         throws NoSuchFieldException,
                                IllegalAccessException
挿入SQL取得。

パラメータ:
cls - dtoクラス
戻り値:
挿入SQL文字列
例外:
NoSuchFieldException
IllegalAccessException

getUpdateQuery

protected String getUpdateQuery(Class<?> cls)
                         throws NoSuchFieldException,
                                IllegalAccessException
更新SQL取得。

パラメータ:
cls - dtoクラス
戻り値:
更新SQL文字列
例外:
NoSuchFieldException
IllegalAccessException

getDeleteQuery

protected String getDeleteQuery(Class<?> cls)
                         throws NoSuchFieldException,
                                IllegalAccessException
削除SQL取得。

パラメータ:
cls - dtoクラス
戻り値:
削除SQL文字列
例外:
NoSuchFieldException
IllegalAccessException

getConditionForKey

protected String getConditionForKey(Class<?> cls)
                             throws IllegalAccessException
キーによる条件SQL取得。

パラメータ:
cls - dtoクラス
戻り値:
キーによる条件SQL文字列
例外:
IllegalAccessException

getAddConditionForKey

protected String getAddConditionForKey(Class<?> cls)
                                throws IllegalAccessException
キーによる条件SQL取得(追加用)。

パラメータ:
cls - dtoクラス
戻り値:
キーによる条件SQL文字列
例外:
IllegalAccessException

getOrderForKey

protected String getOrderForKey(Class<?> cls)
                         throws IllegalAccessException
キーによるソートSQL取得。

パラメータ:
cls - daoクラス
戻り値:
キーによるソートSQL文字列
例外:
IllegalAccessException

getTable

protected String getTable(Class<?> cls)
                   throws NoSuchFieldException,
                          IllegalAccessException
テーブル名取得。

パラメータ:
cls - daoクラス
戻り値:
テーブル名文字列
例外:
NoSuchFieldException
IllegalAccessException
MospException
SQLException

getPageStatement

protected String getPageStatement(String sortKey,
                                  boolean isAscending)
頁操作用SQL取得。

パラメータ:
sortKey - ソートキー
isAscending - 昇順フラグ
戻り値:
頁操作用SQL文字列

getForUpdate

protected String getForUpdate()
FOR UPDATE SQL取得。

戻り値:
FOR UPDATE 文字列

getOrderBy

protected String getOrderBy()
ORDER BY SQL取得。

戻り値:
ORDER BY 文字列

getDesc

protected String getDesc()
DESC SQL取得。

戻り値:
DESC 文字列

getLimit

protected String getLimit()
LIMIT SQL取得。

戻り値:
LIMIT 文字列

getOffset

protected String getOffset()
OFFSET SQL取得。

戻り値:
OFFSET 文字列

mappingCommonInfo

protected void mappingCommonInfo(BaseDto dto)
                          throws SQLException
共通情報取得。

パラメータ:
dto - 対象dto
例外:
SQLException

setCommonParams

protected void setCommonParams(boolean isInsert)
                        throws SQLException
共通情報設定。

パラメータ:
isInsert - 挿入文フラグ(true:挿入文、false:挿入文)
例外:
SQLException

chkInsert

protected void chkInsert(int expectedCount)
                  throws MospException
挿入件数確認。

パラメータ:
expectedCount - 想定される挿入件数
例外:
MospException

chkUpdate

protected void chkUpdate(int expectedCount)
                  throws MospException
更新件数確認。

パラメータ:
expectedCount - 想定される更新件数
例外:
MospException

chkDelete

protected void chkDelete(int expectedCount)
                  throws MospException
削除件数確認。

パラメータ:
expectedCount - 想定される削除件数
例外:
MospException

getRdbmsType

protected int getRdbmsType()
                    throws MospException
RDBMS種類を取得する。
connの情報からRDBMSの種類を特定する。

戻り値:
RDBMS種類
例外:
MospException

getTableDescriptionQuery

protected String getTableDescriptionQuery(String tableName)
                                   throws MospException
テーブル定義取得SQLを取得する。
RDBMS依存機能。MySQLをベースとしている。

パラメータ:
tableName - テーブル名
戻り値:
テーブル定義取得SQL
例外:
SQLException
MospException

getInsertQuery

protected String getInsertQuery(Class<?> cls,
                                int size,
                                int max)
                         throws IllegalAccessException,
                                NoSuchFieldException
挿入SQLを取得する。
挿入レコード数分を一度に挿入するSQLを作成する。
但し、挿入レコード最大数以上はSQLを作成しない。

パラメータ:
cls - daoクラス
size - 挿入レコード数
max - 挿入レコード最大数
戻り値:
挿入SQL文字列
例外:
IllegalAccessException
NoSuchFieldException

executeUpdate

protected void executeUpdate(Class<?> cls,
                             int size,
                             int max,
                             int idx)
                      throws SQLException,
                             IllegalAccessException,
                             NoSuchFieldException
更新系SQLを実行する。
処理インデックスが挿入レコード上限数か挿入対象件数に達した場合、 挿入処理を行う。
getInsertQuery(Class)と併せて用いる。 大量のデータを挿入する場合、パフォーマンスの向上が見込める。

パラメータ:
cls - dtoクラス
size - 挿入対象件数
max - 挿入レコード上限数(一度に挿入する上限)
idx - 処理インデックス
例外:
SQLException
IllegalAccessException
NoSuchFieldException