[Cherbot-commit] SF.net SVN: cherbot: [69] trunk/src/net/sf/cherbot
Status: Alpha
Brought to you by:
christianhujer
|
From: <chr...@us...> - 2007-06-16 22:23:09
|
Revision: 69
http://svn.sourceforge.net/cherbot/?rev=69&view=rev
Author: christianhujer
Date: 2007-06-16 15:23:07 -0700 (Sat, 16 Jun 2007)
Log Message:
-----------
Started implementation of PlayerModel as first PersistentModule implementation.
Added Paths:
-----------
trunk/src/net/sf/cherbot/Player.java
trunk/src/net/sf/cherbot/PlayerModule.java
Added: trunk/src/net/sf/cherbot/Player.java
===================================================================
--- trunk/src/net/sf/cherbot/Player.java (rev 0)
+++ trunk/src/net/sf/cherbot/Player.java 2007-06-16 22:23:07 UTC (rev 69)
@@ -0,0 +1,55 @@
+/*
+ * Copyright © 2007, Christian Hujer and the CherBot developers. All Rights Reserved.
+ * License: GNU General Public License v2.0 or newer.
+ * See file COPYING in the root directory of this project.
+ */
+
+package net.sf.cherbot;
+
+/** Represents a single player.
+ * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
+ */
+public class Player {
+
+ /** The id of this player. */
+ private final int id;
+
+ /** The serverId of this player. */
+ private final int serverId;
+
+ /** The name of this player. */
+ private final String name;
+
+ /** Create a Player.
+ * @param id Id of this player.
+ * @param serverId ServerId of this player.
+ * @param name Name of this player.
+ */
+ public Player(final int id, final int serverId, final String name) {
+ this.id = id;
+ this.serverId = serverId;
+ this.name = name;
+ }
+
+ /** Returns the id of this player.
+ * @return The id of this player.
+ */
+ public int getId() {
+ return id;
+ }
+
+ /** Returns the server id of this player.
+ * @return The server id of this player.
+ */
+ public int getServerId() {
+ return serverId;
+ }
+
+ /** Returns the name of this player.
+ * @return The name of this player.
+ */
+ public String getName() {
+ return name;
+ }
+
+} // class Player
Property changes on: trunk/src/net/sf/cherbot/Player.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ LF
Added: trunk/src/net/sf/cherbot/PlayerModule.java
===================================================================
--- trunk/src/net/sf/cherbot/PlayerModule.java (rev 0)
+++ trunk/src/net/sf/cherbot/PlayerModule.java 2007-06-16 22:23:07 UTC (rev 69)
@@ -0,0 +1,62 @@
+/*
+ * Copyright © 2007, Christian Hujer and the CherBot developers. All Rights Reserved.
+ * License: GNU General Public License v2.0 or newer.
+ * See file COPYING in the root directory of this project.
+ */
+
+package net.sf.cherbot;
+
+import org.jetbrains.annotations.NotNull;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.sql.ResultSet;
+import java.util.List;
+import java.util.ArrayList;
+
+/**
+ * Created by IntelliJ IDEA.
+ * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
+ */
+public class PlayerModule implements PersistentModule {
+
+ private final List<Player> players = new ArrayList<Player>();
+
+ /** {@inheritDoc} */
+ public void load(@NotNull final Connection con) throws SQLException {
+ final PreparedStatement stmt = con.prepareStatement("SELECT id, serverId, name FROM Player");
+ final ResultSet result = stmt.executeQuery();
+ while (result.next()) {
+ final int id = result.getInt(1);
+ final int serverId = result.getInt(2);
+ final String name = result.getString(3);
+ players.add(new Player(id, serverId, name));
+ }
+ }
+
+ /** {@inheritDoc} */
+ public void save(@NotNull final Connection con) throws SQLException {
+ createTables(con);
+ final PreparedStatement lookup = con.prepareStatement("SELECT id FROM Player WHERE id = ?");
+ final PreparedStatement update = con.prepareStatement("UPDATE Player SET id = ?, serverId = ?, name = ? WHERE id = ?");
+ final PreparedStatement insert = con.prepareStatement("INSERT INTO Player (id, serverId, name) VALUES (?, ?, ?)");
+ }
+
+ /** Creates the tables if they don't exist.
+ * @param con Connection to use for creating the tables.
+ * @throws SQLException In case of persistence problems.
+ */
+ private void createTables(@NotNull final Connection con) throws SQLException {
+ try {
+ final PreparedStatement stmt = con.prepareStatement("CREATE TABLE Player (id INT, serverId INT, name VARCHAR(32)");
+ stmt.execute();
+ } catch (final SQLException ignore) {
+ System.err.println(ignore);
+ }
+ }
+
+ /** {@inheritDoc} */
+ public void parseMessage(@NotNull final Channel channel, @NotNull final String msg) {
+ }
+
+} // class PlayerModule
Property changes on: trunk/src/net/sf/cherbot/PlayerModule.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ LF
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|