mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
WIP update/refactoring on caching
This commit is contained in:
+33
-39
@@ -1,50 +1,44 @@
|
||||
package com.avaje.ebeaninternal.server.cache;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import com.avaje.ebeaninternal.server.core.PersistRequestBean;
|
||||
import com.avaje.ebean.bean.EntityBean;
|
||||
import com.avaje.ebean.bean.EntityBeanIntercept;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
|
||||
|
||||
/**
|
||||
* Create a new CachedBeanData based on the existing CachedBeanData and the updated bean.
|
||||
*/
|
||||
public class CachedBeanDataUpdate {
|
||||
|
||||
public static CachedBeanData update(BeanDescriptor<?> desc, CachedBeanData data, PersistRequestBean<?> updateRequest){
|
||||
/**
|
||||
* Create a new CachedBeanData based on the existing CachedBeanData and the updated bean.
|
||||
*/
|
||||
public static CachedBeanData update(BeanDescriptor<?> desc, CachedBeanData existingData, EntityBean updateBean) {
|
||||
|
||||
//
|
||||
// Set<String> loadedProperties = data.getLoadedProperties();
|
||||
// Object[] copyOfData = data.copyData();
|
||||
//
|
||||
// Object updateBean = updateRequest.getBean();
|
||||
// Set<String> updatedProperties = updateRequest.getUpdatedProperties();
|
||||
//
|
||||
// int naturalKeyUpdate = -1;
|
||||
// boolean mergeProperties = false;
|
||||
// BeanProperty[] props = desc.propertiesNonMany();
|
||||
// for (int i = 0; i < props.length; i++) {
|
||||
// if (updatedProperties.contains(props[i].getName())){
|
||||
// if (props[i].isNaturalKey()){
|
||||
// naturalKeyUpdate = i;
|
||||
// }
|
||||
// copyOfData[i] = props[i].getCacheDataValue(updateBean);
|
||||
// if (loadedProperties != null && !mergeProperties && !loadedProperties.contains(props[i].getName())){
|
||||
// mergeProperties = true;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// if (mergeProperties){
|
||||
// HashSet<String> mergeProps = new HashSet<String>();
|
||||
// mergeProps.addAll(loadedProperties);
|
||||
// mergeProps.addAll(updatedProperties);
|
||||
// loadedProperties = mergeProps;
|
||||
// }
|
||||
//
|
||||
// return new CachedBeanData(null, loadedProperties, copyOfData, naturalKeyUpdate);
|
||||
|
||||
return null;
|
||||
// take a copy of the raw data and loaded status
|
||||
boolean[] copyLoaded = existingData.copyLoaded();
|
||||
Object[] copyData = existingData.copyData();
|
||||
|
||||
EntityBeanIntercept ebi = updateBean._ebean_getIntercept();
|
||||
|
||||
Object newNaturalKey = null;
|
||||
Object oldNaturalKey = existingData.getNaturalKey();
|
||||
|
||||
BeanProperty[] props = desc.propertiesNonMany();
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
// check if the properties was in the update
|
||||
int propertyIndex = props[i].getPropertyIndex();
|
||||
if (ebi.isLoadedProperty(propertyIndex)) {
|
||||
if (props[i].isNaturalKey()) {
|
||||
newNaturalKey = updateBean._ebean_getField(i);
|
||||
}
|
||||
// set the cache safe value for the property and mark it as loaded
|
||||
copyData[propertyIndex] = props[i].getCacheDataValue(updateBean);
|
||||
copyLoaded[propertyIndex] = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
return new CachedBeanData(null, copyLoaded, copyData, newNaturalKey, oldNaturalKey);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user