@SuppressWarnings("deprecation") protected Blob writeDataToBlob(ResultSet rs, int column, byte[] data) throws SQLException { Blob blob = rs.getBlob(column); // get blob if (blob == null) { throw new SQLException("Driver's Blob representation is null!"); } if (blob instanceof oracle.sql.BLOB) { // is it an oracle blob? ((oracle.sql.BLOB) blob).putBytes(1, data); ((oracle.sql.BLOB) blob).trim(data.length); return blob; } else { throw new SQLException( "Driver's Blob representation is of an unsupported type: " + blob.getClass().getName()); } } }
/** * Convience method for ARRAY construction. * * <p>Compare and contrast with toORDINATE - which treats <code>Double.NaN</code> as<code>NULL * </code> */ protected final ARRAY toARRAY(double doubles[], String dataType) throws SQLException { ArrayDescriptor descriptor = ArrayDescriptor.createDescriptor(dataType, connection); return new ARRAY(descriptor, connection, doubles); }
/** Presents datum as an int */ protected int asInteger(Datum datum, final int DEFAULT) throws SQLException { if (datum == null) return DEFAULT; return ((NUMBER) datum).intValue(); } /** Presents datum as a double */
/** Convience method for STRUCT construction. */ protected final STRUCT toSTRUCT(Datum attributes[], String dataType) throws SQLException { if (dataType.startsWith("*.")) { dataType = "DRA." + dataType.substring(2); // TODO here } StructDescriptor descriptor = StructDescriptor.createDescriptor(dataType, connection); return new STRUCT(descriptor, connection, attributes); }
/** Convience method for NUMBER construction */ protected final NUMBER toNUMBER(int number) { return new NUMBER(number); }
protected int[] asIntArray(ARRAY array, int DEFAULT) throws SQLException { if (array == null) return null; if (DEFAULT == 0) return array.getIntArray(); return asIntArray(array.getOracleArray(), DEFAULT); } /** Presents Datum[] as a int[] */
/** * @param rs result set of the dimension info query * @param column column of the dimension info * @return the envelope out of the dimension info (assumption: x before y or longitude before * latitude) or null, if no data is in the specified column * @throws SQLException if dimension info can not be parsed * @author Hendrik Peilke */ private Envelope decodeDiminfoEnvelope(ResultSet rs, int column) throws SQLException { ARRAY returnArray = (ARRAY) rs.getObject(column); if (returnArray == null) { throw new SQLException("no data inside the specified column"); } Datum data[] = returnArray.getOracleArray(); if (data.length < 2) { throw new SQLException("too little dimension information found in sdo_geom_metadata"); } Datum[] xInfo = ((STRUCT) data[0]).getOracleAttributes(); Datum[] yInfo = ((STRUCT) data[1]).getOracleAttributes(); Double minx = xInfo[1].doubleValue(); Double maxx = xInfo[2].doubleValue(); Double miny = yInfo[1].doubleValue(); Double maxy = yInfo[2].doubleValue(); return new Envelope(minx, maxx, miny, maxy); }
/** Presents array as a double[] */ protected double[] asDoubleArray(ARRAY array, final double DEFAULT) throws SQLException { if (array == null) return null; if (DEFAULT == 0) return array.getDoubleArray(); return asDoubleArray(array.getOracleArray(), DEFAULT); }
/** Convience method for CHAR construction */ protected final CHAR toCHAR(String s) { // make sure if the string is larger than one character, only take the first character if (s.length() > 1) s = new String((new Character(s.charAt(0))).toString()); try { // BUG: make sure I am correct return new CHAR(s, CharacterSet.make(CharacterSet.ISO_LATIN_1_CHARSET)); } catch (SQLException e) { java.util.logging.Logger.getGlobal().log(java.util.logging.Level.INFO, "", e); } return null; }
/** Presents struct as a double[] */ protected double[] asDoubleArray(STRUCT struct, final double DEFAULT) throws SQLException { if (struct == null) return null; return asDoubleArray(struct.getOracleAttributes(), DEFAULT); }
/** Presents datum as a double */ protected double asDouble(Datum datum, final double DEFAULT) throws SQLException { if (datum == null) return DEFAULT; return ((NUMBER) datum).doubleValue(); }
/** Convience method for ARRAY construction. */ protected final ARRAY toARRAY(int ints[], String dataType) throws SQLException { ArrayDescriptor descriptor = ArrayDescriptor.createDescriptor(dataType, connection); return new ARRAY(descriptor, connection, ints); }
@SuppressWarnings("deprecation") protected Blob writeDataToBlob(ResultSet rs, int column, byte[] data) throws SQLException { Blob blob = rs.getBlob(column); // get blob if (blob == null) { throw new SQLException("Driver's Blob representation is null!"); } if (blob instanceof oracle.sql.BLOB) { // is it an oracle blob? ((oracle.sql.BLOB) blob).putBytes(1, data); ((oracle.sql.BLOB) blob).trim(data.length); return blob; } else { throw new SQLException( "Driver's Blob representation is of an unsupported type: " + blob.getClass().getName()); } } }
/** * Convience method for NUMBER construction. * * <p>Double.NaN is represented as <code>NULL</code> to agree with JTS use. */ protected final NUMBER toNUMBER(double number) throws SQLException { if (Double.isNaN(number)) { return null; } return new NUMBER(number); }
/** * Convert provided SDO_GEOMETRY to JTS Geometry. * * <p>Will return <code>null</code> as <code>null</code>. * * @param sdoGeometry datum STRUCT to be converted to a double[] * @return JTS <code>Geometry</code> representing the provided <code>datum</code> * @throws SQLException * @see net.refractions.jspatial.Converter#toObject(oracle.sql.STRUCT) */ public Geometry asGeometry(STRUCT sdoGeometry) throws SQLException { // Note Returning null for null Datum if (sdoGeometry == null) return null; Datum data[] = sdoGeometry.getOracleAttributes(); final int GTYPE = asInteger(data[0], 0); final int SRID = asInteger(data[1], SDO.SRID_NULL); final double POINT[] = asDoubleArray((STRUCT) data[2], Double.NaN); final int ELEMINFO[] = asIntArray((ARRAY) data[3], 0); final double ORDINATES[] = asDoubleArray((ARRAY) data[4], Double.NaN); return SDO.create(geometryFactory, GTYPE, SRID, POINT, ELEMINFO, ORDINATES); }
protected final ARRAY toATTRIBUTE(double ords[], String desc) throws SQLException { ArrayDescriptor descriptor = ArrayDescriptor.createDescriptor(desc, connection); final int LENGTH = ords.length; Datum data[] = new Datum[LENGTH]; for (int i = 0; i < LENGTH; i++) { data[i] = toNUMBER(ords[i]); } return new ARRAY(descriptor, connection, data); }
protected final ARRAY toORDINATE(double ords[]) throws SQLException { ArrayDescriptor descriptor = ArrayDescriptor.createDescriptor("MDSYS.SDO_ORDINATE_ARRAY", connection); final int LENGTH = ords.length; Datum data[] = new Datum[LENGTH]; for (int i = 0; i < LENGTH; i++) { data[i] = toNUMBER(ords[i]); } return new ARRAY(descriptor, connection, data); }
throws SQLException { ArrayDescriptor descriptor = ArrayDescriptor.createDescriptor("MDSYS.SDO_ORDINATE_ARRAY", connection); return new ARRAY(descriptor, connection, data);
/** * Convience method for ARRAY construction. */ public static ARRAY toARRAY(int[] ints, String dataType, OracleConnection connection) throws SQLException { ArrayDescriptor descriptor = ArrayDescriptor.createDescriptor(dataType, connection); return new ARRAY(descriptor, connection, ints); }