{
// avoid unnecessary request to database
return new ArrayList<NodeDataIndexing>();
}
JDBCStorageConnection conn = (JDBCStorageConnection)connFactory.openConnection();
final boolean isOffsetSupported = connFactory.isOffsetSupported();
try
{
if (!isOffsetSupported)
{
// The offset is not supported so we need to synchronize the access
lock.lock();
}
int currentOffset;
String currentLastNodeId;
int currentPage;
synchronized (this)
{
currentOffset = offset.getAndAdd(pageSize);
currentLastNodeId = lastNodeId.get();
currentPage = page.incrementAndGet();
}
if (!hasNext())
{
// avoid unnecessary request to database
return new ArrayList<NodeDataIndexing>();
}
long time = 0;
if (PropertyManager.isDevelopping())
{
time = System.currentTimeMillis();
}
List<NodeDataIndexing> result = conn.getNodesAndProperties(currentLastNodeId, currentOffset, pageSize);
if (PropertyManager.isDevelopping())
{
LOG.info("Page = " + currentPage + " Offset = " + currentOffset + " LastNodeId = '" + currentLastNodeId
+ "', query time = " + (System.currentTimeMillis() - time) + " ms, from '"
+ (result.isEmpty() ? "unknown" : result.get(0).getIdentifier()) + "' to '"
+ (result.isEmpty() ? "unknown" : result.get(result.size() - 1).getIdentifier()) + "'");
}
hasNext.compareAndSet(true, result.size() == pageSize);
if (hasNext() && connFactory.isIDNeededForPaging())
{
synchronized (this)
{
lastNodeId.set(result.get(result.size() - 1).getIdentifier());
offset.set((page.get() - currentPage) * pageSize);
}
}
return result;
}
finally
{
if (!isOffsetSupported)
{
// The offset is not supported so we need to synchronize the access
lock.unlock();
}
conn.close();
}
}