本文整理汇总了Java中com.j256.ormlite.dao.CloseableIterator类的典型用法代码示例。如果您正苦于以下问题:Java CloseableIterator类的具体用法?Java CloseableIterator怎么用?Java CloseableIterator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CloseableIterator类属于com.j256.ormlite.dao包,在下文中一共展示了CloseableIterator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: textList
import com.j256.ormlite.dao.CloseableIterator; //导入依赖的package包/类
public String textList() {
String result = "";
CloseableIterator<DbRequest> iterator = null;
try {
iterator = MainApp.getDbHelper().getDbRequestInterator();
try {
while (iterator.hasNext()) {
DbRequest dbr = iterator.next();
result += "<br>";
result += dbr.action.toUpperCase() + " ";
result += dbr.collection + ": ";
result += dbr.data;
}
} finally {
iterator.close();
}
} catch (SQLException e) {
log.error("Unhandled exception", e);
}
return result;
}
示例2: query
import com.j256.ormlite.dao.CloseableIterator; //导入依赖的package包/类
/**
* Query for all feature index results
*
* @return feature index results, close when done
*/
public FeatureIndexResults query() {
FeatureIndexResults results = null;
switch (getIndexedType()) {
case GEOPACKAGE:
long count = featureTableIndex.count();
CloseableIterator<GeometryIndex> geometryIndices = featureTableIndex.query();
results = new FeatureIndexGeoPackageResults(featureTableIndex, count, geometryIndices);
break;
case METADATA:
Cursor geometryMetadata = featureIndexer.query();
results = new FeatureIndexMetadataResults(featureIndexer, geometryMetadata);
break;
}
return results;
}
示例3: obtainCursor
import com.j256.ormlite.dao.CloseableIterator; //导入依赖的package包/类
private Cursor obtainCursor(PreparedQuery<Observation> query, Dao<Observation, Long> oDao) throws SQLException {
Cursor c = null;
CloseableIterator<Observation> iterator = oDao.iterator(query);
// get the raw results which can be cast under Android
AndroidDatabaseResults results = (AndroidDatabaseResults) iterator.getRawResults();
c = results.getRawCursor();
if (c.moveToLast()) {
long oldestTime = c.getLong(c.getColumnIndex("last_modified"));
Log.i(LOG_NAME, "last modified is: " + c.getLong(c.getColumnIndex("last_modified")));
Log.i(LOG_NAME, "querying again in: " + (oldestTime - requeryTime)/60000 + " minutes");
if (queryUpdateHandle != null) {
queryUpdateHandle.cancel(true);
}
queryUpdateHandle = scheduler.schedule(new Runnable() {
public void run() {
updateFilter();
}
}, oldestTime - requeryTime, TimeUnit.MILLISECONDS);
c.moveToFirst();
}
return c;
}
示例4: obtainCursor
import com.j256.ormlite.dao.CloseableIterator; //导入依赖的package包/类
private Cursor obtainCursor(PreparedQuery<Location> query, Dao<Location, Long> lDao) throws SQLException {
Cursor c = null;
CloseableIterator<Location> iterator = lDao.iterator(query);
// get the raw results which can be cast under Android
AndroidDatabaseResults results = (AndroidDatabaseResults) iterator.getRawResults();
c = results.getRawCursor();
if (c.moveToLast()) {
if (queryUpdateHandle != null) {
queryUpdateHandle.cancel(true);
}
queryUpdateHandle = scheduler.schedule(new Runnable() {
public void run() {
updateTimeFilter(getTimeFilterId());
}
}, 30*1000, TimeUnit.MILLISECONDS);
c.moveToFirst();
}
return c;
}
示例5: iterator
import com.j256.ormlite.dao.CloseableIterator; //导入依赖的package包/类
private CloseableIterator<Location> iterator() throws SQLException {
Dao<Location, Long> dao = DaoStore.getInstance(context).getLocationDao();
QueryBuilder<Location, Long> query = dao.queryBuilder();
Where<? extends Temporal, Long> where = query.where().ge("timestamp", locationCollection.getLatestDate());
User currentUser = null;
try {
currentUser = UserHelper.getInstance(context.getApplicationContext()).readCurrentUser();
} catch (UserException e) {
e.printStackTrace();
}
if (currentUser != null) {
where.and().ne("user_id", currentUser.getId()).and().eq("event_id", currentUser.getUserLocal().getCurrentEvent().getId());
}
if (filter != null) {
filter.and(where);
}
query.orderBy("timestamp", false);
return dao.iterator(query.prepare());
}
示例6: doInBackground
import com.j256.ormlite.dao.CloseableIterator; //导入依赖的package包/类
@Override
protected Void doInBackground(Void... params ) {
CloseableIterator<Observation> iterator = null;
try {
iterator = iterator();
while (iterator.hasNext() && !isCancelled()) {
Observation o = iterator.current();
Geometry geometry = o.getGeometry();
Point centroid = GeometryUtils.getCentroid(geometry);
MarkerOptions options = new MarkerOptions().position(new LatLng(centroid.getY(), centroid.getX())).icon(ObservationBitmapFactory.bitmapDescriptor(context, o));
publishProgress(new Pair<>(options, o));
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
if (iterator != null) {
iterator.closeQuietly();
}
}
return null;
}
示例7: iterator
import com.j256.ormlite.dao.CloseableIterator; //导入依赖的package包/类
private CloseableIterator<Observation> iterator() throws SQLException {
Dao<Observation, Long> dao = DaoStore.getInstance(context).getObservationDao();
QueryBuilder<Observation, Long> query = dao.queryBuilder();
Where<Observation, Long> where = query
.orderBy("timestamp", false)
.where()
.ge("last_modified", observationCollection.getLatestDate())
.and()
.eq("event_id", currentEventId);
for (Filter filter : filters) {
QueryBuilder<?, ?> filterQuery = filter.query();
if (filterQuery != null) {
query.join(filterQuery);
}
filter.and(where);
}
return dao.iterator(query.prepare());
}
示例8: loadLazyForeignCollection
import com.j256.ormlite.dao.CloseableIterator; //导入依赖的package包/类
/**
* Load a Collection who was not loaded du to lazyLoading.
*
* @param toLoad Collection to load.
* @param <T> Type of objects of the collection.
* @return List of loaded objects.
*/
public static <T> List<T> loadLazyForeignCollection(final Collection<T> toLoad) {
return wrapException(new Callable<List<T>>() {
@Override
public List<T> call() throws Exception {
ArrayList<T> result = new ArrayList<>();
if (!(toLoad instanceof LazyForeignCollection)) {
throw new RuntimeException("not a lazyloaded collection");
}
CloseableIterator<T> iterator = ((LazyForeignCollection<T, Long>) toLoad).closeableIterator();
try {
while (iterator.hasNext()) {
result.add(iterator.next());
}
} finally {
iterator.close();
}
return result;
}
});
}
示例9: query
import com.j256.ormlite.dao.CloseableIterator; //导入依赖的package包/类
/**
* Query for all Geometry Index objects
*
* @return geometry indices iterator
*/
public CloseableIterator<GeometryIndex> query() {
CloseableIterator<GeometryIndex> geometryIndices = null;
QueryBuilder<GeometryIndex, GeometryIndexKey> qb = queryBuilder();
try {
geometryIndices = qb.iterator();
} catch (SQLException e) {
throw new GeoPackageException(
"Failed to query for all Geometry Indices. GeoPackage: "
+ geoPackage.getName() + ", Table Name: "
+ tableName + ", Column Name: " + columnName, e);
}
return geometryIndices;
}
示例10: getGeometryColumns
import com.j256.ormlite.dao.CloseableIterator; //导入依赖的package包/类
/**
* Get the Geometry Columns, should only return one or no value
*
* @return geometry columns
*/
public GeometryColumns getGeometryColumns() {
GeometryColumns result = null;
if (geometryColumns.size() > 1) {
// This shouldn't happen with the unique table name constraint on
// geometry columns
throw new GeoPackageException(
"Unexpected state. More than one GeometryColumn has a foreign key to the Contents. Count: "
+ geometryColumns.size());
} else if (geometryColumns.size() == 1) {
CloseableIterator<GeometryColumns> iterator = geometryColumns
.closeableIterator();
try {
result = iterator.next();
} finally {
try {
iterator.close();
} catch (IOException e) {
throw new GeoPackageException(
"Failed to close the Geometry Columns iterator", e);
}
}
}
return result;
}
示例11: getTileMatrixSet
import com.j256.ormlite.dao.CloseableIterator; //导入依赖的package包/类
/**
* Get the Tile Matrix Set, should only return one or no value
*
* @return tile matrix set
*/
public TileMatrixSet getTileMatrixSet() {
TileMatrixSet result = null;
if (tileMatrixSet.size() > 1) {
// This shouldn't happen with the table name primary key on tile
// matrix set
throw new GeoPackageException(
"Unexpected state. More than one TileMatrixSet has a foreign key to the Contents. Count: "
+ tileMatrixSet.size());
} else if (tileMatrixSet.size() == 1) {
CloseableIterator<TileMatrixSet> iterator = tileMatrixSet
.closeableIterator();
try {
result = iterator.next();
} finally {
try {
iterator.close();
} catch (IOException e) {
throw new GeoPackageException(
"Failed to close the Tile Matrix Set iterator", e);
}
}
}
return result;
}
示例12: drawTile
import com.j256.ormlite.dao.CloseableIterator; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public BufferedImage drawTile(int zoom, BoundingBox webMercatorBoundingBox,
CloseableIterator<GeometryIndex> results) {
// Create image and graphics
BufferedImage image = createNewImage();
Graphics2D graphics = getGraphics(image);
// WGS84 to web mercator projection and google shape converter
ProjectionTransform webMercatorTransform = getWebMercatorTransform();
while (results.hasNext()) {
GeometryIndex geometryIndex = results.next();
FeatureRow featureRow = getFeatureIndex().getFeatureRow(
geometryIndex);
drawFeature(zoom, webMercatorBoundingBox, webMercatorTransform,
graphics, featureRow);
}
return image;
}
示例13: testBasic
import com.j256.ormlite.dao.CloseableIterator; //导入依赖的package包/类
@Test
public void testBasic() throws Exception {
Dao<MyDouble, Object> dao = createDao(MyDouble.class, true);
MyDouble foo = new MyDouble();
foo.val = 1.23456789123456;
assertEquals(1, dao.create(foo));
MyDouble result = dao.queryForId(foo.id);
assertNotNull(result);
assertEquals(foo.val, result.val, 0.0);
GenericRawResults<String[]> results = dao.queryRaw(dao.queryBuilder().prepareStatementString());
CloseableIterator<String[]> iterator = results.closeableIterator();
try {
assertTrue(iterator.hasNext());
String[] strings = iterator.next();
assertNotNull(strings);
assertTrue(strings.length >= 2);
assertEquals(Integer.toString(foo.id), strings[0]);
assertEquals(Double.toString(foo.val), strings[1]);
} finally {
iterator.close();
}
}
示例14: testCloseInIterator
import com.j256.ormlite.dao.CloseableIterator; //导入依赖的package包/类
public void testCloseInIterator() throws Exception {
Dao<Foo, Integer> fooDao = createDao(Foo.class, true);
Foo foo1 = new Foo();
foo1.stuff = "s1";
fooDao.create(foo1);
CloseableIterator<Foo> iterator = fooDao.iterator();
try {
while (iterator.hasNext()) {
iterator.next();
closeConnectionSource();
}
if (!CLOSE_IS_NOOP) {
fail("expected exception");
}
} catch (IllegalStateException e) {
// expected
} finally {
iterator.close();
}
}
示例15: testCloseIteratorBeforeNext
import com.j256.ormlite.dao.CloseableIterator; //导入依赖的package包/类
public void testCloseIteratorBeforeNext() throws Exception {
Dao<Foo, Integer> fooDao = createDao(Foo.class, true);
Foo foo1 = new Foo();
foo1.stuff = "s1";
fooDao.create(foo1);
CloseableIterator<Foo> iterator = fooDao.iterator();
try {
while (iterator.hasNext()) {
closeConnectionSource();
iterator.next();
}
if (!CLOSE_IS_NOOP) {
fail("expected exception");
}
} catch (IllegalStateException e) {
// expected
} finally {
iterator.close();
}
}