Created
June 20, 2014 15:25
-
-
Save cbmeeks/6e9130f799c81b3a47d9 to your computer and use it in GitHub Desktop.
Vaadin JPA Container Lazy Loading Broke
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* <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