Permalink
Browse files

Comment updates.

  • Loading branch information...
1 parent d795d07 commit 4f817cee8f11f9b0dfbd9e181bf9de02aaf187d1 @ccorsi committed Sep 4, 2010
@@ -7,10 +7,10 @@
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
- * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer
+ * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the distribution.
- * Neither the name of Claudio Corsi nor the names of its contributors may be used to endorse or promote products derived from
+ * Neither the name of Claudio Corsi nor the names of its contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
@@ -41,6 +41,7 @@
import com.sleepycat.je.Database;
import com.sleepycat.je.DatabaseConfig;
+import com.sleepycat.je.DatabaseException;
import com.sleepycat.je.Environment;
import com.sleepycat.je.EnvironmentConfig;
import com.sleepycat.je.Transaction;
@@ -61,7 +62,7 @@
private Set<BookBerkeleyDB> books = new HashSet<BookBerkeleyDB>();
private Set<PersonBerkeleyDB> persons = new HashSet<PersonBerkeleyDB>();
private Set<GenderBerkeleyDB> genders = new HashSet<GenderBerkeleyDB>();
-
+
/*
* (non-Javadoc)
*
@@ -82,9 +83,19 @@ public void beginTx() {
*/
@Override
public void close() {
- db.close();
- store.close();
- env.close();
+ try {
+ if (db != null) {
+ db.close();
+ }
+ if (store != null) {
+ store.close();
+ }
+ if (env != null) {
+ env.close();
+ }
+ } catch (DatabaseException dbe) {
+ dbe.printStackTrace();
+ }
}
/*
@@ -98,8 +109,9 @@ public void commitTx() {
txn.commit();
// Reset the transaction upon commit it.
txn = null;
- // TODO: I need to manage a failure and not only assume that the transaction
- // will commit properly...
+ // TODO: I need to manage a failure and not only assume that the
+ // transaction
+ // will commit properly...
}
/*
@@ -201,10 +213,10 @@ public void init(Properties properties) {
storeConfig.setAllowCreate(true);
storeConfig.setTransactional(true);
store = new EntityStore(env, "BooksStore", storeConfig);
-
+
accessor = new BookAccessor(store);
-
- // Open the database. Create it if it does not exist
+
+ // Open the database. Create it if it does not exist
DatabaseConfig dbConfig = new DatabaseConfig();
dbConfig.setTransactional(true);
dbConfig.setAllowCreate(true);
@@ -220,17 +232,17 @@ public void init(Properties properties) {
*/
@Override
public void save(Book book) {
-
+
// Add the book instance to the book index...
accessor.booksIdx.put(BookBerkeleyDB.class.cast(book));
-
+
// Add the person instances to the database...
- for(Person person : book.getPersons(PersonType.Author)) {
+ for (Person person : book.getPersons(PersonType.Author)) {
ObjectsContainerManager objects = accessor.allIdx.get(1L);
- if(objects == null) {
+ if (objects == null) {
objects = new ObjectsContainerManager(1L);
}
-
+
objects.addPerson(PersonBerkeleyDB.class.cast(person));
}
}

0 comments on commit 4f817ce

Please sign in to comment.