Package org.geotools.data.teradata

Source Code of org.geotools.data.teradata.TeradataPrimaryKeyTest

/*
*    GeoTools - The Open Source Java GIS Toolkit
*    http://geotools.org
*
*    (C) 2002-2009, Open Source Geospatial Foundation (OSGeo)
*
*    This library is free software; you can redistribute it and/or
*    modify it under the terms of the GNU Lesser General Public
*    License as published by the Free Software Foundation;
*    version 2.1 of the License.
*
*    This library is distributed in the hope that it will be useful,
*    but WITHOUT ANY WARRANTY; without even the implied warranty of
*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
*    Lesser General Public License for more details.
*/
package org.geotools.data.teradata;

import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.GeometryFactory;

import org.geotools.data.DataUtilities;
import org.geotools.data.store.ContentFeatureCollection;
import org.geotools.feature.simple.SimpleFeatureBuilder;
import org.geotools.jdbc.*;
import org.opengis.feature.simple.SimpleFeature;
import org.opengis.feature.simple.SimpleFeatureType;

/**
*
*
* @source $URL$
*/
public class TeradataPrimaryKeyTest extends JDBCPrimaryKeyTest {

    protected JDBCPrimaryKeyTestSetup createTestSetup() {
        return new TeradataPrimaryKeyTestSetup(new TeradataTestSetup());
    }


    public void testUniqueGeneratedPrimaryKey() throws Exception {
        JDBCFeatureStore fs = (JDBCFeatureStore) dataStore.getFeatureSource(tname("uniquetablenotgenerated"));

        assertEquals(1, fs.getPrimaryKey().getColumns().size());
        assertTrue(fs.getPrimaryKey().getColumns().get(0) instanceof NonIncrementingPrimaryKeyColumn);

        ContentFeatureCollection features = fs.getFeatures();
        assertPrimaryKeyValues(features, 3);

        SimpleFeatureType featureType = fs.getSchema();
        SimpleFeatureBuilder b = new SimpleFeatureBuilder( featureType );
        b.add("four");
        b.add( new GeometryFactory().createPoint( new Coordinate(4,4) ) );

        SimpleFeature f = b.buildFeature(null);
        fs.addFeatures( DataUtilities.collection(f));

        //pattern match to handle the multi primary key case
        assertTrue(((String)f.getUserData().get( "fid" )).matches( tname(featureType.getTypeName()) + ".4(\\..*)?"));

        assertPrimaryKeyValues(features, 4);
    }

    public void testUniqueNonGeneratedPrimaryKey() throws Exception {
        JDBCFeatureStore fs = (JDBCFeatureStore) dataStore.getFeatureSource(tname("uniquetable"));

        assertEquals(1, fs.getPrimaryKey().getColumns().size());
        assertTrue(fs.getPrimaryKey().getColumns().get(0) instanceof AutoGeneratedPrimaryKeyColumn);

        ContentFeatureCollection features = fs.getFeatures();
        assertPrimaryKeyValues(features, 3);
        addFeature(fs.getSchema(), fs);
        assertPrimaryKeyValues(features, 4);
    }

    public void testSequencedPrimaryKey() throws Exception {
        JDBCFeatureStore fs = (JDBCFeatureStore) dataStore.getFeatureSource(tname("seq"));

        assertEquals(1, fs.getPrimaryKey().getColumns().size());
        assertTrue(fs.getPrimaryKey().getColumns().get(0) instanceof AutoGeneratedPrimaryKeyColumn);

        ContentFeatureCollection features = fs.getFeatures();
        assertPrimaryKeyValues(features, 3);
        addFeature(fs.getSchema(), fs);
        assertPrimaryKeyValues(features, 4);
    }
}
TOP

Related Classes of org.geotools.data.teradata.TeradataPrimaryKeyTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.