Search in sources :

Example 1 with JDTSSQLServerJNDIDataStoreFactory

use of org.geotools.data.sqlserver.jtds.JDTSSQLServerJNDIDataStoreFactory in project sldeditor by robward-scisys.

the class DatabaseConnectionFactory method createSQLServer.

/**
 * Creates a new DatabaseConnection object for SQL Server.
 *
 * @return the database connection
 */
public static DatabaseConnection createSQLServer() {
    List<DatabaseConnectionField> list = new ArrayList<DatabaseConnectionField>();
    list.add(new DatabaseConnectionField(JTDSSqlServerDataStoreFactory.HOST));
    list.add(new DatabaseConnectionField(JTDSSqlServerDataStoreFactory.PORT));
    list.add(new DatabaseConnectionField(JTDSSqlServerDataStoreFactory.INSTANCE));
    list.add(new DatabaseConnectionField(JTDSSqlServerDataStoreFactory.SCHEMA));
    list.add(new DatabaseConnectionField(JTDSSqlServerDataStoreFactory.DATABASE));
    list.add(new DatabaseConnectionField(JTDSSqlServerDataStoreFactory.USER));
    list.add(new DatabaseConnectionField(JTDSSqlServerDataStoreFactory.PASSWD));
    list.add(new DatabaseConnectionField(JTDSSqlServerDataStoreFactory.GEOMETRY_METADATA_TABLE));
    JDTSSQLServerJNDIDataStoreFactory factory = new JDTSSQLServerJNDIDataStoreFactory();
    DatabaseConnection databaseConnection = new DatabaseConnection(JTDSSqlServerDataStoreFactory.DBTYPE, factory.getDisplayName(), true, list, new DatabaseConnectionName() {

        @Override
        public String getConnectionName(String duplicatePrefix, int noOfTimesDuplicated, Map<String, String> properties) {
            String connectionName = String.format("%s/%s@%s:%s", properties.get(JTDSSqlServerDataStoreFactory.INSTANCE.key), properties.get(JTDSSqlServerDataStoreFactory.DATABASE.key), properties.get(JTDSSqlServerDataStoreFactory.HOST.key), properties.get(JTDSSqlServerDataStoreFactory.PORT.key));
            for (int i = 0; i < noOfTimesDuplicated; i++) {
                connectionName = duplicatePrefix + connectionName;
            }
            return connectionName;
        }
    });
    return databaseConnection;
}
Also used : DatabaseConnectionField(com.sldeditor.common.data.DatabaseConnectionField) JDTSSQLServerJNDIDataStoreFactory(org.geotools.data.sqlserver.jtds.JDTSSQLServerJNDIDataStoreFactory) ArrayList(java.util.ArrayList) DatabaseConnection(com.sldeditor.common.data.DatabaseConnection)

Aggregations

DatabaseConnection (com.sldeditor.common.data.DatabaseConnection)1 DatabaseConnectionField (com.sldeditor.common.data.DatabaseConnectionField)1 ArrayList (java.util.ArrayList)1 JDTSSQLServerJNDIDataStoreFactory (org.geotools.data.sqlserver.jtds.JDTSSQLServerJNDIDataStoreFactory)1