Example usage for java.sql ResultSet TYPE_SCROLL_SENSITIVE

List of usage examples for java.sql ResultSet TYPE_SCROLL_SENSITIVE

Introduction

In this page you can find the example usage for java.sql ResultSet TYPE_SCROLL_SENSITIVE.

Prototype

int TYPE_SCROLL_SENSITIVE

To view the source code for java.sql ResultSet TYPE_SCROLL_SENSITIVE.

Click Source Link

Document

The constant indicating the type for a ResultSet object that is scrollable and generally sensitive to changes to the data that underlies the ResultSet.

Usage

From source file:org.apache.openjpa.jdbc.sql.PostgresDictionary.java

private void updatePostgresBlob(Row row, Column col, JDBCStore store, Object ob, Select sel)
        throws SQLException {
    JDBCFetchConfiguration fetch = store.getFetchConfiguration();
    SQLBuffer sql = sel.toSelect(true, fetch);
    ResultSet res = null;//  w  ww. j av  a2  s.  co  m
    DelegatingConnection conn = (DelegatingConnection) store.getConnection();
    PreparedStatement stmnt = null;
    try {
        stmnt = sql.prepareStatement(conn, fetch, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
        setTimeouts(stmnt, fetch, true);
        res = stmnt.executeQuery();
        if (!res.next()) {
            throw new InternalException(_loc.get("stream-exception"));
        }
        int oid = res.getInt(1);
        if (oid != -1) {
            conn.setAutoCommit(false);
            LargeObjectManager lom = getLargeObjectManager(conn);
            if (ob != null) {
                LargeObject lo = lom.open(oid, LargeObjectManager.WRITE);
                OutputStream os = lo.getOutputStream();
                long size = copy((InputStream) ob, os);
                lo.truncate((int) size);
                lo.close();
            } else {
                lom.delete(oid);
                row.setInt(col, -1);
            }
        } else {
            if (ob != null) {
                conn.setAutoCommit(false);
                LargeObjectManager lom = getLargeObjectManager(conn);
                oid = lom.create();
                LargeObject lo = lom.open(oid, LargeObjectManager.WRITE);
                OutputStream os = lo.getOutputStream();
                copy((InputStream) ob, os);
                lo.close();
                row.setInt(col, oid);
            }
        }

    } catch (IOException ioe) {
        throw new StoreException(ioe);
    } finally {
        if (res != null)
            try {
                res.close();
            } catch (SQLException e) {
            }
        if (stmnt != null)
            try {
                stmnt.close();
            } catch (SQLException e) {
            }
        if (conn != null)
            try {
                conn.close();
            } catch (SQLException e) {
            }
    }

}

From source file:com.commander4j.db.JDBUserReport.java

public boolean runReport() {
    PreparedStatement prepStatement;
    boolean result = true;

    try {//from   w  ww .ja va  2  s .c o  m
        prepStatement = Common.hostList.getHost(getHostID()).getConnection(getSessionID())
                .prepareStatement(getSQL(), ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
        prepStatement.setFetchSize(25);

        if (isParamDateRequired()) {
            prepStatement.setTimestamp(1, getParamFromDate());
            prepStatement.setTimestamp(2, getParamToDate());
        }

        if (getDestination().equals("SYSTEM")) {
            for (int x = 0; x < systemParams.size(); x++) {
                String type = systemParams.get(x).parameterType;

                if (type.toLowerCase().equals("string")) {
                    prepStatement.setString(systemParams.get(x).parameterPosition,
                            systemParams.get(x).parameterStringValue);
                }
                if (type.toLowerCase().equals("integer")) {
                    prepStatement.setInt(systemParams.get(x).parameterPosition,
                            systemParams.get(x).parameterIntegerValue);
                }
                if (type.toLowerCase().equals("long")) {
                    prepStatement.setLong(systemParams.get(x).parameterPosition,
                            systemParams.get(x).parameterLongValue);
                }
                if (type.toLowerCase().equals("timestamp")) {
                    prepStatement.setTimestamp(systemParams.get(x).parameterPosition,
                            systemParams.get(x).parameterTimestampValue);
                }
            }
        }

        ResultSet tempResult = prepStatement.executeQuery();

        boolean dataReturned = true;
        if (!tempResult.next()) {
            dataReturned = false;
        }
        tempResult.beforeFirst();
        if (dataReturned) {
            if (getDestination().equals("EXCEL")) {
                generateExcel(tempResult);
            }

            if (getDestination().equals("JASPER_REPORTS")) {
                generateJasper(prepStatement);
            }
            if (getDestination().equals("PDF")) {
                generatePDF(prepStatement);
            }
            if (getDestination().equals("ACCESS")) {
                generateAccess(tempResult);
            }

            if (getDestination().equals("CSV")) {
                generateCSV(tempResult);
            }

            if (getDestination().equals("SYSTEM")) {
                generateSYSTEM(tempResult);
            }

            if (isPreviewRequired()) {
                try {
                    Desktop.getDesktop().open(new File(getExportFilename()));
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            if (isEmailEnabled()) {

                String emailaddresses = getEmailAddresses();

                if (isEmailPromptEnabled()) {
                    emailaddresses = JUtility.replaceNullStringwithBlank(
                            JOptionPane.showInputDialog(lang.get("lbl_Email_Addresses")));
                }

                StringConverter stringConverter = new StringConverter();
                ArrayConverter arrayConverter = new ArrayConverter(String[].class, stringConverter);
                arrayConverter.setDelimiter(';');
                arrayConverter.setAllowedChars(new char[] { '@', '_' });

                String[] emailList = (String[]) arrayConverter.convert(String[].class, emailaddresses);

                if (emailList.length > 0) {
                    String shortFilename = JUtility.getFilenameFromPath(getExportFilename());
                    mail.postMail(emailList,
                            "Commande4j User Report requested by "
                                    + Common.userList.getUser(Common.sessionID).getUserId() + " from ["
                                    + Common.hostList.getHost(getHostID()).getSiteDescription() + "] on "
                                    + JUtility.getClientName(),
                            "See attached report.\n", shortFilename, getExportFilename());
                    com.commander4j.util.JWait.milliSec(2000);
                }
            }

        } else {
            result = false;
            setErrorMessage("No data returned by query.");
        }

    } catch (Exception ex) {
        setErrorMessage(ex.getMessage());
        result = false;
    }

    return result;
}

From source file:org.apache.openjpa.jdbc.sql.PostgresDictionary.java

public void deleteStream(JDBCStore store, Select sel) throws SQLException {
    JDBCFetchConfiguration fetch = store.getFetchConfiguration();
    SQLBuffer sql = sel.toSelect(true, fetch);
    ResultSet res = null;//from  www  . j a  v a 2s  .com
    DelegatingConnection conn = (DelegatingConnection) store.getConnection();
    PreparedStatement stmnt = null;
    try {
        stmnt = sql.prepareStatement(conn, fetch, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
        setTimeouts(stmnt, fetch, true);
        res = stmnt.executeQuery();
        if (!res.next()) {
            throw new InternalException(_loc.get("stream-exception"));
        }
        int oid = res.getInt(1);
        if (oid != -1) {
            conn.setAutoCommit(false);
            LargeObjectManager lom = getLargeObjectManager(conn);
            lom.delete(oid);
        }
    } finally {
        if (res != null)
            try {
                res.close();
            } catch (SQLException e) {
            }
        if (stmnt != null)
            try {
                stmnt.close();
            } catch (SQLException e) {
            }
        if (conn != null)
            try {
                conn.close();
            } catch (SQLException e) {
            }
    }
}

From source file:com.udps.hive.jdbc.HiveConnection.java

@Override
public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException {
    if (resultSetConcurrency != ResultSet.CONCUR_READ_ONLY) {
        throw new SQLException(
                "Statement with resultset concurrency " + resultSetConcurrency + " is not supported", "HYC00"); // Optional
        // feature
        // not/*w w w.  ja  va2s. c om*/
        // implemented
    }
    if (resultSetType == ResultSet.TYPE_SCROLL_SENSITIVE) {
        throw new SQLException("Statement with resultset type " + resultSetType + " is not supported", "HYC00"); // Optional
        // feature
        // not
        // implemented
    }
    return new HiveStatement(this, client, sessHandle, resultSetType == ResultSet.TYPE_SCROLL_INSENSITIVE);
}

From source file:org.springframework.jdbc.object.SqlQueryTests.java

public void testFancyCustomerQuery() throws SQLException {
    mockResultSet.next();/* www.  ja v  a 2s.  c  o  m*/
    ctrlResultSet.setReturnValue(true);
    mockResultSet.getInt("id");
    ctrlResultSet.setReturnValue(1);
    mockResultSet.getString("forename");
    ctrlResultSet.setReturnValue("rod");
    mockResultSet.next();
    ctrlResultSet.setReturnValue(false);
    mockResultSet.close();
    ctrlResultSet.setVoidCallable();

    mockPreparedStatement.setObject(1, new Integer(1), Types.NUMERIC);
    ctrlPreparedStatement.setVoidCallable();
    mockPreparedStatement.executeQuery();
    ctrlPreparedStatement.setReturnValue(mockResultSet);
    if (debugEnabled) {
        mockPreparedStatement.getWarnings();
        ctrlPreparedStatement.setReturnValue(null);
    }
    mockPreparedStatement.close();
    ctrlPreparedStatement.setVoidCallable();

    mockConnection.prepareStatement(SELECT_ID_FORENAME_WHERE, ResultSet.TYPE_SCROLL_SENSITIVE,
            ResultSet.CONCUR_READ_ONLY);
    ctrlConnection.setReturnValue(mockPreparedStatement);

    replay();

    class CustomerQuery extends MappingSqlQuery {

        public CustomerQuery(DataSource ds) {
            super(ds, SELECT_ID_FORENAME_WHERE);
            setResultSetType(ResultSet.TYPE_SCROLL_SENSITIVE);
            declareParameter(new SqlParameter(Types.NUMERIC));
            compile();
        }

        protected Object mapRow(ResultSet rs, int rownum) throws SQLException {
            Customer cust = new Customer();
            cust.setId(rs.getInt(COLUMN_NAMES[0]));
            cust.setForename(rs.getString(COLUMN_NAMES[1]));
            return cust;
        }

        public Customer findCustomer(int id) {
            return (Customer) findObject(id);
        }
    }

    CustomerQuery query = new CustomerQuery(mockDataSource);
    Customer cust = query.findCustomer(1);
    assertTrue("Customer id was assigned correctly", cust.getId() == 1);
    assertTrue("Customer forename was assigned correctly", cust.getForename().equals("rod"));
}

From source file:org.alinous.plugin.derby.DerbyDataSource.java

private List<Record> executeSelectSQL(Object connectionHandle, String sql, LimitOffsetClause limit,
        PostContext context, VariableRepository provider, AdjustWhere adjWhere, TypeHelper helper)
        throws DataSourceException, ExecutionException {
    Connection con = (Connection) connectionHandle;
    Statement stmt = null;/*from   www .j  av  a 2 s. com*/
    List<Record> retList = new LinkedList<Record>();

    try {
        stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
        stmt.execute(sql);

        ResultSet rs = stmt.getResultSet();

        ResultSetMetaData metaData = rs.getMetaData();

        if (limit != null && limit.isReady(context, provider, adjWhere)) {
            fetchWithOffset(rs, metaData, retList, limit, context, provider, adjWhere, helper);
        } else {
            while (rs.next()) {
                int cnt = metaData.getColumnCount();
                Record rec = new Record();
                for (int i = 0; i < cnt; i++) {
                    String colName = metaData.getColumnName(i + 1).toUpperCase();
                    String value = rs.getString(i + 1);

                    int colType = metaData.getColumnType(i + 1);
                    rec.addFieldValue(colName, value, colType);
                }

                retList.add(rec);
            }
        }

    } catch (SQLException e) {
        throw new DataSourceException(e);
    } finally {
        try {
            stmt.close();
        } catch (SQLException ignore) {
        }
    }

    return retList;
}

From source file:net.sf.jasperreports.engine.query.JRJdbcQueryExecuter.java

protected static int getResultSetType(String type) {
    if (TYPE_FORWARD_ONLY.equals(type)) {
        return ResultSet.TYPE_FORWARD_ONLY;
    } else if (TYPE_SCROLL_INSENSITIVE.equals(type)) {
        return ResultSet.TYPE_SCROLL_INSENSITIVE;
    } else if (TYPE_SCROLL_SENSITIVE.equals(type)) {
        return ResultSet.TYPE_SCROLL_SENSITIVE;
    }//from  w  w  w .j av  a2  s. co  m

    return ResultSet.TYPE_FORWARD_ONLY;
}

From source file:org.springframework.jdbc.object.SqlQueryTests.java

public void testUnnamedParameterDeclarationWithNamedParameterQuery() throws SQLException {
    replay();//from  ww  w. j a  v a2 s .c o m

    class CustomerQuery extends MappingSqlQuery {

        public CustomerQuery(DataSource ds) {
            super(ds, SELECT_ID_FORENAME_WHERE);
            setResultSetType(ResultSet.TYPE_SCROLL_SENSITIVE);
            declareParameter(new SqlParameter(Types.NUMERIC));
            compile();
        }

        protected Object mapRow(ResultSet rs, int rownum) throws SQLException {
            Customer cust = new Customer();
            cust.setId(rs.getInt(COLUMN_NAMES[0]));
            cust.setForename(rs.getString(COLUMN_NAMES[1]));
            return cust;
        }

        public Customer findCustomer(int id) {
            Map params = new HashMap();
            params.put("id", new Integer(id));
            return (Customer) executeByNamedParam(params).get(0);
        }
    }

    CustomerQuery query = new CustomerQuery(mockDataSource);
    try {
        Customer cust = query.findCustomer(1);
        fail("Query should not succeed since parameter declaration did not specify parameter name");
    } catch (InvalidDataAccessApiUsageException ex) {
        // OK - it worked
    }
}

From source file:com.alibaba.wasp.jdbc.result.JdbcDatabaseMetaData.java

/**
 * Returns whether a specific result set type is supported.
 * ResultSet.TYPE_SCROLL_SENSITIVE is not supported.
 * //  w w w .j  a  v a  2s  .c  o  m
 * @param type
 *          the result set type
 * @return true for all types except ResultSet.TYPE_FORWARD_ONLY
 */
public boolean supportsResultSetType(int type) {
    return type != ResultSet.TYPE_SCROLL_SENSITIVE;
}

From source file:com.alibaba.wasp.jdbc.result.JdbcDatabaseMetaData.java

/**
 * Returns whether a specific result set concurrency is supported.
 * ResultSet.TYPE_SCROLL_SENSITIVE is not supported.
 * /*from   www. j ava 2s.c  o m*/
 * @param type
 *          the result set type
 * @param concurrency
 *          the result set concurrency
 * @return true if the type is not ResultSet.TYPE_SCROLL_SENSITIVE
 */
public boolean supportsResultSetConcurrency(int type, int concurrency) {
    return type != ResultSet.TYPE_SCROLL_SENSITIVE;
}