PhotoInfo photo, int instanceType ) {
log.debug( "Creating instance, volume = " + volume.getName() + " photo = " + photo.getUid()
+ " image file = " + imageFile.getName() );
// Initialize transaction context
ODMGXAWrapper txw = new ODMGXAWrapper();
ImageInstance f = new ImageInstance();
f.uuid = UUID.randomUUID();
// Set up the primary key fields before locking the object
f.volume = volume;
f.volumeId = volume.getName();
f.imageFile = imageFile;
f.fileSize = imageFile.length();
f.mtime = imageFile.lastModified();
f.fname = volume.mapFileToVolumeRelativeName( imageFile );
f.instanceType = instanceType;
txw.lock( f, Transaction.WRITE );
log.debug( "locked instance" );
f.photoUid = photo.getUid();
// Read the rest of fields from the image file
try {
f.readImageFile();
} catch (Exception e ) {
txw.abort();
log.warn( "Error opening image file: " + e.getMessage() );
// The image does not exist, so it cannot be read!!!
return null;
}
f.calcHash();
f.checkTime = new java.util.Date();
txw.commit();
return f;
}