Extract values from ResultSet and create a new lock.

@return org.apereo.portal.groups.IEntityLock
@param rs java.sql.ResultSet
196121
private IEntityLock instanceFromResultSet(java.sql.ResultSet rs)
            throws SQLException, LockingException {
        Integer entityTypeID = rs.getInt(1);
        Class entityType = EntityTypesLocator.getEntityTypes().getEntityTypeFromID(entityTypeID);
        String key = rs.getString(2);
        int lockType = rs.getInt(3);
        Timestamp ts = rs.getTimestamp(4);
        String lockOwner = rs.getString(5);

        return newInstance(entityType, key, lockType, ts, lockOwner);
    }
653970
private IEntityLock[] primSelect(String sql) throws LockingException {
        Connection conn = null;
        Statement stmnt = null;
        ResultSet rs = null;
        List locks = new ArrayList();

        if (log.isDebugEnabled()) log.debug("RDBMEntityLockStore.primSelect(): " + sql);

        try {
            conn = RDBMServices.getConnection();
            stmnt = conn.createStatement();
            try {
                rs = stmnt.executeQuery(sql);
                try {
                    while (rs.next()) {
                        locks.add(instanceFromResultSet(rs));
                    }
                } finally {
                    rs.close();
                }
            } finally {
                stmnt.close();
            }
        } catch (SQLException sqle) {
            log.error(sqle, sqle);
            throw new LockingException("Problem retrieving EntityLocks", sqle);
        } finally {
            RDBMServices.releaseConnection(conn);
        }

        return ((IEntityLock[]) locks.toArray(new IEntityLock[locks.size()]));
    }
596112
private IEntityLock[] retrieveLocks(Class entityType, String entityKey, Integer lockType)
            throws LockingException {
        Date expiration =
                (multiServer)
                        ? new Date(System.currentTimeMillis() - getLockToleranceMillis())
                        : new Date();

        return getLockStore().findUnexpired(expiration, entityType, entityKey, lockType, null);
    }
1059559
@Override
    public DataBinder process(ResultSet rset) throws Exception {
        try {
            if (rset.next()) {
                ResultSetMetaData meta = rset.getMetaData();
                int width = meta.getColumnCount();
                for (int i = 1; i <= width; ++i) {
                    Object value = rset.getObject(i);
                    if (value != null) {
                        put(Strings.toLowerCamelCase(meta.getColumnLabel(i), '_'), value.toString());
                    }
                }
            } else {
                throw new NoSuchElementException("NoSuchRow");
            }
            return this;
        } finally {
            rset.close();
        }
    }
597290
static void closeResultSet(ResultSet rs) {
        if (com.ibm.websphere.ras.TraceComponent.isAnyTracingEnabled() && LoggingUtil.SESSION_LOGGER_WAS.isLoggable(Level.FINE)) {
            LoggingUtil.SESSION_LOGGER_WAS.entering(methodClassName, methodNames[CLOSE_RESULT_SET], "closing " + rs);
        }
        try {
            rs.close();
        } catch (Throwable t) {
            com.ibm.ws.ffdc.FFDCFilter.processException(t, "com.ibm.ws.session.store.db.DatabaseHashMap.closeResultSet", "1018");
        }
    }
266886
protected boolean _load ()
    {
        java.sql.ResultSet rs = null;
        try
        {
            // This synchronization is necessary for Oracle JDBC drivers 8.1.7, 9.0.1, 9.2.0.1
            // The documentation says synchronization is done within the driver, but they
            // must have overlooked something. Without the lock we'd get mysterious error
            // messages.            
            synchronized(getDbMeta())
            {
                getDbMetaTreeModel().setStatusBarMessage("Reading columns for table " + getSchema().getCatalog().getCatalogName() + "." + getSchema().getSchemaName() + "." + getTableName());
                rs = getDbMeta().getColumns(getSchema().getCatalog().getCatalogName(), 
                                                          getSchema().getSchemaName(),
                                                          getTableName(), "%");
                final java.util.ArrayList alNew = new java.util.ArrayList();
                while (rs.next())
                {
                    alNew.add(new DBMetaColumnNode(getDbMeta(), getDbMetaTreeModel(), DBMetaTableNode.this, rs.getString("COLUMN_NAME")));
                }
                alChildren = alNew;            
                javax.swing.SwingUtilities.invokeLater(new Runnable()
                {
                    public void run()
                    {
                        getDbMetaTreeModel().nodeStructureChanged(DBMetaTableNode.this);
                    }
                });
                rs.close();
            }
        }
        catch (java.sql.SQLException sqlEx)
        {
            this.getDbMetaTreeModel().reportSqlError("Error retrieving columns", sqlEx);
            try
            {
                if (rs != null) rs.close ();
            }
            catch (java.sql.SQLException sqlEx2)
            {
                this.getDbMetaTreeModel().reportSqlError("Error retrieving columns", sqlEx2);
            }
            return false;
        }
        return true;
    }
1031271
static void closeQuietly(ResultSet rs) {
        try {
            if (rs != null && !rs.isClosed()) {
                rs.close();
                log.debug("closed {}", rs);
            }
        } catch (SQLException e) {
            log.debug(e.getMessage(), e);
        } catch (RuntimeException e) {
            log.debug(e.getMessage(), e);
        }
    }
232037
public static byte[] getBinaryStream(final ResultSet rs, final String name) throws SQLException {
		final InputStream in = rs.getBinaryStream(name);
		if (in == null) {
			return null;
		}
		return JKIOUtil.readStream(in);
	}
818692
public Map<String, Object> convertToMap(ResultSet rs) throws SQLException{
		return convertToMap(rs, null);
	}
702643
public static DateTime getUTCDateTime(final ResultSet rs, final String columnName) throws SQLException
    {
        final Timestamp ts = rs.getTimestamp(columnName);

        return (ts == null) ? null : new DateTime(ts).withZone(DateTimeZone.UTC);
    }
394273
public static String[] extractColumnLabels(ResultSet rs) throws SQLException {
        ResultSetMetaData rsmd = rs.getMetaData();
        int numColumns = rsmd.getColumnCount();
        String[] colLabels = new String[numColumns];
        for (int i = 1; i <= numColumns; i++) {
            colLabels[i - 1] = rsmd.getColumnLabel(i);
            if (colLabels[i - 1] == null) {
                colLabels[i - 1] = rsmd.getColumnName(i);
            }
        }
        return colLabels;
    }
991750
private <A> TableData<A> tableData(final ResultSet rs,
                                       final RowFunction<A> f)
        throws SQLException {

        final ResultSetMetaData meta = rs.getMetaData();
        final int c = meta.getColumnCount();
        final TableData<A> td = new TableData<A>();

        for (int p = 1; p <= c; p++) {
            final String n = meta.getColumnLabel(p);
            td.columns.add((n == null || "".equals(n)) ? "col" + p : n);
        } // end of for

        // First row
        td.rows.add(f.apply(rs));

        // Other row(s)
        while (rs.next()) {
            td.rows.add(f.apply(rs));
        } // end of if

        return td;
    }
1317527
public static void print(ResultSet rs, PrintStream out) throws SQLException {
    ResultSetMetaData meta = rs.getMetaData();
    int columns = meta.getColumnCount();
    for (int i = 0; i < columns; i++) {
      if (i > 0) {
        out.print(",");
      }
      out.print("\"");
      out.print(meta.getColumnName(i + 1));
      out.print("\"");
    }
    out.println();

    while (rs.next()) {
      for (int i = 0; i < columns; i++) {
        if (i > 0) {
          out.print(",");
        }
        String value = rs.getString(i + 1);
        if (value != null) {
          out.print("\"");
          out.print(value.replaceAll("\"", "\"\""));
          out.print("\"");
        } else {
          out.print("NULL");
        }
      }
      out.println();
    }
  }
515478
public Object getValue(final JavaType type, final ResultSet rs, final int columnIndex) throws SQLException {
		Class<?> rawType = type.getRawType();
		for (PropertyMapper<?> propertyMapper : this.mappers) {
			if (propertyMapper.canAccept(rawType) && propertyMapper.canAcceptTest(type, rs, columnIndex, this)) {
				return propertyMapper.getValue(type, rs, columnIndex, this);
			}
		}

		if (String.class.equals(rawType)) {
			return rs.getString(columnIndex);
		}
		if (Boolean.class.equals(rawType)) {
			boolean result = rs.getBoolean(columnIndex);
			if (rs.wasNull()) {
				return null;
			}
			return result;
		}
		if (boolean.class.equals(rawType)) {
			return rs.getBoolean(columnIndex);
		}
		if (Byte.class.equals(rawType)) {
			byte result = rs.getByte(columnIndex);
			if (rs.wasNull()) {
				return null;
			}
			return result;
		}
		if (byte.class.equals(rawType)) {
			return rs.getByte(columnIndex);
		}
		if (Short.class.equals(rawType)) {
			short result = rs.getShort(columnIndex);
			if (rs.wasNull()) {
				return null;
			}
			return result;
		}
		if (short.class.equals(rawType)) {
			return rs.getShort(columnIndex);
		}
		if (Integer.class.equals(rawType)) {
			int result = rs.getInt(columnIndex);
			if (rs.wasNull()) {
				return null;
			}
			return result;
		}
		if (int.class.equals(rawType)) {
			return rs.getInt(columnIndex);
		}
		if (Long.class.equals(rawType)) {
			long result = rs.getLong(columnIndex);
			if (rs.wasNull()) {
				return null;
			}
			return result;
		}
		if (long.class.equals(rawType)) {
			return rs.getLong(columnIndex);
		}
		if (Float.class.equals(rawType)) {
			float result = rs.getFloat(columnIndex);
			if (rs.wasNull()) {
				return null;
			}
			return result;
		}
		if (float.class.equals(rawType)) {
			return rs.getFloat(columnIndex);
		}
		if (Double.class.equals(rawType)) {
			double result = rs.getDouble(columnIndex);
			if (rs.wasNull()) {
				return null;
			}
			return result;
		}
		if (double.class.equals(rawType)) {
			return rs.getDouble(columnIndex);
		}
		if (BigDecimal.class.equals(rawType)) {
			return rs.getBigDecimal(columnIndex);
		}
		if (byte[].class.equals(rawType)) {
			return rs.getBytes(columnIndex);
		}
		if (java.sql.Timestamp.class.equals(rawType)) {
			return rs.getTimestamp(columnIndex);
		}
		if (java.sql.Time.class.equals(rawType)) {
			return rs.getTime(columnIndex);
		}
		if (java.sql.Date.class.equals(rawType)) {
			return rs.getDate(columnIndex);
		}
		if (Date.class.equals(rawType)) {
			return rs.getTimestamp(columnIndex);
		}
		if (java.sql.Array.class.equals(rawType)) {
			return rs.getArray(columnIndex);
		}
		if (java.sql.Blob.class.equals(rawType)) {
			return rs.getBlob(columnIndex);
		}
		if (java.sql.Clob.class.equals(rawType)) {
			return rs.getClob(columnIndex);
		}
		if (java.sql.NClob.class.equals(rawType)) {
			return rs.getNClob(columnIndex);
		}
		if (java.sql.Ref.class.equals(rawType)) {
			return rs.getRef(columnIndex);
		}
		if (java.sql.SQLXML.class.equals(rawType)) {
			return rs.getSQLXML(columnIndex);
		}
		for (PropertyMapper<?> propertyMapper : DEFAULT_MAPPERS) {
			if (propertyMapper.canAccept(rawType) && propertyMapper.canAcceptTest(type, rs, columnIndex, this)) {
				return propertyMapper.getValue(type, rs, columnIndex, this);
			}
		}
		return rs.getObject(columnIndex);
	}
1070482
public static String[] getColumnNames(ResultSet rs) throws DbRuntimeException {
		try {
			ResultSetMetaData rsmd = rs.getMetaData();
			int columnCount = rsmd.getColumnCount();
			String[] labelNames = new String[columnCount];
			for (int i = 0; i < labelNames.length; i++) {
				labelNames[i] = rsmd.getColumnLabel(i + 1);
			}
			return labelNames;
		} catch (Exception e) {
			throw new DbRuntimeException("Get colunms error!", e);
		}
	}
1152749
public void addRows(ResultSet rs) throws SQLException{
		ResultSetMetaData rsmd = rs.getMetaData();
		int columnCount = rsmd.getColumnCount();
		
		while (rs.next()) {
			Map<String, Object> row = new HashMap<String, Object>();
			for (int i = 1; i < columnCount + 1; i++) {
				String colName = rsmd.getColumnName(i);
				Object colObj = rs.getObject(i);
				if (colObj == null){		// avoid error if trying to convert data types
					row.put(colName, colObj);
				}else{
					if (colObj instanceof oracle.sql.Datum){
						colObj = ((oracle.sql.TIMESTAMP)colObj).toJdbc();
					}
					
					if (colObj instanceof java.sql.Timestamp){
						row.put(colName, new Date(((java.sql.Timestamp)colObj).getTime()));
					}else if (colObj instanceof java.sql.Date){
						row.put(colName, new Date(((java.sql.Date)colObj).getTime()));
					}else{
						row.put(colName, colObj);
					}
				}
			}
			addRow(row);
		}
	}
348681
private Object getValue(final ResultSet rs, final ResultSetMetaData rsmd, final int columnIndex)
			throws SQLException {
		JavaType javaType = this.dialect.getJavaType(rsmd.getColumnType(columnIndex),
				rsmd.getColumnTypeName(columnIndex));
		return this.mapperManager.getValue(javaType, rs, columnIndex);
	}