Package marauroa.server.db

Examples of marauroa.server.db.TransactionPool


   * @throws DatabaseConnectionException in case the database configuration is broken
   */
  public void initializeDatabase() throws DatabaseConnectionException {
    try {
      if (TransactionPool.get() == null) {
        TransactionPool pool = new TransactionPool(Configuration.getConfiguration().getAsProperties());
        pool.registerGlobally();
        initializeDatabaseSchema();
        DAORegister.get();
        configureGameDatabaseAccess();
      }
    } catch (Exception e) {
View Full Code Here


      props.put("jdbc_url", "jdbc:mysql://127.0.0.1/marauroatest");
      props.put("jdbc_class", "com.mysql.jdbc.Driver");
      props.put("jdbc_user", "junittest");
      props.put("jdbc_pwd", "passwd");

      TransactionPool pool = new TransactionPool(props);
      pool.rollback(pool.beginWork());
      pool.close();
    } catch (Exception e) {
      throw new Exception("Database is not accessible. Please check \"marauroatest\" is created and that user \"junittest\" with password \"passwd\" can access it.", e);
    }
  }
View Full Code Here

    props.put("jdbc_url", "jdbc:mysql://127.0.0.1/marauroatest");
    props.put("jdbc_class", "com.mysql.jdbc.Driver");
    props.put("jdbc_user", "junittest");
    props.put("jdbc_pwd", "passwd");

    transactionPool = new TransactionPool(props);
    accountDAO = DAORegister.get().get(AccountDAO.class);
    loginEventDAO = DAORegister.get().get(LoginEventDAO.class);
  }
View Full Code Here

    props.put("jdbc_url", "jdbc:mysql://127.0.0.1/marauroatest");
    props.put("jdbc_class", "com.mysql.jdbc.Driver");
    props.put("jdbc_user", "junittest");
    props.put("jdbc_pwd", "passwd");

    transactionPool = new TransactionPool(props);
    rpzoneDAO = DAORegister.get().get(RPZoneDAO.class)
  }
View Full Code Here

    props.put("jdbc_url", "jdbc:mysql://127.0.0.1/marauroatest");
    props.put("jdbc_class", "com.mysql.jdbc.Driver");
    props.put("jdbc_user", "junittest");
    props.put("jdbc_pwd", "passwd");

    transactionPool = new TransactionPool(props);
   
    accountDAO = DAORegister.get().get(AccountDAO.class);
    characterDAO = DAORegister.get().get(CharacterDAO.class);
  }
View Full Code Here

public class CopyTable {

  public static void main(String[] args) throws SQLException, InterruptedException {
    new DatabaseFactory().initializeDatabase();
    TransactionPool transactionPool = TransactionPool.get();
   
    for (int i = 1122; i < 346000; i++) {
      System.out.println("> " + i);
      String cmd = "INSERT INTO itemlog_new (id, timedate, itemid, source, event, param1, param2, param3, param4)"
        + " SELECT id, timedate, itemid, source, event, param1, param2, param3, param4 FROM itemlog WHERE id >= " + (i * 100) + " AND id < "  + ((i+1) * 100);
      DBTransaction transaction = transactionPool.beginWork();
      transaction.execute(cmd, null);
      transactionPool.commit(transaction);
      System.out.println("< " + i);
      Thread.sleep(3000);
    }
  }
View Full Code Here

public class ReadTable {
  private static Logger logger = Logger.getLogger(ReadTable.class);

  public static void main(String[] args) throws SQLException, InterruptedException, IOException {
    new DatabaseFactory().initializeDatabase();
    TransactionPool transactionPool = TransactionPool.get();

    BufferedReader br = new BufferedReader(new FileReader(args[0]));
    String line = br.readLine();
    int i = 0;
    StringBuilder cmd = new StringBuilder();
    while (line != null) {
      System.out.println("> " + i);
      if (line.startsWith("--")) {
        line = br.readLine();
        i++;
        continue;
      }
      cmd.append(" " + line);
     
      if (cmd.indexOf(";") > -1) {
        DBTransaction transaction = transactionPool.beginWork();
        try {
          if (cmd.indexOf("DROP TABLE") != 0 && cmd.indexOf("CREATE TABLE") != 0) {
            transaction.execute(line, null);
          }
        } catch (SQLException e) {
          logger.error(cmd, e);
        }
        transactionPool.commit(transaction);
        cmd = new StringBuilder();
        Thread.sleep(3000);
      }

      System.out.println("< " + i);
View Full Code Here

    final Result result = validators.runValidators();
    if (result != null) {
      return new CharacterResult(result, character, template);
    }

    final TransactionPool transactionPool = SingletonRepository.getTransactionPool();
    final DBTransaction trans = transactionPool.beginWork();
    final CharacterDAO characterDAO = DAORegister.get().get(CharacterDAO.class);

    try {
      if (characterDAO.hasCharacter(trans, character)) {
        logger.warn("Character already exist: " + character);
        transactionPool.commit(trans);
        return new CharacterResult(Result.FAILED_PLAYER_EXISTS,
            character, template);
      }

      final Player object = Player.createZeroLevelPlayer(character, template);
           // monitor new account names
          final String text = "Support: A new character has just been created called " + character + ".";
  
        SingletonRepository.getRuleProcessor().sendMessageToSupporters(text);
     
      /*
       * Finally we add it to database.
       */
        characterDAO.addCharacter(trans, username, character, object);
      transactionPool.commit(trans);

      return new CharacterResult(Result.OK_CREATED, character, object);
    } catch (final Exception e) {
      transactionPool.rollback(trans);
      logger.error("Can't create character", e);
      return new CharacterResult(Result.FAILED_EXCEPTION, character, template);
    }
  }
View Full Code Here

   * tries to create the player in the database.
   *
   * @return Result.OK_CREATED on success
   */
  private AccountResult insertIntoDatabase() {
    final TransactionPool transactionPool = SingletonRepository.getTransactionPool();
    final DBTransaction transaction = transactionPool.beginWork();
    final AccountDAO accountDAO = DAORegister.get().get(AccountDAO.class);

    try {
      if (accountDAO.hasPlayer(transaction, username)) {
        logger.warn("Account already exist: " + username);
        transactionPool.commit(transaction);
        return new AccountResult(Result.FAILED_PLAYER_EXISTS, username);
      }

      accountDAO.addPlayer(transaction, username, Hash.hash(password), email);

      transactionPool.commit(transaction);
      return new AccountResult(Result.OK_CREATED, username);
    } catch (final SQLException e) {
      logger.warn("SQL exception while trying to create a new account", e);
      transactionPool.rollback(transaction);
      return new AccountResult(Result.FAILED_EXCEPTION, username);
    }
  }
View Full Code Here

TOP

Related Classes of marauroa.server.db.TransactionPool

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.