All Downloads are FREE. Search and download functionalities are using the official Maven repository.

metridoc.plugins.impl.iterators.SqlIterator.groovy Maven / Gradle / Ivy

There is a newer version: 0.30
Show newest version
/*
 * Copyright 2010 Trustees of the University of Pennsylvania Licensed under the
 * Educational Community License, Version 2.0 (the "License"); you may
 * not use this file except in compliance with the License. You may
 * obtain a copy of the License at
 *
 * http://www.osedu.org/licenses/ECL-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an "AS IS"
 * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing
 * permissions and limitations under the License.
 */
package metridoc.plugins.impl.iterators

import java.sql.ResultSet
import metridoc.plugins.Plugin

import metridoc.utils.Assert
import org.apache.camel.Exchange
import metridoc.plugins.iterators.DefaultIteratorCreator

/**
 * Created by IntelliJ IDEA.
 * User: tbarker
 * Date: 9/27/11
 * Time: 8:53 AM
 */
@Plugin(category = "grid", name = "sql")
class SqlIterator extends DefaultIteratorCreator {

    ResultSet resultSet

    @Override
    Iterator doCreate(Exchange exchange) {
        def resultSet = exchange.in.getBody(ResultSet.class)
        Assert.notNull(resultSet, "exchange must contain a ResultSet to create an SqlIterator")
        return new SqlIterator(resultSet: resultSet)
    }

    @Override
    List doNext() {

        if (resultSet.next()) {
            def result = new SqlResult(map: resultSet.toRowResult())
            return result
        }

        return null
    }
}

class SqlResult implements List {

    LinkedHashMap map
    List values

    List getValues() {
        if(values) {
            return values
        }

        values = map.values() as List
    }

    @Override
    Object getProperty(String property) {
        if(map.containsKey(property)) {
            return map[property]
        }

        throw new MissingPropertyException(property, SqlResult.class)
    }

    int size() {
        return 0  //To change body of implemented methods use File | Settings | File Templates.
    }

    boolean isEmpty() {
        return false  //To change body of implemented methods use File | Settings | File Templates.
    }

    boolean contains(Object o) {
        return false  //To change body of implemented methods use File | Settings | File Templates.
    }

    Iterator iterator() {
        return null  //To change body of implemented methods use File | Settings | File Templates.
    }

    Object[] toArray() {
        return new Object[0]  //To change body of implemented methods use File | Settings | File Templates.
    }

    Object[] toArray(Object[] a) {
        return new Object[0]  //To change body of implemented methods use File | Settings | File Templates.
    }

    boolean add(Object e) {
        return false  //To change body of implemented methods use File | Settings | File Templates.
    }

    boolean remove(Object o) {
        return false  //To change body of implemented methods use File | Settings | File Templates.
    }

    boolean containsAll(Collection c) {
        return false  //To change body of implemented methods use File | Settings | File Templates.
    }

    boolean addAll(Collection c) {
        return false  //To change body of implemented methods use File | Settings | File Templates.
    }

    boolean addAll(int index, Collection c) {
        return false  //To change body of implemented methods use File | Settings | File Templates.
    }

    boolean removeAll(Collection c) {
        return false  //To change body of implemented methods use File | Settings | File Templates.
    }

    boolean retainAll(Collection c) {
        return false  //To change body of implemented methods use File | Settings | File Templates.
    }

    void clear() {
        //To change body of implemented methods use File | Settings | File Templates.
    }

    Object get(int index) {
        return null  //To change body of implemented methods use File | Settings | File Templates.
    }

    Object set(int index, Object element) {
        return null  //To change body of implemented methods use File | Settings | File Templates.
    }

    void add(int index, Object element) {
        //To change body of implemented methods use File | Settings | File Templates.
    }

    Object remove(int index) {
        return null  //To change body of implemented methods use File | Settings | File Templates.
    }

    int indexOf(Object o) {
        return 0  //To change body of implemented methods use File | Settings | File Templates.
    }

    int lastIndexOf(Object o) {
        return 0  //To change body of implemented methods use File | Settings | File Templates.
    }

    ListIterator listIterator() {
        return null  //To change body of implemented methods use File | Settings | File Templates.
    }

    ListIterator listIterator(int index) {
        return null  //To change body of implemented methods use File | Settings | File Templates.
    }

    List subList(int fromIndex, int toIndex) {
        return null  //To change body of implemented methods use File | Settings | File Templates.
    }
}






© 2015 - 2024 Weber Informatics LLC | Privacy Policy