diff --git a/build.xml b/build.xml
index dfd2ef293..a129430d3 100644
--- a/build.xml
+++ b/build.xml
@@ -161,6 +161,8 @@
source="1.5" target="1.5">
+
+
diff --git a/src/java/com/threerings/presents/peer/server/persist/NodeRecord.java b/src/java/com/threerings/presents/peer/server/persist/NodeRecord.java
index 88ed8a9bd..74635ad13 100644
--- a/src/java/com/threerings/presents/peer/server/persist/NodeRecord.java
+++ b/src/java/com/threerings/presents/peer/server/persist/NodeRecord.java
@@ -23,26 +23,76 @@ package com.threerings.presents.peer.server.persist;
import java.sql.Timestamp;
+import com.samskivert.jdbc.depot.Key;
+import com.samskivert.jdbc.depot.PersistentRecord;
+import com.samskivert.jdbc.depot.annotation.Column;
+import com.samskivert.jdbc.depot.annotation.Entity;
+import com.samskivert.jdbc.depot.annotation.Id;
+import com.samskivert.jdbc.depot.expression.ColumnExp;
import com.samskivert.util.StringUtil;
/**
* Contains information on an active node in a Presents server cluster.
*/
-public class NodeRecord
+@Entity
+public class NodeRecord extends PersistentRecord
{
+ // AUTO-GENERATED: FIELDS START
+ /** The column identifier for the {@link #nodeName} field. */
+ public static final String NODE_NAME = "nodeName";
+
+ /** The qualified column identifier for the {@link #nodeName} field. */
+ public static final ColumnExp NODE_NAME_C =
+ new ColumnExp(NodeRecord.class, NODE_NAME);
+
+ /** The column identifier for the {@link #hostName} field. */
+ public static final String HOST_NAME = "hostName";
+
+ /** The qualified column identifier for the {@link #hostName} field. */
+ public static final ColumnExp HOST_NAME_C =
+ new ColumnExp(NodeRecord.class, HOST_NAME);
+
+ /** The column identifier for the {@link #publicHostName} field. */
+ public static final String PUBLIC_HOST_NAME = "publicHostName";
+
+ /** The qualified column identifier for the {@link #publicHostName} field. */
+ public static final ColumnExp PUBLIC_HOST_NAME_C =
+ new ColumnExp(NodeRecord.class, PUBLIC_HOST_NAME);
+
+ /** The column identifier for the {@link #port} field. */
+ public static final String PORT = "port";
+
+ /** The qualified column identifier for the {@link #port} field. */
+ public static final ColumnExp PORT_C =
+ new ColumnExp(NodeRecord.class, PORT);
+
+ /** The column identifier for the {@link #lastUpdated} field. */
+ public static final String LAST_UPDATED = "lastUpdated";
+
+ /** The qualified column identifier for the {@link #lastUpdated} field. */
+ public static final ColumnExp LAST_UPDATED_C =
+ new ColumnExp(NodeRecord.class, LAST_UPDATED);
+ // AUTO-GENERATED: FIELDS END
+
/** The unique name assigned to this node. */
+ @Id
+ @Column(name="NODE_NAME", length=64)
public String nodeName;
/** The DNS name used to connect to this node by other peers. */
+ @Column(name="HOST_NAME", length=64)
public String hostName;
/** The DNS name used to connect to this node by normal clients. */
+ @Column(name="PUBLIC_HOST_NAME", length=64)
public String publicHostName;
/** The port on which to connect to this node. */
+ @Column(name="PORT")
public int port;
/** The last time this node has reported in. */
+ @Column(name="LAST_UPDATED")
public Timestamp lastUpdated;
/** Used to create a blank instance when loading from the database. */
@@ -72,4 +122,18 @@ public class NodeRecord
{
return StringUtil.fieldsToString(this);
}
+
+ // AUTO-GENERATED: METHODS START
+ /**
+ * Create and return a primary {@link Key} to identify a {@link #NodeRecord}
+ * with the supplied key values.
+ */
+ public static Key getKey (String nodeName)
+ {
+ return new Key(
+ NodeRecord.class,
+ new String[] { NODE_NAME },
+ new Comparable[] { nodeName });
+ }
+ // AUTO-GENERATED: METHODS END
}
diff --git a/src/java/com/threerings/presents/peer/server/persist/NodeRepository.java b/src/java/com/threerings/presents/peer/server/persist/NodeRepository.java
index 1105c706e..d8b25e076 100644
--- a/src/java/com/threerings/presents/peer/server/persist/NodeRepository.java
+++ b/src/java/com/threerings/presents/peer/server/persist/NodeRepository.java
@@ -21,23 +21,18 @@
package com.threerings.presents.peer.server.persist;
-import java.sql.Connection;
-import java.sql.SQLException;
import java.sql.Timestamp;
-import java.util.ArrayList;
+import java.util.List;
import com.samskivert.io.PersistenceException;
-
import com.samskivert.jdbc.ConnectionProvider;
-import com.samskivert.jdbc.DatabaseLiaison;
-import com.samskivert.jdbc.JDBCUtil;
-import com.samskivert.jdbc.JORARepository;
-import com.samskivert.jdbc.jora.Table;
+import com.samskivert.jdbc.depot.DepotRepository;
+import com.samskivert.jdbc.depot.PersistenceContext;
/**
* Used to share information on active nodes in a Presents server cluster.
*/
-public class NodeRepository extends JORARepository
+public class NodeRepository extends DepotRepository
{
/** The database identifier used when establishing a database connection. This value being
* nodedb. */
@@ -51,16 +46,16 @@ public class NodeRepository extends JORARepository
public NodeRepository (ConnectionProvider conprov)
throws PersistenceException
{
- super(conprov, NODE_DB_IDENT);
+ super(new PersistenceContext(NODE_DB_IDENT, conprov));
}
/**
* Returns a list of all nodes registered in the repository.
*/
- public ArrayList loadNodes ()
+ public List loadNodes ()
throws PersistenceException
{
- return loadAll(_ntable, "");
+ return findAll(NodeRecord.class);
}
/**
@@ -70,7 +65,7 @@ public class NodeRepository extends JORARepository
throws PersistenceException
{
record.lastUpdated = new Timestamp(System.currentTimeMillis());
- store(_ntable, record);
+ store(record);
}
/**
@@ -80,10 +75,9 @@ public class NodeRepository extends JORARepository
public void heartbeatNode (String nodeName)
throws PersistenceException
{
- NodeRecord record = new NodeRecord();
- record.nodeName = nodeName;
- record.lastUpdated = new Timestamp(System.currentTimeMillis());
- updateField(_ntable, record, "lastUpdated");
+ updatePartial(NodeRecord.class, nodeName, new Object[] {
+ NodeRecord.LAST_UPDATED, new Timestamp(System.currentTimeMillis())
+ });
}
/**
@@ -92,33 +86,6 @@ public class NodeRepository extends JORARepository
public void deleteNode (String nodeName)
throws PersistenceException
{
- delete(_ntable, new NodeRecord(nodeName));
+ delete(NodeRecord.class, nodeName);
}
-
- @Override // documentation inherited
- protected void migrateSchema (Connection conn, DatabaseLiaison liaison)
- throws SQLException, PersistenceException
- {
- JDBCUtil.createTableIfMissing(conn, "NODES", new String[] {
- "NODE_NAME VARCHAR(64) NOT NULL",
- "HOST_NAME VARCHAR(64) NOT NULL",
- "PUBLIC_HOST_NAME VARCHAR(64) NOT NULL",
- "PORT INTEGER NOT NULL",
- "LAST_UPDATED TIMESTAMP NOT NULL",
- "PRIMARY KEY (NODE_NAME)",
- }, "");
-
- // TEMP: add our new column
- JDBCUtil.addColumn(conn, "NODES", "PUBLIC_HOST_NAME",
- "VARCHAR(64) NOT NULL", "HOST_NAME");
- // END TEMP
- }
-
- @Override // documentation inherited
- protected void createTables ()
- {
- _ntable = new Table(NodeRecord.class, "NODES", "NODE_NAME", true);
- }
-
- protected Table _ntable;
}