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:
@@ -161,8 +161,6 @@
|
||||
source="1.5" target="1.5">
|
||||
<classpath refid="classpath"/>
|
||||
<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:-serial"/>
|
||||
</javac>
|
||||
|
||||
@@ -23,76 +23,26 @@ 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.
|
||||
*/
|
||||
@Entity
|
||||
public class NodeRecord extends PersistentRecord
|
||||
public class NodeRecord
|
||||
{
|
||||
// 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. */
|
||||
@@ -122,18 +72,4 @@ public class NodeRecord extends PersistentRecord
|
||||
{
|
||||
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;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.samskivert.io.PersistenceException;
|
||||
|
||||
import com.samskivert.jdbc.ConnectionProvider;
|
||||
import com.samskivert.jdbc.depot.DepotRepository;
|
||||
import com.samskivert.jdbc.depot.PersistenceContext;
|
||||
import com.samskivert.jdbc.DatabaseLiaison;
|
||||
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.
|
||||
*/
|
||||
public class NodeRepository extends DepotRepository
|
||||
public class NodeRepository extends JORARepository
|
||||
{
|
||||
/** The database identifier used when establishing a database connection. This value being
|
||||
* <code>nodedb</code>. */
|
||||
@@ -46,16 +51,16 @@ public class NodeRepository extends DepotRepository
|
||||
public NodeRepository (ConnectionProvider conprov)
|
||||
throws PersistenceException
|
||||
{
|
||||
super(new PersistenceContext(NODE_DB_IDENT, conprov));
|
||||
super(conprov, NODE_DB_IDENT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of all nodes registered in the repository.
|
||||
*/
|
||||
public List<NodeRecord> loadNodes ()
|
||||
public ArrayList<NodeRecord> loadNodes ()
|
||||
throws PersistenceException
|
||||
{
|
||||
return findAll(NodeRecord.class);
|
||||
return loadAll(_ntable, "");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -65,7 +70,7 @@ public class NodeRepository extends DepotRepository
|
||||
throws PersistenceException
|
||||
{
|
||||
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)
|
||||
throws PersistenceException
|
||||
{
|
||||
updatePartial(NodeRecord.class, nodeName, new Object[] {
|
||||
NodeRecord.LAST_UPDATED, new Timestamp(System.currentTimeMillis())
|
||||
});
|
||||
NodeRecord record = new NodeRecord();
|
||||
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)
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user