Example usage for javax.sql.rowset RowSetProvider newFactory

List of usage examples for javax.sql.rowset RowSetProvider newFactory

Introduction

In this page you can find the example usage for javax.sql.rowset RowSetProvider newFactory.

Prototype

public static RowSetFactory newFactory() throws SQLException 

Source Link

Document

Creates a new instance of a RowSetFactory implementation.

Usage

From source file:com.kumarvv.setl.utils.RowSetUtil.java

/**
 * @return builds and returns source row set
 *//*w  ww.  j  a  va 2s. com*/
public JdbcRowSet getRowSet(DS ds) throws SQLException {
    if (ds == null) {
        throw new SQLException("Invalid DS");
    }

    if (rowSetFactory == null) {
        rowSetFactory = RowSetProvider.newFactory();
    }

    loadDriver(ds);

    JdbcRowSet jrs = rowSetFactory.createJdbcRowSet();
    jrs.setUrl(ds.getUrl());
    jrs.setUsername(ds.getUsername());
    jrs.setPassword(ds.getPassword());

    return jrs;
}

From source file:com.jaspersoft.jasperserver.remote.dbservices.impl.MetaDataServiceImpl.java

/**
 * This method invokes a method ( a total of around 170 odd ) on the DatabaseMetaData object based on 
 * method name and parameters. If the result is a Resultset a CachedRowSet object is populated with 
 * its results and returned. Else all other types are returned as is.
 * @param request/*from   www  .j  av  a 2s.c o m*/
 * @return
 */

public byte[] getDBMetaData(Resource resource, CachedRowSetWrapper crw) {
    long startTime = System.currentTimeMillis();
    byte[] ret = new byte[0];
    Connection conn = null;
    Method method = null;
    CachedRowSet crs = null;
    Object result = null;
    try {
        if (logger.isDebugEnabled()) {
            logger.debug("Enter getDBMetaData .. Start Time" + System.currentTimeMillis());
        }
        if (crw.getParameters() != null) {
            for (int i = 0; i < crw.getParameters().length; i++) {
                Object param = crw.getParameters()[i];

                //if(param instanceof String && ((String) param).length() == 0){
                if (param instanceof String && StringUtil.isEmpty((String) param)) {
                    crw.getParameters()[i] = null; // make it null
                }
            }
        }
        conn = QueryUtil.getConnection(resource);
        DatabaseMetaData dm = conn.getMetaData();
        method = QueryUtil.findMethod(dm, crw.getRequestId(), crw.getParameters());
        if (null != method) {
            result = method.invoke(dm, crw.getParameters());
            if (null != result) {
                if (result instanceof java.sql.ResultSet) { // got a resultset
                    crs = RowSetProvider.newFactory().createCachedRowSet();
                    crs.populate((ResultSet) result);
                    ((java.sql.ResultSet) result).close(); // close the resultset
                    result = crs;
                }
                if (result instanceof Serializable) {
                    ret = JasperSerializationUtil.serialize((Serializable) result);
                } else {
                    logger.warn("Cannot serialize object" + result.getClass().getName());
                }
            } // if
        } else {
            throw new RemoteException(crw.getRequestId() + " method name is not supported.");
        }
    } catch (Exception ex) {
        logger.error(ex.getMessage(), ex);
        throw new RemoteException("Meta Data fail." + ex.getMessage());
    } finally {
        try {
            if (conn != null)
                conn.close();
            if (crs != null)
                crs.close();
        } catch (Exception ex) {
            logger.error(ex.getMessage(), ex);
            throw new RemoteException("Meta Data fail." + ex.getMessage());
        }
        if (logger.isDebugEnabled()) {
            long elapsedTime = System.currentTimeMillis() - startTime;
            logger.debug("Exit getDBMetaData .. Total Time Spent: " + elapsedTime);
        }
    }
    return ret;
}

From source file:at.ac.univie.isc.asio.engine.sql.JooqEngineTest.java

private WebRowSet parseWebRowSet(final byte[] raw) throws SQLException, IOException {
    final WebRowSet wrs = RowSetProvider.newFactory().createWebRowSet();
    wrs.readXml(new ByteArrayInputStream(raw));
    return wrs;/*from w  w  w  .ja  v a  2 s . co  m*/
}

From source file:uk.ac.ox.it.ords.api.database.structure.services.impl.hibernate.StructureServiceImpl.java

protected CachedRowSet runJDBCQuery(String query, List<Object> parameters, String server, int port,
        String databaseName, String userName, String password) throws Exception {
    Connection connection = null;
    Properties connectionProperties = new Properties();
    PreparedStatement preparedStatement = null;

    connectionProperties.put("user", userName);
    connectionProperties.put("password", password);

    String connectionURL = "jdbc:postgresql://" + server + ":" + port + "/" + databaseName;

    try {//from www . j  av  a  2 s . c om
        connection = DriverManager.getConnection(connectionURL, connectionProperties);
        preparedStatement = connection.prepareStatement(query);
        if (parameters != null) {
            int paramCount = 1;
            for (Object parameter : parameters) {
                @SuppressWarnings("rawtypes")
                Class type = parameter.getClass();
                if (type.equals(String.class)) {
                    preparedStatement.setString(paramCount, (String) parameter);
                }
                if (type.equals(Integer.class)) {
                    preparedStatement.setInt(paramCount, (Integer) parameter);
                }
                paramCount++;
            }

        }
        if (query.toLowerCase().startsWith("select")) {
            ResultSet result = preparedStatement.executeQuery();
            CachedRowSet rowSet = RowSetProvider.newFactory().createCachedRowSet();
            rowSet.populate(result);
            log.debug("prepareAndExecuteStatement:return result");
            return rowSet;
        } else {
            preparedStatement.execute();
            log.debug("prepareAndExecuteStatement:return null");
            return null;
        }

    } catch (SQLException e) {
        log.error("Error with this command", e);
        log.error("Query:" + query);
        throw e;
    } finally {
        if (preparedStatement != null) {
            preparedStatement.close();
        }
        if (connection != null) {
            connection.close();
        }
    }

}