Java Code Examples for mil.nga.geopackage.schema.constraints.DataColumnConstraintsDao#isTableExists()

The following examples show how to use mil.nga.geopackage.schema.constraints.DataColumnConstraintsDao#isTableExists() . 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: GeoPackageCoreImpl.java    From geopackage-core-java with MIT License 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public boolean createDataColumnConstraintsTable() {
	verifyWritable();

	boolean created = false;
	DataColumnConstraintsDao dao = getDataColumnConstraintsDao();
	try {
		if (!dao.isTableExists()) {
			created = tableCreator.createDataColumnConstraints() > 0;
			if (created) {
				// Create the schema extension record
				SchemaExtension schemaExtension = new SchemaExtension(this);
				schemaExtension.getOrCreate();
			}
		}
	} catch (SQLException e) {
		throw new GeoPackageException("Failed to check if "
				+ DataColumnConstraints.class.getSimpleName()
				+ " table exists and create it", e);
	}
	return created;
}
 
Example 2
Source File: DataColumnConstraintsUtils.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 {

	DataColumnConstraintsDao dao = geoPackage.getDataColumnConstraintsDao();

	if (dao.isTableExists()) {

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

		// Create new data column constraints
		String name = "test_create_constraint";
		DataColumnConstraintType type = DataColumnConstraintType.RANGE;
		BigDecimal min = new BigDecimal(50);
		boolean minInclusive = false;
		BigDecimal max = new BigDecimal(50000000);
		boolean maxInclusive = true;
		String description = "test create description";

		DataColumnConstraints dataColumnConstraints = new DataColumnConstraints();
		dataColumnConstraints.setConstraintName(name);
		dataColumnConstraints.setConstraintType(type);
		dataColumnConstraints.setMin(min);
		dataColumnConstraints.setMinIsInclusive(minInclusive);
		dataColumnConstraints.setMax(max);
		dataColumnConstraints.setMaxIsInclusive(maxInclusive);
		dataColumnConstraints.setDescription(description);
		dao.create(dataColumnConstraints);

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

		// Verify saved data column constraints
		DataColumnConstraints queryDataColumnConstraints = dao
				.queryByUnique(name, type, null);
		TestCase.assertEquals(name,
				queryDataColumnConstraints.getConstraintName());
		TestCase.assertEquals(type,
				queryDataColumnConstraints.getConstraintType());
		TestCase.assertNull(queryDataColumnConstraints.getValue());
		TestCase.assertEquals(min, queryDataColumnConstraints.getMin());
		TestCase.assertEquals(minInclusive, queryDataColumnConstraints
				.getMinIsInclusive().booleanValue());
		TestCase.assertEquals(max, queryDataColumnConstraints.getMax());
		TestCase.assertEquals(maxInclusive, queryDataColumnConstraints
				.getMaxIsInclusive().booleanValue());
		TestCase.assertEquals(description,
				queryDataColumnConstraints.getDescription());

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

	DataColumnConstraintsDao dao = geoPackage.getDataColumnConstraintsDao();
	DataColumnsDao dataColumnsDao = geoPackage.getDataColumnsDao();
	if (dao.isTableExists()) {
		List<DataColumnConstraints> results = dao.queryForAll();

		if (!results.isEmpty()) {

			// Choose random data column constraints
			int random = (int) (Math.random() * results.size());
			DataColumnConstraints dataColumnConstraints = results
					.get(random);

			int remainingConstraints = dao.queryByConstraintName(
					dataColumnConstraints.getConstraintName()).size();
			int dataColumns = dataColumnsDao.queryByConstraintName(
					dataColumnConstraints.getConstraintName()).size();

			// Delete the data column constraints
			dao.deleteCascade(dataColumnConstraints);

			// Verify deleted
			DataColumnConstraints queryDataColumns = dao.queryByUnique(
					dataColumnConstraints.getConstraintName(),
					dataColumnConstraints.getConstraintType(),
					dataColumnConstraints.getValue());
			TestCase.assertNull(queryDataColumns);

			// Verify cascade delete
			int afterRemainingConstraints = dao.queryByConstraintName(
					dataColumnConstraints.getConstraintName()).size();
			int afterDataColumns = dataColumnsDao.queryByConstraintName(
					dataColumnConstraints.getConstraintName()).size();

			TestCase.assertEquals(remainingConstraints - 1,
					afterRemainingConstraints);
			if (remainingConstraints == 1) {
				TestCase.assertEquals(0, afterDataColumns);
			} else {
				TestCase.assertEquals(dataColumns, afterDataColumns);
			}

			// Prepared deleted
			results = dao.queryForAll();
			if (!results.isEmpty()) {

				// Choose random data column constraints
				random = (int) (Math.random() * results.size());
				dataColumnConstraints = results.get(random);

				// Find which data column constraints to delete
				QueryBuilder<DataColumnConstraints, Void> qb = dao
						.queryBuilder();
				qb.where().eq(DataColumnConstraints.COLUMN_CONSTRAINT_NAME,
						dataColumnConstraints.getConstraintName());
				PreparedQuery<DataColumnConstraints> query = qb.prepare();
				List<DataColumnConstraints> queryResults = dao.query(query);
				int count = queryResults.size();

				// Delete
				DeleteBuilder<DataColumnConstraints, Void> db = dao
						.deleteBuilder();
				db.where().eq(DataColumnConstraints.COLUMN_CONSTRAINT_NAME,
						dataColumnConstraints.getConstraintName());
				PreparedDelete<DataColumnConstraints> deleteQuery = db
						.prepare();
				int deleted = dao.delete(deleteQuery);

				TestCase.assertEquals(count, deleted);

			}
		}
	}
}
 
Example 4
Source File: DataColumnConstraintsUtils.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 {

	DataColumnConstraintsDao dao = geoPackage.getDataColumnConstraintsDao();

	if (dao.isTableExists()) {

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

		// Create new data column constraints
		String name = "test_create_constraint";
		DataColumnConstraintType type = DataColumnConstraintType.RANGE;
		BigDecimal min = new BigDecimal(50);
		boolean minInclusive = false;
		BigDecimal max = new BigDecimal(50000000);
		boolean maxInclusive = true;
		String description = "test create description";

		DataColumnConstraints dataColumnConstraints = new DataColumnConstraints();
		dataColumnConstraints.setConstraintName(name);
		dataColumnConstraints.setConstraintType(type);
		dataColumnConstraints.setMin(min);
		dataColumnConstraints.setMinIsInclusive(minInclusive);
		dataColumnConstraints.setMax(max);
		dataColumnConstraints.setMaxIsInclusive(maxInclusive);
		dataColumnConstraints.setDescription(description);
		dao.create(dataColumnConstraints);

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

		// Verify saved data column constraints
		DataColumnConstraints queryDataColumnConstraints = dao
				.queryByUnique(name, type, null);
		TestCase.assertEquals(name,
				queryDataColumnConstraints.getConstraintName());
		TestCase.assertEquals(type,
				queryDataColumnConstraints.getConstraintType());
		TestCase.assertNull(queryDataColumnConstraints.getValue());
		TestCase.assertEquals(min, queryDataColumnConstraints.getMin());
		TestCase.assertEquals(minInclusive, queryDataColumnConstraints
				.getMinIsInclusive().booleanValue());
		TestCase.assertEquals(max, queryDataColumnConstraints.getMax());
		TestCase.assertEquals(maxInclusive, queryDataColumnConstraints
				.getMaxIsInclusive().booleanValue());
		TestCase.assertEquals(description,
				queryDataColumnConstraints.getDescription());

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

	DataColumnConstraintsDao dao = geoPackage.getDataColumnConstraintsDao();
	DataColumnsDao dataColumnsDao = geoPackage.getDataColumnsDao();
	if (dao.isTableExists()) {
		List<DataColumnConstraints> results = dao.queryForAll();

		if (!results.isEmpty()) {

			// Choose random data column constraints
			int random = (int) (Math.random() * results.size());
			DataColumnConstraints dataColumnConstraints = results
					.get(random);

			int remainingConstraints = dao.queryByConstraintName(
					dataColumnConstraints.getConstraintName()).size();
			int dataColumns = dataColumnsDao.queryByConstraintName(
					dataColumnConstraints.getConstraintName()).size();

			// Delete the data column constraints
			dao.deleteCascade(dataColumnConstraints);

			// Verify deleted
			DataColumnConstraints queryDataColumns = dao.queryByUnique(
					dataColumnConstraints.getConstraintName(),
					dataColumnConstraints.getConstraintType(),
					dataColumnConstraints.getValue());
			TestCase.assertNull(queryDataColumns);

			// Verify cascade delete
			int afterRemainingConstraints = dao.queryByConstraintName(
					dataColumnConstraints.getConstraintName()).size();
			int afterDataColumns = dataColumnsDao.queryByConstraintName(
					dataColumnConstraints.getConstraintName()).size();

			TestCase.assertEquals(remainingConstraints - 1,
					afterRemainingConstraints);
			if (remainingConstraints == 1) {
				TestCase.assertEquals(0, afterDataColumns);
			} else {
				TestCase.assertEquals(dataColumns, afterDataColumns);
			}

			// Prepared deleted
			results = dao.queryForAll();
			if (!results.isEmpty()) {

				// Choose random data column constraints
				random = (int) (Math.random() * results.size());
				dataColumnConstraints = results.get(random);

				// Find which data column constraints to delete
				QueryBuilder<DataColumnConstraints, Void> qb = dao
						.queryBuilder();
				qb.where().eq(DataColumnConstraints.COLUMN_CONSTRAINT_NAME,
						dataColumnConstraints.getConstraintName());
				PreparedQuery<DataColumnConstraints> query = qb.prepare();
				List<DataColumnConstraints> queryResults = dao.query(query);
				int count = queryResults.size();

				// Delete
				DeleteBuilder<DataColumnConstraints, Void> db = dao
						.deleteBuilder();
				db.where().eq(DataColumnConstraints.COLUMN_CONSTRAINT_NAME,
						dataColumnConstraints.getConstraintName());
				PreparedDelete<DataColumnConstraints> deleteQuery = db
						.prepare();
				int deleted = dao.delete(deleteQuery);

				TestCase.assertEquals(count, deleted);

			}
		}
	}
}