Example #1
0
 public static void updatePass(String password, String username) {
   String s = "update neighbors set password= :password where username = :username";
   SqlUpdate update = Ebean.createSqlUpdate(s);
   update.setParameter("password", password);
   update.setParameter("username", username);
   update.execute();
 }
  public void convertNewDatabaseSystem() {
    if (existTable("playerstats")) {
      databaseServer.beginTransaction();
      try {
        final SqlUpdate convert =
            databaseServer.createSqlUpdate(
                "INSERT INTO player_stats "
                    + "(playername, kills, deaths, mobkills, killstreak, last_online) "
                    + "SELECT playername, kills, deaths, mobkills, killstreak, ? "
                    + "FROM playerstats");

        // sql parameters begins with one
        convert.setParameter(1, System.currentTimeMillis());
        final int affectedRows = convert.execute();
        final SqlUpdate dropTable = databaseServer.createSqlUpdate("DROP TABLE playerstats");
        dropTable.execute();
        // a drop have to commited and should be rollbackable if process wasn't complete
        databaseServer.commitTransaction();

        Logger.getLogger("ScoreboardStats")
            .log(Level.INFO, "Successfully converted {0} into new table structure", affectedRows);
      } finally {
        databaseServer.endTransaction();
      }
    }
  }
  @Transactional
  public void doSomething(EBasicVer v) {

    EbeanServer server = Ebean.getServer(null);

    inMethodTransaction = server.currentTransaction();

    Transaction t = server.createTransaction();
    SqlUpdate u =
        server.createSqlUpdate("update e_basicver set last_update = last_update+1 where id = ?");
    u.setParameter(1, v.getId());
    int count = server.execute(u, t);
    Assert.assertEquals(1, count);

    t.commit();

    v.setName("some change");
    try {
      Ebean.save(v);
      // never get here
      Assert.assertTrue(false);
    } catch (PersistenceException e) {
      throw e;
    }
  }
Example #4
0
 /**
  * Pour utiliser les noms de commune dicté par AER : c'est-à-dire en minuscule avec des articles.
  */
 private void metAJourNomAERCommunes() {
   for (Commune c : Commune.find.all()) {
     if (c.ville_nom.startsWith("LA ")) c.ville_nom_aer = "La " + c.ville_nom_reel;
     else if (c.ville_nom.startsWith("LE ")) c.ville_nom_aer = "Le " + c.ville_nom_reel;
     else if (c.ville_nom.startsWith("LES ")) c.ville_nom_aer = "Les " + c.ville_nom_reel;
     else if (c.ville_nom.startsWith("L'")) c.ville_nom_aer = "L'" + c.ville_nom_reel;
     else c.ville_nom_aer = c.ville_nom_reel;
     SqlUpdate update =
         Ebean.createSqlUpdate("UPDATE commune SET ville_nom_aer=:aer WHERE ville_id=:id")
             .setParameter("aer", c.ville_nom_aer)
             .setParameter("id", c.ville_id);
     update.execute();
   }
 }