summaryrefslogtreecommitdiff
path: root/src/main/java/com/amazon/carbonado/layout/Layout.java
diff options
context:
space:
mode:
authorBrian S. O'Neill <bronee@gmail.com>2010-03-14 20:13:11 +0000
committerBrian S. O'Neill <bronee@gmail.com>2010-03-14 20:13:11 +0000
commit10b8b1179e4b1c90db455e68ff81c89e4cb3f015 (patch)
tree89e9d8e5e809b9488ae55efe854a0058f5f51c0e /src/main/java/com/amazon/carbonado/layout/Layout.java
parent8d5c1796c151375ac8978ded048514bdc8922c1e (diff)
Allow storable types to differ between client and server.
Diffstat (limited to 'src/main/java/com/amazon/carbonado/layout/Layout.java')
-rw-r--r--src/main/java/com/amazon/carbonado/layout/Layout.java39
1 files changed, 35 insertions, 4 deletions
diff --git a/src/main/java/com/amazon/carbonado/layout/Layout.java b/src/main/java/com/amazon/carbonado/layout/Layout.java
index 7aea758..570db8c 100644
--- a/src/main/java/com/amazon/carbonado/layout/Layout.java
+++ b/src/main/java/com/amazon/carbonado/layout/Layout.java
@@ -19,8 +19,11 @@
package com.amazon.carbonado.layout;
import java.io.IOException;
+import java.io.OutputStream;
+
import java.net.InetAddress;
import java.net.UnknownHostException;
+
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -135,7 +138,7 @@ public class Layout {
private final StoredLayout mStoredLayout;
private final LayoutOptions mOptions;
- private transient List<LayoutProperty> mAllProperties;
+ private volatile List<LayoutProperty> mAllProperties;
/**
* Creates a Layout around an existing storable.
@@ -248,7 +251,9 @@ public class Layout {
* Returns all the properties of this layout, in their proper order.
*/
public List<LayoutProperty> getAllProperties() throws FetchException {
- if (mAllProperties == null) {
+ List<LayoutProperty> all = mAllProperties;
+
+ if (all == null) {
Cursor <StoredLayoutProperty> cursor = mLayoutFactory.mPropertyStorage
.query("layoutID = ?")
.with(mStoredLayout.getLayoutID())
@@ -262,13 +267,13 @@ public class Layout {
list.add(new LayoutProperty(cursor.next()));
}
- mAllProperties = Collections.unmodifiableList(list);
+ mAllProperties = all = Collections.unmodifiableList(list);
} finally {
cursor.close();
}
}
- return mAllProperties;
+ return all;
}
/**
@@ -482,6 +487,32 @@ public class Layout {
&& getAllProperties().equals(layout.getAllProperties());
}
+ /**
+ * Write a layout to be read by {@link LayoutFactory#readLayoutFrom}.
+ *
+ * @since 1.2.2
+ */
+ public void writeTo(OutputStream out) throws IOException, RepositoryException {
+ mStoredLayout.writeTo(out);
+
+ Cursor <StoredLayoutProperty> cursor = mLayoutFactory.mPropertyStorage
+ .query("layoutID = ?")
+ .with(mStoredLayout.getLayoutID())
+ .fetch();
+
+ try {
+ while (cursor.hasNext()) {
+ StoredLayoutProperty prop = cursor.next();
+ out.write(1);
+ prop.writeTo(out);
+ }
+ } finally {
+ cursor.close();
+ }
+
+ out.write(0);
+ }
+
// Assumes caller is in a transaction.
void insert(int generation) throws PersistException {
if (mAllProperties == null) {