try {
TileSet oldTileSet;
TileSet newTileSet;
Quota oldQuota;
Quota newQuota;
TilePage oldPage;
TilePage newPage;
while (null != (oldTileSet = tileSets.next())) {
final String gridsetId = oldTileSet.getGridsetId();
final String blobFormat = oldTileSet.getBlobFormat();
final String parametersId = oldTileSet.getParametersId();
newTileSet = new TileSet(newLayerName, gridsetId, blobFormat, parametersId);
// this creates the tileset's empty used Quota too
newTileSet = getOrCreateTileSet(transaction, newTileSet);
final String oldTileSetId = oldTileSet.getId();
final String newTileSetId = newTileSet.getId();
oldQuota = usedQuotaByTileSetId
.get(transaction, oldTileSetId, LockMode.DEFAULT);
newQuota = usedQuotaByTileSetId
.get(transaction, newTileSetId, LockMode.DEFAULT);
newQuota.setBytes(oldQuota.getBytes());
usedQuotaById.putNoReturn(transaction, newQuota);
EntityCursor<TilePage> oldPages = pagesByTileSetId.entities(transaction,
oldTileSetId, true, oldTileSetId, true, CursorConfig.DEFAULT);
try {
while (null != (oldPage = oldPages.next())) {
long oldPageId = oldPage.getId();
newPage = new TilePage(newTileSetId, oldPage.getPageX(),
oldPage.getPageY(), oldPage.getZoomLevel());
pageById.put(transaction, newPage);
PageStats pageStats = pageStatsByPageId.get(oldPageId);
if (pageStats != null) {
pageStats.setPageId(newPage.getId());
pageStatsById.putNoReturn(transaction, pageStats);
}
}
} finally {
oldPages.close();