📄 intramartdbconnector.java
字号:
/*
* IntramartDBConnector.java
*
* Created on 2002/02/19, 16:09
*/
package jp.co.intra_mart.framework.base.data;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
import javax.naming.NamingException;
import jp.co.intra_mart.foundation.database.DbsConnection;
import jp.co.intra_mart.foundation.security.exception.AccessSecurityException;
import jp.co.intra_mart.foundation.security.exception.NotExistException;
import jp.co.intra_mart.system.database.DbsConnectionImpl;
/**
* 僀儞僩儔儅乕僩偱愝掕偝傟偰偄傞DB僐僱僋僔儑儞偱偡丅
*
* @author INTRAMART
* @version 1.0
* @deprecated 偙偺僋儔僗偱偼側偔{@link LoginGroupDBConnector}傑偨偼
* {@link SystemDBConnector}傪巊梡偟偰偔偩偝偄丅
*/
public class IntramartDBConnector extends DataConnector {
/**
* DbsConnection偺堦棗
*/
protected Map connections;
/**
* IntramartDBConnector傪怴婯偵惗惉偟傑偡丅
*/
public IntramartDBConnector() {
super();
this.connections = new HashMap();
}
/**
* 僐儈僢僩偟傑偡丅
*
* @throws DataConnectException 僐儈僢僩偵幐攕
*/
public void commit() throws DataConnectException {
Iterator connectionsIterator;
DbsConnection connection;
DataConnectException exception = null;
if (this.connections != null) {
connectionsIterator = this.connections.values().iterator();
while (connectionsIterator.hasNext()) {
connection = (DbsConnection)connectionsIterator.next();
try {
connection.commit();
} catch (Exception e) {
String message = null;
try {
message =
ResourceBundle.getBundle(
"jp.co.intra_mart.framework.base.data.i18n")
.getString(
"Common.FailedToCommit");
} catch (MissingResourceException ex) {
}
exception = new DataConnectException(message, e);
}
}
}
if (exception != null) {
throw exception;
}
}
/**
* 儘乕儖僶僢僋偟傑偡丅
*
* @throws DataConnectException 儘乕儖僶僢僋偵幐攕
*/
public void rollback() throws DataConnectException {
Iterator connectionsIterator;
DbsConnection connection;
DataConnectException exception = null;
if (this.connections != null) {
connectionsIterator = this.connections.values().iterator();
while (connectionsIterator.hasNext()) {
connection = (DbsConnection)connectionsIterator.next();
try {
connection.rollback();
} catch (Exception e) {
String message = null;
try {
message =
ResourceBundle.getBundle(
"jp.co.intra_mart.framework.base.data.i18n")
.getString(
"Common.FailedToRollBack");
} catch (MissingResourceException ex) {
}
exception = new DataConnectException(message, e);
}
}
}
if (exception != null) {
throw exception;
}
}
/**
* 僨乕僞僗僩傾偺帒尮傪夝曻偟傑偡丅
*
* @throws DataConnectException 帒尮奐曻偵幐攕
*/
public void release() throws DataConnectException {
Iterator connectionsIterator;
DbsConnection connection;
DataConnectException exception = null;
String key;
if (this.connections != null) {
connectionsIterator = this.connections.keySet().iterator();
while (connectionsIterator.hasNext()) {
key = (String)connectionsIterator.next();
connection = (DbsConnection)this.connections.get(key);
try {
connection.release();
} catch (Exception e) {
String message = null;
try {
message =
ResourceBundle.getBundle(
"jp.co.intra_mart.framework.base.data.i18n")
.getString(
"Common.FailedToReleaseResource");
} catch (MissingResourceException ex) {
}
exception = new DataConnectException(message, e);
}
}
}
this.connections.clear();
if (exception != null) {
throw exception;
}
}
/**
* 僐僱僋僔儑儞忣曬傪捛壛偟傑偡丅
*
* @param connect 愙懕忣曬
* @throws DataConnectException 愙懕偵幐攕
* @return 僐僱僋僔儑儞
*/
private DbsConnection putResource(String connect)
throws DataConnectException {
DbsConnection result = null;
try {
result = new DbsConnectionImpl(connect);
} catch (SQLException e) {
throw new DataConnectException(e.getMessage(), e);
} catch (NotExistException e) {
throw new DataConnectException(e.getMessage(), e);
} catch (AccessSecurityException e) {
throw new DataConnectException(e.getMessage(), e);
} catch (NamingException e) {
throw new DataConnectException(e.getMessage(), e);
}
// 僐僱僋僔儑儞傪捛壛
this.connections.put(connect, result);
return result;
}
/**
* 儕僜乕僗傪庢摼偟傑偡丅
*
* @param key 僉乕
* @param connect 愙懕忣曬
* @param resource 儕僜乕僗柤
* @return 儕僜乕僗
* @throws DataPropertyException 儕僜乕僗偺庢摼偵幐攕
* @throws DataConnectException 愙懕偵幐攕
*/
protected Object getResource(String key, String connect, String resource)
throws DataPropertyException, DataConnectException {
Object obj = this.connections.get(connect);
if (obj == null) {
obj = putResource(connect);
}
return obj;
}
/**
* 僨乕僞儀乕僗傊偺僐僱僋僔儑儞傪庢摼偟傑偡丅
*
* @param connect 愙懕忣曬
* @return 僨乕僞儀乕僗傊偺僐僱僋僔儑儞
* @throws DataPropertyException 僨乕僞儀乕僗傊偺僐僱僋僔儑儞偺庢摼偵幐攕
* @throws DataConnectException 僨乕僞儀乕僗傊偺愙懕偵幐攕
*/
public DbsConnection getConnection(String connect)
throws DataPropertyException, DataConnectException {
return (DbsConnection)getResource("", connect, "");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -