protected BlobHandler setObject(Connection c, PreparedStatement ps, int i, Object obj) throws PalantirSqlException { if (obj instanceof ByteArrayInputStream) { ByteArrayInputStream bais = (ByteArrayInputStream)obj; // Using #available is only okay for ByteArrayInputStream, // not for a generic InputStream PreparedStatements.setBinaryStream(ps, i, bais, bais.available()); } else if (obj instanceof org.joda.time.DateTime) { setDateTime(c, ps, i, (DateTime)obj); } else if (obj instanceof Boolean) { // TODO: gross hack because our code abuses the distinction between // boolean true and false and non-zeroness on a numeric field and // postgres complains because it is strict on column types. Boolean b = (Boolean)obj; Long converted = b.booleanValue() ? 1L : 0L; PreparedStatements.setObject(ps, i, converted); } else if (obj instanceof Number) { setNumber(ps, i, obj); } else { assert !(obj instanceof InputStream) : "InputStreams must be passed as PTInputStreams so we know the length"; //$NON-NLS-1$ PreparedStatements.setObject(ps, i, obj); } return null; }
protected BlobHandler setObject(Connection c, PreparedStatement ps, int i, Object obj) throws PalantirSqlException { if (obj instanceof ByteArrayInputStream) { ByteArrayInputStream bais = (ByteArrayInputStream)obj; // Using #available is only okay for ByteArrayInputStream, // not for a generic InputStream PreparedStatements.setBinaryStream(ps, i, bais, bais.available()); } else if (obj instanceof org.joda.time.DateTime) { setDateTime(c, ps, i, (DateTime)obj); } else if (obj instanceof Boolean) { // TODO: gross hack because our code abuses the distinction between // boolean true and false and non-zeroness on a numeric field and // postgres complains because it is strict on column types. Boolean b = (Boolean)obj; Long converted = b.booleanValue() ? 1L : 0L; PreparedStatements.setObject(ps, i, converted); } else if (obj instanceof Number) { setNumber(ps, i, obj); } else { assert !(obj instanceof InputStream) : "InputStreams must be passed as PTInputStreams so we know the length"; //$NON-NLS-1$ PreparedStatements.setObject(ps, i, obj); } return null; }