diff --git a/src/java/com/threerings/admin/server/persist/ConfigRecord.java b/src/java/com/threerings/admin/server/persist/ConfigRecord.java new file mode 100644 index 000000000..63d227539 --- /dev/null +++ b/src/java/com/threerings/admin/server/persist/ConfigRecord.java @@ -0,0 +1,113 @@ +// +// $Id: PuzzleManagerDelegate.java 209 2007-02-24 00:37:33Z mdb $ +// +// Vilya library - tools for developing networked games +// Copyright (C) 2002-2007 Three Rings Design, Inc., All Rights Reserved +// http://www.threerings.net/code/vilya/ +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published +// by the Free Software Foundation; either version 2.1 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +package com.threerings.admin.server.persist; + +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; + +@Entity(name="CONFIG") +public class ConfigRecord extends PersistentRecord +{ + // AUTO-GENERATED: FIELDS START + /** The column identifier for the {@link #node} field. */ + public static final String NODE = "node"; + + /** The qualified column identifier for the {@link #node} field. */ + public static final ColumnExp NODE_C = + new ColumnExp(ConfigRecord.class, NODE); + + /** The column identifier for the {@link #object} field. */ + public static final String OBJECT = "object"; + + /** The qualified column identifier for the {@link #object} field. */ + public static final ColumnExp OBJECT_C = + new ColumnExp(ConfigRecord.class, OBJECT); + + /** The column identifier for the {@link #field} field. */ + public static final String FIELD = "field"; + + /** The qualified column identifier for the {@link #field} field. */ + public static final ColumnExp FIELD_C = + new ColumnExp(ConfigRecord.class, FIELD); + + /** The column identifier for the {@link #value} field. */ + public static final String VALUE = "value"; + + /** The qualified column identifier for the {@link #value} field. */ + public static final ColumnExp VALUE_C = + new ColumnExp(ConfigRecord.class, VALUE); + // AUTO-GENERATED: FIELDS END + + public static final int SCHEMA_VERSION = 2; + + @Id + @Column(name="NODE", length=64) + public String node; + + /** The code of the stat. */ + @Id + @Column(name="OBJECT", length=128) + public String object; + + @Id + @Column(name="FIELD", length=64) + public String field; + + @Column(name="VALUE", type="TEXT") + public String value; + + + /** + * An empty constructor for unmarshalling. + */ + public ConfigRecord () + { + super(); + } + + public ConfigRecord (String node, String object, String field, String value) + { + super(); + this.node = node; + this.object = object; + this.field = field; + this.value = value; + } + + // AUTO-GENERATED: METHODS START + /** + * Create and return a primary {@link Key} to identify a {@link #ConfigRecord} + * with the supplied key values. + */ + public static Key getKey (String node, String object, String field) + { + return new Key( + ConfigRecord.class, + new String[] { NODE, OBJECT, FIELD }, + new Comparable[] { node, object, field }); + } + // AUTO-GENERATED: METHODS END +} diff --git a/src/java/com/threerings/admin/server/persist/ConfigRepository.java b/src/java/com/threerings/admin/server/persist/ConfigRepository.java index 3e3db6f8a..47950001a 100644 --- a/src/java/com/threerings/admin/server/persist/ConfigRepository.java +++ b/src/java/com/threerings/admin/server/persist/ConfigRepository.java @@ -21,25 +21,20 @@ package com.threerings.admin.server.persist; -import java.sql.Connection; -import java.sql.SQLException; -import java.sql.Statement; -import java.util.ArrayList; import java.util.HashMap; +import java.util.Set; 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.threerings.admin.Log; +import com.samskivert.jdbc.depot.DepotRepository; +import com.samskivert.jdbc.depot.PersistenceContext; +import com.samskivert.jdbc.depot.PersistentRecord; +import com.samskivert.jdbc.depot.clause.Where; /** * Stores configuration information in a database table. */ -public class ConfigRepository extends JORARepository +public class ConfigRepository extends DepotRepository { /** The identifier used when establishing a database connection. */ public static final String CONFIG_DB_IDENT = "configdb"; @@ -51,7 +46,7 @@ public class ConfigRepository extends JORARepository public ConfigRepository (ConnectionProvider conprov) throws PersistenceException { - super(conprov, CONFIG_DB_IDENT); + super(new PersistenceContext(CONFIG_DB_IDENT, conprov)); } /** @@ -63,13 +58,10 @@ public class ConfigRepository extends JORARepository public HashMap loadConfig (String node, String object) throws PersistenceException { - ArrayList list = loadAll( - _ctable, "where OBJECT = " + JDBCUtil.escape(object) + - " and NODE = " + JDBCUtil.escape(node)); HashMap data = new HashMap(); - for (int ii = 0, ll = list.size(); ii < ll; ii++) { - ConfigDatum datum = list.get(ii); - data.put(datum.field, datum.value); + Where where = new Where(ConfigRecord.OBJECT_C, object, ConfigRecord.NODE_C, node); + for (ConfigRecord record : findAll(ConfigRecord.class, where)) { + data.put(record.field, record.value.toString()); } return data; } @@ -80,47 +72,12 @@ public class ConfigRepository extends JORARepository public void updateConfig (String node, String object, String field, String value) throws PersistenceException { - ConfigDatum datum = new ConfigDatum(); - datum.node = node; - datum.object = object; - datum.field = field; - datum.value = value; - store(_ctable, datum); + store(new ConfigRecord(node, object, field, value)); } - // documentation inherited - protected void migrateSchema (Connection conn, DatabaseLiaison liaison) - throws SQLException, PersistenceException + @Override // from DepotRepository + protected void getManagedRecords (Set> classes) { - JDBCUtil.createTableIfMissing(conn, "CONFIG", new String[] { - "NODE VARCHAR(64) NOT NULL", - "OBJECT VARCHAR(128) NOT NULL", - "FIELD VARCHAR(64) NOT NULL", - "VALUE TEXT NOT NULL", - "PRIMARY KEY (NODE, OBJECT, FIELD)", - }, ""); - - // TEMP: add NODE column - if (!JDBCUtil.tableContainsColumn(conn, "CONFIG", "NODE")) { - JDBCUtil.addColumn(conn, "CONFIG", "NODE", "VARCHAR(64) NOT NULL FIRST", null); - Statement stmt = conn.createStatement(); - try { - stmt.executeUpdate( - "alter table CONFIG drop PRIMARY KEY, add PRIMARY KEY (NODE, OBJECT, FIELD)"); - } finally { - stmt.close(); - } - } - // END TEMP + classes.add(ConfigRecord.class); } - - // documentation inherited - protected void createTables () - { - _ctable = new Table( - ConfigDatum.class, "CONFIG", - new String[] { "NODE", "OBJECT", "FIELD" }, true); - } - - protected Table _ctable; }