java类java.sql.Array的实例源码

EventConverter.java 文件源码 项目:neoscada 阅读 27 收藏 0 点赞 0 评论 0
public Array toSqlArray ( final Connection connection, final Event event ) throws SQLException
{
    final DateFormat isoDateFormat = new SimpleDateFormat ( isoDatePatterrn );
    final String[] fields;
    // array must be large enough to hold all attributes plus id and both time stamps
    fields = new String[ ( event.getAttributes ().size () + 3 ) * 2];
    // now populate values
    fields[0] = "id";
    fields[1] = event.getId ().toString ();
    fields[2] = "sourceTimestamp";
    fields[3] = isoDateFormat.format ( event.getSourceTimestamp () );
    fields[4] = "entryTimestamp";
    fields[5] = isoDateFormat.format ( event.getEntryTimestamp () );
    int i = 6;
    for ( final Entry<String, Variant> entry : event.getAttributes ().entrySet () )
    {
        fields[i] = entry.getKey ();
        fields[i + 1] = entry.getValue ().toString ();
        i += 2;
    }
    return connection.createArrayOf ( "text", fields );
}
TestTypeConversion.java 文件源码 项目:OpenDiabetes 阅读 29 收藏 0 点赞 0 评论 0
public void testArrayA() {

        try {
            String ddl0 = "DROP TABLE ARRAYTEST IF EXISTS";
            String ddl1 = "CREATE TABLE ARRAYTEST(A INTEGER ARRAY)";
            String dml1 = "INSERT INTO ARRAYTEST VALUES(ARRAY[0,0])";
            String dml2 = "INSERT INTO ARRAYTEST VALUES ?";

            statement.execute(ddl0);
            statement.execute(ddl1);
            statement.execute(dml1);

            PreparedStatement ps      = connection.prepareStatement(dml2);
            Object[]          objects = new Object[] {
                "1", 3, 9
            };
            Array array = connection.createArrayOf("INTEGER", objects);

            ps.setArray(1, array);
            ps.execute();
        } catch (SQLException e) {
            e.printStackTrace();
            fail("array failure");
        }
    }
ArrayTypeTest.java 文件源码 项目:calcite-avatica 阅读 23 收藏 0 点赞 0 评论 0
@Test public void shortArraysWithNull() throws Exception {
  final Random r = new Random();
  try (Connection conn = DriverManager.getConnection(url)) {
    ScalarType component = ColumnMetaData.scalar(Types.SMALLINT, "SMALLINT", Rep.SHORT);
    List<Array> arrays = new ArrayList<>();
    // Construct the data
    for (int i = 0; i < 5; i++) {
      List<Short> elements = new ArrayList<>();
      for (int j = 0; j < 4; j++) {
        short value = (short) r.nextInt(Short.MAX_VALUE);
        // 50% of the time, negate the value
        if (0 == r.nextInt(2)) {
          value *= -1;
        }
        elements.add(Short.valueOf(value));
      }
      elements.add(null);
      arrays.add(createArray("SMALLINT", component, elements));
    }
    // Verify read/write
    writeAndReadArrays(conn, "short_arrays", "SMALLINT", component, arrays,
        PRIMITIVE_LIST_VALIDATOR);
  }
}
ConnectionStore.java 文件源码 项目:aceql-http 阅读 33 收藏 0 点赞 0 评论 0
/**
 * Stores the Array in static for username + connectionId
 * 
 * @param array
 *            the Array to store
 */
public void put(Array array) {

    debug("Creating an array for user: " + connectionKey);
    if (array == null) {
        throw new IllegalArgumentException("array is null!");
    }

    Set<Array> arraySet = arrayMap.get(connectionKey);
    if (arraySet == null) {
        arraySet = new LinkedHashSet<Array>();
    }

    arraySet.add(array);
    arrayMap.put(connectionKey, arraySet);

}
DoubleWrapperArrayParameterMapperTest.java 文件源码 项目:uroborosql 阅读 28 收藏 0 点赞 0 评论 0
@Test
public void test() {
    BindParameterMapperManager parameterMapperManager = new BindParameterMapperManager();
    Array jdbcArray = newProxy(Array.class);
    Double[] array = { Double.valueOf(111.11d), Double.valueOf(222.22d) };

    Connection conn = newProxy(Connection.class, (proxy, method, args) -> {
        if (method.getName().equals("createArrayOf")) {
            assertThat(args[0], is("FLOAT"));
            assertThat(args[1], is(array));
            return jdbcArray;
        }
        return method.invoke(proxy, args);
    });

    assertThat(parameterMapperManager.toJdbc(array, conn), is(jdbcArray));

    Object[] objArray = { Double.valueOf(333.33d), "A" };
    assertThat(parameterMapperManager.toJdbc(objArray, conn), is(objArray));

}
AbstractWayGraphDaoImpl.java 文件源码 项目:graphium 阅读 33 收藏 0 点赞 0 评论 0
protected Array convertToArray(Connection con, Set<Access> accessTypes) throws SQLException {
    if (accessTypes != null) {
        Integer[] accessIds = new Integer[accessTypes.size()];
        int j = 0;
        for (Access access : accessTypes) {
            accessIds[j++] = access.getId();
        }
        return con.createArrayOf("smallint", accessIds);
    } else {
        return null;
    }
}
JDBCConnection.java 文件源码 项目:OpenDiabetes 阅读 35 收藏 0 点赞 0 评论 0
/**
     *  Factory method for creating Array objects.
     * <p>
     *  <b>Note: </b>When <code>createArrayOf</code> is used to create an array object
     *  that maps to a primitive data type, then it is implementation-defined
     *  whether the <code>Array</code> object is an array of that primitive
     *  data type or an array of <code>Object</code>.
     *  <p>
     *  <b>Note: </b>The JDBC driver is responsible for mapping the elements
     *  <code>Object</code> array to the default JDBC SQL type defined in
     *  java.sql.Types for the given class of <code>Object</code>. The default
     *  mapping is specified in Appendix B of the JDBC specification.  If the
     *  resulting JDBC type is not the appropriate type for the given typeName then
     *  it is implementation defined whether an <code>SQLException</code> is
     *  thrown or the driver supports the resulting conversion.
     *
     *  @param typeName the SQL name of the type the elements of the array map to. The typeName is a
     *  database-specific name which may be the name of a built-in type, a user-defined type or a standard  SQL type supported by this database. This
     *   is the value returned by <code>Array.getBaseTypeName</code>
     *  @param elements the elements that populate the returned object
     *  @return an Array object whose elements map to the specified SQL type
     *  @throws SQLException if a database error occurs, the JDBC type is not
     *   appropriate for the typeName and the conversion is not supported, the typeName is null or this method is called on a closed connection
     *  @throws SQLFeatureNotSupportedException  if the JDBC driver does not support this data type
     *  @since 1.6
     */
//#ifdef JAVA6
    public Array createArrayOf(String typeName,
                               Object[] elements) throws SQLException {

        checkClosed();

        if (typeName == null) {
            throw JDBCUtil.nullArgument();
        }
        typeName = typeName.toUpperCase();

        int typeCode = Type.getTypeNr(typeName);

        if (typeCode < 0) {
            throw JDBCUtil.invalidArgument(typeName);
        }

        Type type = Type.getDefaultType(typeCode);

        if (type.isArrayType() || type.isLobType() || type.isRowType()) {
            throw JDBCUtil.invalidArgument(typeName);
        }

        Object[] newData = new Object[elements.length];

        try {
            for (int i = 0; i < elements.length; i++) {
                Object o = type.convertJavaToSQL(sessionProxy, elements[i]);

                newData[i] = type.convertToTypeLimits(sessionProxy, o);
            }
        } catch (HsqlException e) {
            throw JDBCUtil.sqlException(e);
        }

        return new JDBCArray(newData, type, this);
    }
ConnectionSpy.java 文件源码 项目:dswork 阅读 31 收藏 0 点赞 0 评论 0
public Array createArrayOf(String typeName, Object[] elements) throws SQLException
{
    try
    {
        return realConnection.createArrayOf(typeName, elements);
    }
    catch(SQLException s)
    {
        String methodCall = "createArrayOf(" + typeName + ", " + elements + ")";
        reportException(methodCall, s, null);
        throw s;
    }
}
CommonCachedRowSetTests.java 文件源码 项目:jdk8u-jdk 阅读 32 收藏 0 点赞 0 评论 0
protected void createDataTypesRows(RowSet crs) throws SQLException {

        Integer aInteger = 100;
        String aChar = "Oswald Cobblepot";
        Long aLong = Long.MAX_VALUE;
        Short aShort = Short.MAX_VALUE;
        Double aDouble = Double.MAX_VALUE;
        BigDecimal aBigDecimal = BigDecimal.ONE;
        Boolean aBoolean = false;
        Float aFloat = Float.MAX_VALUE;
        Byte aByte = Byte.MAX_VALUE;
        Date aDate = Date.valueOf(LocalDate.now());
        Time aTime = Time.valueOf(LocalTime.now());
        Timestamp aTimeStamp = Timestamp.valueOf(LocalDateTime.now());
        Array aArray = new StubArray("INTEGER", new Object[1]);
        Ref aRef = new SerialRef(new StubRef("INTEGER", query));
        byte[] bytes = new byte[10];
        crs.moveToInsertRow();
        crs.updateInt(1, aInteger);
        crs.updateString(2, aChar);
        crs.updateString(3, aChar);
        crs.updateLong(4, aLong);
        crs.updateBoolean(5, aBoolean);
        crs.updateShort(6, aShort);
        crs.updateDouble(7, aDouble);
        crs.updateBigDecimal(8, aBigDecimal);
        crs.updateFloat(9, aFloat);
        crs.updateByte(10, aByte);
        crs.updateDate(11, aDate);
        crs.updateTime(12, aTime);
        crs.updateTimestamp(13, aTimeStamp);
        crs.updateBytes(14, bytes);
        crs.updateArray(15, aArray);
        crs.updateRef(16, aRef);
        crs.updateDouble(17, aDouble);
        crs.insertRow();
        crs.moveToCurrentRow();

    }
CallableStatementWrapper.java 文件源码 项目:BibliotecaPS 阅读 31 收藏 0 点赞 0 评论 0
public Array getArray(int parameterIndex) throws SQLException {
    try {
        if (this.wrappedStmt != null) {
            return ((CallableStatement) this.wrappedStmt).getArray(parameterIndex);
        }
        throw SQLError.createSQLException("No operations allowed after statement closed", SQLError.SQL_STATE_GENERAL_ERROR, this.exceptionInterceptor);

    } catch (SQLException sqlEx) {
        checkAndFireConnectionError(sqlEx);
    }
    return null;
}
TestTypeConversion.java 文件源码 项目:dev-courses 阅读 27 收藏 0 点赞 0 评论 0
public void testArrayA() {

        try {
            String ddl0 = "DROP TABLE ARRAYTEST IF EXISTS";
            String ddl1 = "CREATE TABLE ARRAYTEST(A INTEGER ARRAY)";
            String dml1 = "INSERT INTO ARRAYTEST VALUES(ARRAY[0,0])";
            String dml2 = "INSERT INTO ARRAYTEST VALUES ?";

            statement.execute(ddl0);
            statement.execute(ddl1);
            statement.execute(dml1);

            PreparedStatement ps      = connection.prepareStatement(dml2);
            Object[]          objects = new Object[] {
                "1", 3, 9
            };
            Array array = connection.createArrayOf("INTEGER", objects);

            ps.setArray(1, array);
            ps.execute();
        } catch (SQLException e) {
            e.printStackTrace();
            fail("array failure");
        }
    }
ArrayTypeHandler.java 文件源码 项目:tangyuan2 阅读 29 收藏 0 点赞 0 评论 0
@Override
public Object getNullableResult(ResultSet rs, String columnName) throws SQLException {
    Array array = rs.getArray(columnName);
    return array == null ? null : array.getArray();
}
EventConverter.java 文件源码 项目:neoscada 阅读 33 收藏 0 点赞 0 评论 0
public Event fromSqlArray ( final Array array ) throws SQLException, ParseException
{
    final DateFormat isoDateFormat = new SimpleDateFormat ( isoDatePatterrn );
    final EventBuilder eb = Event.create ();
    final String[] fields = (String[])array.getArray ();
    for ( int i = 0; i < fields.length; i += 2 )
    {
        final String key = fields[i];
        final String value = fields[i + 1];

        if ( key.equals ( "id" ) )
        {
            eb.id ( UUID.fromString ( value ) );
        }
        else if ( key.equals ( "sourceTimestamp" ) )
        {
            eb.sourceTimestamp ( isoDateFormat.parse ( value ) );
        }
        else if ( key.equals ( "entryTimestamp" ) )
        {
            eb.entryTimestamp ( isoDateFormat.parse ( value ) );
        }
        else
        {
            eb.attribute ( key, VariantEditor.toVariant ( value ) );
        }
    }
    return eb.build ();
}
AbstractCursor.java 文件源码 项目:calcite-avatica 阅读 38 收藏 0 点赞 0 评论 0
@SuppressWarnings("unchecked") @Override public Array getArray() throws SQLException {
  final Object o = getObject();
  if (o == null) {
    return null;
  }
  if (o instanceof ArrayImpl) {
    return (ArrayImpl) o;
  }
  // If it's not an Array already, assume it is a List.
  return new ArrayImpl((List<Object>) o, this);
}
SQLInputImplTests.java 文件源码 项目:openjdk-jdk10 阅读 32 收藏 0 点赞 0 评论 0
@Test(enabled = true)
public void test06() throws Exception {
    Object[] coffees = new Object[]{"Espresso", "Colombian", "French Roast",
        "Cappuccino"};
    Array a = new StubArray("VARCHAR", coffees);
    Object[] values = {a};
    SQLInputImpl sqli = new SQLInputImpl(values, map);
    Array a2 = sqli.readArray();
    assertTrue(Arrays.equals((Object[]) a2.getArray(), (Object[]) a.getArray()));
    assertTrue(a.getBaseTypeName().equals(a2.getBaseTypeName()));
}
SQLOutputImplTests.java 文件源码 项目:openjdk-jdk10 阅读 28 收藏 0 点赞 0 评论 0
@Test(enabled = true)
public void test04() throws Exception {
    Object[] coffees = new Object[]{"Espresso", "Colombian", "French Roast",
        "Cappuccino"};
    Array a = new StubArray("VARCHAR", coffees);
    outImpl.writeArray(a);
    SerialArray sa = (SerialArray) results.get(0);
    assertTrue(Arrays.equals(coffees, (Object[]) sa.getArray()));
    assertTrue(a.getBaseTypeName().equals(sa.getBaseTypeName()));
}
SQLResultSetWrapper.java 文件源码 项目:pgcodekeeper 阅读 36 收藏 0 点赞 0 评论 0
@Override
public <T> T[] getArray(String columnName, Class<T> arrayElement) throws WrapperAccessException {
    try {
        Array arr = rs.getArray(columnName);
        if (arr != null) {
            @SuppressWarnings("unchecked")
            T[] ret = (T[]) arr.getArray();
            return ret;
        }
        return null;
    } catch (SQLException ex) {
        throw new WrapperAccessException(ex.getLocalizedMessage(), ex);
    }
}
JDBC4ConnectionWrapper.java 文件源码 项目:BibliotecaPS 阅读 28 收藏 0 点赞 0 评论 0
public java.sql.Array createArrayOf(String typeName, Object[] elements) throws SQLException {
    checkClosed();

    try {
        return ((java.sql.Connection) this.mc).createArrayOf(typeName, elements);
    } catch (SQLException sqlException) {
        checkAndFireConnectionError(sqlException);
    }

    return null; // never reached, but compiler can't tell
}
JDBC4ConnectionWrapper.java 文件源码 项目:OpenVertretung 阅读 33 收藏 0 点赞 0 评论 0
public java.sql.Array createArrayOf(String typeName, Object[] elements) throws SQLException {
    checkClosed();

    try {
        return ((java.sql.Connection) this.mc).createArrayOf(typeName, elements);
    } catch (SQLException sqlException) {
        checkAndFireConnectionError(sqlException);
    }

    return null; // never reached, but compiler can't tell
}
DremioConnectionImpl.java 文件源码 项目:dremio-oss 阅读 27 收藏 0 点赞 0 评论 0
@Override
public Array createArrayOf(String typeName, Object[] elements) throws SQLException {
  throwIfClosed();
  try {
    return super.createArrayOf(typeName, elements);
  }
  catch (UnsupportedOperationException e) {
    throw new SQLFeatureNotSupportedException(e.getMessage(), e);
  }
}
ArrayTypeTest.java 文件源码 项目:calcite-avatica 阅读 29 收藏 0 点赞 0 评论 0
@Test public void testCreateArrayOf() throws Exception {
  try (Connection conn = DriverManager.getConnection(url)) {
    final String componentName = SqlType.INTEGER.name();
    Array a1 = conn.createArrayOf(componentName, new Object[] {1, 2, 3, 4, 5});
    Array a2 = conn.createArrayOf(componentName, new Object[] {2, 3, 4, 5, 6});
    Array a3 = conn.createArrayOf(componentName, new Object[] {3, 4, 5, 6, 7});
    AvaticaType arrayType = ColumnMetaData.array(
        ColumnMetaData.scalar(Types.INTEGER, componentName, Rep.INTEGER), "NUMBERS", Rep.ARRAY);
    writeAndReadArrays(conn, "CREATE_ARRAY_OF_INTEGERS", componentName, arrayType,
        Arrays.asList(a1, a2, a3), PRIMITIVE_LIST_VALIDATOR);
  }
}
TsfileConnection.java 文件源码 项目:iotdb-jdbc 阅读 30 收藏 0 点赞 0 评论 0
@Override
   public Array createArrayOf(String arg0, Object[] arg1) throws SQLException {
throw new SQLException("Method not supported");
   }
StubConnection.java 文件源码 项目:openjdk-jdk10 阅读 31 收藏 0 点赞 0 评论 0
@Override
public Array createArrayOf(String typeName, Object[] elements) throws SQLException {
    throw new UnsupportedOperationException("Not supported yet.");
}
AvaticaDrillSqlAccessor.java 文件源码 项目:QDrill 阅读 27 收藏 0 点赞 0 评论 0
@Override
public Array getArray() throws SQLException {
  throw new SQLFeatureNotSupportedException();
}
StubSyncResolver.java 文件源码 项目:jdk8u-jdk 阅读 23 收藏 0 点赞 0 评论 0
@Override
public void updateArray(int columnIndex, Array x) throws SQLException {
    throw new UnsupportedOperationException("Not supported yet.");
}
AbstractCloudSpannerPreparedStatement.java 文件源码 项目:spanner-jdbc 阅读 26 收藏 0 点赞 0 评论 0
@Override
public void setArray(int parameterIndex, Array x) throws SQLException
{
    parameters.setParameter(parameterIndex, x);
}
JDBC4FabricMySQLConnectionProxy.java 文件源码 项目:lams 阅读 31 收藏 0 点赞 0 评论 0
public java.sql.Array createArrayOf(String typeName, Object[] elements) throws SQLException {
    return getActiveConnection().createArrayOf(typeName, elements);
}
JDBC4Connection.java 文件源码 项目:s-store 阅读 25 收藏 0 点赞 0 评论 0
@Override
public Array createArrayOf(String typeName, Object[] elements) throws SQLException
{
    checkClosed();
    throw SQLError.noSupport();
}
AbstractBlancoGenericJdbcPreparedStatement.java 文件源码 项目:blanco-sfdc-jdbc-driver 阅读 32 收藏 0 点赞 0 评论 0
public void setArray(int parameterIndex, Array x) throws SQLException {
    throw new SQLException("Not Implemented: setArray(int parameterIndex, Array x)");
}
StubFilteredRowSetImpl.java 文件源码 项目:openjdk-jdk10 阅读 28 收藏 0 点赞 0 评论 0
@Override
public Array getArray(int columnIndex) throws SQLException {
    throw new UnsupportedOperationException("Not supported yet.");
}


问题


面经


文章

微信
公众号

扫码关注公众号