@SuppressWarnings("unchecked") public <T> T getObject(int columnIndex, Class<T> type) throws SQLException { if (type == null) { throw SQLError.createSQLException("Type parameter can not be null", SQLError.SQL_STATE_ILLEGAL_ARGUMENT, getExceptionInterceptor()); } if (type.equals(Struct.class)) { throw new SQLFeatureNotSupportedException(); } else if (type.equals(RowId.class)) { return (T) getRowId(columnIndex); } else if (type.equals(NClob.class)) { return (T) getNClob(columnIndex); } else if (type.equals(SQLXML.class)) { return (T) getSQLXML(columnIndex); } return super.getObject(columnIndex, type); }
private static ConcurrentHashMap<Class, Integer> buildJdbcJavaClassMappings() { ConcurrentHashMap<Class, Integer> jdbcJavaClassMappings = new ConcurrentHashMap<Class, Integer>(); // these mappings are the ones outlined specifically in the spec jdbcJavaClassMappings.put( String.class, Types.VARCHAR ); jdbcJavaClassMappings.put( BigDecimal.class, Types.NUMERIC ); jdbcJavaClassMappings.put( Boolean.class, Types.BIT ); jdbcJavaClassMappings.put( Integer.class, Types.INTEGER ); jdbcJavaClassMappings.put( Long.class, Types.BIGINT ); jdbcJavaClassMappings.put( Float.class, Types.REAL ); jdbcJavaClassMappings.put( Double.class, Types.DOUBLE ); jdbcJavaClassMappings.put( byte[].class, Types.LONGVARBINARY ); jdbcJavaClassMappings.put( java.sql.Date.class, Types.DATE ); jdbcJavaClassMappings.put( Time.class, Types.TIME ); jdbcJavaClassMappings.put( Timestamp.class, Types.TIMESTAMP ); jdbcJavaClassMappings.put( Blob.class, Types.BLOB ); jdbcJavaClassMappings.put( Clob.class, Types.CLOB ); jdbcJavaClassMappings.put( Array.class, Types.ARRAY ); jdbcJavaClassMappings.put( Struct.class, Types.STRUCT ); jdbcJavaClassMappings.put( Ref.class, Types.REF ); jdbcJavaClassMappings.put( Class.class, Types.JAVA_OBJECT ); // additional "common sense" registrations jdbcJavaClassMappings.put( Character.class, Types.CHAR ); jdbcJavaClassMappings.put( char[].class, Types.VARCHAR ); jdbcJavaClassMappings.put( Character[].class, Types.VARCHAR ); jdbcJavaClassMappings.put( Byte[].class, Types.LONGVARBINARY ); jdbcJavaClassMappings.put( java.util.Date.class, Types.TIMESTAMP ); jdbcJavaClassMappings.put( Calendar.class, Types.TIMESTAMP ); return jdbcJavaClassMappings; }
@Override public Struct getStruct() throws SQLException { final Object o = super.getObject(); if (o == null) { return null; } else if (o instanceof StructImpl) { return (StructImpl) o; } else if (o instanceof List) { return new StructImpl((List) o); } else { final List<Object> list = new ArrayList<>(); for (Accessor fieldAccessor : fieldAccessors) { try { list.add(fieldAccessor.getObject()); } catch (SQLException e) { throw new RuntimeException(e); } } return new StructImpl(list); } }
/** * Tratar o retorno vido do java * @param result * @param returnType * @return */ @SuppressWarnings("CallToPrintStackTrace") private static Object treatReturn (Object result, int returnType) { Object currectObject = result; try { if (returnType == ARRAY && result instanceof Array) { Array r = (Array) result; currectObject = new ArrayList<> (Arrays.asList((Object [])r.getArray())); } else if (Types.STRUCT == returnType) { System.out.println("dbdkj"); currectObject = ((Struct) result).getAttributes(); } }catch(Exception ex) { ex.printStackTrace(); } if(currectObject != null) System.out.println("RETURN = class{"+currectObject.getClass().getName()+"} | toString = "+currectObject.toString()+"\n"); return currectObject; }
public Struct createStruct(String typeName, Object[] attributes) throws SQLException { checkClosed(); try { return ((java.sql.Connection) this.mc).createStruct(typeName, attributes); } catch (SQLException sqlException) { checkAndFireConnectionError(sqlException); } return null; // never reached, but compiler can't tell }
public Struct createStruct(String typeName, Object[] attributes) throws SQLException { try { return realConnection.createStruct(typeName, attributes); } catch(SQLException s) { String methodCall = "createStruct(" + typeName + ", " + attributes + ")"; reportException(methodCall, s, null); throw s; } }
@Test(enabled = true) public void test08() throws Exception { Object[] attributes = new Object[]{"Bruce", "Wayne", 1939, "Batman"}; Struct s = new StubStruct(sqlType, attributes); outImpl.writeStruct(s); SerialStruct ss = (SerialStruct) results.get(0); assertTrue(Arrays.equals(attributes, (Object[]) ss.getAttributes())); assertTrue(sqlType.equals(ss.getSQLTypeName())); }
@Test() public void test11() throws Exception { Object[] attributes = new Object[]{"Bruce", "Wayne", 1939, "Batman"}; map.put(sqlType, Class.forName("util.SuperHero")); Struct struct = new StubStruct(sqlType, attributes); Object[] values = {struct}; SQLInputImpl sqli = new SQLInputImpl(values, map); Object o = sqli.readObject(); assertTrue(hero.equals(o)); }
@SuppressWarnings("unchecked") @Override public <T> T getObject(Class<T> clz) throws SQLException { // getStruct() is not exposed on Accessor, only AccessorImpl. getObject(Class) is exposed, // so we can make it do the right thing (call getStruct()). if (clz.equals(Struct.class)) { return (T) getStruct(); } return super.getObject(clz); }
@Override public Struct createStruct(String typeName, Object[] attributes) throws SQLException { throwIfClosed(); try { return super.createStruct(typeName, attributes); } catch (UnsupportedOperationException e) { throw new SQLFeatureNotSupportedException(e.getMessage(), e); } }
@Override public Struct createStruct(String typeName, Object[] attributes) throws SQLException { return checkClosedAndThrowUnsupportedException(); }
@Override public Struct createStruct(String typeName, Object[] attributes) throws SQLException { checkClosed(); throw SQLError.noSupport(); }
@Override public Struct createStruct(String typeName, Object[] attributes) throws SQLException { return con.createStruct(typeName, attributes); }
@Override public Struct createStruct(String typeName, Object[] attributes) throws SQLException { return conn.createStruct(typeName, attributes); }
@Override public Struct createStruct(String typeName, Object[] attributes) throws SQLException { return connection.createStruct(typeName, attributes); }
@Override public Struct createStruct(String typeName, Object[] attributes) throws SQLException { return wrapped.createStruct(typeName, attributes); }
@Override public Struct createStruct(String typeName, Object[] attributes) throws SQLException { return null; }
public Struct createStruct(String typeName, Object[] attributes) throws SQLException { transactionBegun(); return getActiveConnection().createStruct(typeName, attributes); }
public Struct createStruct(String typeName, Object[] attributes) throws SQLException { return this.getJDBC4Connection().createStruct(typeName, attributes); }
public Struct createStruct(String typeName, Object[] attributes) throws SQLException { throw SQLError.createSQLFeatureNotSupportedException(); }
@Override public Struct createStruct(String s, Object[] objects) throws SQLException { return call(c -> c.createStruct(s, objects)); }
@Override public Struct createStruct(String s, Object[] objects) throws SQLException { return connection.createStruct(s, objects); }
/** {@inheritDoc} */ public Struct createStruct(String typeName, Object[] attributes) throws SQLException { return null; }