use of jp.ossc.nimbus.service.connection.ConnectionFactoryException in project nimbus by nimbus-org.
the class DatabaseScheduleStateManagerService method clearState.
// ScheduleStateManagerのJavaDoc
public void clearState(String name) {
Connection con = null;
PreparedStatement updatePs = null;
PreparedStatement deletePs = null;
try {
con = connectionFactory.getConnection();
if (scheduleStateDeleteQuery == null) {
updatePs = con.prepareStatement(scheduleStateUpdateQuery);
updatePs.setInt(1, STATE_UNKNOWN);
updatePs.setString(2, name);
updatePs.setTimestamp(3, new Timestamp(System.currentTimeMillis()));
updatePs.executeUpdate();
} else {
deletePs = con.prepareStatement(scheduleStateDeleteQuery);
deletePs.setString(1, name);
deletePs.executeUpdate();
}
} catch (ConnectionFactoryException e) {
getLogger().write(MSG_ID_00001, new Object[] { name, new Integer(STATE_UNKNOWN) }, e);
} catch (SQLException e) {
getLogger().write(MSG_ID_00001, new Object[] { name, new Integer(STATE_UNKNOWN) }, e);
} finally {
if (updatePs != null) {
try {
updatePs.close();
} catch (SQLException e) {
}
}
if (deletePs != null) {
try {
deletePs.close();
} catch (SQLException e) {
}
}
if (con != null) {
try {
con.close();
} catch (SQLException e) {
}
}
}
}
use of jp.ossc.nimbus.service.connection.ConnectionFactoryException in project nimbus by nimbus-org.
the class DatabaseScheduleStateManagerService method clearAllStates.
// ScheduleStateManagerのJavaDoc
public void clearAllStates() {
Connection con = null;
Statement st = null;
try {
con = connectionFactory.getConnection();
st = con.createStatement();
st.executeQuery(scheduleStateTruncateQuery);
} catch (ConnectionFactoryException e) {
getLogger().write(MSG_ID_00003, e);
} catch (SQLException e) {
getLogger().write(MSG_ID_00003, e);
} finally {
if (st != null) {
try {
st.close();
} catch (SQLException e) {
}
}
if (con != null) {
try {
con.close();
} catch (SQLException e) {
}
}
}
}
use of jp.ossc.nimbus.service.connection.ConnectionFactoryException in project nimbus by nimbus-org.
the class DatabaseDatasetFactoryService method createDataset.
// DatasetFactoryのJavaDoc
public Dataset createDataset(DatasetCondition[] dsConditions) throws DatasetCreateException {
// コネクションを取得
Connection conn = null;
try {
conn = connFactory.getConnection();
} catch (ConnectionFactoryException e) {
// コネクション取得失敗
throw new DatasetCreateException("Dataset [" + name + "]", e);
}
DatasetCondition[] conditions = null;
if (dsConditions != null && dsConditions.length > 0) {
// 引数のデータセット条件を設定
conditions = dsConditions;
}
if (conditions == null && dsConditionList.size() > 0) {
// サービス定義で設定されたデータセット条件を設定
conditions = (DatasetCondition[]) dsConditionList.toArray(new DatasetCondition[dsConditionList.size()]);
}
Dataset dataset = null;
// キーにシリーズ名、値にResultSet
Map seriesRsMap = new LinkedHashMap();
// すべてのPreparedStatementに適用するデータセット条件
List allConditions = new ArrayList();
// シリーズ名にマッピングされたデータセット条件
Map conditionMap = new HashMap();
if (conditions != null && conditions.length > 0) {
// 自分と同じデータセット名のデータセット条件を検索
for (int i = 0; i < conditions.length; i++) {
DatasetCondition dsCondition = conditions[i];
if (dsCondition instanceof DatabaseDatasetCondition && name.equals(dsCondition.getName())) {
String seriesName = conditions[i].getSeriesName();
if (seriesName == null) {
/*
* シリーズ名がないデータセット条件は
* すべてに適用するデータセット条件
*/
allConditions.add((DatabaseDatasetCondition) dsCondition);
} else {
if (conditionMap.containsKey(seriesName)) {
List list = (List) conditionMap.get(seriesName);
list.add(dsCondition);
} else {
List list = new ArrayList();
list.add(dsCondition);
// キーにシリーズ名、値にデータセット条件のリスト
conditionMap.put(seriesName, list);
}
}
}
}
}
try {
Iterator itr = seriesSqlMap.keySet().iterator();
while (itr.hasNext()) {
// シリーズ
String series = (String) itr.next();
PreparedStatement pstmt = conn.prepareStatement((String) seriesSqlMap.get(series), ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
pstmt.setFetchSize(fetchSize);
pstmt.setFetchDirection(ResultSet.FETCH_FORWARD);
if (allConditions.size() > 0) {
/*
* シリーズ名なしのデータセット条件を
* すべてのPreparedStatementに適用
*/
for (int i = 0; i < allConditions.size(); i++) {
DatabaseDatasetCondition condition = (DatabaseDatasetCondition) allConditions.get(i);
setObject(pstmt, condition);
}
} else if (conditionMap.containsKey(series)) {
// 各シリーズ用のデータセット条件をPreparedStatementに適用
List list = (List) conditionMap.get(series);
for (int i = 0; i < list.size(); i++) {
DatabaseDatasetCondition condition = (DatabaseDatasetCondition) list.get(i);
setObject(pstmt, condition);
}
}
// SQL実行
ResultSet rs = pstmt.executeQuery();
seriesRsMap.put(series, rs);
}
// シリーズ名の配列
String[] series = null;
// 検索結果の配列
ResultSet[] rSets = null;
if (seriesRsMap.size() > 0) {
series = (String[]) seriesRsMap.keySet().toArray(new String[seriesRsMap.size()]);
rSets = (ResultSet[]) seriesRsMap.values().toArray(new ResultSet[seriesRsMap.size()]);
}
// データセットを作る
dataset = createDataset(dsConditions, series, rSets);
} catch (SQLException e) {
// データベース関連
throw new DatasetCreateException("Dataset [" + name + "]", e);
} finally {
if (conn != null) {
try {
conn.close();
} catch (SQLException e) {
}
}
}
return dataset;
}
use of jp.ossc.nimbus.service.connection.ConnectionFactoryException in project nimbus by nimbus-org.
the class DatabaseOHLCDatasetFactoryService method createConnection.
protected DatasetConnection createConnection(DatasetCondition[] dsConditions) throws DatasetCreateException {
DateFormat dateFormat = null;
if (dateFormatServiceName != null) {
dateFormat = (DateFormat) ServiceManagerFactory.getServiceObject(dateFormatServiceName);
} else if (dateFormatPattern != null) {
dateFormat = new SimpleDateFormat(dateFormatPattern);
}
// コネクションを取得
Connection conn = null;
try {
conn = connFactory.getConnection();
} catch (ConnectionFactoryException e) {
// コネクション取得失敗
throw new DatasetCreateException("Dataset [" + getName() + "]", e);
}
DatasetConnection connection = new DatabaseOHLCDatasetConnection(getName(), conn);
DatabaseOHLCDatasetSeriesCursor cursor = new DatabaseOHLCDatasetSeriesCursor(seriesName, conn, sql, dateFormat);
for (int i = 0, imax = dsConditionList.size(); i < imax; i++) {
cursor.addCondition((DatasetCondition) dsConditionList.get(i));
}
if (dsConditions != null) {
for (int i = 0; i < dsConditions.length; i++) {
cursor.addCondition(dsConditions[i]);
}
}
cursor.execute();
connection.addSeriesCursor(cursor);
return connection;
}
use of jp.ossc.nimbus.service.connection.ConnectionFactoryException in project nimbus by nimbus-org.
the class DatabaseTimeSeriesCollectionFactoryService method createConnection.
protected DatasetConnection createConnection(DatasetCondition[] dsConditions) throws DatasetCreateException {
DateFormat dateFormat = null;
if (dateFormatServiceName != null) {
dateFormat = (DateFormat) ServiceManagerFactory.getServiceObject(dateFormatServiceName);
} else if (dateFormatPattern != null) {
dateFormat = new SimpleDateFormat(dateFormatPattern);
}
// コネクションを取得
Connection conn = null;
try {
conn = connFactory.getConnection();
} catch (ConnectionFactoryException e) {
// コネクション取得失敗
throw new DatasetCreateException("Dataset [" + getName() + "]", e);
}
DatasetConnection connection = new DatabaseTimeSeriesDatasetConnection(getName(), conn);
Iterator itr = seriesSqlMap.keySet().iterator();
while (itr.hasNext()) {
// シリーズ
String series = (String) itr.next();
DatabaseTimeSeriesCursor cursor = new DatabaseTimeSeriesCursor(series, conn, (String) seriesSqlMap.get(series), dateFormat);
for (int i = 0, imax = dsConditionList.size(); i < imax; i++) {
cursor.addCondition((DatasetCondition) dsConditionList.get(i));
}
if (dsConditions != null) {
for (int i = 0; i < dsConditions.length; i++) {
cursor.addCondition(dsConditions[i]);
}
}
cursor.execute();
connection.addSeriesCursor(cursor);
}
return connection;
}
Aggregations