io.agrest.cayenne.compiler.ObjectIdReader Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of agrest-cayenne Show documentation
Show all versions of agrest-cayenne Show documentation
Cayenne backend for Agrest
package io.agrest.cayenne.compiler;
import io.agrest.property.IdReader;
import org.apache.cayenne.ObjectId;
import org.apache.cayenne.Persistent;
import java.util.Map;
class ObjectIdReader implements IdReader {
private static final IdReader instance = new ObjectIdReader();
public static IdReader reader() {
return instance;
}
public Map id(Object root) {
ObjectId id = ((Persistent) root).getObjectId();
if (id.isTemporary()) {
// can only extract properties from permanent IDs
throw new IllegalArgumentException("Can't read from temporary ObjectId: " + id);
}
return id.getIdSnapshot();
}
}