if (_persistence == null) {
throw new PersistenceException("non persistence capable: "
+ oid.getName());
}
ProposedEntity entity = new ProposedEntity();
entity.initializeFields(_fhs.length);
Identity ids = oid.getIdentity();
// set the new timeStamp into the data object
long timeStamp = System.currentTimeMillis();
if (object instanceof TimeStampable) {
((TimeStampable) object).jdoSetTimeStamp(timeStamp);
}
// copy the object to cache should make a new field now,
for (int i = 0; i < _fhs.length; i++) {
fieldType = _fhs[i].getFieldType();
switch (fieldType) {
case FieldMolder.PRIMITIVE:
case FieldMolder.PERSISTANCECAPABLE:
case FieldMolder.SERIALIZABLE:
case FieldMolder.ONE_TO_MANY:
case FieldMolder.MANY_TO_MANY:
entity.setField(_resolvers[i].create(tx, object), i);
break;
default:
throw new IllegalArgumentException("Field type invalid!");
}
}
// ask Persistent to create the object into the persistence storage
Identity createdId = _persistence.create(tx.getDatabase(),
tx.getConnection(oid.getMolder().getLockEngine()), entity, ids);
if (createdId == null) {
throw new PersistenceException("Identity can't be created!");
}
// set the field values into the cache
locker.setObject(tx, entity.getFields(), timeStamp);
oid.setDbLock(true);
// set the identity into the object
setIdentity(tx, object, createdId);
// after successful creation, add the entry in the relation table for
// all many-to-many relationship
for (int i = 0; i < _fhs.length; i++) {
entity.setField(_resolvers[i].postCreate(
tx, oid, object, entity.getField(i), createdId), i);
}
return createdId;
}