Search in sources :

Example 1 with JDBCArrayImpl

use of org.jkiss.dbeaver.model.impl.jdbc.JDBCArrayImpl in project dbeaver by dbeaver.

the class JDBCCollection method getArrayValue.

public Array getArrayValue() throws DBCException {
    Object[] attrs = new Object[contents.length];
    for (int i = 0; i < contents.length; i++) {
        Object attr = contents[i];
        if (attr instanceof DBDValue) {
            attr = ((DBDValue) attr).getRawValue();
        }
        attrs[i] = attr;
    }
    final DBSDataType dataType = getComponentType();
    try (DBCSession session = DBUtils.openUtilSession(new VoidProgressMonitor(), dataType.getDataSource(), "Create JDBC array")) {
        if (session instanceof Connection) {
            return ((Connection) session).createArrayOf(dataType.getTypeName(), attrs);
        } else {
            return new JDBCArrayImpl(dataType.getTypeName(), dataType.getTypeID(), attrs);
        }
    } catch (Throwable e) {
        throw new DBCException("Error creating struct", e);
    }
}
Also used : JDBCArrayImpl(org.jkiss.dbeaver.model.impl.jdbc.JDBCArrayImpl) DBSDataType(org.jkiss.dbeaver.model.struct.DBSDataType) Connection(java.sql.Connection) DBSTypedObject(org.jkiss.dbeaver.model.struct.DBSTypedObject) DBCException(org.jkiss.dbeaver.model.exec.DBCException) VoidProgressMonitor(org.jkiss.dbeaver.model.runtime.VoidProgressMonitor) DBCSession(org.jkiss.dbeaver.model.exec.DBCSession) JDBCSession(org.jkiss.dbeaver.model.exec.jdbc.JDBCSession)

Example 2 with JDBCArrayImpl

use of org.jkiss.dbeaver.model.impl.jdbc.JDBCArrayImpl in project dbeaver by serge-rider.

the class JDBCCollection method getArrayValue.

public Array getArrayValue() throws DBCException {
    if (contents == null) {
        return null;
    }
    Object[] attrs = new Object[contents.length];
    for (int i = 0; i < contents.length; i++) {
        Object attr = contents[i];
        if (attr instanceof DBDValue) {
            attr = ((DBDValue) attr).getRawValue();
        }
        attrs[i] = attr;
    }
    final DBSDataType dataType = getComponentType();
    try (DBCSession session = DBUtils.openUtilSession(new VoidProgressMonitor(), dataType, "Create JDBC array")) {
        if (session instanceof Connection) {
            String typeName = DBUtils.getObjectFullName(dataType, DBPEvaluationContext.DML);
            return ((Connection) session).createArrayOf(typeName, attrs);
        } else {
            return new JDBCArrayImpl(dataType.getTypeName(), dataType.getTypeID(), attrs);
        }
    } catch (Throwable e) {
        throw new DBCException("Error creating struct", e);
    }
}
Also used : JDBCArrayImpl(org.jkiss.dbeaver.model.impl.jdbc.JDBCArrayImpl) VoidProgressMonitor(org.jkiss.dbeaver.model.runtime.VoidProgressMonitor) JDBCSession(org.jkiss.dbeaver.model.exec.jdbc.JDBCSession)

Aggregations

JDBCSession (org.jkiss.dbeaver.model.exec.jdbc.JDBCSession)2 JDBCArrayImpl (org.jkiss.dbeaver.model.impl.jdbc.JDBCArrayImpl)2 VoidProgressMonitor (org.jkiss.dbeaver.model.runtime.VoidProgressMonitor)2 Connection (java.sql.Connection)1 DBCException (org.jkiss.dbeaver.model.exec.DBCException)1 DBCSession (org.jkiss.dbeaver.model.exec.DBCSession)1 DBSDataType (org.jkiss.dbeaver.model.struct.DBSDataType)1 DBSTypedObject (org.jkiss.dbeaver.model.struct.DBSTypedObject)1