Java Code Examples for mil.nga.geopackage.core.srs.SpatialReferenceSystemDao#countOf()

The following examples show how to use mil.nga.geopackage.core.srs.SpatialReferenceSystemDao#countOf() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TransactionTest.java    From geopackage-android with MIT License 4 votes vote down vote up
/**
 * Test an ORMLite transaction
 *
 * @param geoPackage GeoPackage
 * @param successful true for a successful transaction
 * @throws SQLException upon error
 */
private void testORMLite(final GeoPackage geoPackage,
                         final boolean successful) throws SQLException {

    final String tableName = "test_table";

    final Contents contents = new Contents();
    contents.setTableName(tableName);
    contents.setDataType(ContentsDataType.ATTRIBUTES);

    if (!geoPackage.isTable(tableName)) {
        geoPackage.execSQL("CREATE TABLE " + tableName
                + " (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL)");
    }

    final SpatialReferenceSystemDao srsDao = geoPackage
            .getSpatialReferenceSystemDao();
    final ContentsDao contentsDao = geoPackage.getContentsDao();

    long srsCount = srsDao.countOf();
    long contentsCount = contentsDao.countOf();

    Callable<Void> callable = new Callable<Void>() {
        public Void call() throws Exception {

            SpatialReferenceSystem srs = srsDao.createWgs84Geographical3D();

            contents.setSrs(srs);
            contentsDao.create(contents);

            if (!successful) {
                throw new SQLException();
            }

            return null;
        }
    };

    try {
        geoPackage.callInTransaction(callable);
    } catch (SQLException e) {
        if (successful) {
            TestCase.fail(e.getMessage());
        }
    }

    TestCase.assertEquals(successful ? srsCount + 1 : srsCount,
            srsDao.countOf());
    TestCase.assertEquals(successful ? contentsCount + 1 : contentsCount,
            contentsDao.countOf());

    TestCase.assertEquals(successful,
            geoPackage.isAttributeTable(tableName));

}
 
Example 2
Source File: SpatialReferenceSystemUtils.java    From geopackage-android with MIT License 4 votes vote down vote up
/**
 * Test create
 * 
 * @param geoPackage
 * @throws SQLException
 */
public static void testCreate(GeoPackage geoPackage) throws SQLException {

	SpatialReferenceSystemDao dao = geoPackage
			.getSpatialReferenceSystemDao();

	// Get current count
	long count = dao.countOf();

	String srsName = "TEST_SRS_NAME";
	long srsId = 123456l;
	String organization = "TEST_ORG";
	int organizationCoordSysId = 123456;
	String definition = "TEST_DEFINITION";
	String description = "TEST_DESCRIPTION";

	// Create new srs
	SpatialReferenceSystem srs = new SpatialReferenceSystem();
	srs.setSrsName(srsName);
	srs.setSrsId(srsId);
	srs.setOrganization(organization);
	srs.setOrganizationCoordsysId(organizationCoordSysId);
	srs.setDefinition(definition);
	srs.setDescription(description);
	dao.create(srs);

	// Verify count
	long newCount = dao.countOf();
	TestCase.assertEquals(count + 1, newCount);

	// Verify saved srs
	SpatialReferenceSystem querySrs = dao.queryForId(srsId);
	TestCase.assertEquals(srsName, querySrs.getSrsName());
	TestCase.assertEquals(srsId, querySrs.getSrsId());
	TestCase.assertEquals(organization, querySrs.getOrganization());
	TestCase.assertEquals(organizationCoordSysId,
			querySrs.getOrganizationCoordsysId());
	TestCase.assertEquals(definition, querySrs.getDefinition());
	TestCase.assertEquals(description, querySrs.getDescription());

	// Test copied srs
	SpatialReferenceSystem copySrs = new SpatialReferenceSystem(querySrs);
	TestCase.assertEquals(querySrs.getSrsName(), copySrs.getSrsName());
	TestCase.assertEquals(querySrs.getId(), copySrs.getId());
	TestCase.assertEquals(querySrs.getOrganization(),
			copySrs.getOrganization());
	TestCase.assertEquals(querySrs.getOrganizationCoordsysId(),
			copySrs.getOrganizationCoordsysId());
	TestCase.assertEquals(querySrs.getDefinition(), copySrs.getDefinition());
	TestCase.assertEquals(querySrs.getDescription(),
			copySrs.getDescription());
	TestCase.assertEquals(querySrs.getDefinition_12_063(),
			copySrs.getDefinition_12_063());

	// Change pk
	long copySrsId = 654321l;
	copySrs.setSrsId(copySrsId);

	dao.create(copySrs);

	// Verify count
	long newCount2 = dao.countOf();
	TestCase.assertEquals(count + 2, newCount2);

	// Verify saved contents
	SpatialReferenceSystem queryCopiedSrs = dao.queryForId(copySrsId);
	TestCase.assertEquals(querySrs.getSrsName(),
			queryCopiedSrs.getSrsName());
	TestCase.assertEquals(copySrsId, queryCopiedSrs.getSrsId());
	TestCase.assertEquals(querySrs.getOrganization(),
			queryCopiedSrs.getOrganization());
	TestCase.assertEquals(querySrs.getOrganizationCoordsysId(),
			queryCopiedSrs.getOrganizationCoordsysId());
	TestCase.assertEquals(querySrs.getDefinition(),
			queryCopiedSrs.getDefinition());
	TestCase.assertEquals(querySrs.getDescription(),
			queryCopiedSrs.getDescription());

}
 
Example 3
Source File: TransactionTest.java    From geopackage-java with MIT License 4 votes vote down vote up
/**
 * Test an ORMLite transaction
 * 
 * @param geoPackage
 *            GeoPackage
 * @param successful
 *            true for a successful transaction
 * @throws SQLException
 *             upon error
 */
private void testORMLite(final GeoPackage geoPackage,
		final boolean successful) throws SQLException {

	final String tableName = "test_table";

	final Contents contents = new Contents();
	contents.setTableName(tableName);
	contents.setDataType(ContentsDataType.ATTRIBUTES);

	if (!geoPackage.isTable(tableName)) {
		geoPackage.execSQL("CREATE TABLE " + tableName
				+ " (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL)");
	}

	final SpatialReferenceSystemDao srsDao = geoPackage
			.getSpatialReferenceSystemDao();
	final ContentsDao contentsDao = geoPackage.getContentsDao();

	long srsCount = srsDao.countOf();
	long contentsCount = contentsDao.countOf();

	Callable<Void> callable = new Callable<Void>() {
		public Void call() throws Exception {

			SpatialReferenceSystem srs = srsDao.createWgs84Geographical3D();

			contents.setSrs(srs);
			contentsDao.create(contents);

			if (!successful) {
				throw new SQLException();
			}

			return null;
		}
	};

	try {
		geoPackage.callInTransaction(callable);
	} catch (SQLException e) {
		if (successful) {
			TestCase.fail(e.getMessage());
		}
	}

	TestCase.assertEquals(successful ? srsCount + 1 : srsCount,
			srsDao.countOf());
	TestCase.assertEquals(successful ? contentsCount + 1 : contentsCount,
			contentsDao.countOf());

	TestCase.assertEquals(successful,
			geoPackage.isAttributeTable(tableName));

}
 
Example 4
Source File: SpatialReferenceSystemUtils.java    From geopackage-java with MIT License 4 votes vote down vote up
/**
 * Test create
 * 
 * @param geoPackage
 * @throws SQLException
 */
public static void testCreate(GeoPackage geoPackage) throws SQLException {

	SpatialReferenceSystemDao dao = geoPackage
			.getSpatialReferenceSystemDao();

	// Get current count
	long count = dao.countOf();

	String srsName = "TEST_SRS_NAME";
	long srsId = 123456l;
	String organization = "TEST_ORG";
	int organizationCoordSysId = 123456;
	String definition = "TEST_DEFINITION";
	String description = "TEST_DESCRIPTION";

	// Create new srs
	SpatialReferenceSystem srs = new SpatialReferenceSystem();
	srs.setSrsName(srsName);
	srs.setSrsId(srsId);
	srs.setOrganization(organization);
	srs.setOrganizationCoordsysId(organizationCoordSysId);
	srs.setDefinition(definition);
	srs.setDescription(description);
	dao.create(srs);

	// Verify count
	long newCount = dao.countOf();
	TestCase.assertEquals(count + 1, newCount);

	// Verify saved srs
	SpatialReferenceSystem querySrs = dao.queryForId(srsId);
	TestCase.assertEquals(srsName, querySrs.getSrsName());
	TestCase.assertEquals(srsId, querySrs.getSrsId());
	TestCase.assertEquals(organization, querySrs.getOrganization());
	TestCase.assertEquals(organizationCoordSysId,
			querySrs.getOrganizationCoordsysId());
	TestCase.assertEquals(definition, querySrs.getDefinition());
	TestCase.assertEquals(description, querySrs.getDescription());

	// Test copied srs
	SpatialReferenceSystem copySrs = new SpatialReferenceSystem(querySrs);
	TestCase.assertEquals(querySrs.getSrsName(), copySrs.getSrsName());
	TestCase.assertEquals(querySrs.getId(), copySrs.getId());
	TestCase.assertEquals(querySrs.getOrganization(),
			copySrs.getOrganization());
	TestCase.assertEquals(querySrs.getOrganizationCoordsysId(),
			copySrs.getOrganizationCoordsysId());
	TestCase.assertEquals(querySrs.getDefinition(), copySrs.getDefinition());
	TestCase.assertEquals(querySrs.getDescription(),
			copySrs.getDescription());
	TestCase.assertEquals(querySrs.getDefinition_12_063(),
			copySrs.getDefinition_12_063());

	// Change pk
	long copySrsId = 654321l;
	copySrs.setSrsId(copySrsId);

	dao.create(copySrs);

	// Verify count
	long newCount2 = dao.countOf();
	TestCase.assertEquals(count + 2, newCount2);

	// Verify saved contents
	SpatialReferenceSystem queryCopiedSrs = dao.queryForId(copySrsId);
	TestCase.assertEquals(querySrs.getSrsName(),
			queryCopiedSrs.getSrsName());
	TestCase.assertEquals(copySrsId, queryCopiedSrs.getSrsId());
	TestCase.assertEquals(querySrs.getOrganization(),
			queryCopiedSrs.getOrganization());
	TestCase.assertEquals(querySrs.getOrganizationCoordsysId(),
			queryCopiedSrs.getOrganizationCoordsysId());
	TestCase.assertEquals(querySrs.getDefinition(),
			queryCopiedSrs.getDefinition());
	TestCase.assertEquals(querySrs.getDescription(),
			queryCopiedSrs.getDescription());

}