sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1651674 [5/5] - in /sis/trunk: ./ application/sis-webapp/src/main/java/org/apache/sis/index/tree/ core/sis-build-helper/src/main/java/org/apache/sis/internal/doclet/ core/sis-build-helper/src/main/java/org/apache/sis/util/resources/ core/s...
Date Wed, 14 Jan 2015 14:01:47 GMT
Modified: sis/trunk/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/MetadataReader.java
URL: http://svn.apache.org/viewvc/sis/trunk/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/MetadataReader.java?rev=1651674&r1=1651673&r2=1651674&view=diff
==============================================================================
--- sis/trunk/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/MetadataReader.java [UTF-8] (original)
+++ sis/trunk/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/MetadataReader.java [UTF-8] Wed Jan 14 14:01:44 2015
@@ -70,6 +70,7 @@ import org.apache.sis.internal.netcdf.Gr
 import org.apache.sis.internal.system.DefaultFactories;
 import org.apache.sis.internal.metadata.Standards;
 import org.apache.sis.util.resources.Errors;
+import org.apache.sis.measure.Units;
 
 // The following dependency is used only for static final String constants.
 // Consequently the compiled class files should not have this dependency.
@@ -200,6 +201,15 @@ final class MetadataReader {
     }
 
     /**
+     * Returns the localized error resource bundle for the locale given by {@link #getLocale()}.
+     *
+     * @return The localized error resource bundle.
+     */
+    private Errors errors() {
+        return Errors.getResources(decoder.listeners.getLocale());
+    }
+
+    /**
      * Reads the attribute value for the given name, then trims the leading and trailing spaces.
      * If the value is null, empty or contains only spaces, then this method returns {@code null}.
      */
@@ -229,7 +239,7 @@ final class MetadataReader {
     private <T extends Enum<T>> T forEnumName(final Class<T> enumType, final String name) {
         final T code = Types.forEnumName(enumType, name);
         if (code == null && name != null) {
-            decoder.listeners.warning(Errors.format(Errors.Keys.UnknownEnumValue_2, enumType, name), null);
+            decoder.listeners.warning(errors().getString(Errors.Keys.UnknownEnumValue_2, enumType, name), null);
         }
         return code;
     }
@@ -245,7 +255,7 @@ final class MetadataReader {
              * CodeLists are not enums, but using the error message for enums is not completly wrong since
              * if we did not allowed CodeList to create new elements, then we are using it like an enum.
              */
-            decoder.listeners.warning(Errors.format(Errors.Keys.UnknownEnumValue_2, codeType, name), null);
+            decoder.listeners.warning(errors().getString(Errors.Keys.UnknownEnumValue_2, codeType, name), null);
         }
         return code;
     }
@@ -585,7 +595,7 @@ final class MetadataReader {
             identification.setPointOfContacts(singleton(pointOfContact));
         }
         addKeywords(identification, project,   KeywordType.valueOf("project"));
-        addKeywords(identification, publisher, KeywordType.valueOf("dataCenter"));
+        addKeywords(identification, publisher, KeywordType.valueOf("dataCentre"));
         identification.setSupplementalInformation(toInternationalString(stringValue(COMMENT)));
         return identification;
     }
@@ -862,9 +872,12 @@ final class MetadataReader {
         if (description != null && !(description = description.trim()).isEmpty() && !description.equals(name)) {
             band.setDescription(new SimpleInternationalString(description));
         }
-//TODO: Can't store the units, because the Band interface restricts it to length.
-//      We need the SampleDimension interface proposed in ISO 19115 revision draft.
-//      band.setUnits(Units.valueOf(variable.getUnitsString()));
+        final String units = variable.getUnitsString();
+        if (units != null) try {
+            band.setUnits(Units.valueOf(units));
+        } catch (IllegalArgumentException e) {
+            decoder.listeners.warning(errors().getString(Errors.Keys.CanNotAssignUnitToDimension_2, name, units), e);
+        }
         return band;
     }
 
@@ -933,7 +946,7 @@ final class MetadataReader {
         metadata.setMetadataIdentifier(identifier);
         final Date creation = decoder.dateValue(METADATA_CREATION);
         if (creation != null) {
-            metadata.setDates(singleton(new DefaultCitationDate(creation, DateType.CREATION)));
+            metadata.setDateInfo(singleton(new DefaultCitationDate(creation, DateType.CREATION)));
         }
         metadata.setMetadataScopes(singleton(new DefaultMetadataScope(ScopeCode.DATASET, null)));
         for (final String service : SERVICES) {

Modified: sis/trunk/storage/sis-netcdf/src/test/java/org/apache/sis/storage/netcdf/MetadataReaderTest.java
URL: http://svn.apache.org/viewvc/sis/trunk/storage/sis-netcdf/src/test/java/org/apache/sis/storage/netcdf/MetadataReaderTest.java?rev=1651674&r1=1651673&r2=1651674&view=diff
==============================================================================
--- sis/trunk/storage/sis-netcdf/src/test/java/org/apache/sis/storage/netcdf/MetadataReaderTest.java [UTF-8] (original)
+++ sis/trunk/storage/sis-netcdf/src/test/java/org/apache/sis/storage/netcdf/MetadataReaderTest.java [UTF-8] Wed Jan 14 14:01:44 2015
@@ -148,6 +148,7 @@ public final strictfp class MetadataRead
             "  │   └─Attribute group\n" +
             "  │       └─Attribute\n" +
             "  │           ├─Sequence identifier……………………………… SST\n" +
+            "  │           ├─Units…………………………………………………………………… K\n" +
             "  │           └─Description…………………………………………………… Sea temperature\n" +
             "  ├─Data quality info\n" +
             "  │   └─Lineage\n" +

Copied: sis/trunk/storage/sis-shapefile/src/main/java/org/apache/sis/internal/shapefile/ShapefileByteReader.java (from r1651615, sis/branches/JDK6/storage/sis-shapefile/src/main/java/org/apache/sis/internal/shapefile/ShapefileByteReader.java)
URL: http://svn.apache.org/viewvc/sis/trunk/storage/sis-shapefile/src/main/java/org/apache/sis/internal/shapefile/ShapefileByteReader.java?p2=sis/trunk/storage/sis-shapefile/src/main/java/org/apache/sis/internal/shapefile/ShapefileByteReader.java&p1=sis/branches/JDK6/storage/sis-shapefile/src/main/java/org/apache/sis/internal/shapefile/ShapefileByteReader.java&r1=1651615&r2=1651674&rev=1651674&view=diff
==============================================================================
--- sis/branches/JDK6/storage/sis-shapefile/src/main/java/org/apache/sis/internal/shapefile/ShapefileByteReader.java [UTF-8] (original)
+++ sis/trunk/storage/sis-shapefile/src/main/java/org/apache/sis/internal/shapefile/ShapefileByteReader.java [UTF-8] Wed Jan 14 14:01:44 2015
@@ -26,7 +26,7 @@ import org.apache.sis.feature.DefaultAtt
 import org.apache.sis.feature.DefaultFeatureType;
 import org.apache.sis.internal.shapefile.jdbc.*;
 import org.apache.sis.storage.shapefile.ShapeTypeEnum;
-import org.opengis.feature.Feature;
+import org.apache.sis.feature.AbstractFeature;
 
 import com.esri.core.geometry.*;
 
@@ -159,7 +159,7 @@ public class ShapefileByteReader extends
      * @param feature Feature to complete.
      * @throws InvalidShapefileFormatException if a validation problem occurs.
      */
-    public void completeFeature(Feature feature) throws InvalidShapefileFormatException {
+    public void completeFeature(AbstractFeature feature) throws InvalidShapefileFormatException {
         // insert points into some type of list
         int RecordNumber = getByteBuffer().getInt();
         @SuppressWarnings("unused")
@@ -197,7 +197,7 @@ public class ShapefileByteReader extends
      * Load point feature.
      * @param feature Feature to fill.
      */
-    private void loadPointFeature(Feature feature) {
+    private void loadPointFeature(AbstractFeature feature) {
         double x = getByteBuffer().getDouble();
         double y = getByteBuffer().getDouble();
         Point pnt = new Point(x, y);
@@ -209,7 +209,7 @@ public class ShapefileByteReader extends
      * @param feature Feature to fill.
      * @throws InvalidShapefileFormatException if the polygon cannot be handled.
      */
-    private void loadPolygonFeature(Feature feature) throws InvalidShapefileFormatException {
+    private void loadPolygonFeature(AbstractFeature feature) throws InvalidShapefileFormatException {
         /* double xmin = */getByteBuffer().getDouble();
         /* double ymin = */getByteBuffer().getDouble();
         /* double xmax = */getByteBuffer().getDouble();
@@ -245,7 +245,7 @@ public class ShapefileByteReader extends
      * Load polyline feature.
      * @param feature Feature to fill.
      */
-    private void loadPolylineFeature(Feature feature) {
+    private void loadPolylineFeature(AbstractFeature feature) {
         /* double xmin = */getByteBuffer().getDouble();
         /* double ymin = */getByteBuffer().getDouble();
         /* double xmax = */getByteBuffer().getDouble();

Modified: sis/trunk/storage/sis-shapefile/src/main/java/org/apache/sis/internal/shapefile/jdbc/AbstractJDBC.java
URL: http://svn.apache.org/viewvc/sis/trunk/storage/sis-shapefile/src/main/java/org/apache/sis/internal/shapefile/jdbc/AbstractJDBC.java?rev=1651674&r1=1651673&r2=1651674&view=diff
==============================================================================
--- sis/trunk/storage/sis-shapefile/src/main/java/org/apache/sis/internal/shapefile/jdbc/AbstractJDBC.java [UTF-8] (original)
+++ sis/trunk/storage/sis-shapefile/src/main/java/org/apache/sis/internal/shapefile/jdbc/AbstractJDBC.java [UTF-8] Wed Jan 14 14:01:44 2015
@@ -16,71 +16,47 @@
  */
 package org.apache.sis.internal.shapefile.jdbc;
 
+import java.io.File;
+import java.sql.*;
 import java.util.logging.Level;
-import java.util.logging.Logger;
-import java.util.logging.LogRecord;
-import java.sql.Wrapper;
-import java.sql.SQLException;
-import java.sql.SQLFeatureNotSupportedException;
-import java.sql.SQLWarning;
-import org.apache.sis.util.logging.Logging;
+
+import org.apache.sis.internal.shapefile.AutoChecker;
 
 
 /**
  * Base class for each JDBC class.
- *
  * @author  Marc Le Bihan
  * @version 0.5
  * @since   0.5
  * @module
  */
-abstract class AbstractJDBC implements Wrapper {
-    /**
-     * The logger for JDBC operations. We use the {@code "org.apache.sis.storage.jdbc"} logger name instead than
-     * the package name because this package is internal and may move in any future SIS version. The logger name
-     * does not need to be the name of an existing package. The important thing is to not change it, because it
-     * can been seen as a kind of public API since user may want to control verbosity level by logger names.
-     */
-    static final Logger LOGGER = Logging.getLogger("org.apache.sis.storage.jdbc");
-
+public abstract class AbstractJDBC extends AutoChecker implements Wrapper {
     /**
      * Constructs a new instance of a JDBC interface.
      */
-    AbstractJDBC() {
+    public AbstractJDBC() {
     }
 
     /**
      * Returns the JDBC interface implemented by this class.
      * This is used for formatting error messages.
-     *
      * @return The JDBC interface implemented by this class.
      */
-    abstract Class<?> getInterface();
+    abstract protected Class<?> getInterface();
 
     /**
      * Unsupported by default.
-     *
-     * @param  iface the type of the wrapped object.
+     * @param iface the type of the wrapped object.
      * @return The wrapped object.
      */
     @Override
     public <T> T unwrap(Class<T> iface) throws SQLException {
-        throw unsupportedOperation("unwrap");
-    }
-
-    /**
-     * Default to {@code false}, assuming that no non-standard features are handled.
-     *
-     * @param  iface the type of the wrapped object.
-     * @return {@code true} if this instance is a wrapper for the given type of object.
-     */
-    @Override
-    public boolean isWrapperFor(Class<?> iface) {
-        return false;
+        throw unsupportedOperation("unwrap", iface);
     }
 
     /**
      * Defaults to {@code null}.
+     * @return SQL Warning.
      */
     public SQLWarning getWarnings() {
         return null;
@@ -94,36 +70,91 @@ abstract class AbstractJDBC implements W
 
     /**
      * Returns an unsupported operation exception to be thrown.
-     *
-     * @param  methodOrWishedFeatureName The feature / call the caller attempted.
-     * @return The exception to throw.
-     */
-    final SQLException unsupportedOperation(final String methodOrWishedFeatureName) {
-        return new SQLFeatureNotSupportedException(Resources.format(Resources.Keys.UnsupportedDriverFeature_2,
-                getInterface(), methodOrWishedFeatureName));
+     * @param methodOrWishedFeatureName The feature / call the caller attempted.
+     * @return the not supported feature exception.
+     * @throws SQLFeatureNotSupportedException the not supported feature.
+     */
+    public final SQLFeatureNotSupportedException unsupportedOperation(final String methodOrWishedFeatureName) throws SQLFeatureNotSupportedException {
+        String message = format(Level.WARNING, "excp.unsupportedDriverFeature", getInterface(), methodOrWishedFeatureName, getClass().getSimpleName());
+        throw new SQLFeatureNotSupportedException(message);
+    }
+
+    /**
+     * Returns an unsupported operation exception to be thrown : this exception add parameters sent to the method that isn't implemented.
+     * @param methodOrWishedFeatureName The feature / call the caller attempted.
+     * @param args Arguments that where sent to the unimplemented function.
+     * @return the not supported feature exception.
+     * @throws SQLFeatureNotSupportedException the not supported feature.
+     */
+    public final SQLFeatureNotSupportedException unsupportedOperation(final String methodOrWishedFeatureName, Object... args) throws SQLFeatureNotSupportedException {
+        StringBuffer arguments = new StringBuffer();
+
+        for(Object arg : args) {
+            arguments.append(arguments.length() == 0 ? "" : ", ");   // Separator if needed.
+            arguments.append(arg instanceof String ? "\"" : "");     // Enclosing " for String, if needed.
+            arguments.append(arg == null ? "null" : arg.toString()); // String value of the argument.
+            arguments.append(arg instanceof String ? "\"" : "");     // Enclosing " for String, if needed.
+        }
+
+        String message = format(Level.WARNING, "excp.unsupportedDriverFeature_with_arguments", getInterface(), methodOrWishedFeatureName, getClass().getSimpleName(), arguments.toString());
+        throw new SQLFeatureNotSupportedException(message);
+    }
+
+    /**
+     * log a function call in the driver : very verbose.
+     * @param methodName The call the caller attempted.
+     */
+    public void logStep(final String methodName) {
+        format(Level.FINER, "log.step", methodName, getClass().getSimpleName());
+    }
+
+    /**
+     * log a function call in the driver : very verbose.
+     * @param methodName The call the caller attempted.
+     * @param args Arguments that where sent to the unimplemented function.
+     */
+    public void logStep(final String methodName, Object... args) {
+        format(Level.FINER, "log.step_with_arguments", methodName, getClass().getSimpleName(), arguments(args));
     }
 
     /**
      * log an unsupported feature as a warning.
-     *
      * @param methodName The call the caller attempted.
      */
-    final void logUnsupportedOperation(final String methodName) {
-        logWarning(methodName, Resources.Keys.UnsupportedDriverFeature_2, getInterface(), methodName);
+    public void logUnsupportedOperation(final String methodName) {
+        format(Level.WARNING, "excp.unsupportedDriverFeature", getInterface(), methodName, getClass().getSimpleName());
     }
 
     /**
-     * Logs a warning with the given resource keys and arguments.
-     *
-     * @param methodName  The name of the method which is emitting the warning.
-     * @param resourceKey One of the {@link org.apache.sis.internal.shapefile.jdbc.Resources.Keys} values.
-     * @param arguments   Arguments to be given to {@link java.text.MessageFormat}, or {@code null} if none.
-     */
-    final void logWarning(final String methodName, final short resourceKey, final Object... arguments) {
-        final LogRecord record = Resources.getResources(null).getLogRecord(Level.WARNING, resourceKey, arguments);
-        record.setSourceClassName(getClass().getCanonicalName());
-        record.setSourceMethodName(methodName);
-        record.setLoggerName(LOGGER.getName());
-        LOGGER.log(record);
+     * log an unsupported feature as a warning.
+     * @param methodName The call the caller attempted.
+     * @param args Arguments that where sent to the unimplemented function.
+     */
+    public void logUnsupportedOperation(final String methodName, Object... args) {
+        format(Level.WARNING, "excp.unsupportedDriverFeature_with_arguments", getInterface(), methodName, getClass().getSimpleName(), arguments(args));
+    }
+
+    /**
+     * Returns the Database File.
+     * @return Database File.
+     */
+    abstract protected File getFile();
+
+    /**
+     * Concat arguments in a StringBuffer.
+     * @param args arguments.
+     * @return Arguments.
+     */
+    private StringBuffer arguments(Object... args) {
+        StringBuffer arguments = new StringBuffer();
+
+        for(Object arg : args) {
+            arguments.append(arguments.length() == 0 ? "" : ", ");   // Separator if needed.
+            arguments.append(arg instanceof String ? "\"" : "");     // Enclosing " for String, if needed.
+            arguments.append(arg == null ? "null" : arg.toString()); // String value of the argument.
+            arguments.append(arg instanceof String ? "\"" : "");     // Enclosing " for String, if needed.
+        }
+
+        return arguments;
     }
 }

Modified: sis/trunk/storage/sis-shapefile/src/main/java/org/apache/sis/internal/shapefile/jdbc/DBFDriver.java
URL: http://svn.apache.org/viewvc/sis/trunk/storage/sis-shapefile/src/main/java/org/apache/sis/internal/shapefile/jdbc/DBFDriver.java?rev=1651674&r1=1651673&r2=1651674&view=diff
==============================================================================
--- sis/trunk/storage/sis-shapefile/src/main/java/org/apache/sis/internal/shapefile/jdbc/DBFDriver.java [UTF-8] (original)
+++ sis/trunk/storage/sis-shapefile/src/main/java/org/apache/sis/internal/shapefile/jdbc/DBFDriver.java [UTF-8] Wed Jan 14 14:01:44 2015
@@ -16,13 +16,16 @@
  */
 package org.apache.sis.internal.shapefile.jdbc;
 
+import java.io.*;
 import java.sql.*;
-import java.io.File;
-import java.io.IOException;
-import java.util.Properties;
-import java.util.logging.Logger;
-import org.apache.sis.util.ArgumentChecks;
-import org.apache.sis.internal.system.Modules;
+import java.util.*;
+import java.util.logging.*;
+
+import org.apache.sis.internal.shapefile.jdbc.connection.DBFConnection;
+import org.apache.sis.internal.system.*;
+
+// Branch-dependent imports
+import org.apache.sis.internal.jdk7.Objects;
 
 
 /**
@@ -41,11 +44,19 @@ public class DBFDriver extends AbstractJ
     }
 
     /**
+     * @see java.sql.Wrapper#isWrapperFor(java.lang.Class)
+     */
+    @Override
+    public boolean isWrapperFor(Class<?> iface) {
+        return iface.isAssignableFrom(getInterface());
+    }
+
+    /**
      * Returns the JDBC interface implemented by this class.
      * This is used for formatting error messages.
      */
     @Override
-    final Class<?> getInterface() {
+    final protected Class<?> getInterface() {
         return Driver.class;
     }
 
@@ -55,17 +66,17 @@ public class DBFDriver extends AbstractJ
      * @param  url  The path to a {@code .dbf} file.
      * @param  info Ignored in current implementation.
      * @return A connection to the given DBF file.
-     * @throws SQLException if this method can not create a connection to the given file.
+     * @throws InvalidDbaseFileFormatException if the database file format is invalid.
+     * @throws DbaseFileNotFoundException if the database file doesn't exist.
+     * @throws InvalidDbaseFileFormatException if the database file has a wrong format.
      */
     @Override
-    public Connection connect(final String url, @SuppressWarnings("unused") Properties info) throws SQLException {
-        ArgumentChecks.ensureNonNull("url", url);
-        try {
-            return new DBFConnection(new File(url));
-        } catch (IOException e) {
-            throw new SQLNonTransientConnectionException(Resources.format(
-                    Resources.Keys.InvalidDBFFormatDescriptor_2, url, e.getLocalizedMessage()));
-        }
+    @SuppressWarnings("resource") // the function opens a connection.
+    public Connection connect(final String url, @SuppressWarnings("unused") Properties info) throws InvalidDbaseFileFormatException, DbaseFileNotFoundException {
+        Objects.requireNonNull(url, "the DBase3 url cannot be null");
+        File file = new File(url);
+
+        return new DBFConnection(file, new MappedByteReader(file));
     }
 
     /**
@@ -76,16 +87,24 @@ public class DBFDriver extends AbstractJ
         if (!url.endsWith(".dbf")) {
             return false;
         }
+
         final File datafile = new File(url);
         return datafile.isFile(); // Future version should check for magic number.
     }
 
     /**
+     * @see org.apache.sis.internal.shapefile.jdbc.AbstractJDBC#getFile()
+     */
+    @Override protected File getFile() {
+        return null;
+    }
+
+    /**
      * Gets information about the possible properties for this driver.
      * The current version has none.
      */
     @Override
-    public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) {
+    public DriverPropertyInfo[] getPropertyInfo(@SuppressWarnings("unused") String url, @SuppressWarnings("unused") Properties info) {
         return new DriverPropertyInfo[0];
     }
 
@@ -120,8 +139,7 @@ public class DBFDriver extends AbstractJ
     /**
      * The logger used by this driver.
      */
-    // No @Override on JDK6
     public Logger getParentLogger() {
-        return LOGGER;
+        return super.getLogger();
     }
 }

Copied: sis/trunk/storage/sis-shapefile/src/main/java/org/apache/sis/internal/shapefile/jdbc/Dbase3ByteReader.java (from r1651615, sis/branches/JDK6/storage/sis-shapefile/src/main/java/org/apache/sis/internal/shapefile/jdbc/Dbase3ByteReader.java)
URL: http://svn.apache.org/viewvc/sis/trunk/storage/sis-shapefile/src/main/java/org/apache/sis/internal/shapefile/jdbc/Dbase3ByteReader.java?p2=sis/trunk/storage/sis-shapefile/src/main/java/org/apache/sis/internal/shapefile/jdbc/Dbase3ByteReader.java&p1=sis/branches/JDK6/storage/sis-shapefile/src/main/java/org/apache/sis/internal/shapefile/jdbc/Dbase3ByteReader.java&r1=1651615&r2=1651674&rev=1651674&view=diff
==============================================================================
--- sis/branches/JDK6/storage/sis-shapefile/src/main/java/org/apache/sis/internal/shapefile/jdbc/Dbase3ByteReader.java [UTF-8] (original)
+++ sis/trunk/storage/sis-shapefile/src/main/java/org/apache/sis/internal/shapefile/jdbc/Dbase3ByteReader.java [UTF-8] Wed Jan 14 14:01:44 2015
@@ -24,7 +24,7 @@ import java.util.Map;
 
 import org.apache.sis.internal.shapefile.jdbc.resultset.SQLIllegalColumnIndexException;
 import org.apache.sis.internal.shapefile.jdbc.resultset.SQLNoSuchFieldException;
-import org.opengis.feature.Feature;
+import org.apache.sis.feature.AbstractFeature;
 
 /**
  * Database byte reader contract. Used to allow refactoring of core byte management of a DBase file.
@@ -102,7 +102,7 @@ public interface Dbase3ByteReader {
      * Load a row into a feature.
      * @param feature Feature to fill.
      */
-    public void loadRowIntoFeature(Feature feature);
+    public void loadRowIntoFeature(AbstractFeature feature);
 
     /**
      * Checks if a next row is available. Warning : it may be a deleted one.

Copied: sis/trunk/storage/sis-shapefile/src/main/java/org/apache/sis/internal/shapefile/jdbc/MappedByteReader.java (from r1651615, sis/branches/JDK6/storage/sis-shapefile/src/main/java/org/apache/sis/internal/shapefile/jdbc/MappedByteReader.java)
URL: http://svn.apache.org/viewvc/sis/trunk/storage/sis-shapefile/src/main/java/org/apache/sis/internal/shapefile/jdbc/MappedByteReader.java?p2=sis/trunk/storage/sis-shapefile/src/main/java/org/apache/sis/internal/shapefile/jdbc/MappedByteReader.java&p1=sis/branches/JDK6/storage/sis-shapefile/src/main/java/org/apache/sis/internal/shapefile/jdbc/MappedByteReader.java&r1=1651615&r2=1651674&rev=1651674&view=diff
==============================================================================
--- sis/branches/JDK6/storage/sis-shapefile/src/main/java/org/apache/sis/internal/shapefile/jdbc/MappedByteReader.java [UTF-8] (original)
+++ sis/trunk/storage/sis-shapefile/src/main/java/org/apache/sis/internal/shapefile/jdbc/MappedByteReader.java [UTF-8] Wed Jan 14 14:01:44 2015
@@ -24,7 +24,7 @@ import java.util.logging.Level;
 
 import org.apache.sis.internal.shapefile.jdbc.resultset.SQLIllegalColumnIndexException;
 import org.apache.sis.internal.shapefile.jdbc.resultset.SQLNoSuchFieldException;
-import org.opengis.feature.Feature;
+import org.apache.sis.feature.AbstractFeature;
 
 
 /**
@@ -54,7 +54,7 @@ public class MappedByteReader extends Ab
      * Load a row into a feature.
      * @param feature Feature to fill.
      */
-    @Override public void loadRowIntoFeature(Feature feature) {
+    @Override public void loadRowIntoFeature(AbstractFeature feature) {
         // TODO: ignore deleted records
         getByteBuffer().get(); // denotes whether deleted or current
         // read first part of record

Modified: sis/trunk/storage/sis-shapefile/src/main/java/org/apache/sis/internal/shapefile/jdbc/package-info.java
URL: http://svn.apache.org/viewvc/sis/trunk/storage/sis-shapefile/src/main/java/org/apache/sis/internal/shapefile/jdbc/package-info.java?rev=1651674&r1=1651673&r2=1651674&view=diff
==============================================================================
--- sis/trunk/storage/sis-shapefile/src/main/java/org/apache/sis/internal/shapefile/jdbc/package-info.java [UTF-8] (original)
+++ sis/trunk/storage/sis-shapefile/src/main/java/org/apache/sis/internal/shapefile/jdbc/package-info.java [UTF-8] Wed Jan 14 14:01:44 2015
@@ -16,8 +16,8 @@
  */
 
 /**
- * Allows access to {@link org.apache.sis.storage.shapefile} storage through JDBC driver.
- *
+ * Allows access to the DBase3 part of a shapefile through JDBC driver.
+ * Many exceptions are declared inside this package, to help trouble descriptions and permit precise unit tests.
  * @author  Marc Le Bihan
  * @version 0.5
  * @since   0.5

Copied: sis/trunk/storage/sis-shapefile/src/main/java/org/apache/sis/storage/shapefile/InputFeatureStream.java (from r1651615, sis/branches/JDK6/storage/sis-shapefile/src/main/java/org/apache/sis/storage/shapefile/InputFeatureStream.java)
URL: http://svn.apache.org/viewvc/sis/trunk/storage/sis-shapefile/src/main/java/org/apache/sis/storage/shapefile/InputFeatureStream.java?p2=sis/trunk/storage/sis-shapefile/src/main/java/org/apache/sis/storage/shapefile/InputFeatureStream.java&p1=sis/branches/JDK6/storage/sis-shapefile/src/main/java/org/apache/sis/storage/shapefile/InputFeatureStream.java&r1=1651615&r2=1651674&rev=1651674&view=diff
==============================================================================
--- sis/branches/JDK6/storage/sis-shapefile/src/main/java/org/apache/sis/storage/shapefile/InputFeatureStream.java [UTF-8] (original)
+++ sis/trunk/storage/sis-shapefile/src/main/java/org/apache/sis/storage/shapefile/InputFeatureStream.java [UTF-8] Wed Jan 14 14:01:44 2015
@@ -33,7 +33,7 @@ import org.apache.sis.internal.shapefile
 import org.apache.sis.internal.shapefile.jdbc.sql.SQLInvalidStatementException;
 import org.apache.sis.internal.shapefile.jdbc.sql.SQLUnsupportedParsingFeatureException;
 import org.apache.sis.internal.shapefile.jdbc.statement.DBFStatement;
-import org.opengis.feature.Feature;
+import org.apache.sis.feature.AbstractFeature;
 
 /**
  * Input Stream of features.
@@ -139,7 +139,7 @@ public class InputFeatureStream extends
      * @throws SQLFeatureNotSupportedException if a SQL ability is not currently available through this driver.
      * @throws InvalidShapefileFormatException if the shapefile format is invalid.
      */
-    public Feature readFeature() throws SQLConnectionClosedException, SQLInvalidStatementException, SQLIllegalParameterException, SQLNoSuchFieldException, SQLUnsupportedParsingFeatureException, SQLNotNumericException, SQLNotDateException, SQLFeatureNotSupportedException, SQLIllegalColumnIndexException, InvalidShapefileFormatException {
+    public AbstractFeature readFeature() throws SQLConnectionClosedException, SQLInvalidStatementException, SQLIllegalParameterException, SQLNoSuchFieldException, SQLUnsupportedParsingFeatureException, SQLNotNumericException, SQLNotDateException, SQLFeatureNotSupportedException, SQLIllegalColumnIndexException, InvalidShapefileFormatException {
         try {
             if (endOfFile) {
                 return null;
@@ -150,7 +150,7 @@ public class InputFeatureStream extends
                 return null;
             }
 
-            Feature feature = featuresType.newInstance();
+            AbstractFeature feature = featuresType.newInstance();
             shapefileReader.completeFeature(feature);
             DBFDatabaseMetaData metadata = (DBFDatabaseMetaData)connection.getMetaData();
 

Modified: sis/trunk/storage/sis-shapefile/src/main/java/org/apache/sis/storage/shapefile/ShapeFile.java
URL: http://svn.apache.org/viewvc/sis/trunk/storage/sis-shapefile/src/main/java/org/apache/sis/storage/shapefile/ShapeFile.java?rev=1651674&r1=1651673&r2=1651674&view=diff
==============================================================================
--- sis/trunk/storage/sis-shapefile/src/main/java/org/apache/sis/storage/shapefile/ShapeFile.java [UTF-8] (original)
+++ sis/trunk/storage/sis-shapefile/src/main/java/org/apache/sis/storage/shapefile/ShapeFile.java [UTF-8] Wed Jan 14 14:01:44 2015
@@ -16,26 +16,17 @@
  */
 package org.apache.sis.storage.shapefile;
 
-import java.io.IOException;
-import java.nio.ByteOrder;
-import java.nio.MappedByteBuffer;
-import java.nio.channels.FileChannel;
-import java.io.FileInputStream;
-import java.util.HashMap;
-import java.util.Map;
-import java.text.MessageFormat;
-import com.esri.core.geometry.Point;
-import com.esri.core.geometry.Polygon;
-import com.esri.core.geometry.Polyline;
-import com.esri.core.geometry.Geometry;
+import java.io.File;
 
-import org.apache.sis.feature.DefaultFeatureType;
-import org.apache.sis.feature.DefaultAttributeType;
-import org.apache.sis.storage.DataStoreException;
+import org.apache.sis.internal.shapefile.InvalidShapefileFormatException;
+import org.apache.sis.internal.shapefile.ShapefileNotFoundException;
+import org.apache.sis.internal.shapefile.jdbc.DbaseFileNotFoundException;
+import org.apache.sis.internal.shapefile.jdbc.InvalidDbaseFileFormatException;
+import org.apache.sis.internal.shapefile.jdbc.sql.SQLInvalidStatementException;
 
 // Branch-dependent imports
 import org.apache.sis.internal.jdk7.Objects;
-import org.apache.sis.feature.AbstractFeature;
+
 
 /**
  * Provides a ShapeFile Reader.
@@ -49,309 +40,37 @@ import org.apache.sis.feature.AbstractFe
  * @see <a href="http://ulisse.elettra.trieste.it/services/doc/dbase/DBFstruct.htm">dBASE III File Structure</a>
  */
 public class ShapeFile {
-    /** Name of the Geometry field. */
-    private static final String GEOMETRY_NAME = "geometry";
-
-    /** File code. */
-    public int FileCode; // big
-
-    /** File length. */
-    public int FileLength; // big // The value for file length is the total length of the file in 16-bit words
-
-    /** File version. */
-    public int Version; // little
-
-    /** Shapefile type. */
-    public ShapeTypeEnum ShapeType; // little
-
-    /** X Min. */
-    public double xmin; // little
-
-    /** Y Min. */
-    public double ymin; // little
-
-    /** X Max. */
-    public double xmax; // little
-
-    /** Y Max. */
-    public double ymax; // little
-
-    /** Z Min. */
-    public double zmin; // little
+    /** Shapefile. */
+    private File shapeFile;
 
-    /** Z Max. */
-    public double zmax; // little
-
-    /** M Min. */
-    public double mmin; // little
-
-    /** M Max. */
-    public double mmax; // little
-
-    /** Underlying databasefile content. */
-    private Database dbf;
-
-    /** Features existing in the shapefile. */
-    public Map<Integer, AbstractFeature> FeatureMap = new HashMap<Integer, AbstractFeature>();
+    /** Database file. */
+    private File databaseFile;
 
     /**
      * Construct a Shapefile from a file.
      * @param shpfile file to read.
-     * @throws IOException if the file cannot be opened.
-     * @throws DataStoreException if the shapefile is not valid.
      */
-    public ShapeFile(String shpfile) throws IOException, DataStoreException {
+    public ShapeFile(String shpfile) {
         Objects.requireNonNull(shpfile, "The shapefile to load cannot be null.");
 
-        // Deduct database file name.
-        StringBuilder b = new StringBuilder(shpfile);
-        b.replace(shpfile.length() - 3, shpfile.length(), "dbf");
-
-        dbf = new Database(b.toString());
-
-        FileInputStream fis = new FileInputStream(shpfile);
-        FileChannel fc = fis.getChannel();
-        try {
-            int fsize = (int) fc.size();
-            MappedByteBuffer rf = fc.map(FileChannel.MapMode.READ_ONLY, 0, fsize);
-
-            this.FileCode = rf.getInt();
-            rf.getInt();
-            rf.getInt();
-            rf.getInt();
-            rf.getInt();
-            rf.getInt();
-            this.FileLength = rf.getInt() * 2;
-
-            rf.order(ByteOrder.LITTLE_ENDIAN);
-            this.Version = rf.getInt();
-            this.ShapeType = ShapeTypeEnum.get(rf.getInt());
-            this.xmin = rf.getDouble();
-            this.ymin = rf.getDouble();
-            this.xmax = rf.getDouble();
-            this.ymax = rf.getDouble();
-            this.zmin = rf.getDouble();
-            this.zmax = rf.getDouble();
-            this.mmin = rf.getDouble();
-            this.mmax = rf.getDouble();
-            rf.order(ByteOrder.BIG_ENDIAN);
-
-            dbf.loadDescriptor();
-            final DefaultFeatureType featureType = getFeatureType(shpfile);
-
-            dbf.getByteBuffer().get(); // should be 0d for field terminator
-            loadFeatures(featureType, rf);
-        } finally {
-            dbf.close();
-            fc.close();
-            fis.close();
-        }
-    }
-
-    /**
-     * Returns the underlying database file.
-     * @return Underlying database file.
-     */
-    public Database getDatabase() {
-        return this.dbf;
-    }
-
-    /**
-     * Returns the feature count of the shapefile.
-     * @return Feature count.
-     */
-    public int getFeatureCount() {
-        return this.dbf.getRecordCount();
-    }
-
-    /**
-     * Load the features of a shapefile.
-     * @param featureType Features descriptor.
-     * @param rf byte buffer mapper.
-     * @throws DataStoreException if a validation problem occurs.
-     */
-    private void loadFeatures(DefaultFeatureType featureType, MappedByteBuffer rf) throws DataStoreException {
-        for (Integer i = 0; i < this.dbf.getRecordCount(); i++) {
-            // insert points into some type of list
-            int RecordNumber = rf.getInt();
-            @SuppressWarnings("unused")
-            int ContentLength = rf.getInt();
-
-            rf.order(ByteOrder.LITTLE_ENDIAN);
-            int iShapeType = rf.getInt();
-            final AbstractFeature f = featureType.newInstance();
-
-            ShapeTypeEnum type = ShapeTypeEnum.get(iShapeType);
-
-            if (type == null)
-                throw new DataStoreException(MessageFormat.format("The shapefile feature type {0} doesn''t match to any known feature type.", featureType));
-
-            switch (type) {
-            case Point:
-                loadPointFeature(rf, f);
-                break;
-
-            case Polygon:
-                loadPolygonFeature(rf, f);
-                break;
-
-            case PolyLine:
-                loadPolylineFeature(rf, f);
-                break;
+        shapeFile = new File(shpfile);
 
-            default:
-                throw new DataStoreException("Unsupported shapefile type: " + iShapeType);
-            }
-
-            rf.order(ByteOrder.BIG_ENDIAN);
-            // read in each Record and Populate the Feature
-
-            dbf.loadRowIntoFeature(f);
-
-            this.FeatureMap.put(RecordNumber, f);
-        }
-    }
-
-    /**
-     * Load point feature.
-     * @param rf Byte buffer.
-     * @param feature Feature to fill.
-     */
-    private void loadPointFeature(MappedByteBuffer rf, AbstractFeature feature) {
-        double x = rf.getDouble();
-        double y = rf.getDouble();
-        Point pnt = new Point(x, y);
-        feature.setPropertyValue(GEOMETRY_NAME, pnt);
-    }
-
-    /**
-     * Load polygon feature.
-     * @param rf Byte buffer.
-     * @param feature Feature to fill.
-     * @throws DataStoreException if the polygon cannot be handled.
-     */
-    private void loadPolygonFeature(MappedByteBuffer rf, AbstractFeature feature) throws DataStoreException {
-        /* double xmin = */rf.getDouble();
-        /* double ymin = */rf.getDouble();
-        /* double xmax = */rf.getDouble();
-        /* double ymax = */rf.getDouble();
-        int NumParts = rf.getInt();
-        int NumPoints = rf.getInt();
-
-        if (NumParts > 1) {
-            throw new DataStoreException("Polygons with multiple linear rings have not implemented yet.");
-        }
-
-        // read the one part
-        @SuppressWarnings("unused")
-        int Part = rf.getInt();
-        Polygon poly = new Polygon();
-
-        // create a line from the points
-        double xpnt = rf.getDouble();
-        double ypnt = rf.getDouble();
-        // Point oldpnt = new Point(xpnt, ypnt);
-        poly.startPath(xpnt, ypnt);
-
-        for (int j = 0; j < NumPoints - 1; j++) {
-            xpnt = rf.getDouble();
-            ypnt = rf.getDouble();
-            poly.lineTo(xpnt, ypnt);
-        }
-
-        feature.setPropertyValue(GEOMETRY_NAME, poly);
-    }
-
-    /**
-     * Load polyline feature.
-     * @param rf Byte buffer.
-     * @param feature Feature to fill.
-     */
-    private void loadPolylineFeature(MappedByteBuffer rf, AbstractFeature feature) {
-        /* double xmin = */rf.getDouble();
-        /* double ymin = */rf.getDouble();
-        /* double xmax = */rf.getDouble();
-        /* double ymax = */rf.getDouble();
-
-        int NumParts = rf.getInt();
-        int NumPoints = rf.getInt();
-
-        int[] NumPartArr = new int[NumParts + 1];
-
-        for (int n = 0; n < NumParts; n++) {
-            int idx = rf.getInt();
-            NumPartArr[n] = idx;
-        }
-        NumPartArr[NumParts] = NumPoints;
-
-        double xpnt, ypnt;
-        Polyline ply = new Polyline();
-
-        for (int m = 0; m < NumParts; m++) {
-            xpnt = rf.getDouble();
-            ypnt = rf.getDouble();
-            ply.startPath(xpnt, ypnt);
-
-            for (int j = NumPartArr[m]; j < NumPartArr[m + 1] - 1; j++) {
-                xpnt = rf.getDouble();
-                ypnt = rf.getDouble();
-                ply.lineTo(xpnt, ypnt);
-            }
-        }
-
-        feature.setPropertyValue(GEOMETRY_NAME, ply);
-    }
-
-    /**
-     * Create a feature descriptor.
-     * @param name Name of the field.
-     * @return The feature type.
-     */
-    private DefaultFeatureType getFeatureType(final String name) {
-        Objects.requireNonNull(name, "The feature name cannot be null.");
-
-        final int n = dbf.getFieldsDescriptor().size();
-        final DefaultAttributeType<?>[] attributes = new DefaultAttributeType<?>[n + 1];
-        final Map<String, Object> properties = new HashMap<String, Object>(4);
-
-        // Load data field.
-        for (int i = 0; i < n; i++) {
-            properties.put(DefaultAttributeType.NAME_KEY, dbf.getFieldsDescriptor().get(i).getName());
-            attributes[i] = new DefaultAttributeType<String>(properties, String.class, 1, 1, null);
-        }
-
-        // Add geometry field.
-        properties.put(DefaultAttributeType.NAME_KEY, GEOMETRY_NAME);
-        attributes[n] = new DefaultAttributeType<Geometry>(properties, Geometry.class, 1, 1, null);
-
-        // Add name.
-        properties.put(DefaultAttributeType.NAME_KEY, name);
-        return new DefaultFeatureType(properties, false, null, attributes);
+        // Deduct database file name.
+        StringBuilder dbfFileName = new StringBuilder(shpfile);
+        dbfFileName.replace(shpfile.length() - 3, shpfile.length(), "dbf");
+        databaseFile = new File(dbfFileName.toString());
     }
 
     /**
-     * @see java.lang.Object#toString()
+     * Find features corresponding to an SQL request SELECT * FROM database.
+     * @return Features
+     * @throws SQLInvalidStatementException if the SQL statement is invalid.
+     * @throws DbaseFileNotFoundException if the database file has not been found.
+     * @throws ShapefileNotFoundException if the shapefile has not been found.
+     * @throws InvalidDbaseFileFormatException if the database file format is invalid.
+     * @throws InvalidShapefileFormatException if the shapefile format is invalid.
      */
-    @Override
-    public String toString() {
-        StringBuilder s = new StringBuilder();
-        String lineSeparator = System.getProperty("line.separator", "\n");
-
-        s.append("FileCode: ").append(FileCode).append(lineSeparator);
-        s.append("FileLength: ").append(FileLength).append(lineSeparator);
-        s.append("Version: ").append(Version).append(lineSeparator);
-        s.append("ShapeType: ").append(ShapeType).append(lineSeparator);
-        s.append("xmin: ").append(xmin).append(lineSeparator);
-        s.append("ymin: ").append(ymin).append(lineSeparator);
-        s.append("xmax: ").append(xmax).append(lineSeparator);
-        s.append("ymax: ").append(ymax).append(lineSeparator);
-        s.append("zmin: ").append(zmin).append(lineSeparator);
-        s.append("zmax: ").append(zmax).append(lineSeparator);
-        s.append("mmin: ").append(mmin).append(lineSeparator);
-        s.append("mmax: ").append(mmax).append(lineSeparator);
-        s.append("------------------------").append(lineSeparator);
-        s.append(dbf.toString());
-
-        return s.toString();
+    public InputFeatureStream findAll() throws InvalidDbaseFileFormatException, ShapefileNotFoundException, DbaseFileNotFoundException, SQLInvalidStatementException, InvalidShapefileFormatException {
+        return new InputFeatureStream(shapeFile, databaseFile);
     }
 }

Modified: sis/trunk/storage/sis-shapefile/src/test/java/org/apache/sis/internal/shapefile/jdbc/DBFResultSetTest.java
URL: http://svn.apache.org/viewvc/sis/trunk/storage/sis-shapefile/src/test/java/org/apache/sis/internal/shapefile/jdbc/DBFResultSetTest.java?rev=1651674&r1=1651673&r2=1651674&view=diff
==============================================================================
--- sis/trunk/storage/sis-shapefile/src/test/java/org/apache/sis/internal/shapefile/jdbc/DBFResultSetTest.java [UTF-8] (original)
+++ sis/trunk/storage/sis-shapefile/src/test/java/org/apache/sis/internal/shapefile/jdbc/DBFResultSetTest.java [UTF-8] Wed Jan 14 14:01:44 2015
@@ -16,106 +16,210 @@
  */
 package org.apache.sis.internal.shapefile.jdbc;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
 import java.sql.*;
-import java.io.File;
-import java.net.URL;
-import java.net.URISyntaxException;
-import org.apache.sis.storage.shapefile.Database;
-import org.apache.sis.test.DependsOnMethod;
-import org.apache.sis.test.TestCase;
-import org.junit.*;
+import java.text.MessageFormat;
+import java.util.ArrayList;
 
-import static org.junit.Assert.*;
+import org.apache.sis.internal.shapefile.jdbc.resultset.DBFRecordBasedResultSet;
+import org.apache.sis.test.DependsOnMethod;
+import org.junit.Test;
 
 
 /**
- * Tests {@link DBFResultSet}.
+ * Tests {@link DBFRecordBasedResultSet}.
  *
  * @author  Marc Le Bihan
  * @version 0.5
  * @since   0.5
  * @module
  */
-public class DBFResultSetTest extends TestCase {
-    /**
-     * The database file to use for testing purpose.
-     */
-    private File dbfFile;
-
-    /**
-     * Test setup.
-     *
-     * @throws URISyntaxException If an error occurred while getting the file to the test database.
-     */
-    @Before
-    public void setup() throws URISyntaxException {
-        final URL url = Database.class.getResource("SignedBikeRoute_4326_clipped.dbf");
-        assertNotNull("The database file used for testing doesn't exist.", url);
-        dbfFile = new File(url.toURI());
-        assertTrue(dbfFile.isFile());
-    }
-
-    /**
-     * Open and close a connection.
-     *
-     * @throws SQLException if an error occurred while querying the database.
-     */
-    @Test
-    public void openCloseConnection() throws SQLException {
-        final Driver     driver     = new DBFDriver();
-        final Connection connection = driver.connect(dbfFile.getAbsolutePath(), null);
-        assertFalse("Connection should be opened", connection.isClosed());
-        assertTrue ("Connection should be valid",  connection.isValid(0));
-
-        connection.close();
-        assertTrue ("Connection should be closed", connection.isClosed());
-        assertFalse("Connection should no more be valid", connection.isValid(0));
-    }
-
+public class DBFResultSetTest extends AbstractTestBaseForInternalJDBC {
     /**
      * Reads the first record.
-     *
      * @throws SQLException if an error occurred while querying the database.
      */
     @Test
-    @DependsOnMethod("openCloseConnection")
     public void readFirstRecord() throws SQLException {
-        final Driver     driver     = new DBFDriver();
-        final Connection connection = driver.connect(dbfFile.getAbsolutePath(), null);
-        final Statement  stmt       = connection.createStatement();
-        final ResultSet  rs         = stmt.executeQuery("SELECT * FROM SignedBikeRoute");
-        // We don't care currently of the request: we are returning everything each time.
-
-        rs.next();
-        assertEquals("getString(\"ST_NAME\")", "336TH ST", rs.getString("ST_NAME"));
-
-        rs.close();
-        stmt.close();
-        connection.close();
+        Connection connection = connect();
+        Statement stmt = connection.createStatement();
+        ResultSet rs = stmt.executeQuery("SELECT * FROM SignedBikeRoute");
+        try {
+            rs.next();
+            assertEquals("getString(\"ST_NAME\")", "36TH ST", rs.getString("ST_NAME"));                                    // ST_NAME Character(29)
+            assertEquals("getInt(\"FNODE_\")", 1199, rs.getInt("FNODE_"));                                                 // FNODE_ Number(10, 0)
+            assertEquals("getDouble(\"SHAPE_LEN\")", 43.0881492571, rs.getDouble("SHAPE_LEN"), 0.1);                       // SHAPE_LEN Number(19, 11)
+            assertEquals("getBigDecimal(\"SHAPE_LEN\")", 43.0881492571, rs.getBigDecimal("SHAPE_LEN").doubleValue(), 0.1); // SHAPE_LEN Number(19, 11)
+            assertEquals("getDate(\"TR_DATE\")", null, rs.getDate("TR_DATE"));                       // TR_DATE Date(8)
+        } finally {
+            rs.close();
+            stmt.close();
+            connection.close();
+        }
     }
 
     /**
      * Read all the DBF records.
-     *
      * @throws SQLException if an error occurred while querying the database.
      */
     @Test
     @DependsOnMethod("readFirstRecord")
     public void readAllRecords() throws SQLException {
-        final Driver     driver     = new DBFDriver();
-        final Connection connection = driver.connect(dbfFile.getAbsolutePath(), null);
-        final Statement  stmt       = connection.createStatement();
-        final ResultSet  rs         = stmt.executeQuery("SELECT * FROM SignedBikeRoute");
-        // We don't care currently of the request: we are returning everything each time.
-
-        int count = 0;
-        while (rs.next()) {
-            count++;
-        }
-        assertTrue("Less than one record was readed.", count > 1);
-
-        rs.close();
-        stmt.close();
-        connection.close();
+        Connection connection = connect();
+        Statement stmt = connection.createStatement();
+        ResultSet rs = stmt.executeQuery("SELECT * FROM SignedBikeRoute");
+        try {
+            int count = 0;
+
+            while(rs.next()) {
+                ArrayList<Object> record = new ArrayList<Object>();
+
+                record.add(rs.getLong("OBJECTID"));         // Type : Number, Field length : 10, Decimal positions : 0
+                record.add(rs.getLong("FNODE_"));           // Type : Number, Field length : 10, Decimal positions : 0
+                record.add(rs.getLong("TNODE_"));           // Type : Number, Field length : 10, Decimal positions : 0
+                record.add(rs.getLong("LPOLY_"));           // Type : Number, Field length : 10, Decimal positions : 0
+                record.add(rs.getLong("RPOLY_"));           // Type : Number, Field length : 10, Decimal positions : 0
+                record.add(rs.getLong("SCL_"));             // Type : Number, Field length : 10, Decimal positions : 0
+                record.add(rs.getLong("SCL_ID"));           // Type : Number, Field length : 10, Decimal positions : 0
+                record.add(rs.getLong("SCL_CODE"));         // Type : Number, Field length : 10, Decimal positions : 0
+                record.add(rs.getString("DXF_LAYER"));      // Type : Character, Field length : 16, Decimal positions : 0
+                record.add(rs.getString("SIS_ID"));         // Type : Character, Field length : 12, Decimal positions : 0
+                record.add(rs.getString("QUAD_CODE"));      // Type : Character, Field length : 1, Decimal positions : 0
+                record.add(rs.getString("PRIME_ST"));       // Type : Character, Field length : 4, Decimal positions : 0
+                record.add(rs.getString("INT_SEQ"));        // Type : Character, Field length : 3, Decimal positions : 0
+                record.add(rs.getString("ST_NAME"));        // Type : Character, Field length : 29, Decimal positions : 0
+                record.add(rs.getString("FDPRE"));          // Type : Character, Field length : 2, Decimal positions : 0
+                record.add(rs.getString("FNAME"));          // Type : Character, Field length : 30, Decimal positions : 0
+                record.add(rs.getString("FTYPE"));          // Type : Character, Field length : 4, Decimal positions : 0
+                record.add(rs.getString("FDSUF"));          // Type : Character, Field length : 2, Decimal positions : 0
+                record.add(rs.getLong("LEFTRANGE1"));       // Type : Number, Field length : 10, Decimal positions : 0
+                record.add(rs.getLong("LEFTRANGE2"));       // Type : Number, Field length : 10, Decimal positions : 0
+                record.add(rs.getLong("RGTRANGE1"));        // Type : Number, Field length : 10, Decimal positions : 0
+                record.add(rs.getLong("RGTRANGE2"));        // Type : Number, Field length : 10, Decimal positions : 0
+                record.add(rs.getString("STREET"));         // Type : Character, Field length : 26, Decimal positions : 0
+                record.add(rs.getString("QUAD"));           // Type : Character, Field length : 2, Decimal positions : 0
+                record.add(rs.getString("FROM_ST"));        // Type : Character, Field length : 100, Decimal positions : 0
+                record.add(rs.getString("TO_ST"));          // Type : Character, Field length : 100, Decimal positions : 0
+                record.add(rs.getString("ODD_WARD"));       // Type : Character, Field length : 1, Decimal positions : 0
+                record.add(rs.getString("EVEN_WARD"));      // Type : Character, Field length : 1, Decimal positions : 0
+                record.add(rs.getString("WARD"));           // Type : Character, Field length : 3, Decimal positions : 0
+                record.add(rs.getString("FC"));             // Type : Character, Field length : 40, Decimal positions : 0
+                record.add(rs.getInt("NHS"));               // Type : Number, Field length : 5, Decimal positions : 0
+                record.add(rs.getString("SIGNEDRTE1"));     // Type : Character, Field length : 5, Decimal positions : 0
+                record.add(rs.getString("RTETYPE1"));       // Type : Character, Field length : 10, Decimal positions : 0
+                record.add(rs.getString("SIGNEDRTE2"));     // Type : Character, Field length : 5, Decimal positions : 0
+                record.add(rs.getString("RTETYPE2"));       // Type : Character, Field length : 10, Decimal positions : 0
+                record.add(rs.getBigDecimal("AADT"));       // Type : Number, Field length : 19, Decimal positions : 8
+                record.add(rs.getBigDecimal("AADT_YEAR"));  // Type : Number, Field length : 19, Decimal positions : 8
+                record.add(rs.getBigDecimal("COM_SING_P")); // Type : Number, Field length : 19, Decimal positions : 8
+                record.add(rs.getBigDecimal("COM_SING_A")); // Type : Number, Field length : 19, Decimal positions : 8
+                record.add(rs.getBigDecimal("COM_COMB_P")); // Type : Number, Field length : 19, Decimal positions : 8
+                record.add(rs.getBigDecimal("COM_COMB_A")); // Type : Number, Field length : 19, Decimal positions : 8
+                record.add(rs.getString("IS_ONEWAY"));      // Type : Number, Field length : 5, Decimal positions : 0
+                record.add(rs.getString("TRAVEL_DIR"));     // Type : Character, Field length : 20, Decimal positions : 0
+                record.add(rs.getBigDecimal("LEN_MI"));     // Type : Number, Field length : 19, Decimal positions : 8
+                record.add(rs.getLong("STUDY_NET"));        // Type : Number, Field length : 10, Decimal positions : 0
+                record.add(rs.getDate("TR_DATE"));          // Type : Date, Field length : 8, Decimal positions : 0
+                record.add(rs.getBigDecimal("AADT_2"));     // Type : Number, Field length : 19, Decimal positions : 8
+                record.add(rs.getBigDecimal("AADT_FINAL")); // Type : Number, Field length : 19, Decimal positions : 8
+                record.add(rs.getBigDecimal("ROUTENET"));   // Type : Number, Field length : 19, Decimal positions : 8
+                record.add(rs.getString("NOTES"));          // Type : Character, Field length : 50, Decimal positions : 0
+                record.add(rs.getBigDecimal("LENGTH_MI"));  // Type : Number, Field length : 19, Decimal positions : 8
+                record.add(rs.getInt("NET_MARCH"));         // Type : Number, Field length : 5, Decimal positions : 0
+                record.add(rs.getString("SIGNED_JOI"));     // Type : Character, Field length : 5, Decimal positions : 0
+                record.add(rs.getString("SIGNED_FAC"));     // Type : Character, Field length : 30, Decimal positions : 0
+                record.add(rs.getString("NEW_USE"));        // Type : Character, Field length : 30, Decimal positions : 0
+                record.add(rs.getBigDecimal("SHAPE_LEN"));  // Type : Number, Field length : 19, Decimal positions : 11
+
+                count ++;
+                log.info(MessageFormat.format("Record {0,number} : {1}\n", count, record));
+            }
+
+            assertTrue("Less than one record was readed.", count > 1);
+        } finally {
+            rs.close();
+            stmt.close();
+            connection.close();
+        }
+    }
+
+    /**
+     * An attempt to use a closed resultSet must fail with the correct exception and message.
+     * @throws SQLException if an error occurred while opening the database, the statement or the resultset.
+     */
+    @Test
+    public void resultSetClosed() throws SQLException {
+        // 1) Open a connection, open a statement, open and close a ResultSet.
+        String sql = "SELECT * FROM SignedBikeRoute";
+        Connection connection = connect();
+        Statement stmt = connection.createStatement();
+        try {
+            // Then, attempt to use it.
+            try {
+                ResultSet rs = stmt.executeQuery(sql);
+                rs.close();
+            }
+            catch(SQLConnectionClosedException e) {
+                assertEquals("The database name in this exception is not well set.", e.getDatabase().getName(), dbfFile.getName());
+                assertEquals("The SQL Query is exception is not well set.", e.getSQL(), sql);
+            }
+            catch(SQLException e) {
+                fail("Not the expected exception for using a closed ResultSet.");
+            }
+        } finally {
+            stmt.close();
+            connection.close();
+        }
+
+        // 2) Same, but we close the connection instead.
+        connection = connect();
+        stmt = connection.createStatement();
+        ResultSet rs = stmt.executeQuery(sql);
+
+        connection.close(); // At this time, you expect also a warning on the console, telling that you have one statement and one ResultSet still opened.
+
+        // Then, attempt to use it.
+        try {
+            rs.next();
+        }
+        catch(SQLConnectionClosedException e) {
+            assertEquals("The database name is exception message is not well set.", e.getDatabase().getName(), dbfFile.getName());
+        }
+        catch(SQLException e) {
+            fail("Not the expected exception for using a closed ResultSet.");
+        }
+        finally {
+            rs.close();
+            stmt.close();
+        }
+
+        // 3) Same, but we close the statement instead .
+        Connection cnt = connect();
+        try {
+            stmt = cnt.createStatement();
+            rs = stmt.executeQuery(sql);
+
+            stmt.close(); // At this time, you expect also a information message on the console, telling that the statement has closed its current ResultSet.
+
+            // Then, attempt to use it.
+            try {
+                rs.next();
+            }
+            catch(SQLConnectionClosedException e) {
+                assertEquals("The database name is exception message is not well set.", e.getDatabase().getName(), dbfFile.getName());
+            }
+            catch(SQLException e) {
+                fail("Not the expected exception for using a closed ResultSet.");
+            }
+            finally {
+                rs.close();
+                stmt.close();
+            }
+        } finally {
+            cnt.close();
+        }
     }
 }

Modified: sis/trunk/storage/sis-shapefile/src/test/java/org/apache/sis/storage/shapefile/ShapeFileTest.java
URL: http://svn.apache.org/viewvc/sis/trunk/storage/sis-shapefile/src/test/java/org/apache/sis/storage/shapefile/ShapeFileTest.java?rev=1651674&r1=1651673&r2=1651674&view=diff
==============================================================================
--- sis/trunk/storage/sis-shapefile/src/test/java/org/apache/sis/storage/shapefile/ShapeFileTest.java [UTF-8] (original)
+++ sis/trunk/storage/sis-shapefile/src/test/java/org/apache/sis/storage/shapefile/ShapeFileTest.java [UTF-8] Wed Jan 14 14:01:44 2015
@@ -17,13 +17,13 @@
 package org.apache.sis.storage.shapefile;
 
 import java.io.File;
-import java.io.IOException;
 import java.net.URISyntaxException;
-import org.apache.sis.storage.DataStoreException;
+import java.sql.SQLException;
+
+import org.apache.sis.internal.shapefile.InvalidShapefileFormatException;
 import org.apache.sis.test.TestCase;
 import org.junit.Test;
-
-import static org.junit.Assert.*;
+import org.apache.sis.feature.AbstractFeature;
 
 
 /**
@@ -48,36 +48,55 @@ public final strictfp class ShapeFileTes
     /**
      * Test polylines count.
      * @throws URISyntaxException if the resource name is incorrect.
-     * @throws IOException if the shapefile cannot be found or an I/O error occurs.
-     * @throws DataStoreException if the shapefile has a structure problem.
+     * @throws InvalidShapefileFormatException if the shapefile format is invalid.
+     * @throws SQLException if any SQL Exception occuring.
      */
     @Test
-    public void testPolyineCount() throws URISyntaxException, IOException, DataStoreException {
+    public void testPolyineCount() throws URISyntaxException, SQLException, InvalidShapefileFormatException {
         ShapeFile shp = new ShapeFile(path("SignedBikeRoute_4326_clipped.shp"));
-        assertEquals(shp.FeatureMap.size(), shp.getFeatureCount());
+        readAll(shp);
     }
 
     /**
      * Test polygon count.
      * @throws URISyntaxException if the resource name is incorrect.
-     * @throws IOException if the shapefile cannot be found or an I/O error occurs.
-     * @throws DataStoreException if the shapefile has a structure problem.
+     * @throws InvalidShapefileFormatException if the shapefile format is invalid.
+     * @throws SQLException if any SQL Exception occuring.
      */
      @Test
-     public void testPolygonCount() throws URISyntaxException, IOException, DataStoreException {
+     public void testPolygonCount() throws URISyntaxException, SQLException, InvalidShapefileFormatException {
         ShapeFile shp = new ShapeFile(path("ANC90Ply_4326.shp"));
-        assertEquals(shp.FeatureMap.size(), shp.getFeatureCount());
+        readAll(shp);
     }
 
      /**
       * Test point count.
       * @throws URISyntaxException if the resource name is incorrect.
-      * @throws IOException if the shapefile cannot be found or an I/O error occurs.
-      * @throws DataStoreException if the shapefile has a structure problem.
+      * @throws InvalidShapefileFormatException if the shapefile format is invalid.
+      * @throws SQLException if any SQL Exception occuring.
       */
      @Test
-     public void testPointCount() throws URISyntaxException, IOException, DataStoreException {
+     public void testPointCount() throws URISyntaxException, SQLException, InvalidShapefileFormatException {
         ShapeFile shp = new ShapeFile(path("ABRALicenseePt_4326_clipped.shp"));
-        assertEquals(shp.FeatureMap.size(), shp.getFeatureCount());
+        readAll(shp);
+     }
+
+    /**
+     * Read all the shapefile content.
+     * @param shp Shapefile to read.
+     * @throws InvalidShapefileFormatException if the shapefile format is invalid.
+     * @throws SQLException if any SQL Exception occuring.
+     */
+    private void readAll(ShapeFile shp) throws SQLException, InvalidShapefileFormatException {
+        InputFeatureStream is = shp.findAll();
+        try {
+            AbstractFeature feature = is.readFeature();
+
+            while(feature != null) {
+                feature = is.readFeature();
+            }
+        } finally {
+            is.close();
+        }
     }
 }

Modified: sis/trunk/storage/sis-shapefile/src/test/java/org/apache/sis/test/suite/ShapefileTestSuite.java
URL: http://svn.apache.org/viewvc/sis/trunk/storage/sis-shapefile/src/test/java/org/apache/sis/test/suite/ShapefileTestSuite.java?rev=1651674&r1=1651673&r2=1651674&view=diff
==============================================================================
--- sis/trunk/storage/sis-shapefile/src/test/java/org/apache/sis/test/suite/ShapefileTestSuite.java [UTF-8] (original)
+++ sis/trunk/storage/sis-shapefile/src/test/java/org/apache/sis/test/suite/ShapefileTestSuite.java [UTF-8] Wed Jan 14 14:01:44 2015
@@ -26,7 +26,10 @@ import org.junit.BeforeClass;
  */
 @Suite.SuiteClasses({
     org.apache.sis.storage.shapefile.ShapeFileTest.class,
-    org.apache.sis.internal.shapefile.jdbc.DBFResultSetTest.class
+    org.apache.sis.internal.shapefile.jdbc.DBFConnectionTest.class,
+    org.apache.sis.internal.shapefile.jdbc.DBFStatementTest.class,
+    org.apache.sis.internal.shapefile.jdbc.DBFResultSetTest.class,
+    org.apache.sis.internal.shapefile.jdbc.sql.WhereClauseTest.class
 })
 public final strictfp class ShapefileTestSuite extends TestSuite {
     /**



Mime
View raw message