001: /*
002: * Geotools2 - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2002-2006, Geotools Project Managment Committee (PMC)
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation;
009: * version 2.1 of the License.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: */
017: package org.geotools.arcsde.data;
018:
019: import java.io.IOException;
020:
021: import org.geotools.data.DataSourceException;
022:
023: import com.esri.sde.sdk.client.SeColumnDefinition;
024: import com.esri.sde.sdk.client.SeException;
025: import com.esri.sde.sdk.client.SeRow;
026: import com.esri.sde.sdk.client.SeShape;
027:
028: /**
029: * Wrapper for an SeRow so it allows asking multiple times for the same
030: * property.
031: *
032: * @author Gabriel Roldan, Axios Engineering
033: * @version $Id: SdeRow.java 25949 2007-06-20 16:07:37Z desruisseaux $
034: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/unsupported/arcsde/datastore/src/main/java/org/geotools/arcsde/data/SdeRow.java $
035: * @since 2.4.0
036: */
037: class SdeRow {
038: /** The actual SeRow */
039: private SeRow row;
040:
041: /** cached SeRow values */
042: private Object[] values;
043:
044: /**
045: * Creates a new SdeRow object.
046: *
047: * @param row DOCUMENT ME!
048: * @param previousValues needed in case of its a joined
049: * result, thus arcsde does not returns geometry attributes
050: * duplicated, just on their first occurrence (sigh)
051: *
052: * @throws IOException DOCUMENT ME!
053: * @throws DataSourceException DOCUMENT ME!
054: */
055: public SdeRow(SeRow row, Object[] previousValues)
056: throws IOException {
057: this .row = row;
058: int nCols;
059:
060: try {
061: nCols = row.getNumColumns();
062: } catch (NullPointerException e) {
063: e.printStackTrace();
064: throw e;
065: }
066:
067: values = new Object[nCols];
068:
069: int i = 0;
070:
071: int statusIndicator = 0;
072:
073: try {
074: for (i = 0; i < nCols; i++) {
075: statusIndicator = row.getIndicator(i);
076:
077: if (statusIndicator == SeRow.SE_IS_ALREADY_FETCHED
078: || statusIndicator == SeRow.SE_IS_REPEATED_FEATURE) {
079: values[i] = previousValues[i];
080: } else if (statusIndicator == SeRow.SE_IS_NULL_VALUE) {
081: values[i] = null;
082: } else {
083: values[i] = row.getObject(i);
084: }
085: }
086: } catch (SeException e) {
087: throw new DataSourceException("getting property #" + i, e);
088: } catch (Exception e) {
089: System.err.println("statusIndicator=" + statusIndicator
090: + ", i=" + i);
091: }
092: }
093:
094: /**
095: * DOCUMENT ME!
096: *
097: * @param index DOCUMENT ME!
098: *
099: * @return DOCUMENT ME!
100: *
101: * @throws IOException DOCUMENT ME!
102: */
103: public Object getObject(int index) throws IOException {
104: return values[index];
105: }
106:
107: /**
108: * DOCUMENT ME!
109: *
110: * @return DOCUMENT ME!
111: */
112: public Object[] getAll() {
113: return values;
114: }
115:
116: /**
117: * DOCUMENT ME!
118: *
119: * @param index DOCUMENT ME!
120: *
121: * @return DOCUMENT ME!
122: *
123: * @throws IOException DOCUMENT ME!
124: */
125: public Long getLong(int index) throws IOException {
126: return (Long) getObject(index);
127: }
128:
129: /**
130: * DOCUMENT ME!
131: *
132: * @param index DOCUMENT ME!
133: *
134: * @return DOCUMENT ME!
135: *
136: * @throws IOException DOCUMENT ME!
137: */
138: public SeShape getShape(int index) throws IOException {
139: return (SeShape) getObject(index);
140: }
141:
142: /**
143: * DOCUMENT ME!
144: *
145: * @return DOCUMENT ME!
146: */
147: public SeColumnDefinition[] getColumns() {
148: return row.getColumns();
149: }
150: }
|