Skip to content

Instantly share code, notes, and snippets.

@cbmeeks
Created June 20, 2014 15:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cbmeeks/6e9130f799c81b3a47d9 to your computer and use it in GitHub Desktop.
Save cbmeeks/6e9130f799c81b3a47d9 to your computer and use it in GitHub Desktop.
Vaadin JPA Container Lazy Loading Broke
/**
* <strong>This implementation does not use lazy loading and performs
* <b>extremely</b> bad when the number of items is large! Do not use unless
* you absolutely have to!</strong>
* <p>
* {@inheritDoc }
*/
public int indexOfId(Object itemId) {
/*
* This is intentionally an ugly implementation! This method should not
* be used!
*/
int size = size();
if (size > 100) {
Logger.getLogger(getClass().getName())
.warning(
"(JPAContainer) WARNING! Invoking indexOfId() when size > 100 is not recommended!");
}
for (int i = 0; i < size; i++) {
Object id = getIdByIndex(i);
if (id == null) {
return -1;
} else if (id.equals(itemId)) {
if (!isWriteThrough() && bufferingDelegate.isDeleted(id)) {
return -1;
}
return i;
}
}
return -1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment