<commit_before>/*
 * This is part of Geomajas, a GIS framework, http://www.geomajas.org/.
 *
 * Copyright 2008-2011 Geosparc nv, http://www.geosparc.com/, Belgium.
 *
 * The program is available in open source according to the GNU Affero
 * General Public License. All contributions in this program are covered
 * by the Geomajas Contributors License Agreement. For full licensing
 * details, see LICENSE.txt in the project root.
 */
package org.geomajas.layer.geotools;

import java.io.IOException;
import java.util.Map;

import org.geomajas.layer.geotools.postgis.NonTypedPostgisFidMapperFactory;
import org.geotools.data.DataStore;
import org.geotools.data.DataStoreFinder;
import org.geotools.data.jdbc.JDBC1DataStore;
import org.geotools.data.jdbc.JDBCDataStore;
import org.geotools.data.postgis.PostgisDataStore;
import org.springframework.util.ResourceUtils;

/**
 * A simple utility factory for injecting a {@link DataStore} via Spring.
 * 
 * @author <NAME>
 */
public final class DataStoreFactory {

	/**
	 * Protect construction.
	 */
	private DataStoreFactory() {
	}

	/**
	 * Creates a suitable {@link DataStore} for the specified parameters.
	 * 
	 * @param parameters
	 *            list of GeoTools parameters.
	 * @return data store
	 * @throws IOException oops
	 */
	public static DataStore create(Map<String, String> parameters) throws IOException {
		String url = parameters.get("url");
		if (url != null) {
			parameters.put("url", ResourceUtils.getURL(url).toExternalForm());
		}
		DataStore store = DataStoreFinder.getDataStore(parameters);
		if (store instanceof PostgisDataStore) {
			PostgisDataStore jdbcStore = (PostgisDataStore) store;
			jdbcStore.setFIDMapperFactory(new NonTypedPostgisFidMapperFactory(false));
		} else if (store instanceof JDBCDataStore) {
			JDBCDataStore jdbcStore = (JDBCDataStore) store;
			jdbcStore.setFIDMapperFactory(new NonTypedFidMapperFactory());
		}
		if (store instanceof JDBC1DataStore) {
			store = new ExtendedDataStore((JDBC1DataStore) store);
		}<commit_msg>GT-14: IO exception thrown when datastore can't be found<commit_after>/*
 * This is part of Geomajas, a GIS framework, http://www.geomajas.org/.
 *
 * Copyright 2008-2011 Geosparc nv, http://www.geosparc.com/, Belgium.
 *
 * The program is available in open source according to the GNU Affero
 * General Public License. All contributions in this program are covered
 * by the Geomajas Contributors License Agreement. For full licensing
 * details, see LICENSE.txt in the project root.
 */
package org.geomajas.layer.geotools;

import java.io.IOException;
import java.util.Map;

import org.geomajas.layer.geotools.postgis.NonTypedPostgisFidMapperFactory;
import org.geotools.data.DataStore;
import org.geotools.data.DataStoreFinder;
import org.geotools.data.jdbc.JDBC1DataStore;
import org.geotools.data.jdbc.JDBCDataStore;
import org.geotools.data.postgis.PostgisDataStore;
import org.springframework.util.ResourceUtils;

/**
 * A simple utility factory for injecting a {@link DataStore} via Spring.
 * 
 * @author <NAME>
 */
public final class DataStoreFactory {

	/**
	 * Protect construction.
	 */
	private DataStoreFactory() {
	}

	/**
	 * Creates a suitable {@link DataStore} for the specified parameters.
	 * 
	 * @param parameters
	 *            list of GeoTools parameters.
	 * @return data store
	 * @throws IOException
	 *             oops
	 */
	public static DataStore create(Map<String, String> parameters) throws IOException {
		String url = parameters.get("url");
		if (url != null) {
			parameters.put("url", ResourceUtils.getURL(url).toExternalForm());
		}
		DataStore store = DataStoreFinder.getDataStore(parameters);
		if (store instanceof PostgisDataStore) {
			PostgisDataStore jdbcStore = (PostgisDataStore) store;
			jdbcStore.setFIDMapperFactory(new NonTypedPostgisFidMapperFactory(false));
		} else if (store instanceof JDBCDataStore) {
			JDBCDataStore jdbcStore = (JDBCDataStore) store;
			jdbcStore.setFIDMapperFactory(new NonTypedFidMapperFactory());
		}
		if (store instanceof JDBC1DataStore) {
			store = new ExtendedDataStore((JDBC1DataStore) store);
		} else if (store == null) {
			throw new IOException(
					"No datastore found. Possible causes are missing provider or missing library for your datastore"
							+ " (e.g. database driver).\nCheck the isAvailable() method of your"
							+ " DataStoreFactory class to find out which libraries are needed.");
		}
{'fraction_non_alphanumeric': 0.09882406151062867, 'fraction_numerical': 0.005427408412483039, 'mean_word_length': 4.328915662650602, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2567616', 'n_tokens_mistral': 1452, 'n_tokens_neox': 1314, 'n_words': 374}