Exemplo n.º 1
0
    private void emptyQueue() {
      // Empties both the string and the prepared queues by
      // executing all of the functions in the arrays
      try {
        synchronized (stmts) {
          while (stmts.size() > 0) {
            String stmtString = stmts.poll();
            if (stmt != null) {
              stmt.execute(stmtString);
            } else {
              Debug.log("Not running a stmt because it was " + "null", "MySQL");
            }

            Debug.log("Delay ran a SQL stmt.", "MySQL");
          }
        }
        synchronized (pstmts) {
          while (pstmts.size() > 0) {
            PreparedStatement pstmt = pstmts.poll();
            if (pstmt != null) {
              pstmt.executeUpdate();
            } else {
              Debug.log("Not running a pstmt because it was " + "null", "MySQL");
            }

            Debug.log("Delay ran a SQL pstmt.", "MySQL");
          }
        }
      } catch (SQLException e) {
        System.err.println("Delayed execution of SQL failed.");
        System.err.println(e.toString());
      }
    }
Exemplo n.º 2
0
 @Override
 public void run() {
   // Waits on notifier to wake up
   Debug.log("Started MySQL Delayed Runner Thread", "Thread");
   try {
     while (LADJava.running) {
       synchronized (notifier) {
         notifier.wait();
         emptyQueue();
       }
     }
   } catch (InterruptedException e) {
   }
   emptyQueue();
   Debug.log("Ended MySQL Delayed Runner Thread", "Thread");
 }
Exemplo n.º 3
0
  /**
   * Initializes the table.
   *
   * <p>Starts by performing validation on the given table in SQL. If the headers do not match/do
   * not exist, then the table is re/created. Once the table is known to be good, all rows are
   * pulled and sent through the profile for handling. Any errors that occur during this process are
   * fatal and will cause the server to shutdown immediately.
   */
  public void initialize() {
    TableProfile[] profs = profiles();
    final int proflen = profs.length;
    Connection conn = MySQLDB.getConn();

    for (int i = 0; i < proflen; i++) {
      String[] tableHeaders = profs[i].tableHeaders();
      String tableName = profs[i].tableName();
      String createStr = profs[i].createString();
      MySQLDB db = MySQLDB.getInstance();
      try {
        db.validateTable(tableName, createStr);
      } catch (SQLException e) {
        System.err.println("Error with " + tableName + " table:" + e.toString());
        System.exit(-1);
      }
      try {
        db.validateStructure(tableHeaders, tableName);
      } catch (SQLException e) {
        System.err.println("Error with " + tableName + " headers." + e.toString());
        System.exit(-1);
      } catch (GameException g) {
        Debug.log("Recreating table " + tableName, "Thread");
        try {
          db.dropStructure(tableName);
          db.validateTable(tableName, createStr);
        } catch (SQLException e) {
          System.err.println("Can't drop table " + tableName + e.toString());
          System.exit(-1);
        }
      }

      try {
        profs[i].postinit();
        if (profs[i].loadData()) {
          Statement stmt = conn.createStatement();
          ResultSet result = stmt.executeQuery("SELECT * FROM " + tableName);
          while (result.next()) {
            profs[i].loadRow(result);
          }
        }
      } catch (SQLException e) {
        System.err.println("Error while initializing " + tableName + ": " + e.toString());
        System.exit(-1);
      }
    }
  }