public List<SqlDataItem> getDataItemList() { List<SqlDataItem> result = new ArrayList<SqlDataItem>(); if (mCurRow == 0 && !mClose) { try { next(); } catch (SQLException e) { Factory.getLogger() .log(Level.WARNING, "Unable to initialize group's data items children", e); } } if (mNbRows >= 0 && mCurRow == 1) { try { ResultSet set = getResultSet(); ResultSetMetaData meta = set.getMetaData(); int count = meta.getColumnCount(); // prepare columns names String[] names = new String[count]; SqlDataItem[] items = new SqlDataItem[count]; // Create a SQL array loader SqlArrayLoader loader = new SqlArrayLoader(this); SqlArray[] arrays = loader.getArrays(); // Get name for each items for (int col = 1; col <= count; col++) { // Get the name of the column names[col - 1] = meta.getColumnName(col); } // Fill the array asynchronously Thread thread = PostTreatmentManager.launchParallelTreatment(loader); // Create items for each arrays for (int col = 1; col <= count; col++) { // Create the data item try { items[col - 1] = new SqlDataItem( mDataset.getFactoryName(), (SqlGroup) mDataset.getRootGroup(), names[col - 1]); result.add(items[col - 1]); items[col - 1].setCachedData(arrays[col - 1], false); } catch (InvalidArrayTypeException e) { Factory.getLogger() .log( Level.SEVERE, "Unable to initialize data for the data item: " + names[col - 1], e); } } } catch (SQLException e) { Factory.getLogger().log(Level.WARNING, "Unable to initialize group's children", e); } } return result; }
private ResultSet executeQuery() throws SQLException { ResultSet result = null; if (!mInitialized) { prepareStatement(); } // Get the SQL connection SqlConnector sql_connector = mDataset.getSqlConnector(); if (sql_connector != null) { // Count number of result if (mNbRows < 0) { setParams(mStatCount); ResultSet tmp = mStatCount.executeQuery(); if (tmp.next()) { mNbRows = tmp.getInt(1); } } // Execute the query setParams(mStatQuery); result = mStatQuery.executeQuery(); } return result; }
private void prepareStatement() throws SQLException { // Get the SQL connection SqlConnector sql_connector = mDataset.getSqlConnector(); if (sql_connector != null) { try { Connection connection = sql_connector.getConnection(); // Check statements are still valid if (mStatQuery == null || mStatQuery.isClosed()) { // Create the query statement mStatQuery = connection.prepareStatement(mQuery); mStatQuery.setFetchSize(1000); } if (mStatCount == null || mStatCount.isClosed()) { // Create the count statement mStatCount = connection.prepareStatement("SELECT COUNT(*) FROM (" + mQuery + ")"); mStatCount.setFetchSize(1000); } } catch (IOException e) { mNbRows = -1; Factory.getLogger().log(Level.SEVERE, e.getMessage(), e); close(); } } mInitialized = true; }