GeoTools
  1. GeoTools
  2. GEOT-1348

PostGIS createSchema method fails when asked to represent a String.class

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 2.3.1, 2.3.2, 2.4-M3
    • Fix Version/s: 2.2.3, 2.4-M4
    • Component/s: jdbc-postgis plugin
    • Labels:
      None
    • Environment:
      This problem was reported against 2.3.1 with postgresql + postgis 8.2.

      Description

      Thanks to Enam for the original report :-D

      Apparently we are asking for the max integer value which is a little bit more that the legal limit.

          public static void main(String[] args) throws Exception
           {   
               Map params = new HashMap();
               params.put("dbtype", "postgis");        //must be postgis
               params.put("host", "localhost");        //the name or ip address of the machine running PostGIS
               params.put("port", new Integer(5432));  //the port that PostGIS is running on (generally 5432)
               params.put("database", "postgres");      //the name of the database to connect to.
               params.put("user", "postgres");         //the user to connect with
               params.put("passwd", "pass");               //the password of the user.
                                                                                                                            
               DataStore pgDatastore = DataStoreFinder.getDataStore(params);                                                
               pgDatastore.createSchema(someSchema);
      }
      

      Results in the following message:

      • java.io.IOException: ERROR: length for type varchar cannot exceed 10485760

      This issue is marked minor as you can work around it by actually mentioning the string length:

      // bad
      AttributeType cgi = AttributeTypeFactory.newAttributeType("propertyName", String.class);
      // good
      AttributeType cgi = AttributeTypeFactory.newAttributeType("propertyName", String.class, true, 30);
      

      Long term I would like to see datastores provide their own FeatureTypeFactory so this kind of thing is not a problem ever again (and we can be sure that the GeoTools FeatureType is always a representation of what the data store can support).

        Activity

        Hide
        Jody Garnett added a comment -
        Enamual has provided the following patch:

        if (length < 1) {
              LOGGER.warning("FeatureType did not specify string length; defaulted to 256");
              length = 256;
        }
        else if (length > MAX_ALLOWED_VALUE) // this is the check that I think should be added and MAX_ALLOWED_VALUE should be set to 10485760
        {
              length = MAX_ALLOWED_VALUE;
        }
        Show
        Jody Garnett added a comment - Enamual has provided the following patch: if (length < 1) {       LOGGER.warning("FeatureType did not specify string length; defaulted to 256");       length = 256; } else if (length > MAX_ALLOWED_VALUE) // this is the check that I think should be added and MAX_ALLOWED_VALUE should be set to 10485760 {       length = MAX_ALLOWED_VALUE; }
        Hide
        Jody Garnett added a comment -
        Bug is resolved on trunk, the revision number is 25936 if you want somebody to apply it to 2.3.x. This bug will be closed when the user gets back to us and is happy (or the next major release).
        Show
        Jody Garnett added a comment - Bug is resolved on trunk, the revision number is 25936 if you want somebody to apply it to 2.3.x. This bug will be closed when the user gets back to us and is happy (or the next major release).
        Hide
        Jody Garnett added a comment -
        simboss has applied the fix to 2.3.x now as well; updating the fixed-for field.
        Show
        Jody Garnett added a comment - simboss has applied the fix to 2.3.x now as well; updating the fixed-for field.
        Hide
        Simone Giannecchini added a comment -
        Simboss rocks!
        (I had to write something :-) )
        Show
        Simone Giannecchini added a comment - Simboss rocks! (I had to write something :-) )

          People

          • Assignee:
            Jody Garnett
            Reporter:
            Jody Garnett
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: