You can subscribe to this list here.
| 2001 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(39) |
Dec
(70) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2002 |
Jan
(52) |
Feb
(168) |
Mar
(248) |
Apr
(143) |
May
(418) |
Jun
(558) |
Jul
(702) |
Aug
(311) |
Sep
(141) |
Oct
(350) |
Nov
(172) |
Dec
(182) |
| 2003 |
Jan
(320) |
Feb
(362) |
Mar
(356) |
Apr
(218) |
May
(447) |
Jun
(203) |
Jul
(745) |
Aug
(494) |
Sep
(175) |
Oct
(422) |
Nov
(554) |
Dec
(162) |
| 2004 |
Jan
(217) |
Feb
(353) |
Mar
(228) |
Apr
(407) |
May
(211) |
Jun
(270) |
Jul
(264) |
Aug
(198) |
Sep
(268) |
Oct
(227) |
Nov
(118) |
Dec
(47) |
| 2005 |
Jan
(207) |
Feb
(243) |
Mar
(297) |
Apr
(197) |
May
(281) |
Jun
(166) |
Jul
(164) |
Aug
(92) |
Sep
(155) |
Oct
(196) |
Nov
(189) |
Dec
(114) |
| 2006 |
Jan
(129) |
Feb
(219) |
Mar
(274) |
Apr
(213) |
May
(245) |
Jun
(220) |
Jul
(376) |
Aug
(347) |
Sep
(179) |
Oct
(493) |
Nov
(448) |
Dec
(339) |
| 2007 |
Jan
(304) |
Feb
(273) |
Mar
(237) |
Apr
(186) |
May
(215) |
Jun
(320) |
Jul
(229) |
Aug
(313) |
Sep
(331) |
Oct
(279) |
Nov
(347) |
Dec
(266) |
| 2008 |
Jan
(332) |
Feb
(280) |
Mar
(203) |
Apr
(277) |
May
(301) |
Jun
(356) |
Jul
(292) |
Aug
(203) |
Sep
(277) |
Oct
(142) |
Nov
(210) |
Dec
(239) |
| 2009 |
Jan
(250) |
Feb
(193) |
Mar
(174) |
Apr
(183) |
May
(342) |
Jun
(230) |
Jul
(292) |
Aug
(161) |
Sep
(204) |
Oct
(280) |
Nov
(281) |
Dec
(175) |
| 2010 |
Jan
(113) |
Feb
(106) |
Mar
(199) |
Apr
(166) |
May
(298) |
Jun
(147) |
Jul
(175) |
Aug
(192) |
Sep
(71) |
Oct
(79) |
Nov
(58) |
Dec
(55) |
| 2011 |
Jan
(83) |
Feb
(169) |
Mar
(142) |
Apr
(207) |
May
(311) |
Jun
(183) |
Jul
(218) |
Aug
(190) |
Sep
(158) |
Oct
(197) |
Nov
(93) |
Dec
(74) |
| 2012 |
Jan
(92) |
Feb
(50) |
Mar
(64) |
Apr
(45) |
May
(100) |
Jun
(70) |
Jul
(3) |
Aug
(1) |
Sep
(2) |
Oct
(5) |
Nov
(7) |
Dec
(4) |
| 2013 |
Jan
(6) |
Feb
(2) |
Mar
(2) |
Apr
(4) |
May
(3) |
Jun
|
Jul
(2) |
Aug
|
Sep
|
Oct
(1) |
Nov
(1) |
Dec
|
| 2014 |
Jan
(2) |
Feb
(2) |
Mar
(2) |
Apr
(3) |
May
(3) |
Jun
(1) |
Jul
|
Aug
(4) |
Sep
|
Oct
(1) |
Nov
(1) |
Dec
|
| 2015 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(1) |
Jul
|
Aug
(1) |
Sep
|
Oct
|
Nov
(1) |
Dec
(1) |
| 2016 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(1) |
Jun
(1) |
Jul
|
Aug
(3) |
Sep
|
Oct
|
Nov
(1) |
Dec
|
| 2017 |
Jan
(1) |
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
|
From: <svn...@os...> - 2012-01-25 07:01:52
|
Author: ang05a
Date: 2012-01-24 23:01:42 -0800 (Tue, 24 Jan 2012)
New Revision: 38524
Modified:
trunk/modules/extension/app-schema/app-schema/src/test/resources/test-data/CGITermValue.xml
trunk/modules/extension/app-schema/app-schema/src/test/resources/test-data/CompositionPart.xml
trunk/modules/extension/app-schema/app-schema/src/test/resources/test-data/FirstParentFeature.xml
trunk/modules/extension/app-schema/app-schema/src/test/resources/test-data/GeologicUnit.xml
trunk/modules/extension/app-schema/app-schema/src/test/resources/test-data/SecondParentFeature.xml
Log:
Removing functions in gt-app-schema test mapping files temporarily for Oracle online tests.
Modified: trunk/modules/extension/app-schema/app-schema/src/test/resources/test-data/CGITermValue.xml
===================================================================
--- trunk/modules/extension/app-schema/app-schema/src/test/resources/test-data/CGITermValue.xml 2012-01-25 05:49:34 UTC (rev 38523)
+++ trunk/modules/extension/app-schema/app-schema/src/test/resources/test-data/CGITermValue.xml 2012-01-25 07:01:42 UTC (rev 38524)
@@ -86,7 +86,7 @@
FEATURE_LINK
</targetAttribute>
<sourceExpression>
- <OCQL>strTrim(getId())</OCQL>
+ <OCQL>getId()</OCQL>
</sourceExpression>
</AttributeMapping>
</attributeMappings>
@@ -116,7 +116,7 @@
FEATURE_LINK
</targetAttribute>
<sourceExpression>
- <OCQL>strTrim(getId())</OCQL>
+ <OCQL>getId()</OCQL>
</sourceExpression>
</AttributeMapping>
</attributeMappings>
Modified: trunk/modules/extension/app-schema/app-schema/src/test/resources/test-data/CompositionPart.xml
===================================================================
--- trunk/modules/extension/app-schema/app-schema/src/test/resources/test-data/CompositionPart.xml 2012-01-25 05:49:34 UTC (rev 38523)
+++ trunk/modules/extension/app-schema/app-schema/src/test/resources/test-data/CompositionPart.xml 2012-01-25 07:01:42 UTC (rev 38524)
@@ -96,7 +96,7 @@
<AttributeMapping>
<targetAttribute>gsml:lithology</targetAttribute>
<sourceExpression>
- <OCQL>strTrim(getId())</OCQL>
+ <OCQL>getID()</OCQL>
<linkElement>gsml:ControlledConcept</linkElement>
<linkField>FEATURE_LINK</linkField>
</sourceExpression>
@@ -107,7 +107,7 @@
FEATURE_LINK
</targetAttribute>
<sourceExpression>
- <OCQL>strTrim(getId())</OCQL>
+ <OCQL>getId()</OCQL>
</sourceExpression>
</AttributeMapping>
</attributeMappings>
Modified: trunk/modules/extension/app-schema/app-schema/src/test/resources/test-data/FirstParentFeature.xml
===================================================================
--- trunk/modules/extension/app-schema/app-schema/src/test/resources/test-data/FirstParentFeature.xml 2012-01-25 05:49:34 UTC (rev 38523)
+++ trunk/modules/extension/app-schema/app-schema/src/test/resources/test-data/FirstParentFeature.xml 2012-01-25 07:01:42 UTC (rev 38524)
@@ -41,7 +41,7 @@
<AttributeMapping>
<targetAttribute>ex:nestedFeature</targetAttribute>
<sourceExpression>
- <OCQL>strTrim(getID())</OCQL>
+ <OCQL>getID()</OCQL>
<linkElement>simpleContent</linkElement>
<linkField>FEATURE_LINK[1]</linkField>
</sourceExpression>
Modified: trunk/modules/extension/app-schema/app-schema/src/test/resources/test-data/GeologicUnit.xml
===================================================================
--- trunk/modules/extension/app-schema/app-schema/src/test/resources/test-data/GeologicUnit.xml 2012-01-25 05:49:34 UTC (rev 38523)
+++ trunk/modules/extension/app-schema/app-schema/src/test/resources/test-data/GeologicUnit.xml 2012-01-25 07:01:42 UTC (rev 38524)
@@ -111,7 +111,7 @@
FEATURE_LINK
</targetAttribute>
<sourceExpression>
- <OCQL>strTrim(getId())</OCQL>
+ <OCQL>getId()</OCQL>
</sourceExpression>
</AttributeMapping>
<AttributeMapping>
Modified: trunk/modules/extension/app-schema/app-schema/src/test/resources/test-data/SecondParentFeature.xml
===================================================================
--- trunk/modules/extension/app-schema/app-schema/src/test/resources/test-data/SecondParentFeature.xml 2012-01-25 05:49:34 UTC (rev 38523)
+++ trunk/modules/extension/app-schema/app-schema/src/test/resources/test-data/SecondParentFeature.xml 2012-01-25 07:01:42 UTC (rev 38524)
@@ -43,7 +43,7 @@
<AttributeMapping>
<targetAttribute>ex:nestedFeature</targetAttribute>
<sourceExpression>
- <OCQL>strTrim(getID())</OCQL>
+ <OCQL>getID()</OCQL>
<linkElement>ex:SimpleContent</linkElement>
<linkField>FEATURE_LINK[2]</linkField>
</sourceExpression>
|
|
From: <svn...@os...> - 2012-01-25 05:49:42
|
Author: ang05a
Date: 2012-01-24 21:49:34 -0800 (Tue, 24 Jan 2012)
New Revision: 38523
Added:
trunk/modules/extension/app-schema/app-schema/src/test/java/org/geotools/util/ComplexAttributeConverterFactoryTest.java
Modified:
trunk/modules/extension/app-schema/app-schema/src/main/java/org/geotools/util/ComplexAttributeConverterFactory.java
Log:
GEOT-3908: ComplexAttributeConverterFactory creates misbehaving converters
Modified: trunk/modules/extension/app-schema/app-schema/src/main/java/org/geotools/util/ComplexAttributeConverterFactory.java
===================================================================
--- trunk/modules/extension/app-schema/app-schema/src/main/java/org/geotools/util/ComplexAttributeConverterFactory.java 2012-01-23 17:43:19 UTC (rev 38522)
+++ trunk/modules/extension/app-schema/app-schema/src/main/java/org/geotools/util/ComplexAttributeConverterFactory.java 2012-01-25 05:49:34 UTC (rev 38523)
@@ -20,9 +20,12 @@
import java.util.Collection;
import org.geotools.factory.Hints;
+import org.geotools.feature.AttributeImpl;
+import org.geotools.filter.identity.FeatureIdImpl;
import org.opengis.feature.Attribute;
import org.opengis.feature.ComplexAttribute;
import org.opengis.feature.Property;
+import org.opengis.filter.identity.FeatureId;
/**
* This converter retrieves the values out of attributes.
@@ -39,32 +42,31 @@
if (ComplexAttribute.class.isAssignableFrom(source)) {
return new Converter() {
public Object convert(Object source, Class target) throws Exception {
- while (source instanceof ComplexAttribute) {
- if (!((ComplexAttribute) source).getType().getDescriptors().isEmpty()) {
- // this is not the leaf type..
+ if (source instanceof ComplexAttribute) {
+ Collection<? extends Property> valueMap = ((ComplexAttribute) source)
+ .getValue();
+ if (valueMap.isEmpty() || valueMap.size() > 1) {
return null;
} else {
- Collection<? extends Property> valueMap = ((ComplexAttribute) source)
- .getValue();
- if (valueMap.isEmpty()) {
- return null;
- } else {
- // there should only be one value
- source = valueMap.iterator().next();
+ // there should only be one value
+ source = valueMap.iterator().next();
+ if (AttributeImpl.class.equals(source.getClass())) {
+ return Converters.convert(((Attribute) source).getValue(), target);
}
}
}
- if (source instanceof Attribute) {
- return ((Attribute) source).getValue();
- }
return null;
}
};
}
- if (Attribute.class.isAssignableFrom(source)) {
+ // String to FeatureId comparison
+ if (FeatureId.class.isAssignableFrom(target) && String.class.isAssignableFrom(source)) {
return new Converter() {
- public Object convert(Object source, Class target) throws Exception {
- return ((Attribute) source).getValue();
+ public Object convert(Object source, Class target) {
+ if (source != null) {
+ return new FeatureIdImpl((String) source);
+ }
+ return null;
}
};
}
Added: trunk/modules/extension/app-schema/app-schema/src/test/java/org/geotools/util/ComplexAttributeConverterFactoryTest.java
===================================================================
--- trunk/modules/extension/app-schema/app-schema/src/test/java/org/geotools/util/ComplexAttributeConverterFactoryTest.java (rev 0)
+++ trunk/modules/extension/app-schema/app-schema/src/test/java/org/geotools/util/ComplexAttributeConverterFactoryTest.java 2012-01-25 05:49:34 UTC (rev 38523)
@@ -0,0 +1,104 @@
+/*
+ * GeoTools - The Open Source Java GIS Toolkit
+ * http://geotools.org
+ *
+ * (C) 2009-2011, Open Source Geospatial Foundation (OSGeo)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ */
+
+package org.geotools.util;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Set;
+
+import junit.framework.TestCase;
+
+import org.geotools.data.complex.ComplexFeatureConstants;
+import org.geotools.feature.AttributeImpl;
+import org.geotools.feature.ComplexAttributeImpl;
+import org.geotools.feature.type.AttributeDescriptorImpl;
+import org.geotools.gml3.GMLSchema;
+import org.geotools.xs.XSSchema;
+import org.opengis.feature.Attribute;
+import org.opengis.feature.ComplexAttribute;
+import org.opengis.feature.Property;
+import org.opengis.feature.type.AttributeDescriptor;
+import org.opengis.filter.identity.FeatureId;
+/**
+ * Tests for {@link ComplexAttributeConverterFactory}.
+ *
+ * @author Rini Angreani (CSIRO Earth Science and Resource Engineering)
+ *
+ *
+ *
+ *
+ * @source $URL: http://svn.osgeo.org/geotools/trunk/modules/extension/app-schema/app-schema/src/test/java/org/geotools/util/ComplexAttributeConverterFactoryTest.java $
+ */
+public class ComplexAttributeConverterFactoryTest extends TestCase {
+
+ /**
+ * Test extracting complex attribute leaf value should be successful.
+ */
+ public void testLeafComplexAttribute() {
+ Collection<Property> attributes = new ArrayList<Property>();
+ AttributeDescriptor descriptor = new AttributeDescriptorImpl(XSSchema.STRING_TYPE,
+ ComplexFeatureConstants.SIMPLE_CONTENT, 1, 1, true, (Object) null);
+ attributes.add(new AttributeImpl("rini", descriptor, null));
+ ComplexAttribute gmlName = new ComplexAttributeImpl(attributes, GMLSchema.CODETYPE_TYPE, null);
+ String nameString = Converters.convert(gmlName, String.class);
+ assertEquals("rini", nameString);
+ }
+
+ /**
+ * Test extracting complex attribute non-leaf value should fail.
+ */
+ public void testParentComplexAttribute() {
+ Collection<Property> attributes = new ArrayList<Property>();
+ AttributeDescriptor descriptor = new AttributeDescriptorImpl(XSSchema.STRING_TYPE,
+ ComplexFeatureConstants.SIMPLE_CONTENT, 1, 1, true, (Object) null);
+ attributes.add(new AttributeImpl("rini", descriptor, null));
+ ComplexAttribute gmlName = new ComplexAttributeImpl(attributes, GMLSchema.CODETYPE_TYPE, null);
+
+ Collection<Property> parentAttributes = new ArrayList<Property>();
+ parentAttributes.add(gmlName);
+ ComplexAttribute parentAtt = new ComplexAttributeImpl(parentAttributes, GMLSchema.ABSTRACTFEATURETYPE_TYPE, null);
+ String nameString = Converters.convert(parentAtt, String.class);
+
+ assertEquals(parentAtt.toString(), nameString);
+ assertNotSame("rini", nameString);
+ }
+
+ /**
+ * Test that normal Attribute shouldn't be affected by the converter.
+ */
+ public void testAttribute() {
+ AttributeDescriptor descriptor = new AttributeDescriptorImpl(XSSchema.STRING_TYPE,
+ ComplexFeatureConstants.SIMPLE_CONTENT, 1, 1, true, (Object) null);
+ Attribute att = new AttributeImpl("rini", descriptor, null);
+ Set<ConverterFactory> factories = Converters.getConverterFactories(att.getClass(), String.class);
+ for (ConverterFactory factory : factories) {
+ assertFalse(factory instanceof ComplexAttributeConverterFactory);
+ }
+ }
+
+ /**
+ * Test converting String to FeatureId successful. This is required by feature chaining.
+ * @throws Exception
+ */
+ public void testFeatureId() throws Exception {
+ FeatureId id = Converters.convert("blah", FeatureId.class);
+ assertNotNull(id);
+ assertEquals(id.getID(), "blah");
+ }
+
+}
|
|
From: <svn...@os...> - 2012-01-23 17:43:28
|
Author: aaime
Date: 2012-01-23 09:43:19 -0800 (Mon, 23 Jan 2012)
New Revision: 38522
Modified:
trunk/modules/library/jdbc/src/main/java/org/geotools/jdbc/JDBCDataStore.java
trunk/modules/library/jdbc/src/main/java/org/geotools/jdbc/JDBCFeatureSource.java
Log:
[GEOT-4025] Use fetch size for metadata gathering as well
Modified: trunk/modules/library/jdbc/src/main/java/org/geotools/jdbc/JDBCDataStore.java
===================================================================
--- trunk/modules/library/jdbc/src/main/java/org/geotools/jdbc/JDBCDataStore.java 2012-01-23 17:43:04 UTC (rev 38521)
+++ trunk/modules/library/jdbc/src/main/java/org/geotools/jdbc/JDBCDataStore.java 2012-01-23 17:43:19 UTC (rev 38522)
@@ -855,6 +855,9 @@
DatabaseMetaData metaData = cx.getMetaData();
ResultSet tables = metaData.getTables(null, databaseSchema, "%",
new String[] { "TABLE", "VIEW" });
+ if(fetchSize > 1) {
+ tables.setFetchSize(fetchSize);
+ }
try {
while (tables.next()) {
Modified: trunk/modules/library/jdbc/src/main/java/org/geotools/jdbc/JDBCFeatureSource.java
===================================================================
--- trunk/modules/library/jdbc/src/main/java/org/geotools/jdbc/JDBCFeatureSource.java 2012-01-23 17:43:04 UTC (rev 38521)
+++ trunk/modules/library/jdbc/src/main/java/org/geotools/jdbc/JDBCFeatureSource.java 2012-01-23 17:43:19 UTC (rev 38522)
@@ -705,6 +705,9 @@
* </UL>
*/
ResultSet columns = metaData.getColumns(null, databaseSchema, tableName, "%");
+ if(getDataStore().getFetchSize() > 0) {
+ columns.setFetchSize(getDataStore().getFetchSize());
+ }
try {
while (columns.next()) {
|
Author: aaime
Date: 2012-01-23 09:43:04 -0800 (Mon, 23 Jan 2012)
New Revision: 38521
Added:
trunk/modules/library/jdbc/src/main/java/org/geotools/jdbc/ConnectionLifecycleListener.java
trunk/modules/library/jdbc/src/main/java/org/geotools/jdbc/LifecycleConnection.java
trunk/modules/library/jdbc/src/main/java/org/geotools/jdbc/LifecycleConnectionUnWrapper.java
trunk/modules/library/jdbc/src/main/java/org/geotools/jdbc/SessionCommandsListener.java
trunk/modules/library/jdbc/src/test/java/org/geotools/jdbc/JDBCConnectionLifecycleTest.java
trunk/modules/library/jdbc/src/test/java/org/geotools/jdbc/SessionCommandListenerTest.java
trunk/modules/plugin/jdbc/jdbc-h2/src/test/java/org/geotools/data/h2/H2ConnectionLifecycleTest.java
trunk/modules/plugin/jdbc/jdbc-oracle/src/test/java/org/geotools/data/oracle/OracleConnectionLifecycleTest.java
trunk/modules/plugin/jdbc/jdbc-postgis/src/test/java/org/geotools/data/postgis/PostgisConnectionLifecycleTest.java
Modified:
trunk/modules/library/api/src/main/java/org/geotools/data/Parameter.java
trunk/modules/library/jdbc/src/main/java/org/geotools/jdbc/JDBCDataStore.java
trunk/modules/library/jdbc/src/main/java/org/geotools/jdbc/JDBCDataStoreFactory.java
trunk/modules/library/jdbc/src/main/java/org/geotools/jdbc/JDBCJNDIDataStoreFactory.java
trunk/modules/library/jdbc/src/main/resources/META-INF/services/org.geotools.data.jdbc.datasource.UnWrapper
trunk/modules/library/render/src/main/java/org/geotools/renderer/style/ExpressionExtractor.java
Log:
[GEOT-3994] Allow configurable database session startup and closeup sql commands
Modified: trunk/modules/library/api/src/main/java/org/geotools/data/Parameter.java
===================================================================
--- trunk/modules/library/api/src/main/java/org/geotools/data/Parameter.java 2012-01-23 17:34:51 UTC (rev 38520)
+++ trunk/modules/library/api/src/main/java/org/geotools/data/Parameter.java 2012-01-23 17:43:04 UTC (rev 38521)
@@ -89,6 +89,11 @@
* provides a hint for UI's to mask text fields, configuration systems to encrypt content, etc
*/
public static final String IS_PASSWORD = "isPassword";
+
+ /** Boolean indicating whether the parameter is meant to be a long text,
+ * provides a hint for UI's use long text fields, textareas and the like
+ */
+ public static final String IS_LARGE_TEXT = "isLargeText";
/**
* "length" Integer used to limit the length of strings or literal geometries.
Added: trunk/modules/library/jdbc/src/main/java/org/geotools/jdbc/ConnectionLifecycleListener.java
===================================================================
--- trunk/modules/library/jdbc/src/main/java/org/geotools/jdbc/ConnectionLifecycleListener.java (rev 0)
+++ trunk/modules/library/jdbc/src/main/java/org/geotools/jdbc/ConnectionLifecycleListener.java 2012-01-23 17:43:04 UTC (rev 38521)
@@ -0,0 +1,52 @@
+/*
+ * GeoTools - The Open Source Java GIS Toolkit
+ * http://geotools.org
+ *
+ * (C) 2002-2008, Open Source Geospatial Foundation (OSGeo)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ */
+package org.geotools.jdbc;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+
+/**
+ * This interface can be implemented to perform custom behavior on each connection as it gets
+ * borrowed from the connection pool and then released back to the pool.
+ *
+ * @author Andrea Aime - GeoSolutions
+ *
+ */
+public interface ConnectionLifecycleListener {
+
+ /**
+ * Called when the collection is being borrowed from the connection pool
+ */
+ public void onBorrow(JDBCDataStore store, Connection cx) throws SQLException;
+
+ /**
+ * Called when the collection is being released back to the connection pool
+ */
+ public void onRelease(JDBCDataStore store, Connection cx) throws SQLException;
+
+ /**
+ * Called when the connection comes to a commit
+ * @throws SQLException
+ */
+ public void onCommit(JDBCDataStore store, Connection cx) throws SQLException;
+
+ /**
+ * Called when the connection comes to a rollback
+ */
+ public void onRollback(JDBCDataStore store, Connection cx) throws SQLException;
+
+}
Modified: trunk/modules/library/jdbc/src/main/java/org/geotools/jdbc/JDBCDataStore.java
===================================================================
--- trunk/modules/library/jdbc/src/main/java/org/geotools/jdbc/JDBCDataStore.java 2012-01-23 17:34:51 UTC (rev 38520)
+++ trunk/modules/library/jdbc/src/main/java/org/geotools/jdbc/JDBCDataStore.java 2012-01-23 17:43:04 UTC (rev 38521)
@@ -42,6 +42,7 @@
import java.util.Set;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.CopyOnWriteArrayList;
import java.util.logging.Level;
import javax.sql.DataSource;
@@ -269,6 +270,11 @@
* Contains the SQL definition of the various virtual tables
*/
protected Map<String, VirtualTable> virtualTables = new ConcurrentHashMap<String, VirtualTable>();
+
+ /**
+ * The listeners that are allowed to handle the connection lifecycle
+ */
+ protected List<ConnectionLifecycleListener> connectionLifecycleListeners = new CopyOnWriteArrayList<ConnectionLifecycleListener>();
public JDBCFeatureSource getAbsoluteFeatureSource(String typeName) throws IOException {
ContentFeatureSource featureSource = getFeatureSource(typeName);
@@ -297,6 +303,14 @@
}
/**
+ * Returns a modifiable list of connection lifecycle listeners
+ * @return
+ */
+ public List<ConnectionLifecycleListener> getConnectionLifecycleListeners() {
+ return connectionLifecycleListeners;
+ }
+
+ /**
* Removes and returns the specified virtual table
* @param name
* @return
@@ -1630,6 +1644,12 @@
//call dialect callback to initialize the connection
dialect.initializeConnection( cx );
+
+ // if there is any lifecycle listener use it
+ if(connectionLifecycleListeners.size() > 0) {
+ List<ConnectionLifecycleListener> locals = new ArrayList<ConnectionLifecycleListener>(connectionLifecycleListeners);
+ cx = new LifecycleConnection(this, cx, locals);
+ }
return cx;
} catch (SQLException e) {
throw new RuntimeException("Unable to obtain connection: " + e.getMessage(), e);
Modified: trunk/modules/library/jdbc/src/main/java/org/geotools/jdbc/JDBCDataStoreFactory.java
===================================================================
--- trunk/modules/library/jdbc/src/main/java/org/geotools/jdbc/JDBCDataStoreFactory.java 2012-01-23 17:34:51 UTC (rev 38520)
+++ trunk/modules/library/jdbc/src/main/java/org/geotools/jdbc/JDBCDataStoreFactory.java 2012-01-23 17:43:04 UTC (rev 38521)
@@ -114,6 +114,17 @@
public static final Param EXPOSE_PK = new Param("Expose primary keys", Boolean.class, "Expose primary key columns as " +
"attributes of the feature type", false, false);
+ /** SQL executed when the session begins */
+ public static final Param SQL_ON_BORROW = new Param("Session startup SQL", String.class,
+ "SQL statement executed when the connection is grabbed from the pool", false, null,
+ Collections.singletonMap(Parameter.IS_LARGE_TEXT, Boolean.TRUE));
+
+ /** SQL executed when the session ends */
+ public static final Param SQL_ON_RELEASE = new Param("Session close-up SQL", String.class,
+ "SQL statement executed when the connection is released to the pool", false, null,
+ Collections.singletonMap(Parameter.IS_LARGE_TEXT, Boolean.TRUE));
+
+
@Override
public String getDisplayName() {
return getDescription();
@@ -208,6 +219,14 @@
dataStore.setExposePrimaryKeyColumns(exposePk);
}
+ // session startup and teardown
+ String sqlOnBorrow = (String) SQL_ON_BORROW.lookUp(params);
+ String sqlOnRelease = (String) SQL_ON_RELEASE.lookUp(params);
+ if(sqlOnBorrow != null || sqlOnRelease != null) {
+ SessionCommandsListener listener = new SessionCommandsListener(sqlOnBorrow, sqlOnRelease);
+ dataStore.getConnectionLifecycleListeners().add(listener);
+ }
+
// factories
dataStore.setFilterFactory(CommonFactoryFinder.getFilterFactory(null));
dataStore.setGeometryFactory(new GeometryFactory());
@@ -293,6 +312,8 @@
if(getValidationQuery() != null)
parameters.put(VALIDATECONN.key, VALIDATECONN);
parameters.put(PK_METADATA_TABLE.key, PK_METADATA_TABLE);
+ parameters.put(SQL_ON_BORROW.key, SQL_ON_BORROW);
+ parameters.put(SQL_ON_RELEASE.key, SQL_ON_RELEASE);
}
/**
Modified: trunk/modules/library/jdbc/src/main/java/org/geotools/jdbc/JDBCJNDIDataStoreFactory.java
===================================================================
--- trunk/modules/library/jdbc/src/main/java/org/geotools/jdbc/JDBCJNDIDataStoreFactory.java 2012-01-23 17:34:51 UTC (rev 38520)
+++ trunk/modules/library/jdbc/src/main/java/org/geotools/jdbc/JDBCJNDIDataStoreFactory.java 2012-01-23 17:43:04 UTC (rev 38521)
@@ -158,7 +158,8 @@
parameters.put(NAMESPACE.key, NAMESPACE);
parameters.put(EXPOSE_PK.key, EXPOSE_PK);
parameters.put(PK_METADATA_TABLE.key, PK_METADATA_TABLE);
-
+ parameters.put(SQL_ON_BORROW.key, SQL_ON_BORROW);
+ parameters.put(SQL_ON_RELEASE.key, SQL_ON_RELEASE);
}
@Override
Added: trunk/modules/library/jdbc/src/main/java/org/geotools/jdbc/LifecycleConnection.java
===================================================================
--- trunk/modules/library/jdbc/src/main/java/org/geotools/jdbc/LifecycleConnection.java (rev 0)
+++ trunk/modules/library/jdbc/src/main/java/org/geotools/jdbc/LifecycleConnection.java 2012-01-23 17:43:04 UTC (rev 38521)
@@ -0,0 +1,283 @@
+/*
+ * GeoTools - The Open Source Java GIS Toolkit
+ * http://geotools.org
+ *
+ * (C) 2008, Open Source Geospatial Foundation (OSGeo)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ */
+package org.geotools.jdbc;
+
+import java.sql.Array;
+import java.sql.Blob;
+import java.sql.CallableStatement;
+import java.sql.Clob;
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.NClob;
+import java.sql.PreparedStatement;
+import java.sql.SQLClientInfoException;
+import java.sql.SQLException;
+import java.sql.SQLWarning;
+import java.sql.SQLXML;
+import java.sql.Savepoint;
+import java.sql.Statement;
+import java.sql.Struct;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+/**
+ * Calls the {@link ConnectionLifecycleListener#onBorrow(Connection)} method on construction and
+ * makes sure the {@link ConnectionLifecycleListener#onRelease(Connection)} is called when this
+ * connection is closed (the assumption is that the wrapped connection is pooled, as such on "close"
+ * it will actually be returned to the pool)
+ *
+ * @author Andrea Aime - GeoSolutions
+ */
+class LifecycleConnection implements Connection {
+
+ Connection delegate;
+
+ JDBCDataStore store;
+
+ List<ConnectionLifecycleListener> listeners;
+
+ public LifecycleConnection(JDBCDataStore store, Connection delegate, List<ConnectionLifecycleListener> listeners)
+ throws SQLException {
+ this.delegate = delegate;
+ this.listeners = listeners;
+ this.store = store;
+
+ for (ConnectionLifecycleListener listener : listeners) {
+ listener.onBorrow(store, delegate);
+ }
+ }
+
+ public void commit() throws SQLException {
+ for (ConnectionLifecycleListener listener : listeners) {
+ listener.onCommit(store, delegate);
+ }
+ delegate.commit();
+ }
+
+ public void rollback() throws SQLException {
+ delegate.rollback();
+ for (ConnectionLifecycleListener listener : listeners) {
+ listener.onRollback(store, delegate);
+ }
+ }
+
+ public void close() throws SQLException {
+ try {
+ for (ConnectionLifecycleListener listener : listeners) {
+ listener.onRelease(store, delegate);
+ }
+ } finally {
+ delegate.close();
+ }
+ }
+
+ public Statement createStatement() throws SQLException {
+ return delegate.createStatement();
+ }
+
+ public PreparedStatement prepareStatement(String sql) throws SQLException {
+ return delegate.prepareStatement(sql);
+ }
+
+ public CallableStatement prepareCall(String sql) throws SQLException {
+ return delegate.prepareCall(sql);
+ }
+
+ public String nativeSQL(String sql) throws SQLException {
+ return delegate.nativeSQL(sql);
+ }
+
+ public void setAutoCommit(boolean autoCommit) throws SQLException {
+ delegate.setAutoCommit(autoCommit);
+ }
+
+ public boolean getAutoCommit() throws SQLException {
+ return delegate.getAutoCommit();
+ }
+
+ public boolean isClosed() throws SQLException {
+ return delegate.isClosed();
+ }
+
+ public DatabaseMetaData getMetaData() throws SQLException {
+ return delegate.getMetaData();
+ }
+
+ public void setReadOnly(boolean readOnly) throws SQLException {
+ delegate.setReadOnly(readOnly);
+ }
+
+ public boolean isReadOnly() throws SQLException {
+ return delegate.isReadOnly();
+ }
+
+ public void setCatalog(String catalog) throws SQLException {
+ delegate.setCatalog(catalog);
+ }
+
+ public String getCatalog() throws SQLException {
+ return delegate.getCatalog();
+ }
+
+ public void setTransactionIsolation(int level) throws SQLException {
+ delegate.setTransactionIsolation(level);
+ }
+
+ public int getTransactionIsolation() throws SQLException {
+ return delegate.getTransactionIsolation();
+ }
+
+ public SQLWarning getWarnings() throws SQLException {
+ return delegate.getWarnings();
+ }
+
+ public void clearWarnings() throws SQLException {
+ delegate.clearWarnings();
+ }
+
+ public Statement createStatement(int resultSetType, int resultSetConcurrency)
+ throws SQLException {
+ return delegate.createStatement(resultSetType, resultSetConcurrency);
+ }
+
+ public PreparedStatement prepareStatement(String sql, int resultSetType,
+ int resultSetConcurrency) throws SQLException {
+ return delegate.prepareStatement(sql, resultSetType, resultSetConcurrency);
+ }
+
+ public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency)
+ throws SQLException {
+ return delegate.prepareCall(sql, resultSetType, resultSetConcurrency);
+ }
+
+ public Map<String, Class<?>> getTypeMap() throws SQLException {
+ return delegate.getTypeMap();
+ }
+
+ public void setTypeMap(Map<String, Class<?>> map) throws SQLException {
+ delegate.setTypeMap(map);
+ }
+
+ public void setHoldability(int holdability) throws SQLException {
+ delegate.setHoldability(holdability);
+ }
+
+ public int getHoldability() throws SQLException {
+ return delegate.getHoldability();
+ }
+
+ public Savepoint setSavepoint() throws SQLException {
+ return delegate.setSavepoint();
+ }
+
+ public Savepoint setSavepoint(String name) throws SQLException {
+ return delegate.setSavepoint(name);
+ }
+
+ public void rollback(Savepoint savepoint) throws SQLException {
+ delegate.rollback(savepoint);
+ }
+
+ public void releaseSavepoint(Savepoint savepoint) throws SQLException {
+ delegate.releaseSavepoint(savepoint);
+ }
+
+ public Statement createStatement(int resultSetType, int resultSetConcurrency,
+ int resultSetHoldability) throws SQLException {
+ return delegate.createStatement(resultSetType, resultSetConcurrency, resultSetHoldability);
+ }
+
+ public PreparedStatement prepareStatement(String sql, int resultSetType,
+ int resultSetConcurrency, int resultSetHoldability) throws SQLException {
+ return delegate.prepareStatement(sql, resultSetType, resultSetConcurrency,
+ resultSetHoldability);
+ }
+
+ public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency,
+ int resultSetHoldability) throws SQLException {
+ return delegate.prepareCall(sql, resultSetType, resultSetConcurrency, resultSetHoldability);
+ }
+
+ public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys)
+ throws SQLException {
+ return delegate.prepareStatement(sql, autoGeneratedKeys);
+ }
+
+ public PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException {
+ return delegate.prepareStatement(sql, columnIndexes);
+ }
+
+ public PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException {
+ return delegate.prepareStatement(sql, columnNames);
+ }
+
+ public <T> T unwrap(Class<T> iface) throws SQLException {
+ return delegate.unwrap(iface);
+ }
+
+ public boolean isWrapperFor(Class<?> iface) throws SQLException {
+ return delegate.isWrapperFor(iface);
+ }
+
+ public Clob createClob() throws SQLException {
+ return delegate.createClob();
+ }
+
+ public Blob createBlob() throws SQLException {
+ return delegate.createBlob();
+ }
+
+ public NClob createNClob() throws SQLException {
+ return delegate.createNClob();
+ }
+
+ public SQLXML createSQLXML() throws SQLException {
+ return delegate.createSQLXML();
+ }
+
+ public boolean isValid(int timeout) throws SQLException {
+ return delegate.isValid(timeout);
+ }
+
+ public void setClientInfo(String name, String value) throws SQLClientInfoException {
+ delegate.setClientInfo(name, value);
+ }
+
+ public void setClientInfo(Properties properties) throws SQLClientInfoException {
+ delegate.setClientInfo(properties);
+ }
+
+ public String getClientInfo(String name) throws SQLException {
+ return delegate.getClientInfo(name);
+ }
+
+ public Properties getClientInfo() throws SQLException {
+ return delegate.getClientInfo();
+ }
+
+ public Array createArrayOf(String typeName, Object[] elements) throws SQLException {
+ return delegate.createArrayOf(typeName, elements);
+ }
+
+ public Struct createStruct(String typeName, Object[] attributes) throws SQLException {
+ return delegate.createStruct(typeName, attributes);
+ }
+
+
+
+}
Added: trunk/modules/library/jdbc/src/main/java/org/geotools/jdbc/LifecycleConnectionUnWrapper.java
===================================================================
--- trunk/modules/library/jdbc/src/main/java/org/geotools/jdbc/LifecycleConnectionUnWrapper.java (rev 0)
+++ trunk/modules/library/jdbc/src/main/java/org/geotools/jdbc/LifecycleConnectionUnWrapper.java 2012-01-23 17:43:04 UTC (rev 38521)
@@ -0,0 +1,31 @@
+package org.geotools.jdbc;
+
+import java.sql.Connection;
+import java.sql.Statement;
+
+import org.geotools.data.jdbc.datasource.UnWrapper;
+
+/**
+ * Un-wraps the {@link LifecycleConnection} instances
+ *
+ * @author Andrea Aime - GeoSolutions
+ */
+public class LifecycleConnectionUnWrapper implements UnWrapper {
+
+ public boolean canUnwrap(Connection conn) {
+ return conn instanceof LifecycleConnection;
+ }
+
+ public boolean canUnwrap(Statement st) {
+ return false;
+ }
+
+ public Connection unwrap(Connection conn) {
+ return ((LifecycleConnection) conn).delegate;
+ }
+
+ public Statement unwrap(Statement statement) {
+ throw new UnsupportedOperationException("This un-wrapper cannot operate on statements");
+ }
+
+}
\ No newline at end of file
Added: trunk/modules/library/jdbc/src/main/java/org/geotools/jdbc/SessionCommandsListener.java
===================================================================
--- trunk/modules/library/jdbc/src/main/java/org/geotools/jdbc/SessionCommandsListener.java (rev 0)
+++ trunk/modules/library/jdbc/src/main/java/org/geotools/jdbc/SessionCommandsListener.java 2012-01-23 17:43:04 UTC (rev 38521)
@@ -0,0 +1,223 @@
+/*
+ * GeoTools - The Open Source Java GIS Toolkit
+ * http://geotools.org
+ *
+ * (C) 2002-2008, Open Source Geospatial Foundation (OSGeo)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ */
+package org.geotools.jdbc;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.geotools.factory.CommonFactoryFinder;
+import org.geotools.filter.function.EnvFunction;
+import org.opengis.filter.FilterFactory2;
+import org.opengis.filter.expression.Expression;
+
+/**
+ * A {@link ConnectionLifecycleListener} that executes custom SQL commands on connection grab and
+ * release. The SQL commands can contain environment variable references, where the enviroment
+ * variable reference contains a name and an eventual default value.
+ *
+ * Parsing rules are:
+ * <ul>
+ * <li>whatever is between <code>${</code> and <code>}</code> is considered a enviroment variable
+ * reference in the form <code>${name,defaultvalue}, the default value being optional</li>
+ * <li><code>$</code> and <code>}</code> can be used stand alone only escaped with <code>\</code>
+ * (e.g. <code>\$</code> and <code>\}</code>)</li>
+ * <li><code>\</code> can be used stand alone only escaped with another <code>\</code></li> (e.g.
+ * <code>\\</code>)
+ * <li>a enviroment variable name cannot contain a comma, which is used as the separator between the
+ * enviroemnt variable name and its default value (first comma acts as a separator)</li>
+ * <li>the default value is always interpreted as a string and expanded as such in the sql commands</li>
+ * </ul>
+ *
+ * Examples of valid expressions:
+ * <ul>
+ * <li>"one two three \} \$ \\" (simple literal with special chars escaped)</li>
+ * <li>"My name is ${name}" (a simple enviroment variable reference without a default value)</li>
+ * <li>"My name is ${name,Joe}" (a simple enviroment variable reference with a default value)</li>
+ * </ul>
+ *
+ * Examples of non valid expressions:
+ * <ul>
+ * <li>"bla ${myAttName" (unclosed expression section)</li>
+ * <li>"bla } bla" (<code>}</code> is reserved, should have been escaped)</li>
+ *
+ *
+ * @author Andrea Aime - GeoSolutions
+ */
+public class SessionCommandsListener implements ConnectionLifecycleListener {
+
+ FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2(null);
+
+ private Expression sqlOnBorrow;
+
+ private Expression sqlOnRelease;
+
+ public SessionCommandsListener(String sqlOnBorrow, String sqlOnRelease) {
+ this.sqlOnBorrow = expandEviromentVariables(sqlOnBorrow);
+ this.sqlOnRelease = expandEviromentVariables(sqlOnRelease);
+ }
+
+ public void onBorrow(JDBCDataStore store, Connection cx) throws SQLException {
+ if (sqlOnBorrow != null && !"".equals(sqlOnBorrow)) {
+ String command = sqlOnBorrow.evaluate(null, String.class);
+ Statement st = null;
+ try {
+ st = cx.createStatement();
+ st.execute(command);
+ } finally {
+ store.closeSafe(st);
+ }
+
+ }
+ }
+
+ public void onRelease(JDBCDataStore store, Connection cx) throws SQLException {
+ if (sqlOnRelease != null) {
+ String command = sqlOnRelease.evaluate(null, String.class);
+ Statement st = null;
+ try {
+ st = cx.createStatement();
+ st.execute(command);
+ } finally {
+ store.closeSafe(st);
+ }
+
+ }
+ }
+
+ public void onCommit(JDBCDataStore store, Connection cx) {
+ // nothing to do
+ }
+
+ public void onRollback(JDBCDataStore store, Connection cx) {
+ // nothing to do
+ }
+
+ /**
+ * Parses the original sql command and returns a Expression that has all environment variable
+ * references expanded to a {@link EnvFunction} call.</p>
+ * This code is partially copied from gt-renderer ExpressionExtractor code, but simplified
+ * to only have enviroment variable references instead of CQL to avoid creating a dependendcy
+ * cascading issue (ExpressionExtractor would have to be moved to gt-cql and gt-jdbc made
+ * to depend on it.
+ *
+ * @param sql
+ * @return
+ */
+ Expression expandEviromentVariables(String sql) {
+ if(sql == null || "".equals(sql)) {
+ return null;
+ }
+
+ boolean inEnvVariable = false;
+ List<Expression> expressions = new ArrayList<Expression>();
+ StringBuilder sb = new StringBuilder();
+ for (int i = 0; i < sql.length(); i++) {
+ final char curr = sql.charAt(i);
+ final boolean last = (i == sql.length() - 1);
+ final char next = last ? 0 : sql.charAt(i + 1);
+
+ if (curr == '\\') {
+ if (last)
+ throw new IllegalArgumentException("Unescaped \\ at position " + (i + 1));
+
+ if (next == '\\')
+ sb.append('\\');
+ else if (next == '$')
+ sb.append('$');
+ else if (next == '}')
+ sb.append('}');
+ else
+ throw new IllegalArgumentException("Unescaped \\ at position " + (i + 1));
+
+ // skip the next character
+ i++;
+ } else if (curr == '$') {
+ if (last || next != '{')
+ throw new IllegalArgumentException("Unescaped $ at position " + (i + 1));
+ if (inEnvVariable)
+ throw new IllegalArgumentException(
+ "Already found a ${ sequence before the one at " + (i + 1));
+
+ // if we extracted a literal in between two expressions, add it to the result
+ if (sb.length() > 0) {
+ expressions.add(ff.literal(sb.toString()));
+ sb.setLength(0);
+ }
+
+ // mark the beginning and skip the next character
+ inEnvVariable = true;
+ i++;
+ } else if (curr == '}') {
+ if (!inEnvVariable)
+ throw new IllegalArgumentException(
+ "Already found a ${ sequence before the one at " + (i + 1));
+
+ if (sb.length() == 0)
+ throw new IllegalArgumentException(
+ "Invalid empty enviroment variable reference ${} at " + (i - 1));
+
+ String name = sb.toString();
+ String defaultValue = null;
+ int idx = name.indexOf(',');
+ if(idx >= 0) {
+ if(idx == 0) {
+ throw new IllegalArgumentException("There is no variable name before " +
+ "the comma, the valid format is '${name,defaultValue}'");
+ } else if(idx < name.length() - 1) {
+ defaultValue = name.substring(idx + 1);
+ name = name.substring(0, idx);
+ }
+ }
+ Expression env;
+ if(defaultValue != null) {
+ env = ff.function("env", ff.literal(name), ff.literal(defaultValue));
+ } else {
+ env = ff.function("env", ff.literal(name));
+ }
+ expressions.add(env);
+ sb.setLength(0);
+ inEnvVariable = false;
+ } else {
+ sb.append(curr);
+ }
+ }
+
+ // when done, if we are still in a environment variable reference it means it hasn't been
+ // closed
+ if (inEnvVariable) {
+ throw new IllegalArgumentException("Unclosed enviroment variable reference '" + sb
+ + "'");
+ } else if (sb.length() > 0) {
+ expressions.add(ff.literal(sb.toString()));
+ }
+
+ // now concatenate back all the references
+ if (expressions == null || expressions.size() == 0)
+ throw new IllegalArgumentException("The SQL command appears to be empty: " + sql);
+
+ Expression result = expressions.get(0);
+ for (int i = 1; i < expressions.size(); i++) {
+ result = ff.function("strConcat", result, expressions.get(i));
+ }
+
+ return result;
+ }
+
+}
Modified: trunk/modules/library/jdbc/src/main/resources/META-INF/services/org.geotools.data.jdbc.datasource.UnWrapper
===================================================================
--- trunk/modules/library/jdbc/src/main/resources/META-INF/services/org.geotools.data.jdbc.datasource.UnWrapper 2012-01-23 17:34:51 UTC (rev 38520)
+++ trunk/modules/library/jdbc/src/main/resources/META-INF/services/org.geotools.data.jdbc.datasource.UnWrapper 2012-01-23 17:43:04 UTC (rev 38521)
@@ -1 +1,2 @@
org.geotools.data.jdbc.datasource.DBCPUnWrapper
+org.geotools.jdbc.LifecycleConnectionUnWrapper
\ No newline at end of file
Added: trunk/modules/library/jdbc/src/test/java/org/geotools/jdbc/JDBCConnectionLifecycleTest.java
===================================================================
--- trunk/modules/library/jdbc/src/test/java/org/geotools/jdbc/JDBCConnectionLifecycleTest.java (rev 0)
+++ trunk/modules/library/jdbc/src/test/java/org/geotools/jdbc/JDBCConnectionLifecycleTest.java 2012-01-23 17:43:04 UTC (rev 38521)
@@ -0,0 +1,155 @@
+/*
+ * GeoTools - The Open Source Java GIS Toolkit
+ * http://geotools.org
+ *
+ * (C) 2002-2008, Open Source Geospatial Foundation (OSGeo)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ */
+package org.geotools.jdbc;
+
+import java.io.IOException;
+import java.sql.Connection;
+import java.sql.SQLException;
+
+import org.geotools.data.DefaultTransaction;
+import org.geotools.data.Query;
+import org.geotools.data.Transaction;
+import org.geotools.data.simple.SimpleFeatureIterator;
+import org.geotools.feature.DefaultFeatureCollection;
+import org.geotools.feature.simple.SimpleFeatureBuilder;
+
+import com.vividsolutions.jts.geom.Coordinate;
+import com.vividsolutions.jts.geom.GeometryFactory;
+
+public abstract class JDBCConnectionLifecycleTest extends JDBCTestSupport {
+
+ protected MockListener mockListener = new MockListener();
+
+
+
+ JDBCFeatureStore featureStore;
+
+ protected void connect() throws Exception {
+ super.connect();
+ featureStore = (JDBCFeatureStore) dataStore.getFeatureSource(tname("ft1"));
+ }
+
+ /**
+ * Check null encoding is working properly
+ *
+ * @throws IOException
+ */
+ public void testListenerCalled() throws IOException {
+ dataStore.getConnectionLifecycleListeners().add(mockListener);
+
+ // read some features, this will force unwrapping in Oracle
+ SimpleFeatureIterator fi = null;
+ try {
+ fi = featureStore.getFeatures().features();
+ while(fi.hasNext()) {
+ fi.next();
+ }
+ } finally {
+ if(fi != null) {
+ fi.close();
+ }
+ }
+ assertTrue(mockListener.onBorrowCalled);
+ assertTrue(mockListener.onReleaseCalled);
+ assertFalse(mockListener.onCommitCalled);
+ assertFalse(mockListener.onRollbackCalled);
+
+ // now write something within a transaction
+ Transaction t = new DefaultTransaction();
+ SimpleFeatureBuilder b = new SimpleFeatureBuilder(featureStore.getSchema());
+ DefaultFeatureCollection collection = new DefaultFeatureCollection(null,
+ featureStore.getSchema());
+ featureStore.setTransaction(t);
+ for (int i = 3; i < 6; i++) {
+ b.set(aname("intProperty"), new Integer(i));
+ b.set(aname("geometry"), new GeometryFactory().createPoint(new Coordinate(i, i)));
+ collection.add(b.buildFeature(null));
+ }
+ featureStore.addFeatures(collection);
+ t.commit();
+ assertTrue(mockListener.onBorrowCalled);
+ assertTrue(mockListener.onReleaseCalled);
+ assertTrue(mockListener.onCommitCalled);
+ assertFalse(mockListener.onRollbackCalled);
+
+ // and now do a rollback
+ t.rollback();
+ assertTrue(mockListener.onRollbackCalled);
+ }
+
+ public void testConnectionReleased() throws IOException {
+ dataStore.getConnectionLifecycleListeners().add(new ExceptionListener());
+
+ // get a count repeatedly, if we fail to release the connections this will eventually lock up
+ for (int i = 0; i < 100; i++) {
+ // we don't actually expect an exception to percolate up since it's happening
+ // on the closeSafe method, that swallows exceptions
+ featureStore.getCount(Query.ALL);
+ }
+ }
+
+ private static class MockListener implements ConnectionLifecycleListener {
+
+ boolean
+
+ boolean
+
+ boolean onCommitCalled;
+
+ boolean onRollbackCalled;
+
+ public void onBorrow(JDBCDataStore store, Connection cx) throws SQLException {
+
+ }
+
+ public void onRelease(JDBCDataStore store, Connection cx) throws SQLException {
+
+ }
+
+ public void onCommit(JDBCDataStore store, Connection cx) throws SQLException {
+
+
+ }
+
+ public void onRollback(JDBCDataStore store, Connection cx) throws SQLException {
+
+
+ }
+
+ }
+
+ private static class ExceptionListener implements ConnectionLifecycleListener {
+
+ public void onBorrow(JDBCDataStore store, Connection cx) throws SQLException {
+ // nothing to do
+ }
+
+ public void onRelease(JDBCDataStore store, Connection cx) throws SQLException {
+ throw new SQLException("Ha, are you relasing the connection anyways??");
+ }
+
+ public void onCommit(JDBCDataStore store, Connection cx) throws SQLException {
+ throw new SQLException("Nope, no writes sir");
+ }
+
+ public void onRollback(JDBCDataStore store, Connection cx) throws SQLException {
+ // nothing to do
+ }
+
+ }
+
+}
Added: trunk/modules/library/jdbc/src/test/java/org/geotools/jdbc/SessionCommandListenerTest.java
===================================================================
--- trunk/modules/library/jdbc/src/test/java/org/geotools/jdbc/SessionCommandListenerTest.java (rev 0)
+++ trunk/modules/library/jdbc/src/test/java/org/geotools/jdbc/SessionCommandListenerTest.java 2012-01-23 17:43:04 UTC (rev 38521)
@@ -0,0 +1,109 @@
+package org.geotools.jdbc;
+
+import static org.junit.Assert.*;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.geotools.filter.function.EnvFunction;
+import org.junit.Test;
+
+import com.mockrunner.mock.jdbc.MockConnection;
+import com.mockrunner.mock.jdbc.MockStatement;
+
+public class SessionCommandListenerTest {
+
+ static class RecordingConnection extends MockConnection {
+
+ List<String> commands = new ArrayList<String>();
+
+ public java.sql.Statement createStatement() throws java.sql.SQLException {
+ return new MockStatement(this) {
+ public boolean execute(String sql) throws java.sql.SQLException {
+ commands.add(sql);
+ return false;
+ }
+ };
+ }
+ };
+
+ RecordingConnection conn = new RecordingConnection();
+
+ JDBCDataStore store = new JDBCDataStore();
+
+ @Test
+ public void testPlain() throws Exception {
+ SessionCommandsListener listener = new SessionCommandsListener("A", "B");
+
+ // check borrow
+ listener.onBorrow(store, conn);
+ assertEquals(1, conn.commands.size());
+ assertEquals("A", conn.commands.get(0));
+ conn.commands.clear();
+
+ // check release
+ listener.onRelease(store, conn);
+ assertEquals(1, conn.commands.size());
+ assertEquals("B", conn.commands.get(0));
+ }
+
+ @Test
+ public void testOnlyBorrow() throws Exception {
+ SessionCommandsListener listener = new SessionCommandsListener("A", null);
+
+ // check borrow
+ listener.onBorrow(store, conn);
+ assertEquals(1, conn.commands.size());
+ assertEquals("A", conn.commands.get(0));
+ conn.commands.clear();
+
+ // check release
+ listener.onRelease(store, conn);
+ assertEquals(0, conn.commands.size());
+ }
+
+ @Test
+ public void testOnlyRelease() throws Exception {
+ SessionCommandsListener listener = new SessionCommandsListener(null, "B");
+
+ // check borrow
+ listener.onBorrow(store, conn);
+ assertEquals(0, conn.commands.size());
+
+ // check release
+ listener.onRelease(store, conn);
+ assertEquals(1, conn.commands.size());
+ assertEquals("B", conn.commands.get(0));
+ }
+
+ @Test
+ public void testExpandVariables() throws Exception {
+ SessionCommandsListener listener = new SessionCommandsListener("call startSession('${user}')",
+ "call endSession('${user,joe}')");
+
+ // check borrow
+ EnvFunction.setLocalValue("user", "abcde");
+ listener.onBorrow(store, conn);
+ assertEquals(1, conn.commands.size());
+ assertEquals("call startSession('abcde')", conn.commands.get(0));
+ conn.commands.clear();
+
+ // check release
+ EnvFunction.clearLocalValues();
+ listener.onRelease(store, conn);
+ assertEquals(1, conn.commands.size());
+ assertEquals("call endSession('joe')", conn.commands.get(0));
+ conn.commands.clear();
+ }
+
+ @Test
+ public void testInvalid() throws Exception {
+ try {
+ new SessionCommandsListener("startSession('${user')", null);
+ fail("This should have failed, the syntax is not valid");
+ } catch(IllegalArgumentException e) {
+ // fine
+ }
+ }
+
+}
Modified: trunk/modules/library/render/src/main/java/org/geotools/renderer/style/ExpressionExtractor.java
===================================================================
--- trunk/modules/library/render/src/main/java/org/geotools/renderer/style/ExpressionExtractor.java 2012-01-23 17:34:51 UTC (rev 38520)
+++ trunk/modules/library/render/src/main/java/org/geotools/renderer/style/ExpressionExtractor.java 2012-01-23 17:43:04 UTC (rev 38521)
@@ -153,6 +153,12 @@
return result;
}
+ /**
+ * Builds a CQL expression equivalent to the specified string, see class javadocs for
+ * rules on how to build the expression in string form
+ * @param expression
+ * @return
+ */
public static Expression extractCqlExpressions(String expression) {
return catenateExpressions(splitCqlExpressions(expression));
}
Added: trunk/modules/plugin/jdbc/jdbc-h2/src/test/java/org/geotools/data/h2/H2ConnectionLifecycleTest.java
===================================================================
--- trunk/modules/plugin/jdbc/jdbc-h2/src/test/java/org/geotools/data/h2/H2ConnectionLifecycleTest.java (rev 0)
+++ trunk/modules/plugin/jdbc/jdbc-h2/src/test/java/org/geotools/data/h2/H2ConnectionLifecycleTest.java 2012-01-23 17:43:04 UTC (rev 38521)
@@ -0,0 +1,84 @@
+/*
+ * GeoTools - The Open Source Java GIS Toolkit
+ * http://geotools.org
+ *
+ * (C) 2002-2008, Open Source Geospatial Foundation (OSGeo)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ */
+package org.geotools.data.h2;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import org.geotools.data.Query;
+import org.geotools.data.simple.SimpleFeatureSource;
+import org.geotools.jdbc.ConnectionLifecycleListener;
+import org.geotools.jdbc.JDBCConnectionLifecycleTest;
+import org.geotools.jdbc.JDBCDataStore;
+import org.geotools.jdbc.JDBCTestSetup;
+import org.geotools.jdbc.VirtualTable;
+
+
+public class H2ConnectionLifecycleTest extends JDBCConnectionLifecycleTest {
+
+ private class SetVariableListener implements ConnectionLifecycleListener {
+
+ double value;
+
+ public void onBorrow(JDBCDataStore store, Connection cx) throws SQLException {
+ Statement st = null;
+ try {
+ st = cx.createStatement();
+ st.execute("SET @MYVAR = " + value);
+ } finally {
+ store.closeSafe(st);
+ }
+ }
+
+ public void onRelease(JDBCDataStore store, Connection cx) throws SQLException {
+ // nothing to do
+ }
+
+ public void onCommit(JDBCDataStore store, Connection cx) throws SQLException {
+ // nothing to do
+ }
+
+ public void onRollback(JDBCDataStore store, Connection cx) throws SQLException {
+ // nothing to do
+ }
+
+ }
+
+ protected JDBCTestSetup createTestSetup() {
+ return new H2TestSetup();
+ }
+
+ public void testVariableListener() throws Exception {
+ // setup a virtual table using the user variable
+ VirtualTable vt = new VirtualTable("ft1var", "select * from \"geotools\".\"ft1\" where \"doubleProperty\" > @MYVAR");
+ dataStore.addVirtualTable(vt);
+
+ // setup a listener that uses said variable
+ SetVariableListener listener = new SetVariableListener();
+ dataStore.getConnectionLifecycleListeners().add(listener);
+
+ // set the value and test
+ listener.value = 1.0;
+ SimpleFeatureSource fs = dataStore.getFeatureSource("ft1var");
+ assertEquals(2, fs.getCount(Query.ALL));
+
+ listener.value = 10;
+ assertEquals(0, fs.getCount(Query.ALL));
+
+ }
+}
Added: trunk/modules/plugin/jdbc/jdbc-oracle/src/test/java/org/geotools/data/oracle/OracleConnectionLifecycleTest.java
===================================================================
--- trunk/modules/plugin/jdbc/jdbc-oracle/src/test/java/org/geotools/data/oracle/OracleConnectionLifecycleTest.java (rev 0)
+++ trunk/modules/plugin/jdbc/jdbc-oracle/src/test/java/org/geotools/data/oracle/OracleConnectionLifecycleTest.java 2012-01-23 17:43:04 UTC (rev 38521)
@@ -0,0 +1,29 @@
+/*
+ * GeoTools - The Open Source Java GIS Toolkit
+ * http://geotools.org
+ *
+ * (C) 2002-2008, Open Source Geospatial Foundation (OSGeo)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ */
+package org.geotools.data.oracle;
+
+import org.geotools.jdbc.JDBCConnectionLifecycleTest;
+import org.geotools.jdbc.JDBCTestSetup;
+
+public class OracleConnectionLifecycleTest extends JDBCConnectionLifecycleTest {
+
+ @Override
+ protected JDBCTestSetup createTestSetup() {
+ return new OracleTestSetup();
+ }
+
+}
Added: trunk/modules/plugin/jdbc/jdbc-postgis/src/test/java/org/geotools/data/postgis/PostgisConnectionLifecycleTest.java
===================================================================
--- trunk/modules/plugin/jdbc/jdbc-postgis/src/test/java/org/geotools/data/postgis/PostgisConnectionLifecycleTest.java (rev 0)
+++ trunk/modules/plugin/jdbc/jdbc-postgis/src/test/java/org/geotools/data/postgis/PostgisConnectionLifecycleTest.java 2012-01-23 17:43:04 UTC (rev 38521)
@@ -0,0 +1,28 @@
+/*
+ * GeoTools - The Open Source Java GIS Toolkit
+ * http://geotools.org
+ *
+ * (C) 2002-2008, Open Source Geospatial Foundation (OSGeo)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ */
+package org.geotools.data.postgis;
+
+import org.geotools.jdbc.JDBCConnectionLifecycleTest;
+import org.geotools.jdbc.JDBCTestSetup;
+
+
+public class PostgisConnectionLifecycleTest extends JDBCConnectionLifecycleTest {
+
+ protected JDBCTestSetup createTestSetup() {
+ return new PostGISTestSetup();
+ }
+}
|
|
From: <svn...@os...> - 2012-01-23 17:34:58
|
Author: aaime
Date: 2012-01-23 09:34:51 -0800 (Mon, 23 Jan 2012)
New Revision: 38520
Modified:
branches/2.7.x/modules/library/jdbc/src/main/java/org/geotools/jdbc/JDBCDataStore.java
branches/2.7.x/modules/library/jdbc/src/main/java/org/geotools/jdbc/JDBCFeatureSource.java
Log:
[GEOT-4025] Use fetch size for metadata gathering as well
Modified: branches/2.7.x/modules/library/jdbc/src/main/java/org/geotools/jdbc/JDBCDataStore.java
===================================================================
--- branches/2.7.x/modules/library/jdbc/src/main/java/org/geotools/jdbc/JDBCDataStore.java 2012-01-23 17:34:38 UTC (rev 38519)
+++ branches/2.7.x/modules/library/jdbc/src/main/java/org/geotools/jdbc/JDBCDataStore.java 2012-01-23 17:34:51 UTC (rev 38520)
@@ -841,6 +841,9 @@
DatabaseMetaData metaData = cx.getMetaData();
ResultSet tables = metaData.getTables(null, databaseSchema, "%",
new String[] { "TABLE", "VIEW" });
+ if(fetchSize > 1) {
+ tables.setFetchSize(fetchSize);
+ }
try {
while (tables.next()) {
Modified: branches/2.7.x/modules/library/jdbc/src/main/java/org/geotools/jdbc/JDBCFeatureSource.java
===================================================================
--- branches/2.7.x/modules/library/jdbc/src/main/java/org/geotools/jdbc/JDBCFeatureSource.java 2012-01-23 17:34:38 UTC (rev 38519)
+++ branches/2.7.x/modules/library/jdbc/src/main/java/org/geotools/jdbc/JDBCFeatureSource.java 2012-01-23 17:34:51 UTC (rev 38520)
@@ -640,6 +640,9 @@
* </UL>
*/
ResultSet columns = metaData.getColumns(null, databaseSchema, tableName, "%");
+ if(getDataStore().getFetchSize() > 0) {
+ columns.setFetchSize(getDataStore().getFetchSize());
+ }
try {
while (columns.next()) {
|
Author: aaime
Date: 2012-01-23 09:34:38 -0800 (Mon, 23 Jan 2012)
New Revision: 38519
Added:
branches/2.7.x/modules/library/jdbc/src/main/java/org/geotools/jdbc/ConnectionLifecycleListener.java
branches/2.7.x/modules/library/jdbc/src/main/java/org/geotools/jdbc/LifecycleConnection.java
branches/2.7.x/modules/library/jdbc/src/main/java/org/geotools/jdbc/LifecycleConnectionUnWrapper.java
branches/2.7.x/modules/library/jdbc/src/main/java/org/geotools/jdbc/SessionCommandsListener.java
branches/2.7.x/modules/library/jdbc/src/test/java/org/geotools/jdbc/JDBCConnectionLifecycleTest.java
branches/2.7.x/modules/library/jdbc/src/test/java/org/geotools/jdbc/SessionCommandListenerTest.java
branches/2.7.x/modules/plugin/jdbc/jdbc-h2/src/test/java/org/geotools/data/h2/H2ConnectionLifecycleTest.java
branches/2.7.x/modules/plugin/jdbc/jdbc-oracle/src/test/java/org/geotools/data/oracle/OracleConnectionLifecycleTest.java
branches/2.7.x/modules/plugin/jdbc/jdbc-postgis/src/test/java/org/geotools/data/postgis/PostgisConnectionLifecycleTest.java
Modified:
branches/2.7.x/modules/library/api/src/main/java/org/geotools/data/Parameter.java
branches/2.7.x/modules/library/jdbc/src/main/java/org/geotools/jdbc/JDBCDataStore.java
branches/2.7.x/modules/library/jdbc/src/main/java/org/geotools/jdbc/JDBCDataStoreFactory.java
branches/2.7.x/modules/library/jdbc/src/main/java/org/geotools/jdbc/JDBCJNDIDataStoreFactory.java
branches/2.7.x/modules/library/jdbc/src/main/resources/META-INF/services/org.geotools.data.jdbc.datasource.UnWrapper
branches/2.7.x/modules/library/render/src/main/java/org/geotools/renderer/style/ExpressionExtractor.java
Log:
[GEOT-3994] Allow configurable database session startup and closeup sql commands
Modified: branches/2.7.x/modules/library/api/src/main/java/org/geotools/data/Parameter.java
===================================================================
--- branches/2.7.x/modules/library/api/src/main/java/org/geotools/data/Parameter.java 2012-01-23 08:23:14 UTC (rev 38518)
+++ branches/2.7.x/modules/library/api/src/main/java/org/geotools/data/Parameter.java 2012-01-23 17:34:38 UTC (rev 38519)
@@ -88,6 +88,11 @@
* provides a hint for UI's to mask text fields, configuration systems to encrypt content, etc
*/
public static final String IS_PASSWORD = "isPassword";
+
+ /** Boolean indicating whether the parameter is meant to be a long text,
+ * provides a hint for UI's use long text fields, textareas and the like
+ */
+ public static final String IS_LARGE_TEXT = "isLargeText";
/**
* "length" Integer used to limit the length of strings or literal geometries.
Added: branches/2.7.x/modules/library/jdbc/src/main/java/org/geotools/jdbc/ConnectionLifecycleListener.java
===================================================================
--- branches/2.7.x/modules/library/jdbc/src/main/java/org/geotools/jdbc/ConnectionLifecycleListener.java (rev 0)
+++ branches/2.7.x/modules/library/jdbc/src/main/java/org/geotools/jdbc/ConnectionLifecycleListener.java 2012-01-23 17:34:38 UTC (rev 38519)
@@ -0,0 +1,52 @@
+/*
+ * GeoTools - The Open Source Java GIS Toolkit
+ * http://geotools.org
+ *
+ * (C) 2002-2008, Open Source Geospatial Foundation (OSGeo)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ */
+package org.geotools.jdbc;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+
+/**
+ * This interface can be implemented to perform custom behavior on each connection as it gets
+ * borrowed from the connection pool and then released back to the pool.
+ *
+ * @author Andrea Aime - GeoSolutions
+ *
+ */
+public interface ConnectionLifecycleListener {
+
+ /**
+ * Called when the collection is being borrowed from the connection pool
+ */
+ public void onBorrow(JDBCDataStore store, Connection cx) throws SQLException;
+
+ /**
+ * Called when the collection is being released back to the connection pool
+ */
+ public void onRelease(JDBCDataStore store, Connection cx) throws SQLException;
+
+ /**
+ * Called when the connection comes to a commit
+ * @throws SQLException
+ */
+ public void onCommit(JDBCDataStore store, Connection cx) throws SQLException;
+
+ /**
+ * Called when the connection comes to a rollback
+ */
+ public void onRollback(JDBCDataStore store, Connection cx) throws SQLException;
+
+}
Modified: branches/2.7.x/modules/library/jdbc/src/main/java/org/geotools/jdbc/JDBCDataStore.java
===================================================================
--- branches/2.7.x/modules/library/jdbc/src/main/java/org/geotools/jdbc/JDBCDataStore.java 2012-01-23 08:23:14 UTC (rev 38518)
+++ branches/2.7.x/modules/library/jdbc/src/main/java/org/geotools/jdbc/JDBCDataStore.java 2012-01-23 17:34:38 UTC (rev 38519)
@@ -42,6 +42,7 @@
import java.util.Set;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.CopyOnWriteArrayList;
import java.util.logging.Level;
import javax.sql.DataSource;
@@ -263,6 +264,11 @@
* Contains the SQL definition of the various virtual tables
*/
protected Map<String, VirtualTable> virtualTables = new ConcurrentHashMap<String, VirtualTable>();
+
+ /**
+ * The listeners that are allowed to handle the connection lifecycle
+ */
+ protected List<ConnectionLifecycleListener> connectionLifecycleListeners = new CopyOnWriteArrayList<ConnectionLifecycleListener>();
/**
* Adds a virtual table to the data store. If a virtual table with the same name was registered this
@@ -283,6 +289,14 @@
}
/**
+ * Returns a modifiable list of connection lifecycle listeners
+ * @return
+ */
+ public List<ConnectionLifecycleListener> getConnectionLifecycleListeners() {
+ return connectionLifecycleListeners;
+ }
+
+ /**
* Removes and returns the specified virtual table
* @param name
* @return
@@ -1616,6 +1630,12 @@
//call dialect callback to initialize the connection
dialect.initializeConnection( cx );
+
+ // if there is any lifecycle listener use it
+ if(connectionLifecycleListeners.size() > 0) {
+ List<ConnectionLifecycleListener> locals = new ArrayList<ConnectionLifecycleListener>(connectionLifecycleListeners);
+ cx = new LifecycleConnection(this, cx, locals);
+ }
return cx;
} catch (SQLException e) {
throw new RuntimeException("Unable to obtain connection: " + e.getMessage(), e);
Modified: branches/2.7.x/modules/library/jdbc/src/main/java/org/geotools/jdbc/JDBCDataStoreFactory.java
===================================================================
--- branches/2.7.x/modules/library/jdbc/src/main/java/org/geotools/jdbc/JDBCDataStoreFactory.java 2012-01-23 08:23:14 UTC (rev 38518)
+++ branches/2.7.x/modules/library/jdbc/src/main/java/org/geotools/jdbc/JDBCDataStoreFactory.java 2012-01-23 17:34:38 UTC (rev 38519)
@@ -113,6 +113,17 @@
public static final Param EXPOSE_PK = new Param("Expose primary keys", Boolean.class, "Expose primary key columns as " +
"attributes of the feature type", false, false);
+ /** SQL executed when the session begins */
+ public static final Param SQL_ON_BORROW = new Param("Session startup SQL", String.class,
+ "SQL statement executed when the connection is grabbed from the pool", false, null,
+ Collections.singletonMap(Parameter.IS_LARGE_TEXT, Boolean.TRUE));
+
+ /** SQL executed when the session ends */
+ public static final Param SQL_ON_RELEASE = new Param("Session close-up SQL", String.class,
+ "SQL statement executed when the connection is released to the pool", false, null,
+ Collections.singletonMap(Parameter.IS_LARGE_TEXT, Boolean.TRUE));
+
+
@Override
public String getDisplayName() {
return getDescription();
@@ -207,6 +218,14 @@
dataStore.setExposePrimaryKeyColumns(exposePk);
}
+ // session startup and teardown
+ String sqlOnBorrow = (String) SQL_ON_BORROW.lookUp(params);
+ String sqlOnRelease = (String) SQL_ON_RELEASE.lookUp(params);
+ if(sqlOnBorrow != null || sqlOnRelease != null) {
+ SessionCommandsListener listener = new SessionCommandsListener(sqlOnBorrow, sqlOnRelease);
+ dataStore.getConnectionLifecycleListeners().add(listener);
+ }
+
// factories
dataStore.setFilterFactory(CommonFactoryFinder.getFilterFactory(null));
dataStore.setGeometryFactory(new GeometryFactory());
@@ -292,6 +311,8 @@
if(getValidationQuery() != null)
parameters.put(VALIDATECONN.key, VALIDATECONN);
parameters.put(PK_METADATA_TABLE.key, PK_METADATA_TABLE);
+ parameters.put(SQL_ON_BORROW.key, SQL_ON_BORROW);
+ parameters.put(SQL_ON_RELEASE.key, SQL_ON_RELEASE);
}
/**
Modified: branches/2.7.x/modules/library/jdbc/src/main/java/org/geotools/jdbc/JDBCJNDIDataStoreFactory.java
===================================================================
--- branches/2.7.x/modules/library/jdbc/src/main/java/org/geotools/jdbc/JDBCJNDIDataStoreFactory.java 2012-01-23 08:23:14 UTC (rev 38518)
+++ branches/2.7.x/modules/library/jdbc/src/main/java/org/geotools/jdbc/JDBCJNDIDataStoreFactory.java 2012-01-23 17:34:38 UTC (rev 38519)
@@ -157,7 +157,8 @@
parameters.put(NAMESPACE.key, NAMESPACE);
parameters.put(EXPOSE_PK.key, EXPOSE_PK);
parameters.put(PK_METADATA_TABLE.key, PK_METADATA_TABLE);
-
+ parameters.put(SQL_ON_BORROW.key, SQL_ON_BORROW);
+ parameters.put(SQL_ON_RELEASE.key, SQL_ON_RELEASE);
}
@Override
Added: branches/2.7.x/modules/library/jdbc/src/main/java/org/geotools/jdbc/LifecycleConnection.java
===================================================================
--- branches/2.7.x/modules/library/jdbc/src/main/java/org/geotools/jdbc/LifecycleConnection.java (rev 0)
+++ branches/2.7.x/modules/library/jdbc/src/main/java/org/geotools/jdbc/LifecycleConnection.java 2012-01-23 17:34:38 UTC (rev 38519)
@@ -0,0 +1,228 @@
+/*
+ * GeoTools - The Open Source Java GIS Toolkit
+ * http://geotools.org
+ *
+ * (C) 2008, Open Source Geospatial Foundation (OSGeo)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ */
+package org.geotools.jdbc;
+
+import java.sql.Array;
+import java.sql.Blob;
+import java.sql.CallableStatement;
+import java.sql.Clob;
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.sql.SQLWarning;
+import java.sql.Savepoint;
+import java.sql.Statement;
+import java.sql.Struct;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+/**
+ * Calls the {@link ConnectionLifecycleListener#onBorrow(Connection)} method on construction and
+ * makes sure the {@link ConnectionLifecycleListener#onRelease(Connection)} is called when this
+ * connection is closed (the assumption is that the wrapped connection is pooled, as such on "close"
+ * it will actually be returned to the pool)
+ *
+ * @author Andrea Aime - GeoSolutions
+ */
+class LifecycleConnection implements Connection {
+
+ Connection delegate;
+
+ JDBCDataStore store;
+
+ List<ConnectionLifecycleListener> listeners;
+
+ public LifecycleConnection(JDBCDataStore store, Connection delegate, List<ConnectionLifecycleListener> listeners)
+ throws SQLException {
+ this.delegate = delegate;
+ this.listeners = listeners;
+ this.store = store;
+
+ for (ConnectionLifecycleListener listener : listeners) {
+ listener.onBorrow(store, delegate);
+ }
+ }
+
+ public void commit() throws SQLException {
+ for (ConnectionLifecycleListener listener : listeners) {
+ listener.onCommit(store, delegate);
+ }
+ delegate.commit();
+ }
+
+ public void rollback() throws SQLException {
+ delegate.rollback();
+ for (ConnectionLifecycleListener listener : listeners) {
+ listener.onRollback(store, delegate);
+ }
+ }
+
+ public void close() throws SQLException {
+ try {
+ for (ConnectionLifecycleListener listener : listeners) {
+ listener.onRelease(store, delegate);
+ }
+ } finally {
+ delegate.close();
+ }
+ }
+
+ public Statement createStatement() throws SQLException {
+ return delegate.createStatement();
+ }
+
+ public PreparedStatement prepareStatement(String sql) throws SQLException {
+ return delegate.prepareStatement(sql);
+ }
+
+ public CallableStatement prepareCall(String sql) throws SQLException {
+ return delegate.prepareCall(sql);
+ }
+
+ public String nativeSQL(String sql) throws SQLException {
+ return delegate.nativeSQL(sql);
+ }
+
+ public void setAutoCommit(boolean autoCommit) throws SQLException {
+ delegate.setAutoCommit(autoCommit);
+ }
+
+ public boolean getAutoCommit() throws SQLException {
+ return delegate.getAutoCommit();
+ }
+
+ public boolean isClosed() throws SQLException {
+ return delegate.isClosed();
+ }
+
+ public DatabaseMetaData getMetaData() throws SQLException {
+ return delegate.getMetaData();
+ }
+
+ public void setReadOnly(boolean readOnly) throws SQLException {
+ delegate.setReadOnly(readOnly);
+ }
+
+ public boolean isReadOnly() throws SQLException {
+ return delegate.isReadOnly();
+ }
+
+ public void setCatalog(String catalog) throws SQLException {
+ delegate.setCatalog(catalog);
+ }
+
+ public String getCatalog() throws SQLException {
+ return delegate.getCatalog();
+ }
+
+ public void setTransactionIsolation(int level) throws SQLException {
+ delegate.setTransactionIsolation(level);
+ }
+
+ public int getTransactionIsolation() throws SQLException {
+ return delegate.getTransactionIsolation();
+ }
+
+ public SQLWarning getWarnings() throws SQLException {
+ return delegate.getWarnings();
+ }
+
+ public void clearWarnings() throws SQLException {
+ delegate.clearWarnings();
+ }
+
+ public Statement createStatement(int resultSetType, int resultSetConcurrency)
+ throws SQLException {
+ return delegate.createStatement(resultSetType, resultSetConcurrency);
+ }
+
+ public PreparedStatement prepareStatement(String sql, int resultSetType,
+ int resultSetConcurrency) throws SQLException {
+ return delegate.prepareStatement(sql, resultSetType, resultSetConcurrency);
+ }
+
+ public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency)
+ throws SQLException {
+ return delegate.prepareCall(sql, resultSetType, resultSetConcurrency);
+ }
+
+ public Map<String, Class<?>> getTypeMap() throws SQLException {
+ return delegate.getTypeMap();
+ }
+
+ public void setTypeMap(Map<String, Class<?>> map) throws SQLException {
+ delegate.setTypeMap(map);
+ }
+
+ public void setHoldability(int holdability) throws SQLException {
+ delegate.setHoldability(holdability);
+ }
+
+ public int getHoldability() throws SQLException {
+ return delegate.getHoldability();
+ }
+
+ public Savepoint setSavepoint() throws SQLException {
+ return delegate.setSavepoint();
+ }
+
+ public Savepoint setSavepoint(String name) throws SQLException {
+ return delegate.setSavepoint(name);
+ }
+
+ public void rollback(Savepoint savepoint) throws SQLException {
+ delegate.rollback(savepoint);
+ }
+
+ public void releaseSavepoint(Savepoint savepoint) throws SQLException {
+ delegate.releaseSavepoint(savepoint);
+ }
+
+ public Statement createStatement(int resultSetType, int resultSetConcurrency,
+ int resultSetHoldability) throws SQLException {
+ return delegate.createStatement(resultSetType, resultSetConcurrency, resultSetHoldability);
+ }
+
+ public PreparedStatement prepareStatement(String sql, int resultSetType,
+ int resultSetConcurrency, int resultSetHoldability) throws SQLException {
+ return delegate.prepareStatement(sql, resultSetType, resultSetConcurrency,
+ resultSetHoldability);
+ }
+
+ public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency,
+ int resultSetHoldability) throws SQLException {
+ return delegate.prepareCall(sql, resultSetType, resultSetConcurrency, resultSetHoldability);
+ }
+
+ public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys)
+ throws SQLException {
+ return delegate.prepareStatement(sql, autoGeneratedKeys);
+ }
+
+ public PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException {
+ return delegate.prepareStatement(sql, columnIndexes);
+ }
+
+ public PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException {
+ return delegate.prepareStatement(sql, columnNames);
+ }
+
+
+
+}
Added: branches/2.7.x/modules/library/jdbc/src/main/java/org/geotools/jdbc/LifecycleConnectionUnWrapper.java
===================================================================
--- branches/2.7.x/modules/library/jdbc/src/main/java/org/geotools/jdbc/LifecycleConnectionUnWrapper.java (rev 0)
+++ branches/2.7.x/modules/library/jdbc/src/main/java/org/geotools/jdbc/LifecycleConnectionUnWrapper.java 2012-01-23 17:34:38 UTC (rev 38519)
@@ -0,0 +1,31 @@
+package org.geotools.jdbc;
+
+import java.sql.Connection;
+import java.sql.Statement;
+
+import org.geotools.data.jdbc.datasource.UnWrapper;
+
+/**
+ * Un-wraps the {@link LifecycleConnection} instances
+ *
+ * @author Andrea Aime - GeoSolutions
+ */
+public class LifecycleConnectionUnWrapper implements UnWrapper {
+
+ public boolean canUnwrap(Connection conn) {
+ return conn instanceof LifecycleConnection;
+ }
+
+ public boolean canUnwrap(Statement st) {
+ return false;
+ }
+
+ public Connection unwrap(Connection conn) {
+ return ((LifecycleConnection) conn).delegate;
+ }
+
+ public Statement unwrap(Statement statement) {
+ throw new UnsupportedOperationException("This un-wrapper cannot operate on statements");
+ }
+
+}
\ No newline at end of file
Added: branches/2.7.x/modules/library/jdbc/src/main/java/org/geotools/jdbc/SessionCommandsListener.java
===================================================================
--- branches/2.7.x/modules/library/jdbc/src/main/java/org/geotools/jdbc/SessionCommandsListener.java (rev 0)
+++ branches/2.7.x/modules/library/jdbc/src/main/java/org/geotools/jdbc/SessionCommandsListener.java 2012-01-23 17:34:38 UTC (rev 38519)
@@ -0,0 +1,223 @@
+/*
+ * GeoTools - The Open Source Java GIS Toolkit
+ * http://geotools.org
+ *
+ * (C) 2002-2008, Open Source Geospatial Foundation (OSGeo)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ */
+package org.geotools.jdbc;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.geotools.factory.CommonFactoryFinder;
+import org.geotools.filter.function.EnvFunction;
+import org.opengis.filter.FilterFactory2;
+import org.opengis.filter.expression.Expression;
+
+/**
+ * A {@link ConnectionLifecycleListener} that executes custom SQL commands on connection grab and
+ * release. The SQL commands can contain environment variable references, where the enviroment
+ * variable reference contains a name and an eventual default value.
+ *
+ * Parsing rules are:
+ * <ul>
+ * <li>whatever is between <code>${</code> and <code>}</code> is considered a enviroment variable
+ * reference in the form <code>${name,defaultvalue}, the default value being optional</li>
+ * <li><code>$</code> and <code>}</code> can be used stand alone only escaped with <code>\</code>
+ * (e.g. <code>\$</code> and <code>\}</code>)</li>
+ * <li><code>\</code> can be used stand alone only escaped with another <code>\</code></li> (e.g.
+ * <code>\\</code>)
+ * <li>a enviroment variable name cannot contain a comma, which is used as the separator between the
+ * enviroemnt variable name and its default value (first comma acts as a separator)</li>
+ * <li>the default value is always interpreted as a string and expanded as such in the sql commands</li>
+ * </ul>
+ *
+ * Examples of valid expressions:
+ * <ul>
+ * <li>"one two three \} \$ \\" (simple literal with special chars escaped)</li>
+ * <li>"My name is ${name}" (a simple enviroment variable reference without a default value)</li>
+ * <li>"My name is ${name,Joe}" (a simple enviroment variable reference with a default value)</li>
+ * </ul>
+ *
+ * Examples of non valid expressions:
+ * <ul>
+ * <li>"bla ${myAttName" (unclosed expression section)</li>
+ * <li>"bla } bla" (<code>}</code> is reserved, should have been escaped)</li>
+ *
+ *
+ * @author Andrea Aime - GeoSolutions
+ */
+public class SessionCommandsListener implements ConnectionLifecycleListener {
+
+ FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2(null);
+
+ private Expression sqlOnBorrow;
+
+ private Expression sqlOnRelease;
+
+ public SessionCommandsListener(String sqlOnBorrow, String sqlOnRelease) {
+ this.sqlOnBorrow = expandEviromentVariables(sqlOnBorrow);
+ this.sqlOnRelease = expandEviromentVariables(sqlOnRelease);
+ }
+
+ public void onBorrow(JDBCDataStore store, Connection cx) throws SQLException {
+ if (sqlOnBorrow != null && !"".equals(sqlOnBorrow)) {
+ String command = sqlOnBorrow.evaluate(null, String.class);
+ Statement st = null;
+ try {
+ st = cx.createStatement();
+ st.execute(command);
+ } finally {
+ store.closeSafe(st);
+ }
+
+ }
+ }
+
+ public void onRelease(JDBCDataStore store, Connection cx) throws SQLException {
+ if (sqlOnRelease != null) {
+ String command = sqlOnRelease.evaluate(null, String.class);
+ Statement st = null;
+ try {
+ st = cx.createStatement();
+ st.execute(command);
+ } finally {
+ store.closeSafe(st);
+ }
+
+ }
+ }
+
+ public void onCommit(JDBCDataStore store, Connection cx) {
+ // nothing to do
+ }
+
+ public void onRollback(JDBCDataStore store, Connection cx) {
+ // nothing to do
+ }
+
+ /**
+ * Parses the original sql command and returns a Expression that has all environment variable
+ * references expanded to a {@link EnvFunction} call.</p>
+ * This code is partially copied from gt-renderer ExpressionExtractor code, but simplified
+ * to only have enviroment variable references instead of CQL to avoid creating a dependendcy
+ * cascading issue (ExpressionExtractor would have to be moved to gt-cql and gt-jdbc made
+ * to depend on it.
+ *
+ * @param sql
+ * @return
+ */
+ Expression expandEviromentVariables(String sql) {
+ if(sql == null || "".equals(sql)) {
+ return null;
+ }
+
+ boolean inEnvVariable = false;
+ List<Expression> expressions = new ArrayList<Expression>();
+ StringBuilder sb = new StringBuilder();
+ for (int i = 0; i < sql.length(); i++) {
+ final char curr = sql.charAt(i);
+ final boolean last = (i == sql.length() - 1);
+ final char next = last ? 0 : sql.charAt(i + 1);
+
+ if (curr == '\\') {
+ if (last)
+ throw new IllegalArgumentException("Unescaped \\ at position " + (i + 1));
+
+ if (next == '\\')
+ sb.append('\\');
+ else if (next == '$')
+ sb.append('$');
+ else if (next == '}')
+ sb.append('}');
+ else
+ throw new IllegalArgumentException("Unescaped \\ at position " + (i + 1));
+
+ // skip the next character
+ i++;
+ } else if (curr == '$') {
+ if (last || next != '{')
+ throw new IllegalArgumentException("Unescaped $ at position " + (i + 1));
+ if (inEnvVariable)
+ throw new IllegalArgumentException(
+ "Already found a ${ sequence before the one at " + (i + 1));
+
+ // if we extracted a literal in between two expressions, add it to the result
+ if (sb.length() > 0) {
+ expressions.add(ff.literal(sb.toString()));
+ sb.setLength(0);
+ }
+
+ // mark the beginning and skip the next character
+ inEnvVariable = true;
+ i++;
+ } else if (curr == '}') {
+ if (!inEnvVariable)
+ throw new IllegalArgumentException(
+ "Already found a ${ sequence before the one at " + (i + 1));
+
+ if (sb.length() == 0)
+ throw new IllegalArgumentException(
+ "Invalid empty enviroment variable reference ${} at " + (i - 1));
+
+ String name = sb.toString();
+ String defaultValue = null;
+ int idx = name.indexOf(',');
+ if(idx >= 0) {
+ if(idx == 0) {
+ throw new IllegalArgumentException("There is no variable name before " +
+ "the comma, the valid format is '${name,defaultValue}'");
+ } else if(idx < name.length() - 1) {
+ defaultValue = name.substring(idx + 1);
+ name = name.substring(0, idx);
+ }
+ }
+ Expression env;
+ if(defaultValue != null) {
+ env = ff.function("env", ff.literal(name), ff.literal(defaultValue));
+ } else {
+ env = ff.function("env", ff.literal(name));
+ }
+ expressions.add(env);
+ sb.setLength(0);
+ inEnvVariable = false;
+ } else {
+ sb.append(curr);
+ }
+ }
+
+ // when done, if we are still in a environment variable reference it means it hasn't been
+ // closed
+ if (inEnvVariable) {
+ throw new IllegalArgumentException("Unclosed enviroment variable reference '" + sb
+ + "'");
+ } else if (sb.length() > 0) {
+ expressions.add(ff.literal(sb.toString()));
+ }
+
+ // now concatenate back all the references
+ if (expressions == null || expressions.size() == 0)
+ throw new IllegalArgumentException("The SQL command appears to be empty: " + sql);
+
+ Expression result = expressions.get(0);
+ for (int i = 1; i < expressions.size(); i++) {
+ result = ff.function("strConcat", result, expressions.get(i));
+ }
+
+ return result;
+ }
+
+}
Modified: branches/2.7.x/modules/library/jdbc/src/main/resources/META-INF/services/org.geotools.data.jdbc.datasource.UnWrapper
===================================================================
--- branches/2.7.x/modules/library/jdbc/src/main/resources/META-INF/services/org.geotools.data.jdbc.datasource.UnWrapper 2012-01-23 08:23:14 UTC (rev 38518)
+++ branches/2.7.x/modules/library/jdbc/src/main/resources/META-INF/services/org.geotools.data.jdbc.datasource.UnWrapper 2012-01-23 17:34:38 UTC (rev 38519)
@@ -1 +1,2 @@
org.geotools.data.jdbc.datasource.DBCPUnWrapper
+org.geotools.jdbc.LifecycleConnectionUnWrapper
\ No newline at end of file
Added: branches/2.7.x/modules/library/jdbc/src/test/java/org/geotools/jdbc/JDBCConnectionLifecycleTest.java
===================================================================
--- branches/2.7.x/modules/library/jdbc/src/test/java/org/geotools/jdbc/JDBCConnectionLifecycleTest.java (rev 0)
+++ branches/2.7.x/modules/library/jdbc/src/test/java/org/geotools/jdbc/JDBCConnectionLifecycleTest.java 2012-01-23 17:34:38 UTC (rev 38519)
@@ -0,0 +1,155 @@
+/*
+ * GeoTools - The Open Source Java GIS Toolkit
+ * http://geotools.org
+ *
+ * (C) 2002-2008, Open Source Geospatial Foundation (OSGeo)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ */
+package org.geotools.jdbc;
+
+import java.io.IOException;
+import java.sql.Connection;
+import java.sql.SQLException;
+
+import org.geotools.data.DefaultTransaction;
+import org.geotools.data.Query;
+import org.geotools.data.Transaction;
+import org.geotools.data.simple.SimpleFeatureIterator;
+import org.geotools.feature.DefaultFeatureCollection;
+import org.geotools.feature.simple.SimpleFeatureBuilder;
+
+import com.vividsolutions.jts.geom.Coordinate;
+import com.vividsolutions.jts.geom.GeometryFactory;
+
+public abstract class JDBCConnectionLifecycleTest extends JDBCTestSupport {
+
+ protected MockListener mockListener = new MockListener();
+
+
+
+ JDBCFeatureStore featureStore;
+
+ protected void connect() throws Exception {
+ super.connect();
+ featureStore = (JDBCFeatureStore) dataStore.getFeatureSource(tname("ft1"));
+ }
+
+ /**
+ * Check null encoding is working properly
+ *
+ * @throws IOException
+ */
+ public void testListenerCalled() throws IOException {
+ dataStore.getConnectionLifecycleListeners().add(mockListener);
+
+ // read some features, this will force unwrapping in Oracle
+ SimpleFeatureIterator fi = null;
+ try {
+ fi = featureStore.getFeatures().features();
+ while(fi.hasNext()) {
+ fi.next();
+ }
+ } finally {
+ if(fi != null) {
+ fi.close();
+ }
+ }
+ assertTrue(mockListener.onBorrowCalled);
+ assertTrue(mockListener.onReleaseCalled);
+ assertFalse(mockListener.onCommitCalled);
+ assertFalse(mockListener.onRollbackCalled);
+
+ // now write something within a transaction
+ Transaction t = new DefaultTransaction();
+ SimpleFeatureBuilder b = new SimpleFeatureBuilder(featureStore.getSchema());
+ DefaultFeatureCollection collection = new DefaultFeatureCollection(null,
+ featureStore.getSchema());
+ featureStore.setTransaction(t);
+ for (int i = 3; i < 6; i++) {
+ b.set(aname("intProperty"), new Integer(i));
+ b.set(aname("geometry"), new GeometryFactory().createPoint(new Coordinate(i, i)));
+ collection.add(b.buildFeature(null));
+ }
+ featureStore.addFeatures(collection);
+ t.commit();
+ assertTrue(mockListener.onBorrowCalled);
+ assertTrue(mockListener.onReleaseCalled);
+ assertTrue(mockListener.onCommitCalled);
+ assertFalse(mockListener.onRollbackCalled);
+
+ // and now do a rollback
+ t.rollback();
+ assertTrue(mockListener.onRollbackCalled);
+ }
+
+ public void testConnectionReleased() throws IOException {
+ dataStore.getConnectionLifecycleListeners().add(new ExceptionListener());
+
+ // get a count repeatedly, if we fail to release the connections this will eventually lock up
+ for (int i = 0; i < 100; i++) {
+ // we don't actually expect an exception to percolate up since it's happening
+ // on the closeSafe method, that swallows exceptions
+ featureStore.getCount(Query.ALL);
+ }
+ }
+
+ private static class MockListener implements ConnectionLifecycleListener {
+
+ boolean
+
+ boolean
+
+ boolean onCommitCalled;
+
+ boolean onRollbackCalled;
+
+ public void onBorrow(JDBCDataStore store, Connection cx) throws SQLException {
+
+ }
+
+ public void onRelease(JDBCDataStore store, Connection cx) throws SQLException {
+
+ }
+
+ public void onCommit(JDBCDataStore store, Connection cx) throws SQLException {
+
+
+ }
+
+ public void onRollback(JDBCDataStore store, Connection cx) throws SQLException {
+
+
+ }
+
+ }
+
+ private static class ExceptionListener implements ConnectionLifecycleListener {
+
+ public void onBorrow(JDBCDataStore store, Connection cx) throws SQLException {
+ // nothing to do
+ }
+
+ public void onRelease(JDBCDataStore store, Connection cx) throws SQLException {
+ throw new SQLException("Ha, are you relasing the connection anyways??");
+ }
+
+ public void onCommit(JDBCDataStore store, Connection cx) throws SQLException {
+ throw new SQLException("Nope, no writes sir");
+ }
+
+ public void onRollback(JDBCDataStore store, Connection cx) throws SQLException {
+ // nothing to do
+ }
+
+ }
+
+}
Added: branches/2.7.x/modules/library/jdbc/src/test/java/org/geotools/jdbc/SessionCommandListenerTest.java
===================================================================
--- branches/2.7.x/modules/library/jdbc/src/test/java/org/geotools/jdbc/SessionCommandListenerTest.java (rev 0)
+++ branches/2.7.x/modules/library/jdbc/src/test/java/org/geotools/jdbc/SessionCommandListenerTest.java 2012-01-23 17:34:38 UTC (rev 38519)
@@ -0,0 +1,109 @@
+package org.geotools.jdbc;
+
+import static org.junit.Assert.*;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.geotools.filter.function.EnvFunction;
+import org.junit.Test;
+
+import com.mockrunner.mock.jdbc.MockConnection;
+import com.mockrunner.mock.jdbc.MockStatement;
+
+public class SessionCommandListenerTest {
+
+ static class RecordingConnection extends MockConnection {
+
+ List<String> commands = new ArrayList<String>();
+
+ public java.sql.Statement createStatement() throws java.sql.SQLException {
+ return new MockStatement(this) {
+ public boolean execute(String sql) throws java.sql.SQLException {
+ commands.add(sql);
+ return false;
+ }
+ };
+ }
+ };
+
+ RecordingConnection conn = new RecordingConnection();
+
+ JDBCDataStore store = new JDBCDataStore();
+
+ @Test
+ public void testPlain() throws Exception {
+ SessionCommandsListener listener = new SessionCommandsListener("A", "B");
+
+ // check borrow
+ listener.onBorrow(store, conn);
+ assertEquals(1, conn.commands.size());
+ assertEquals("A", conn.commands.get(0));
+ conn.commands.clear();
+
+ // check release
+ listener.onRelease(store, conn);
+ assertEquals(1, conn.commands.size());
+ assertEquals("B", conn.commands.get(0));
+ }
+
+ @Test
+ public void testOnlyBorrow() throws Exception {
+ SessionCommandsListener listener = new SessionCommandsListener("A", null);
+
+ // check borrow
+ listener.onBorrow(store, conn);
+ assertEquals(1, conn.commands.size());
+ assertEquals("A", conn.commands.get(0));
+ conn.commands.clear();
+
+ // check release
+ listener.onRelease(store, conn);
+ assertEquals(0, conn.commands.size());
+ }
+
+ @Test
+ public void testOnlyRelease() throws Exception {
+ SessionCommandsListener listener = new SessionCommandsListener(null, "B");
+
+ // check borrow
+ listener.onBorrow(store, conn);
+ assertEquals(0, conn.commands.size());
+
+ // check release
+ listener.onRelease(store, conn);
+ assertEquals(1, conn.commands.size());
+ assertEquals("B", conn.commands.get(0));
+ }
+
+ @Test
+ public void testExpandVariables() throws Exception {
+ SessionCommandsListener listener = new SessionCommandsListener("call startSession('${user}')",
+ "call endSession('${user,joe}')");
+
+ // check borrow
+ EnvFunction.setLocalValue("user", "abcde");
+ listener.onBorrow(store, conn);
+ assertEquals(1, conn.commands.size());
+ assertEquals("call startSession('abcde')", conn.commands.get(0));
+ conn.commands.clear();
+
+ // check release
+ EnvFunction.clearLocalValues();
+ listener.onRelease(store, conn);
+ assertEquals(1, conn.commands.size());
+ assertEquals("call endSession('joe')", conn.commands.get(0));
+ conn.commands.clear();
+ }
+
+ @Test
+ public void testInvalid() throws Exception {
+ try {
+ new SessionCommandsListener("startSession('${user')", null);
+ fail("This should have failed, the syntax is not valid");
+ } catch(IllegalArgumentException e) {
+ // fine
+ }
+ }
+
+}
Modified: branches/2.7.x/modules/library/render/src/main/java/org/geotools/renderer/style/ExpressionExtractor.java
===================================================================
--- branches/2.7.x/modules/library/render/src/main/java/org/geotools/renderer/style/ExpressionExtractor.java 2012-01-23 08:23:14 UTC (rev 38518)
+++ branches/2.7.x/modules/library/render/src/main/java/org/geotools/renderer/style/ExpressionExtractor.java 2012-01-23 17:34:38 UTC (rev 38519)
@@ -152,6 +152,12 @@
return result;
}
+ /**
+ * Builds a CQL expression equivalent to the specified string, see class javadocs for
+ * rules on how to build the expression in string form
+ * @param expression
+ * @return
+ */
public static Expression extractCqlExpressions(String expression) {
return catenateExpressions(splitCqlExpressions(expression));
}
Added: branches/2.7.x/modules/plugin/jdbc/jdbc-h2/src/test/java/org/geotools/data/h2/H2ConnectionLifecycleTest.java
===================================================================
--- branches/2.7.x/modules/plugin/jdbc/jdbc-h2/src/test/java/org/geotools/data/h2/H2ConnectionLifecycleTest.java (rev 0)
+++ branches/2.7.x/modules/plugin/jdbc/jdbc-h2/src/test/java/org/geotools/data/h2/H2ConnectionLifecycleTest.java 2012-01-23 17:34:38 UTC (rev 38519)
@@ -0,0 +1,84 @@
+/*
+ * GeoTools - The Open Source Java GIS Toolkit
+ * http://geotools.org
+ *
+ * (C) 2002-2008, Open Source Geospatial Foundation (OSGeo)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ */
+package org.geotools.data.h2;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import org.geotools.data.Query;
+import org.geotools.data.simple.SimpleFeatureSource;
+import org.geotools.jdbc.ConnectionLifecycleListener;
+import org.geotools.jdbc.JDBCConnectionLifecycleTest;
+import org.geotools.jdbc.JDBCDataStore;
+import org.geotools.jdbc.JDBCTestSetup;
+import org.geotools.jdbc.VirtualTable;
+
+
+public class H2ConnectionLifecycleTest extends JDBCConnectionLifecycleTest {
+
+ private class SetVariableListener implements ConnectionLifecycleListener {
+
+ double value;
+
+ public void onBorrow(JDBCDataStore store, Connection cx) throws SQLException {
+ Statement st = null;
+ try {
+ st = cx.createStatement();
+ st.execute("SET @MYVAR = " + value);
+ } finally {
+ store.closeSafe(st);
+ }
+ }
+
+ public void onRelease(JDBCDataStore store, Connection cx) throws SQLException {
+ // nothing to do
+ }
+
+ public void onCommit(JDBCDataStore store, Connection cx) throws SQLException {
+ // nothing to do
+ }
+
+ public void onRollback(JDBCDataStore store, Connection cx) throws SQLException {
+ // nothing to do
+ }
+
+ }
+
+ protected JDBCTestSetup createTestSetup() {
+ return new H2TestSetup();
+ }
+
+ public void testVariableListener() throws Exception {
+ // setup a virtual table using the user variable
+ VirtualTable vt = new VirtualTable("ft1var", "select * from \"geotools\".\"ft1\" where \"doubleProperty\" > @MYVAR");
+ dataStore.addVirtualTable(vt);
+
+ // setup a listener that uses said variable
+ SetVariableListener listener = new SetVariableListener();
+ dataStore.getConnectionLifecycleListeners().add(listener);
+
+ // set the value and test
+ listener.value = 1.0;
+ SimpleFeatureSource fs = dataStore.getFeatureSource("ft1var");
+ assertEquals(2, fs.getCount(Query.ALL));
+
+ listener.value = 10;
+ assertEquals(0, fs.getCount(Query.ALL));
+
+ }
+}
Added: branches/2.7.x/modules/plugin/jdbc/jdbc-oracle/src/test/java/org/geotools/data/oracle/OracleConnectionLifecycleTest.java
===================================================================
--- branches/2.7.x/modules/plugin/jdbc/jdbc-oracle/src/test/java/org/geotools/data/oracle/OracleConnectionLifecycleTest.java (rev 0)
+++ branches/2.7.x/modules/plugin/jdbc/jdbc-oracle/src/test/java/org/geotools/data/oracle/OracleConnectionLifecycleTest.java 2012-01-23 17:34:38 UTC (rev 38519)
@@ -0,0 +1,29 @@
+/*
+ * GeoTools - The Open Source Java GIS Toolkit
+ * http://geotools.org
+ *
+ * (C) 2002-2008, Open Source Geospatial Foundation (OSGeo)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ */
+package org.geotools.data.oracle;
+
+import org.geotools.jdbc.JDBCConnectionLifecycleTest;
+import org.geotools.jdbc.JDBCTestSetup;
+
+public class OracleConnectionLifecycleTest extends JDBCConnectionLifecycleTest {
+
+ @Override
+ protected JDBCTestSetup createTestSetup() {
+ return new OracleTestSetup();
+ }
+
+}
Added: branches/2.7.x/modules/plugin/jdbc/jdbc-postgis/src/test/java/org/geotools/data/postgis/PostgisConnectionLifecycleTest.java
===================================================================
--- branches/2.7.x/modules/plugin/jdbc/jdbc-postgis/src/test/java/org/geotools/data/postgis/PostgisConnectionLifecycleTest.java (rev 0)
+++ branches/2.7.x/modules/plugin/jdbc/jdbc-postgis/src/test/java/org/geotools/data/postgis/PostgisConnectionLifecycleTest.java 2012-01-23 17:34:38 UTC (rev 38519)
@@ -0,0 +1,28 @@
+/*
+ * GeoTools - The Open Source Java GIS Toolkit
+ * http://geotools.org
+ *
+ * (C) 2002-2008, Open Source Geospatial Foundation (OSGeo)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ */
+package org.geotools.data.postgis;
+
+import org.geotools.jdbc.JDBCConnectionLifecycleTest;
+import org.geotools.jdbc.JDBCTestSetup;
+
+
+public class PostgisConnectionLifecycleTest extends JDBCConnectionLifecycleTest {
+
+ protected JDBCTestSetup createTestSetup() {
+ return new PostGISTestSetup();
+ }
+}
|
|
From: <svn...@os...> - 2012-01-23 08:23:21
|
Author: simonegiannecchini
Date: 2012-01-23 00:23:14 -0800 (Mon, 23 Jan 2012)
New Revision: 38518
Modified:
trunk/pom.xml
Log:
GEOT-2867
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2012-01-23 08:22:01 UTC (rev 38517)
+++ trunk/pom.xml 2012-01-23 08:23:14 UTC (rev 38518)
@@ -108,7 +108,7 @@
<property><name>all</name></property>
</activation>
<modules>
- <module>docs</module>
+ <!--module>docs</module-->
</modules>
</profile>
<profile>
@@ -686,6 +686,11 @@
</dependency>
<dependency>
<groupId>it.geosolutions.imageio-ext</groupId>
+ <artifactId>imageio-ext-streams</artifactId>
+ <version>${imageio.ext.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>it.geosolutions.imageio-ext</groupId>
<artifactId>imageio-ext-netcdf</artifactId>
<version>${imageio.ext.version}</version>
</dependency>
@@ -1405,8 +1410,15 @@
<name>Java.net repository</name>
<url>http://download.java.net/maven/2</url>
</repository>
+
<repository>
+ <id>geosolutions</id>
+ <name>geosolutions repository</name>
+ <url>http://maven.geo-solutions.it/</url>
+ </repository>
+
+ <repository>
<id>osgeo</id>
<name>Open Source Geospatial Foundation Repository</name>
<url>http://download.osgeo.org/webdav/geotools/</url>
|
|
From: <svn...@os...> - 2012-01-23 08:22:11
|
Author: simonegiannecchini
Date: 2012-01-23 00:22:01 -0800 (Mon, 23 Jan 2012)
New Revision: 38517
Modified:
trunk/modules/plugin/imagemosaic/pom.xml
trunk/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/GranuleDescriptor.java
trunk/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/ImageMosaicFormat.java
trunk/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/ImageMosaicFormatFactory.java
trunk/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/ImageMosaicReader.java
trunk/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/MosaicConfigurationBean.java
trunk/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/PathType.java
trunk/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/RasterLayerRequest.java
trunk/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/RasterLayerResponse.java
trunk/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/RasterManager.java
trunk/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/ReadType.java
trunk/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/Utils.java
trunk/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/catalog/AbstractGranuleCatalog.java
trunk/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/catalog/GTDataStoreGranuleCatalog.java
trunk/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/catalog/GranuleCatalogFactory.java
trunk/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/catalog/GranuleCatalogVisitor.java
trunk/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/catalog/STRTreeGranuleCatalog.java
trunk/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/catalogbuilder/CatalogBuilder.java
trunk/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/catalogbuilder/CatalogBuilderConfiguration.java
trunk/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/processing/ArtifactsFilterOpImage.java
trunk/modules/plugin/imagemosaic/src/test/java/org/geotools/gce/imagemosaic/CatalogBuilderTest.java
trunk/modules/plugin/imagemosaic/src/test/java/org/geotools/gce/imagemosaic/ImageMosaicReaderTest.java
Log:
GEOT-2867
Modified: trunk/modules/plugin/imagemosaic/pom.xml
===================================================================
--- trunk/modules/plugin/imagemosaic/pom.xml 2012-01-23 03:46:30 UTC (rev 38516)
+++ trunk/modules/plugin/imagemosaic/pom.xml 2012-01-23 08:22:01 UTC (rev 38517)
@@ -139,20 +139,14 @@
<version>${project.version}</version>
</dependency>
<dependency>
- <groupId>org.geotools</groupId>
- <artifactId>gt-image</artifactId>
- <version>${project.version}</version>
+ <groupId>it.geosolutions.imageio-ext</groupId>
+ <artifactId>imageio-ext-streams</artifactId>
</dependency>
- <!--dependency>
- <groupId>org.geotools</groupId>
- <artifactId>gt-imageio-ext-gdal</artifactId>
- <version>${project.version}</version>
- </dependency-->
<dependency>
<groupId>org.geotools</groupId>
- <artifactId>gt-jp2k</artifactId>
+ <artifactId>gt-image</artifactId>
<version>${project.version}</version>
- </dependency>
+ </dependency>
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-cql</artifactId>
Modified: trunk/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/GranuleDescriptor.java
===================================================================
--- trunk/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/GranuleDescriptor.java 2012-01-23 03:46:30 UTC (rev 38516)
+++ trunk/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/GranuleDescriptor.java 2012-01-23 08:22:01 UTC (rev 38517)
@@ -34,8 +34,10 @@
import java.util.logging.Level;
import java.util.logging.Logger;
+import javax.imageio.ImageIO;
import javax.imageio.ImageReadParam;
import javax.imageio.ImageReader;
+import javax.imageio.spi.ImageInputStreamSpi;
import javax.imageio.spi.ImageReaderSpi;
import javax.imageio.stream.ImageInputStream;
import javax.media.jai.BorderExtender;
@@ -265,9 +267,12 @@
ImageReaderSpi cachedReaderSPI;
SimpleFeature originator;
+
boolean handleArtifactsFiltering = false;
boolean filterMe = false;
+
+ ImageInputStreamSpi cachedStreamSPI;
private void init(final BoundingBox granuleBBOX, final URL granuleUrl,
final ImageReaderSpi suggestedSPI, final Geometry inclusionGeometry,
@@ -294,9 +299,29 @@
//
// get a stream
- inStream = Utils.getInputStream(granuleUrl);
- if(inStream == null)
- throw new IllegalArgumentException("Unable to get an input stream for the provided file "+granuleUrl.toString());
+ if(cachedStreamSPI==null){
+ cachedStreamSPI=ImageIOExt.getImageInputStreamSPI(granuleUrl, true);
+ if(cachedStreamSPI==null){
+ final File file = DataUtilities.urlToFile(granuleUrl);
+ if(file!=null){
+ if(LOGGER.isLoggable(Level.WARNING)){
+ LOGGER.log(Level.WARNING,Utils.getFileInfo(file));
+ }
+ }
+ throw new IllegalArgumentException("Unable to get an input stream for the provided granule "+granuleUrl.toString());
+ }
+ }
+ assert cachedStreamSPI!=null:"no cachedStreamSPI available!";
+ inStream = cachedStreamSPI.createInputStreamInstance(granuleUrl, ImageIO.getUseCache(), ImageIO.getCacheDirectory());
+ if(inStream == null){
+ final File file = DataUtilities.urlToFile(granuleUrl);
+ if(file!=null){
+ if(LOGGER.isLoggable(Level.WARNING)){
+ LOGGER.log(Level.WARNING,Utils.getFileInfo(file));
+ }
+ }
+ throw new IllegalArgumentException("Unable to get an input stream for the provided file "+granuleUrl.toString());
+ }
// get a reader and try to cache the suggested SPI first
if(cachedReaderSPI == null){
@@ -596,7 +621,8 @@
//
// get a stream
- inStream = Utils.getInputStream(granuleUrl);
+ assert cachedStreamSPI!=null:"no cachedStreamSPI available!";
+ inStream = cachedStreamSPI.createInputStreamInstance(granuleUrl, ImageIO.getUseCache(), ImageIO.getCacheDirectory());
if(inStream==null)
return null;
@@ -888,7 +914,7 @@
} finally {
try {
- if (inStream != null) {
+ if (request.getReadType() != ReadType.JAI_IMAGEREAD && inStream != null) {
inStream.close();
}
} finally {
@@ -952,7 +978,8 @@
try {
// get a stream
- inStream = Utils.getInputStream(granuleUrl);
+ assert cachedStreamSPI!=null:"no cachedStreamSPI available!";
+ inStream = cachedStreamSPI.createInputStreamInstance(granuleUrl, ImageIO.getUseCache(), ImageIO.getCacheDirectory());
if(inStream==null)
throw new IllegalArgumentException("Unable to create an inputstream for the granuleurl:"+(granuleUrl!=null?granuleUrl:"null"));
Modified: trunk/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/ImageMosaicFormat.java
===================================================================
--- trunk/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/ImageMosaicFormat.java 2012-01-23 03:46:30 UTC (rev 38516)
+++ trunk/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/ImageMosaicFormat.java 2012-01-23 08:22:01 UTC (rev 38517)
@@ -102,6 +102,7 @@
*
* @source $URL$
*/
+@SuppressWarnings("rawtypes")
public final class ImageMosaicFormat extends AbstractGridFormat implements Format {
final static double DEFAULT_ARTIFACTS_FILTER_PTILE_THRESHOLD = 0.1;
@@ -200,7 +201,7 @@
}
/**
- * @see org.geotools.data.coverage.grid.AbstractGridFormat#getImageioReader(Object)
+ * @see org.geotools.data.coverage.grid.AbstractGridFormat#getReader(Object)
*/
@Override
public ImageMosaicReader getReader( Object source ) {
@@ -265,6 +266,7 @@
return true;
}
+ @SuppressWarnings("unchecked")
private boolean checkForUrl( Object source, Hints hints){
try {
@@ -278,12 +280,11 @@
return false; // file does not exist
}
}
- // /////////////////////////////////////////////////////////////////////
+
//
// Load tiles informations, especially the bounds, which will be
// reused
//
- // /////////////////////////////////////////////////////////////////////
DataStore tileIndexStore = null;
CoordinateReferenceSystem crs=null;
boolean shapefile=true;
@@ -358,11 +359,9 @@
if(crs==null)
return false;
- // /////////////////////////////////////////////////////////////////////
- //
- // Now look for the properties file and try to parse relevant fields
- //
- // /////////////////////////////////////////////////////////////////////
+ //
+ // Now look for the properties file and try to parse relevant fields
+ //
URL propsUrl = null;
if(shapefile)
propsUrl=DataUtilities.changeUrlExt(sourceURL, "properties");
Modified: trunk/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/ImageMosaicFormatFactory.java
===================================================================
--- trunk/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/ImageMosaicFormatFactory.java 2012-01-23 03:46:30 UTC (rev 38516)
+++ trunk/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/ImageMosaicFormatFactory.java 2012-01-23 08:22:01 UTC (rev 38517)
@@ -47,362 +47,349 @@
* @source $URL$
*/
public final class ImageMosaicFormatFactory implements GridFormatFactorySpi {
-
- /** Logger. */
- private final static Logger LOGGER = org.geotools.util.logging.Logging.getLogger(ImageMosaicFormatFactory.class);
-
- private static final String KAKADU_SPI = "it.geosolutions.imageio.plugins.jp2k.JP2KKakaduImageReaderSpi";
-
- private static final String GDAL_SPI = "it.geosolutions.imageio.gdalframework.GDALImageReaderSpi";
-
- private static final String GDAL_JP2ECW_SPI = "it.geosolutions.imageio.plugins.jp2ecw.JP2GDALEcwImageReaderSpi";
-
- private static final String GDAL_JP2MrSID_SPI = "it.geosolutions.imageio.plugins.jp2mrsid.JP2GDALMrSidImageReaderSpi";
-
- private static final String GDAL_JP2KAKADU_SPI = "it.geosolutions.imageio.plugins.jp2kakadu.JP2GDALKakaduImageReaderSpi";
- static {
-
- replaceTIFF();
-
- if(hasJP2Kakadu()){
- replaceJP2Kakadu();
- }
-
- else{
- if(hasJP2GDALECW()){
- replaceECW();
- }
- if(hasJP2GDALMRSID()){
- replaceMRSID();
- }
- if(hasJP2GDALKakadu()){
- replaceGDALKakadu();
- }
- }
-
- }
- /**
- * Tells me if this plugin will work on not given the actual installation.
- *
- * <p>
- * Dependecies are mostly from JAI and ImageIO so if they are installed you
- * should not have many problems.
- *
- * @return False if something's missing, true otherwise.
- */
- public boolean isAvailable() {
- boolean available = true;
+ private static final String GDAL_JP2ECW_SPI = "it.geosolutions.imageio.plugins.jp2ecw.JP2GDALEcwImageReaderSpi";
+ private static final String GDAL_JP2KAKADU_SPI = "it.geosolutions.imageio.plugins.jp2kakadu.JP2GDALKakaduImageReaderSpi";
+ private static final String GDAL_JP2MrSID_SPI = "it.geosolutions.imageio.plugins.jp2mrsid.JP2GDALMrSidImageReaderSpi";
+ private static final String GDAL_SPI = "it.geosolutions.imageio.gdalframework.GDALImageReaderSpi";
+ private static final String KAKADU_SPI = "it.geosolutions.imageio.plugins.jp2k.JP2KKakaduImageReaderSpi";
+ /** Logger. */
+ private final static Logger LOGGER = org.geotools.util.logging.Logging.getLogger(ImageMosaicFormatFactory.class);
- // if these classes are here, then the runtine environment has
- // access to JAI and the JAI ImageI/O toolbox.
- try {
- Class.forName("javax.media.jai.JAI");
- Class.forName("com.sun.media.jai.operator.ImageReadDescriptor");
- } catch (ClassNotFoundException cnf) {
- available = false;
- }
+ static {
+
+ replaceTIFF();
+
+ if(hasJP2Kakadu()){
+ replaceJP2Kakadu();
+ }
+
+ else{
+ if(hasJP2GDALECW()){
+ replaceECW();
+ }
+ if(hasJP2GDALMRSID()){
+ replaceMRSID();
+ }
+ if(hasJP2GDALKakadu()){
+ replaceGDALKakadu();
+ }
+ }
+
+ }
- return available;
- }
+ private static boolean hasJP2GDALECW() {
+ try{
+ Class<?> cl = Class.forName(GDAL_JP2ECW_SPI);
+ Class<?> cGdal = Class.forName(GDAL_SPI);
+ Object jp2ecwSPI = cl.newInstance();
+ final Method method = cGdal.getDeclaredMethod("isAvailable", (Class[])null);
+ if (method != null){
+ return (Boolean) method.invoke(jp2ecwSPI,(Object[]) null);
+ }
+ } catch (ClassNotFoundException e) {
+ if (LOGGER.isLoggable(Level.FINE))
+ LOGGER.log(Level.FINE, "Unable to load GDAL JP2 ECW Reader SPI", e);
+ } catch (SecurityException e) {
+ if (LOGGER.isLoggable(Level.FINE))
+ LOGGER.log(Level.FINE, "Unable to load GDAL JP2 ECW Reader SPI", e);
+ } catch (NoSuchMethodException e) {
+ if (LOGGER.isLoggable(Level.FINE))
+ LOGGER.log(Level.FINE, "Unable to load GDAL JP2 ECW Reader SPI", e);
+ } catch (IllegalArgumentException e) {
+ if (LOGGER.isLoggable(Level.FINE))
+ LOGGER.log(Level.FINE, "Unable to load GDAL JP2 ECW Reader SPI", e);
+ } catch (IllegalAccessException e) {
+ if (LOGGER.isLoggable(Level.FINE))
+ LOGGER.log(Level.FINE, "Unable to load GDAL JP2 ECW Reader SPI", e);
+ } catch (InvocationTargetException e) {
+ if (LOGGER.isLoggable(Level.FINE))
+ LOGGER.log(Level.FINE, "Unable to load GDAL JP2 ECW Reader SPI", e);
+ } catch (InstantiationException e) {
+ if (LOGGER.isLoggable(Level.FINE))
+ LOGGER.log(Level.FINE, "Unable to load GDAL JP2 ECW Reader SPI", e);
+ }
+ return false;
+ }
+ private static boolean hasJP2GDALKakadu() {
+ try{
+ Class<?> cl = Class.forName(GDAL_JP2KAKADU_SPI);
+ Class<?> cGdal = Class.forName(GDAL_SPI);
+ Object jp2Kak = cl.newInstance();
+ final Method method = cGdal.getDeclaredMethod("isAvailable", (Class[])null);
+ if (method != null){
+ return (Boolean) method.invoke(jp2Kak,(Object[])null);
+ }
+ } catch (ClassNotFoundException e) {
+ if (LOGGER.isLoggable(Level.FINE))
+ LOGGER.log(Level.FINE, "Unable to load GDAL JP2 Kakadu Reader SPI", e);
+ } catch (SecurityException e) {
+ if (LOGGER.isLoggable(Level.FINE))
+ LOGGER.log(Level.FINE, "Unable to load GDAL JP2 Kakadu Reader SPI", e);
+ } catch (NoSuchMethodException e) {
+ if (LOGGER.isLoggable(Level.FINE))
+ LOGGER.log(Level.FINE, "Unable to load GDAL JP2 Kakadu Reader SPI", e);
+ } catch (IllegalArgumentException e) {
+ if (LOGGER.isLoggable(Level.FINE))
+ LOGGER.log(Level.FINE, "Unable to load GDAL JP2 Kakadu Reader SPI", e);
+ } catch (IllegalAccessException e) {
+ if (LOGGER.isLoggable(Level.FINE))
+ LOGGER.log(Level.FINE, "Unable to load GDAL JP2 Kakadu Reader SPI", e);
+ } catch (InvocationTargetException e) {
+ if (LOGGER.isLoggable(Level.FINE))
+ LOGGER.log(Level.FINE, "Unable to load GDAL JP2 Kakadu Reader SPI", e);
+ } catch (InstantiationException e) {
+ if (LOGGER.isLoggable(Level.FINE))
+ LOGGER.log(Level.FINE, "Unable to load GDAL JP2 Kakadu Reader SPI", e);
+ }
+ return false;
+ }
- private static boolean hasJP2Kakadu() {
- try{
- @SuppressWarnings("unused")
- Class<?> cl = Class.forName(KAKADU_SPI);
- Class<?> utilityClass = Class.forName("it.geosolutions.util.KakaduUtilities");
- final Method method = utilityClass.getDeclaredMethod("isKakaduAvailable", (Class[])null);
- if (method != null){
- Boolean isAvailable = (Boolean) method.invoke(null, null);
- return isAvailable.booleanValue();
- }
- } catch (ClassNotFoundException e) {
- if (LOGGER.isLoggable(Level.FINE))
- LOGGER.log(Level.FINE, "Unable to load kakadu JPEG2000 reader spi",e);
- } catch (SecurityException e) {
- if (LOGGER.isLoggable(Level.FINE))
- LOGGER.log(Level.FINE, "Unable to load kakadu JPEG2000 reader spi",e);
- } catch (NoSuchMethodException e) {
- if (LOGGER.isLoggable(Level.FINE))
- LOGGER.log(Level.FINE, "Unable to load kakadu JPEG2000 reader spi",e);
- } catch (IllegalArgumentException e) {
- if (LOGGER.isLoggable(Level.FINE))
- LOGGER.log(Level.FINE, "Unable to load kakadu JPEG2000 reader spi",e);
- } catch (IllegalAccessException e) {
- if (LOGGER.isLoggable(Level.FINE))
- LOGGER.log(Level.FINE, "Unable to load kakadu JPEG2000 reader spi",e);
- } catch (InvocationTargetException e) {
- if (LOGGER.isLoggable(Level.FINE))
- LOGGER.log(Level.FINE, "Unable to load kakadu JPEG2000 reader spi",e);
- }
- return false;
- }
-
- private static void replaceJP2Kakadu() {
- try{
- Class.forName(KAKADU_SPI);
-
- // imageio kakJP2 reader
- final String imageioJ2KImageReaderCodecName=J2KImageReaderCodecLibSpi.class.getName();
-
- if(PackageUtil.isCodecLibAvailable()){
- boolean succeeded=ImageIOUtilities.replaceProvider(ImageReaderSpi.class, KAKADU_SPI, imageioJ2KImageReaderCodecName, "JPEG 2000");
- if(!succeeded)
- if (LOGGER.isLoggable(Level.WARNING))
- LOGGER.warning("Unable to set ordering between jp2 readers spi-"+KAKADU_SPI+":"+imageioJ2KImageReaderCodecName);
- }
-
- // imageio kakJP2 reader
- final String imageioJ2KImageReaderName=J2KImageReaderSpi.class.getName();
-
- final boolean succeeded=ImageIOUtilities.replaceProvider(ImageReaderSpi.class, KAKADU_SPI, imageioJ2KImageReaderName, "JPEG 2000");
- if(!succeeded)
- if (LOGGER.isLoggable(Level.WARNING))
- LOGGER.warning("Unable to set ordering between jp2 readers spi-"+KAKADU_SPI+":"+imageioJ2KImageReaderName);
-
- } catch (ClassNotFoundException e) {
- if (LOGGER.isLoggable(Level.WARNING))
- LOGGER.log(Level.WARNING, "Unable to load specific JPEG2000 reader spi",e);
- }
- }
-
- private static void replaceTIFF() {
- try{
- //check if our tiff plugin is in the path
- final String customTiffName=it.geosolutions.imageioimpl.plugins.tiff.TIFFImageReaderSpi.class.getName();
- Class.forName(customTiffName);
-
- // imageio tiff reader
- final String imageioTiffName=TIFFImageReaderSpi.class.getName();
-
- final boolean succeeded=ImageIOUtilities.replaceProvider(ImageReaderSpi.class, customTiffName, imageioTiffName, "tiff");
- if(!succeeded)
- if (LOGGER.isLoggable(Level.WARNING))
- LOGGER.warning("Unable to set ordering between tiff readers spi");
-
- } catch (ClassNotFoundException e) {
- if (LOGGER.isLoggable(Level.WARNING))
- LOGGER.log(Level.WARNING,"Unable to load specific TIFF reader spi",e);
- }
-
- }
-
- private static boolean hasJP2GDALKakadu() {
- try{
- @SuppressWarnings("unused")
- Class<?> cl = Class.forName(GDAL_JP2KAKADU_SPI);
- Class<?> cGdal = Class.forName(GDAL_SPI);
- Object jp2Kak = cl.newInstance();
- final Method method = cGdal.getDeclaredMethod("isAvailable", (Class[])null);
- if (method != null){
- Boolean isAvailable = (Boolean) method.invoke(jp2Kak, null);
- return isAvailable.booleanValue();
- }
- } catch (ClassNotFoundException e) {
- if (LOGGER.isLoggable(Level.FINE))
- LOGGER.log(Level.FINE, "Unable to load GDAL JP2 Kakadu Reader SPI", e);
- } catch (SecurityException e) {
- if (LOGGER.isLoggable(Level.FINE))
- LOGGER.log(Level.FINE, "Unable to load GDAL JP2 Kakadu Reader SPI", e);
- } catch (NoSuchMethodException e) {
- if (LOGGER.isLoggable(Level.FINE))
- LOGGER.log(Level.FINE, "Unable to load GDAL JP2 Kakadu Reader SPI", e);
- } catch (IllegalArgumentException e) {
- if (LOGGER.isLoggable(Level.FINE))
- LOGGER.log(Level.FINE, "Unable to load GDAL JP2 Kakadu Reader SPI", e);
- } catch (IllegalAccessException e) {
- if (LOGGER.isLoggable(Level.FINE))
- LOGGER.log(Level.FINE, "Unable to load GDAL JP2 Kakadu Reader SPI", e);
- } catch (InvocationTargetException e) {
- if (LOGGER.isLoggable(Level.FINE))
- LOGGER.log(Level.FINE, "Unable to load GDAL JP2 Kakadu Reader SPI", e);
- } catch (InstantiationException e) {
- if (LOGGER.isLoggable(Level.FINE))
- LOGGER.log(Level.FINE, "Unable to load GDAL JP2 Kakadu Reader SPI", e);
- }
- return false;
+ private static boolean hasJP2GDALMRSID() {
+ try{
+ Class<?> cl = Class.forName(GDAL_JP2MrSID_SPI);
+ Class<?> cGdal = Class.forName(GDAL_SPI);
+ Object jp2MrSid = cl.newInstance();
+ final Method method = cGdal.getDeclaredMethod("isAvailable", (Class[])null);
+ if (method != null){
+ return (Boolean) method.invoke(jp2MrSid, (Object[])null);
+ }
+ } catch (ClassNotFoundException e) {
+ if (LOGGER.isLoggable(Level.FINE))
+ LOGGER.log(Level.FINE, "Unable to load GDAL JP2 MrSID Reader SPI", e);
+ } catch (SecurityException e) {
+ if (LOGGER.isLoggable(Level.FINE))
+ LOGGER.log(Level.FINE, "Unable to load GDAL JP2 MrSID Reader SPI", e);
+ } catch (NoSuchMethodException e) {
+ if (LOGGER.isLoggable(Level.FINE))
+ LOGGER.log(Level.FINE, "Unable to load GDAL JP2 MrSID Reader SPI", e);
+ } catch (IllegalArgumentException e) {
+ if (LOGGER.isLoggable(Level.FINE))
+ LOGGER.log(Level.FINE, "Unable to load GDAL JP2 MrSID Reader SPI", e);
+ } catch (IllegalAccessException e) {
+ if (LOGGER.isLoggable(Level.FINE))
+ LOGGER.log(Level.FINE, "Unable to load GDAL JP2 MrSID Reader SPI", e);
+ } catch (InvocationTargetException e) {
+ if (LOGGER.isLoggable(Level.FINE))
+ LOGGER.log(Level.FINE, "Unable to load GDAL JP2 MrSID Reader SPI", e);
+ } catch (InstantiationException e) {
+ if (LOGGER.isLoggable(Level.FINE))
+ LOGGER.log(Level.FINE, "Unable to load GDAL JP2 MrSID Reader SPI", e);
}
+ return false;
+ }
- private static void replaceGDALKakadu() {
- try{
- //check if our kakJP2 plugin is in the path
+ private static boolean hasJP2Kakadu() {
+ try{
+ Class<?> cl = Class.forName(KAKADU_SPI);
+ Class<?> utilityClass = Class.forName("it.geosolutions.util.KakaduUtilities");
+ final Method method = utilityClass.getDeclaredMethod("isKakaduAvailable", (Class[])null);
+ if (method != null){
+ return (Boolean) method.invoke(null, (Object[])null);
+ }
+ } catch (ClassNotFoundException e) {
+ if (LOGGER.isLoggable(Level.FINE))
+ LOGGER.log(Level.FINE, "Unable to load kakadu JPEG2000 reader spi",e);
+ } catch (SecurityException e) {
+ if (LOGGER.isLoggable(Level.FINE))
+ LOGGER.log(Level.FINE, "Unable to load kakadu JPEG2000 reader spi",e);
+ } catch (NoSuchMethodException e) {
+ if (LOGGER.isLoggable(Level.FINE))
+ LOGGER.log(Level.FINE, "Unable to load kakadu JPEG2000 reader spi",e);
+ } catch (IllegalArgumentException e) {
+ if (LOGGER.isLoggable(Level.FINE))
+ LOGGER.log(Level.FINE, "Unable to load kakadu JPEG2000 reader spi",e);
+ } catch (IllegalAccessException e) {
+ if (LOGGER.isLoggable(Level.FINE))
+ LOGGER.log(Level.FINE, "Unable to load kakadu JPEG2000 reader spi",e);
+ } catch (InvocationTargetException e) {
+ if (LOGGER.isLoggable(Level.FINE))
+ LOGGER.log(Level.FINE, "Unable to load kakadu JPEG2000 reader spi",e);
+ }
+ return false;
+ }
- Class.forName(GDAL_JP2KAKADU_SPI);
+ private static void replaceECW() {
+ try{
+ //check if our ecwJP2 plugin is in the path
+ Class.forName(GDAL_JP2ECW_SPI);
+
+ // imageio ecwJP2 reader
+ final String imageioJ2KImageReaderCodecName=J2KImageReaderCodecLibSpi.class.getName();
+
+ if(PackageUtil.isCodecLibAvailable()){
+ boolean succeeded=ImageIOUtilities.replaceProvider(ImageReaderSpi.class, GDAL_JP2ECW_SPI, imageioJ2KImageReaderCodecName, "JPEG 2000");
+ if(!succeeded)
+ if (LOGGER.isLoggable(Level.WARNING))
+ LOGGER.warning("Unable to set ordering between jp2 readers spi-"+GDAL_JP2ECW_SPI+":"+imageioJ2KImageReaderCodecName);
+ }
+
+ // imageio ecwJP2 reader
+ final String imageioJ2KImageReaderName=J2KImageReaderSpi.class.getName();
+
+ final boolean succeeded=ImageIOUtilities.replaceProvider(ImageReaderSpi.class, GDAL_JP2ECW_SPI, imageioJ2KImageReaderName, "JPEG 2000");
+ if(!succeeded)
+ if (LOGGER.isLoggable(Level.WARNING))
+ LOGGER.warning("Unable to set ordering between jp2 readers spi-"+GDAL_JP2ECW_SPI+":"+imageioJ2KImageReaderName);
+
+ } catch (ClassNotFoundException e) {
+ if (LOGGER.isLoggable(Level.WARNING))
+ LOGGER.log(Level.WARNING, "Unable to load specific JPEG2000 reader spi",e);
+ }
+
+ }
- // imageio kakJP2 reader
- final String imageioJ2KImageReaderCodecName=J2KImageReaderCodecLibSpi.class.getName();
-
- if(PackageUtil.isCodecLibAvailable()){
- boolean succeeded=ImageIOUtilities.replaceProvider(ImageReaderSpi.class, GDAL_JP2KAKADU_SPI, imageioJ2KImageReaderCodecName, "JPEG 2000");
- if(!succeeded)
- if (LOGGER.isLoggable(Level.WARNING))
- LOGGER.warning("Unable to set ordering between jp2 readers spi-"+GDAL_JP2KAKADU_SPI+":"+imageioJ2KImageReaderCodecName);
- }
-
- // imageio kakJP2 reader
- final String imageioJ2KImageReaderName=J2KImageReaderSpi.class.getName();
-
-
- final boolean succeeded=ImageIOUtilities.replaceProvider(ImageReaderSpi.class, GDAL_JP2KAKADU_SPI, imageioJ2KImageReaderName, "JPEG 2000");
- if(!succeeded)
- if (LOGGER.isLoggable(Level.WARNING))
- LOGGER.warning("Unable to set ordering between jp2 readers spi-"+GDAL_JP2KAKADU_SPI+":"+imageioJ2KImageReaderName);
-
- } catch (ClassNotFoundException e) {
- if (LOGGER.isLoggable(Level.WARNING))
- LOGGER.log(Level.WARNING, "Unable to load specific JPEG2000 reader spi",e);
- }
-
- }
+ private static void replaceGDALKakadu() {
+ try{
+ //check if our kakJP2 plugin is in the path
+
+ Class.forName(GDAL_JP2KAKADU_SPI);
+
+ // imageio kakJP2 reader
+ final String imageioJ2KImageReaderCodecName=J2KImageReaderCodecLibSpi.class.getName();
+
+ if(PackageUtil.isCodecLibAvailable()){
+ boolean succeeded=ImageIOUtilities.replaceProvider(ImageReaderSpi.class, GDAL_JP2KAKADU_SPI, imageioJ2KImageReaderCodecName, "JPEG 2000");
+ if(!succeeded)
+ if (LOGGER.isLoggable(Level.WARNING))
+ LOGGER.warning("Unable to set ordering between jp2 readers spi-"+GDAL_JP2KAKADU_SPI+":"+imageioJ2KImageReaderCodecName);
+ }
+
+ // imageio kakJP2 reader
+ final String imageioJ2KImageReaderName=J2KImageReaderSpi.class.getName();
+
+
+ final boolean succeeded=ImageIOUtilities.replaceProvider(ImageReaderSpi.class, GDAL_JP2KAKADU_SPI, imageioJ2KImageReaderName, "JPEG 2000");
+ if(!succeeded)
+ if (LOGGER.isLoggable(Level.WARNING))
+ LOGGER.warning("Unable to set ordering between jp2 readers spi-"+GDAL_JP2KAKADU_SPI+":"+imageioJ2KImageReaderName);
+
+ } catch (ClassNotFoundException e) {
+ if (LOGGER.isLoggable(Level.WARNING))
+ LOGGER.log(Level.WARNING, "Unable to load specific JPEG2000 reader spi",e);
+ }
+
+ }
- private static void replaceMRSID() {
- try{
- //check if our mrsidJP2 plugin is in the path
- Class.forName(GDAL_JP2MrSID_SPI );
+ private static void replaceJP2Kakadu() {
+ try{
+ Class.forName(KAKADU_SPI);
+
+ // imageio kakJP2 reader
+ final String imageioJ2KImageReaderCodecName=J2KImageReaderCodecLibSpi.class.getName();
+
+ if(PackageUtil.isCodecLibAvailable()){
+ boolean succeeded=ImageIOUtilities.replaceProvider(ImageReaderSpi.class, KAKADU_SPI, imageioJ2KImageReaderCodecName, "JPEG 2000");
+ if(!succeeded)
+ if (LOGGER.isLoggable(Level.WARNING))
+ LOGGER.warning("Unable to set ordering between jp2 readers spi-"+KAKADU_SPI+":"+imageioJ2KImageReaderCodecName);
+ }
+
+ // imageio kakJP2 reader
+ final String imageioJ2KImageReaderName=J2KImageReaderSpi.class.getName();
+
+ final boolean succeeded=ImageIOUtilities.replaceProvider(ImageReaderSpi.class, KAKADU_SPI, imageioJ2KImageReaderName, "JPEG 2000");
+ if(!succeeded)
+ if (LOGGER.isLoggable(Level.WARNING))
+ LOGGER.warning("Unable to set ordering between jp2 readers spi-"+KAKADU_SPI+":"+imageioJ2KImageReaderName);
+
+ } catch (ClassNotFoundException e) {
+ if (LOGGER.isLoggable(Level.WARNING))
+ LOGGER.log(Level.WARNING, "Unable to load specific JPEG2000 reader spi",e);
+ }
+ }
- // imageio tiff reader
- final String imageioJ2KImageReaderCodecName=J2KImageReaderCodecLibSpi.class.getName();
-
- if(PackageUtil.isCodecLibAvailable()){
- boolean succeeded=ImageIOUtilities.replaceProvider(ImageReaderSpi.class, GDAL_JP2MrSID_SPI , imageioJ2KImageReaderCodecName, "JPEG 2000");
- if(!succeeded)
- if (LOGGER.isLoggable(Level.WARNING))
- LOGGER.warning("Unable to set ordering between jp2 readers spi-"+GDAL_JP2MrSID_SPI +":"+imageioJ2KImageReaderCodecName);
- }
-
- // imageio mrsidJP2 reader
- final String imageioJ2KImageReaderName=J2KImageReaderSpi.class.getName();
-
-
- final boolean succeeded=ImageIOUtilities.replaceProvider(ImageReaderSpi.class, GDAL_JP2MrSID_SPI , imageioJ2KImageReaderName, "JPEG 2000");
- if(!succeeded)
- if (LOGGER.isLoggable(Level.WARNING))
- LOGGER.warning("Unable to set ordering between jp2 readers spi-"+GDAL_JP2MrSID_SPI +":"+imageioJ2KImageReaderName);
-
- } catch (ClassNotFoundException e) {
- if (LOGGER.isLoggable(Level.WARNING))
- LOGGER.log(Level.WARNING, "Unable to load specific JPEG2000 reader spi",e);
- }
-
- }
+ private static void replaceMRSID() {
+ try{
+ //check if our mrsidJP2 plugin is in the path
+ Class.forName(GDAL_JP2MrSID_SPI );
+
+ // imageio tiff reader
+ final String imageioJ2KImageReaderCodecName=J2KImageReaderCodecLibSpi.class.getName();
+
+ if(PackageUtil.isCodecLibAvailable()){
+ boolean succeeded=ImageIOUtilities.replaceProvider(ImageReaderSpi.class, GDAL_JP2MrSID_SPI , imageioJ2KImageReaderCodecName, "JPEG 2000");
+ if(!succeeded)
+ if (LOGGER.isLoggable(Level.WARNING))
+ LOGGER.warning("Unable to set ordering between jp2 readers spi-"+GDAL_JP2MrSID_SPI +":"+imageioJ2KImageReaderCodecName);
+ }
+
+ // imageio mrsidJP2 reader
+ final String imageioJ2KImageReaderName=J2KImageReaderSpi.class.getName();
+
+
+ final boolean succeeded=ImageIOUtilities.replaceProvider(ImageReaderSpi.class, GDAL_JP2MrSID_SPI , imageioJ2KImageReaderName, "JPEG 2000");
+ if(!succeeded)
+ if (LOGGER.isLoggable(Level.WARNING))
+ LOGGER.warning("Unable to set ordering between jp2 readers spi-"+GDAL_JP2MrSID_SPI +":"+imageioJ2KImageReaderName);
+
+ } catch (ClassNotFoundException e) {
+ if (LOGGER.isLoggable(Level.WARNING))
+ LOGGER.log(Level.WARNING, "Unable to load specific JPEG2000 reader spi",e);
+ }
+
+ }
- private static boolean hasJP2GDALMRSID() {
- try{
- @SuppressWarnings("unused")
- Class<?> cl = Class.forName(GDAL_JP2MrSID_SPI);
- Class<?> cGdal = Class.forName(GDAL_SPI);
- Object jp2MrSid = cl.newInstance();
- final Method method = cGdal.getDeclaredMethod("isAvailable", (Class[])null);
- if (method != null){
- Boolean isAvailable = (Boolean) method.invoke(jp2MrSid, null);
- return isAvailable.booleanValue();
- }
- } catch (ClassNotFoundException e) {
- if (LOGGER.isLoggable(Level.FINE))
- LOGGER.log(Level.FINE, "Unable to load GDAL JP2 MrSID Reader SPI", e);
- } catch (SecurityException e) {
- if (LOGGER.isLoggable(Level.FINE))
- LOGGER.log(Level.FINE, "Unable to load GDAL JP2 MrSID Reader SPI", e);
- } catch (NoSuchMethodException e) {
- if (LOGGER.isLoggable(Level.FINE))
- LOGGER.log(Level.FINE, "Unable to load GDAL JP2 MrSID Reader SPI", e);
- } catch (IllegalArgumentException e) {
- if (LOGGER.isLoggable(Level.FINE))
- LOGGER.log(Level.FINE, "Unable to load GDAL JP2 MrSID Reader SPI", e);
- } catch (IllegalAccessException e) {
- if (LOGGER.isLoggable(Level.FINE))
- LOGGER.log(Level.FINE, "Unable to load GDAL JP2 MrSID Reader SPI", e);
- } catch (InvocationTargetException e) {
- if (LOGGER.isLoggable(Level.FINE))
- LOGGER.log(Level.FINE, "Unable to load GDAL JP2 MrSID Reader SPI", e);
- } catch (InstantiationException e) {
- if (LOGGER.isLoggable(Level.FINE))
- LOGGER.log(Level.FINE, "Unable to load GDAL JP2 MrSID Reader SPI", e);
- }
- return false;
- }
+ private static void replaceTIFF() {
+ try{
+ //check if our tiff plugin is in the path
+ final String customTiffName=it.geosolutions.imageioimpl.plugins.tiff.TIFFImageReaderSpi.class.getName();
+ Class.forName(customTiffName);
+
+ // imageio tiff reader
+ final String imageioTiffName=TIFFImageReaderSpi.class.getName();
+
+ final boolean succeeded=ImageIOUtilities.replaceProvider(ImageReaderSpi.class, customTiffName, imageioTiffName, "tiff");
+ if(!succeeded)
+ if (LOGGER.isLoggable(Level.WARNING))
+ LOGGER.warning("Unable to set ordering between tiff readers spi");
+
+ } catch (ClassNotFoundException e) {
+ if (LOGGER.isLoggable(Level.WARNING))
+ LOGGER.log(Level.WARNING,"Unable to load specific TIFF reader spi",e);
+ }
+
+ }
- private static void replaceECW() {
- try{
- //check if our ecwJP2 plugin is in the path
- Class.forName(GDAL_JP2ECW_SPI);
+ /**
+ * @see GridFormatFactorySpi#createFormat().
+ */
+ public AbstractGridFormat createFormat() {
+ return new ImageMosaicFormat();
+ }
- // imageio ecwJP2 reader
- final String imageioJ2KImageReaderCodecName=J2KImageReaderCodecLibSpi.class.getName();
-
- if(PackageUtil.isCodecLibAvailable()){
- boolean succeeded=ImageIOUtilities.replaceProvider(ImageReaderSpi.class, GDAL_JP2ECW_SPI, imageioJ2KImageReaderCodecName, "JPEG 2000");
- if(!succeeded)
- if (LOGGER.isLoggable(Level.WARNING))
- LOGGER.warning("Unable to set ordering between jp2 readers spi-"+GDAL_JP2ECW_SPI+":"+imageioJ2KImageReaderCodecName);
- }
-
- // imageio ecwJP2 reader
- final String imageioJ2KImageReaderName=J2KImageReaderSpi.class.getName();
-
- final boolean succeeded=ImageIOUtilities.replaceProvider(ImageReaderSpi.class, GDAL_JP2ECW_SPI, imageioJ2KImageReaderName, "JPEG 2000");
- if(!succeeded)
- if (LOGGER.isLoggable(Level.WARNING))
- LOGGER.warning("Unable to set ordering between jp2 readers spi-"+GDAL_JP2ECW_SPI+":"+imageioJ2KImageReaderName);
-
- } catch (ClassNotFoundException e) {
- if (LOGGER.isLoggable(Level.WARNING))
- LOGGER.log(Level.WARNING, "Unable to load specific JPEG2000 reader spi",e);
- }
-
- }
+ /**
+ * Returns the implementation hints. The default implementation returns an
+ * empty map.
+ *
+ * @return An empty map.
+ */
+ public Map<RenderingHints.Key, ?> getImplementationHints() {
+ return Collections.emptyMap();
+ }
- private static boolean hasJP2GDALECW() {
- try{
- @SuppressWarnings("unused")
- Class<?> cl = Class.forName(GDAL_JP2ECW_SPI);
- Class<?> cGdal = Class.forName(GDAL_SPI);
- Object jp2ecwSPI = cl.newInstance();
- final Method method = cGdal.getDeclaredMethod("isAvailable", (Class[])null);
- if (method != null){
- Boolean isAvailable = (Boolean) method.invoke(jp2ecwSPI, null);
- return isAvailable.booleanValue();
- }
- } catch (ClassNotFoundException e) {
- if (LOGGER.isLoggable(Level.FINE))
- LOGGER.log(Level.FINE, "Unable to load GDAL JP2 ECW Reader SPI", e);
- } catch (SecurityException e) {
- if (LOGGER.isLoggable(Level.FINE))
- LOGGER.log(Level.FINE, "Unable to load GDAL JP2 ECW Reader SPI", e);
- } catch (NoSuchMethodException e) {
- if (LOGGER.isLoggable(Level.FINE))
- LOGGER.log(Level.FINE, "Unable to load GDAL JP2 ECW Reader SPI", e);
- } catch (IllegalArgumentException e) {
- if (LOGGER.isLoggable(Level.FINE))
- LOGGER.log(Level.FINE, "Unable to load GDAL JP2 ECW Reader SPI", e);
- } catch (IllegalAccessException e) {
- if (LOGGER.isLoggable(Level.FINE))
- LOGGER.log(Level.FINE, "Unable to load GDAL JP2 ECW Reader SPI", e);
- } catch (InvocationTargetException e) {
- if (LOGGER.isLoggable(Level.FINE))
- LOGGER.log(Level.FINE, "Unable to load GDAL JP2 ECW Reader SPI", e);
- } catch (InstantiationException e) {
- if (LOGGER.isLoggable(Level.FINE))
- LOGGER.log(Level.FINE, "Unable to load GDAL JP2 ECW Reader SPI", e);
- }
- return false;
+ /**
+ * Tells me if this plugin will work on not given the actual installation.
+ *
+ * <p>
+ * Dependecies are mostly from JAI and ImageIO so if they are installed you
+ * should not have many problems.
+ *
+ * @return False if something's missing, true otherwise.
+ */
+ public boolean isAvailable() {
+ boolean available = true;
+
+ // if these classes are here, then the runtine environment has
+ // access to JAI and the JAI ImageI/O toolbox.
+ try {
+ Class.forName("javax.media.jai.JAI");
+ Class.forName("com.sun.media.jai.operator.ImageReadDescriptor");
+ } catch (ClassNotFoundException cnf) {
+ available = false;
}
-
- /**
- * @see GridFormatFactorySpi#createFormat().
- */
- public AbstractGridFormat createFormat() {
- return new ImageMosaicFormat();
- }
-
- /**
- * Returns the implementation hints. The default implementation returns an
- * empty map.
- *
- * @return An empty map.
- */
- public Map<RenderingHints.Key, ?> getImplementationHints() {
- return Collections.emptyMap();
- }
+
+ return available;
+ }
}
Modified: trunk/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/ImageMosaicReader.java
===================================================================
--- trunk/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/ImageMosaicReader.java 2012-01-23 03:46:30 UTC (rev 38516)
+++ trunk/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/ImageMosaicReader.java 2012-01-23 08:22:01 UTC (rev 38517)
@@ -141,8 +141,6 @@
boolean cachingIndex;
String elevationAttribute;
-
- String runtimeAttribute;
boolean imposedBBox;
@@ -523,14 +521,9 @@
// elevation param
final String elevationAttribute = configuration.getElevationAttribute();
if(elevationAttribute != null)
- this.elevationAttribute = elevationAttribute;
+ this.elevationAttribute = elevationAttribute;
- // runtime param
- final String runtimeAttribute = configuration.getRuntimeAttribute();
- if(runtimeAttribute != null)
- this.runtimeAttribute = runtimeAttribute;
-
// caching for the index
cachingIndex = configuration.isCaching();
@@ -791,54 +784,7 @@
}
-// final boolean getRuntimeAttribute=name.equalsIgnoreCase("runtime_domain");
-// if(getRuntimeAttribute){
-// Query query;
-// try {
-// query = new DefaultQuery(rasterManager.granuleCatalog.getType().getTypeName());
-// query.setPropertyNames(Arrays.asList("runtime"));
-// final SortBy[] sortBy=new SortBy[]{
-// new SortByImpl(
-// FeatureUtilities.DEFAULT_FILTER_FACTORY.property("runtime"),
-// SortOrder.DESCENDING
-// )};
-// if(queryCapabilities.supportsSorting(sortBy))
-// query.setSortBy(sortBy);
-//// else
-//// manualSort=true;
-// final UniqueVisitor visitor= new UniqueVisitor("runtime");
-// rasterManager.granuleCatalog.computeAggregateFunction(query, visitor);
-//
-// // check result
-// final Set<Integer> result = new TreeSet<Integer>(new Comparator<Integer>() {
-//
-// public int compare(Integer o1, Integer o2) {
-// // Revert Order
-// if (o1 > 02)
-// return -1;
-// else if (o1 < o2)
-// return 1;
-// return 0;
-// }
-// });
-// result.addAll(visitor.getUnique());
-// if(result.size()<=0)
-// return null;
-// final StringBuilder buff= new StringBuilder();
-// for(Iterator<Integer> it=result.iterator();it.hasNext();){
-// final int value= it.next();
-// buff.append(value);
-// if(it.hasNext())
-// buff.append(",");
-// }
-// return buff.toString();
-// } catch (IOException e) {
-// if(LOGGER.isLoggable(Level.WARNING))
-// LOGGER.log(Level.WARNING,"Unable to parse attribute:"+name,e);
-// }
-//
-// }
-//
+
return super.getMetadataValue(name);
}
Modified: trunk/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/MosaicConfigurationBean.java
===================================================================
--- trunk/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/MosaicConfigurationBean.java 2012-01-23 03:46:30 UTC (rev 38516)
+++ trunk/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/MosaicConfigurationBean.java 2012-01-23 08:22:01 UTC (rev 38517)
@@ -35,6 +35,9 @@
*/
public class MosaicConfigurationBean {
+ /**
+ * Default constructor
+ */
public MosaicConfigurationBean() {
}
@@ -55,7 +58,7 @@
/**
* <code>true</code> it tells us if the mosaic points to absolute paths or to relative ones. (in case of <code>false</code>).
*/
- private boolean absolutePath;
+ private boolean absolutePath= Utils.DEFAULT_PATH_BEHAVIOR;
/**
* <code>true</code> if we need to expand to RGB(A) the single tiles in case they use a different {@link IndexColorModel}.
@@ -72,7 +75,7 @@
private int levelsNum;
/** location attribute name*/
- private String locationAttribute;
+ private String locationAttribute=Utils.DEFAULT_LOCATION_ATTRIBUTE;
/**Suggested SPI for the various tiles. May be null.**/
private String suggestedSPI;
@@ -82,9 +85,6 @@
/** elevation attribute name. <code>null</code> if absent.*/
private String elevationAttribute;
-
- /** runtime attribute name. <code>null</code> if absent.*/
- private String runtimeAttribute;
/**
* mosaic's dummy sample model useful to store dataType and number of bands. All the other fields
@@ -120,13 +120,6 @@
this.elevationAttribute = elevationAttribute;
}
- public String getRuntimeAttribute() {
- return runtimeAttribute;
- }
- public void setRuntimeAttribute(final String runtimeAttribute) {
- this.runtimeAttribute = runtimeAttribute;
- }
-
/** we want to use caching for our index.*/
private boolean caching = Utils.DEFAULT_CONFIGURATION_CACHING;
Modified: trunk/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/PathType.java
===================================================================
--- trunk/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/PathType.java 2012-01-23 03:46:30 UTC (rev 38516)
+++ trunk/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/PathType.java 2012-01-23 08:22:01 UTC (rev 38517)
@@ -68,19 +68,6 @@
} catch (MalformedURLException e) {
return null;
}
-
-// // create a file for the provided location, relative to parent location
-// File rasterFile= new File(parentLocation,location);
-// if(!ImageMosaicUtils.checkFileReadable(rasterFile))
-// {
-// if (LOGGER.isLoggable(Level.INFO))
-// LOGGER.info("Unable to read image for file "+ rasterFile.getAbsolutePath());
-//
-// return null;
-//
-// }
-// return rasterFile;
-
}
},
Modified: trunk/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/RasterLayerRequest.java
===================================================================
--- trunk/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/RasterLayerRequest.java 2012-01-23 03:46:30 UTC (rev 38516)
+++ trunk/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/RasterLayerRequest.java 2012-01-23 08:22:01 UTC (rev 38517)
@@ -71,6 +71,7 @@
* @author Daniele Romagnoli, GeoSolutions
* @author Simone Giannecchini, GeoSolutions
*/
+@SuppressWarnings("rawtypes")
class RasterLayerRequest {
/** Logger. */
@@ -243,7 +244,6 @@
prepare();
}
- @SuppressWarnings({ "unchecked"})
private void setDefaultParameterValues() {
// get the read parameters for this format plus the ones for the basic format and set them to the default
@@ -465,7 +465,6 @@
* @param name
* the name of the parameter
*/
- @SuppressWarnings("unchecked")
private void extractParameter(ParameterValue<?> param, Identifier name) {
// //
Modified: trunk/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/RasterLayerResponse.java
===================================================================
--- trunk/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/RasterLayerResponse.java 2012-01-23 03:46:30 UTC (rev 38516)
+++ trunk/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/RasterLayerResponse.java 2012-01-23 08:22:01 UTC (rev 38517)
@@ -125,6 +125,7 @@
* @author Daniele Romagnoli, GeoSolutions
* @author Stefan Alfons Krueger (alfonx), Wikisquare.de : Support for jar:file:foo.jar/bar.properties URLs
*/
+@SuppressWarnings("rawtypes")
class RasterLayerResponse{
private static final class SimplifiedGridSampleDimension extends GridSampleDimension implements SampleDimension{
@@ -287,7 +288,7 @@
}
@SuppressWarnings("unchecked")
- @Override
+ @Override
public void visit(Feature feature) {
super.visit(feature);
// if we got a NAN let's leave
@@ -324,18 +325,9 @@
*
*/
class MosaicBuilder implements GranuleCatalogVisitor{
-
- private final int maxNumberOfGranules;
-
- /**
- * Default {@link Constructor}
- */
- public MosaicBuilder(final RasterLayerRequest request) {
- this.request=request;
- maxNumberOfGranules=request.getMaximumNumberOfGranules();
- }
+ private final int maxNumberOfGranules;
private final List<Future<GranuleLoadingResult>> tasks= new ArrayList<Future<GranuleLoadingResult>>();
private int granulesNumber;
private List<ROI> rois = new ArrayList<ROI>();
@@ -351,6 +343,15 @@
private List<RenderedImage> sources = new ArrayList<RenderedImage>();
+
+ /**
+ * Default {@link Constructor}
+ */
+ public MosaicBuilder(final RasterLayerRequest request) {
+ this.request=request;
+ maxNumberOfGranules=request.getMaximumNumberOfGranules();
+ }
+
public RenderedImage[] getSourcesAsArray() {
RenderedImage []imageSources = new RenderedImage[sources.size()];
sources.toArray(imageSources);
@@ -903,7 +904,6 @@
true));
} else {
// convert to range and create a correct range filter
- @SuppressWarnings("rawtypes")
final NumberRange range= (NumberRange)elevation;
elevationF.add(
FeatureUtilities.DEFAULT_FILTER_FACTORY.and(
Modified: trunk/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/RasterManager.java
===================================================================
--- trunk/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/RasterManager.java 2012-01-23 03:46:30 UTC (rev 38516)
+++ trunk/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/RasterManager.java 2012-01-23 08:22:01 UTC (rev 38517)
@@ -190,8 +190,6 @@
String elevationAttribute;
- String runtimeAttribute;
-
ImageLayout defaultImageLayout;
public RasterManager(final ImageMosaicReader reader) throws DataSourceException {
@@ -208,7 +206,6 @@
timeAttribute=parent.timeAttribute;
elevationAttribute=parent.elevationAttribute;
- runtimeAttribute=parent.runtimeAttribute;
coverageIdentifier=reader.getName();
hints = reader.getHints();
this.coverageIdentifier =reader.getName();
Modified: trunk/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/ReadType.java
===================================================================
--- trunk/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/ReadType.java 2012-01-23 03:46:30 UTC (rev 38516)
+++ trunk/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/ReadType.java 2012-01-23 08:22:01 UTC (rev 38517)
@@ -16,7 +16,6 @@
*/
package org.geotools.gce.imagemosaic;
-import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.image.RenderedImage;
import java.io.IOException;
@@ -26,7 +25,6 @@
import javax.imageio.ImageReadParam;
import javax.imageio.ImageReader;
-import javax.imageio.spi.ImageReaderSpi;
import javax.imageio.stream.ImageInputStream;
import javax.media.jai.RenderedOp;
@@ -59,23 +57,30 @@
final ImageReader reader,
final Hints hints,
final boolean closeElements) {
- //
+ //
// Using ImageReader to load the data directly
//
try{
+ //check source region
+ if(CoverageUtilities.checkEmptySourceRegion(readParameters, rasterDimensions)){
+ if (LOGGER.isLoggable(Level.WARNING))
+ LOGGER.warning("Provided an emptu source region to this read method ");
+ return null;
+ }
+
+ // checks on url
+ if(granuleUrl==null){
+ if (LOGGER.isLoggable(Level.WARNING))
+ LOGGER.warning("Provided a null URL to this read method ");
+ return null;
+ }
- if(reader==null)
- {
+ if(reader==null){
if (LOGGER.isLoggable(Level.WARNING))
LOGGER.warning("Unable to get reader for URL " + granuleUrl);
return null;
}
-
- //check source regione
- if(CoverageUtilities.checkEmptySourceRegion(readParameters, rasterDimensions))
- return null;
-
if (LOGGER.isLoggable(Level.FINER))
LOGGER.log(Level.FINER, "reading file: " + granuleUrl);
@@ -98,127 +103,11 @@
}
- }
-
- RenderedImage read(
- final ImageReadParam readP,
- final int imageIndex,
- final URL rasterURL,
- final Rectangle readDimension,
- final ImageReaderSpi spi,
- final Hints hints
- )throws IOException{
- //
- // Using ImageReader to load the data directly
- //
- ImageInputStream inStream=null;
- ImageReader reader=null;
- try{
- inStream = Utils.getInputStream(rasterURL);
- if(inStream==null)
- return null;
-
- reader=spi.createReaderInstance();
- if(reader==null)
- {
- if (LOGGER.isLoggable(Level.WARNING))
- LOGGER.warning("Unable to get reader for URL " + rasterURL);
- return null;
- }
-
- inStream.reset();
- reader.setInput(inStream);
-
- //check source regione
- if(CoverageUtilities.checkEmptySourceRegion(readP, readDimension))
- return null;
-
- if (LOGGER.isLoggable(Level.FINER))
- LOGGER.log(Level.FINER, "reading file: " + rasterURL);
-
- // read data
- return reader.read(imageIndex,readP);
- } catch (IOException e) {
- if (LOGGER.isLoggable(Level.WARNING))
- LOGGER.log(Level.WARNING,"Unable to compute source area for URL "
- + rasterURL,e);
- return null;
- } finally {
- //close everything
- try {
- // reader
- reader.dispose();
- } catch (Throwable t) {
- // swallow the exception, we are just trying to close as much stuff as possible
- }
-
- try {
- // instream
- inStream.close();
- } catch (Throwable t) {
- // swallow the exception, we are just trying to close as much stuff as possible
- }
- }
- }
+ }
},
JAI_IMAGEREAD{
- @Override
- RenderedImage read(
- final ImageReadParam readP,
- final int imageIndex,
- final URL rasterUrl,
- final Rectangle readDimension,
- final ImageReaderSpi spi,
- final Hints hints
- ) throws IOException{
-
- //check source regionepbjMosaic,
- if(CoverageUtilities.checkEmptySourceRegion(readP, readDimension))
- return null;
-
-
-
- // read data
-// final ParameterBlock pbjImageRead = new ParameterBlock();
-// pbjImageRead.add(Utils.getInputStream(rasterUrl));
-// pbjImageRead.add(imageIndex);
-// pbjImageRead.add(false);
-// pbjImageRead.add(false);
-// pbjImageRead.add(false);
-// pbjImageRead.add(null);
-// pbjImageRead.add(null);
-// pbjImageRead.add(readP);
-// pbjImageRead.add(spi.createReaderInstance());
- final RenderedOp raster;
-// if(tileDimension != null){
-// if (hints != null){
- //build a proper layout
-// final ImageLayout layout = new ImageLayout();
-// layout.setTileWidth(tileDimension.width).setTileHeight(tileDimension.height);
-// raster = JAI.create("ImageRead", pbjImageRead,new RenderingHints(JAI.KEY_IMAGE_LAYOUT,layout));
-// raster = JAI.create("ImageRead", pbjImageRead, hints);
- raster = ImageReadDescriptor.create(
- Utils.getInputStream(rasterUrl),
- imageIndex,
- false,
- false,
- false,
- null,
- null,
- readP,
- spi.createReaderInstance(),
- hints);
-// }
-// else
-// raster = JAI.create("ImageRead", pbjImageRead);
- //force rendering (a-la JAI)
- if (raster != null)
- raster.getWidth();
- return raster;
- }
-
@Override
RenderedImage read(
final ImageReadParam readParameters,
@@ -232,12 +121,30 @@
try{
//check source regionepbjMosaic,
- if(CoverageUtilities.checkEmptySourceRegion(readParameters, rasterDimensions))
- return null;
-
+ if(CoverageUtilities.checkEmptySourceRegion(readParameters, rasterDimensions)){
+ if (LOGGER.isLoggable(Level.WARNING))
+ LOGGER.warning("Provided an emptu source region to this read method ");
+ return null;
+ }
+
+ // checks on url
+ if(granuleUrl==null){
+ if (LOGGER.isLoggable(Level.WARNING))
+ LOGGER.warning("Provided a null URL to this read method ");
+ return null;
+ }
+
+ if(reader==null){
+ if (LOGGER.isLoggable(Level.WARNING))
+ LOGGER.warning("Unable to get reader for URL " + granuleUrl);
+ return null;
+ }
+
+ // check input stream
+ final ImageInputStream inStream=(ImageInputStream) reader.getInput();
// read data
final RenderedOp raster = ImageReadDescriptor.create(
- Utils.getInputStream(granuleUrl),
+ inStream,
imageIndex,
false,
false,
@@ -251,7 +158,7 @@
if (raster != null)
raster.getWidth();
return raster;
- }catch (IOException e) {
+ }catch (Exception e) {
if(LOGGER.isLoggable(Level.INFO))
LOGGER.log(Level.INFO,e.getLocalizedMessage(),e);
return null;
@@ -271,17 +178,6 @@
final boolean closeElements) {
throw new UnsupportedOperationException(Errors.format(ErrorKeys.UNSUPPORTED_OPERATION_$1,"read"));
}
- @Override
- RenderedImage read(
- final ImageReadParam readP,
- final int imageIndex,
- final URL rasterUrl,
- final Rectangle readDimension,
- final ImageReaderSpi spi,
- final Hints hints
- )throws IOException{
- throw new UnsupportedOperationException(Errors.format(ErrorKeys.UNSUPPORTED_OPERATION_$1,"read"));
- }
};
/** Logger. */
@@ -300,34 +196,23 @@
return JAI_IMAGEREAD;
}
- /**
- * Load the raster data from the underlying source with the specified read
- * type.
- *
- * @param readParameters
- * @param imageIndex
- * @param rasterUr...
[truncated message content] |
Author: bencaradocdavies
Date: 2012-01-22 19:46:30 -0800 (Sun, 22 Jan 2012)
New Revision: 38516
Modified:
trunk/modules/extension/app-schema/app-schema-resolver/src/main/java/org/geotools/xml/AppSchemaCache.java
trunk/modules/extension/app-schema/app-schema/src/main/java/org/geotools/data/complex/config/AppSchemaDataAccessConfigurator.java
Log:
Renamed methods used for cache automatic configuration
Modified: trunk/modules/extension/app-schema/app-schema/src/main/java/org/geotools/data/complex/config/AppSchemaDataAccessConfigurator.java
===================================================================
--- trunk/modules/extension/app-schema/app-schema/src/main/java/org/geotools/data/complex/config/AppSchemaDataAccessConfigurator.java 2012-01-22 19:51:32 UTC (rev 38515)
+++ trunk/modules/extension/app-schema/app-schema/src/main/java/org/geotools/data/complex/config/AppSchemaDataAccessConfigurator.java 2012-01-23 03:46:30 UTC (rev 38516)
@@ -583,7 +583,8 @@
*/
private AppSchemaCache buildCache() {
try {
- return AppSchemaCache.buildFromGeoserverUrl(new URL(config.getBaseSchemasUrl()));
+ return AppSchemaCache.buildAutomaticallyConfiguredUsingFileUrl(
+ new URL(config.getBaseSchemasUrl()));
} catch (MalformedURLException e) {
LOGGER.warning("Malformed mapping file URL: " + config.getBaseSchemasUrl() + " Detail: "
+ e.getMessage());
Modified: trunk/modules/extension/app-schema/app-schema-resolver/src/main/java/org/geotools/xml/AppSchemaCache.java
===================================================================
--- trunk/modules/extension/app-schema/app-schema-resolver/src/main/java/org/geotools/xml/AppSchemaCache.java 2012-01-22 19:51:32 UTC (rev 38515)
+++ trunk/modules/extension/app-schema/app-schema-resolver/src/main/java/org/geotools/xml/AppSchemaCache.java 2012-01-23 03:46:30 UTC (rev 38516)
@@ -2,7 +2,7 @@
* GeoTools - The Open Source Java GIS Toolkit
* http://geotools.org
*
- * (C) 2010-2011, Open Source Geospatial Foundation (OSGeo)
+ * (C) 2010-2012, Open Source Geospatial Foundation (OSGeo)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -51,9 +51,9 @@
* {@link AppSchemaResolver#getSimpleHttpResourcePath(URI))}.
*
* @author Ben Caradoc-Davies (CSIRO Earth Science and Resource Engineering)
- *
- *
- *
+ *
+ *
+ *
* @source $URL$
*/
public class AppSchemaCache {
@@ -67,27 +67,29 @@
private static final int DEFAULT_DOWNLOAD_BLOCK_SIZE = 4096;
/**
- * Filenames used to recognise a GeoServer data directory.
+ * Filenames used to recognise a GeoServer data directory if automatic configuration is enabled.
*/
private static final String[] GEOSERVER_DATA_DIRECTORY_FILENAMES = { "global.xml", "wcs.xml",
"wfs.xml", "wms.xml" };
/**
- * Subdirectories used to recognise a GeoServer data directory.
+ * Subdirectories used to recognise a GeoServer data directory if automatic configuration is
+ * enabled.
*/
private static final String[] GEOSERVER_DATA_DIRECTORY_SUBDIRECTORIES = { "styles",
"workspaces" };
/**
- * Name of the subdirectory of the GeoServer data directory used for the cache.
+ * Name of the subdirectory of a GeoServer data directory (or other directory) used for the
+ * cache if automatic configuration is enabled.
*/
- private static final String GEOSERVER_CACHE_DIRECTORY_NAME = "app-schema-cache";
+ private static final String CACHE_DIRECTORY_NAME = "app-schema-cache";
/**
- * Is support for automatic detection of GeoServer data directories enabled? It is useful to
- * disable this in tests, to prevent downloading.
+ * Is support for automatic detection of GeoServer data directories or existing cache
+ * directories enabled? It is useful to disable this in tests, to prevent downloading.
*/
- private static boolean geoserverSupportEnabled = true;
+ private static boolean automaticConfigurationEnabled = true;
/**
* Root directory of the cache.
@@ -306,15 +308,17 @@
}
/**
- * Search parents of url for a GeoServer data directory. If found, use it to create a cache in
- * the "app-schema-cache" subdirectory, with downloading enabled.
+ * If automatic configuration is enabled, recursively search parent directories of file url for
+ * a GeoServer data directory or directory containing an existing cache. If found, use it to
+ * create a cache in the "app-schema-cache" subdirectory with downloading enabled.
*
* @param url
* a URL for a file in a GeoServer data directory.
- * @return a cache in the "app-schema-cache" subdirectory
+ * @return a cache in the "app-schema-cache" subdirectory or null if not found or automatic
+ * configuration disabled.
*/
- public static AppSchemaCache buildFromGeoserverUrl(URL url) {
- if (!geoserverSupportEnabled) {
+ public static AppSchemaCache buildAutomaticallyConfiguredUsingFileUrl(URL url) {
+ if (!automaticConfigurationEnabled) {
return null;
}
File file = DataUtilities.urlToFile(url);
@@ -322,58 +326,63 @@
if (file == null) {
return null;
}
- if (isGeoserverDataDirectory(file)) {
- return new AppSchemaCache(new File(file, GEOSERVER_CACHE_DIRECTORY_NAME), true);
+ if (isSuitableDirectoryToContainCache(file)) {
+ return new AppSchemaCache(new File(file, CACHE_DIRECTORY_NAME), true);
}
file = file.getParentFile();
}
}
/**
- * Turn off support for automatic construction of a cache in GeoServer data directory. Intended
- * for testing.
+ * Turn off support for automatic configuration of a cache in GeoServer data directory or
+ * detection of an existing cache. Intended for testing. Automatic configuration is enabled by
+ * default.
*/
- public static void disableGeoserverSupport() {
- geoserverSupportEnabled = false;
+ public static void disableAutomaticConfiguration() {
+ automaticConfigurationEnabled = false;
}
/**
- * The opposite of {@link #disableGeoserverSupport()}
+ * The opposite of {@link #disableAutomaticConfiguration()}. Automatic configuration is enabled
+ * by default.
*/
- public static void enableGeoserverSupport() {
- geoserverSupportEnabled = true;
+ public static void enableAutomaticConfiguration() {
+ automaticConfigurationEnabled = true;
}
/**
- * @see #disableGeoserverSupport()
+ * Is automatic configuration enabled? Automatic configuration is enabled by default.
+ *
+ * @see #disableAutomaticConfiguration()
*/
- public static boolean isGeoserverSupportEnabled() {
- return geoserverSupportEnabled;
+ public static boolean isAutomaticConfigurationEnabled() {
+ return automaticConfigurationEnabled;
}
/**
- * Guess whether a file is a GeoServer data directory.
+ * Guess whether a file is a GeoServer data directory or contains an existing app-schema-cache
+ * subdirectory.
*
- * @param dataDirectory
+ * @param directory
* the candidate file
* @return true if it has the files and subdirectories expected of a GeoServer data directory,
* or contains an existing app-schema-cache subdirectory
*/
- static boolean isGeoserverDataDirectory(File dataDirectory) {
- if (dataDirectory.isDirectory() == false) {
+ static boolean isSuitableDirectoryToContainCache(File directory) {
+ if (directory.isDirectory() == false) {
return false;
}
- if ((new File(dataDirectory, GEOSERVER_CACHE_DIRECTORY_NAME)).isDirectory()) {
+ if ((new File(directory, CACHE_DIRECTORY_NAME)).isDirectory()) {
return true;
}
for (String filename : GEOSERVER_DATA_DIRECTORY_FILENAMES) {
- File file = new File(dataDirectory, filename);
+ File file = new File(directory, filename);
if (!file.isFile()) {
return false;
}
}
for (String subdirectory : GEOSERVER_DATA_DIRECTORY_SUBDIRECTORIES) {
- File dir = new File(dataDirectory, subdirectory);
+ File dir = new File(directory, subdirectory);
if (!dir.isDirectory()) {
return false;
}
|
|
From: <svn...@os...> - 2012-01-22 19:51:39
|
Author: simonegiannecchini
Date: 2012-01-22 11:51:32 -0800 (Sun, 22 Jan 2012)
New Revision: 38515
Modified:
branches/2.7.x/modules/plugin/imagemosaic/pom.xml
branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/Utils.java
branches/2.7.x/pom.xml
Log:
GEOT-2867
Modified: branches/2.7.x/modules/plugin/imagemosaic/pom.xml
===================================================================
--- branches/2.7.x/modules/plugin/imagemosaic/pom.xml 2012-01-22 19:44:30 UTC (rev 38514)
+++ branches/2.7.x/modules/plugin/imagemosaic/pom.xml 2012-01-22 19:51:32 UTC (rev 38515)
@@ -168,7 +168,6 @@
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
- <version>1.6.2</version>
</dependency>
<!-- Test dependencies -->
Modified: branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/Utils.java
===================================================================
--- branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/Utils.java 2012-01-22 19:44:30 UTC (rev 38514)
+++ branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/Utils.java 2012-01-22 19:51:32 UTC (rev 38515)
@@ -869,7 +869,6 @@
builder.append("isFile").append(file.isFile()).append("\n");
builder.append("canRead:").append(file.canRead()).append("\n");
builder.append("canWrite").append(file.canWrite()).append("\n");
- builder.append("canExecute:").append(file.canExecute()).append("\n");
builder.append("isAbsolute:").append(file.isAbsolute()).append("\n");
builder.append("lastModified:").append(file.lastModified()).append("\n");
builder.append("length:").append(file.length());
Modified: branches/2.7.x/pom.xml
===================================================================
--- branches/2.7.x/pom.xml 2012-01-22 19:44:30 UTC (rev 38514)
+++ branches/2.7.x/pom.xml 2012-01-22 19:51:32 UTC (rev 38515)
@@ -902,6 +902,12 @@
<version>2.6.0</version>
</dependency>
+ <!-- Other random non test dependencies -->
+ <dependency>
+ <groupId>net.sf.ehcache</groupId>
+ <artifactId>ehcache</artifactId>
+ <version>1.6.2</version>
+ </dependency>
<!-- Tests or legacy -->
<dependency>
<groupId>junit</groupId>
|
|
From: <svn...@os...> - 2012-01-22 19:44:37
|
Author: simonegiannecchini
Date: 2012-01-22 11:44:30 -0800 (Sun, 22 Jan 2012)
New Revision: 38514
Added:
branches/2.7.x/modules/plugin/imagemosaic/src/test/resources/org/geotools/gce/imagemosaic/test-data/watertemp.zip
Modified:
branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/RasterLayerRequest.java
branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/Utils.java
branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/catalogbuilder/CatalogBuilder.java
branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/catalogbuilder/CatalogBuilderConfiguration.java
branches/2.7.x/modules/plugin/imagemosaic/src/test/java/org/geotools/gce/imagemosaic/CatalogBuilderTest.java
branches/2.7.x/modules/plugin/imagemosaic/src/test/java/org/geotools/gce/imagemosaic/ImageMosaicReaderTest.java
Log:
GEOT-2867
Modified: branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/RasterLayerRequest.java
===================================================================
--- branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/RasterLayerRequest.java 2012-01-22 18:53:14 UTC (rev 38513)
+++ branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/RasterLayerRequest.java 2012-01-22 19:44:30 UTC (rev 38514)
@@ -81,7 +81,7 @@
/** The {@link BoundingBox} requested */
private BoundingBox requestedBBox;
-
+
/** The {@link BoundingBox} of the portion of the coverage that intersects the requested bbox */
private BoundingBox cropBBox;
Modified: branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/Utils.java
===================================================================
--- branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/Utils.java 2012-01-22 18:53:14 UTC (rev 38513)
+++ branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/Utils.java 2012-01-22 19:44:30 UTC (rev 38514)
@@ -1008,7 +1008,7 @@
sampleImageFile));
ooStream = new ObjectOutputStream(outStream);
sri = new SerializableRenderedImage(sampleImage, true);
- ooStream.writeObject(sri);
+ ooStream.writeObject(sri);
} finally {
try {
if (ooStream != null)
Modified: branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/catalogbuilder/CatalogBuilder.java
===================================================================
--- branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/catalogbuilder/CatalogBuilder.java 2012-01-22 18:53:14 UTC (rev 38513)
+++ branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/catalogbuilder/CatalogBuilder.java 2012-01-22 19:44:30 UTC (rev 38514)
@@ -51,6 +51,7 @@
import javax.imageio.ImageIO;
import javax.imageio.ImageReader;
import javax.imageio.ImageTypeSpecifier;
+import javax.imageio.spi.ImageInputStreamSpi;
import javax.imageio.spi.ImageReaderSpi;
import javax.imageio.stream.ImageInputStream;
import javax.swing.SwingUtilities;
@@ -86,6 +87,7 @@
import org.geotools.gce.imagemosaic.properties.PropertiesCollectorSPI;
import org.geotools.geometry.GeneralEnvelope;
import org.geotools.geometry.jts.ReferencedEnvelope;
+import org.geotools.image.io.ImageIOExt;
import org.geotools.referencing.CRS;
import org.geotools.resources.coverage.CoverageUtilities;
import org.geotools.util.Utilities;
@@ -117,8 +119,6 @@
/** Default Logger * */
final static Logger LOGGER = org.geotools.util.logging.Logging.getLogger(CatalogBuilder.class);
-
-
static abstract public class ProcessingEventListener implements EventListener {
abstract public void getNotification(final ProcessingEvent event);
@@ -327,23 +327,35 @@
// STEP 1
// Getting an ImageIO reader for this coverage.
//
- inStream = ImageIO.createImageInputStream(fileBeingProcessed);
- if(inStream==null) {
- fireEvent(Level.INFO,fileBeingProcessed+" has been skipped since we could not get a stream for it", ((fileIndex * 100.0) / numFiles));
- return;
- }
+ // try to use cache
+ if(cachedStreamSPI!=null ){
+ inStream=cachedStreamSPI.createInputStreamInstance(fileBeingProcessed);
+ }
+ if(inStream==null ){
+ // failed, look for a new SPI
+ cachedStreamSPI= ImageIOExt.getImageInputStreamSPI(fileBeingProcessed);
+ if(cachedStreamSPI!=null){
+ inStream=cachedStreamSPI.createInputStreamInstance(fileBeingProcessed);
+ }
+
+ }
+ if(inStream==null) {
+ // failed again
+ fireEvent(Level.INFO,fileBeingProcessed+" has been skipped since we could not get a stream for it", ((fileIndex * 100.0) / numFiles));
+ return;
+ }
inStream.mark();
- cachedSPITest: {
+ cachedReaderSPITest: {
// there is no cached reader spi, let's look for one
- if(cachedSPI==null){
+ if(cachedReaderSPI==null){
final Iterator<ImageReader> it = ImageIO.getImageReaders(inStream);
if (it.hasNext()) {
imageioReader = it.next();
if(imageioReader!=null){
//cache the SPI
- cachedSPI=imageioReader.getOriginatingProvider();
+ cachedReaderSPI=imageioReader.getOriginatingProvider();
imageioReader.setInput(inStream);
}
} else {
@@ -351,14 +363,14 @@
}
} else {
// we have a cached SPI, let's try to use it
- if(!cachedSPI.canDecodeInput(inStream)){
+ if(!cachedReaderSPI.canDecodeInput(inStream)){
// the SPI is no good for this input
- cachedSPI=null;
+ cachedReaderSPI=null;
//take me to the SPI search
- break cachedSPITest;
+ break cachedReaderSPITest;
}
// the spi is good
- imageioReader=cachedSPI.createReaderInstance();
+ imageioReader=cachedReaderSPI.createReaderInstance();
imageioReader.setInput(inStream);
}
}
@@ -877,8 +889,10 @@
private CatalogBuilderConfiguration runConfiguration;
- private ImageReaderSpi cachedSPI;
+ private ImageReaderSpi cachedReaderSPI;
+ private ImageInputStreamSpi cachedStreamSPI;
+
private List<PropertiesCollector> propertiesCollectors;
private SampleModel defaultSM;
@@ -1497,9 +1511,9 @@
properties.setProperty("ExpandToRGB", Boolean.toString(mustConvertToRGB));
properties.setProperty("Heterogeneous", Boolean.toString(mosaicConfiguration.isHeterogeneous()));
- if (cachedSPI != null){
+ if (cachedReaderSPI != null){
// suggested spi
- properties.setProperty("SuggestedSPI", cachedSPI.getClass().getName());
+ properties.setProperty("SuggestedSPI", cachedReaderSPI.getClass().getName());
}
// write down imposed bbox
Modified: branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/catalogbuilder/CatalogBuilderConfiguration.java
===================================================================
--- branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/catalogbuilder/CatalogBuilderConfiguration.java 2012-01-22 18:53:14 UTC (rev 38513)
+++ branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/catalogbuilder/CatalogBuilderConfiguration.java 2012-01-22 19:44:30 UTC (rev 38514)
@@ -241,6 +241,7 @@
public void setRootMosaicDirectory(final String rootMosaicDirectory) {
Utilities.ensureNonNull("rootMosaicDirectory", rootMosaicDirectory);
String testingDirectory = rootMosaicDirectory;
+ Utils.checkDirectory(testingDirectory,false);
this.rootMosaicDirectory = testingDirectory;
}
Modified: branches/2.7.x/modules/plugin/imagemosaic/src/test/java/org/geotools/gce/imagemosaic/CatalogBuilderTest.java
===================================================================
--- branches/2.7.x/modules/plugin/imagemosaic/src/test/java/org/geotools/gce/imagemosaic/CatalogBuilderTest.java 2012-01-22 18:53:14 UTC (rev 38513)
+++ branches/2.7.x/modules/plugin/imagemosaic/src/test/java/org/geotools/gce/imagemosaic/CatalogBuilderTest.java 2012-01-22 19:44:30 UTC (rev 38514)
@@ -23,6 +23,7 @@
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
+import java.net.InetAddress;
import java.util.Arrays;
import java.util.Properties;
@@ -35,13 +36,14 @@
import org.geotools.coverage.grid.io.AbstractGridFormat;
import org.geotools.gce.imagemosaic.catalog.GranuleCatalog;
import org.geotools.gce.imagemosaic.catalogbuilder.CatalogBuilder;
-import org.geotools.gce.imagemosaic.catalogbuilder.CatalogBuilderConfiguration;
import org.geotools.gce.imagemosaic.catalogbuilder.CatalogBuilder.ExceptionEvent;
import org.geotools.gce.imagemosaic.catalogbuilder.CatalogBuilder.ProcessingEvent;
import org.geotools.gce.imagemosaic.catalogbuilder.CatalogBuilder.ProcessingEventListener;
+import org.geotools.gce.imagemosaic.catalogbuilder.CatalogBuilderConfiguration;
import org.geotools.geometry.GeneralEnvelope;
import org.geotools.test.TestData;
import org.junit.Assert;
+import org.junit.Before;
import org.junit.Test;
import org.opengis.parameter.GeneralParameterValue;
import org.opengis.parameter.ParameterValue;
@@ -55,6 +57,19 @@
* @source $URL: http://svn.osgeo.org/geotools/branches/2.7.x/build/maven/javadoc/../../../modules/plugin/imagemosaic/src/test/java/org/geotools/gce/imagemosaic/CatalogBuilderTest.java $
*/
public class CatalogBuilderTest extends Assert {
+
+ /** Used to avoid errors if building on a system where hostname is not defined */
+ private boolean hostnameDefined;
+
+ @Before
+ public void setup() {
+ try {
+ InetAddress.getLocalHost();
+ hostnameDefined = true;
+ } catch (Exception ex) {
+ hostnameDefined = false;
+ }
+ }
private final class CatalogBuilderListener extends ProcessingEventListener{
@@ -72,7 +87,7 @@
}
@Test
- public void catalogBuilderConfiguration() throws FileNotFoundException, IOException, CloneNotSupportedException{
+ public void catalogBuilderConfiguration() throws Exception{
// create a stub configuration
final CatalogBuilderConfiguration c1= new CatalogBuilderConfiguration();
c1.setIndexName("index");
@@ -102,8 +117,9 @@
}
- @Test
- public void buildCatalog() throws FileNotFoundException, IOException{
+ @Test
+ public void buildCatalog() throws FileNotFoundException, IOException{
+ if (hostnameDefined){
CatalogBuilder builder = null;
ImageMosaicReader reader = null;
ParameterValue<GridGeometry2D> gg = null;
@@ -228,14 +244,16 @@
PlanarImage.wrapRenderedImage( coverage.getRenderedImage()).getTiles();
- // dispose
- coverage.dispose(true);
- reader.dispose();
+ // dispose
+ coverage.dispose(true);
+ reader.dispose();
+ }
}
@Test
public void buildCachingIndex() throws FileNotFoundException, IOException {
+ if (hostnameDefined){
CatalogBuilder builder = null;
ImageMosaicReader reader = null;
FileInputStream inStream = null;
@@ -324,6 +342,6 @@
//Eat exception
}
}
-
+ }
}
}
Modified: branches/2.7.x/modules/plugin/imagemosaic/src/test/java/org/geotools/gce/imagemosaic/ImageMosaicReaderTest.java
===================================================================
--- branches/2.7.x/modules/plugin/imagemosaic/src/test/java/org/geotools/gce/imagemosaic/ImageMosaicReaderTest.java 2012-01-22 18:53:14 UTC (rev 38513)
+++ branches/2.7.x/modules/plugin/imagemosaic/src/test/java/org/geotools/gce/imagemosaic/ImageMosaicReaderTest.java 2012-01-22 19:44:30 UTC (rev 38514)
@@ -338,6 +338,44 @@
"Time-Elevation Test");
}
+ /**
+ *
+ * @throws IOException
+ * @throws ParseException
+ * @throws FactoryException
+ * @throws NoSuchAuthorityCodeException
+ * @throws MismatchedDimensionException
+ * @throws NoSuchAuthorityCodeException
+ */
+ @Test
+ public void timeIntegerElevation() throws IOException, ParseException, NoSuchAuthorityCodeException, FactoryException {
+ // Check we can have an integer elevation too
+ TestData.unzipFile(this, "watertemp.zip");
+ final URL timeElevURL = TestData.url(this, "watertemp");
+ System.setProperty("org.geotools.shapefile.datetime", "true");
+ final AbstractGridFormat format = getFormat(timeElevURL);
+ assertNotNull(format);
+ ImageMosaicReader reader = getReader(timeElevURL, format);
+ assertNotNull(format);
+
+ final String[] metadataNames = reader.getMetadataNames();
+ assertNotNull(metadataNames);
+ assertEquals(metadataNames.length,10);
+
+ assertEquals("true", reader.getMetadataValue("HAS_TIME_DOMAIN"));
+ final String timeMetadata = reader.getMetadataValue("TIME_DOMAIN");
+ assertNotNull(timeMetadata);
+ assertEquals(2,timeMetadata.split(",").length);
+ assertEquals(timeMetadata.split(",")[0],reader.getMetadataValue("TIME_DOMAIN_MINIMUM"));
+ assertEquals(timeMetadata.split(",")[1],reader.getMetadataValue("TIME_DOMAIN_MAXIMUM"));
+
+ assertEquals("true", reader.getMetadataValue("HAS_ELEVATION_DOMAIN"));
+ final String elevationMetadata = reader.getMetadataValue("ELEVATION_DOMAIN");
+ assertNotNull(elevationMetadata);
+ assertEquals(2,elevationMetadata.split(",").length);
+ assertEquals("0",reader.getMetadataValue("ELEVATION_DOMAIN_MINIMUM"));
+ assertEquals("100",reader.getMetadataValue("ELEVATION_DOMAIN_MAXIMUM"));
+ }
@Test
// @Ignore
Added: branches/2.7.x/modules/plugin/imagemosaic/src/test/resources/org/geotools/gce/imagemosaic/test-data/watertemp.zip
===================================================================
(Binary files differ)
Property changes on: branches/2.7.x/modules/plugin/imagemosaic/src/test/resources/org/geotools/gce/imagemosaic/test-data/watertemp.zip
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
|
|
From: <svn...@os...> - 2012-01-22 18:53:22
|
Author: simonegiannecchini
Date: 2012-01-22 10:53:14 -0800 (Sun, 22 Jan 2012)
New Revision: 38513
Modified:
branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/GranuleLoader.java
branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/ImageMosaicReader.java
branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/RasterLayerResponse.java
branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/RasterManager.java
branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/Utils.java
Log:
GEOT-2867
Modified: branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/GranuleLoader.java
===================================================================
--- branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/GranuleLoader.java 2012-01-22 18:12:06 UTC (rev 38512)
+++ branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/GranuleLoader.java 2012-01-22 18:53:14 UTC (rev 38513)
@@ -31,9 +31,11 @@
import org.opengis.referencing.operation.MathTransform2D;
/**
+ * Specific {@link Callable} implementation that can be used to load the result of a request on a
+ * single {@link GranuleDescriptor} via {@link GranuleLoadingResult}.
*
* @author Simone Giannecchini, GeoSolutions SAS
- *
+ *
*/
class GranuleLoader implements Callable<GranuleLoadingResult>{
Modified: branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/ImageMosaicReader.java
===================================================================
--- branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/ImageMosaicReader.java 2012-01-22 18:12:06 UTC (rev 38512)
+++ branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/ImageMosaicReader.java 2012-01-22 18:53:14 UTC (rev 38513)
@@ -109,7 +109,7 @@
*/
public final class ImageMosaicReader extends AbstractGridCoverage2DReader implements GridCoverageReader, GridCoverageWriter {
- /** Logger. */
+ /** Logger. */
private final static Logger LOGGER = org.geotools.util.logging.Logging.getLogger(ImageMosaicReader.class);
/**
@@ -783,54 +783,7 @@
}
-// final boolean getRuntimeAttribute=name.equalsIgnoreCase("runtime_domain");
-// if(getRuntimeAttribute){
-// Query query;
-// try {
-// query = new DefaultQuery(rasterManager.granuleCatalog.getType().getTypeName());
-// query.setPropertyNames(Arrays.asList("runtime"));
-// final SortBy[] sortBy=new SortBy[]{
-// new SortByImpl(
-// FeatureUtilities.DEFAULT_FILTER_FACTORY.property("runtime"),
-// SortOrder.DESCENDING
-// )};
-// if(queryCapabilities.supportsSorting(sortBy))
-// query.setSortBy(sortBy);
-//// else
-//// manualSort=true;
-// final UniqueVisitor visitor= new UniqueVisitor("runtime");
-// rasterManager.granuleCatalog.computeAggregateFunction(query, visitor);
-//
-// // check result
-// final Set<Integer> result = new TreeSet<Integer>(new Comparator<Integer>() {
-//
-// public int compare(Integer o1, Integer o2) {
-// // Revert Order
-// if (o1 > 02)
-// return -1;
-// else if (o1 < o2)
-// return 1;
-// return 0;
-// }
-// });
-// result.addAll(visitor.getUnique());
-// if(result.size()<=0)
-// return null;
-// final StringBuilder buff= new StringBuilder();
-// for(Iterator<Integer> it=result.iterator();it.hasNext();){
-// final int value= it.next();
-// buff.append(value);
-// if(it.hasNext())
-// buff.append(",");
-// }
-// return buff.toString();
-// } catch (IOException e) {
-// if(LOGGER.isLoggable(Level.WARNING))
-// LOGGER.log(Level.WARNING,"Unable to parse attribute:"+name,e);
-// }
-//
-// }
-//
+
return super.getMetadataValue(name);
}
@@ -897,8 +850,12 @@
final FeatureCalc visitor = createExtremaQuery(metadataName,rasterManager.elevationAttribute);
// check result
- final Double result=(Double) visitor.getResult().getValue();
- return Double.toString(result);
+ final Object result = visitor.getResult().getValue();
+ if(result instanceof Number) {
+ return result.toString();
+ } else {
+ return null;
+ }
} catch (IOException e) {
if(LOGGER.isLoggable(Level.WARNING))
LOGGER.log(Level.WARNING,"Unable to compute extrema for ELEVATION_DOMAIN",e);
@@ -917,14 +874,14 @@
return null;
}
try {
- final Set<Double> result = extractDomain(elevationAttribute);
+ final Set<Number> result = extractDomain(elevationAttribute);
// check result
if(result.size()<=0)
- return null;
+ return "";
final StringBuilder buff= new StringBuilder();
- for(Iterator<Double> it=result.iterator();it.hasNext();){
- final double value= (Double) it.next();
+ for(Iterator<Number> it= result.iterator(); it.hasNext();){
+ final double value= ((Number) it.next()).doubleValue();
buff.append(value);
if(it.hasNext())
buff.append(",");
@@ -933,7 +890,7 @@
} catch (IOException e) {
if(LOGGER.isLoggable(Level.WARNING))
LOGGER.log(Level.WARNING,"Unable to parse attribute: ELEVATION_DOMAIN",e);
- return null;
+ return "";
}
}
Modified: branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/RasterLayerResponse.java
===================================================================
--- branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/RasterLayerResponse.java 2012-01-22 18:12:06 UTC (rev 38512)
+++ branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/RasterLayerResponse.java 2012-01-22 18:53:14 UTC (rev 38513)
@@ -242,10 +242,8 @@
* My specific {@link MaxVisitor} that keeps track of the feature used for the maximum.
* @author Simone Giannecchini, GeoSolutions SAS
*
- *
- * @source $URL: http://svn.osgeo.org/geotools/branches/2.7.x/build/maven/javadoc/../../../modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/RasterLayerResponse.java $
*/
- public static class MaxVisitor2 extends MaxVisitor{
+ static class MaxVisitor2 extends MaxVisitor{
private Comparable oldValue;
private int oldNanCount;
@@ -327,8 +325,18 @@
*
*/
class MosaicBuilder implements GranuleCatalogVisitor{
- private final int maxNumberOfGranules;
+ /**
+ * Default {@link Constructor}
+ */
+ public MosaicBuilder(final RasterLayerRequest request) {
+ this.request=request;
+ maxNumberOfGranules=request.getMaximumNumberOfGranules();
+ }
+
+ private final int maxNumberOfGranules;
+
+
private final List<Future<GranuleLoadingResult>> tasks= new ArrayList<Future<GranuleLoadingResult>>();
private int granulesNumber;
private List<ROI> rois = new ArrayList<ROI>();
@@ -344,14 +352,6 @@
private List<RenderedImage> sources = new ArrayList<RenderedImage>();
-
- /**
- * Default {@link Constructor}
- */
- public MosaicBuilder(final RasterLayerRequest request) {
- this.request=request;
- maxNumberOfGranules=request.getMaximumNumberOfGranules();
- }
public RenderedImage[] getSourcesAsArray() {
RenderedImage []imageSources = new RenderedImage[sources.size()];
@@ -701,12 +701,11 @@
// assemble granules
final RenderedImage mosaic = prepareResponse();
-
//postproc
RenderedImage finalRaster = postProcessRaster(mosaic);
-
//create the coverage
gridCoverage = prepareCoverage(finalRaster);
+
}
@@ -1316,115 +1315,115 @@
return new Rectangle2D.Double(minx, miny, maxx - minx, maxy - miny).getBounds();
}
- /**
- * This method is responsible for creating a coverage from the supplied {@link RenderedImage}.
- *
- * @param image
- * @return
- * @throws IOException
- */
- private GridCoverage2D prepareCoverage(RenderedImage image) throws IOException {
-
- // creating bands
+ /**
+ * This method is responsible for creating a coverage from the supplied {@link RenderedImage}.
+ *
+ * @param image
+ * @return
+ * @throws IOException
+ */
+ private GridCoverage2D prepareCoverage(RenderedImage image) throws IOException {
+
+ // creating bands
final SampleModel sm=image.getSampleModel();
final ColorModel cm=image.getColorModel();
- final int numBands = sm.getNumBands();
- final GridSampleDimension[] bands = new GridSampleDimension[numBands];
- Set<String> bandNames = new HashSet<String>();
- // setting bands names.
- for (int i = 0; i < numBands; i++) {
- // color interpretation
- final ColorInterpretation colorInterpretation=TypeMap.getColorInterpretation(cm, i);
- if(colorInterpretation==null)
- throw new IOException("Unrecognized sample dimension type");
+ final int numBands = sm.getNumBands();
+ final GridSampleDimension[] bands = new GridSampleDimension[numBands];
+ Set<String> bandNames = new HashSet<String>();
+ // setting bands names.
+ for (int i = 0; i < numBands; i++) {
+ // color interpretation
+ final ColorInterpretation colorInterpretation=TypeMap.getColorInterpretation(cm, i);
+ if(colorInterpretation==null)
+ throw new IOException("Unrecognized sample dimension type");
// make sure we create no duplicate band names
- String bandName = colorInterpretation.name();
+ String bandName = colorInterpretation.name();
if(colorInterpretation == ColorInterpretation.UNDEFINED || bandNames.contains(bandName)) {
bandName = "Band" + (i + 1);
- }
-
- // sample dimension type
- final SampleDimensionType st=TypeMap.getSampleDimensionType(sm, i);
-
- // set some no data values, as well as Min and Max values
- final double noData;
- double min=-Double.MAX_VALUE,max=Double.MAX_VALUE;
- if(backgroundValues!=null)
- {
- // sometimes background values are not specified as 1 per each band, therefore we need to be careful
- noData= backgroundValues[backgroundValues.length > i ? i:0];
- }
- else
- {
- if(st.compareTo(SampleDimensionType.REAL_32BITS)==0)
- noData= Float.NaN;
- else
- if(st.compareTo(SampleDimensionType.REAL_64BITS)==0)
- noData= Double.NaN;
- else
- if(st.compareTo(SampleDimensionType.SIGNED_16BITS)==0)
- {
- noData=Short.MIN_VALUE;
- min=Short.MIN_VALUE;
- max=Short.MAX_VALUE;
- }
- else
- if(st.compareTo(SampleDimensionType.SIGNED_32BITS)==0)
- {
- noData= Integer.MIN_VALUE;
+ }
+
+ // sample dimension type
+ final SampleDimensionType st=TypeMap.getSampleDimensionType(sm, i);
+
+ // set some no data values, as well as Min and Max values
+ final double noData;
+ double min=-Double.MAX_VALUE,max=Double.MAX_VALUE;
+ if(backgroundValues!=null)
+ {
+ // sometimes background values are not specified as 1 per each band, therefore we need to be careful
+ noData= backgroundValues[backgroundValues.length > i ? i:0];
+ }
+ else
+ {
+ if(st.compareTo(SampleDimensionType.REAL_32BITS)==0)
+ noData= Float.NaN;
+ else
+ if(st.compareTo(SampleDimensionType.REAL_64BITS)==0)
+ noData= Double.NaN;
+ else
+ if(st.compareTo(SampleDimensionType.SIGNED_16BITS)==0)
+ {
+ noData=Short.MIN_VALUE;
+ min=Short.MIN_VALUE;
+ max=Short.MAX_VALUE;
+ }
+ else
+ if(st.compareTo(SampleDimensionType.SIGNED_32BITS)==0)
+ {
+ noData= Integer.MIN_VALUE;
- min=Integer.MIN_VALUE;
- max=Integer.MAX_VALUE;
- }
- else
- if(st.compareTo(SampleDimensionType.SIGNED_8BITS)==0)
- {
- noData= -128;
- min=-128;
- max=127;
- }
- else
- {
- //unsigned
- noData= 0;
- min=0;
-
-
- // compute max
- if(st.compareTo(SampleDimensionType.UNSIGNED_1BIT)==0)
- max=1;
- else
- if(st.compareTo(SampleDimensionType.UNSIGNED_2BITS)==0)
- max=3;
- else
- if(st.compareTo(SampleDimensionType.UNSIGNED_4BITS)==0)
- max=7;
- else
- if(st.compareTo(SampleDimensionType.UNSIGNED_8BITS)==0)
- max=255;
- else
- if(st.compareTo(SampleDimensionType.UNSIGNED_16BITS)==0)
- max=65535;
- else
- if(st.compareTo(SampleDimensionType.UNSIGNED_32BITS)==0)
- max=Math.pow(2, 32)-1;
-
- }
-
-
- }
- bands[i] = new SimplifiedGridSampleDimension(
- bandName,
- st,
- colorInterpretation,
- noData,
- min,
- max,
- 1, //no scale
- 0, //no offset
- null
- ).geophysics(true);
- }
+ min=Integer.MIN_VALUE;
+ max=Integer.MAX_VALUE;
+ }
+ else
+ if(st.compareTo(SampleDimensionType.SIGNED_8BITS)==0)
+ {
+ noData= -128;
+ min=-128;
+ max=127;
+ }
+ else
+ {
+ //unsigned
+ noData= 0;
+ min=0;
+
+
+ // compute max
+ if(st.compareTo(SampleDimensionType.UNSIGNED_1BIT)==0)
+ max=1;
+ else
+ if(st.compareTo(SampleDimensionType.UNSIGNED_2BITS)==0)
+ max=3;
+ else
+ if(st.compareTo(SampleDimensionType.UNSIGNED_4BITS)==0)
+ max=7;
+ else
+ if(st.compareTo(SampleDimensionType.UNSIGNED_8BITS)==0)
+ max=255;
+ else
+ if(st.compareTo(SampleDimensionType.UNSIGNED_16BITS)==0)
+ max=65535;
+ else
+ if(st.compareTo(SampleDimensionType.UNSIGNED_32BITS)==0)
+ max=Math.pow(2, 32)-1;
+
+ }
+
+
+ }
+ bands[i] = new SimplifiedGridSampleDimension(
+ bandName,
+ st,
+ colorInterpretation,
+ noData,
+ min,
+ max,
+ 1, //no scale
+ 0, //no offset
+ null
+ ).geophysics(true);
+ }
return coverageFactory.create(
rasterManager.getCoverageIdentifier(),
@@ -1437,8 +1436,8 @@
hints),
bands,
null,
- null);
+ null);
- }
+ }
}
Modified: branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/RasterManager.java
===================================================================
--- branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/RasterManager.java 2012-01-22 18:12:06 UTC (rev 38512)
+++ branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/RasterManager.java 2012-01-22 18:53:14 UTC (rev 38513)
@@ -134,7 +134,7 @@
// basic initialization
//
coverageGeographicBBox = Utils.getWGS84ReferencedEnvelope(coverageEnvelope);
- coverageGeographicCRS2D = coverageGeographicBBox==null?coverageGeographicBBox.getCoordinateReferenceSystem():null;
+ coverageGeographicCRS2D = coverageGeographicBBox!=null?coverageGeographicBBox.getCoordinateReferenceSystem():null;
//
// Get the original envelope 2d and its spatial reference system
Modified: branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/Utils.java
===================================================================
--- branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/Utils.java 2012-01-22 18:12:06 UTC (rev 38512)
+++ branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/Utils.java 2012-01-22 18:53:14 UTC (rev 38513)
@@ -103,11 +103,12 @@
* @source $URL: http://svn.osgeo.org/geotools/branches/2.7.x/build/maven/javadoc/../../../modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/Utils.java $
*/
public class Utils {
+
+ public final static String INDEXER_PROPERTIES = "indexer.properties";
/** EHCache instance to cache histograms */
private static Cache ehcache;
- public final static String INDEXER_PROPERTIES = "indexer.properties";
/** RGB to GRAY coefficients (for Luminance computation) */
public final static double RGB_TO_GRAY_MATRIX [][]= {{ 0.114, 0.587, 0.299, 0 }};
|
|
From: <svn...@os...> - 2012-01-22 18:12:13
|
Author: simonegiannecchini
Date: 2012-01-22 10:12:06 -0800 (Sun, 22 Jan 2012)
New Revision: 38512
Modified:
branches/2.7.x/modules/plugin/imagepyramid/src/main/java/org/geotools/gce/imagepyramid/Utils.java
branches/2.7.x/pom.xml
Log:
GEOT-2867
Modified: branches/2.7.x/modules/plugin/imagepyramid/src/main/java/org/geotools/gce/imagepyramid/Utils.java
===================================================================
--- branches/2.7.x/modules/plugin/imagepyramid/src/main/java/org/geotools/gce/imagepyramid/Utils.java 2012-01-22 17:32:30 UTC (rev 38511)
+++ branches/2.7.x/modules/plugin/imagepyramid/src/main/java/org/geotools/gce/imagepyramid/Utils.java 2012-01-22 18:12:06 UTC (rev 38512)
@@ -162,8 +162,8 @@
if(LOGGER.isLoggable(Level.FINE)){
LOGGER.fine("Created '0' subidr, now moving files");
}
- FileFilter notDirFilter = FileFilterUtils.notFileFilter(directoryFilter);
- for (File f : directory.listFiles(notDirFilter)) {
+ FileFilter zeroLevelsFiles = FileFilterUtils.makeSVNAware(FileFilterUtils.makeCVSAware(FileFilterUtils.notFileFilter(directoryFilter)));
+ for (File f : directory.listFiles(zeroLevelsFiles)) {
if(LOGGER.isLoggable(Level.FINE)){
LOGGER.fine("Moving file"+f.getAbsolutePath());
}
Modified: branches/2.7.x/pom.xml
===================================================================
--- branches/2.7.x/pom.xml 2012-01-22 17:32:30 UTC (rev 38511)
+++ branches/2.7.x/pom.xml 2012-01-22 18:12:06 UTC (rev 38512)
@@ -630,7 +630,12 @@
<artifactId>imageio-ext-utilities</artifactId>
<version>${imageio.ext.version}</version>
</dependency>
-
+ <dependency>
+ <groupId>it.geosolutions.imageio-ext</groupId>
+ <artifactId>imageio-ext-streams</artifactId>
+ <version>${imageio.ext.version}</version>
+ </dependency>
+
<!-- JAITools -->
<dependency>
<groupId>com.googlecode.jaitools</groupId>
@@ -1297,8 +1302,15 @@
<name>Java.net repository</name>
<url>http://download.java.net/maven/2</url>
</repository>
+
<repository>
+ <id>geosolutions</id>
+ <name>geosolutions repository</name>
+ <url>http://maven.geo-solutions.it/</url>
+ </repository>
+
+ <repository>
<id>osgeo</id>
<name>Open Source Geospatial Foundation Repository</name>
<url>http://download.osgeo.org/webdav/geotools/</url>
|
|
From: <svn...@os...> - 2012-01-22 17:32:42
|
Author: simonegiannecchini
Date: 2012-01-22 09:32:30 -0800 (Sun, 22 Jan 2012)
New Revision: 38511
Modified:
branches/2.7.x/modules/plugin/imagemosaic/pom.xml
branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/GranuleDescriptor.java
branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/ImageMosaicFormat.java
branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/ImageMosaicFormatFactory.java
branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/ImageMosaicReader.java
branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/MosaicConfigurationBean.java
branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/PathType.java
branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/RasterLayerRequest.java
branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/RasterLayerResponse.java
branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/RasterManager.java
branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/ReadType.java
branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/Utils.java
branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/catalog/AbstractGranuleCatalog.java
branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/catalog/GTDataStoreGranuleCatalog.java
branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/catalog/GranuleCatalogFactory.java
branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/catalog/GranuleCatalogVisitor.java
branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/catalog/STRTreeGranuleCatalog.java
branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/catalogbuilder/CatalogBuilder.java
branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/catalogbuilder/CatalogBuilderConfiguration.java
branches/2.7.x/modules/plugin/imagemosaic/src/test/java/org/geotools/gce/imagemosaic/CatalogBuilderTest.java
Log:
GEOT-2867
Modified: branches/2.7.x/modules/plugin/imagemosaic/pom.xml
===================================================================
--- branches/2.7.x/modules/plugin/imagemosaic/pom.xml 2012-01-21 14:19:53 UTC (rev 38510)
+++ branches/2.7.x/modules/plugin/imagemosaic/pom.xml 2012-01-22 17:32:30 UTC (rev 38511)
@@ -139,22 +139,16 @@
<version>${project.version}</version>
</dependency>
<dependency>
- <groupId>org.geotools</groupId>
- <artifactId>gt-image</artifactId>
- <version>${project.version}</version>
+ <groupId>it.geosolutions.imageio-ext</groupId>
+ <artifactId>imageio-ext-streams</artifactId>
</dependency>
<dependency>
<groupId>org.geotools</groupId>
- <artifactId>gt-imageio-ext-gdal</artifactId>
+ <artifactId>gt-image</artifactId>
<version>${project.version}</version>
- </dependency>
+ </dependency>
<dependency>
<groupId>org.geotools</groupId>
- <artifactId>gt-jp2k</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.geotools</groupId>
<artifactId>gt-cql</artifactId>
<version>${project.version}</version>
<scope>test</scope>
Modified: branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/GranuleDescriptor.java
===================================================================
--- branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/GranuleDescriptor.java 2012-01-21 14:19:53 UTC (rev 38510)
+++ branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/GranuleDescriptor.java 2012-01-22 17:32:30 UTC (rev 38511)
@@ -17,7 +17,6 @@
package org.geotools.gce.imagemosaic;
import it.geosolutions.imageio.utilities.ImageIOUtilities;
-import it.geosolutions.imageio.utilities.Utilities;
import jaitools.imageutils.ROIGeometry;
import jaitools.media.jai.vectorbinarize.VectorBinarizeDescriptor;
import jaitools.media.jai.vectorbinarize.VectorBinarizeRIF;
@@ -38,8 +37,10 @@
import java.util.logging.Level;
import java.util.logging.Logger;
+import javax.imageio.ImageIO;
import javax.imageio.ImageReadParam;
import javax.imageio.ImageReader;
+import javax.imageio.spi.ImageInputStreamSpi;
import javax.imageio.spi.ImageReaderSpi;
import javax.imageio.stream.ImageInputStream;
import javax.media.jai.BorderExtender;
@@ -59,6 +60,7 @@
import org.geotools.geometry.jts.JTS;
import org.geotools.geometry.jts.ReferencedEnvelope;
import org.geotools.image.ImageWorker;
+import org.geotools.image.io.ImageIOExt;
import org.geotools.image.jai.Registry;
import org.geotools.referencing.CRS;
import org.geotools.referencing.operation.builder.GridToEnvelopeMapper;
@@ -264,9 +266,12 @@
ImageReaderSpi cachedReaderSPI;
SimpleFeature originator;
+
boolean handleArtifactsFiltering = false;
boolean filterMe = false;
+
+ ImageInputStreamSpi cachedStreamSPI;
private void init(final BoundingBox granuleBBOX, final URL granuleUrl,
final ImageReaderSpi suggestedSPI, final Geometry inclusionGeometry,
@@ -293,9 +298,29 @@
//
// get a stream
- inStream = Utils.getInputStream(granuleUrl);
- if(inStream == null)
- throw new IllegalArgumentException("Unable to get an input stream for the provided file "+granuleUrl.toString());
+ if(cachedStreamSPI==null){
+ cachedStreamSPI=ImageIOExt.getImageInputStreamSPI(granuleUrl, true);
+ if(cachedStreamSPI==null){
+ final File file = DataUtilities.urlToFile(granuleUrl);
+ if(file!=null){
+ if(LOGGER.isLoggable(Level.WARNING)){
+ LOGGER.log(Level.WARNING,Utils.getFileInfo(file));
+ }
+ }
+ throw new IllegalArgumentException("Unable to get an input stream for the provided granule "+granuleUrl.toString());
+ }
+ }
+ assert cachedStreamSPI!=null:"no cachedStreamSPI available!";
+ inStream = cachedStreamSPI.createInputStreamInstance(granuleUrl, ImageIO.getUseCache(), ImageIO.getCacheDirectory());
+ if(inStream == null){
+ final File file = DataUtilities.urlToFile(granuleUrl);
+ if(file!=null){
+ if(LOGGER.isLoggable(Level.WARNING)){
+ LOGGER.log(Level.WARNING,Utils.getFileInfo(file));
+ }
+ }
+ throw new IllegalArgumentException("Unable to get an input stream for the provided file "+granuleUrl.toString());
+ }
// get a reader and try to cache the suggested SPI first
if(cachedReaderSPI == null){
@@ -595,7 +620,8 @@
//
// get a stream
- inStream = Utils.getInputStream(granuleUrl);
+ assert cachedStreamSPI!=null:"no cachedStreamSPI available!";
+ inStream = cachedStreamSPI.createInputStreamInstance(granuleUrl, ImageIO.getUseCache(), ImageIO.getCacheDirectory());
if(inStream==null)
return null;
@@ -678,7 +704,7 @@
if (pluginName != null && pluginName.equals(ImageUtilities.DIRECT_KAKADU_PLUGIN)){
final int ssx = readParameters.getSourceXSubsampling();
final int ssy = readParameters.getSourceYSubsampling();
- newSubSamplingFactor = Utilities.getSubSamplingFactor2(ssx, ssy);
+ newSubSamplingFactor = ImageIOUtilities.getSubSamplingFactor2(ssx, ssy);
if (newSubSamplingFactor != 0) {
if (newSubSamplingFactor > maxDecimationFactor && maxDecimationFactor != -1){
newSubSamplingFactor = maxDecimationFactor;
@@ -887,7 +913,7 @@
} finally {
try {
- if (inStream != null) {
+ if (request.getReadType() != ReadType.JAI_IMAGEREAD && inStream != null) {
inStream.close();
}
} finally {
@@ -951,7 +977,8 @@
try {
// get a stream
- inStream = Utils.getInputStream(granuleUrl);
+ assert cachedStreamSPI!=null:"no cachedStreamSPI available!";
+ inStream = cachedStreamSPI.createInputStreamInstance(granuleUrl, ImageIO.getUseCache(), ImageIO.getCacheDirectory());
if(inStream==null)
throw new IllegalArgumentException("Unable to create an inputstream for the granuleurl:"+(granuleUrl!=null?granuleUrl:"null"));
Modified: branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/ImageMosaicFormat.java
===================================================================
--- branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/ImageMosaicFormat.java 2012-01-21 14:19:53 UTC (rev 38510)
+++ branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/ImageMosaicFormat.java 2012-01-22 17:32:30 UTC (rev 38511)
@@ -101,6 +101,7 @@
*
* @source $URL$
*/
+@SuppressWarnings("rawtypes")
public final class ImageMosaicFormat extends AbstractGridFormat implements Format {
final static double DEFAULT_ARTIFACTS_FILTER_PTILE_THRESHOLD = 0.1;
@@ -264,6 +265,7 @@
return true;
}
+ @SuppressWarnings("unchecked")
private boolean checkForUrl( Object source, Hints hints){
try {
@@ -277,12 +279,11 @@
return false; // file does not exist
}
}
- // /////////////////////////////////////////////////////////////////////
+
//
// Load tiles informations, especially the bounds, which will be
// reused
//
- // /////////////////////////////////////////////////////////////////////
DataStore tileIndexStore = null;
CoordinateReferenceSystem crs=null;
boolean shapefile=true;
@@ -357,11 +358,9 @@
if(crs==null)
return false;
- // /////////////////////////////////////////////////////////////////////
- //
- // Now look for the properties file and try to parse relevant fields
- //
- // /////////////////////////////////////////////////////////////////////
+ //
+ // Now look for the properties file and try to parse relevant fields
+ //
URL propsUrl = null;
if(shapefile)
propsUrl=DataUtilities.changeUrlExt(sourceURL, "properties");
Modified: branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/ImageMosaicFormatFactory.java
===================================================================
--- branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/ImageMosaicFormatFactory.java 2012-01-21 14:19:53 UTC (rev 38510)
+++ branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/ImageMosaicFormatFactory.java 2012-01-22 17:32:30 UTC (rev 38511)
@@ -16,9 +16,6 @@
*/
package org.geotools.gce.imagemosaic;
-import it.geosolutions.imageio.plugins.jp2ecw.JP2GDALEcwImageReaderSpi;
-import it.geosolutions.imageio.plugins.jp2kakadu.JP2GDALKakaduImageReaderSpi;
-import it.geosolutions.imageio.plugins.jp2mrsid.JP2GDALMrSidImageReaderSpi;
import it.geosolutions.imageio.utilities.ImageIOUtilities;
import java.awt.RenderingHints;
@@ -33,9 +30,6 @@
import org.geotools.coverage.grid.io.AbstractGridFormat;
import org.geotools.coverage.grid.io.GridFormatFactorySpi;
-import org.geotools.coverageio.gdal.jp2ecw.JP2ECWFormatFactory;
-import org.geotools.coverageio.gdal.jp2kak.JP2KFormatFactory;
-import org.geotools.coverageio.gdal.jp2mrsid.JP2MrSIDFormatFactory;
import com.sun.media.imageioimpl.common.PackageUtil;
import com.sun.media.imageioimpl.plugins.jpeg2000.J2KImageReaderCodecLibSpi;
@@ -52,260 +46,349 @@
* @source $URL$
*/
public final class ImageMosaicFormatFactory implements GridFormatFactorySpi {
-
- /** Logger. */
- private final static Logger LOGGER = org.geotools.util.logging.Logging.getLogger(ImageMosaicFormatFactory.class);
-
- private static final String KAKADU_SPI = "it.geosolutions.imageio.plugins.jp2k.JP2KKakaduImageReaderSpi";
- static {
-
- replaceTIFF();
-
- if(JP2KAK()){
- replaceJP2KAK();
- }
-
- else{
- if(JP2ECW()){
- replaceECW();
- }
- if(JP2MRSID()){
- replaceMRSID();
- }
- if(JP2GDALKAK()){
- replaceGDALKAK();
- }
- }
-
- }
- /**
- * Tells me if this plugin will work on not given the actual installation.
- *
- * <p>
- * Dependecies are mostly from JAI and ImageIO so if they are installed you
- * should not have many problems.
- *
- * @return False if something's missing, true otherwise.
- */
- public boolean isAvailable() {
- boolean available = true;
+ private static final String GDAL_JP2ECW_SPI = "it.geosolutions.imageio.plugins.jp2ecw.JP2GDALEcwImageReaderSpi";
+ private static final String GDAL_JP2KAKADU_SPI = "it.geosolutions.imageio.plugins.jp2kakadu.JP2GDALKakaduImageReaderSpi";
+ private static final String GDAL_JP2MrSID_SPI = "it.geosolutions.imageio.plugins.jp2mrsid.JP2GDALMrSidImageReaderSpi";
+ private static final String GDAL_SPI = "it.geosolutions.imageio.gdalframework.GDALImageReaderSpi";
+ private static final String KAKADU_SPI = "it.geosolutions.imageio.plugins.jp2k.JP2KKakaduImageReaderSpi";
+ /** Logger. */
+ private final static Logger LOGGER = org.geotools.util.logging.Logging.getLogger(ImageMosaicFormatFactory.class);
- // if these classes are here, then the runtine environment has
- // access to JAI and the JAI ImageI/O toolbox.
- try {
- Class.forName("javax.media.jai.JAI");
- Class.forName("com.sun.media.jai.operator.ImageReadDescriptor");
- } catch (ClassNotFoundException cnf) {
- available = false;
- }
+ static {
+
+ replaceTIFF();
+
+ if(hasJP2Kakadu()){
+ replaceJP2Kakadu();
+ }
+
+ else{
+ if(hasJP2GDALECW()){
+ replaceECW();
+ }
+ if(hasJP2GDALMRSID()){
+ replaceMRSID();
+ }
+ if(hasJP2GDALKakadu()){
+ replaceGDALKakadu();
+ }
+ }
+
+ }
- return available;
- }
+ private static boolean hasJP2GDALECW() {
+ try{
+ Class<?> cl = Class.forName(GDAL_JP2ECW_SPI);
+ Class<?> cGdal = Class.forName(GDAL_SPI);
+ Object jp2ecwSPI = cl.newInstance();
+ final Method method = cGdal.getDeclaredMethod("isAvailable", (Class[])null);
+ if (method != null){
+ return (Boolean) method.invoke(jp2ecwSPI,(Object[]) null);
+ }
+ } catch (ClassNotFoundException e) {
+ if (LOGGER.isLoggable(Level.FINE))
+ LOGGER.log(Level.FINE, "Unable to load GDAL JP2 ECW Reader SPI", e);
+ } catch (SecurityException e) {
+ if (LOGGER.isLoggable(Level.FINE))
+ LOGGER.log(Level.FINE, "Unable to load GDAL JP2 ECW Reader SPI", e);
+ } catch (NoSuchMethodException e) {
+ if (LOGGER.isLoggable(Level.FINE))
+ LOGGER.log(Level.FINE, "Unable to load GDAL JP2 ECW Reader SPI", e);
+ } catch (IllegalArgumentException e) {
+ if (LOGGER.isLoggable(Level.FINE))
+ LOGGER.log(Level.FINE, "Unable to load GDAL JP2 ECW Reader SPI", e);
+ } catch (IllegalAccessException e) {
+ if (LOGGER.isLoggable(Level.FINE))
+ LOGGER.log(Level.FINE, "Unable to load GDAL JP2 ECW Reader SPI", e);
+ } catch (InvocationTargetException e) {
+ if (LOGGER.isLoggable(Level.FINE))
+ LOGGER.log(Level.FINE, "Unable to load GDAL JP2 ECW Reader SPI", e);
+ } catch (InstantiationException e) {
+ if (LOGGER.isLoggable(Level.FINE))
+ LOGGER.log(Level.FINE, "Unable to load GDAL JP2 ECW Reader SPI", e);
+ }
+ return false;
+ }
+ private static boolean hasJP2GDALKakadu() {
+ try{
+ Class<?> cl = Class.forName(GDAL_JP2KAKADU_SPI);
+ Class<?> cGdal = Class.forName(GDAL_SPI);
+ Object jp2Kak = cl.newInstance();
+ final Method method = cGdal.getDeclaredMethod("isAvailable", (Class[])null);
+ if (method != null){
+ return (Boolean) method.invoke(jp2Kak,(Object[])null);
+ }
+ } catch (ClassNotFoundException e) {
+ if (LOGGER.isLoggable(Level.FINE))
+ LOGGER.log(Level.FINE, "Unable to load GDAL JP2 Kakadu Reader SPI", e);
+ } catch (SecurityException e) {
+ if (LOGGER.isLoggable(Level.FINE))
+ LOGGER.log(Level.FINE, "Unable to load GDAL JP2 Kakadu Reader SPI", e);
+ } catch (NoSuchMethodException e) {
+ if (LOGGER.isLoggable(Level.FINE))
+ LOGGER.log(Level.FINE, "Unable to load GDAL JP2 Kakadu Reader SPI", e);
+ } catch (IllegalArgumentException e) {
+ if (LOGGER.isLoggable(Level.FINE))
+ LOGGER.log(Level.FINE, "Unable to load GDAL JP2 Kakadu Reader SPI", e);
+ } catch (IllegalAccessException e) {
+ if (LOGGER.isLoggable(Level.FINE))
+ LOGGER.log(Level.FINE, "Unable to load GDAL JP2 Kakadu Reader SPI", e);
+ } catch (InvocationTargetException e) {
+ if (LOGGER.isLoggable(Level.FINE))
+ LOGGER.log(Level.FINE, "Unable to load GDAL JP2 Kakadu Reader SPI", e);
+ } catch (InstantiationException e) {
+ if (LOGGER.isLoggable(Level.FINE))
+ LOGGER.log(Level.FINE, "Unable to load GDAL JP2 Kakadu Reader SPI", e);
+ }
+ return false;
+ }
- private static boolean JP2KAK() {
- try{
- @SuppressWarnings("unused")
- Class<?> cl = Class.forName(KAKADU_SPI);
- Class<?> utilityClass = Class.forName("it.geosolutions.util.KakaduUtilities");
- final Method method = utilityClass.getDeclaredMethod("isKakaduAvailable", (Class[])null);
- if (method != null){
- Boolean isAvailable = (Boolean) method.invoke(null, null);
- return isAvailable.booleanValue();
- }
- } catch (ClassNotFoundException e) {
- if (LOGGER.isLoggable(Level.FINE))
- LOGGER.log(Level.FINE, "Unable to load kakadu JPEG2000 reader spi",e);
- } catch (SecurityException e) {
- if (LOGGER.isLoggable(Level.FINE))
- LOGGER.log(Level.FINE, "Unable to load kakadu JPEG2000 reader spi",e);
- } catch (NoSuchMethodException e) {
- if (LOGGER.isLoggable(Level.FINE))
- LOGGER.log(Level.FINE, "Unable to load kakadu JPEG2000 reader spi",e);
- } catch (IllegalArgumentException e) {
- if (LOGGER.isLoggable(Level.FINE))
- LOGGER.log(Level.FINE, "Unable to load kakadu JPEG2000 reader spi",e);
- } catch (IllegalAccessException e) {
- if (LOGGER.isLoggable(Level.FINE))
- LOGGER.log(Level.FINE, "Unable to load kakadu JPEG2000 reader spi",e);
- } catch (InvocationTargetException e) {
- if (LOGGER.isLoggable(Level.FINE))
- LOGGER.log(Level.FINE, "Unable to load kakadu JPEG2000 reader spi",e);
- }
- return false;
- }
+ private static boolean hasJP2GDALMRSID() {
+ try{
+ Class<?> cl = Class.forName(GDAL_JP2MrSID_SPI);
+ Class<?> cGdal = Class.forName(GDAL_SPI);
+ Object jp2MrSid = cl.newInstance();
+ final Method method = cGdal.getDeclaredMethod("isAvailable", (Class[])null);
+ if (method != null){
+ return (Boolean) method.invoke(jp2MrSid, (Object[])null);
+ }
+ } catch (ClassNotFoundException e) {
+ if (LOGGER.isLoggable(Level.FINE))
+ LOGGER.log(Level.FINE, "Unable to load GDAL JP2 MrSID Reader SPI", e);
+ } catch (SecurityException e) {
+ if (LOGGER.isLoggable(Level.FINE))
+ LOGGER.log(Level.FINE, "Unable to load GDAL JP2 MrSID Reader SPI", e);
+ } catch (NoSuchMethodException e) {
+ if (LOGGER.isLoggable(Level.FINE))
+ LOGGER.log(Level.FINE, "Unable to load GDAL JP2 MrSID Reader SPI", e);
+ } catch (IllegalArgumentException e) {
+ if (LOGGER.isLoggable(Level.FINE))
+ LOGGER.log(Level.FINE, "Unable to load GDAL JP2 MrSID Reader SPI", e);
+ } catch (IllegalAccessException e) {
+ if (LOGGER.isLoggable(Level.FINE))
+ LOGGER.log(Level.FINE, "Unable to load GDAL JP2 MrSID Reader SPI", e);
+ } catch (InvocationTargetException e) {
+ if (LOGGER.isLoggable(Level.FINE))
+ LOGGER.log(Level.FINE, "Unable to load GDAL JP2 MrSID Reader SPI", e);
+ } catch (InstantiationException e) {
+ if (LOGGER.isLoggable(Level.FINE))
+ LOGGER.log(Level.FINE, "Unable to load GDAL JP2 MrSID Reader SPI", e);
+ }
+ return false;
+ }
- private static void replaceJP2KAK() {
- try{
- Class.forName(KAKADU_SPI);
+ private static boolean hasJP2Kakadu() {
+ try{
+ Class<?> cl = Class.forName(KAKADU_SPI);
+ Class<?> utilityClass = Class.forName("it.geosolutions.util.KakaduUtilities");
+ final Method method = utilityClass.getDeclaredMethod("isKakaduAvailable", (Class[])null);
+ if (method != null){
+ return (Boolean) method.invoke(null, (Object[])null);
+ }
+ } catch (ClassNotFoundException e) {
+ if (LOGGER.isLoggable(Level.FINE))
+ LOGGER.log(Level.FINE, "Unable to load kakadu JPEG2000 reader spi",e);
+ } catch (SecurityException e) {
+ if (LOGGER.isLoggable(Level.FINE))
+ LOGGER.log(Level.FINE, "Unable to load kakadu JPEG2000 reader spi",e);
+ } catch (NoSuchMethodException e) {
+ if (LOGGER.isLoggable(Level.FINE))
+ LOGGER.log(Level.FINE, "Unable to load kakadu JPEG2000 reader spi",e);
+ } catch (IllegalArgumentException e) {
+ if (LOGGER.isLoggable(Level.FINE))
+ LOGGER.log(Level.FINE, "Unable to load kakadu JPEG2000 reader spi",e);
+ } catch (IllegalAccessException e) {
+ if (LOGGER.isLoggable(Level.FINE))
+ LOGGER.log(Level.FINE, "Unable to load kakadu JPEG2000 reader spi",e);
+ } catch (InvocationTargetException e) {
+ if (LOGGER.isLoggable(Level.FINE))
+ LOGGER.log(Level.FINE, "Unable to load kakadu JPEG2000 reader spi",e);
+ }
+ return false;
+ }
- // imageio kakJP2 reader
- final String imageioJ2KImageReaderCodecName=J2KImageReaderCodecLibSpi.class.getName();
-
- if(PackageUtil.isCodecLibAvailable()){
- boolean succeeded=ImageIOUtilities.replaceProvider(ImageReaderSpi.class, KAKADU_SPI, imageioJ2KImageReaderCodecName, "JPEG 2000");
- if(!succeeded)
- if (LOGGER.isLoggable(Level.WARNING))
- LOGGER.warning("Unable to set ordering between jp2 readers spi-"+KAKADU_SPI+":"+imageioJ2KImageReaderCodecName);
- }
-
- // imageio kakJP2 reader
- final String imageioJ2KImageReaderName=J2KImageReaderSpi.class.getName();
-
- final boolean succeeded=ImageIOUtilities.replaceProvider(ImageReaderSpi.class, KAKADU_SPI, imageioJ2KImageReaderName, "JPEG 2000");
- if(!succeeded)
- if (LOGGER.isLoggable(Level.WARNING))
- LOGGER.warning("Unable to set ordering between jp2 readers spi-"+KAKADU_SPI+":"+imageioJ2KImageReaderName);
-
- } catch (ClassNotFoundException e) {
- if (LOGGER.isLoggable(Level.WARNING))
- LOGGER.log(Level.WARNING, "Unable to load specific JPEG2000 reader spi",e);
- }
- }
+ private static void replaceECW() {
+ try{
+ //check if our ecwJP2 plugin is in the path
+ Class.forName(GDAL_JP2ECW_SPI);
+
+ // imageio ecwJP2 reader
+ final String imageioJ2KImageReaderCodecName=J2KImageReaderCodecLibSpi.class.getName();
+
+ if(PackageUtil.isCodecLibAvailable()){
+ boolean succeeded=ImageIOUtilities.replaceProvider(ImageReaderSpi.class, GDAL_JP2ECW_SPI, imageioJ2KImageReaderCodecName, "JPEG 2000");
+ if(!succeeded)
+ if (LOGGER.isLoggable(Level.WARNING))
+ LOGGER.warning("Unable to set ordering between jp2 readers spi-"+GDAL_JP2ECW_SPI+":"+imageioJ2KImageReaderCodecName);
+ }
+
+ // imageio ecwJP2 reader
+ final String imageioJ2KImageReaderName=J2KImageReaderSpi.class.getName();
+
+ final boolean succeeded=ImageIOUtilities.replaceProvider(ImageReaderSpi.class, GDAL_JP2ECW_SPI, imageioJ2KImageReaderName, "JPEG 2000");
+ if(!succeeded)
+ if (LOGGER.isLoggable(Level.WARNING))
+ LOGGER.warning("Unable to set ordering between jp2 readers spi-"+GDAL_JP2ECW_SPI+":"+imageioJ2KImageReaderName);
+
+ } catch (ClassNotFoundException e) {
+ if (LOGGER.isLoggable(Level.WARNING))
+ LOGGER.log(Level.WARNING, "Unable to load specific JPEG2000 reader spi",e);
+ }
+
+ }
- private static void replaceTIFF() {
- try{
- //check if our tiff plugin is in the path
- final String customTiffName=it.geosolutions.imageioimpl.plugins.tiff.TIFFImageReaderSpi.class.getName();
- Class.forName(customTiffName);
+ private static void replaceGDALKakadu() {
+ try{
+ //check if our kakJP2 plugin is in the path
+
+ Class.forName(GDAL_JP2KAKADU_SPI);
+
+ // imageio kakJP2 reader
+ final String imageioJ2KImageReaderCodecName=J2KImageReaderCodecLibSpi.class.getName();
+
+ if(PackageUtil.isCodecLibAvailable()){
+ boolean succeeded=ImageIOUtilities.replaceProvider(ImageReaderSpi.class, GDAL_JP2KAKADU_SPI, imageioJ2KImageReaderCodecName, "JPEG 2000");
+ if(!succeeded)
+ if (LOGGER.isLoggable(Level.WARNING))
+ LOGGER.warning("Unable to set ordering between jp2 readers spi-"+GDAL_JP2KAKADU_SPI+":"+imageioJ2KImageReaderCodecName);
+ }
+
+ // imageio kakJP2 reader
+ final String imageioJ2KImageReaderName=J2KImageReaderSpi.class.getName();
+
+
+ final boolean succeeded=ImageIOUtilities.replaceProvider(ImageReaderSpi.class, GDAL_JP2KAKADU_SPI, imageioJ2KImageReaderName, "JPEG 2000");
+ if(!succeeded)
+ if (LOGGER.isLoggable(Level.WARNING))
+ LOGGER.warning("Unable to set ordering between jp2 readers spi-"+GDAL_JP2KAKADU_SPI+":"+imageioJ2KImageReaderName);
+
+ } catch (ClassNotFoundException e) {
+ if (LOGGER.isLoggable(Level.WARNING))
+ LOGGER.log(Level.WARNING, "Unable to load specific JPEG2000 reader spi",e);
+ }
+
+ }
- // imageio tiff reader
- final String imageioTiffName=TIFFImageReaderSpi.class.getName();
-
- final boolean succeeded=ImageIOUtilities.replaceProvider(ImageReaderSpi.class, customTiffName, imageioTiffName, "tiff");
- if(!succeeded)
- if (LOGGER.isLoggable(Level.WARNING))
- LOGGER.warning("Unable to set ordering between tiff readers spi");
-
- } catch (ClassNotFoundException e) {
- if (LOGGER.isLoggable(Level.WARNING))
- LOGGER.log(Level.WARNING,"Unable to load specific TIFF reader spi",e);
- }
-
- }
+ private static void replaceJP2Kakadu() {
+ try{
+ Class.forName(KAKADU_SPI);
+
+ // imageio kakJP2 reader
+ final String imageioJ2KImageReaderCodecName=J2KImageReaderCodecLibSpi.class.getName();
+
+ if(PackageUtil.isCodecLibAvailable()){
+ boolean succeeded=ImageIOUtilities.replaceProvider(ImageReaderSpi.class, KAKADU_SPI, imageioJ2KImageReaderCodecName, "JPEG 2000");
+ if(!succeeded)
+ if (LOGGER.isLoggable(Level.WARNING))
+ LOGGER.warning("Unable to set ordering between jp2 readers spi-"+KAKADU_SPI+":"+imageioJ2KImageReaderCodecName);
+ }
+
+ // imageio kakJP2 reader
+ final String imageioJ2KImageReaderName=J2KImageReaderSpi.class.getName();
+
+ final boolean succeeded=ImageIOUtilities.replaceProvider(ImageReaderSpi.class, KAKADU_SPI, imageioJ2KImageReaderName, "JPEG 2000");
+ if(!succeeded)
+ if (LOGGER.isLoggable(Level.WARNING))
+ LOGGER.warning("Unable to set ordering between jp2 readers spi-"+KAKADU_SPI+":"+imageioJ2KImageReaderName);
+
+ } catch (ClassNotFoundException e) {
+ if (LOGGER.isLoggable(Level.WARNING))
+ LOGGER.log(Level.WARNING, "Unable to load specific JPEG2000 reader spi",e);
+ }
+ }
- private static boolean JP2GDALKAK() {
- return new JP2KFormatFactory().isAvailable();
- }
+ private static void replaceMRSID() {
+ try{
+ //check if our mrsidJP2 plugin is in the path
+ Class.forName(GDAL_JP2MrSID_SPI );
+
+ // imageio tiff reader
+ final String imageioJ2KImageReaderCodecName=J2KImageReaderCodecLibSpi.class.getName();
+
+ if(PackageUtil.isCodecLibAvailable()){
+ boolean succeeded=ImageIOUtilities.replaceProvider(ImageReaderSpi.class, GDAL_JP2MrSID_SPI , imageioJ2KImageReaderCodecName, "JPEG 2000");
+ if(!succeeded)
+ if (LOGGER.isLoggable(Level.WARNING))
+ LOGGER.warning("Unable to set ordering between jp2 readers spi-"+GDAL_JP2MrSID_SPI +":"+imageioJ2KImageReaderCodecName);
+ }
+
+ // imageio mrsidJP2 reader
+ final String imageioJ2KImageReaderName=J2KImageReaderSpi.class.getName();
+
+
+ final boolean succeeded=ImageIOUtilities.replaceProvider(ImageReaderSpi.class, GDAL_JP2MrSID_SPI , imageioJ2KImageReaderName, "JPEG 2000");
+ if(!succeeded)
+ if (LOGGER.isLoggable(Level.WARNING))
+ LOGGER.warning("Unable to set ordering between jp2 readers spi-"+GDAL_JP2MrSID_SPI +":"+imageioJ2KImageReaderName);
+
+ } catch (ClassNotFoundException e) {
+ if (LOGGER.isLoggable(Level.WARNING))
+ LOGGER.log(Level.WARNING, "Unable to load specific JPEG2000 reader spi",e);
+ }
+
+ }
- private static void replaceGDALKAK() {
- try{
- //check if our kakJP2 plugin is in the path
- final String kakJP2=JP2GDALKakaduImageReaderSpi.class.getName();
- Class.forName(kakJP2);
+ private static void replaceTIFF() {
+ try{
+ //check if our tiff plugin is in the path
+ final String customTiffName=it.geosolutions.imageioimpl.plugins.tiff.TIFFImageReaderSpi.class.getName();
+ Class.forName(customTiffName);
+
+ // imageio tiff reader
+ final String imageioTiffName=TIFFImageReaderSpi.class.getName();
+
+ final boolean succeeded=ImageIOUtilities.replaceProvider(ImageReaderSpi.class, customTiffName, imageioTiffName, "tiff");
+ if(!succeeded)
+ if (LOGGER.isLoggable(Level.WARNING))
+ LOGGER.warning("Unable to set ordering between tiff readers spi");
+
+ } catch (ClassNotFoundException e) {
+ if (LOGGER.isLoggable(Level.WARNING))
+ LOGGER.log(Level.WARNING,"Unable to load specific TIFF reader spi",e);
+ }
+
+ }
- // imageio kakJP2 reader
- final String imageioJ2KImageReaderCodecName=J2KImageReaderCodecLibSpi.class.getName();
-
- if(PackageUtil.isCodecLibAvailable()){
- boolean succeeded=ImageIOUtilities.replaceProvider(ImageReaderSpi.class, kakJP2, imageioJ2KImageReaderCodecName, "JPEG 2000");
- if(!succeeded)
- if (LOGGER.isLoggable(Level.WARNING))
- LOGGER.warning("Unable to set ordering between jp2 readers spi-"+kakJP2+":"+imageioJ2KImageReaderCodecName);
- }
-
- // imageio kakJP2 reader
- final String imageioJ2KImageReaderName=J2KImageReaderSpi.class.getName();
-
-
- final boolean succeeded=ImageIOUtilities.replaceProvider(ImageReaderSpi.class, kakJP2, imageioJ2KImageReaderName, "JPEG 2000");
- if(!succeeded)
- if (LOGGER.isLoggable(Level.WARNING))
- LOGGER.warning("Unable to set ordering between jp2 readers spi-"+kakJP2+":"+imageioJ2KImageReaderName);
-
- } catch (ClassNotFoundException e) {
- if (LOGGER.isLoggable(Level.WARNING))
- LOGGER.log(Level.WARNING, "Unable to load specific JPEG2000 reader spi",e);
- }
-
- }
+ /**
+ * @see GridFormatFactorySpi#createFormat().
+ */
+ public AbstractGridFormat createFormat() {
+ return new ImageMosaicFormat();
+ }
- private static void replaceMRSID() {
- try{
- //check if our mrsidJP2 plugin is in the path
- final String mrsidJP2=JP2GDALMrSidImageReaderSpi.class.getName();
- Class.forName(mrsidJP2);
+ /**
+ * Returns the implementation hints. The default implementation returns an
+ * empty map.
+ *
+ * @return An empty map.
+ */
+ public Map<RenderingHints.Key, ?> getImplementationHints() {
+ return Collections.emptyMap();
+ }
- // imageio tiff reader
- final String imageioJ2KImageReaderCodecName=J2KImageReaderCodecLibSpi.class.getName();
-
- if(PackageUtil.isCodecLibAvailable()){
- boolean succeeded=ImageIOUtilities.replaceProvider(ImageReaderSpi.class, mrsidJP2, imageioJ2KImageReaderCodecName, "JPEG 2000");
- if(!succeeded)
- if (LOGGER.isLoggable(Level.WARNING))
- LOGGER.warning("Unable to set ordering between jp2 readers spi-"+mrsidJP2+":"+imageioJ2KImageReaderCodecName);
- }
-
- // imageio mrsidJP2 reader
- final String imageioJ2KImageReaderName=J2KImageReaderSpi.class.getName();
-
-
- final boolean succeeded=ImageIOUtilities.replaceProvider(ImageReaderSpi.class, mrsidJP2, imageioJ2KImageReaderName, "JPEG 2000");
- if(!succeeded)
- if (LOGGER.isLoggable(Level.WARNING))
- LOGGER.warning("Unable to set ordering between jp2 readers spi-"+mrsidJP2+":"+imageioJ2KImageReaderName);
-
- } catch (ClassNotFoundException e) {
- if (LOGGER.isLoggable(Level.WARNING))
- LOGGER.log(Level.WARNING, "Unable to load specific JPEG2000 reader spi",e);
- }
-
- }
-
- private static boolean JP2MRSID() {
- return new JP2MrSIDFormatFactory().isAvailable();
- }
-
- private static void replaceECW() {
- try{
- //check if our ecwJP2 plugin is in the path
- final String ecwJP2=JP2GDALEcwImageReaderSpi.class.getName();
- Class.forName(ecwJP2);
-
- // imageio ecwJP2 reader
- final String imageioJ2KImageReaderCodecName=J2KImageReaderCodecLibSpi.class.getName();
-
- if(PackageUtil.isCodecLibAvailable()){
- boolean succeeded=ImageIOUtilities.replaceProvider(ImageReaderSpi.class, ecwJP2, imageioJ2KImageReaderCodecName, "JPEG 2000");
- if(!succeeded)
- if (LOGGER.isLoggable(Level.WARNING))
- LOGGER.warning("Unable to set ordering between jp2 readers spi-"+ecwJP2+":"+imageioJ2KImageReaderCodecName);
- }
-
- // imageio ecwJP2 reader
- final String imageioJ2KImageReaderName=J2KImageReaderSpi.class.getName();
-
- final boolean succeeded=ImageIOUtilities.replaceProvider(ImageReaderSpi.class, ecwJP2, imageioJ2KImageReaderName, "JPEG 2000");
- if(!succeeded)
- if (LOGGER.isLoggable(Level.WARNING))
- LOGGER.warning("Unable to set ordering between jp2 readers spi-"+ecwJP2+":"+imageioJ2KImageReaderName);
-
- } catch (ClassNotFoundException e) {
- if (LOGGER.isLoggable(Level.WARNING))
- LOGGER.log(Level.WARNING, "Unable to load specific JPEG2000 reader spi",e);
- }
-
- }
-
- private static boolean JP2ECW() {
- return new JP2ECWFormatFactory().isAvailable();
- }
-
- /**
- * @see GridFormatFactorySpi#createFormat().
- */
- public AbstractGridFormat createFormat() {
- return new ImageMosaicFormat();
- }
-
- /**
- * Returns the implementation hints. The default implementation returns an
- * empty map.
- *
- * @return An empty map.
- */
- public Map<RenderingHints.Key, ?> getImplementationHints() {
- return Collections.emptyMap();
- }
+ /**
+ * Tells me if this plugin will work on not given the actual installation.
+ *
+ * <p>
+ * Dependecies are mostly from JAI and ImageIO so if they are installed you
+ * should not have many problems.
+ *
+ * @return False if something's missing, true otherwise.
+ */
+ public boolean isAvailable() {
+ boolean available = true;
+
+ // if these classes are here, then the runtine environment has
+ // access to JAI and the JAI ImageI/O toolbox.
+ try {
+ Class.forName("javax.media.jai.JAI");
+ Class.forName("com.sun.media.jai.operator.ImageReadDescriptor");
+ } catch (ClassNotFoundException cnf) {
+ available = false;
+ }
+
+ return available;
+ }
}
Modified: branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/ImageMosaicReader.java
===================================================================
--- branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/ImageMosaicReader.java 2012-01-21 14:19:53 UTC (rev 38510)
+++ branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/ImageMosaicReader.java 2012-01-22 17:32:30 UTC (rev 38511)
@@ -28,7 +28,6 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
-import java.util.Collections;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
@@ -141,8 +140,6 @@
boolean cachingIndex;
String elevationAttribute;
-
- String runtimeAttribute;
boolean imposedBBox;
@@ -523,14 +520,9 @@
// elevation param
final String elevationAttribute = configuration.getElevationAttribute();
if(elevationAttribute != null)
- this.elevationAttribute = elevationAttribute;
+ this.elevationAttribute = elevationAttribute;
- // runtime param
- final String runtimeAttribute = configuration.getRuntimeAttribute();
- if(runtimeAttribute != null)
- this.runtimeAttribute = runtimeAttribute;
-
// caching for the index
cachingIndex = configuration.isCaching();
Modified: branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/MosaicConfigurationBean.java
===================================================================
--- branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/MosaicConfigurationBean.java 2012-01-21 14:19:53 UTC (rev 38510)
+++ branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/MosaicConfigurationBean.java 2012-01-22 17:32:30 UTC (rev 38511)
@@ -34,6 +34,9 @@
*/
public class MosaicConfigurationBean {
+ /**
+ * Default constructor
+ */
public MosaicConfigurationBean() {
}
@@ -54,7 +57,7 @@
/**
* <code>true</code> it tells us if the mosaic points to absolute paths or to relative ones. (in case of <code>false</code>).
*/
- private boolean absolutePath;
+ private boolean absolutePath= Utils.DEFAULT_PATH_BEHAVIOR;
/**
* <code>true</code> if we need to expand to RGB(A) the single tiles in case they use a different {@link IndexColorModel}.
@@ -71,7 +74,7 @@
private int levelsNum;
/** location attribute name*/
- private String locationAttribute;
+ private String locationAttribute=Utils.DEFAULT_LOCATION_ATTRIBUTE;
/**Suggested SPI for the various tiles. May be null.**/
private String suggestedSPI;
@@ -81,9 +84,6 @@
/** elevation attribute name. <code>null</code> if absent.*/
private String elevationAttribute;
-
- /** runtime attribute name. <code>null</code> if absent.*/
- private String runtimeAttribute;
/**
* mosaic's dummy sample model useful to store dataType and number of bands. All the other fields
@@ -119,13 +119,6 @@
this.elevationAttribute = elevationAttribute;
}
- public String getRuntimeAttribute() {
- return runtimeAttribute;
- }
- public void setRuntimeAttribute(final String runtimeAttribute) {
- this.runtimeAttribute = runtimeAttribute;
- }
-
/** we want to use caching for our index.*/
private boolean caching = Utils.DEFAULT_CONFIGURATION_CACHING;
Modified: branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/PathType.java
===================================================================
--- branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/PathType.java 2012-01-21 14:19:53 UTC (rev 38510)
+++ branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/PathType.java 2012-01-22 17:32:30 UTC (rev 38511)
@@ -32,7 +32,6 @@
* @author Simone Giannecchini, GeoSolutions SAS
* @author Stefan Alfons Krueger (alfonx), Wikisquare.de : Support for jar:file:foo.jar/bar.properties URLs
*
- *
* @source $URL: http://svn.osgeo.org/geotools/branches/2.7.x/build/maven/javadoc/../../../modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/PathType.java $
*/
public enum PathType {
@@ -67,19 +66,6 @@
} catch (MalformedURLException e) {
return null;
}
-
-// // create a file for the provided location, relative to parent location
-// File rasterFile= new File(parentLocation,location);
-// if(!ImageMosaicUtils.checkFileReadable(rasterFile))
-// {
-// if (LOGGER.isLoggable(Level.INFO))
-// LOGGER.info("Unable to read image for file "+ rasterFile.getAbsolutePath());
-//
-// return null;
-//
-// }
-// return rasterFile;
-
}
},
Modified: branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/RasterLayerRequest.java
===================================================================
--- branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/RasterLayerRequest.java 2012-01-21 14:19:53 UTC (rev 38510)
+++ branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/RasterLayerRequest.java 2012-01-22 17:32:30 UTC (rev 38511)
@@ -71,6 +71,7 @@
* @author Daniele Romagnoli, GeoSolutions
* @author Simone Giannecchini, GeoSolutions
*/
+@SuppressWarnings("rawtypes")
class RasterLayerRequest {
/** Logger. */
@@ -243,7 +244,6 @@
prepare();
}
- @SuppressWarnings({ "unchecked"})
private void setDefaultParameterValues() {
// get the read parameters for this format plus the ones for the basic format and set them to the default
@@ -465,7 +465,6 @@
* @param name
* the name of the parameter
*/
- @SuppressWarnings("unchecked")
private void extractParameter(ParameterValue<?> param, Identifier name) {
// //
Modified: branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/RasterLayerResponse.java
===================================================================
--- branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/RasterLayerResponse.java 2012-01-21 14:19:53 UTC (rev 38510)
+++ branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/RasterLayerResponse.java 2012-01-22 17:32:30 UTC (rev 38511)
@@ -126,6 +126,7 @@
* @author Daniele Romagnoli, GeoSolutions
* @author Stefan Alfons Krueger (alfonx), Wikisquare.de : Support for jar:file:foo.jar/bar.properties URLs
*/
+@SuppressWarnings("rawtypes")
class RasterLayerResponse{
private static final class SimplifiedGridSampleDimension extends GridSampleDimension implements SampleDimension{
@@ -289,7 +290,7 @@
}
@SuppressWarnings("unchecked")
- @Override
+ @Override
public void visit(Feature feature) {
super.visit(feature);
// if we got a NAN let's leave
@@ -905,7 +906,6 @@
true));
} else {
// convert to range and create a correct range filter
- @SuppressWarnings("rawtypes")
final NumberRange range= (NumberRange)elevation;
elevationF.add(
FeatureUtilities.DEFAULT_FILTER_FACTORY.and(
Modified: branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/RasterManager.java
===================================================================
--- branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/RasterManager.java 2012-01-21 14:19:53 UTC (rev 38510)
+++ branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/RasterManager.java 2012-01-22 17:32:30 UTC (rev 38511)
@@ -189,8 +189,6 @@
String elevationAttribute;
- String runtimeAttribute;
-
ImageLayout defaultImageLayout;
public RasterManager(final ImageMosaicReader reader) throws DataSourceException {
@@ -207,7 +205,6 @@
timeAttribute=parent.timeAttribute;
elevationAttribute=parent.elevationAttribute;
- runtimeAttribute=parent.runtimeAttribute;
coverageIdentifier=reader.getName();
hints = reader.getHints();
this.coverageIdentifier =reader.getName();
Modified: branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/ReadType.java
===================================================================
--- branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/ReadType.java 2012-01-21 14:19:53 UTC (rev 38510)
+++ branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/ReadType.java 2012-01-22 17:32:30 UTC (rev 38511)
@@ -16,7 +16,6 @@
*/
package org.geotools.gce.imagemosaic;
-import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.image.RenderedImage;
import java.io.IOException;
@@ -26,7 +25,6 @@
import javax.imageio.ImageReadParam;
import javax.imageio.ImageReader;
-import javax.imageio.spi.ImageReaderSpi;
import javax.imageio.stream.ImageInputStream;
import javax.media.jai.RenderedOp;
@@ -59,23 +57,30 @@
final ImageReader reader,
final Hints hints,
final boolean closeElements) {
- //
+ //
// Using ImageReader to load the data directly
//
try{
+ //check source region
+ if(CoverageUtilities.checkEmptySourceRegion(readParameters, rasterDimensions)){
+ if (LOGGER.isLoggable(Level.WARNING))
+ LOGGER.warning("Provided an emptu source region to this read method ");
+ return null;
+ }
+
+ // checks on url
+ if(granuleUrl==null){
+ if (LOGGER.isLoggable(Level.WARNING))
+ LOGGER.warning("Provided a null URL to this read method ");
+ return null;
+ }
- if(reader==null)
- {
+ if(reader==null){
if (LOGGER.isLoggable(Level.WARNING))
LOGGER.warning("Unable to get reader for URL " + granuleUrl);
return null;
}
-
- //check source regione
- if(CoverageUtilities.checkEmptySourceRegion(readParameters, rasterDimensions))
- return null;
-
if (LOGGER.isLoggable(Level.FINER))
LOGGER.log(Level.FINER, "reading file: " + granuleUrl);
@@ -98,127 +103,11 @@
}
- }
-
- RenderedImage read(
- final ImageReadParam readP,
- final int imageIndex,
- final URL rasterURL,
- final Rectangle readDimension,
- final ImageReaderSpi spi,
- final Hints hints
- )throws IOException{
- //
- // Using ImageReader to load the data directly
- //
- ImageInputStream inStream=null;
- ImageReader reader=null;
- try{
- inStream = Utils.getInputStream(rasterURL);
- if(inStream==null)
- return null;
-
- reader=spi.createReaderInstance();
- if(reader==null)
- {
- if (LOGGER.isLoggable(Level.WARNING))
- LOGGER.warning("Unable to get reader for URL " + rasterURL);
- return null;
- }
-
- inStream.reset();
- reader.setInput(inStream);
-
- //check source regione
- if(CoverageUtilities.checkEmptySourceRegion(readP, readDimension))
- return null;
-
- if (LOGGER.isLoggable(Level.FINER))
- LOGGER.log(Level.FINER, "reading file: " + rasterURL);
-
- // read data
- return reader.read(imageIndex,readP);
- } catch (IOException e) {
- if (LOGGER.isLoggable(Level.WARNING))
- LOGGER.log(Level.WARNING,"Unable to compute source area for URL "
- + rasterURL,e);
- return null;
- } finally {
- //close everything
- try {
- // reader
- reader.dispose();
- } catch (Throwable t) {
- // swallow the exception, we are just trying to close as much stuff as possible
- }
-
- try {
- // instream
- inStream.close();
- } catch (Throwable t) {
- // swallow the exception, we are just trying to close as much stuff as possible
- }
- }
- }
+ }
},
JAI_IMAGEREAD{
- @Override
- RenderedImage read(
- final ImageReadParam readP,
- final int imageIndex,
- final URL rasterUrl,
- final Rectangle readDimension,
- final ImageReaderSpi spi,
- final Hints hints
- ) throws IOException{
-
- //check source regionepbjMosaic,
- if(CoverageUtilities.checkEmptySourceRegion(readP, readDimension))
- return null;
-
-
-
- // read data
-// final ParameterBlock pbjImageRead = new ParameterBlock();
-// pbjImageRead.add(Utils.getInputStream(rasterUrl));
-// pbjImageRead.add(imageIndex);
-// pbjImageRead.add(false);
-// pbjImageRead.add(false);
-// pbjImageRead.add(false);
-// pbjImageRead.add(null);
-// pbjImageRead.add(null);
-// pbjImageRead.add(readP);
-// pbjImageRead.add(spi.createReaderInstance());
- final RenderedOp raster;
-// if(tileDimension != null){
-// if (hints != null){
- //build a proper layout
-// final ImageLayout layout = new ImageLayout();
-// layout.setTileWidth(tileDimension.width).setTileHeight(tileDimension.height);
-// raster = JAI.create("ImageRead", pbjImageRead,new RenderingHints(JAI.KEY_IMAGE_LAYOUT,layout));
-// raster = JAI.create("ImageRead", pbjImageRead, hints);
- raster = ImageReadDescriptor.create(
- Utils.getInputStream(rasterUrl),
- imageIndex,
- false,
- false,
- false,
- null,
- null,
- readP,
- spi.createReaderInstance(),
- hints);
-// }
-// else
-// raster = JAI.create("ImageRead", pbjImageRead);
- //force rendering (a-la JAI)
- if (raster != null)
- raster.getWidth();
- return raster;
- }
-
@Override
RenderedImage read(
final ImageReadParam readParameters,
@@ -232,12 +121,30 @@
try{
//check source regionepbjMosaic,
- if(CoverageUtilities.checkEmptySourceRegion(readParameters, rasterDimensions))
- return null;
-
+ if(CoverageUtilities.checkEmptySourceRegion(readParameters, rasterDimensions)){
+ if (LOGGER.isLoggable(Level.WARNING))
+ LOGGER.warning("Provided an emptu source region to this read method ");
+ return null;
+ }
+
+ // checks on url
+ if(granuleUrl==null){
+ if (LOGGER.isLoggable(Level.WARNING))
+ LOGGER.warning("Provided a null URL to this read method ");
+ return null;
+ }
+
+ if(reader==null){
+ if (LOGGER.isLoggable(Level.WARNING))
+ LOGGER.warning("Unable to get reader for URL " + granuleUrl);
+ return null;
+ }
+
+ // check input stream
+ final ImageInputStream inStream=(ImageInputStream) reader.getInput();
// read data
final RenderedOp raster = ImageReadDescriptor.create(
- Utils.getInputStream(granuleUrl),
+ inStream,
imageIndex,
false,
false,
@@ -251,7 +158,7 @@
if (raster != null)
raster.getWidth();
return raster;
- }catch (IOException e) {
+ }catch (Exception e) {
if(LOGGER.isLoggable(Level.INFO))
LOGGER.log(Level.INFO,e.getLocalizedMessage(),e);
return null;
@@ -271,17 +178,6 @@
final boolean closeElements) {
throw new UnsupportedOperationException(Errors.format(ErrorKeys.UNSUPPORTED_OPERATION_$1,"read"));
}
- @Override
- RenderedImage read(
- final ImageReadParam readP,
- final int imageIndex,
- final URL rasterUrl,
- final Rectangle readDimension,
- final ImageReaderSpi spi,
- final Hints hints
- )throws IOException{
- throw new UnsupportedOperationException(Errors.format(ErrorKeys.UNSUPPORTED_OPERATION_$1,"read"));
- }
};
/** Logger. */
@@ -300,34 +196,23 @@
return JAI_IMAGEREAD;
}
- /**
- * Load the raster data from the underlying source with the specified read
- * type.
- *
- * @param readParameters
- * @param imageIndex
- * @param rasterUrl
- * @param readDimension
- * @param tileDimension
- * a {@link Dimension} object that can be used to suggest specific
- * tile dimension for the raster to load. It can be <code>null</code>.
- *
- * @return a {@link RenderedImage} instance that matches the provided
- * request parameters as close as possible.
- *
- * @throws IOException
- * in case something bad occurs during the decoding process.
- */
+ /**
+ * Load the raster data from the underlying source with the specified read
+ * type.
+ *
+ * @param readParameters
+ * @param imageIndex
+ * @param rasterUrl
+ * @param readDimension
+ * @param hints {@link Hints} to control the read process
+ *
+ * @return a {@link RenderedImage} instance that matches the provided
+ * request parameters as close as possible.
+ *
+ * @throws IOException
+ * in case something bad occurs during the decoding process.
+ */
abstract RenderedImage read(
- final ImageReadParam readParameters,
- final int imageIndex,
- final URL rasterUrl,
- final Rectangle readDimension,
- final ImageReaderSpi spi,
- final Hints hints
- ) throws IOException;
-
- abstract RenderedImage read(
final ImageReadParam readParameters,
final int imageIndex,
final URL granuleUrl,
Modified: branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/Utils.java
===================================================================
--- branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/Utils.java 2012-01-21 14:19:53 UTC (rev 38510)
+++ branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/Utils.java 2012-01-22 17:32:30 UTC (rev 38511)
@@ -16,8 +16,6 @@
*/
package org.geotools.gce.imagemosaic;
-import it.geosolutions.imageio.stream.input.spi.URLImageInputStreamSpi;
-
import java.awt.Color;
import java.awt.Rectangle;
import java.awt.geom.AffineTransform;
@@ -57,7 +55,6 @@
import javax.imageio.ImageIO;
import javax.imageio.ImageReadParam;
import javax.imageio.ImageReader;
-import javax.imageio.spi.ImageInputStreamSpi;
import javax.imageio.stream.ImageInputStream;
import javax.media.jai.Histogram;
import javax.media.jai.Interpolation;
@@ -342,16 +339,11 @@
public static final boolean DEFAULT_PATH_BEHAVIOR = false;
/**
- * Default path behavior with respect to index caching.
+ * Default behavior with respect to index caching.
*/
private static final boolean DEFAULT_CACHING_BEHAVIOR = false;
-
- /**
- * Cached instance of {@link URLImageInputStreamSpi} for creating
- * {@link ImageInputStream} instances.
- */
- private static ImageInputStreamSpi CACHED_STREAM_SPI = new URLImageInputStreamSpi();
+
/**
* Creates a mosaic for the provided input parameters.
*
@@ -827,39 +819,6 @@
}
/**
- * Retrieves an {@link ImageInputStream} for the provided input {@link File}
- * .
- *
- * @param file
- * @return
- * @throws IOException
- */
- static ImageInputStream getInputStream(final File file) throws IOException {
- Utilities.ensureNonNull("file", file);
- final ImageInputStream inStream = ImageIO.createImageInputStream(file);
- if (inStream == null)
- return null;
- return inStream;
- }
-
- /**
- * Retrieves an {@link ImageInputStream} for the provided input {@link URL}.
- *
- * @param url
- * @return
- * @throws IOException
- */
- static ImageInputStream getInputStream(final URL url) throws IOException {
- Utilities.ensureNonNull("url", url);
- final ImageInputStream inStream = CACHED_STREAM_SPI
- .createInputStreamInstance(url, ImageIO.getUseCache(), ImageIO
- .getCacheDirectory());
- if (inStream == null)
- return null;
- return inStream;
- }
-
- /**
* Default priority for the underlying {@link Thread}.
*/
public static final int DEFAULT_PRIORITY = Thread.NORM_PRIORITY;
@@ -881,35 +840,67 @@
*/
public static boolean checkFileReadable(final File file) {
if (LOGGER.isLoggable(Level.FINE)) {
- final StringBuilder builder = new StringBuilder();
- builder.append("Checking file:").append(
- FilenameUtils.getFullPath(file.getAbsolutePath())).append(
- "\n");
- builder.append("canRead:").append(file.canRead()).append("\n");
- builder.append("isHidden:").append(file.isHidden()).append("\n");
- builder.append("isFile").append(file.isFile()).append("\n");
- builder.append("canWrite").append(file.canWrite()).append("\n");
- LOGGER.fine(builder.toString());
+ final String message = getFileInfo(file);
+ LOGGER.fine(message);
}
if (!file.exists() || !file.canRead() || !file.isFile())
return false;
return true;
}
+ /**
+ * Creates a human readable message that describe the provided {@link File} object in terms of its properties.
+ *
+ * <p>
+ * Useful for creating meaningful log messages.
+ *
+ * @param file the {@link File} object to create a descriptive message for
+ * @return a {@link String} containing a descriptive message about the provided {@link File}.
+ *
+ */
+ public static String getFileInfo(final File file) {
+ final StringBuilder builder = new StringBuilder();
+ builder.append("Checking file:").append(
+ FilenameUtils.getFullPath(file.getAbsolutePath())).append(
+ "\n");
+ builder.append("isHidden:").append(file.isHidden()).append("\n");
+ builder.append("exists:").append(file.exists()).append("\n");
+ builder.append("isFile").append(file.isFile()).append("\n");
+ builder.append("canRead:").append(file.canRead()).append("\n");
+ builder.append("canWrite").append(file.canWrite()).append("\n");
+ builder.append("canExecute:").append(file.canExecute()).append("\n");
+ builder.append("isAbsolute:").append(file.isAbsolute()).append("\n");
+ builder.append("lastModified:").append(file.lastModified()).append("\n");
+ builder.append("length:").append(file.length());
+ final String message=builder.toString();
+ return message;
+ }
+
/**
* @param testingDirecto...
[truncated message content] |
|
From: <svn...@os...> - 2012-01-21 14:20:00
|
Author: aaime
Date: 2012-01-21 06:19:53 -0800 (Sat, 21 Jan 2012)
New Revision: 38510
Added:
branches/2.7.x/modules/library/main/src/test/java/org/geotools/geometry/jts/PointIteratorTest.java
Modified:
branches/2.7.x/modules/library/main/src/main/java/org/geotools/geometry/jts/PointIterator.java
Log:
[GEOT-4001] JTS PointIterator just moving, not drawing (patch by Hajo Kliemeck)
Modified: branches/2.7.x/modules/library/main/src/main/java/org/geotools/geometry/jts/PointIterator.java
===================================================================
--- branches/2.7.x/modules/library/main/src/main/java/org/geotools/geometry/jts/PointIterator.java 2012-01-21 14:19:01 UTC (rev 38509)
+++ branches/2.7.x/modules/library/main/src/main/java/org/geotools/geometry/jts/PointIterator.java 2012-01-21 14:19:53 UTC (rev 38510)
@@ -40,6 +40,8 @@
/** True when the point has been read once */
private boolean done;
+ /** Current coordinate */
+ private boolean moved;
/**
* Creates a new PointIterator object.
@@ -55,6 +57,7 @@
this.at = at;
this.point = point;
done = false;
+ moved = false;
}
/**
@@ -77,18 +80,27 @@
* @see java.awt.geom.PathIterator#isDone()
*/
public boolean isDone() {
- return done;
+ return done && moved;
}
/**
* @see java.awt.geom.PathIterator#currentSegment(double[])
*/
public int currentSegment(double[] coords) {
- coords[0] = point.getX();
- coords[1] = point.getY();
- at.transform(coords, 0, coords, 0, 1);
+ if (!done && !moved) {
+ coords[0] = point.getX();
+ coords[1] = point.getY();
+ at.transform(coords, 0, coords, 0, 1);
- return SEG_MOVETO;
+ return SEG_MOVETO;
+ } else {
+ coords[0] = point.getX();
+ coords[1] = point.getY();
+ at.transform(coords, 0, coords, 0, 1);
+
+ moved = true;
+ return SEG_LINETO;
+ }
}
}
Added: branches/2.7.x/modules/library/main/src/test/java/org/geotools/geometry/jts/PointIteratorTest.java
===================================================================
--- branches/2.7.x/modules/library/main/src/test/java/org/geotools/geometry/jts/PointIteratorTest.java (rev 0)
+++ branches/2.7.x/modules/library/main/src/test/java/org/geotools/geometry/jts/PointIteratorTest.java 2012-01-21 14:19:53 UTC (rev 38510)
@@ -0,0 +1,35 @@
+package org.geotools.geometry.jts;
+
+import static org.junit.Assert.*;
+
+import java.awt.geom.AffineTransform;
+import java.awt.geom.PathIterator;
+
+import org.junit.Test;
+
+import com.vividsolutions.jts.geom.Point;
+import com.vividsolutions.jts.io.WKTReader;
+
+public class PointIteratorTest {
+
+
+ @Test
+ public void testPointIteration() throws Exception {
+ Point p = (Point) new WKTReader().read("POINT(1 10)");
+ AffineTransform at = AffineTransform.getScaleInstance(2, 2);
+ PointIterator it = new PointIterator(p, at);
+ double[] coords = new double[2];
+
+
+ assertFalse(it.isDone());
+ assertEquals(PathIterator.SEG_MOVETO, it.currentSegment(coords));
+ assertEquals(2.0, coords[0], 0d);
+ assertEquals(20.0, coords[1], 0d);
+ assertFalse(it.isDone());
+ it.next();
+ assertEquals(PathIterator.SEG_LINETO, it.currentSegment(coords));
+ assertEquals(2.0, coords[0], 0d);
+ assertEquals(20.0, coords[1], 0d);
+ assertTrue(it.isDone());
+ }
+}
|
|
From: <svn...@os...> - 2012-01-21 14:19:09
|
Author: aaime
Date: 2012-01-21 06:19:01 -0800 (Sat, 21 Jan 2012)
New Revision: 38509
Added:
trunk/modules/library/main/src/test/java/org/geotools/geometry/jts/PointIteratorTest.java
Modified:
trunk/modules/library/main/src/main/java/org/geotools/geometry/jts/PointIterator.java
Log:
[GEOT-4001] JTS PointIterator just moving, not drawing (patch by Hajo Kliemeck)
Modified: trunk/modules/library/main/src/main/java/org/geotools/geometry/jts/PointIterator.java
===================================================================
--- trunk/modules/library/main/src/main/java/org/geotools/geometry/jts/PointIterator.java 2012-01-21 11:58:28 UTC (rev 38508)
+++ trunk/modules/library/main/src/main/java/org/geotools/geometry/jts/PointIterator.java 2012-01-21 14:19:01 UTC (rev 38509)
@@ -41,6 +41,8 @@
/** True when the point has been read once */
private boolean done;
+ /** Current coordinate */
+ private boolean moved;
/**
* Creates a new PointIterator object.
@@ -56,6 +58,7 @@
this.at = at;
this.point = point;
done = false;
+ moved = false;
}
/**
@@ -78,18 +81,27 @@
* @see java.awt.geom.PathIterator#isDone()
*/
public boolean isDone() {
- return done;
+ return done && moved;
}
/**
* @see java.awt.geom.PathIterator#currentSegment(double[])
*/
public int currentSegment(double[] coords) {
- coords[0] = point.getX();
- coords[1] = point.getY();
- at.transform(coords, 0, coords, 0, 1);
+ if (!done && !moved) {
+ coords[0] = point.getX();
+ coords[1] = point.getY();
+ at.transform(coords, 0, coords, 0, 1);
- return SEG_MOVETO;
+ return SEG_MOVETO;
+ } else {
+ coords[0] = point.getX();
+ coords[1] = point.getY();
+ at.transform(coords, 0, coords, 0, 1);
+
+ moved = true;
+ return SEG_LINETO;
+ }
}
}
Added: trunk/modules/library/main/src/test/java/org/geotools/geometry/jts/PointIteratorTest.java
===================================================================
--- trunk/modules/library/main/src/test/java/org/geotools/geometry/jts/PointIteratorTest.java (rev 0)
+++ trunk/modules/library/main/src/test/java/org/geotools/geometry/jts/PointIteratorTest.java 2012-01-21 14:19:01 UTC (rev 38509)
@@ -0,0 +1,35 @@
+package org.geotools.geometry.jts;
+
+import static org.junit.Assert.*;
+
+import java.awt.geom.AffineTransform;
+import java.awt.geom.PathIterator;
+
+import org.junit.Test;
+
+import com.vividsolutions.jts.geom.Point;
+import com.vividsolutions.jts.io.WKTReader;
+
+public class PointIteratorTest {
+
+
+ @Test
+ public void testPointIteration() throws Exception {
+ Point p = (Point) new WKTReader().read("POINT(1 10)");
+ AffineTransform at = AffineTransform.getScaleInstance(2, 2);
+ PointIterator it = new PointIterator(p, at);
+ double[] coords = new double[2];
+
+
+ assertFalse(it.isDone());
+ assertEquals(PathIterator.SEG_MOVETO, it.currentSegment(coords));
+ assertEquals(2.0, coords[0], 0d);
+ assertEquals(20.0, coords[1], 0d);
+ assertFalse(it.isDone());
+ it.next();
+ assertEquals(PathIterator.SEG_LINETO, it.currentSegment(coords));
+ assertEquals(2.0, coords[0], 0d);
+ assertEquals(20.0, coords[1], 0d);
+ assertTrue(it.isDone());
+ }
+}
|
Author: aaime Date: 2012-01-21 03:58:28 -0800 (Sat, 21 Jan 2012) New Revision: 38508 Added: trunk/modules/library/api/src/main/java/org/geotools/styling/ResourceLocator.java Modified: trunk/modules/library/main/src/main/java/org/geotools/styling/SLDParser.java trunk/modules/library/main/src/test/java/org/geotools/styling/SLDParserTest.java Log: [GEOT-4000] Configurable resource locator in SLDParser (patch by Jan De Moerloose) Added: trunk/modules/library/api/src/main/java/org/geotools/styling/ResourceLocator.java =================================================================== --- trunk/modules/library/api/src/main/java/org/geotools/styling/ResourceLocator.java (rev 0) +++ trunk/modules/library/api/src/main/java/org/geotools/styling/ResourceLocator.java 2012-01-21 11:58:28 UTC (rev 38508) @@ -0,0 +1,35 @@ +/* + * GeoTools - The Open Source Java GIS Toolkit + * http://geotools.org + * + * (C) 2002-2008, Open Source Geospatial Foundation (OSGeo) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License. + * + * This library 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 + * Lesser General Public License for more details. + */ +package org.geotools.styling; + +import java.net.URL; + +/** + * Provides a hook to locate online resources in {@link ExternalGraphic} instances. To be used by parser implementors. + * + * @source $URL: http://svn.osgeo.org/geotools/tags/2.7.4/modules/library/api/src/main/java/org/geotools/styling/ResourceLocator.java $ + */ +public interface ResourceLocator { + + /** + * Locate the specified resource. + * + * @param uri uri of the resource + * @return the fully resolved URL of the resource or null, if the resource cannot be located. + */ + URL locateResource(String uri); +} Modified: trunk/modules/library/main/src/main/java/org/geotools/styling/SLDParser.java =================================================================== --- trunk/modules/library/main/src/main/java/org/geotools/styling/SLDParser.java 2012-01-21 11:57:16 UTC (rev 38507) +++ trunk/modules/library/main/src/main/java/org/geotools/styling/SLDParser.java 2012-01-21 11:58:28 UTC (rev 38508) @@ -114,6 +114,9 @@ /** useful for detecting relative onlineresources */ private URL sourceUrl; + + /** provides complete control for detecting relative onlineresources */ + private ResourceLocator onlineResourceLocator; /** * Create a Stylereader - use if you already have a dom to parse. @@ -128,6 +131,7 @@ public SLDParser(StyleFactory factory, FilterFactory filterFactory) { this.factory = factory; this.ff = filterFactory; + this. DefaultResourceLocator(); } /** @@ -276,6 +280,10 @@ public void setInput(java.io.Reader in) { source = new InputSource(in); } + + public void setOnLineResourceLocator(ResourceLocator onlineResourceLocator) { + this. + } /** * Read the xml inputsource provided and create a Style object for each user style found @@ -1659,26 +1667,7 @@ } } - URL url = null; - try { - url = new URL(uri); - } catch (MalformedURLException mfe) { - LOGGER.fine("Looks like " + uri + " is a relative path.."); - if (sourceUrl != null) { - try { - url = new URL(sourceUrl, uri); - } catch (MalformedURLException e) { - LOGGER.warning("can't parse " + uri + " as relative to" - + sourceUrl.toExternalForm()); - } - } - if (url == null) - { - url = getClass().getResource(uri); - if (url == null) - LOGGER.warning("can't parse " + uri + " as a java resource present in the classpath"); - } - } + URL url = onlineResourceLocator.locateResource(uri); ExternalGraphic extgraph; if (url == null) { @@ -2364,4 +2353,39 @@ return halo; } + + /** + * Default locator for online resources. Searches by absolute URL, relative + * path w.r.t. to SLD document or classpath. + * + * @author Jan De Moerloose + * + */ + class DefaultResourceLocator implements ResourceLocator { + + public URL locateResource(String uri) { + URL url = null; + try { + url = new URL(uri); + } catch (MalformedURLException mfe) { + LOGGER.fine("Looks like " + uri + " is a relative path.."); + if (sourceUrl != null) { + try { + url = new URL(sourceUrl, uri); + } catch (MalformedURLException e) { + LOGGER.warning("can't parse " + uri + " as relative to" + + sourceUrl.toExternalForm()); + } + } + if (url == null) + { + url = getClass().getResource(uri); + if (url == null) + LOGGER.warning("can't parse " + uri + " as a java resource present in the classpath"); + } + } + return url; + } + + } } Modified: trunk/modules/library/main/src/test/java/org/geotools/styling/SLDParserTest.java =================================================================== --- trunk/modules/library/main/src/test/java/org/geotools/styling/SLDParserTest.java 2012-01-21 11:57:16 UTC (rev 38507) +++ trunk/modules/library/main/src/test/java/org/geotools/styling/SLDParserTest.java 2012-01-21 11:58:28 UTC (rev 38508) @@ -21,8 +21,12 @@ import java.io.ByteArrayInputStream; import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; import java.util.List; +import junit.framework.Assert; + import org.geotools.factory.CommonFactoryFinder; import org.junit.Test; import org.opengis.style.GraphicalSymbol; @@ -76,6 +80,36 @@ " </UserStyle>\n" + "</StyledLayerDescriptor>"; + static String SLD_EXTERNAL_GRAPHIC = + "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + + "<StyledLayerDescriptor version=\"1.0.0\" \n" + + " xsi:schemaLocation=\"http://www.opengis.net/sld StyledLayerDescriptor.xsd\" \n" + + " xmlns=\"http://www.opengis.net/sld\" xmlns:ogc=\"http://www.opengis.net/ogc\" \n" + + " xmlns:xlink=\"http://www.w3.org/1999/xlink\" \n" + + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n" + + " <UserStyle>\n" + + " <Name>Default Styler</Name>\n" + + " <Title>Default Styler</Title>\n" + + " <Abstract></Abstract>\n" + + " <FeatureTypeStyle>\n" + + " <FeatureTypeName>Feature</FeatureTypeName>\n" + + " <Rule>\n" + + " <PointSymbolizer>\n" + + " <Graphic>\n" + + " <ExternalGraphic>\n" + + " <OnlineResource xlink:type=\"simple\"\n" + + " xlink:href=\"test-data/blob.gif\">\n" + + " </OnlineResource>\n" + + " <Format>image/png</Format>\n" + + " </ExternalGraphic>\n" + + " <Size>20</Size>\n" + + " </Graphic>\n" + + " </PointSymbolizer>\n" + + " </Rule>\n" + + " </FeatureTypeStyle>\n" + + " </UserStyle>\n" + + "</StyledLayerDescriptor>"; + static StyleFactory styleFactory = CommonFactoryFinder.getStyleFactory(null); @Test @@ -122,6 +156,33 @@ assertEquals(mark, CommonFactoryFinder.getStyleFactory(null).createMark()); } + @Test + public void testOnlineResourceLocator() throws MalformedURLException { + // test whether the configured resolver is called and the url is used correctly + SLDParser parser = new SLDParser(styleFactory, input(SLD_EXTERNAL_GRAPHIC)); + parser.setOnLineResourceLocator(new ResourceLocator() { + + public URL locateResource(String uri) { + Assert.assertEquals("test-data/blob.gif", uri); + return getClass().getResource(uri); + } + }); + Style[] styles = parser.readXML(); + assertEquals(1, styles.length); + List<FeatureTypeStyle> fts = styles[0].featureTypeStyles(); + assertEquals(1, fts.size()); + List<Rule> rules = fts.get(0).rules(); + assertEquals(1, rules.size()); + List<Symbolizer> symbolizers = rules.get(0).symbolizers(); + assertEquals(1, symbolizers.size()); + PointSymbolizer ps = (PointSymbolizer) symbolizers.get(0); + // here we would have had two instead of one + List<GraphicalSymbol> graphicalSymbols = ps.getGraphic().graphicalSymbols(); + assertEquals(1, graphicalSymbols.size()); + ExternalGraphic graphic = (ExternalGraphic) graphicalSymbols.get(0); + assertEquals(getClass().getResource("test-data/blob.gif"), graphic.getLocation()); + } + void assertStyles(Style[] styles) { assertEquals(1, styles.length); assertEquals("style", styles[0].getName()); |
Author: aaime Date: 2012-01-21 03:57:16 -0800 (Sat, 21 Jan 2012) New Revision: 38507 Added: branches/2.7.x/modules/library/api/src/main/java/org/geotools/styling/ResourceLocator.java Modified: branches/2.7.x/modules/library/main/src/main/java/org/geotools/styling/SLDParser.java branches/2.7.x/modules/library/main/src/test/java/org/geotools/styling/SLDParserTest.java Log: [GEOT-4000] Configurable resource locator in SLDParser (patch by Jan De Moerloose) Added: branches/2.7.x/modules/library/api/src/main/java/org/geotools/styling/ResourceLocator.java =================================================================== --- branches/2.7.x/modules/library/api/src/main/java/org/geotools/styling/ResourceLocator.java (rev 0) +++ branches/2.7.x/modules/library/api/src/main/java/org/geotools/styling/ResourceLocator.java 2012-01-21 11:57:16 UTC (rev 38507) @@ -0,0 +1,35 @@ +/* + * GeoTools - The Open Source Java GIS Toolkit + * http://geotools.org + * + * (C) 2002-2008, Open Source Geospatial Foundation (OSGeo) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License. + * + * This library 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 + * Lesser General Public License for more details. + */ +package org.geotools.styling; + +import java.net.URL; + +/** + * Provides a hook to locate online resources in {@link ExternalGraphic} instances. To be used by parser implementors. + * + * @source $URL: http://svn.osgeo.org/geotools/tags/2.7.4/modules/library/api/src/main/java/org/geotools/styling/ResourceLocator.java $ + */ +public interface ResourceLocator { + + /** + * Locate the specified resource. + * + * @param uri uri of the resource + * @return the fully resolved URL of the resource or null, if the resource cannot be located. + */ + URL locateResource(String uri); +} Modified: branches/2.7.x/modules/library/main/src/main/java/org/geotools/styling/SLDParser.java =================================================================== --- branches/2.7.x/modules/library/main/src/main/java/org/geotools/styling/SLDParser.java 2012-01-21 11:12:52 UTC (rev 38506) +++ branches/2.7.x/modules/library/main/src/main/java/org/geotools/styling/SLDParser.java 2012-01-21 11:57:16 UTC (rev 38507) @@ -110,6 +110,9 @@ /** useful for detecting relative onlineresources */ private URL sourceUrl; + + /** provides complete control for detecting relative onlineresources */ + private ResourceLocator onlineResourceLocator; /** * Create a Stylereader - use if you already have a dom to parse. @@ -124,6 +127,7 @@ public SLDParser(StyleFactory factory, FilterFactory filterFactory) { this.factory = factory; this.ff = filterFactory; + this. DefaultResourceLocator(); } /** @@ -272,6 +276,10 @@ public void setInput(java.io.Reader in) { source = new InputSource(in); } + + public void setOnLineResourceLocator(ResourceLocator onlineResourceLocator) { + this. + } /** * Read the xml inputsource provided and create a Style object for each user style found @@ -1634,26 +1642,7 @@ } } - URL url = null; - try { - url = new URL(uri); - } catch (MalformedURLException mfe) { - LOGGER.fine("Looks like " + uri + " is a relative path.."); - if (sourceUrl != null) { - try { - url = new URL(sourceUrl, uri); - } catch (MalformedURLException e) { - LOGGER.warning("can't parse " + uri + " as relative to" - + sourceUrl.toExternalForm()); - } - } - if (url == null) - { - url = getClass().getResource(uri); - if (url == null) - LOGGER.warning("can't parse " + uri + " as a java resource present in the classpath"); - } - } + URL url = onlineResourceLocator.locateResource(uri); ExternalGraphic extgraph; if (url == null) { @@ -2339,4 +2328,39 @@ return halo; } + + /** + * Default locator for online resources. Searches by absolute URL, relative + * path w.r.t. to SLD document or classpath. + * + * @author Jan De Moerloose + * + */ + class DefaultResourceLocator implements ResourceLocator { + + public URL locateResource(String uri) { + URL url = null; + try { + url = new URL(uri); + } catch (MalformedURLException mfe) { + LOGGER.fine("Looks like " + uri + " is a relative path.."); + if (sourceUrl != null) { + try { + url = new URL(sourceUrl, uri); + } catch (MalformedURLException e) { + LOGGER.warning("can't parse " + uri + " as relative to" + + sourceUrl.toExternalForm()); + } + } + if (url == null) + { + url = getClass().getResource(uri); + if (url == null) + LOGGER.warning("can't parse " + uri + " as a java resource present in the classpath"); + } + } + return url; + } + + } } Modified: branches/2.7.x/modules/library/main/src/test/java/org/geotools/styling/SLDParserTest.java =================================================================== --- branches/2.7.x/modules/library/main/src/test/java/org/geotools/styling/SLDParserTest.java 2012-01-21 11:12:52 UTC (rev 38506) +++ branches/2.7.x/modules/library/main/src/test/java/org/geotools/styling/SLDParserTest.java 2012-01-21 11:57:16 UTC (rev 38507) @@ -21,8 +21,12 @@ import java.io.ByteArrayInputStream; import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; import java.util.List; +import junit.framework.Assert; + import org.geotools.factory.CommonFactoryFinder; import org.junit.Test; import org.opengis.style.GraphicalSymbol; @@ -71,6 +75,36 @@ " </UserStyle>\n" + "</StyledLayerDescriptor>"; + static String SLD_EXTERNAL_GRAPHIC = + "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + + "<StyledLayerDescriptor version=\"1.0.0\" \n" + + " xsi:schemaLocation=\"http://www.opengis.net/sld StyledLayerDescriptor.xsd\" \n" + + " xmlns=\"http://www.opengis.net/sld\" xmlns:ogc=\"http://www.opengis.net/ogc\" \n" + + " xmlns:xlink=\"http://www.w3.org/1999/xlink\" \n" + + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n" + + " <UserStyle>\n" + + " <Name>Default Styler</Name>\n" + + " <Title>Default Styler</Title>\n" + + " <Abstract></Abstract>\n" + + " <FeatureTypeStyle>\n" + + " <FeatureTypeName>Feature</FeatureTypeName>\n" + + " <Rule>\n" + + " <PointSymbolizer>\n" + + " <Graphic>\n" + + " <ExternalGraphic>\n" + + " <OnlineResource xlink:type=\"simple\"\n" + + " xlink:href=\"test-data/blob.gif\">\n" + + " </OnlineResource>\n" + + " <Format>image/png</Format>\n" + + " </ExternalGraphic>\n" + + " <Size>20</Size>\n" + + " </Graphic>\n" + + " </PointSymbolizer>\n" + + " </Rule>\n" + + " </FeatureTypeStyle>\n" + + " </UserStyle>\n" + + "</StyledLayerDescriptor>"; + static StyleFactory styleFactory = CommonFactoryFinder.getStyleFactory(null); @Test @@ -117,6 +151,33 @@ assertEquals(mark, CommonFactoryFinder.getStyleFactory(null).createMark()); } + @Test + public void testOnlineResourceLocator() throws MalformedURLException { + // test whether the configured resolver is called and the url is used correctly + SLDParser parser = new SLDParser(styleFactory, input(SLD_EXTERNAL_GRAPHIC)); + parser.setOnLineResourceLocator(new ResourceLocator() { + + public URL locateResource(String uri) { + Assert.assertEquals("test-data/blob.gif", uri); + return getClass().getResource(uri); + } + }); + Style[] styles = parser.readXML(); + assertEquals(1, styles.length); + List<FeatureTypeStyle> fts = styles[0].featureTypeStyles(); + assertEquals(1, fts.size()); + List<Rule> rules = fts.get(0).rules(); + assertEquals(1, rules.size()); + List<Symbolizer> symbolizers = rules.get(0).symbolizers(); + assertEquals(1, symbolizers.size()); + PointSymbolizer ps = (PointSymbolizer) symbolizers.get(0); + // here we would have had two instead of one + List<GraphicalSymbol> graphicalSymbols = ps.getGraphic().graphicalSymbols(); + assertEquals(1, graphicalSymbols.size()); + ExternalGraphic graphic = (ExternalGraphic) graphicalSymbols.get(0); + assertEquals(getClass().getResource("test-data/blob.gif"), graphic.getLocation()); + } + void assertStyles(Style[] styles) { assertEquals(1, styles.length); assertEquals("style", styles[0].getName()); |
|
From: <svn...@os...> - 2012-01-21 11:12:58
|
Author: aaime
Date: 2012-01-21 03:12:52 -0800 (Sat, 21 Jan 2012)
New Revision: 38506
Added:
trunk/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerUuidTest.java
trunk/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerUuidTestSetup.java
Modified:
trunk/modules/plugin/jdbc/jdbc-sqlserver/src/main/java/org/geotools/data/sqlserver/SQLServerDialect.java
Log:
[GEOT-4023] Add support for uuid type in sql server
Modified: trunk/modules/plugin/jdbc/jdbc-sqlserver/src/main/java/org/geotools/data/sqlserver/SQLServerDialect.java
===================================================================
--- trunk/modules/plugin/jdbc/jdbc-sqlserver/src/main/java/org/geotools/data/sqlserver/SQLServerDialect.java 2012-01-21 11:11:39 UTC (rev 38505)
+++ trunk/modules/plugin/jdbc/jdbc-sqlserver/src/main/java/org/geotools/data/sqlserver/SQLServerDialect.java 2012-01-21 11:12:52 UTC (rev 38506)
@@ -25,6 +25,7 @@
import java.sql.Time;
import java.sql.Types;
import java.util.Map;
+import java.util.UUID;
import org.geotools.data.jdbc.FilterToSQL;
import org.geotools.geometry.jts.ReferencedEnvelope;
@@ -35,7 +36,6 @@
import org.opengis.feature.type.AttributeDescriptor;
import org.opengis.feature.type.GeometryDescriptor;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
-import org.opengis.referencing.crs.ProjectedCRS;
import org.opengis.referencing.cs.CoordinateSystem;
import com.vividsolutions.jts.geom.Envelope;
@@ -88,6 +88,7 @@
mappings.put( "geometry", Geometry.class );
+ mappings.put( "uniqueidentifier", UUID.class );
}
@Override
@@ -172,7 +173,8 @@
if ( rs.next() ) {
return rs.getInt( 1 );
}
- return -1;
+ // the default sql server srid
+ return 0;
}
finally {
dataStore.closeSafe( rs );
Added: trunk/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerUuidTest.java
===================================================================
--- trunk/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerUuidTest.java (rev 0)
+++ trunk/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerUuidTest.java 2012-01-21 11:12:52 UTC (rev 38506)
@@ -0,0 +1,13 @@
+package org.geotools.data.sqlserver;
+
+import org.geotools.jdbc.JDBCUuidTest;
+import org.geotools.jdbc.JDBCUuidTestSetup;
+
+public class SQLServerUuidTest extends JDBCUuidTest {
+
+ @Override
+ protected JDBCUuidTestSetup createTestSetup() {
+ return new SQLServerUuidTestSetup();
+ }
+
+}
Added: trunk/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerUuidTestSetup.java
===================================================================
--- trunk/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerUuidTestSetup.java (rev 0)
+++ trunk/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerUuidTestSetup.java 2012-01-21 11:12:52 UTC (rev 38506)
@@ -0,0 +1,28 @@
+package org.geotools.data.sqlserver;
+
+import org.geotools.jdbc.JDBCUuidTestSetup;
+
+public class SQLServerUuidTestSetup extends JDBCUuidTestSetup {
+
+ protected SQLServerUuidTestSetup() {
+ super(new SQLServerTestSetup());
+ }
+
+ @Override
+ protected void createUuidTable() throws Exception {
+ run( "CREATE TABLE \"guid\" ( \"id\" int identity(0, 1) PRIMARY KEY, \"uuidProperty\" uniqueidentifier)" );
+ run( "INSERT INTO \"guid\" (\"uuidProperty\") VALUES ('" + uuid1 + "')");
+ run( "INSERT INTO \"guid\" (\"uuidProperty\") VALUES ('" + uuid2 + "')");
+
+ /*
+ * A table with UUID as primary key
+ */
+ run( "CREATE TABLE \"uuidt\" ( \"id\" uniqueidentifier PRIMARY KEY, \"the_geom\" geometry)" );
+ }
+
+ @Override
+ protected void dropUuidTable() throws Exception {
+ run("DROP TABLE \"guid\"");
+ run("DROP TABLE \"uuidt\"");
+ }
+}
|
|
From: <svn...@os...> - 2012-01-21 11:11:46
|
Author: aaime
Date: 2012-01-21 03:11:39 -0800 (Sat, 21 Jan 2012)
New Revision: 38505
Added:
branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerUuidTest.java
branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerUuidTestSetup.java
Modified:
branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/main/java/org/geotools/data/sqlserver/SQLServerDialect.java
Log:
[GEOT-4023] Add support for uuid type in sql server
Modified: branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/main/java/org/geotools/data/sqlserver/SQLServerDialect.java
===================================================================
--- branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/main/java/org/geotools/data/sqlserver/SQLServerDialect.java 2012-01-20 06:55:30 UTC (rev 38504)
+++ branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/main/java/org/geotools/data/sqlserver/SQLServerDialect.java 2012-01-21 11:11:39 UTC (rev 38505)
@@ -25,6 +25,7 @@
import java.sql.Time;
import java.sql.Types;
import java.util.Map;
+import java.util.UUID;
import org.geotools.data.jdbc.FilterToSQL;
import org.geotools.geometry.jts.ReferencedEnvelope;
@@ -35,7 +36,6 @@
import org.opengis.feature.type.AttributeDescriptor;
import org.opengis.feature.type.GeometryDescriptor;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
-import org.opengis.referencing.crs.ProjectedCRS;
import org.opengis.referencing.cs.CoordinateSystem;
import com.vividsolutions.jts.geom.Envelope;
@@ -87,6 +87,7 @@
mappings.put( "geometry", Geometry.class );
+ mappings.put( "uniqueidentifier", UUID.class );
}
@Override
@@ -171,7 +172,8 @@
if ( rs.next() ) {
return rs.getInt( 1 );
}
- return -1;
+ // the default sql server srid
+ return 0;
}
finally {
dataStore.closeSafe( rs );
Added: branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerUuidTest.java
===================================================================
--- branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerUuidTest.java (rev 0)
+++ branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerUuidTest.java 2012-01-21 11:11:39 UTC (rev 38505)
@@ -0,0 +1,13 @@
+package org.geotools.data.sqlserver;
+
+import org.geotools.jdbc.JDBCUuidTest;
+import org.geotools.jdbc.JDBCUuidTestSetup;
+
+public class SQLServerUuidTest extends JDBCUuidTest {
+
+ @Override
+ protected JDBCUuidTestSetup createTestSetup() {
+ return new SQLServerUuidTestSetup();
+ }
+
+}
Added: branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerUuidTestSetup.java
===================================================================
--- branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerUuidTestSetup.java (rev 0)
+++ branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerUuidTestSetup.java 2012-01-21 11:11:39 UTC (rev 38505)
@@ -0,0 +1,28 @@
+package org.geotools.data.sqlserver;
+
+import org.geotools.jdbc.JDBCUuidTestSetup;
+
+public class SQLServerUuidTestSetup extends JDBCUuidTestSetup {
+
+ protected SQLServerUuidTestSetup() {
+ super(new SQLServerTestSetup());
+ }
+
+ @Override
+ protected void createUuidTable() throws Exception {
+ run( "CREATE TABLE \"guid\" ( \"id\" int identity(0, 1) PRIMARY KEY, \"uuidProperty\" uniqueidentifier)" );
+ run( "INSERT INTO \"guid\" (\"uuidProperty\") VALUES ('" + uuid1 + "')");
+ run( "INSERT INTO \"guid\" (\"uuidProperty\") VALUES ('" + uuid2 + "')");
+
+ /*
+ * A table with UUID as primary key
+ */
+ run( "CREATE TABLE \"uuidt\" ( \"id\" uniqueidentifier PRIMARY KEY, \"the_geom\" geometry)" );
+ }
+
+ @Override
+ protected void dropUuidTable() throws Exception {
+ run("DROP TABLE \"guid\"");
+ run("DROP TABLE \"uuidt\"");
+ }
+}
|
|
From: <svn...@os...> - 2012-01-20 06:55:40
|
Author: bencaradocdavies Date: 2012-01-19 22:55:30 -0800 (Thu, 19 Jan 2012) New Revision: 38504 Removed: trunk/spike/mauro/ogr/.classpath trunk/spike/mauro/ogr/.project trunk/spike/mauro/ogr/.settings/org.eclipse.jdt.core.prefs Log: Removed Eclipse configuration files (these should be generated locally using mvn eclipse:eclipse) Deleted: trunk/spike/mauro/ogr/.classpath =================================================================== --- trunk/spike/mauro/ogr/.classpath 2012-01-19 17:27:22 UTC (rev 38503) +++ trunk/spike/mauro/ogr/.classpath 2012-01-20 06:55:30 UTC (rev 38504) @@ -1,31 +0,0 @@ -<classpath> - <classpathentry kind="src" path="src/main/java"/> - <classpathentry kind="src" path="src/main/resources" excluding="**/*.java"/> - <classpathentry kind="src" path="src/test/java" output="target/test-classes"/> - <classpathentry kind="src" path="src/test/resources" output="target/test-classes" excluding="**/*.java"/> - <classpathentry kind="output" path="target/classes"/> - <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> - <classpathentry kind="var" path="M2_REPO/com/nativelibs4java/bridj/0.6/bridj-0.6-c-only.jar"/> - <classpathentry kind="var" path="M2_REPO/commons-pool/commons-pool/1.5.4/commons-pool-1.5.4.jar" sourcepath="M2_REPO/commons-pool/commons-pool/1.5.4/commons-pool-1.5.4-sources.jar"/> - <classpathentry kind="var" path="M2_REPO/org/geotools/gt-api/8-SNAPSHOT/gt-api-8-SNAPSHOT.jar" sourcepath="M2_REPO/org/geotools/gt-api/8-SNAPSHOT/gt-api-8-SNAPSHOT-sources.jar"/> - <classpathentry kind="var" path="M2_REPO/org/geotools/gt-data/8-SNAPSHOT/gt-data-8-SNAPSHOT.jar" sourcepath="M2_REPO/org/geotools/gt-data/8-SNAPSHOT/gt-data-8-SNAPSHOT-sources.jar"/> - <classpathentry kind="var" path="M2_REPO/org/geotools/gt-epsg-hsql/8-SNAPSHOT/gt-epsg-hsql-8-SNAPSHOT.jar" sourcepath="M2_REPO/org/geotools/gt-epsg-hsql/8-SNAPSHOT/gt-epsg-hsql-8-SNAPSHOT-sources.jar"/> - <classpathentry kind="var" path="M2_REPO/org/geotools/gt-main/8-SNAPSHOT/gt-main-8-SNAPSHOT.jar" sourcepath="M2_REPO/org/geotools/gt-main/8-SNAPSHOT/gt-main-8-SNAPSHOT-sources.jar"/> - <classpathentry kind="var" path="M2_REPO/org/geotools/gt-metadata/8-SNAPSHOT/gt-metadata-8-SNAPSHOT.jar" sourcepath="M2_REPO/org/geotools/gt-metadata/8-SNAPSHOT/gt-metadata-8-SNAPSHOT-sources.jar"/> - <classpathentry kind="var" path="M2_REPO/org/geotools/gt-opengis/8-SNAPSHOT/gt-opengis-8-SNAPSHOT.jar" sourcepath="M2_REPO/org/geotools/gt-opengis/8-SNAPSHOT/gt-opengis-8-SNAPSHOT-sources.jar"/> - <classpathentry kind="var" path="M2_REPO/org/geotools/gt-referencing/8-SNAPSHOT/gt-referencing-8-SNAPSHOT.jar" sourcepath="M2_REPO/org/geotools/gt-referencing/8-SNAPSHOT/gt-referencing-8-SNAPSHOT-sources.jar"/> - <classpathentry kind="var" path="M2_REPO/org/geotools/gt-sample-data/8-SNAPSHOT/gt-sample-data-8-SNAPSHOT.jar" sourcepath="M2_REPO/org/geotools/gt-sample-data/8-SNAPSHOT/gt-sample-data-8-SNAPSHOT-sources.jar"/> - <classpathentry kind="var" path="M2_REPO/org/geotools/gt-shapefile/8-SNAPSHOT/gt-shapefile-8-SNAPSHOT.jar" sourcepath="M2_REPO/org/geotools/gt-shapefile/8-SNAPSHOT/gt-shapefile-8-SNAPSHOT-sources.jar"/> - <classpathentry kind="var" path="M2_REPO/hsqldb/hsqldb/1.8.0.7/hsqldb-1.8.0.7.jar"/> - <classpathentry kind="var" path="M2_REPO/javax/media/jai_core/1.1.3/jai_core-1.1.3.jar"/> - <classpathentry kind="var" path="M2_REPO/jdom/jdom/1.0/jdom-1.0.jar" sourcepath="M2_REPO/jdom/jdom/1.0/jdom-1.0-sources.jar"/> - <classpathentry kind="var" path="M2_REPO/net/java/dev/jsr-275/jsr-275/1.0-beta-2/jsr-275-1.0-beta-2.jar" sourcepath="M2_REPO/net/java/dev/jsr-275/jsr-275/1.0-beta-2/jsr-275-1.0-beta-2-sources.jar"/> - <classpathentry kind="var" path="M2_REPO/com/vividsolutions/jts/1.12/jts-1.12.jar" sourcepath="M2_REPO/com/vividsolutions/jts/1.12/jts-1.12-sources.jar"/> - <classpathentry kind="var" path="M2_REPO/junit/junit/4.4/junit-4.4.jar" sourcepath="M2_REPO/junit/junit/4.4/junit-4.4-sources.jar"> - <attributes> - <attribute value="jar:file:/home/mauro/.m2/repository/junit/junit/4.4/junit-4.4-javadoc.jar!/" name="javadoc_location"/> - </attributes> - </classpathentry> - <classpathentry kind="var" path="M2_REPO/java3d/vecmath/1.3.2/vecmath-1.3.2.jar"/> - <classpathentry kind="var" path="M2_REPO/xerces/xercesImpl/2.7.1/xercesImpl-2.7.1.jar"/> -</classpath> \ No newline at end of file Deleted: trunk/spike/mauro/ogr/.project =================================================================== --- trunk/spike/mauro/ogr/.project 2012-01-19 17:27:22 UTC (rev 38503) +++ trunk/spike/mauro/ogr/.project 2012-01-20 06:55:30 UTC (rev 38504) @@ -1,13 +0,0 @@ -<projectDescription> - <name>gt-ogr</name> - <comment>A datastore levearing OGR for reading/writing a slew of data formats</comment> - <projects/> - <buildSpec> - <buildCommand> - <name>org.eclipse.jdt.core.javabuilder</name> - </buildCommand> - </buildSpec> - <natures> - <nature>org.eclipse.jdt.core.javanature</nature> - </natures> -</projectDescription> \ No newline at end of file Deleted: trunk/spike/mauro/ogr/.settings/org.eclipse.jdt.core.prefs =================================================================== --- trunk/spike/mauro/ogr/.settings/org.eclipse.jdt.core.prefs 2012-01-19 17:27:22 UTC (rev 38503) +++ trunk/spike/mauro/ogr/.settings/org.eclipse.jdt.core.prefs 2012-01-20 06:55:30 UTC (rev 38504) @@ -1,5 +0,0 @@ -#Mon Nov 28 12:30:30 CET 2011 -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.source=1.6 -org.eclipse.jdt.core.compiler.compliance=1.6 |
|
From: <svn...@os...> - 2012-01-19 17:27:34
|
Author: aaime
Date: 2012-01-19 09:27:22 -0800 (Thu, 19 Jan 2012)
New Revision: 38503
Added:
branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerDateTest.java
branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerDateTestSetup.java
Modified:
branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/main/java/org/geotools/data/sqlserver/SQLServerFilterToSQL.java
Log:
[GEOT-4012] Implement date/datetime support for sql server on 2.7.x
Modified: branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/main/java/org/geotools/data/sqlserver/SQLServerFilterToSQL.java
===================================================================
--- branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/main/java/org/geotools/data/sqlserver/SQLServerFilterToSQL.java 2012-01-17 18:40:35 UTC (rev 38502)
+++ branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/main/java/org/geotools/data/sqlserver/SQLServerFilterToSQL.java 2012-01-19 17:27:22 UTC (rev 38503)
@@ -17,6 +17,8 @@
package org.geotools.data.sqlserver;
import java.io.IOException;
+import java.sql.Date;
+import java.text.SimpleDateFormat;
import org.geotools.data.jdbc.FilterToSQL;
import org.geotools.filter.FilterCapabilities;
@@ -163,4 +165,15 @@
return extraData;
}
+
+ static SimpleDateFormat DATETIME_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+
+ @Override
+ protected void writeLiteral(Object literal) throws IOException {
+ if (literal instanceof Date) {
+ out.write("'" + DATETIME_FORMAT.format(literal) + "'");
+ } else {
+ super.writeLiteral(literal);
+ }
+ }
}
Added: branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerDateTest.java
===================================================================
--- branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerDateTest.java (rev 0)
+++ branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerDateTest.java 2012-01-19 17:27:22 UTC (rev 38503)
@@ -0,0 +1,29 @@
+/*
+ * GeoTools - The Open Source Java GIS Toolkit
+ * http://geotools.org
+ *
+ * (C) 2002-2011, Open Source Geospatial Foundation (OSGeo)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ */
+package org.geotools.data.sqlserver;
+
+import org.geotools.jdbc.JDBCDateTest;
+import org.geotools.jdbc.JDBCDateTestSetup;
+
+public class SQLServerDateTest extends JDBCDateTest {
+
+ @Override
+ protected JDBCDateTestSetup createTestSetup() {
+ return new SQLServerDateTestSetup();
+ }
+
+}
\ No newline at end of file
Added: branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerDateTestSetup.java
===================================================================
--- branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerDateTestSetup.java (rev 0)
+++ branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerDateTestSetup.java 2012-01-19 17:27:22 UTC (rev 38503)
@@ -0,0 +1,52 @@
+/*
+ * GeoTools - The Open Source Java GIS Toolkit
+ * http://geotools.org
+ *
+ * (C) 2002-2011, Open Source Geospatial Foundation (OSGeo)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ */
+package org.geotools.data.sqlserver;
+
+import org.geotools.jdbc.JDBCDateTestSetup;
+
+public class SQLServerDateTestSetup extends JDBCDateTestSetup {
+
+ protected SQLServerDateTestSetup() {
+ super(new SQLServerTestSetup());
+ }
+
+ @Override
+ protected void createDateTable() throws Exception {
+ run( "CREATE TABLE dates (d DATE, dt DATETIME, t TIME)");
+
+ run( "INSERT INTO dates VALUES (" +
+ "CAST('2009-06-28' as DATE), " +
+ "CAST('2009-06-28 15:12:41' as DATETIME)," +
+ "CAST('15:12:41' as TIME) )");
+
+ run( "INSERT INTO dates VALUES (" +
+ "CAST('2009-01-15' as DATE), " +
+ "CAST('2009-01-15 13:10:12' as DATETIME)," +
+ "CAST('13:10:12' as TIME) )");
+
+ run( "INSERT INTO dates VALUES (" +
+ "CAST('2009-09-29' as DATE), " +
+ "CAST('2009-09-29 17:54:23' as DATETIME)," +
+ "CAST('17:54:23' as TIME) )");
+ }
+
+ @Override
+ protected void dropDateTable() throws Exception {
+ runSafe("DROP TABLE dates");
+ }
+
+}
\ No newline at end of file
|
|
From: <svn...@os...> - 2012-01-17 18:40:42
|
Author: aaime
Date: 2012-01-17 10:40:35 -0800 (Tue, 17 Jan 2012)
New Revision: 38502
Added:
branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerFeatureReaderTest.java
branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerFeatureSourceExposePkTest.java
branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerFeatureStoreExposedPkTest.java
branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerLobTest.java
branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerLobTestSetup.java
branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerNoPrimaryKeyTest.java
branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerNoPrimaryKeyTestSetup.java
branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerSkipColumnTest.java
branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerSkipColumnTestSetup.java
branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerViewTest.java
branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerViewTestSetup.java
branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerVirtualTableTest.java
Modified:
branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/main/java/org/geotools/data/sqlserver/SQLServerDialect.java
branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerDataStoreAPITestSetup.java
branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerPrimaryKeyTestSetup.java
branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerTestSetup.java
Log:
[GEOT-4021] Increase test coverage for SQL server store
Modified: branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/main/java/org/geotools/data/sqlserver/SQLServerDialect.java
===================================================================
--- branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/main/java/org/geotools/data/sqlserver/SQLServerDialect.java 2012-01-17 18:40:08 UTC (rev 38501)
+++ branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/main/java/org/geotools/data/sqlserver/SQLServerDialect.java 2012-01-17 18:40:35 UTC (rev 38502)
@@ -369,4 +369,19 @@
}
}
+ @Override
+ public void encodeValue(Object value, Class type, StringBuffer sql) {
+ if(byte[].class.equals(type)) {
+ byte[] b = (byte[]) value;
+
+ //encode as hex string
+ sql.append("0x");
+ for (int i=0; i < b.length; i++) {
+ sql.append(Integer.toString( ( b[i] & 0xff ) + 0x100, 16).substring( 1 ));
+ }
+ } else {
+ super.encodeValue(value, type, sql);
+ }
+ }
+
}
Modified: branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerDataStoreAPITestSetup.java
===================================================================
--- branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerDataStoreAPITestSetup.java 2012-01-17 18:40:08 UTC (rev 38501)
+++ branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerDataStoreAPITestSetup.java 2012-01-17 18:40:35 UTC (rev 38502)
@@ -34,6 +34,8 @@
+ "geometry::STGeomFromText('LINESTRING(3 0, 3 2, 3 3, 3 4)',4326)," + "'r2')");
run("INSERT INTO road (id,geom,name) VALUES ( 2,"
+ "geometry::STGeomFromText('LINESTRING(3 2, 4 2, 5 3)',4326)," + "'r3')");
+
+ run("CREATE SPATIAL INDEX _road_geometry_index on road(geom) WITH (BOUNDING_BOX = (-10, -10, 10, 10))");
}
@Override
@@ -46,6 +48,8 @@
+ "'rv1', 4.5)");
run("INSERT INTO river (id,geom,river, flow) VALUES ( 1,"
+ "geometry::STGeomFromText('MULTILINESTRING((4 6, 4 8, 6 10))',4326)," + "'rv2', 3.0)");
+
+ run("CREATE SPATIAL INDEX _river_geometry_index on river(geom) WITH (BOUNDING_BOX = (-10, -10, 10, 10))");
}
@Override
@@ -55,6 +59,8 @@
run("INSERT INTO lake (id,geom,name) VALUES ( 0,"
+ "geometry::STGeomFromText('POLYGON((12 6, 14 8, 16 6, 16 4, 14 4, 12 6))',4326)," + "'muddy')");
+
+ run("CREATE SPATIAL INDEX _lake_geometry_index on lake(geom) WITH (BOUNDING_BOX = (-100, -100, 100, 100))");
}
@Override
Added: branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerFeatureReaderTest.java
===================================================================
--- branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerFeatureReaderTest.java (rev 0)
+++ branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerFeatureReaderTest.java 2012-01-17 18:40:35 UTC (rev 38502)
@@ -0,0 +1,13 @@
+package org.geotools.data.sqlserver;
+
+import org.geotools.jdbc.JDBCFeatureReaderTest;
+import org.geotools.jdbc.JDBCTestSetup;
+
+public class SQLServerFeatureReaderTest extends JDBCFeatureReaderTest {
+
+ @Override
+ protected JDBCTestSetup createTestSetup() {
+ return new SQLServerTestSetup();
+ }
+
+}
Added: branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerFeatureSourceExposePkTest.java
===================================================================
--- branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerFeatureSourceExposePkTest.java (rev 0)
+++ branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerFeatureSourceExposePkTest.java 2012-01-17 18:40:35 UTC (rev 38502)
@@ -0,0 +1,13 @@
+package org.geotools.data.sqlserver;
+
+import org.geotools.jdbc.JDBCFeatureSourceExposePkTest;
+import org.geotools.jdbc.JDBCTestSetup;
+
+public class SQLServerFeatureSourceExposePkTest extends JDBCFeatureSourceExposePkTest {
+
+ @Override
+ protected JDBCTestSetup createTestSetup() {
+ return new SQLServerTestSetup();
+ }
+
+}
Added: branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerFeatureStoreExposedPkTest.java
===================================================================
--- branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerFeatureStoreExposedPkTest.java (rev 0)
+++ branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerFeatureStoreExposedPkTest.java 2012-01-17 18:40:35 UTC (rev 38502)
@@ -0,0 +1,63 @@
+package org.geotools.data.sqlserver;
+
+import java.io.IOException;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import org.geotools.data.Transaction;
+import org.geotools.jdbc.JDBCFeatureStoreExposePkTest;
+import org.geotools.jdbc.JDBCTestSetup;
+
+public class SQLServerFeatureStoreExposedPkTest extends JDBCFeatureStoreExposePkTest {
+
+ @Override
+ protected JDBCTestSetup createTestSetup() {
+ return new SQLServerTestSetup();
+ }
+
+ @Override
+ public void testAddInTransaction() throws IOException {
+ // does not work, see GEOT-2832
+ }
+
+ public void testAddFeaturesUseProvidedFid() throws IOException {
+ // cannot work in general since the primary column is an identity:
+ // - it is not possible to insert into an indentity column unless the IDENTITY_INSERT
+ // property is set on it
+ // - however if IDENTITY_INSERT is setup, then the column stops generating values and
+ // requires one to insert values manually, which breaks other tests
+ }
+
+ @Override
+ public void testExternalConnection() throws IOException, SQLException {
+ // MVCC is not enabled by default in SQL Server, to do that one has to
+ // use something like:
+ // ALTER DATABASE ' + DB_NAME() + ' SET SINGLE_USER WITH ROLLBACK IMMEDIATE ;
+ // ALTER DATABASE ' + DB_NAME() + ' SET READ_COMMITTED_SNAPSHOT ON;
+ // ALTER DATABASE ' + DB_NAME() + ' SET MULTI_USER;'
+ // However this requires having admin access to the database, so we cannot
+ // assume we can run it, thus we just check if it's possible at all
+ // When the above is set the test passes, verified against SQL Server 2008
+
+ Connection cx = null;
+ Statement st = null;
+ ResultSet rs = null;
+ try {
+ cx = dataStore.getConnection(Transaction.AUTO_COMMIT);
+ st = cx.createStatement();
+ rs = st.executeQuery("SELECT is_read_committed_snapshot_on FROM sys.databases WHERE name= db_name()");
+ if(rs.next()) {
+ if(rs.getBoolean(1)) {
+ super.testExternalConnection();
+ }
+ }
+ } finally {
+ dataStore.closeSafe(rs);
+ dataStore.closeSafe(st);
+ dataStore.closeSafe(cx);
+ }
+
+ }
+}
Added: branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerLobTest.java
===================================================================
--- branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerLobTest.java (rev 0)
+++ branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerLobTest.java 2012-01-17 18:40:35 UTC (rev 38502)
@@ -0,0 +1,13 @@
+package org.geotools.data.sqlserver;
+
+import org.geotools.jdbc.JDBCLobTest;
+import org.geotools.jdbc.JDBCLobTestSetup;
+
+public class SQLServerLobTest extends JDBCLobTest {
+
+ @Override
+ protected JDBCLobTestSetup createTestSetup() {
+ return new SQLServerLobTestSetup(new SQLServerTestSetup());
+ }
+
+}
Added: branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerLobTestSetup.java
===================================================================
--- branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerLobTestSetup.java (rev 0)
+++ branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerLobTestSetup.java 2012-01-17 18:40:35 UTC (rev 38502)
@@ -0,0 +1,37 @@
+package org.geotools.data.sqlserver;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+
+import org.geotools.jdbc.JDBCLobTestSetup;
+import org.geotools.jdbc.JDBCTestSetup;
+
+public class SQLServerLobTestSetup extends JDBCLobTestSetup {
+
+ protected SQLServerLobTestSetup(JDBCTestSetup delegate) {
+ super(delegate);
+ }
+
+ @Override
+ protected void createLobTable() throws Exception {
+
+ Connection con = getDataSource().getConnection();
+ con.prepareStatement("create table \"testlob\" (\"fid\" int identity(0, 1) primary key, " +
+ "\"blob_field\" VARBINARY(50), \"clob_field\" TEXT, \"raw_field\" VARBINARY(50))").execute();
+
+ PreparedStatement ps =con.prepareStatement( "INSERT INTO \"testlob\" (\"blob_field\",\"clob_field\",\"raw_field\") VALUES (?,?,?)");
+ ps.setBytes(1, new byte[] {1,2,3,4,5});
+ ps.setString(2, "small clob");
+ ps.setBytes(3, new byte[] {6,7,8,9,10});
+ ps.execute();
+ ps.close();
+ con.close();
+ }
+
+ @Override
+ protected void dropLobTable() throws Exception {
+ runSafe("DROP TABLE \"testlob\"");
+ }
+
+
+}
Added: branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerNoPrimaryKeyTest.java
===================================================================
--- branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerNoPrimaryKeyTest.java (rev 0)
+++ branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerNoPrimaryKeyTest.java 2012-01-17 18:40:35 UTC (rev 38502)
@@ -0,0 +1,13 @@
+package org.geotools.data.sqlserver;
+
+import org.geotools.jdbc.JDBCNoPrimaryKeyTest;
+import org.geotools.jdbc.JDBCNoPrimaryKeyTestSetup;
+
+public class SQLServerNoPrimaryKeyTest extends JDBCNoPrimaryKeyTest {
+
+ @Override
+ protected JDBCNoPrimaryKeyTestSetup createTestSetup() {
+ return new SQLServerNoPrimaryKeyTestSetup(new SQLServerTestSetup());
+ }
+
+}
Added: branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerNoPrimaryKeyTestSetup.java
===================================================================
--- branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerNoPrimaryKeyTestSetup.java (rev 0)
+++ branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerNoPrimaryKeyTestSetup.java 2012-01-17 18:40:35 UTC (rev 38502)
@@ -0,0 +1,30 @@
+package org.geotools.data.sqlserver;
+
+import org.geotools.jdbc.JDBCNoPrimaryKeyTestSetup;
+import org.geotools.jdbc.JDBCTestSetup;
+
+public class SQLServerNoPrimaryKeyTestSetup extends JDBCNoPrimaryKeyTestSetup {
+
+ protected SQLServerNoPrimaryKeyTestSetup(JDBCTestSetup delegate) {
+ super(delegate);
+ }
+
+ @Override
+ protected void createLakeTable() throws Exception {
+ run("CREATE TABLE \"lake\"(\"id\" int, "
+ + "\"geom\" geometry, \"name\" varchar(255) )");
+
+ run("INSERT INTO \"lake\" (\"id\",\"geom\",\"name\") VALUES (0,"
+ + "geometry::STGeomFromText('POLYGON((12 6, 14 8, 16 6, 16 4, 14 4, 12 6))',4326),"
+ + "'muddy')");
+
+ // can't do this, sql server requires a primary key to use spatial indexes
+ // run("CREATE SPATIAL INDEX _lake_geometry_index on lake(geom) WITH (BOUNDING_BOX = (-10, -10, 10, 10))");
+ }
+
+ @Override
+ protected void dropLakeTable() throws Exception {
+ runSafe("DROP TABLE \"lake\"");
+ }
+
+}
Modified: branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerPrimaryKeyTestSetup.java
===================================================================
--- branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerPrimaryKeyTestSetup.java 2012-01-17 18:40:08 UTC (rev 38501)
+++ branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerPrimaryKeyTestSetup.java 2012-01-17 18:40:35 UTC (rev 38502)
@@ -32,6 +32,8 @@
run( "INSERT INTO auto (name,geom ) VALUES ('one',geometry::STGeomFromText('POINT(1 1)',4326))");
run( "INSERT INTO auto (name,geom ) VALUES ('two',geometry::STGeomFromText('POINT(2 2)',4326))");
run( "INSERT INTO auto (name,geom ) VALUES ('three',geometry::STGeomFromText('POINT(3 3)',4326))");
+
+ run("CREATE SPATIAL INDEX _auto_geometry_index on auto(geom) WITH (BOUNDING_BOX = (-10, -10, 10, 10))");
}
@Override
@@ -46,6 +48,8 @@
run( "INSERT INTO noninc VALUES (1, 'one', geometry::STGeomFromText('POINT(1 1)',4326))");
run( "INSERT INTO noninc VALUES (2, 'two', geometry::STGeomFromText('POINT(2 2)',4326))");
run( "INSERT INTO noninc VALUES (3, 'three', geometry::STGeomFromText('POINT(3 3)',4326))");
+
+ run("CREATE SPATIAL INDEX _noninc_geometry_index on noninc(geom) WITH (BOUNDING_BOX = (-10, -10, 10, 10))");
}
@Override
@@ -57,6 +61,8 @@
run( "INSERT INTO multi VALUES (1, 'x', 'one', geometry::STGeomFromText('POINT(1 1)',4326))");
run( "INSERT INTO multi VALUES (2, 'y', 'two', geometry::STGeomFromText('POINT(2 2)',4326))");
run( "INSERT INTO multi VALUES (3, 'z', 'three', geometry::STGeomFromText('POINT(3 3)',4326))");
+
+ run("CREATE SPATIAL INDEX _multi_geometry_index on multi(geom) WITH (BOUNDING_BOX = (-10, -10, 10, 10))");
}
@Override
@@ -75,6 +81,9 @@
run( "INSERT INTO uniq VALUES (1, 'one',geometry::STGeomFromText('POINT(1 1)',4326))");
run( "INSERT INTO uniq VALUES (2, 'two',geometry::STGeomFromText('POINT(2 2)',4326))");
run( "INSERT INTO uniq VALUES (3, 'three',geometry::STGeomFromText('POINT(3 3)',4326))");
+
+ // spatial indexes in sql server require a primary key
+ // run("CREATE SPATIAL INDEX _uniq_geometry_index on uniq(geom) WITH (BOUNDING_BOX = (-10, -10, 10, 10))");
}
@Override
Added: branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerSkipColumnTest.java
===================================================================
--- branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerSkipColumnTest.java (rev 0)
+++ branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerSkipColumnTest.java 2012-01-17 18:40:35 UTC (rev 38502)
@@ -0,0 +1,22 @@
+package org.geotools.data.sqlserver;
+
+import org.geotools.geometry.jts.ReferencedEnvelope;
+import org.geotools.jdbc.JDBCSkipColumnTest;
+import org.geotools.jdbc.JDBCSkipColumnTestSetup;
+
+public class SQLServerSkipColumnTest extends JDBCSkipColumnTest {
+
+ @Override
+ protected JDBCSkipColumnTestSetup createTestSetup() {
+ return new SQLServerSkipColumnTestSetup();
+ }
+
+ public void testGetBounds() throws Exception {
+ // sql server does not return empty bounds for a single point, but a very smal one instead
+ ReferencedEnvelope env = dataStore.getFeatureSource(tname(SKIPCOLUMN)).getBounds();
+ assertEquals(0.0, env.getMinX(), 1e-6);
+ assertEquals(0.0, env.getMinY(), 1e-6);
+ assertEquals(0.0, env.getMaxX(), 1e-6);
+ assertEquals(0.0, env.getMaxY(), 1e-6);
+ }
+}
Added: branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerSkipColumnTestSetup.java
===================================================================
--- branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerSkipColumnTestSetup.java (rev 0)
+++ branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerSkipColumnTestSetup.java 2012-01-17 18:40:35 UTC (rev 38502)
@@ -0,0 +1,28 @@
+package org.geotools.data.sqlserver;
+
+import org.geotools.jdbc.JDBCSkipColumnTestSetup;
+
+public class SQLServerSkipColumnTestSetup extends JDBCSkipColumnTestSetup {
+
+ protected SQLServerSkipColumnTestSetup() {
+ super(new SQLServerTestSetup());
+ }
+
+ @Override
+ protected void createSkipColumnTable() throws Exception {
+ run("CREATE TABLE \"skipcolumn\"(" //
+ + "\"fid\" int identity(0, 1) primary key, " //
+ + "\"id\" integer, " //
+ + "\"geom\" geometry, " //
+ + "\"weirdproperty\" datetimeoffset," //
+ + "\"name\" varchar(255))");
+ run("INSERT INTO \"skipcolumn\" VALUES( 0, geometry::STGeomFromText('POINT(0 0)', 4326), null, 'GeoTools')");
+ }
+
+ @Override
+ protected void dropSkipColumnTable() throws Exception {
+ runSafe("DELETE FROM GEOMETRY_COLUMNS WHERE F_TABLE_NAME = 'skipcolumn'");
+ runSafe("DROP TABLE \"skipcolumn\"");
+ }
+
+}
Modified: branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerTestSetup.java
===================================================================
--- branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerTestSetup.java 2012-01-17 18:40:08 UTC (rev 38501)
+++ branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerTestSetup.java 2012-01-17 18:40:35 UTC (rev 38502)
@@ -81,6 +81,9 @@
sql = "INSERT INTO ft1 (geometry,intProperty,doubleProperty,stringProperty) VALUES ("
+ "geometry::STGeomFromText('POINT(2 2)',4326), 2, 2.2,'two');";
run(sql);
+
+ // create the spatial index
+ run("CREATE SPATIAL INDEX _ft1_geometry_index on ft1(geometry) WITH (BOUNDING_BOX = (-10, -10, 10, 10))");
}
@Override
Added: branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerViewTest.java
===================================================================
--- branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerViewTest.java (rev 0)
+++ branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerViewTest.java 2012-01-17 18:40:35 UTC (rev 38502)
@@ -0,0 +1,41 @@
+package org.geotools.data.sqlserver;
+
+import org.geotools.jdbc.JDBCViewTest;
+import org.geotools.jdbc.JDBCViewTestSetup;
+import org.opengis.feature.type.AttributeDescriptor;
+import org.opengis.feature.type.AttributeType;
+
+import com.vividsolutions.jts.geom.Geometry;
+
+public class SQLServerViewTest extends JDBCViewTest {
+
+ @Override
+ protected JDBCViewTestSetup createTestSetup() {
+ return new SQLServerViewTestSetup();
+ }
+
+
+ /**
+ * Override since sql server metadata over nullability over views works differently than in other databases
+ */
+ protected void assertAttributesEqual(AttributeDescriptor expected, AttributeDescriptor actual) {
+ assertEquals(aname(expected.getName()), actual.getName());
+ // assertEquals(expected.getMinOccurs(), actual.getMinOccurs());
+ assertEquals(expected.getMaxOccurs(), actual.getMaxOccurs());
+ // assertEquals(expected.isNillable(), actual.isNillable());
+ assertEquals(expected.getDefaultValue(), actual.getDefaultValue());
+
+ AttributeType texpected = expected.getType();
+ AttributeType tactual = actual.getType();
+
+ if ( Number.class.isAssignableFrom( texpected.getBinding() ) ) {
+ assertTrue( Number.class.isAssignableFrom( tactual.getBinding() ) );
+ }
+ else if ( Geometry.class.isAssignableFrom( texpected.getBinding())) {
+ assertTrue( Geometry.class.isAssignableFrom( tactual.getBinding()));
+ }
+ else {
+ assertTrue(texpected.getBinding().isAssignableFrom(tactual.getBinding()));
+ }
+ }
+}
Added: branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerViewTestSetup.java
===================================================================
--- branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerViewTestSetup.java (rev 0)
+++ branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerViewTestSetup.java 2012-01-17 18:40:35 UTC (rev 38502)
@@ -0,0 +1,50 @@
+package org.geotools.data.sqlserver;
+
+import org.geotools.jdbc.JDBCViewTestSetup;
+
+public class SQLServerViewTestSetup extends JDBCViewTestSetup {
+
+ protected SQLServerViewTestSetup() {
+ super(new SQLServerTestSetup());
+ }
+
+ @Override
+ protected void createLakesTable() throws Exception {
+ run("CREATE TABLE lakes(fid int IDENTITY(0,1) PRIMARY KEY, id int, "
+ + "geom geometry, name varchar(255) )");
+
+ run("INSERT INTO lakes (id,geom,name) VALUES ( 0,"
+ + "geometry::STGeomFromText('POLYGON((12 6, 14 8, 16 6, 16 4, 14 4, 12 6))',4326),"
+ + "'muddy')");
+
+ run("CREATE SPATIAL INDEX _lakes_geometry_index on lakes(geom) WITH (BOUNDING_BOX = (-100, -100, 100, 100))");
+ }
+
+ @Override
+ protected void dropLakesTable() throws Exception {
+ runSafe("DROP TABLE \"lakes\"");
+ }
+
+ @Override
+ protected void createLakesView() throws Exception {
+ run("create view \"lakesview\" as select * from \"lakes\"");
+ }
+
+ @Override
+ protected void dropLakesView() throws Exception {
+ runSafe("DROP VIEW \"lakesview\"");
+ }
+
+ @Override
+ protected void createLakesViewPk() throws Exception {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ protected void dropLakesViewPk() throws Exception {
+ // TODO Auto-generated method stub
+
+ }
+
+}
Added: branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerVirtualTableTest.java
===================================================================
--- branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerVirtualTableTest.java (rev 0)
+++ branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerVirtualTableTest.java 2012-01-17 18:40:35 UTC (rev 38502)
@@ -0,0 +1,14 @@
+package org.geotools.data.sqlserver;
+
+import org.geotools.jdbc.JDBCDataStoreAPITestSetup;
+import org.geotools.jdbc.JDBCVirtualTableTest;
+
+
+public class SQLServerVirtualTableTest extends JDBCVirtualTableTest {
+
+ @Override
+ protected JDBCDataStoreAPITestSetup createTestSetup() {
+ return new SQLServerDataStoreAPITestSetup();
+ }
+
+}
|
|
From: <svn...@os...> - 2012-01-17 18:40:19
|
Author: aaime
Date: 2012-01-17 10:40:08 -0800 (Tue, 17 Jan 2012)
New Revision: 38501
Modified:
branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/main/java/org/geotools/data/sqlserver/SQLServerDialect.java
Log:
[GEOT-4019] Support native paging in sql server
Modified: branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/main/java/org/geotools/data/sqlserver/SQLServerDialect.java
===================================================================
--- branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/main/java/org/geotools/data/sqlserver/SQLServerDialect.java 2012-01-17 18:39:53 UTC (rev 38500)
+++ branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/main/java/org/geotools/data/sqlserver/SQLServerDialect.java 2012-01-17 18:40:08 UTC (rev 38501)
@@ -328,4 +328,45 @@
}
}
+ @Override
+ public boolean isLimitOffsetSupported() {
+ return true;
+ }
+
+ @Override
+ public void applyLimitOffset(StringBuffer sql, int limit, int offset) {
+ // if we have a nested query (used in sql views) we might have a inner order by,
+ // check for the last closed )
+ int lastClosed = sql.lastIndexOf(")");
+ int orderByIndex = sql.lastIndexOf("ORDER BY");
+ CharSequence orderBy;
+ if(orderByIndex > 0 && orderByIndex > lastClosed) {
+ // we'll move the order by into the ROW_NUMBER call
+ orderBy = sql.subSequence(orderByIndex, sql.length());
+ sql.delete(orderByIndex, orderByIndex + orderBy.length());
+ } else {
+ // ROW_NUMBER requires an order by clause, we need to feed it something
+ orderBy = "ORDER BY CURRENT_TIMESTAMP";
+ }
+
+ // now insert the order by inside the select
+ int fromStart = sql.indexOf("FROM");
+ sql.insert(fromStart - 1, ", ROW_NUMBER() OVER (" + orderBy + ") AS _GT_ROW_NUMBER ");
+
+ // and wrap inside a block that selects the portion we want
+ sql.insert(0, "SELECT * FROM (");
+ sql.append(") AS _GT_PAGING_SUBQUERY WHERE ");
+ if(offset > 0) {
+ sql.append("_GT_ROW_NUMBER > " + offset);
+ }
+ if(limit >= 0 && limit < Integer.MAX_VALUE) {
+ int max = limit;
+ if(offset > 0) {
+ max += offset;
+ sql.append(" AND ");
+ }
+ sql.append("_GT_ROW_NUMBER <= " + max);
+ }
+ }
+
}
|
|
From: <svn...@os...> - 2012-01-17 18:40:04
|
Author: aaime
Date: 2012-01-17 10:39:53 -0800 (Tue, 17 Jan 2012)
New Revision: 38500
Modified:
branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/main/java/org/geotools/data/sqlserver/SQLServerDialect.java
Log:
[GEOT-4020] Have SQL server store use WKB for geometry transfers
Modified: branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/main/java/org/geotools/data/sqlserver/SQLServerDialect.java
===================================================================
--- branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/main/java/org/geotools/data/sqlserver/SQLServerDialect.java 2012-01-17 17:14:52 UTC (rev 38499)
+++ branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/main/java/org/geotools/data/sqlserver/SQLServerDialect.java 2012-01-17 18:39:53 UTC (rev 38500)
@@ -42,6 +42,7 @@
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.GeometryFactory;
import com.vividsolutions.jts.io.ParseException;
+import com.vividsolutions.jts.io.WKBReader;
import com.vividsolutions.jts.io.WKTReader;
/**
@@ -58,7 +59,7 @@
public SQLServerDialect(JDBCDataStore dataStore) {
super(dataStore);
}
-
+
@Override
public boolean includeTable(String schemaName, String tableName,
Connection cx) throws SQLException {
@@ -183,17 +184,8 @@
@Override
public void encodeGeometryColumn(GeometryDescriptor gatt, int srid, StringBuffer sql) {
- sql.append( "CAST(");
encodeColumnName( gatt.getLocalName(), sql );
- sql.append( ".STSrid as VARCHAR)");
-
- sql.append( " + ':' + " );
-
- encodeColumnName( gatt.getLocalName(), sql );
- sql.append( ".STAsText()");
-
- //encodeColumnName(gatt.getLocalName(), sql);
- //sql.append( ".STAsText()");
+ sql.append( ".STAsBinary()");
}
@Override
@@ -212,8 +204,15 @@
public Geometry decodeGeometryValue(GeometryDescriptor descriptor,
ResultSet rs, String column, GeometryFactory factory, Connection cx)
throws IOException, SQLException {
- String s = rs.getString( column );
- return decodeGeometry ( s, factory );
+ byte[] bytes = rs.getBytes(column);
+ if(bytes == null) {
+ return null;
+ }
+ try {
+ return new WKBReader(factory).read(bytes);
+ } catch ( ParseException e ) {
+ throw (IOException) new IOException().initCause( e );
+ }
}
Geometry decodeGeometry( String s, GeometryFactory factory ) throws IOException {
@@ -328,4 +327,5 @@
sql.append(tableName);
}
}
+
}
|