use of org.apache.cayenne.CayenneRuntimeException in project cayenne by apache.
the class ChildDiffLoader method nodeCreated.
public void nodeCreated(Object nodeId) {
setExternalChange(Boolean.TRUE);
try {
ObjectId id = (ObjectId) nodeId;
if (id.getEntityName() == null) {
throw new NullPointerException("Null entity name in id " + id);
}
ObjEntity entity = context.getEntityResolver().getObjEntity(id.getEntityName());
if (entity == null) {
throw new IllegalArgumentException("Entity not mapped with Cayenne: " + id);
}
Persistent dataObject;
try {
dataObject = (Persistent) entity.getJavaClass().newInstance();
} catch (Exception ex) {
throw new CayenneRuntimeException("Error instantiating object.", ex);
}
dataObject.setObjectId(id);
context.registerNewObject(dataObject);
} finally {
setExternalChange(Boolean.FALSE);
}
}
use of org.apache.cayenne.CayenneRuntimeException in project cayenne by apache.
the class CayenneProjectPreferences method removeProjectDetailObject.
// delete property
public void removeProjectDetailObject(Preferences preference) {
try {
preference.removeNode();
projectCayennePreferences.remove(preference);
} catch (BackingStoreException e) {
throw new CayenneRuntimeException("Error delete preferences", e);
}
}
use of org.apache.cayenne.CayenneRuntimeException in project cayenne by apache.
the class PropertyListSerialization method writeObject.
/**
* Internal method to recursively write a property list object.
*/
protected static void writeObject(String offset, Writer out, Object plist) throws IOException {
if (plist == null) {
return;
}
if (plist instanceof Collection) {
Collection list = (Collection) plist;
out.write('\n');
out.write(offset);
if (list.size() == 0) {
out.write("()");
return;
}
out.write("(\n");
String childOffset = offset + " ";
Iterator it = list.iterator();
boolean appended = false;
while (it.hasNext()) {
// Java collections can contain nulls, skip them
Object obj = it.next();
if (obj != null) {
if (appended) {
out.write(", \n");
}
out.write(childOffset);
writeObject(childOffset, out, obj);
appended = true;
}
}
out.write('\n');
out.write(offset);
out.write(')');
} else if (plist instanceof Map) {
Map map = (Map) plist;
out.write('\n');
out.write(offset);
if (map.size() == 0) {
out.write("{}");
return;
}
out.write("{");
String childOffset = offset + " ";
Iterator it = map.entrySet().iterator();
while (it.hasNext()) {
// Java collections can contain nulls, skip them
Map.Entry entry = (Map.Entry) it.next();
Object key = entry.getKey();
if (key == null) {
continue;
}
Object obj = entry.getValue();
if (obj == null) {
continue;
}
out.write('\n');
out.write(childOffset);
out.write(quoteString(key.toString()));
out.write(" = ");
writeObject(childOffset, out, obj);
out.write(';');
}
out.write('\n');
out.write(offset);
out.write('}');
} else if (plist instanceof String) {
out.write(quoteString(plist.toString()));
} else if (plist instanceof Number) {
out.write(plist.toString());
} else {
throw new CayenneRuntimeException("Unsupported class for property list serialization: " + plist.getClass().getName());
}
}
use of org.apache.cayenne.CayenneRuntimeException in project cayenne by apache.
the class WOCompatCase method setupTestDirectory.
protected File setupTestDirectory(String subfolder) {
String classPath = getClass().getName().replace('.', '/');
String location = "target/testrun/" + classPath + "/" + subfolder;
File testDirectory = new File(location);
// delete old tests
if (testDirectory.exists()) {
if (!FileUtil.delete(location, true)) {
throw new CayenneRuntimeException("Error deleting test directory '%s'", location);
}
}
if (!testDirectory.mkdirs()) {
throw new CayenneRuntimeException("Error creating test directory '%s'", location);
}
return testDirectory;
}
use of org.apache.cayenne.CayenneRuntimeException in project cayenne by apache.
the class EntityUtils method getMapKeyType.
/**
* Returns the map key type for a collection relationship of type
* java.util.Map.
*
* @param relationship
* The relationship to look up type information for.
* @return The type of the attribute keyed on.
*/
public String getMapKeyType(final ObjRelationship relationship) {
ObjEntity targetEntity = (ObjEntity) relationship.getTargetEntity();
// key.
if (relationship.getMapKey() == null) {
// If it's a multi-column key, then the return type is always
// ObjectId.
DbEntity dbEntity = targetEntity.getDbEntity();
if ((dbEntity != null) && (dbEntity.getPrimaryKeys().size() > 1)) {
return ObjectId.class.getName();
}
// so default to Object.
return Object.class.getName();
}
// If the map key is a non-default attribute, then fetch the attribute
// and return
// its type.
ObjAttribute attribute = targetEntity.getAttribute(relationship.getMapKey());
if (attribute == null) {
throw new CayenneRuntimeException("Invalid map key '%s', no matching attribute found", relationship.getMapKey());
}
return attribute.getType();
}
Aggregations