Ticket #133: 0001-Fix-handling-of-simultaneous-requests-in-petascope-t.patch

File 0001-Fix-handling-of-simultaneous-requests-in-petascope-t.patch, 9.3 KB (added by Dimitar Misev, 12 years ago)
  • applications/petascope/src/main/java/petascope/core/DbMetadataSource.java

    From 8dd1c7ed6c6d05e296befdacad83ac006887c10b Mon Sep 17 00:00:00 2001
    From: Dimitar Misev <misev@rasdaman.com>
    Date: Wed, 16 Jan 2013 19:20:46 +0100
    Subject: [PATCH] Fix handling of simultaneous requests in petascope (ticket
     133)
    
    ---
     .../main/java/petascope/core/DbMetadataSource.java |   43 +++++---------------
     .../src/main/java/petascope/core/Metadata.java     |    9 ++++
     .../src/main/java/petascope/util/WcsUtil.java      |    7 ++++
     .../wcs2/extensions/GmlFormatExtension.java        |   16 --------
     .../wcs2/handlers/DescribeCoverageHandler.java     |   11 -----
     5 files changed, 26 insertions(+), 60 deletions(-)
    
    diff --git a/applications/petascope/src/main/java/petascope/core/DbMetadataSource.java b/applications/petascope/src/main/java/petascope/core/DbMetadataSource.java
    index db8f7a0..e115e0e 100644
    a b public class DbMetadataSource implements IMetadataSource {  
    451451            ensureConnection();
    452452            s = conn.createStatement();
    453453
    454             ResultSet r = s.executeQuery("SELECT id, type, nullDefault, interpolationTypeDefault, nullResistanceDefault FROM PS_Coverage WHERE name = '" + coverageName + "'");
     454            ResultSet r = null;
     455                r = s.executeQuery("SELECT id, type, nullDefault, interpolationTypeDefault, nullResistanceDefault FROM PS_Coverage WHERE name = '" + coverageName + "'");
    455456
    456457            if (!r.next()) {
    457458                throw new PetascopeException(ExceptionCode.InvalidRequest,
    public class DbMetadataSource implements IMetadataSource {  
    630631            } else if (twoDCoverage) {
    631632                log.warn(" Bounding box missing for 2-D coverage '" + coverageName + "'...");
    632633            }
     634           
     635            r = s.executeQuery("SELECT metadata FROM ps_metadata WHERE coverage in "
     636                     + "(SELECT id FROM ps_coverage WHERE name = '" + coverage + "')");
     637            String metadata = "";
     638            if (r.next()) {
     639                metadata = r.getString("metadata");
     640            }
    633641
    634642            /* Done with SQL statements */
    635643            s.close();
    public class DbMetadataSource implements IMetadataSource {  
    639647                    new InterpolationMethod(interpolationTypeDefault, nullResistanceDefault),
    640648                    coverageName, coverageType, domain, bbox, title, abstr, keywords);
    641649            meta.setCoverageId(coverage);
     650            meta.setMetadata(metadata);
    642651            log.trace("Caching coverage metadata.");
    643652            cache.put(coverageName, meta);
    644653            return meta;
    public class DbMetadataSource implements IMetadataSource {  
    10541063        }
    10551064    }
    10561065   
    1057     /**
    1058      * Given the CoverageID; returns image metadata
    1059      * @param coverageId
    1060      * @return textual metadata
    1061      * @throws PetascopeException
    1062      */
    1063     public String getImageMetadata(String coverageId) throws PetascopeException {
    1064         Statement s = null;
    1065         try {
    1066             ensureConnection();
    1067             s = conn.createStatement();
    1068             ResultSet r = s.executeQuery("SELECT metadata FROM ps_metadata WHERE coverage in "
    1069                      + "(SELECT id FROM ps_coverage WHERE name = '" + coverageId + "')");
    1070             if (r.next()) {
    1071                 return r.getString("metadata");
    1072             } else {
    1073                 return "";
    1074             }
    1075         } catch (SQLException sqle) {
    1076             throw new PetascopeException(ExceptionCode.ResourceError,
    1077                     "Error retrieving metadata for coverage " + coverageId, sqle);
    1078         } finally {
    1079             if (s != null) {
    1080                 try {
    1081                     s.close();
    1082                 } catch (SQLException f) {
    1083                 }
    1084             }
    1085             close();
    1086         }
    1087     }
    1088 
    10891066    /** Insert metadata for a new coverage.
    10901067     *
    10911068     * @param meta Metadata object, container of information
  • applications/petascope/src/main/java/petascope/core/Metadata.java

    diff --git a/applications/petascope/src/main/java/petascope/core/Metadata.java b/applications/petascope/src/main/java/petascope/core/Metadata.java
    index 49581ff..fb78bd0 100644
    a b public class Metadata implements Cloneable {  
    6363    private Bbox bbox = null;
    6464    private CellDomainElement cellX, cellY, cellT;
    6565    private DomainElement domX, domY, domT;
     66    private String metadata;
    6667
    6768    public Metadata(List<CellDomainElement> cellDomain, List<RangeElement> range,
    6869            Set<String> nullSet, String nullDefault, Set<InterpolationMethod> interpolationSet,
    public class Metadata implements Cloneable {  
    683684        BigInteger big = cellT.getHi().subtract(cellT.getLo());
    684685        return big.longValue();
    685686    }
     687
     688    public String getMetadata() {
     689        return metadata;
     690    }
     691
     692    public void setMetadata(String metadata) {
     693        this.metadata = metadata;
     694    }
    686695}
  • applications/petascope/src/main/java/petascope/util/WcsUtil.java

    diff --git a/applications/petascope/src/main/java/petascope/util/WcsUtil.java b/applications/petascope/src/main/java/petascope/util/WcsUtil.java
    index a9a65a3..623f0b6 100644
    a b public class WcsUtil {  
    183183                    Pair.of("\\{code\\}", range.getUomCode()));
    184184        }
    185185
     186        String metadata = m.getMetadata().getMetadata();
     187        if (metadata == null) {
     188            metadata = "<gmlcov:metadata>" + metadata + "</gmlcov:metadata>";
     189        } else {
     190            metadata = "";
     191        }
    186192        String ret = Templates.getTemplate(template,
    187193                Pair.of("\\{coverageId\\}", m.getCoverageId()),
    188194                Pair.of("\\{coverageType\\}", m.getCoverageType()),
    public class WcsUtil {  
    199205                Pair.of("\\{srsName\\}", getSrsName(m)),
    200206                Pair.of("\\{lowerCorner\\}", getLowerCorner(m)),
    201207                Pair.of("\\{upperCorner\\}", getUpperCorner(m)),
     208                Pair.of("\\{metadata\\}", metadata),
    202209                Pair.of("\\{additions\\}", getAdditions(m)));
    203210
    204211        if (replaceBounds) {
  • applications/petascope/src/main/java/petascope/wcs2/extensions/GmlFormatExtension.java

    diff --git a/applications/petascope/src/main/java/petascope/wcs2/extensions/GmlFormatExtension.java b/applications/petascope/src/main/java/petascope/wcs2/extensions/GmlFormatExtension.java
    index a0ae976..980bad7 100644
    a b public class GmlFormatExtension extends AbstractFormatExtension {  
    7272        //Handle the range subset feature
    7373        RangeSubsettingExtension rsubExt = (RangeSubsettingExtension) ExtensionsRegistry.getExtension(ExtensionsRegistry.RANGE_SUBSETTING_IDENTIFIER);
    7474        rsubExt.handle(request, m);
    75         String metadata = "";
    76         try {
    77             metadata = meta.getImageMetadata(request.getCoverageId());
    78         } catch (PetascopeException p) {
    79             throw new WCSException(ExceptionCode.ResourceError, p);
    80         }
    8175       
    8276        if (m.getCoverageType().equals(GetCoverageRequest.MULTIPOINT_COVERAGE)) {
    8377            Response r = handleMultiPoint(request, request.getCoverageId(), meta, m);
    8478            String xml = r.getXml();
    85             if (!metadata.isEmpty()) {
    86                 xml = xml.replace("{metadata}", "<gmlcov:metadata>" + metadata + "</gmlcov:metadata>");
    87             } else {
    88                 xml = xml.replace("{metadata}", "");
    89             }
    9079            return new Response(r.getData(), xml, r.getMimeType());
    9180        }
    9281       
    9382        setBounds(request, m, meta);
    9483        String gml = WcsUtil.getGML(m, Templates.GRID_COVERAGE, true);
    9584        gml = addCoverageData(gml, request, meta, m);
    96         if (!metadata.isEmpty()) {
    97             gml = gml.replace("{metadata}", "<gmlcov:metadata>" + metadata + "</gmlcov:metadata>");
    98         } else {
    99             gml = gml.replace("{metadata}", "");
    100         }
    10185        return new Response(gml);
    10286    }
    10387   
  • applications/petascope/src/main/java/petascope/wcs2/handlers/DescribeCoverageHandler.java

    diff --git a/applications/petascope/src/main/java/petascope/wcs2/handlers/DescribeCoverageHandler.java b/applications/petascope/src/main/java/petascope/wcs2/handlers/DescribeCoverageHandler.java
    index 10aff65..cc80b77 100644
    a b public class DescribeCoverageHandler extends AbstractRequestHandler<DescribeCove  
    8080            if (exc != null) {
    8181                continue;
    8282            }
    83             String metadata = "";
    84             try {
    85                 metadata = meta.getImageMetadata(coverageId);
    86             } catch (PetascopeException p) {
    87                 throw new WCSException(ExceptionCode.ResourceError, p);
    88             }
    89             if (!metadata.isEmpty()) {
    90                 descr = descr.replace("{metadata}", "<gmlcov:metadata>" + metadata + "</gmlcov:metadata>");
    91             } else {
    92                 descr = descr.replace("{metadata}", "");
    93             }
    9483            try {
    9584                root.appendChild(XMLUtil.buildDocument(null, descr).getRootElement().copy());
    9685            } catch (Exception ex) {