OK, so even this little change is going to have to wait for a few days until after the massive Depot restructure. The current version gets fields and columns a little confused from time to time.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4774 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Par Winzell
2007-07-18 18:54:47 +00:00
parent 038e5c5b85
commit 20719ee3f1
3 changed files with 46 additions and 79 deletions
-2
View File
@@ -161,8 +161,6 @@
source="1.5" target="1.5"> source="1.5" target="1.5">
<classpath refid="classpath"/> <classpath refid="classpath"/>
<exclude name="com/threerings/parlor/rating/server/**" unless="depot.present"/> <exclude name="com/threerings/parlor/rating/server/**" unless="depot.present"/>
<exclude name="com/threerings/presents/peer/**" unless="depot.present"/>
<exclude name="com/threerings/crowd/peer/**" unless="depot.present"/>
<compilerarg value="-Xlint"/> <compilerarg value="-Xlint"/>
<compilerarg value="-Xlint:-serial"/> <compilerarg value="-Xlint:-serial"/>
</javac> </javac>
@@ -23,76 +23,26 @@ package com.threerings.presents.peer.server.persist;
import java.sql.Timestamp; 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; import com.samskivert.util.StringUtil;
/** /**
* Contains information on an active node in a Presents server cluster. * Contains information on an active node in a Presents server cluster.
*/ */
@Entity public class NodeRecord
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. */ /** The unique name assigned to this node. */
@Id
@Column(name="NODE_NAME", length=64)
public String nodeName; public String nodeName;
/** The DNS name used to connect to this node by other peers. */ /** The DNS name used to connect to this node by other peers. */
@Column(name="HOST_NAME", length=64)
public String hostName; public String hostName;
/** The DNS name used to connect to this node by normal clients. */ /** The DNS name used to connect to this node by normal clients. */
@Column(name="PUBLIC_HOST_NAME", length=64)
public String publicHostName; public String publicHostName;
/** The port on which to connect to this node. */ /** The port on which to connect to this node. */
@Column(name="PORT")
public int port; public int port;
/** The last time this node has reported in. */ /** The last time this node has reported in. */
@Column(name="LAST_UPDATED")
public Timestamp lastUpdated; public Timestamp lastUpdated;
/** Used to create a blank instance when loading from the database. */ /** Used to create a blank instance when loading from the database. */
@@ -122,18 +72,4 @@ public class NodeRecord extends PersistentRecord
{ {
return StringUtil.fieldsToString(this); 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<NodeRecord> getKey (String nodeName)
{
return new Key<NodeRecord>(
NodeRecord.class,
new String[] { NODE_NAME },
new Comparable[] { nodeName });
}
// AUTO-GENERATED: METHODS END
} }
@@ -21,18 +21,23 @@
package com.threerings.presents.peer.server.persist; package com.threerings.presents.peer.server.persist;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.util.List; import java.util.ArrayList;
import com.samskivert.io.PersistenceException; import com.samskivert.io.PersistenceException;
import com.samskivert.jdbc.ConnectionProvider; import com.samskivert.jdbc.ConnectionProvider;
import com.samskivert.jdbc.depot.DepotRepository; import com.samskivert.jdbc.DatabaseLiaison;
import com.samskivert.jdbc.depot.PersistenceContext; import com.samskivert.jdbc.JDBCUtil;
import com.samskivert.jdbc.JORARepository;
import com.samskivert.jdbc.jora.Table;
/** /**
* Used to share information on active nodes in a Presents server cluster. * Used to share information on active nodes in a Presents server cluster.
*/ */
public class NodeRepository extends DepotRepository public class NodeRepository extends JORARepository
{ {
/** The database identifier used when establishing a database connection. This value being /** The database identifier used when establishing a database connection. This value being
* <code>nodedb</code>. */ * <code>nodedb</code>. */
@@ -46,16 +51,16 @@ public class NodeRepository extends DepotRepository
public NodeRepository (ConnectionProvider conprov) public NodeRepository (ConnectionProvider conprov)
throws PersistenceException throws PersistenceException
{ {
super(new PersistenceContext(NODE_DB_IDENT, conprov)); super(conprov, NODE_DB_IDENT);
} }
/** /**
* Returns a list of all nodes registered in the repository. * Returns a list of all nodes registered in the repository.
*/ */
public List<NodeRecord> loadNodes () public ArrayList<NodeRecord> loadNodes ()
throws PersistenceException throws PersistenceException
{ {
return findAll(NodeRecord.class); return loadAll(_ntable, "");
} }
/** /**
@@ -65,7 +70,7 @@ public class NodeRepository extends DepotRepository
throws PersistenceException throws PersistenceException
{ {
record.lastUpdated = new Timestamp(System.currentTimeMillis()); record.lastUpdated = new Timestamp(System.currentTimeMillis());
store(record); store(_ntable, record);
} }
/** /**
@@ -75,9 +80,10 @@ public class NodeRepository extends DepotRepository
public void heartbeatNode (String nodeName) public void heartbeatNode (String nodeName)
throws PersistenceException throws PersistenceException
{ {
updatePartial(NodeRecord.class, nodeName, new Object[] { NodeRecord record = new NodeRecord();
NodeRecord.LAST_UPDATED, new Timestamp(System.currentTimeMillis()) record.nodeName = nodeName;
}); record.lastUpdated = new Timestamp(System.currentTimeMillis());
updateField(_ntable, record, "lastUpdated");
} }
/** /**
@@ -86,6 +92,33 @@ public class NodeRepository extends DepotRepository
public void deleteNode (String nodeName) public void deleteNode (String nodeName)
throws PersistenceException throws PersistenceException
{ {
delete(NodeRecord.class, nodeName); delete(_ntable, new NodeRecord(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>(NodeRecord.class, "NODES", "NODE_NAME", true);
}
protected Table<NodeRecord> _ntable;
} }