Search in sources :

Example 1 with SpatiaLiteDataStoreFactory

use of org.geotools.data.spatialite.SpatiaLiteDataStoreFactory in project sldeditor by robward-scisys.

the class DatabaseConnectionFactory method createSpatiaLite.

/**
 * Creates a new DatabaseConnection object for a GeoPackage.
 *
 * @return the database connection
 */
public static DatabaseConnection createSpatiaLite() {
    List<DatabaseConnectionField> list = new ArrayList<DatabaseConnectionField>();
    list.add(new DatabaseConnectionField(SpatiaLiteDataStoreFactory.DATABASE));
    FileNameExtensionFilter filter = new FileNameExtensionFilter(Localisation.getString(DatabaseConnector.class, "DatabaseConnectorGeoPkg.fileExtension") + " (*." + SPATIALITE_FILE_EXTENSION + ")", SPATIALITE_FILE_EXTENSION);
    list.add(new DatabaseConnectionField(SpatiaLiteDataStoreFactory.USER, filter));
    SpatiaLiteDataStoreFactory factory = new SpatiaLiteDataStoreFactory();
    DatabaseConnection databaseConnection = new DatabaseConnection(SpatiaLiteDataStoreFactory.DBTYPE, factory.getDisplayName(), false, list, new DatabaseConnectionName() {

        @Override
        public String getConnectionName(String duplicatePrefix, int noOfTimesDuplicated, Map<String, String> properties) {
            String connectionName = Localisation.getString(DatabaseConnectionFactory.class, "common.notSet");
            String databaseName = properties.get(JDBCDataStoreFactory.DATABASE.key);
            if (databaseName != null) {
                File f = new File(databaseName);
                if (f.isFile()) {
                    connectionName = f.getName();
                }
            }
            for (int i = 0; i < noOfTimesDuplicated; i++) {
                connectionName = duplicatePrefix + connectionName;
            }
            return connectionName;
        }
    });
    return databaseConnection;
}
Also used : DatabaseConnectionField(com.sldeditor.common.data.DatabaseConnectionField) ArrayList(java.util.ArrayList) FileNameExtensionFilter(javax.swing.filechooser.FileNameExtensionFilter) SpatiaLiteDataStoreFactory(org.geotools.data.spatialite.SpatiaLiteDataStoreFactory) DatabaseConnection(com.sldeditor.common.data.DatabaseConnection) File(java.io.File)

Aggregations

DatabaseConnection (com.sldeditor.common.data.DatabaseConnection)1 DatabaseConnectionField (com.sldeditor.common.data.DatabaseConnectionField)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 FileNameExtensionFilter (javax.swing.filechooser.FileNameExtensionFilter)1 SpatiaLiteDataStoreFactory (org.geotools.data.spatialite.SpatiaLiteDataStoreFactory)1