Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add method to pull entities from the save buffer #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,53 @@ public void commitBulkWrite()
entitiesToBulkPut.clear();
}

/**
* This equals can be used to compare anything, but specifically it's useful
* to compare key equality.
*
* @param value1
* @param value2
* @return
*/
public static boolean equals(Object value1, Object value2)
{
if (value1 == value2) return true;

if (value1 instanceof Key && value2 instanceof Key)
{
// This is a special case that is necessary for bulkWriteMode. In
// bulkWriteMode,
// the value1==value2 test above would have found equality
// appropriately, therefore
// we must conclude that they are not equal
if (((Key) value1).isComplete() == false && ((Key) value2).isComplete() == false) return false;

if (((Key) value1).getId() == ((Key) value2).getId() && ((Key) value1).getKind().equals(((Key) value2).getKind()))
return true;
else
return false;
}
if (value1 != null && value2 != null && value1.equals(value2)) return true;

return false;
}

/**
* Fetches entities from the save buffer
* @param type
* @param fieldName
* @param equalToValue
* @return
*/
public List<CachedEntity> interceptFromBulkPut(String type, String fieldName, Object equalToValue){
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getEntityListForBulkPut() might be a better word?

This doesn't actually do any intercepting on it's own, it just retrieves the list.

List<CachedEntity> result = new ArrayList<>();
for(CachedEntity ce : entitiesToBulkPut) {
if(equals(ce.getProperty(fieldName), equalToValue) && equals(ce.getKind(), type))
result.add(ce);
}
return result;
}


public void beginTransaction()
{
Expand Down