/**
 * Copyright (c) 2003-2004 System Integrator Corporation.
 *                 All Rights Reserved.
 */
package jp.co.sint.database;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import jp.co.sint.basic.SINameValue;
import jp.co.sint.config.SIConfig;
import jp.co.sint.config.SIDBMultiConf;
import jp.co.sint.tools.SIDateTime;
import jp.co.sint.tools.SIFlagUtil;
import jp.co.sint.tools.SIStringUtil;
import jp.co.sint.tools.SIUtil;
import oracle.jdbc.OracleTypes;

import org.apache.log4j.Category;
import jp.livewell.baby.util.ZenHanConverter;

/**
 * @version $Id : SIDBUtil.java,v 1.0 Exp $
 * @author      : Jinwang Chen
 * <br>Description :データベースへのアクセスするためのユーティリティです。
 * <p>History</p>
 * <p>Author&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Date&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Reason</p>
 * ============&nbsp;&nbsp;&nbsp;==========&nbsp;&nbsp;===========================<br>
 * J.W.Chen       2003/07/09  Original
 */

public class SIDBUtil{

  //ログ用のインスタンスの生成
  private static Category log=Category.getInstance(SIConfig.SILOG4J_WEBSHOP_CATEGORY_NAME);
  /**
   * データベースマネジャーのインスタンスを生成します。
   */
  private SIDBUtil(){}

	/**
	 * getOneRowData
	 * DBから１つの行のデータを獲得し、Setで取り出します。
	 * @param lConnection DBへのコネクション
	 * @param lSql クエリ
	 * @return カラムのデータを入れたSet
	 */
	public static HashMap getOneRowData(Connection lConnection, String lSql) throws SIDBAccessException{
    Statement lStatement =null;
    ResultSet lResultSet =null;
		//データをセットするセットを作成する。
		HashMap lResultMap=new HashMap();
		try{
			//Debug
			log.debug("getOneRowData:lSql="+lSql);
			//Statement の作成
			lStatement = lConnection.createStatement ();
			//Resultset の作成
			lResultSet = lStatement.executeQuery (lSql);
			//データの取得
			if (lResultSet.next()){
				for (int ii=1;ii<=lResultSet.getMetaData().getColumnCount();ii++){
					lResultMap.put(lResultSet.getMetaData().getColumnName(ii).toLowerCase(),lResultSet.getString(ii));
				}
			}else return new HashMap();
		}catch(SQLException ex){
			ex.printStackTrace();
			throw new SIDBAccessException(ex);
		}finally{
      close(lStatement,lResultSet);
		}
		return lResultMap;
	}

  /**
   * DBから１つのカラムのデータを獲得し、Setで取り出します。
   * @param lConnection DBへのコネクション
   * @param lSql クエリ
   * @return カラムのデータを入れたSet
   */
  public static Set getOneColumnData(Connection lConnection, String lSql) throws SIDBAccessException{
    Statement lStatement =null;
    ResultSet lResultSet =null;
    //データをセットするセットを作成する。
    HashSet lSet = new HashSet();
    try{
      //Debug
      log.debug("getOneColumnData:lSql="+lSql);
      //Statement の作成
      lStatement = lConnection.createStatement ();
      //Resultset の作成
      lResultSet = lStatement.executeQuery (lSql);
      //データの取得
      while (lResultSet.next ())lSet.add(lResultSet.getString(1));
    }catch(SQLException ex){
      throw new SIDBAccessException(ex);
    }finally{
      close(lStatement,lResultSet);
    }
    return(lSet);
  }

  /**
   * データがあるかどうかをチェックします。
   * @param connection DBへのコネクション
   * @param sql データをチェックするSQL文。
   * @return true : データがある / false：データがない
   */
  public static boolean hasData(Connection lConnection, String lSql)throws SIDBAccessException{
    Statement lStatement =null;
    ResultSet lResultSet =null;
    try{
      //debug
      log.debug("hasData:lSql="+lSql);
      // Statement の作成
      lStatement = lConnection.createStatement ();
      // Resultset の作成
      lResultSet = lStatement.executeQuery (lSql);
      boolean has = lResultSet.next();
      return has;
    }catch(SQLException ex){
      throw new SIDBAccessException(ex);
    }finally{
      close(lStatement,lResultSet);
    }
  }

  /**
   * データがあるかどうかをチェックします。
   * @param connection DBへのコネクション
   * @param sql データをチェックするSQL文。
   * @return true : データがある / false：データがない
   */
  public static boolean hasData(Connection lConnection, String lSql,List lValues)throws SIDBAccessException{
    Statement lStatement =null;
    ResultSet lResultSet =null;
    try{
      //debug
      log.debug("hasData:lSql="+lSql);
      // Statement の作成
      lStatement = lConnection.createStatement ();
      // Resultset の作成
      lResultSet = lStatement.executeQuery (lSql);
      boolean has = lResultSet.next();
      return has;
    }catch(SQLException ex){
      throw new SIDBAccessException(ex);
    }finally{
      close(lStatement,lResultSet);
    }
  }

  /**
   * レコード数を求めるselect文を指定し、レコード数を返す。
   * @param lConnection DBへのコネクション
   * @param lSql クエリ文
   * @return レコード数
   * @throws SIDBAccessException
   */
  public static int getDataCount(Connection lConnection, String lSql)throws SIDBAccessException{
    Statement lStatement =null;
    ResultSet lResultSet =null;

    try{
      // Statement の作成
      lStatement = lConnection.createStatement ();
      // Resultset の作成
      lResultSet = lStatement.executeQuery (lSql);

      int no = 0;
      if (lResultSet.next()){
        lResultSet.afterLast();
        no = lResultSet.getRow();
      }
      return(no);
    }catch(SQLException ex){
      throw new SIDBAccessException(ex);
    }finally{
      close(lStatement,lResultSet);
    }
  }

  /**
   * 第一行に一番目のデータを戻す
   * @param connection DBへのコネクション
   * @param sql クエリ文
   * @return レコード数
   */
  public static String getFirstData(Connection lConnection, String lSql)throws SIDBAccessException{
    Statement lStatement =null;
    ResultSet lResultSet =null;

    try{
      //debug
      log.debug("getFirstData:lSql="+lSql);
      // Statement の作成
      lStatement = lConnection.createStatement ();
      // Resultset の作成
      lResultSet = lStatement.executeQuery (lSql);

      String firstData = "";
      if (lResultSet.next()){
        firstData = lResultSet.getString(1);
      }
      return(firstData);
    }catch(SQLException ex){
    	ex.printStackTrace();
      throw new SIDBAccessException(ex);
    }finally{
      close(lStatement,lResultSet);
    }
  }

  /**
   * 指定したSQLを実行します。。
   * @param connection DBへのコネクション
   * @param sql 実行用のSQL文
   */
  public static void execSQL(Connection connection, String sql)throws SIDBAccessException{
    Statement stmt =null;
    try{
      // Statement の作成
      log.debug("execSQL:sql="+sql);
      stmt = connection.createStatement ();

      stmt.executeUpdate(sql);

    }catch(SQLException ex){
      throw new SIDBAccessException(ex);
    }finally{
      if (stmt!=null)try{stmt.close();}catch(SQLException sqle){}
    }
  }

  /**
   * 名前と値のpairをコネンクションに入れます。
   * @param lConnection DBへのコネクション
   * @param lSql データを検索するSQL文。
   * @return 結果のコネンクション
   */
  public static Collection getCollection(Connection lConnection,String lSql)throws SIDBAccessException{
    return getCollection(lConnection,lSql,false);
  }

  public static Collection getCollection(Connection lConnection,String lSql,boolean lAddBlank)throws SIDBAccessException{
    return getCollection(lConnection,lSql,lAddBlank,false);
  }//7.3.0 PI-NES0501 追加
  public static Collection getCollection(Connection lConnection,String lSql,boolean lAddBlank,boolean lAddFullBlank)throws SIDBAccessException{//7.3.0 PI-NES0501 修正 ここから
    return getCollection(lConnection,lSql,lAddBlank,lAddFullBlank,0);
  }
  /**
   * 名前と値のpairをコネンクションに入れます。
   * @param lConnection DBへのコネクション
   * @param lSql データを検索するSQL文。
   * @return 結果のコネンクション
   */
  public static Collection getCollection(Connection lConnection,String lSql,boolean lAddBlank,boolean lAddFullBlank,int limitLength)throws SIDBAccessException{//7.3.0 PI-NES0501 修正 ここから
    Collection lResultColl=new ArrayList();
    if (lAddFullBlank)lResultColl.add(SIFlagUtil.getFullBlank());
    else if (lAddBlank)lResultColl.add(SIFlagUtil.getBlank());
    //7.3.0 PI-NES0501 修正 ここまで

    Statement lStatement =null;
    ResultSet lResultSet =null;
    SINameValue lNameValue=new SINameValue();
    try {
      lStatement=lConnection.createStatement();
      lResultSet=lStatement.executeQuery(lSql);
      while (lResultSet.next()){
        String name = lResultSet.getString(1);
        if(limitLength>0&&name.length()>limitLength) lNameValue=new SINameValue(name.substring(0,limitLength),lResultSet.getString(2));
        else lNameValue=new SINameValue(name,lResultSet.getString(2));
        lResultColl.add(lNameValue);
      }
    }catch(Exception ex){
      throw new SIDBAccessException(ex);
    }finally{
      close(lStatement,lResultSet);
    }
    return lResultColl;
  }

  /**
   * 名前と値のpairを全角カタカナから半角カタカナに変換してコレクションに入れます。
   * @param lConnection DBへのコネクション
   * @param lSql データを検索するSQL文。
   * @return 結果のコネンクション
   */
  public static Collection getCollectionHankaku(Connection lConnection,String lSql)throws SIDBAccessException{
    return getCollectionHankaku(lConnection,lSql,false);
  }
  
  public static Collection getCollectionHankaku(Connection lConnection,String lSql,boolean lAddBlank)throws SIDBAccessException{
    return getCollectionHankaku(lConnection,lSql,lAddBlank,false);
  }
  
  public static Collection getCollectionHankaku(Connection lConnection,String lSql,boolean lAddBlank,boolean lAddFullBlank)throws SIDBAccessException{//7.3.0 PI-NES0501 修正 ここから
    Collection lResultColl=new ArrayList();
    ZenHanConverter lConverter = new ZenHanConverter();
    if (lAddFullBlank)lResultColl.add(SIFlagUtil.getFullBlank());
    else if (lAddBlank)lResultColl.add(SIFlagUtil.getBlank());

    Statement lStatement =null;
    ResultSet lResultSet =null;
    SINameValue lNameValue=new SINameValue();
    try {
      lStatement=lConnection.createStatement();
      lResultSet=lStatement.executeQuery(lSql);
      while (lResultSet.next()){
        lNameValue=new SINameValue(lConverter.convert(lResultSet.getString(1)).replaceAll("ー","ｰ"),lConverter.convert(lResultSet.getString(2)).replaceAll("ー","ｰ"));
        lResultColl.add(lNameValue);
      }
    }catch(Exception ex){
      throw new SIDBAccessException(ex);
    }finally{
      close(lStatement,lResultSet);
    }
    return lResultColl;
  }
  
  
  /**
   * 名前と値のpairをコネンクションに入れます。
   * @param lConnection DBへのコネクション
   * @param lSql データを検索するSQL文。
   * @return 結果のコネンクション
   */
  public static Collection getCollectionProc(Connection lConnection,String lSql)throws SIDBAccessException{
    Collection lResultColl=new ArrayList();

    CallableStatement cstmt;

    ResultSet lResultSet =null;
    SINameValue lNameValue=new SINameValue();
    try {
      cstmt = lConnection.prepareCall(lSql);
      cstmt.registerOutParameter(1,OracleTypes.CURSOR);
      cstmt.execute();
      lResultSet =(ResultSet)cstmt.getObject(1);

      while (lResultSet.next()){
        lNameValue=new SINameValue(lResultSet.getString(1),lResultSet.getString(2));
        lResultColl.add(lNameValue);
      }
    }catch(Exception ex){
      throw new SIDBAccessException(ex);
    }finally{
      if (lResultSet!=null)try{lResultSet.close();}catch(SQLException sqle){}
    }
    return lResultColl;
  }
  /**
   * データベースへの更新するプリペアドSQL文を実行します
   * @param connection DBへのコネクション
   * @param preparedSQL プリペアドのSQL文を指定します。
   * @param values ?の部分のデータのリスト
   * @execption SIDBAccessException
   */
  public static void executePrepared(Connection lConnection, String lPreparedSQL,ArrayList lValues)
      throws SIDuplicateKeyException,SIDBAccessException{
    PreparedStatement lPreparedStatement =null;
    try{
      lPreparedStatement = lConnection.prepareStatement(lPreparedSQL);
      setDataPreparedStatement(lPreparedStatement,lValues);
      lPreparedStatement.executeUpdate();
      lPreparedStatement.close();
    }catch(SQLException ex){
      ex.printStackTrace();
      if (ex.toString().indexOf("insert a duplicate key")!=-1) throw new SIDuplicateKeyException("Cannot insert a duplicate key");
      else throw new SIDBAccessException("update database error.");
    }finally{
      if (lPreparedStatement!=null)try{lPreparedStatement.close();}catch(SQLException sqle){}
    }
  }

  /**
   * データベースへの接続のコネンクションなどをクルーズします
   * @param lConnection DBへのコネクション
   * @param lResultSet 結果の保存のリセットセット
   * @param lStatement ステートメント
   * @return なし
   * @throws なし
   */
  public static void close(Connection lConnection,Statement lStatement,ResultSet lResultSet){
    try {
      if (lResultSet!=null)lResultSet.close();
      if (lStatement!=null)lStatement.close();
      if (lConnection!=null)lConnection.close();
      }catch(SQLException sqle){sqle.printStackTrace();}
  }

  /**
   * データベースへの接続のコネンクションなどをクルーズします
   * @param lConnection DBへのコネクション
   * @param lResultSet 結果の保存のリセットセット
   * @param lStatement ステートメント
   * @return なし
   * @throws なし
   */
  public static void close(Statement lStatement,ResultSet lResultSet){
    try {
      if (lResultSet!=null)lResultSet.close();
      if (lStatement!=null)lStatement.close();
      }catch(SQLException sqle){sqle.printStackTrace();}
  }

  /**
   * データベースへの接続のコネンクションをクルーズします
   * @param lConnection DBへのコネクション
   * @return なし
   * @throws なし
   */
  public static void close(Connection lConnection){
    try {
      log.debug("A connection is beend asked to close.");
      if (lConnection!=null)lConnection.close();
      }catch(SQLException sqle){sqle.printStackTrace();}
  }

  /**
   * データベースへの接続のコネンクションなどをクルーズします
   * @param resultSet 結果の保存のリセットセット
   * @param statement ステートメント
   * @return なし
   * @throws なし
   */
  public static void close(ResultSet lResultSet,Statement lStatement){
    try {
      if (lStatement!=null)lStatement.close();
      if (lResultSet!=null)lResultSet.close();
      }catch(SQLException sqle){sqle.printStackTrace();}
  }

  /**
   * 条件のコネクションから条件の文を作成します。
   * @param lCollection 条件を保存するコネクション
   * @return 条件文の文字列
   * @throws なし
   */
  public static String getCondition(Collection lCollection){
    Iterator lIterator=lCollection.iterator();
    SITableCondition lTableCondition=new SITableCondition();
    StringBuffer lResultBuf=new StringBuffer();
    while (lIterator.hasNext()){
      lTableCondition=(SITableCondition)lIterator.next();
      lResultBuf.append(lTableCondition.getCondition());
    }
    return lResultBuf.toString();
  }

  /**
   * コミットする
   * @param なし
   * @return なし
   * @throws なし
   *
   */
  public static void commit(Connection lConnection) throws SIDBAccessException{
    try{
      lConnection.commit();
    }catch(SQLException sqle){
      throw new SIDBAccessException(sqle);
    }
  }

  /**
   * <b>setDataPreparedStatement</b>
   * プリペアドSQL文（SQL文の中に?で変数を指定したもの）を指定し、
   * ?部分は、List にその変数を順番に登録して渡します。<br>
   * @param lPreparedSQL プリペアドのSQL文を指定します。
   * @param lValues プリペアドの ? 部分のデータを渡します。
   * @throws DBAccessException アクセスエラーが発生した場合
   */
  private static void setDataPreparedStatement(PreparedStatement lPreparedSQL, ArrayList lValues) throws SIDBAccessException{
    try{
      if (lValues!=null && lValues.size()>0){
        for (int i=0;i<lValues.size();i++){
          int no = i+1;
          Object data = lValues.get(i);

          if (data==null){
            lPreparedSQL.setString(no,"");
          }else if (data instanceof String){
            log.debug("{"+no+"}="+(String)data);
            lPreparedSQL.setString(no,(String)data);
          }else if (data instanceof Integer){
            lPreparedSQL.setInt(no,((Integer)data).intValue());
          }else if (data instanceof Long){
            lPreparedSQL.setLong(no,((Long)data).longValue());
          }else if (data instanceof SIDateTime){
            SIDateTime dtime = (SIDateTime)data;
            java.sql.Timestamp date = new java.sql.Timestamp(dtime.getTime());
            lPreparedSQL.setTimestamp(no,date);
          }else if (data instanceof InputStream){
            InputStream in = (InputStream)data;
            lPreparedSQL.setBinaryStream(no,in,in.available());
          }else if (data instanceof File){
            File file = (File)data;
            FileInputStream fis = new FileInputStream(file);
            lPreparedSQL.setBinaryStream(no,fis,(int)file.length());
          }else if (data instanceof SIDBNullData){
            lPreparedSQL.setNull(no,((SIDBNullData)data).getType());
          }
        }
      }
    }catch(IOException ex){
      throw new SIDBAccessException(ex);
    }catch(SQLException ex){
      ex.printStackTrace();
      throw new SIDBAccessException(ex);
    }
  }

	/**
	 * <b>sqlEncode</b>
	 * SQL文の中の全ての「'」の符号を「''」に変更します。
	 * @param val 対象の値
	 * @return 変換後の値
	 * @throws なし
	 */
  public static String sqlEncode(String val){
    if (val==null) return null;
    //7.4.0 ST2083 修正 ここから
    if (SIDBMultiConf.SIDB_CURRENT_INX ==SIDBMultiConf.SIDB_POSTGRESQL_INX){
      return SIStringUtil.replace(SIStringUtil.replace(val,"'","''"),"\\","\\\\");
    } else {
      return SIStringUtil.replace(val,"'","''");
    }
    //7.4.0 ST2083 修正 ここまで
  }

  public static String funcEncode(String val){
    if (val==null) return null;
    return SIStringUtil.replace(SIStringUtil.replace(val,"'","''''"),"\\","\\\\");
  }

  /**
   * <b>SQL2Str</b>
   * データの前後に「'」を付けSQLのパラメータのデータを作ります
   * @param val 対象のデータ
   * @param endChar 作ったデータに最後の文字列
   * @return 「'」を付けたパラメータのデータ
   * @throws なし
   */
  public static String SQL2Str(String val,String endChar){
    if (SIUtil.isNull(val)) return "null"+endChar;
    return "'"+sqlEncode(val)+"'"+endChar;
  }

  public static String SQL2Str(String val){
    return SQL2Str(val,"");
  }

  public static String Func2Str(String val,String endChar){
    if (SIUtil.isNull(val)) return "null"+endChar;
    return "'"+funcEncode(val)+"'"+endChar;
  }

  public static String Func2Str(String val){
    return Func2Str(val,"");
  }

  public static String SQL2Like(String val){
    if (SIUtil.isNull(val)) return val;
    String lRes=SIStringUtil.replace(val,"'","''");
    lRes=SIStringUtil.replace(lRes,"\\","\\\\");
    lRes=SIStringUtil.replace(lRes,"%","\\%");
    lRes=SIStringUtil.replace(lRes,"_","\\_");
    return lRes;
  }

  public static String getDateTime(Timestamp lTimestamp){
    if (lTimestamp==null) return "";
    SimpleDateFormat sdf=new SimpleDateFormat(SIConfig.SIDATE_TIME_FORMAT);
    return sdf.format(lTimestamp);
  }

  public static String getDate(Timestamp lTimestamp){
    if (lTimestamp==null) return "";
    SimpleDateFormat sdf=new SimpleDateFormat(SIConfig.SIDATE_FORMAT);
    return sdf.format(lTimestamp);
  }
  public static String getDate2(Timestamp lTimestamp){
      if (lTimestamp==null) return "";
      SimpleDateFormat sdf=new SimpleDateFormat(SIConfig.SIDATE_FORMAT0);//yyyy-mm-dd
      return sdf.format(lTimestamp);
  }

  /**
   * プリペアドSQL文（SQL文の中に?で変数を指定したもの）を指定し、
   * ?部分は、List にその変数を順番に登録して渡します。<br>
   * @param lPreparedSQL プリペアドのSQL文を指定します。
   * @param lValues プリペアドの ? 部分のデータを渡します。
   * @throws DBAccessException アクセスエラーが発生した場合
   */
  public static String getSrchKeySQL(String lShopCode,String lCtgryCode,int lSrchKeyCode){
    StringBuffer resultBuf=new StringBuffer();
    resultBuf.append("SELECT SrchKeyName FROM SrchCtgryMTbl ");
    resultBuf.append("WHERE shopCode='"+sqlEncode(lShopCode)+"' ");
    resultBuf.append("AND ctgryCode='"+sqlEncode(lCtgryCode)+"' ");
    resultBuf.append("AND srchKeyCode="+lSrchKeyCode);
    return resultBuf.toString();
  }

  public static Collection getShopCollection(Connection lConnection){
    String lSql="SELECT AbbvFrontShopName,MallShopCode FROM ShopVW WHERE status=1 ORDER BY AbbvFrontShopName";
    try {
      return SIDBUtil.getCollection(lConnection,lSql,false);
    } catch (SIDBAccessException e) {
      e.printStackTrace();
      return new ArrayList();
    }

  }

  public static Collection getBackShopCollection(Connection lConnection,boolean flag){
    String lSql="SELECT FrontShopName,MallShopCode FROM ShopVW ORDER BY MallShopCode";
    try {
      return SIDBUtil.getCollection(lConnection,lSql,flag);
    } catch (SIDBAccessException e) {
      e.printStackTrace();
      return new ArrayList();
    }
  }

  public static String getNextVal(String lSeqName){
    if (SIUtil.isNull(lSeqName)) {
      log.warn("getNextVal:get an empty seq name!!!");
      return "";
    }
    if (SIDBMultiConf.SIDB_CURRENT_INX ==SIDBMultiConf.SIDB_POSTGRESQL_INX){
      return "SELECT NEXTVAL('"+lSeqName+"')";
    }else{
      return "SELECT "+lSeqName+".NEXTVAL  FROM DUAL";
    }
  }
  /**
   * Pointが利用可能かどうか。(0：不可 1：可)
   * @param request
   * @param connection
   * @return
   */
  public static String getPointEnableFlg(String shopCode,Connection connection){
	  //ポイントが使用できるかどうかを設定
  	String lShopPointEnableFlg="0";
  	try{
  	  if(SIConfig.SIRUNNING_MODE_CURRENT!=SIConfig.SIRUNNING_MODE_TOGETHER){
    		StringBuffer lSqlBuf=new StringBuffer();
    		lSqlBuf.append("SELECT PointEnableFlg FROM MallShopMTbl WHERE MallShopCode=");
    		lSqlBuf.append(SIDBUtil.SQL2Str(shopCode));
    		if (SIUtil.isNotNull(SIDBUtil.getFirstData(connection,lSqlBuf.toString()))){
    		  lShopPointEnableFlg=SIDBUtil.getFirstData(connection,lSqlBuf.toString());
    		}
  	  }
  	}catch(SIDBAccessException e){
  	  e.printStackTrace();
  	  log.debug(e);
  	}
  	if((SIConfig.SIRUNNING_MODE_CURRENT==SIConfig.SIRUNNING_MODE_TOGETHER
  	&&SIConfig.SIMALL.getPointEnableFlg().equals("1")
  	)||lShopPointEnableFlg.equals("1")){
  	  return "1";
  	}else{
  	  return "0";
  	}
  }
  //7.3.0 ST2023 追加  ここから
  /**
   * DBから現在日時を取得する
   * @param Connection
   * @return String 日時 (YYYY/MM/DD HH24:MI:SS)
   */
  public static String getDBDateTime(Connection connection) {

  	StringBuffer sbSQL = new StringBuffer();

  	if ( SIDBMultiConf.SIDB_CURRENT_INX == SIDBMultiConf.SIDB_POSTGRESQL_INX ) {
  	  //PostgreSQL
      sbSQL.append("SELECT TO_CHAR(now(),'YYYY/MM/DD HH24:MI:SS') ");
  	} else {
      //ORACLE
      sbSQL.append("SELECT TO_CHAR(SYSDATE,'YYYY/MM/DD HH24:MI:SS') FROM DUAL");
    }

    try {
      return SIDBUtil.getFirstData(connection,sbSQL.toString());
    } catch (SIDBAccessException e) {
      log.error(e.toString());
      e.printStackTrace();
      return "";
    }
  }
  //7.3.0 ST2023 追加  ここまで
}