if (value != null && ClassInfo.isModel(value.getClass())) {
Key key = GaeMappingUtils.getKey(value);
q.addFilter(propertyName, op, key);
} else {
if (ClassInfo.isId(f)) {
Id id = f.getAnnotation(Id.class);
switch(id.value()) {
case NONE:
if(value != null){
if(!Collection.class.isAssignableFrom(value.getClass())){
// long or string goes toString
Key key;
if(parentKey == null){
key = KeyFactory.createKey(
q.getKind(),
value.toString());
}else {
key = KeyFactory.createKey(
parentKey,
q.getKind(),
value.toString());
}
q.addFilter(Entity.KEY_RESERVED_PROPERTY, op, key);
}else {
List<Key> keys = new ArrayList<Key>();
for(Object val: (Collection<?>)value) {
if(parentKey == null){
keys.add(KeyFactory.createKey(q.getKind(), val.toString()));
}else {
keys.add(KeyFactory.createKey(parentKey, q.getKind(), val.toString()));
}
}
q.addFilter(Entity.KEY_RESERVED_PROPERTY, op, keys);
}
}
break;
case AUTO_INCREMENT:
if(value != null){
if(!Collection.class.isAssignableFrom(value.getClass())){
Key key;
Class<?> type = f.getType();
if(Long.TYPE == type || Long.class.isAssignableFrom(type)){
if(parentKey == null){
key = KeyFactory.createKey(
q.getKind(),
(Long)value);
}else {
key = KeyFactory.createKey(
parentKey,
q.getKind(),
(Long)value);
}
} else {
if(parentKey == null){
key = KeyFactory.createKey(
q.getKind(),
value.toString());
}else {
key = KeyFactory.createKey(
parentKey,
q.getKind(),
value.toString());
}
}
q.addFilter(Entity.KEY_RESERVED_PROPERTY, op, key);
}else {
List<Key> keys = new ArrayList<Key>();
for(Object val: (Collection<?>)value) {
if (value instanceof String)
val = Long.parseLong((String) val);
if(parentKey == null){
keys.add(KeyFactory.createKey(q.getKind(), (Long)val));
}else {
keys.add(KeyFactory.createKey(parentKey, q.getKind(), (Long)val));
}
}
q.addFilter(Entity.KEY_RESERVED_PROPERTY, op, keys);
}
}
break;
case UUID:
if(value != null) {
if(!Collection.class.isAssignableFrom(value.getClass())){
// long or string goes toString
Key key;
if(parentKey == null){
key = KeyFactory.createKey(
q.getKind(),
value.toString());
}else {
key = KeyFactory.createKey(
parentKey,
q.getKind(),
value.toString());
}
q.addFilter(Entity.KEY_RESERVED_PROPERTY, op, key);
}else {
List<Key> keys = new ArrayList<Key>();
for(Object val: (Collection<?>)value) {
keys.add(KeyFactory.createKey(q.getKind(), val.toString()));
}
q.addFilter(Entity.KEY_RESERVED_PROPERTY, op, keys);
}
}
break;
default:
throw new SienaException("Id Generator "+id.value()+ " not supported");
}
} else if (Enum.class.isAssignableFrom(f.getType())) {
value = value.toString();
q.addFilter(propertyName, op, value);