/**
* <p>
* [機能]自動採番処理
* </p>
* <p>
* [説明]
* </p>
* <p>
* [備考]
* </p>
*
* @return 番号
*/
public long saiban(int ID) throws Exception {
Connection conn = null;
PreparedStatement stmt = null;
ResultSet rset = null;
try {
// 戻り値
long retBangou = 0;
long maxID = 0;
boolean bolFirst = true;
String fieldNm = "";
// SQL文の宣言
String strSQL = "";
String strUpdSQL = "";
String strMaxSQL = "";
ArrayList retList = new ArrayList();
while (retBangou <= maxID ) {
if (bolFirst == false) {
retBangou = maxID + 1;
} else {
bolFirst = false;
// 番号の取得
// 選択SQL文の編集
strSQL = " SELECT ";
strSQL = strSQL + " BANGOU + 1 AS BANGOU ";
strSQL = strSQL + " FROM LND_M_HOUZINBANGOU";
strSQL = strSQL + " WHERE ID = " + ID;
strSQL = strSQL + " for update";
// 実行
conn = getConnection();
if (conn == null) {
log.error("InServiceUpdateDB:main::conn is null");
throw new Exception(getLogMessage("DB_ERR_GETCON"));
}
log.fatal("認証用SQL=" + strSQL);
conn.setAutoCommit(false);
stmt = conn.prepareStatement(strSQL);
rset = stmt.executeQuery();
ResultSetMetaData rsmd = rset.getMetaData();
int columnCount = rsmd.getColumnCount();
ArrayList rows = new ArrayList();
while (rset.next()) {
HashMap row = new HashMap();
for (int i = 1; i <= columnCount; i++) {
String name = rsmd.getColumnName(i);
Object obTemp = null;
obTemp = rset.getObject(i);
if (rset.getObject(i) instanceof java.lang.String) {
try {
obTemp = unicodeToWin(rset.getObject(i)
.toString());
} catch (Exception e) {
// e.printStackTrace();
}
}
row.put(name, obTemp == null ? "" : obTemp);
}
rows.add(row);
}
retList = rows;
if (retList.size() < 1) {
// 追加SQL文の編集
strUpdSQL = "";
strUpdSQL = strUpdSQL
+ "INSERT INTO LND_M_HOUZINBANGOU";
strUpdSQL = strUpdSQL
+ " (ID, BANGOU, INSERT_DATE, UPDATE_DATE)";
strUpdSQL = strUpdSQL + " VALUES (" + ID;
strUpdSQL = strUpdSQL + " , 1, SYSDATE, SYSDATE)";
} else {
HashMap hm = (HashMap) retList.get(0);
if (hm.get("BANGOU") != null) {
retBangou = Long.parseLong(hm.get("BANGOU")
.toString());
if (retBangou >= 9999999) {
retBangou = 1;
}
} else {
retBangou = 1;
}
}
}
// 更新SQL文の編集
strUpdSQL = "";
strUpdSQL = strUpdSQL + " UPDATE LND_M_HOUZINBANGOU";
strUpdSQL = strUpdSQL + " SET BANGOU = " + retBangou;
strUpdSQL = strUpdSQL + " , UPDATE_DATE = SYSDATE";
strUpdSQL = strUpdSQL + " WHERE ID = " + ID;
// 番号の更新実行
stmt = conn.prepareStatement(winToUnicode(strUpdSQL));
int RowCount = stmt.executeUpdate();
conn.commit();
if (stmt != null) {
stmt.close();
}
// MAX番号の取得
// 選択SQL文の編集
switch (ID) {
case Define.ID_ORG:
// 法人情報当初
strMaxSQL = "";
strMaxSQL = "SELECT MAX(HOUJINCODE) HOUJINCODE";
strMaxSQL = strMaxSQL + " FROM LND_T_HOUZINORG";
fieldNm = "HOUJINCODE";
break;
case Define.ID_NEW:
// 法人情報最新
strMaxSQL = "";
strMaxSQL = "SELECT MAX(HOUJINCODE) HOUJINCODE";
strMaxSQL = strMaxSQL + " FROM LND_T_HOUZINNEW";
fieldNm = "HOUJINCODE";
break;
case Define.ID_LOG:
// 法人情報更新ログ最新
strMaxSQL = "";
strMaxSQL = "SELECT MAX(HISTORY_ID) HISTORY_ID";
strMaxSQL = strMaxSQL + " FROM LND_T_LOG";
fieldNm = "HISTORY_ID";
break;
case Define.ID_RIREKI:
// 一括実行履歴
strMaxSQL = "";
strMaxSQL = "SELECT MAX(RIREKI_ID) RIREKI_ID";
strMaxSQL = strMaxSQL + " FROM LND_T_ZIKOURIREKI";
fieldNm = "RIREKI_ID";
break;
case Define.ID_ADDERR:
// 法人追加エラー
strMaxSQL = "";
strMaxSQL = "SELECT MAX(ID) ID";
strMaxSQL = strMaxSQL + " FROM LND_T_HOUZINADDERR";
fieldNm = "ID";
break;
case Define.ID_DELERR:
// 法人削除エラー
strMaxSQL = "";
strMaxSQL = "SELECT MAX(ID) ID";
fieldNm = "ID";
strMaxSQL = strMaxSQL + " FROM LND_T_HOUZINDELERR";
break;
}
// 実行
retList = new ArrayList();
retList = GetList(strMaxSQL);
if (retList.size() > 0) {
HashMap hm = (HashMap) retList.get(0);
if (hm.get(fieldNm) != null) {
maxID = Long.parseLong(hm.get(fieldNm).toString());
}
}
}
return retBangou;
} catch (SQLException sqle) {
throw new Exception(sqle);
} finally {
try {
if (stmt != null) {
stmt.close();
}
if (rset != null) {
rset.close();
}
if (conn != null) {
release(conn);
}
} catch (SQLException sqle) {
throw new Exception(sqle);
}
}
}