/*
 * DBeaver - Universal Database Manager
 * Copyright (C) 2010-2016 Serge Rieder (serge@jkiss.org)
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License (version 2)
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */
package org.jkiss.dbeaver.ext.phoenix.model.data;

import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.model.exec.DBCException;
import org.jkiss.dbeaver.model.exec.DBCSession;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCSession;
import org.jkiss.dbeaver.model.impl.jdbc.data.JDBCCollection;
import org.jkiss.dbeaver.model.impl.jdbc.data.handlers.JDBCArrayValueHandler;
import org.jkiss.dbeaver.model.struct.DBSTypedObject;

import java.sql.Array;


/**
 * PhoenixArrayValueHandler
 */
public class PhoenixArrayValueHandler extends JDBCArrayValueHandler {
    public static final PhoenixArrayValueHandler INSTANCE = new PhoenixArrayValueHandler();
    
    public static final String PHOENIX_ARRAY_TYPE = "PhoenixArray";

    @Override
    public Object getValueFromObject(@NotNull DBCSession session, @NotNull DBSTypedObject type, Object object, boolean copy) throws DBCException
    {
        if (object != null && object.getClass().getSimpleName().contains(PHOENIX_ARRAY_TYPE)) {
            return JDBCCollection.makeArray((JDBCSession) session, type, (Array) object);
        }
        return super.getValueFromObject(session, type, object, copy);
    }
    
}

@@ -837,16 +837,67 @@
 otNull;%0A
+import org.jkiss.dbeaver.model.data.DBDCollection;%0A
 import o
@@ -978,32 +978,96 @@
 xec.DBCSession;%0A
+import org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement;%0A
 import org.jkiss
@@ -1322,16 +1322,69 @@
 .Array;%0A
+import java.sql.SQLException;%0Aimport java.sql.Types;%0A
 %0A%0A/**%0A *
@@ -2091,10 +2091,978 @@
  %7D%0A    %0A
+    @Override%0A    protected void bindParameter(%0A        JDBCSession session,%0A        JDBCPreparedStatement statement,%0A        DBSTypedObject paramType,%0A        int paramIndex,%0A        Object value)%0A        throws DBCException, SQLException%0A    %7B%0A        if (value == null) %7B%0A            statement.setNull(paramIndex, Types.ARRAY);%0A        %7D else if (value instanceof DBDCollection) %7B%0A            DBDCollection collection = (DBDCollection) value;%0A            if (collection.isNull()) %7B%0A                statement.setNull(paramIndex, Types.ARRAY);%0A            %7D else if (collection instanceof JDBCCollection) %7B%0A                statement.setArray(paramIndex, ((JDBCCollection) collection).getArrayValue());%0A            %7D else %7B%0A                statement.setArray(paramIndex, (Array)collection.getRawValue());%0A            %7D%0A        %7D else %7B%0A            throw new DBCException(%22Array parameter type '%22 + value.getClass().getName() + %22' not supported%22);%0A        %7D%0A    %7D%0A    %0A
 %7D%0A

enable phoenix/habse array edit