use of org.geotoolkit.storage.feature.FeatureStore in project geotoolkit by Geomatys.
the class Copy method execute.
/**
* {@inheritDoc }
*/
@Override
protected void execute() throws ProcessException {
final FeatureStore sourceDS = inputParameters.getValue(SOURCE_STORE);
final FeatureStore targetDS = inputParameters.getValue(TARGET_STORE);
Session targetSS = inputParameters.getValue(TARGET_SESSION);
final Boolean eraseParam = inputParameters.getValue(ERASE);
final Boolean newVersion = inputParameters.getValue(NEW_VERSION);
// Type name can be removed, it's embedded in the query param.
final String typenameParam = inputParameters.getValue(TYPE_NAME);
final Query queryParam = inputParameters.getValue(QUERY);
final boolean doCommit = targetSS == null;
final Session sourceSS = sourceDS.createSession(false);
if (targetSS == null) {
if (targetDS != null) {
targetSS = targetDS.createSession(true);
} else {
throw new ProcessException("Input target_session or target_datastore missing.", this, null);
}
}
boolean reBuildQuery = false;
final String queryName;
if (queryParam != null) {
queryName = queryParam.getTypeName();
reBuildQuery = true;
} else if (typenameParam != null) {
queryName = typenameParam;
} else {
queryName = "*";
}
final Set<GenericName> names;
if ("*".equals(queryName)) {
// all values
try {
names = sourceDS.getNames();
} catch (DataStoreException ex) {
throw new ProcessException(ex.getMessage(), this, ex);
}
} else {
// pick only the wanted names
names = new HashSet<>();
final List<String> wanted = UnmodifiableArrayList.wrap(queryName.split(","));
for (String s : wanted) {
try {
final FeatureType type = sourceDS.getFeatureType(s);
names.add(type.getName());
} catch (DataStoreException ex) {
throw new ProcessException(ex.getMessage(), this, ex);
}
}
}
final float size = names.size();
int inc = 0;
for (GenericName n : names) {
fireProgressing("Copying " + n + ".", (int) ((inc * 100f) / size), false);
try {
Query query;
if (reBuildQuery) {
Query builder = new Query();
builder.copy(queryParam);
builder.setTypeName(n);
query = builder;
} else {
query = queryParam != null ? queryParam : new Query(n);
}
insert(n, sourceSS, targetSS, query, eraseParam, newVersion);
} catch (DataStoreException ex) {
throw new ProcessException(ex.getMessage(), this, ex);
}
inc++;
}
try {
Date lastVersionDate = null;
if (doCommit) {
LOGGER.log(Level.INFO, "Commit all changes");
targetSS.commit();
// find last version
for (GenericName n : names) {
if (targetSS.getFeatureStore().getQueryCapabilities().handleVersioning()) {
final List<Version> versions = targetSS.getFeatureStore().getVersioning(n.toString()).list();
if (!versions.isEmpty()) {
if (lastVersionDate == null || versions.get(versions.size() - 1).getDate().getTime() > lastVersionDate.getTime()) {
lastVersionDate = versions.get(versions.size() - 1).getDate();
}
}
}
}
}
if (lastVersionDate != null) {
outputParameters.getOrCreate(VERSION).setValue(lastVersionDate);
}
} catch (DataStoreException ex) {
throw new ProcessException(ex.getMessage(), this, ex);
} catch (VersioningException ex) {
throw new ProcessException(ex.getMessage(), this, ex);
}
}
use of org.geotoolkit.storage.feature.FeatureStore in project geotoolkit by Geomatys.
the class AbstractWritingTests method testDataStore.
@Test
public void testDataStore() {
final FeatureStore store = getDataStore();
assertNotNull(store);
}
use of org.geotoolkit.storage.feature.FeatureStore in project geotoolkit by Geomatys.
the class GPXDemo method main.
public static void main(String[] args) throws DataStoreException, URISyntaxException {
Demos.init();
final Map<String, Serializable> parameters = new HashMap<String, Serializable>();
parameters.put("path", GPXDemo.class.getResource("/data/sampleGPX.gpx").toURI());
final FeatureStore store = (FeatureStore) DataStores.open(parameters);
System.out.println("=================== Feature types ====================");
final Set<GenericName> names = store.getNames();
for (GenericName name : names) {
System.out.println(store.getFeatureType(name.toString()));
}
}
use of org.geotoolkit.storage.feature.FeatureStore in project geotoolkit by Geomatys.
the class OSMDemo method main.
public static void main(String[] args) throws DataStoreException, URISyntaxException {
Demos.init();
final Map<String, Serializable> parameters = new HashMap<String, Serializable>();
parameters.put("path", OSMDemo.class.getResource("/data/sampleOSM.osm").toURI());
final FeatureStore store = (FeatureStore) DataStores.open(parameters);
System.out.println("=================== Feature types ====================");
final Set<GenericName> names = store.getNames();
for (GenericName name : names) {
System.out.println(store.getFeatureType(name.toString()));
}
}
use of org.geotoolkit.storage.feature.FeatureStore in project geotoolkit by Geomatys.
the class DefaultFolderFeatureStore method createFeatureType.
/**
* {@inheritDoc}
*/
@Override
public void createFeatureType(final FeatureType featureType) throws DataStoreException {
final GenericName typeName = featureType.getName();
if (getNames().contains(typeName)) {
throw new DataStoreException("Type name " + typeName + " already exists.");
}
final Parameters params = singleFileDefaultParameters.clone();
try {
final Path folder = getFolder(folderParameters);
final String fileName = typeName.tip().toString() + "." + singleFileFactory.getSuffix().iterator().next();
final Path newFile = folder.resolve(fileName);
params.getOrCreate(ShapefileProvider.PATH).setValue(newFile.toUri().toURL());
} catch (MalformedURLException ex) {
throw new DataStoreException(ex);
}
final FeatureStore store = (FeatureStore) singleFileFactory.create(params);
store.addListener(StoreEvent.class, subListener);
store.createFeatureType(featureType);
stores.add(this, typeName, store);
}
Aggregations