// Item item = DomainHelper.findItemById(this.em.getSimpleDb(), domainName, id);
// now set attributes
List<ReplaceableAttribute> attsToPut = new ArrayList<ReplaceableAttribute>();
List<Attribute> attsToDelete = new ArrayList<Attribute>();
if (ai.getDiscriminatorValue() != null) {
attsToPut.add(new ReplaceableAttribute(EntityManagerFactoryImpl.DTYPE, ai.getDiscriminatorValue(), true));
}
LazyInterceptor interceptor = null;
if (o instanceof Factory) {
Factory factory = (Factory) o;
/*for (Callback callback2 : factory.getCallbacks()) {
if(logger.isLoggable(Level.FINER)) logger.finer("callback=" + callback2);
if (callback2 instanceof LazyInterceptor) {
interceptor = (LazyInterceptor) callback2;
}
}*/
interceptor = (LazyInterceptor) factory.getCallback(0);
}
Collection<Method> getters = ai.getGetters();
for (Method getter : getters) {
Object ob;
try
{
ob = getter.invoke(o);
}
catch (Exception e)
{
throw new PersistenceException("Failed invoking getter: " + getter, e);
}
String columnName = NamingHelper.getColumnName(getter);
if (ob == null) {
attsToDelete.add(new Attribute(columnName, null));
continue;
}
if (getter.getAnnotation(ManyToOne.class) != null) {
// store the id of this object
String id2 = em.getId(ob);
attsToPut.add(new ReplaceableAttribute(columnName, id2, true));
} else if (getter.getAnnotation(OneToMany.class) != null) {
// FORCING BI-DIRECTIONAL RIGHT NOW SO JUST IGNORE
} else if (getter.getAnnotation(Lob.class) != null) {
// store in s3
AmazonS3 s3 = null;
// todo: need to make sure we only store to S3 if it's changed, too slow.
logger.fine("putting lob to s3");
long start3 = System.currentTimeMillis();
s3 = em.getS3Service();
String bucketName = em.getS3BucketName();
String s3ObjectId = em.s3ObjectId(id, getter);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(bos);
out.writeObject(ob);
byte[] contentBytes = bos.toByteArray();
out.close();
InputStream input = new ByteArrayInputStream(contentBytes);
s3.putObject(bucketName, s3ObjectId, input, null);
em.statsS3Put(System.currentTimeMillis() - start3);
logger.finer("setting lobkeyattribute=" + columnName + " - " + s3ObjectId);
attsToPut.add(new ReplaceableAttribute(columnName, s3ObjectId, true));
} else if (getter.getAnnotation(Enumerated.class) != null) {
Enumerated enumerated = getter.getAnnotation(Enumerated.class);
Class retType = getter.getReturnType();
EnumType enumType = enumerated.value();
String toSet = null;
if (enumType == EnumType.STRING) {
toSet = ob.toString();
} else { // ordinal
Object[] enumConstants = retType.getEnumConstants();
for (int i = 0; i < enumConstants.length; i++) {
Object enumConstant = enumConstants[i];
if (enumConstant.toString().equals(ob.toString())) {
toSet = Integer.toString(i);
break;
}
}
}
if (toSet == null) {
// should never happen
throw new PersistenceException("Enum value is null, couldn't find ordinal match: " + ob);
}
attsToPut.add(new ReplaceableAttribute(columnName, toSet, true));
}
else if(getter.getAnnotation(Id.class) != null)
{
continue;
}
else {
String toSet = ob != null ? em.padOrConvertIfRequired(ob) : "";
// todo: throw an exception if this is going to exceed maximum size, suggest using @Lob
attsToPut.add(new ReplaceableAttribute(columnName, toSet, true));
}
}
// Now finally send it for storage (If have attributes to add)
long start2 = System.currentTimeMillis();