Java Code Examples for java.sql.Connection.createArrayOf()

The following are Jave code examples for showing how to use createArrayOf() of the java.sql.Connection class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: neoscada   File: EventConverter.java   View Source Code Vote up 8 votes
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 );
}
 
Example 2
Project: mark-framework   File: ArrayTypeHandler.java   View Source Code Vote up 7 votes
@Override
public void setNonNullParameter(PreparedStatement ps, int i, Object[] parameter,
                                JdbcType jdbcType) throws SQLException {

    String typeName = null;
    if (parameter instanceof Integer[]) {
        typeName = TYPE_NAME_INTEGER;
    } else if (parameter instanceof String[]) {
        typeName = TYPE_NAME_VARCHAR;
    } else if (parameter instanceof Boolean[]) {
        typeName = TYPE_NAME_BOOLEAN;
    } else if (parameter instanceof Double[]) {
        typeName = TYPE_NAME_NUMERIC;
    }

    if (typeName == null) {
        throw new TypeException("ArrayTypeHandler parameter typeName error, your type is " + parameter.getClass().getName());
    }

    // 这3行是关键的代码,创建Array,然后ps.setArray(i, array)就可以了
    Connection conn = ps.getConnection();
    Array array = conn.createArrayOf(typeName, parameter);
    ps.setArray(i, array);
}
 
Example 3
Project: SqlSauce   File: ArrayListLongUserType.java   View Source Code Vote up 6 votes
@Override
public void nullSafeSet(PreparedStatement st, Object value, int index, SharedSessionContractImplementor session)
        throws HibernateException, SQLException {
    Connection connection = st.getConnection();

    if (value == null) {
        st.setNull(index, sqlTypes()[0]);
    } else {
        @SuppressWarnings("unchecked") ArrayList<Long> castObject = (ArrayList) value;

        Long[] longs = castObject.toArray(new Long[castObject.size()]);
        Array array = connection.createArrayOf("bigint", longs);

        st.setArray(index, array);
    }
}
 
Example 4
Project: graphium   File: AbstractWayGraphDaoImpl.java   View Source Code Vote up 5 votes
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;
	}
}
 
Example 5
Project: pgcodekeeper   File: SchemasContainer.java   View Source Code Vote up 5 votes
public SchemasContainer(Map<Long, PgSchema> schemas, Connection connection) throws SQLException {
    this.map = schemas;

    final int size = schemas.size();
    int i = 0;
    Long[] oids = new Long[size];
    String[] names = new String[size];
    for (Entry<Long, PgSchema> entry : schemas.entrySet()) {
        oids[i] = entry.getKey();
        names[i] = entry.getValue().getName();
        ++i;
    }
    this.oids = connection.createArrayOf("bigint", oids);
    this.names = connection.createArrayOf("text", names);
}
 
Example 6
Project: uroborosql   File: JdbcParameterFactory.java   View Source Code Vote up 3 votes
/**
 * {@link java.sql.Connection#createArrayOf(String, Object[])}のラッパー
 *
 * @param conn コネクション
 * @param typeName 配列の要素がマッピングされる型のSQL名。typeNameはデータベース固有の名前で、組込み型、ユーザー定義型、またはこのデータベースでサポートされる標準SQL型の名前のこと。これは、Array.getBaseTypeNameで返される値
 * @param elements 返されるオブジェクトを生成する要素
 * @return 指定されたSQL型に要素がマッピングされるArrayオブジェクト
 *
 * @see java.sql.Connection#createArrayOf(String, Object[])
 */
public static Array createArrayOf(final Connection conn, final String typeName, final Object[] elements) {
	try {
		return conn.createArrayOf(typeName, elements);
	} catch (SQLException e) {
		throw new UroborosqlRuntimeException(e);
	}
}