Example usage for java.sql ResultSet getCharacterStream

List of usage examples for java.sql ResultSet getCharacterStream

Introduction

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

Prototype

java.io.Reader getCharacterStream(String columnLabel) throws SQLException;

Source Link

Document

Retrieves the value of the designated column in the current row of this ResultSet object as a java.io.Reader object.

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {
    Connection conn = getConnection();
    Statement st = conn.createStatement();

    st.executeUpdate("create table survey (Id int, b CLOB);");

    PreparedStatement pstmt = conn.prepareStatement("INSERT INTO survey VALUES(1,?)");

    File file = new File("c:/Java_Dev/data.txt");

    FileReader reader = new FileReader(file);
    pstmt.setCharacterStream(1, reader);

    pstmt.execute();/*from  w w  w .ja  v a 2  s.  c o m*/

    ResultSet resultSet = pstmt.executeQuery("select b from survey ");

    File data = new File("C:\\a.txt");
    Reader dataReader = resultSet.getCharacterStream(1);
    FileWriter writer = new FileWriter(data);
    char[] buffer = new char[1];
    while (dataReader.read(buffer) > 0) {
        writer.write(buffer);
    }
    writer.close();

    reader.close();
    st.close();
    conn.close();
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    Class.forName("oracle.jdbc.driver.OracleDriver");
    Connection conn = DriverManager.getConnection(url, username, password);
    PreparedStatement stmt = conn.prepareStatement("SELECT name, description, data FROM documents ");
    ResultSet resultSet = stmt.executeQuery();
    while (resultSet.next()) {
        String name = resultSet.getString(1);
        String description = resultSet.getString(2);
        File data = new File("C:\\a.txt");
        Reader reader = resultSet.getCharacterStream(3);
        FileWriter writer = new FileWriter(data);
        char[] buffer = new char[1];
        while (reader.read(buffer) > 0) {
            writer.write(buffer);/*from  w w w. j av  a2  s . c o m*/
        }
        writer.close();
    }
    conn.close();
}

From source file:io.cloudslang.content.database.services.SQLQueryLobService.java

public static boolean executeSqlQueryLob(SQLInputs sqlInputs) throws Exception {
    if (StringUtils.isEmpty(sqlInputs.getSqlCommand())) {
        throw new Exception("command input is empty.");
    }/*  w w w  .  j  a v  a  2s  . co  m*/
    boolean isLOB = false;
    ConnectionService connectionService = new ConnectionService();
    try (final Connection connection = connectionService.setUpConnection(sqlInputs)) {

        StringBuilder strColumns = new StringBuilder(sqlInputs.getStrColumns());

        connection.setReadOnly(true);
        Statement statement = connection.createStatement(sqlInputs.getResultSetType(),
                sqlInputs.getResultSetConcurrency());
        statement.setQueryTimeout(sqlInputs.getTimeout());

        ResultSet results = statement.executeQuery(sqlInputs.getSqlCommand());
        ResultSetMetaData mtd = results.getMetaData();
        int iNumCols = mtd.getColumnCount();
        for (int i = 1; i <= iNumCols; i++) {
            if (i > 1)
                strColumns.append(sqlInputs.getStrDelim());
            strColumns.append(mtd.getColumnLabel(i));
        }
        sqlInputs.setStrColumns(strColumns.toString());
        int nr = -1;
        while (results.next()) {
            nr++;
            final StringBuilder strRowHolder = new StringBuilder();
            for (int i = 1; i <= iNumCols; i++) {
                if (i > 1)
                    strRowHolder.append(sqlInputs.getStrDelim());
                Object columnObject = results.getObject(i);
                if (columnObject != null) {
                    String value;
                    if (columnObject instanceof java.sql.Clob) {
                        isLOB = true;
                        final File tmpFile = File.createTempFile("CLOB_" + mtd.getColumnLabel(i), ".txt");

                        copyInputStreamToFile(
                                new ReaderInputStream(results.getCharacterStream(i), StandardCharsets.UTF_8),
                                tmpFile);

                        if (sqlInputs.getLRowsFiles().size() == nr) {
                            sqlInputs.getLRowsFiles().add(nr, new ArrayList<String>());
                            sqlInputs.getLRowsNames().add(nr, new ArrayList<String>());
                        }
                        sqlInputs.getLRowsFiles().get(nr).add(tmpFile.getAbsolutePath());
                        sqlInputs.getLRowsNames().get(nr).add(mtd.getColumnLabel(i));
                        value = "(CLOB)...";

                    } else {
                        value = results.getString(i);
                        if (sqlInputs.isNetcool())
                            value = SQLUtils.processNullTerminatedString(value);
                    }
                    strRowHolder.append(value);
                } else
                    strRowHolder.append("null");
            }
            sqlInputs.getLRows().add(strRowHolder.toString());
        }
    }

    return isLOB;
}

From source file:com.sfs.dao.SettingsDAOImpl.java

/**
 * Loads a menu xml document from the database and returns it within a
 * SettingsBean.//w w  w.  j a  v  a2 s  . c om
 *
 * @param type the type
 *
 * @return the settings bean
 *
 * @throws SFSDaoException the SFS dao exception
 */
public final SettingsBean loadSettings(final String type) throws SFSDaoException {

    if (type == null) {
        throw new SFSDaoException("The settings type cannot be null");
    }

    SettingsBean settingsBean = null;

    try {
        settingsBean = (SettingsBean) this.getJdbcTemplateReader().queryForObject(
                this.getSQL().getValue("settings/load"), new Object[] { type }, new RowMapper() {
                    public Object mapRow(final ResultSet rs, final int rowNum) throws SQLException {

                        SettingsBean loadedSettings = new SettingsBean();
                        loadedSettings.setType(type);

                        Reader settingsStream = rs.getCharacterStream("Settings");
                        SAXBuilder builder = new SAXBuilder();
                        try {
                            loadedSettings.setXmlDocument(builder.build(settingsStream));
                            dataLogger.info("XML settings file parsed " + "successfully");
                        } catch (JDOMException jde) {
                            dataLogger.fatal("Error parsing XML settings: " + jde.getMessage());
                        } catch (IOException ioe) {
                            dataLogger.fatal("Error reading XML character " + "stream: " + ioe.getMessage());
                        }
                        return loadedSettings;
                    }
                });

    } catch (IncorrectResultSizeDataAccessException ie) {
        dataLogger.debug("No results found for this search: " + ie.getMessage());
    }
    return settingsBean;
}

From source file:nl.ordina.bag.etl.dao.AbstractBAGMutatiesDAO.java

@Override
public List<BAGMutatie> getNextBAGMutaties() {
    try {//from w  w w . j a v  a  2s.  c  o  m
        List<BAGMutatie> result = jdbcTemplate
                .query("select id, tijdstip_verwerking, volgnr_verwerking, object_type, mutatie_product"
                        + " from bag_mutatie"
                        + " where tijdstip_verwerking = (select min(tijdstip_verwerking) from bag_mutatie)"
                        + " order by volgnr_verwerking asc", new RowMapper<BAGMutatie>() {
                            @Override
                            public BAGMutatie mapRow(ResultSet rs, int row) throws SQLException {
                                try {
                                    BAGMutatie result = new BAGMutatie();
                                    result.setId(rs.getLong("id"));
                                    result.setTijdstipVerwerking(Utils
                                            .toXMLGregorianCalendar(rs.getTimestamp("tijdstip_verwerking")));
                                    result.setVolgnrVerwerking(rs.getInt("volgnr_verwerking"));
                                    result.setObjectType(BAGObjectType.values()[rs.getInt("object_type")]);
                                    result.setMutatieProduct(XMLMessageBuilder.getInstance(MutatieProduct.class)
                                            .handle(rs.getCharacterStream("mutatie_product"),
                                                    MutatieProduct.class));
                                    return result;
                                } catch (JAXBException e) {
                                    throw new DAOException(e);
                                }
                            }
                        });
        return result;
    } catch (DataAccessException e) {
        throw new DAOException(e);
    }
}

From source file:com.nabla.dc.server.handler.company.ImportAccountListHandler.java

private boolean add(final ImportAccountList cmd, final ImportErrorManager errors, final IUserSessionContext ctx)
        throws DispatchException, SQLException {
    final PreparedStatement stmtFile = StatementFormat.prepare(ctx.getReadConnection(),
            "SELECT content, userSessionId FROM import_data WHERE id=?;", cmd.getBatchId());
    try {/*from   w w w  .  jav a2  s  . co  m*/
        final ResultSet rs = stmtFile.executeQuery();
        try {
            if (!rs.next()) {
                errors.add(CommonServerErrors.NO_DATA);
                return false;
            }
            if (!ctx.getSessionId().equals(rs.getString("userSessionId"))) {
                if (log.isTraceEnabled())
                    log.trace("invalid user session ID");
                errors.add(CommonServerErrors.ACCESS_DENIED);
                return false;
            }
            final Connection conn = ctx.getWriteConnection();
            final LockTableGuard lock = new LockTableGuard(conn, "account WRITE");
            try {
                final ConnectionTransactionGuard guard = new ConnectionTransactionGuard(conn);
                try {
                    SqlInsertOptions option = cmd.getOverwrite();
                    if (option == SqlInsertOptions.REPLACE) {
                        Database.executeUpdate(ctx.getWriteConnection(),
                                "UPDATE account SET uname=NULL WHERE company_id=?;", cmd.getCompanyId());
                        option = SqlInsertOptions.OVERWRITE;
                    }
                    final SqlInsert<AddAccount> sql = new SqlInsert<AddAccount>(AddAccount.class, option);
                    final BatchInsertStatement<AddAccount> stmt = sql
                            .prepareBatchStatement(ctx.getWriteConnection());
                    try {
                        final AccountCsvReader csv = new AccountCsvReader(rs.getCharacterStream("content"),
                                conn, cmd.getCompanyId(), errors);
                        try {
                            if (!csv.read(cmd.isRowHeader(), stmt))
                                return false;
                        } finally {
                            csv.close();
                        }
                        stmt.execute();
                    } finally {
                        stmt.close();
                    }
                    UserPreference.save(ctx, null, IImportAccounts.PREFERENCE_GROUP, IImportAccounts.ROW_HEADER,
                            cmd.isRowHeader());
                    UserPreference.save(ctx, null, IImportAccounts.PREFERENCE_GROUP, IImportAccounts.OVERWRITE,
                            cmd.getOverwrite());
                    guard.setSuccess();
                    return true;
                } finally {
                    guard.close();
                }
            } finally {
                lock.close();
            }
        } finally {
            rs.close();
        }
    } finally {
        stmtFile.close();
    }
}

From source file:helma.objectmodel.db.NodeManager.java

/**
 *  Create a new Node from a ResultSet.//from  w w  w.  ja  va2s .co  m
 */
public Node createNode(DbMapping dbm, ResultSet rs, DbColumn[] columns, int offset)
        throws SQLException, IOException, ClassNotFoundException {
    HashMap propBuffer = new HashMap();
    String id = null;
    String name = null;
    String protoName = dbm.getTypeName();
    DbMapping dbmap = dbm;

    Node node = new Node(safe);

    for (int i = 0; i < columns.length; i++) {

        int columnNumber = i + 1 + offset;

        // set prototype?
        if (columns[i].isPrototypeField()) {
            String protoId = rs.getString(columnNumber);
            protoName = dbm.getPrototypeName(protoId);

            if (protoName != null) {
                dbmap = getDbMapping(protoName);

                if (dbmap == null) {
                    // invalid prototype name!
                    app.logError("No prototype defined for prototype mapping \"" + protoName
                            + "\" - Using default prototype \"" + dbm.getTypeName() + "\".");
                    dbmap = dbm;
                    protoName = dbmap.getTypeName();
                }
            }
        }

        // set id?
        if (columns[i].isIdField()) {
            id = rs.getString(columnNumber);
            // if id == null, the object doesn't actually exist - return null
            if (id == null) {
                return null;
            }
        }

        // set name?
        if (columns[i].isNameField()) {
            name = rs.getString(columnNumber);
        }

        Property newprop = new Property(node);

        switch (columns[i].getType()) {
        case Types.BIT:
        case Types.BOOLEAN:
            newprop.setBooleanValue(rs.getBoolean(columnNumber));

            break;

        case Types.TINYINT:
        case Types.BIGINT:
        case Types.SMALLINT:
        case Types.INTEGER:
            newprop.setIntegerValue(rs.getLong(columnNumber));

            break;

        case Types.REAL:
        case Types.FLOAT:
        case Types.DOUBLE:
            newprop.setFloatValue(rs.getDouble(columnNumber));

            break;

        case Types.DECIMAL:
        case Types.NUMERIC:

            BigDecimal num = rs.getBigDecimal(columnNumber);
            if (num == null) {
                break;
            }
            if (num.scale() > 0) {
                newprop.setFloatValue(num.doubleValue());
            } else {
                newprop.setIntegerValue(num.longValue());
            }

            break;

        case Types.VARBINARY:
        case Types.BINARY:
            newprop.setJavaObjectValue(rs.getBytes(columnNumber));

            break;

        case Types.BLOB:
        case Types.LONGVARBINARY: {
            InputStream in = rs.getBinaryStream(columnNumber);
            if (in == null) {
                break;
            }
            ByteArrayOutputStream bout = new ByteArrayOutputStream();
            byte[] buffer = new byte[2048];
            int read;
            while ((read = in.read(buffer)) > -1) {
                bout.write(buffer, 0, read);
            }
            newprop.setJavaObjectValue(bout.toByteArray());
        }

            break;

        case Types.LONGVARCHAR:
            try {
                newprop.setStringValue(rs.getString(columnNumber));
            } catch (SQLException x) {
                Reader in = rs.getCharacterStream(columnNumber);
                if (in == null) {
                    newprop.setStringValue(null);
                    break;
                }
                StringBuffer out = new StringBuffer();
                char[] buffer = new char[2048];
                int read;
                while ((read = in.read(buffer)) > -1) {
                    out.append(buffer, 0, read);
                }
                newprop.setStringValue(out.toString());
            }

            break;

        case Types.CHAR:
        case Types.VARCHAR:
        case Types.OTHER:
            newprop.setStringValue(rs.getString(columnNumber));

            break;

        case Types.DATE:
        case Types.TIME:
        case Types.TIMESTAMP:
            newprop.setDateValue(rs.getTimestamp(columnNumber));

            break;

        case Types.NULL:
            newprop.setStringValue(null);

            break;

        case Types.CLOB:
            Clob cl = rs.getClob(columnNumber);
            if (cl == null) {
                newprop.setStringValue(null);
                break;
            }
            char[] c = new char[(int) cl.length()];
            Reader isr = cl.getCharacterStream();
            isr.read(c);
            newprop.setStringValue(String.copyValueOf(c));
            break;

        default:
            newprop.setStringValue(rs.getString(columnNumber));

            break;
        }

        if (rs.wasNull()) {
            newprop.setStringValue(null);
        }

        propBuffer.put(columns[i].getName(), newprop);

        // mark property as clean, since it's fresh from the db
        newprop.dirty = false;
    }

    if (id == null) {
        return null;
    } else {
        Transactor tx = Transactor.getInstance();
        if (tx != null) {
            // Check if the node is already registered with the transactor -
            // it may be in the process of being DELETED, but do return the
            // new node if the old one has been marked as INVALID.
            DbKey key = new DbKey(dbmap, id);
            Node dirtyNode = tx.getDirtyNode(key);
            if (dirtyNode != null && dirtyNode.getState() != Node.INVALID) {
                return dirtyNode;
            }
        }
    }

    Hashtable propMap = new Hashtable();
    DbColumn[] columns2 = dbmap.getColumns();
    for (int i = 0; i < columns2.length; i++) {
        Relation rel = columns2[i].getRelation();
        if (rel != null && rel.isPrimitiveOrReference()) {
            Property prop = (Property) propBuffer.get(columns2[i].getName());

            if (prop == null) {
                continue;
            }

            prop.setName(rel.propName);

            // if the property is a pointer to another node, change the property type to NODE
            if (rel.isReference() && rel.usesPrimaryKey()) {
                // FIXME: References to anything other than the primary key are not supported
                prop.convertToNodeReference(rel);
            }
            propMap.put(rel.propName, prop);
        }
    }

    node.init(dbmap, id, name, protoName, propMap);
    return node;
}

From source file:com.github.woonsan.jdbc.jcr.impl.JcrJdbcResultSetTest.java

private void assertWrongValueFormatColumn(final ResultSet rs) throws Exception {
    assertFalse(rs.getBoolean(2));/* w ww.j a  va  2 s.c  o m*/
    assertFalse(rs.getBoolean("ename"));

    try {
        rs.getShort(2);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getShort("ename");
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getInt(2);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getInt("ename");
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getLong(2);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getLong("ename");
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getFloat(2);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getFloat("ename");
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getDouble(2);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getDouble("ename");
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getBigDecimal(2);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getBigDecimal("ename");
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getBytes(2);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getBytes("ename");
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getDate(2);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getDate("ename");
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getDate(2, Calendar.getInstance());
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getDate("ename", Calendar.getInstance());
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getTime(2);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getTime("ename");
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getTime(2, Calendar.getInstance());
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getTime("ename", Calendar.getInstance());
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getTimestamp(2);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getTimestamp("ename");
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getTimestamp(2, Calendar.getInstance());
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getTimestamp("ename", Calendar.getInstance());
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getAsciiStream(2);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getAsciiStream("ename");
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getBinaryStream(2);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getBinaryStream("ename");
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getCharacterStream(2);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getCharacterStream("ename");
        fail();
    } catch (SQLException ignore) {
    }

}

From source file:axiom.objectmodel.db.NodeManager.java

/**
 *  Create a new Node from a ResultSet./*from   w  w w.  jav a  2  s. c  om*/
 */
public Node createNode(DbMapping dbm, ResultSet rs, DbColumn[] columns, int offset)
        throws SQLException, IOException, ClassNotFoundException {
    HashMap propBuffer = new HashMap();
    String id = null;
    String name = null;
    String protoName = dbm.getTypeName();
    DbMapping dbmap = dbm;

    Node node = new Node();

    for (int i = 0; i < columns.length; i++) {
        // set prototype?
        if (columns[i].isPrototypeField()) {
            protoName = rs.getString(i + 1 + offset);

            if (protoName != null) {
                dbmap = getDbMapping(protoName);

                if (dbmap == null) {
                    // invalid prototype name!
                    app.logError(ErrorReporter.errorMsg(this.getClass(), "createNode")
                            + "Invalid prototype name: " + protoName + " - using default");
                    dbmap = dbm;
                    protoName = dbmap.getTypeName();
                }
            }
        }

        // set id?
        if (columns[i].isIdField()) {
            id = rs.getString(i + 1 + offset);
            // if id == null, the object doesn't actually exist - return null
            if (id == null) {
                return null;
            }
        }

        // set name?
        if (columns[i].isNameField()) {
            name = rs.getString(i + 1 + offset);
        }

        Property newprop = new Property(node);

        switch (columns[i].getType()) {
        case Types.BIT:
            newprop.setBooleanValue(rs.getBoolean(i + 1 + offset));

            break;

        case Types.TINYINT:
        case Types.BIGINT:
        case Types.SMALLINT:
        case Types.INTEGER:
            newprop.setIntegerValue(rs.getLong(i + 1 + offset));

            break;

        case Types.REAL:
        case Types.FLOAT:
        case Types.DOUBLE:
            newprop.setFloatValue(rs.getDouble(i + 1 + offset));

            break;

        case Types.DECIMAL:
        case Types.NUMERIC:

            BigDecimal num = rs.getBigDecimal(i + 1 + offset);

            if (num == null) {
                break;
            }

            if (num.scale() > 0) {
                newprop.setFloatValue(num.doubleValue());
            } else {
                newprop.setIntegerValue(num.longValue());
            }

            break;

        case Types.VARBINARY:
        case Types.BINARY:
            //                    newprop.setStringValue(rs.getString(i+1+offset));
            newprop.setJavaObjectValue(rs.getBytes(i + 1 + offset));

            break;

        case Types.LONGVARBINARY: {
            InputStream in = rs.getBinaryStream(i + 1 + offset);
            if (in == null) {
                break;
            }
            ByteArrayOutputStream bout = new ByteArrayOutputStream();
            byte[] buffer = new byte[2048];
            int read;
            while ((read = in.read(buffer)) > -1) {
                bout.write(buffer, 0, read);
            }
            newprop.setJavaObjectValue(bout.toByteArray());
        }

            break;
        case Types.LONGVARCHAR:
            try {
                newprop.setStringValue(rs.getString(i + 1 + offset));
            } catch (SQLException x) {
                Reader in = rs.getCharacterStream(i + 1 + offset);
                char[] buffer = new char[2048];
                int read = 0;
                int r;

                while ((r = in.read(buffer, read, buffer.length - read)) > -1) {
                    read += r;

                    if (read == buffer.length) {
                        // grow input buffer
                        char[] newBuffer = new char[buffer.length * 2];

                        System.arraycopy(buffer, 0, newBuffer, 0, buffer.length);
                        buffer = newBuffer;
                    }
                }

                newprop.setStringValue(new String(buffer, 0, read));
            }

            break;

        case Types.CHAR:
        case Types.VARCHAR:
        case Types.OTHER:
            newprop.setStringValue(rs.getString(i + 1 + offset));

            break;

        case Types.DATE:
        case Types.TIME:
        case Types.TIMESTAMP:
            newprop.setDateValue(rs.getTimestamp(i + 1 + offset));

            break;

        case Types.NULL:
            newprop.setStringValue(null);

            break;

        case Types.CLOB:
            Clob cl = rs.getClob(i + 1 + offset);
            if (cl == null) {
                newprop.setStringValue(null);
                break;
            }
            char[] c = new char[(int) cl.length()];
            Reader isr = cl.getCharacterStream();
            isr.read(c);
            newprop.setStringValue(String.copyValueOf(c));
            break;

        default:
            newprop.setStringValue(rs.getString(i + 1 + offset));

            break;
        }

        if (rs.wasNull()) {
            newprop.setStringValue(null);
        }

        propBuffer.put(columns[i].getName(), newprop);

        // mark property as clean, since it's fresh from the db
        newprop.dirty = false;
    }

    if (id == null) {
        return null;
    }

    Hashtable propMap = new Hashtable();
    DbColumn[] columns2 = dbmap.getColumns();
    for (int i = 0; i < columns2.length; i++) {
        Relation rel = columns2[i].getRelation();

        if (rel != null && (rel.reftype == Relation.PRIMITIVE || rel.reftype == Relation.REFERENCE)) {

            Property prop = (Property) propBuffer.get(columns2[i].getName());

            if (prop == null) {
                continue;
            }
            prop.setName(rel.propName);
            // if the property is a pointer to another node, change the property type to NODE
            if ((rel.reftype == Relation.REFERENCE) && rel.usesPrimaryKey()) {
                // FIXME: References to anything other than the primary key are not supported
                prop.convertToNodeReference(rel.otherType, this.app.getCurrentRequestEvaluator().getLayer());
            }
            propMap.put(rel.propName.toLowerCase(), prop);
        }
    }

    node.init(dbmap, id, name, protoName, propMap, safe);

    return node;
}

From source file:com.github.woonsan.jdbc.jcr.impl.JcrJdbcResultSetTest.java

@SuppressWarnings("deprecation")
private void assertNonExistingColumn(final ResultSet rs) throws Exception {
    int nonExistingColIndex = Integer.MAX_VALUE;
    String nonExistingColName = "col" + nonExistingColIndex;

    try {//from w w w. j  a v a 2 s .co m
        rs.getString(nonExistingColIndex);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getString(nonExistingColName);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getBoolean(nonExistingColIndex);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getBoolean(nonExistingColName);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getByte(nonExistingColIndex);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getByte(nonExistingColName);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getShort(nonExistingColIndex);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getShort(nonExistingColName);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getInt(nonExistingColIndex);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getInt(nonExistingColName);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getLong(nonExistingColIndex);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getLong(nonExistingColName);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getFloat(nonExistingColIndex);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getFloat(nonExistingColName);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getDouble(nonExistingColIndex);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getDouble(nonExistingColName);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getBigDecimal(nonExistingColIndex);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getBigDecimal(nonExistingColName);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getBigDecimal(nonExistingColIndex, 1);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getBigDecimal(nonExistingColName, 1);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getBytes(nonExistingColIndex);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getBytes(nonExistingColName);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getDate(nonExistingColIndex);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getDate(nonExistingColName);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getDate(nonExistingColIndex, null);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getDate(nonExistingColName, null);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getTime(nonExistingColIndex);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getTime(nonExistingColName);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getTime(nonExistingColIndex, null);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getTime(nonExistingColName, null);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getTimestamp(nonExistingColIndex);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getTimestamp(nonExistingColName);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getTimestamp(nonExistingColIndex, null);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getTimestamp(nonExistingColName, null);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getAsciiStream(nonExistingColIndex);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getAsciiStream(nonExistingColName);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getUnicodeStream(nonExistingColIndex);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getUnicodeStream(nonExistingColName);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getBinaryStream(nonExistingColIndex);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getBinaryStream(nonExistingColName);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getCharacterStream(nonExistingColIndex);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getCharacterStream(nonExistingColName);
        fail();
    } catch (SQLException ignore) {
    }

}