Issue #2667 make exception of not handling data type the norm, so that not every data type has to override those methods.

Change-Id: I68072bead09f153f0b6b8c459822c4924a0a0988

Former-commit-id: a067b0017d2f214d3ca3a866be69d74816351baa
This commit is contained in:
Matt Nash 2014-01-14 15:30:24 -06:00
parent af83c0cf87
commit 93c132b630
6 changed files with 61 additions and 76 deletions

View file

@ -28,6 +28,11 @@ import java.util.Map;
import com.raytheon.uf.common.dataaccess.IDataFactory; import com.raytheon.uf.common.dataaccess.IDataFactory;
import com.raytheon.uf.common.dataaccess.IDataRequest; import com.raytheon.uf.common.dataaccess.IDataRequest;
import com.raytheon.uf.common.dataaccess.exception.InvalidIdentifiersException; import com.raytheon.uf.common.dataaccess.exception.InvalidIdentifiersException;
import com.raytheon.uf.common.dataaccess.exception.UnsupportedOutputTypeException;
import com.raytheon.uf.common.dataaccess.geom.IGeometryData;
import com.raytheon.uf.common.dataaccess.grid.IGridData;
import com.raytheon.uf.common.time.DataTime;
import com.raytheon.uf.common.time.TimeRange;
/** /**
* *
@ -44,7 +49,8 @@ import com.raytheon.uf.common.dataaccess.exception.InvalidIdentifiersException;
* Feb 14, 2013 1614 bsteffen Refactor data access framework to use * Feb 14, 2013 1614 bsteffen Refactor data access framework to use
* single request. * single request.
* Feb 19, 2012 1552 mpduff Implement IDataFactory. * Feb 19, 2012 1552 mpduff Implement IDataFactory.
* * Jan 14, 2014 2667 mnash Change getGridData and getGeometryData methods
* to throw exception by default
* </pre> * </pre>
* *
* @author njensen * @author njensen
@ -104,4 +110,39 @@ public abstract class AbstractDataFactory implements IDataFactory {
} }
} }
/**
* Default implementation throws an {@link UnsupportedOutputTypeException}
*/
@Override
public IGridData[] getGridData(IDataRequest request, DataTime... times) {
throw new UnsupportedOutputTypeException(request.getDatatype(), "grid");
}
/**
* Default implementation throws an {@link UnsupportedOutputTypeException}
*/
public IGridData[] getGridData(IDataRequest request, TimeRange timeRange) {
throw new UnsupportedOutputTypeException(request.getDatatype(), "grid");
}
/**
* Default implementation throws an {@link UnsupportedOutputTypeException}
*/
@Override
public IGeometryData[] getGeometryData(IDataRequest request,
DataTime... times) {
throw new UnsupportedOutputTypeException(request.getDatatype(),
"geometry");
}
/**
* Default implementation throws an {@link UnsupportedOutputTypeException}
*/
@Override
public IGeometryData[] getGeometryData(IDataRequest request,
TimeRange timeRange) {
throw new UnsupportedOutputTypeException(request.getDatatype(),
"geometry");
}
} }

View file

@ -27,6 +27,7 @@ import java.util.Map;
import com.raytheon.uf.common.dataaccess.IDataRequest; import com.raytheon.uf.common.dataaccess.IDataRequest;
import com.raytheon.uf.common.dataaccess.exception.DataRetrievalException; import com.raytheon.uf.common.dataaccess.exception.DataRetrievalException;
import com.raytheon.uf.common.dataaccess.exception.TimeAgnosticDataException; import com.raytheon.uf.common.dataaccess.exception.TimeAgnosticDataException;
import com.raytheon.uf.common.dataaccess.exception.UnsupportedOutputTypeException;
import com.raytheon.uf.common.dataaccess.geom.IGeometryData; import com.raytheon.uf.common.dataaccess.geom.IGeometryData;
import com.raytheon.uf.common.dataaccess.grid.IGridData; import com.raytheon.uf.common.dataaccess.grid.IGridData;
import com.raytheon.uf.common.dataquery.requests.DbQueryRequest; import com.raytheon.uf.common.dataquery.requests.DbQueryRequest;
@ -53,7 +54,8 @@ import com.raytheon.uf.common.time.TimeRange;
* Feb 14, 2013 1614 bsteffen Refactor data access framework to use * Feb 14, 2013 1614 bsteffen Refactor data access framework to use
* single request. * single request.
* Nov 26, 2013 2537 bsteffen Fix NPEs for dataTimes and timeRange requests. * Nov 26, 2013 2537 bsteffen Fix NPEs for dataTimes and timeRange requests.
* * Jan 14, 2014 2667 mnash Change getGridData and getGeometryData methods
* to throw exception by default
* *
* </pre> * </pre>
* *
@ -61,8 +63,7 @@ import com.raytheon.uf.common.time.TimeRange;
* @version 1.0 * @version 1.0
*/ */
public abstract class AbstractDataPluginFactory public abstract class AbstractDataPluginFactory extends AbstractDataFactory {
extends AbstractDataFactory {
protected static final String FIELD_DATATIME = "dataTime"; protected static final String FIELD_DATATIME = "dataTime";
@ -269,15 +270,18 @@ public abstract class AbstractDataPluginFactory
return dbQueryRequest; return dbQueryRequest;
} }
protected abstract IGridData[] getGridData(IDataRequest request, protected IGridData[] getGridData(IDataRequest request,
DbQueryResponse dbQueryResponse); DbQueryResponse dbQueryResponse) {
throw new UnsupportedOutputTypeException(request.getDatatype(), "grid");
}
protected abstract IGeometryData[] getGeometryData(IDataRequest request, protected IGeometryData[] getGeometryData(IDataRequest request,
DbQueryResponse dbQueryResponse); DbQueryResponse dbQueryResponse) {
throw new UnsupportedOutputTypeException(request.getDatatype(),
"geometry");
}
protected abstract Map<String, RequestConstraint> buildConstraintsFromRequest( protected abstract Map<String, RequestConstraint> buildConstraintsFromRequest(
IDataRequest request); IDataRequest request);
} }

View file

@ -29,9 +29,7 @@ import com.raytheon.uf.common.dataaccess.IDataFactory;
import com.raytheon.uf.common.dataaccess.IDataRequest; import com.raytheon.uf.common.dataaccess.IDataRequest;
import com.raytheon.uf.common.dataaccess.exception.DataRetrievalException; import com.raytheon.uf.common.dataaccess.exception.DataRetrievalException;
import com.raytheon.uf.common.dataaccess.exception.TimeAgnosticDataException; import com.raytheon.uf.common.dataaccess.exception.TimeAgnosticDataException;
import com.raytheon.uf.common.dataaccess.exception.UnsupportedOutputTypeException;
import com.raytheon.uf.common.dataaccess.geom.IGeometryData; import com.raytheon.uf.common.dataaccess.geom.IGeometryData;
import com.raytheon.uf.common.dataaccess.grid.IGridData;
import com.raytheon.uf.common.dataaccess.util.DatabaseQueryUtil; import com.raytheon.uf.common.dataaccess.util.DatabaseQueryUtil;
import com.raytheon.uf.common.dataaccess.util.DatabaseQueryUtil.QUERY_MODE; import com.raytheon.uf.common.dataaccess.util.DatabaseQueryUtil.QUERY_MODE;
import com.raytheon.uf.common.dataplugin.level.Level; import com.raytheon.uf.common.dataplugin.level.Level;
@ -54,7 +52,7 @@ import com.vividsolutions.jts.geom.Geometry;
* Jan 29, 2013 bkowal Initial creation * Jan 29, 2013 bkowal Initial creation
* Feb 14, 2013 1614 bsteffen Refactor data access framework to use * Feb 14, 2013 1614 bsteffen Refactor data access framework to use
* single request. * single request.
* * Jan 14, 2014 2667 mnash Remove getGridData methods
* </pre> * </pre>
* *
* @author bkowal * @author bkowal
@ -151,16 +149,6 @@ public abstract class AbstractGeometryDatabaseFactory extends
request); request);
} }
@Override
public IGridData[] getGridData(IDataRequest request, DataTime... times) {
throw new UnsupportedOutputTypeException(request.getDatatype(), "grid");
}
@Override
public IGridData[] getGridData(IDataRequest request, TimeRange timeRange) {
throw new UnsupportedOutputTypeException(request.getDatatype(), "grid");
}
/** /**
* Runs a query to retrieve Data Times from the database. * Runs a query to retrieve Data Times from the database.
* *

View file

@ -27,8 +27,6 @@ import org.geotools.coverage.grid.GridGeometry2D;
import com.raytheon.uf.common.dataaccess.IDataRequest; import com.raytheon.uf.common.dataaccess.IDataRequest;
import com.raytheon.uf.common.dataaccess.exception.DataRetrievalException; import com.raytheon.uf.common.dataaccess.exception.DataRetrievalException;
import com.raytheon.uf.common.dataaccess.exception.UnsupportedOutputTypeException;
import com.raytheon.uf.common.dataaccess.geom.IGeometryData;
import com.raytheon.uf.common.dataaccess.grid.IGridData; import com.raytheon.uf.common.dataaccess.grid.IGridData;
import com.raytheon.uf.common.dataaccess.util.PDOUtil; import com.raytheon.uf.common.dataaccess.util.PDOUtil;
import com.raytheon.uf.common.dataplugin.PluginDataObject; import com.raytheon.uf.common.dataplugin.PluginDataObject;
@ -49,7 +47,7 @@ import com.raytheon.uf.common.datastorage.records.IDataRecord;
* Jan 17, 2013 bsteffen Initial creation * Jan 17, 2013 bsteffen Initial creation
* Feb 14, 2013 1614 bsteffen Refactor data access framework to use * Feb 14, 2013 1614 bsteffen Refactor data access framework to use
* single request. * single request.
* * Jan 14, 2014 2667 mnash Remove getGeometryData methods
* </pre> * </pre>
* *
* @author bsteffen * @author bsteffen
@ -82,8 +80,7 @@ public abstract class AbstractGridDataPluginFactory extends
"The objects returned by the DbQueryRequest are not of type PluginDataObject as expected."); "The objects returned by the DbQueryRequest are not of type PluginDataObject as expected.");
} }
PluginDataObject pdo = (PluginDataObject) resultMap PluginDataObject pdo = (PluginDataObject) resultMap.get(null);
.get(null);
IDataRecord dataRecord = getDataRecord(pdo); IDataRecord dataRecord = getDataRecord(pdo);
@ -102,14 +99,6 @@ public abstract class AbstractGridDataPluginFactory extends
return gridData.toArray(new IGridData[gridData.size()]); return gridData.toArray(new IGridData[gridData.size()]);
} }
protected IGeometryData[] getGeometryData(IDataRequest request,
DbQueryResponse dbQueryResponse) {
// Subtypes can optionally support geometry by overriding this, default
// is to not support geometry data.
throw new UnsupportedOutputTypeException(request.getDatatype(),
"geometry");
}
protected IDataRecord getDataRecord(PluginDataObject pdo) { protected IDataRecord getDataRecord(PluginDataObject pdo) {
try { try {
return PDOUtil.getDataRecord(pdo, "Data", Request.ALL); return PDOUtil.getDataRecord(pdo, "Data", Request.ALL);
@ -142,5 +131,4 @@ public abstract class AbstractGridDataPluginFactory extends
IDataRequest request, PluginDataObject pdo, IDataRequest request, PluginDataObject pdo,
GridGeometry2D gridGeometry, IDataRecord dataRecord); GridGeometry2D gridGeometry, IDataRecord dataRecord);
} }

View file

@ -28,9 +28,7 @@ import javax.measure.unit.Unit;
import com.raytheon.uf.common.dataaccess.IDataRequest; import com.raytheon.uf.common.dataaccess.IDataRequest;
import com.raytheon.uf.common.dataaccess.exception.DataRetrievalException; import com.raytheon.uf.common.dataaccess.exception.DataRetrievalException;
import com.raytheon.uf.common.dataaccess.exception.UnsupportedOutputTypeException;
import com.raytheon.uf.common.dataaccess.geom.IGeometryData; import com.raytheon.uf.common.dataaccess.geom.IGeometryData;
import com.raytheon.uf.common.dataaccess.grid.IGridData;
import com.raytheon.uf.common.dataaccess.impl.AbstractDataPluginFactory; import com.raytheon.uf.common.dataaccess.impl.AbstractDataPluginFactory;
import com.raytheon.uf.common.dataaccess.impl.DefaultGeometryData; import com.raytheon.uf.common.dataaccess.impl.DefaultGeometryData;
import com.raytheon.uf.common.dataaccess.util.DatabaseQueryUtil; import com.raytheon.uf.common.dataaccess.util.DatabaseQueryUtil;
@ -67,6 +65,7 @@ import com.vividsolutions.jts.geom.Geometry;
* Apr 16, 2013 1912 bsteffen Initial bulk hdf5 access for ffmp * Apr 16, 2013 1912 bsteffen Initial bulk hdf5 access for ffmp
* Jul 15, 2013 2184 dhladky Remove all HUC's for storage except ALL * Jul 15, 2013 2184 dhladky Remove all HUC's for storage except ALL
* Aug,20, 2013 2250 mnash Change some methods that were not working in all cases * Aug,20, 2013 2250 mnash Change some methods that were not working in all cases
* Jan,14, 2014 2667 mnash Remove getGridData method
* *
* </pre> * </pre>
* *
@ -105,17 +104,6 @@ public class FFMPGeometryFactory extends AbstractDataPluginFactory {
public FFMPGeometryFactory() { public FFMPGeometryFactory() {
} }
/**
* Not Supported.
*/
@Override
protected IGridData[] getGridData(IDataRequest request,
DbQueryResponse dbQueryResponse) {
// Not currently handled
throw new UnsupportedOutputTypeException(request.getDatatype(),
PLUGIN_NAME);
}
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */

View file

@ -36,17 +36,14 @@ import com.raytheon.uf.common.comm.CommunicationException;
import com.raytheon.uf.common.dataaccess.DataAccessLayer; import com.raytheon.uf.common.dataaccess.DataAccessLayer;
import com.raytheon.uf.common.dataaccess.IDataRequest; import com.raytheon.uf.common.dataaccess.IDataRequest;
import com.raytheon.uf.common.dataaccess.exception.DataRetrievalException; import com.raytheon.uf.common.dataaccess.exception.DataRetrievalException;
import com.raytheon.uf.common.dataaccess.exception.UnsupportedOutputTypeException;
import com.raytheon.uf.common.dataaccess.geom.IGeometryData; import com.raytheon.uf.common.dataaccess.geom.IGeometryData;
import com.raytheon.uf.common.dataaccess.geom.IGeometryData.Type; import com.raytheon.uf.common.dataaccess.geom.IGeometryData.Type;
import com.raytheon.uf.common.dataaccess.grid.IGridData;
import com.raytheon.uf.common.dataaccess.impl.AbstractDataPluginFactory; import com.raytheon.uf.common.dataaccess.impl.AbstractDataPluginFactory;
import com.raytheon.uf.common.dataaccess.impl.DefaultGeometryData; import com.raytheon.uf.common.dataaccess.impl.DefaultGeometryData;
import com.raytheon.uf.common.dataplugin.level.LevelFactory; import com.raytheon.uf.common.dataplugin.level.LevelFactory;
import com.raytheon.uf.common.dataplugin.level.MasterLevel; import com.raytheon.uf.common.dataplugin.level.MasterLevel;
import com.raytheon.uf.common.dataquery.requests.DbQueryRequest; import com.raytheon.uf.common.dataquery.requests.DbQueryRequest;
import com.raytheon.uf.common.dataquery.requests.RequestConstraint; import com.raytheon.uf.common.dataquery.requests.RequestConstraint;
import com.raytheon.uf.common.dataquery.responses.DbQueryResponse;
import com.raytheon.uf.common.pointdata.PointDataConstants; import com.raytheon.uf.common.pointdata.PointDataConstants;
import com.raytheon.uf.common.pointdata.PointDataContainer; import com.raytheon.uf.common.pointdata.PointDataContainer;
import com.raytheon.uf.common.pointdata.PointDataDescription; import com.raytheon.uf.common.pointdata.PointDataDescription;
@ -69,7 +66,7 @@ import com.vividsolutions.jts.geom.GeometryFactory;
* ------------- -------- ----------- -------------------------- * ------------- -------- ----------- --------------------------
* Oct 31, 2013 2502 bsteffen Initial creation * Oct 31, 2013 2502 bsteffen Initial creation
* Nov 26, 2013 2537 bsteffen Minor code cleanup. * Nov 26, 2013 2537 bsteffen Minor code cleanup.
* * Jan,14, 2014 2667 mnash Remove getGridData method
* </pre> * </pre>
* *
* @author bsteffen * @author bsteffen
@ -145,27 +142,6 @@ public class PointDataAccessFactory extends AbstractDataPluginFactory {
return getGeometryData(request, dbQueryRequest); return getGeometryData(request, dbQueryRequest);
} }
@Override
protected IGeometryData[] getGeometryData(IDataRequest request,
DbQueryResponse dbQueryResponse) {
/*
* Since the public getGeometryData methods have been overriden, this is
* now unreachable code, but since it is an abstract method in the super
* class it must be implemented.
*/
throw new UnsupportedOperationException(
"This method should be unreachable");
}
@Override
protected IGridData[] getGridData(IDataRequest request,
DbQueryResponse dbQueryResponse) {
/*
* Point data cannot be gridded, so don't even try.
*/
throw new UnsupportedOutputTypeException(request.getDatatype(), "grid");
}
@Override @Override
protected Map<String, RequestConstraint> buildConstraintsFromRequest( protected Map<String, RequestConstraint> buildConstraintsFromRequest(
IDataRequest request) { IDataRequest request) {
@ -208,7 +184,7 @@ public class PointDataAccessFactory extends AbstractDataPluginFactory {
"Unable to complete the PointDataRequestMessage for request: " "Unable to complete the PointDataRequestMessage for request: "
+ request, e); + request, e);
} }
if(pdc == null){ if (pdc == null) {
return new IGeometryData[0]; return new IGeometryData[0];
} }
LevelFactory lf = LevelFactory.getInstance(); LevelFactory lf = LevelFactory.getInstance();