Search in sources :

Example 1 with ConnectionFactoryException

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) {
            }
        }
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) Timestamp(java.sql.Timestamp) ConnectionFactoryException(jp.ossc.nimbus.service.connection.ConnectionFactoryException)

Example 2 with ConnectionFactoryException

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) {
            }
        }
    }
}
Also used : SQLException(java.sql.SQLException) Statement(java.sql.Statement) PreparedStatement(java.sql.PreparedStatement) Connection(java.sql.Connection) ConnectionFactoryException(jp.ossc.nimbus.service.connection.ConnectionFactoryException)

Example 3 with ConnectionFactoryException

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;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) SQLException(java.sql.SQLException) Dataset(org.jfree.data.general.Dataset) Connection(java.sql.Connection) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) ConnectionFactoryException(jp.ossc.nimbus.service.connection.ConnectionFactoryException) LinkedHashMap(java.util.LinkedHashMap) Iterator(java.util.Iterator) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 4 with ConnectionFactoryException

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;
}
Also used : SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) Connection(java.sql.Connection) SimpleDateFormat(java.text.SimpleDateFormat) ConnectionFactoryException(jp.ossc.nimbus.service.connection.ConnectionFactoryException)

Example 5 with ConnectionFactoryException

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;
}
Also used : SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) Connection(java.sql.Connection) Iterator(java.util.Iterator) SimpleDateFormat(java.text.SimpleDateFormat) ConnectionFactoryException(jp.ossc.nimbus.service.connection.ConnectionFactoryException)

Aggregations

ConnectionFactoryException (jp.ossc.nimbus.service.connection.ConnectionFactoryException)10 Connection (java.sql.Connection)9 SQLException (java.sql.SQLException)7 PreparedStatement (java.sql.PreparedStatement)5 ResultSet (java.sql.ResultSet)3 List (java.util.List)3 RecordList (jp.ossc.nimbus.beans.dataset.RecordList)3 PersistentException (jp.ossc.nimbus.service.connection.PersistentException)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Timestamp (java.sql.Timestamp)2 DateFormat (java.text.DateFormat)2 SimpleDateFormat (java.text.SimpleDateFormat)2 Iterator (java.util.Iterator)2 Record (jp.ossc.nimbus.beans.dataset.Record)2 Statement (java.sql.Statement)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 DataSet (jp.ossc.nimbus.beans.dataset.DataSet)1