android.database.DatabaseErrorHandler#mil.nga.geopackage.core.contents.Contents源码实例Demo

下面列出了android.database.DatabaseErrorHandler#mil.nga.geopackage.core.contents.Contents 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: geopackage-android   文件: FeatureDao.java
/**
 * Constructor
 *
 * @param database        database name
 * @param db              connection
 * @param geometryColumns geometry columns
 * @param table           feature table
 */
public FeatureDao(String database, GeoPackageConnection db, GeometryColumns geometryColumns,
                  FeatureTable table) {
    super(database, db, new FeatureConnection(db), table);

    this.featureDb = (FeatureConnection) getUserDb();
    this.geometryColumns = geometryColumns;
    if (geometryColumns.getContents() == null) {
        throw new GeoPackageException(GeometryColumns.class.getSimpleName()
                + " " + geometryColumns.getId() + " has null "
                + Contents.class.getSimpleName());
    }
    if (geometryColumns.getSrs() == null) {
        throw new GeoPackageException(GeometryColumns.class.getSimpleName()
                + " " + geometryColumns.getId() + " has null "
                + SpatialReferenceSystem.class.getSimpleName());
    }

    projection = geometryColumns.getProjection();
}
 
源代码2 项目: geopackage-android   文件: GeoPackageImpl.java
/**
 * {@inheritDoc}
 */
@Override
public FeatureDao getFeatureDao(Contents contents) {

    if (contents == null) {
        throw new GeoPackageException("Non null "
                + Contents.class.getSimpleName()
                + " is required to create "
                + FeatureDao.class.getSimpleName());
    }

    GeometryColumns geometryColumns = contents.getGeometryColumns();
    if (geometryColumns == null) {
        throw new GeoPackageException("No "
                + GeometryColumns.class.getSimpleName() + " exists for "
                + Contents.class.getSimpleName() + " " + contents.getId());
    }

    return getFeatureDao(geometryColumns);
}
 
源代码3 项目: geopackage-android   文件: GeoPackageImpl.java
/**
 * {@inheritDoc}
 */
@Override
public TileDao getTileDao(Contents contents) {

    if (contents == null) {
        throw new GeoPackageException("Non null "
                + Contents.class.getSimpleName()
                + " is required to create " + TileDao.class.getSimpleName());
    }

    TileMatrixSet tileMatrixSet = contents.getTileMatrixSet();
    if (tileMatrixSet == null) {
        throw new GeoPackageException("No "
                + TileMatrixSet.class.getSimpleName() + " exists for "
                + Contents.class.getSimpleName() + " " + contents.getId());
    }

    return getTileDao(tileMatrixSet);
}
 
源代码4 项目: geopackage-android   文件: GeoPackageImpl.java
/**
 * {@inheritDoc}
 */
@Override
public AttributesDao getAttributesDao(String tableName) {

    ContentsDao dao = getContentsDao();
    Contents contents = null;
    try {
        contents = dao.queryForId(tableName);
    } catch (SQLException e) {
        throw new GeoPackageException("Failed to retrieve "
                + Contents.class.getSimpleName() + " for table name: "
                + tableName, e);
    }
    if (contents == null) {
        throw new GeoPackageException(
                "No Contents Table exists for table name: " + tableName);
    }
    return getAttributesDao(contents);
}
 
源代码5 项目: geopackage-java   文件: GeoPackageImpl.java
/**
 * {@inheritDoc}
 */
@Override
public AttributesDao getAttributesDao(Contents contents) {

	if (contents == null) {
		throw new GeoPackageException("Non null "
				+ Contents.class.getSimpleName() + " is required to create "
				+ AttributesDao.class.getSimpleName());
	}
	if (contents.getDataType() != ContentsDataType.ATTRIBUTES) {
		throw new GeoPackageException(Contents.class.getSimpleName()
				+ " is required to be of type "
				+ ContentsDataType.ATTRIBUTES + ". Actual: "
				+ contents.getDataTypeString());
	}

	// Read the existing table and create the dao
	AttributesTableReader tableReader = new AttributesTableReader(
			contents.getTableName());
	final AttributesTable attributesTable = tableReader.readTable(database);
	attributesTable.setContents(contents);
	AttributesDao dao = new AttributesDao(getName(), database,
			attributesTable);

	return dao;
}
 
源代码6 项目: geopackage-java   文件: GeoPackageImpl.java
/**
 * {@inheritDoc}
 */
@Override
public AttributesDao getAttributesDao(String tableName) {

	ContentsDao dao = getContentsDao();
	Contents contents = null;
	try {
		contents = dao.queryForId(tableName);
	} catch (SQLException e) {
		throw new GeoPackageException(
				"Failed to retrieve " + Contents.class.getSimpleName()
						+ " for table name: " + tableName,
				e);
	}
	if (contents == null) {
		throw new GeoPackageException(
				"No Contents Table exists for table name: " + tableName);
	}
	return getAttributesDao(contents);
}
 
/**
 * Set the contents in the user table
 * 
 * @param table
 *            user table
 */
public void setContents(UserTable<? extends UserColumn> table) {
	ContentsDao dao = geoPackage.getContentsDao();
	Contents contents = null;
	try {
		contents = dao.queryForId(table.getTableName());
	} catch (SQLException e) {
		throw new GeoPackageException(
				"Failed to retrieve " + Contents.class.getSimpleName()
						+ " for table name: " + table.getTableName(),
				e);
	}
	if (contents == null) {
		throw new GeoPackageException(
				"No Contents Table exists for table name: "
						+ table.getTableName());
	}
	table.setContents(contents);
}
 
源代码8 项目: geopackage-core-java   文件: GeometryColumns.java
/**
 * Set the contents
 * 
 * @param contents
 *            contents
 */
public void setContents(Contents contents) {
	this.contents = contents;
	if (contents != null) {
		// Verify the Contents have a features data type (Spec Requirement
		// 23)
		ContentsDataType dataType = contents.getDataType();
		if (dataType == null || dataType != ContentsDataType.FEATURES) {
			throw new GeoPackageException(
					"The " + Contents.class.getSimpleName() + " of a "
							+ GeometryColumns.class.getSimpleName()
							+ " must have a data type of "
							+ ContentsDataType.FEATURES.getName());
		}
		tableName = contents.getId();
	} else {
		tableName = null;
	}
}
 
public void setContents(Contents contents) {
	this.contents = contents;
	if (contents != null) {
		// Verify the Contents have a features data type (Spec Requirement
		// 23)
		ContentsDataType dataType = contents.getDataType();
		if (dataType == null || dataType != ContentsDataType.FEATURES) {
			throw new GeoPackageException("The "
					+ Contents.class.getSimpleName() + " of a "
					+ GeometryColumnsSqlMm.class.getSimpleName()
					+ " must have a data type of "
					+ ContentsDataType.FEATURES.getName());
		}
		tableName = contents.getId();
	}
}
 
public void setContents(Contents contents) {
	this.contents = contents;
	if (contents != null) {
		// Verify the Contents have a features data type (Spec Requirement
		// 23)
		ContentsDataType dataType = contents.getDataType();
		if (dataType == null || dataType != ContentsDataType.FEATURES) {
			throw new GeoPackageException("The "
					+ Contents.class.getSimpleName() + " of a "
					+ GeometryColumnsSfSql.class.getSimpleName()
					+ " must have a data type of "
					+ ContentsDataType.FEATURES.getName());
		}
		fTableName = contents.getId();
	}
}
 
源代码11 项目: geopackage-core-java   文件: GeoPackageCoreImpl.java
/**
 * Copy the user table
 * 
 * @param tableName
 *            table name
 * @param newTableName
 *            new table name
 * @param transferContent
 *            transfer user table content flag
 * @param validateContents
 *            true to validate a contents was copied
 * @return copied contents
 * @since 3.3.0
 */
protected Contents copyUserTable(String tableName, String newTableName,
		boolean transferContent, boolean validateContents) {

	AlterTable.copyTable(database, tableName, newTableName,
			transferContent);

	Contents contents = copyContents(tableName, newTableName);

	if (contents == null && validateContents) {
		throw new GeoPackageException(
				"No table contents found for table: " + tableName);
	}

	return contents;
}
 
源代码12 项目: geopackage-core-java   文件: GeoPackageCoreImpl.java
/**
 * Copy the contents
 * 
 * @param tableName
 *            table name
 * @param newTableName
 *            new table name
 * @return copied contents
 * @since 3.3.0
 */
protected Contents copyContents(String tableName, String newTableName) {

	Contents contents = getTableContents(tableName);

	if (contents != null) {

		contents.setTableName(newTableName);
		contents.setIdentifier(newTableName);

		try {
			getContentsDao().create(contents);
		} catch (SQLException e) {
			throw new GeoPackageException(
					"Failed to create contents for table: " + newTableName
							+ ", copied from table: " + tableName,
					e);
		}
	}

	return contents;
}
 
/**
 * Unregister all GeoPackage DAO with the connection source
 * 
 * @param connectionSource
 *            connection source
 */
public static void unregisterDaos(ConnectionSource connectionSource) {
	// TODO when ormlite-core version > 5.1 is released, replace with:
	// "DaoManager.unregisterDaos(connectionSource);"
	// See https://github.com/j256/ormlite-core/pull/149
	unregisterDao(connectionSource, Contents.class,
			SpatialReferenceSystem.class,
			SpatialReferenceSystemSfSql.class,
			SpatialReferenceSystemSqlMm.class, Extensions.class,
			GriddedCoverage.class, GriddedTile.class, GeometryIndex.class,
			TableIndex.class, FeatureTileLink.class,
			ExtendedRelation.class, TileScaling.class,
			GeometryColumns.class, GeometryColumnsSfSql.class,
			GeometryColumnsSqlMm.class, Metadata.class,
			MetadataReference.class, DataColumns.class,
			DataColumnConstraints.class, TileMatrix.class,
			TileMatrixSet.class, ContentsId.class);
}
 
源代码14 项目: geopackage-core-java   文件: TileMatrix.java
public void setContents(Contents contents) {
	this.contents = contents;
	if (contents != null) {
		// Verify the Contents have a tiles data type (Spec Requirement 42)
		ContentsDataType dataType = contents.getDataType();
		if (dataType == null
				|| (dataType != ContentsDataType.TILES && dataType != ContentsDataType.GRIDDED_COVERAGE)) {
			throw new GeoPackageException("The "
					+ Contents.class.getSimpleName() + " of a "
					+ TileMatrix.class.getSimpleName()
					+ " must have a data type of "
					+ ContentsDataType.TILES.getName() + " or "
					+ ContentsDataType.GRIDDED_COVERAGE.getName());
		}
		tableName = contents.getId();
	} else {
		tableName = null;
	}
}
 
源代码15 项目: geopackage-java   文件: GeoPackageTextOutput.java
/**
 * Text output from a Contents
 * 
 * @param contents
 *            contents
 * @return text
 */
public String textOutput(Contents contents) {
	StringBuilder output = new StringBuilder();
	output.append("\t" + Contents.COLUMN_TABLE_NAME + ": "
			+ contents.getTableName());
	output.append("\n\t" + Contents.COLUMN_DATA_TYPE + ": "
			+ contents.getDataType());
	output.append("\n\t" + Contents.COLUMN_IDENTIFIER + ": "
			+ contents.getIdentifier());
	output.append("\n\t" + Contents.COLUMN_DESCRIPTION + ": "
			+ contents.getDescription());
	output.append("\n\t" + Contents.COLUMN_LAST_CHANGE + ": "
			+ contents.getLastChange());
	output.append(
			"\n\t" + Contents.COLUMN_MIN_X + ": " + contents.getMinX());
	output.append(
			"\n\t" + Contents.COLUMN_MIN_Y + ": " + contents.getMinY());
	output.append(
			"\n\t" + Contents.COLUMN_MAX_X + ": " + contents.getMaxX());
	output.append(
			"\n\t" + Contents.COLUMN_MAX_Y + ": " + contents.getMaxY());
	output.append("\n" + textOutput(contents.getSrs()));
	return output.toString();
}
 
/**
 * Get table Contents object
 */
public Contents getTableContents(String gpName, String tableName) {
    GeoPackage geo = null;
    try{
        geo = manager.open(gpName);
        if(geo != null) {
            ContentsDao contentsDao = geo.getContentsDao();
            Contents contents = contentsDao.queryForId(tableName);
            return contents;
        }

    } catch (Exception e){

    } finally {
        if(geo !=  null){
            geo.close();
        }
    }
    return null;
}
 
源代码17 项目: geopackage-android-map   文件: TestUtils.java
/**
 * Create the feature table with data columns entry
 *
 * @param geoPackage
 * @param contents
 * @param geometryColumn
 * @param geometryType
 * @return
 * @throws SQLException
 */
public static FeatureTable createFeatureTable(GeoPackage geoPackage,
                                              Contents contents, String geometryColumn, GeometryType geometryType)
        throws SQLException {

    FeatureTable table = buildFeatureTable(contents.getTableName(),
            geometryColumn, geometryType);
    geoPackage.createFeatureTable(table);

    double random = Math.random();

    DataColumnsDao dataColumnsDao = geoPackage.getDataColumnsDao();
    DataColumns dataColumns = new DataColumns();
    dataColumns.setContents(contents);
    dataColumns.setColumnName(TEST_INTEGER_COLUMN);
    dataColumns.setName(contents.getTableName());
    dataColumns.setTitle("TEST_TITLE");
    dataColumns.setDescription("TEST_DESCRIPTION");
    dataColumns.setMimeType("TEST_MIME_TYPE");

    if (random < (1.0 / 3.0)) {
        dataColumns.setConstraintName(SAMPLE_RANGE_CONSTRAINT);
    } else if (random < (2.0 / 3.0)) {
        dataColumns.setConstraintName(SAMPLE_ENUM_CONSTRAINT);
    } else {
        dataColumns.setConstraintName(SAMPLE_GLOB_CONSTRAINT);
    }

    dataColumnsDao.create(dataColumns);

    return table;
}
 
源代码18 项目: geopackage-android   文件: FeatureDao.java
/**
 * {@inheritDoc}
 */
@Override
public BoundingBox getBoundingBox(Projection projection) {
    Contents contents = geometryColumns.getContents();
    BoundingBox boundingBox = contents.getBoundingBox(projection);
    return boundingBox;
}
 
源代码19 项目: geopackage-android   文件: AttributesDao.java
/**
 * Constructor
 *
 * @param database database
 * @param db       db connection
 * @param table    attributes table
 */
public AttributesDao(String database, GeoPackageConnection db,
                     AttributesTable table) {
    super(database, db, new AttributesConnection(db), table);

    this.attributesDb = (AttributesConnection) getUserDb();
    if (table.getContents() == null) {
        throw new GeoPackageException(AttributesTable.class.getSimpleName()
                + " " + table.getTableName() + " has null "
                + Contents.class.getSimpleName());
    }
}
 
源代码20 项目: geopackage-android   文件: GeoPackageImpl.java
/**
 * {@inheritDoc}
 */
@Override
public AttributesDao getAttributesDao(Contents contents) {

    if (contents == null) {
        throw new GeoPackageException("Non null "
                + Contents.class.getSimpleName()
                + " is required to create "
                + AttributesDao.class.getSimpleName());
    }
    if (contents.getDataType() != ContentsDataType.ATTRIBUTES) {
        throw new GeoPackageException(Contents.class.getSimpleName()
                + " is required to be of type "
                + ContentsDataType.ATTRIBUTES + ". Actual: "
                + contents.getDataTypeString());
    }

    // Read the existing table and create the dao
    AttributesTableReader tableReader = new AttributesTableReader(
            contents.getTableName());
    final AttributesTable attributesTable = tableReader.readTable(database);
    attributesTable.setContents(contents);
    AttributesDao dao = new AttributesDao(getName(), database,
            attributesTable);

    // Register the table name (with and without quotes) to wrap cursors with the attributes cursor
    registerCursorWrapper(attributesTable.getTableName(),
            new GeoPackageCursorWrapper() {

                @Override
                public Cursor wrapCursor(Cursor cursor) {
                    return new AttributesCursor(attributesTable, cursor);
                }
            });

    return dao;
}
 
源代码21 项目: geopackage-java   文件: GeoPackageImpl.java
/**
 * {@inheritDoc}
 */
@Override
public TileDao getTileDao(Contents contents) {

	if (contents == null) {
		throw new GeoPackageException("Non null "
				+ Contents.class.getSimpleName() + " is required to create "
				+ TileDao.class.getSimpleName());
	}

	TileMatrixSet tileMatrixSet = null;
	try {
		tileMatrixSet = getTileMatrixSetDao()
				.queryForId(contents.getTableName());
	} catch (SQLException e) {
		throw new GeoPackageException("No "
				+ TileMatrixSet.class.getSimpleName()
				+ " could be retrieved for "
				+ Contents.class.getSimpleName() + " " + contents.getId());
	}

	if (tileMatrixSet == null) {
		throw new GeoPackageException("No "
				+ TileMatrixSet.class.getSimpleName() + " exists for "
				+ Contents.class.getSimpleName() + " " + contents.getId());
	}

	return getTileDao(tileMatrixSet);
}
 
/**
 * Validate contents
 * 
 * @param simpleAttributesTable
 *            simple attributes table
 * @param contents
 *            contents
 */
private static void validateContents(
		SimpleAttributesTable simpleAttributesTable, Contents contents) {
	TestCase.assertNotNull(contents);
	TestCase.assertNotNull(contents.getDataType());
	TestCase.assertEquals(
			SimpleAttributesTable.RELATION_TYPE.getDataType(), contents
					.getDataType().getName());
	TestCase.assertEquals(
			SimpleAttributesTable.RELATION_TYPE.getDataType(),
			contents.getDataTypeString());
	TestCase.assertEquals(simpleAttributesTable.getTableName(),
			contents.getTableName());
	TestCase.assertNotNull(contents.getLastChange());
}
 
源代码23 项目: geopackage-android   文件: RelatedMediaUtils.java
/**
 * Validate contents
 *
 * @param mediaTable media table
 * @param contents   contents
 */
private static void validateContents(MediaTable mediaTable,
                                     Contents contents) {
    TestCase.assertNotNull(contents);
    TestCase.assertNotNull(contents.getDataType());
    TestCase.assertEquals(MediaTable.RELATION_TYPE.getDataType(), contents
            .getDataType().getName());
    TestCase.assertEquals(MediaTable.RELATION_TYPE.getDataType(),
            contents.getDataTypeString());
    TestCase.assertEquals(mediaTable.getTableName(),
            contents.getTableName());
    TestCase.assertNotNull(contents.getLastChange());
}
 
/**
 * Validate contents
 *
 * @param simpleAttributesTable simple attributes table
 * @param contents              contents
 */
private static void validateContents(
        SimpleAttributesTable simpleAttributesTable, Contents contents) {
    TestCase.assertNotNull(contents);
    TestCase.assertNotNull(contents.getDataType());
    TestCase.assertEquals(
            SimpleAttributesTable.RELATION_TYPE.getDataType(), contents
                    .getDataType().getName());
    TestCase.assertEquals(
            SimpleAttributesTable.RELATION_TYPE.getDataType(),
            contents.getDataTypeString());
    TestCase.assertEquals(simpleAttributesTable.getTableName(),
            contents.getTableName());
    TestCase.assertNotNull(contents.getLastChange());
}
 
源代码25 项目: geopackage-java   文件: FeatureDao.java
/**
 * {@inheritDoc}
 */
@Override
public BoundingBox getBoundingBox(Projection projection) {
	Contents contents = geometryColumns.getContents();
	BoundingBox boundingBox = contents.getBoundingBox(projection);
	return boundingBox;
}
 
源代码26 项目: geopackage-android   文件: TestUtils.java
/**
 * Create the feature table with data columns entry
 *
 * @param geoPackage
 * @param contents
 * @param geometryColumn
 * @param geometryType
 * @return
 * @throws SQLException
 */
public static FeatureTable createFeatureTable(GeoPackage geoPackage,
                                              Contents contents, String geometryColumn, GeometryType geometryType)
        throws SQLException {

    FeatureTable table = buildFeatureTable(contents.getTableName(),
            geometryColumn, geometryType);
    geoPackage.createFeatureTable(table);

    double random = Math.random();

    DataColumnsDao dataColumnsDao = geoPackage.getDataColumnsDao();
    DataColumns dataColumns = new DataColumns();
    dataColumns.setContents(contents);
    dataColumns.setColumnName(TEST_INTEGER_COLUMN);
    dataColumns.setName(contents.getTableName());
    dataColumns.setTitle("TEST_TITLE");
    dataColumns.setDescription("TEST_DESCRIPTION");
    dataColumns.setMimeType("TEST_MIME_TYPE");

    if (random < (1.0 / 3.0)) {
        dataColumns.setConstraintName(SAMPLE_RANGE_CONSTRAINT);
    } else if (random < (2.0 / 3.0)) {
        dataColumns.setConstraintName(SAMPLE_ENUM_CONSTRAINT);
    } else {
        dataColumns.setConstraintName(SAMPLE_GLOB_CONSTRAINT);
    }

    dataColumnsDao.create(dataColumns);

    return table;
}
 
源代码27 项目: geopackage-android   文件: TransactionTest.java
/**
 * Test a transaction on the GeoPackage
 *
 * @param geoPackage GeoPackage
 * @param successful true for a successful transaction
 */
private void testGeoPackage(GeoPackage geoPackage, boolean successful) {

    int count = SQLiteMaster.countViewsOnTable(geoPackage.getConnection(),
            Contents.TABLE_NAME);

    geoPackage.beginTransaction();

    try {

        geoPackage.execSQL("CREATE VIEW " + Contents.TABLE_NAME
                + "_view AS SELECT table_name AS tableName FROM "
                + Contents.TABLE_NAME);

    } catch (Exception e) {

        geoPackage.failTransaction();
        TestCase.fail(e.getMessage());

    } finally {

        if (successful) {
            geoPackage.endTransaction();
        } else {
            geoPackage.failTransaction();
        }

    }

    TestCase.assertEquals(successful ? count + 1 : count, SQLiteMaster
            .countViewsOnTable(geoPackage.getConnection(),
                    Contents.TABLE_NAME));
}
 
源代码28 项目: geopackage-core-java   文件: ContentsIdExtension.java
/**
 * Get by contents data type
 * 
 * @param type
 *            contents data type
 * @return contents ids
 */
public List<ContentsId> getIds(String type) {

	List<ContentsId> contentsIds = null;

	ContentsDao contentsDao = geoPackage.getContentsDao();

	try {

		if (contentsIdDao.isTableExists()) {

			QueryBuilder<Contents, String> contentsQueryBuilder = contentsDao
					.queryBuilder();
			QueryBuilder<ContentsId, Long> contentsIdQueryBuilder = contentsIdDao
					.queryBuilder();

			contentsQueryBuilder.where().eq(Contents.COLUMN_DATA_TYPE,
					type);
			contentsIdQueryBuilder.join(contentsQueryBuilder);

			contentsIds = contentsIdQueryBuilder.query();

		} else {
			contentsIds = new ArrayList<>();
		}
	} catch (SQLException e) {
		throw new GeoPackageException(
				"Failed to query for contents id by contents data type. GeoPackage: "
						+ geoPackage.getName() + ", Type: " + type,
				e);
	}

	return contentsIds;
}
 
源代码29 项目: geopackage-core-java   文件: ContentsId.java
/**
 * Set the contents
 * 
 * @param contents
 *            contents
 */
public void setContents(Contents contents) {
	this.contents = contents;
	if (contents != null) {
		this.tableName = contents.getId();
	} else {
		this.tableName = null;
	}
}
 
/**
 * Determine if the feature table is indexed
 * 
 * @return true if indexed
 */
public boolean isIndexed() {
	boolean indexed = false;
	Extensions extension = getExtension();
	if (extension != null) {

		ContentsDao contentsDao = geoPackage.getContentsDao();
		try {
			Contents contents = contentsDao.queryForId(tableName);
			if (contents != null) {
				Date lastChange = contents.getLastChange();

				TableIndexDao tableIndexDao = geoPackage.getTableIndexDao();
				TableIndex tableIndex = tableIndexDao.queryForId(tableName);

				if (tableIndex != null) {
					Date lastIndexed = tableIndex.getLastIndexed();
					indexed = lastIndexed != null && lastIndexed
							.getTime() >= lastChange.getTime();
				}
			}
		} catch (SQLException e) {
			throw new GeoPackageException(
					"Failed to check if table is indexed, GeoPackage: "
							+ geoPackage.getName() + ", Table Name: "
							+ tableName,
					e);
		}
	}
	return indexed;
}