Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache 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.apache.org/licenses/LICENSE-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 groovy.sql;
 
 
 import java.util.Map;
 import java.util.Set;

Represents an extent of objects. It's primarily used by methods of Groovy's Sql class to return ResultSet data in map form; allowing access to the result of a SQL query by the name of the column, or by the column number.

Author(s):
Jean-Louis Berliet
 
 public class GroovyRowResult extends GroovyObjectSupport implements Map {
 
     private final Map result;
 
     public GroovyRowResult(Map result) {
         this. = result;
     }

    
Retrieve the value of the property by its (case-insensitive) name.

Parameters:
property is the name of the property to look at
Returns:
the value of the property
 
     public Object getProperty(String property) {
         try {
             Object key = lookupKeyIgnoringCase(property);
             if (key != null) {
                 return .get(key);
             }
             throw new MissingPropertyException(propertyGroovyRowResult.class);
         }
         catch (Exception e) {
             throw new MissingPropertyException(propertyGroovyRowResult.classe);
         }
     }
 
     private Object lookupKeyIgnoringCase(Object key) {
         // try some special cases first for efficiency
         if (.containsKey(key))
             return key;
         if (!(key instanceof CharSequence))
             return null;
         String keyStr = key.toString();
         for (Object next : .keySet()) {
             if (!(next instanceof String))
                 continue;
             if (keyStr.equalsIgnoreCase((String)next))
                 return next;
         }
         return null;
     }

    
Retrieve the value of the property by its index. A negative index will count backwards from the last column.

Parameters:
index is the number of the column to look at
Returns:
the value of the property
 
     public Object getAt(int index) {
         try {
             // a negative index will count backwards from the last column.
             if (index < 0)
                 index += .size();
             Iterator it = .values().iterator();
             int i = 0;
             Object obj = null;
             while ((obj == null) && (it.hasNext())) {
                 if (i == index)
                     obj = it.next();
                 else
                     it.next();
                 i++;
            }
            return obj;
        }
        catch (Exception e) {
            throw new MissingPropertyException(Integer.toString(index), GroovyRowResult.classe);
        }
    }
    public String toString() {
        return .toString();
    }
    /*
     * The following methods are needed for implementing the Map interface.
     * They are mostly delegating the request to the provided Map.
     */
     
    public void clear() {
        .clear();
    }

    
Checks if the result contains (ignoring case) the given key.

Parameters:
key the property name to look for
Returns:
true if the result contains this property name
    public boolean containsKey(Object key) {
        return lookupKeyIgnoringCase(key) != null;
    }
    public boolean containsValue(Object value) {
        return .containsValue(value);
    }
    public Set entrySet() {
        return .entrySet();
    }
    public boolean equals(Object o) {
        return .equals(o);
    }

    
Find the property value for the given name (ignoring case).

Parameters:
property the name of the property to get
Returns:
the property value
    public Object get(Object property) {
        if (property instanceof String)
            return getProperty((String)property);
        return null;
    }
    public int hashCode() {
        return .hashCode();
    }
    public boolean isEmpty() {
        return .isEmpty();
    }
    public Set keySet() {
        return .keySet();
    }

    
Associates the specified value with the specified property name in this result.

Parameters:
key the property name for the result
value the property value for the result
Returns:
the previous value associated with key, or null if there was no mapping for key. (A null return can also indicate that the map previously associated null with key.)
    @SuppressWarnings("unchecked")
    public Object put(Object keyObject value) {
        // avoid different case keys being added by explicit remove
        Object orig = remove(key);
        .put(keyvalue);
        return orig;
    }

    
Copies all of the mappings from the specified map to this result. If the map contains different case versions of the same (case-insensitive) key only the last (according to the natural ordering of the supplied map) will remain after the putAll method has returned.

Parameters:
t the mappings to store in this result
    @SuppressWarnings("unchecked")
    public void putAll(Map t) {
        // don't delegate to putAll since we want case handling from put
        for (Entry next : (Set<Entry>) t.entrySet()) {
            put(next.getKey(), next.getValue());
        }
    }
    public Object remove(Object rawKey) {
        return .remove(lookupKeyIgnoringCase(rawKey));
    }
    public int size() {
        return .size();
    }
    public Collection values() {
        return .values();
    }
New to GrepCode? Check out our FAQ X