/*
* 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.feature.FeatureCollection;
import org.geotools.feature.simple.SimpleFeatureBuilder;
import org.geotools.jdbc.*;
import org.opengis.feature.simple.SimpleFeature;
import org.opengis.feature.simple.SimpleFeatureType;
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);
FeatureCollection 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);
features.add( 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);
FeatureCollection features = fs.getFeatures();
assertPrimaryKeyValues(features, 3);
addFeature(fs.getSchema(), features);
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);
FeatureCollection features = fs.getFeatures();
assertPrimaryKeyValues(features, 3);
addFeature(fs.getSchema(), features);
assertPrimaryKeyValues(features, 4);
}
}