2015-04-22 3 views
1

Примечание: Запуск геолокаторов 13.0.Geotools 13 - запись ошибок в MySQL в Linux

У меня есть приложение, которое создает формы точек. Затем мое приложение записывает эти функции в шейп-файл, а затем в MySQL.

Когда я запускаю код под Windows, все работает отлично: данные правильно хранятся в MySQL, и я могу использовать его без особых проблем.

Когда я запускаю код под Linux, шейп созданы, но данные не записываются в MySQL и следующее исключение:

WARNING: class org.geotools.filter.function.Collection_NearestFunction has name conflict betwee 'null' and 'Collection_Nearest' 
Exception in thread "main" java.lang.NoSuchFieldError: LINEARIZATION_TOLERANCE 
at org.geotools.jdbc.JDBCFeatureReader.init(JDBCFeatureReader.java:211) 
at org.geotools.jdbc.JDBCFeatureReader.<init>(JDBCFeatureReader.java:137) 
at org.geotools.jdbc.JDBCInsertFeatureWriter.<init>(JDBCInsertFeatureWriter.java:43) 
at org.geotools.jdbc.JDBCFeatureStore.getWriterInternal(JDBCFeatureStore.java:280) 
at org.geotools.data.store.ContentFeatureStore.getWriter(ContentFeatureStore.java:151) 
at org.geotools.data.store.ContentFeatureStore.getWriter(ContentFeatureStore.java:122) 
at org.geotools.data.store.ContentFeatureStore.getWriterAppend(ContentFeatureStore.java:263) 
at org.geotools.data.store.ContentFeatureStore.addFeatures(ContentFeatureStore.java:242) 
at com.technip.projects.gis.GISGenerator.writeShapesMySQL(GISGenerator.java:763) 
at com.technip.projects.gis.GISGenerator.generatePlatforms(GISGenerator.java:416) 
at com.technip.projects.gis.GISGenerator.createShapefiles(GISGenerator.java:249) 
at Machine.run(Machine.java:739) 
at Machine.main(Machine.java:329) 

Мой код:

private void writeShapesMySQL(List<SimpleFeature> features) throws IOException { 
    SimpleFeatureType TYPE = null; 

    if (!features.isEmpty()) { 
     TYPE = features.get(0).getType(); 

     // Drop the table if exists 
     try (Connection con = conf.requestConnection("gis")) { 
      con.prepareCall("DROP TABLE IF EXISTS " + TYPE.getTypeName() + ";").execute(); 
     } catch (Exception e) {} 
     if (factory == null) { 
      initMySQLStore(); 
     } 

     SimpleFeatureCollection collection = new ListFeatureCollection(TYPE, features); 

     gisDS.createSchema(TYPE); 

     Transaction transaction = new DefaultTransaction("create"); 
     String  typeName = null; 

     for (String s : gisDS.getTypeNames()) { 
      if (s.equalsIgnoreCase(TYPE.getTypeName())) { 
       typeName = s; 
       break; 
      } 
     } 
     if (typeName == null) { 
      log.error("Cannot find the type " + TYPE.getTypeName() + " in the known types: " + String.valueOf(gisDS.getTypeNames())); 
      throw new IOException("Cannot find type " + TYPE.getTypeName() + " -- in other words, developer sucks."); 
     } 

     SimpleFeatureSource featureSource = gisDS.getFeatureSource(typeName); 

     // System.out.println("SHAPE:"+SHAPE_TYPE); 
     if (featureSource instanceof SimpleFeatureStore) { 
      SimpleFeatureStore featureStore = (SimpleFeatureStore) featureSource; 

      featureStore.setTransaction(transaction); 
      try { 
       log.info("Adding " + collection.size() + " features into " + TYPE.getTypeName() + " table."); 
       featureStore.addFeatures(collection); 
       transaction.commit(); 
      } catch (Exception problem) { 
       log.error("Cannot create shapes in MySQL for " + TYPE.getTypeName(), problem); 
       transaction.rollback(); 
      } finally { 
       transaction.close(); 
      } 
     } 
    } else { 
     log.warn("Passed empty list to create GIS database."); 
    } 
} 

private void initMySQLStore() throws IOException { 
    factory = new MySQLDataStoreFactory(); 

    Map conMap = new HashMap(); 

    conMap.put("dbtype", "mysql"); 
    conMap.put("host", conf.getDbserver()); 
    conMap.put("port", "3306"); 
    conMap.put("database", "gis"); 
    conMap.put("user", conf.getDbuser()); 
    conMap.put("passwd", conf.getDbpass()); 

    gisDS = factory.createDataStore(conMap); 

    Map<Class<?>, Integer> classMappings = gisDS.getClassToSqlTypeMappings(); 

    classMappings.put(String.class, new Integer(Types.LONGVARCHAR)); 
} 

Мой первый что MySQL чувствителен к регистру в Linux, но не в Windows. Поэтому я проверил созданные таблицы как в Linux, так и в Windows, и ни одно из них не имеет поля с таким именем (LINEARIZATION_TOLERANCE).

Любые подсказки?

Спасибо,

Juan

--update: ПРОБЛЕМА SOLVED--

Оказалось, у меня был старый .jar от предыдущей версии GeoTools в машине Linux. Исправлена ​​проблема с удалением всех старых банок.

ответ

0

Проблема решена:

Оказалось, у меня был старый .jar из предыдущей версии GeoTools в машине Linux. Исправлена ​​проблема с удалением всех старых банок.

Отклонить это, это ошибка пользователя.