我有下一个代码:
PhotoFactory factory = PhotoFactory.getFactory (PhotoResource.PICASA);
PhotoSession session = factory.openSession (login, password);
PhotoAlbum album = factory.createAlbum ();
Photo photo = factory.createPhoto ();
album.addPhoto (photo);
if (session.canUpload ()) {
session.uploadAlbum (album);
}
session.close ();
我不确定我选择了正确的名字。这不是那么重要,但我只是好奇你在我的情况下选择了什么。另一个版本是经理:
PhotoManager manager = PhotoManager.getManager (PhotoResource.PICASA);
PhotoSession session = manager.openSession (login, password);
PhotoAlbum album = manager.createAlbum ();
Photo photo = manager.createPhoto ();
album.addPhoto (photo);
if (session.canUpload ()) {
session.uploadAlbum (album);
}
session.close ();
UPD:我刚刚在 hibernate javadocs 中找到了下一个示例:
Session sess = factory.openSession();
Transaction tx;
try {
tx = sess.beginTransaction();
//do some work
...
tx.commit();
}
这是命名错误吗?