Changeset b269fa1e13fc42660af2dcf293e2e415732e5cb2

Show
Ignore:
Timestamp:
08/04/07 23:15:04 (1 year ago)
Author:
Christopher Jung <bktheg@web.de>
git-committer:
Christopher Jung <bktheg@web.de> 1186262104 +0200
git-parent:

[7202f86833c8df23e12a7a2745f66fa86fb9a4c8]

git-author:
Christopher Jung <bktheg@web.de> 1186262104 +0200
Message:

Schlachten: Weitere Umstellungen auf Hibernate

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • src/net/driftingsouls/ds2/server/battles/Battle.java

    r2321615 rb269fa1  
    3838import net.driftingsouls.ds2.server.config.Systems; 
    3939import net.driftingsouls.ds2.server.config.Weapons; 
     40import net.driftingsouls.ds2.server.entities.Ally; 
    4041import net.driftingsouls.ds2.server.entities.User; 
    4142import net.driftingsouls.ds2.server.framework.BasicUser; 
     
    12701271         
    12711272                if( battledata.isEmpty() ) { 
    1272                         database.update("UPDATE ships SET battle=0 WHERE id>0 AND battle=",battleID); 
     1273                        db.createQuery("update Ship set battle=0 where id>0 and battle=?") 
     1274                                .setInteger(0, battleID) 
     1275                                .executeUpdate(); 
     1276                         
    12731277                        context.addError("Die Schlacht ist bereits zuende!"); 
    12741278                        return false; 
     
    13321336         
    13331337                                // Hat der Spieler ein Schiff in der Schlacht 
    1334                                 SQLResultRow aship = database.first("SELECT id,side ", 
    1335                                                                          "FROM ships t1 JOIN battles_ships t2 ON t1.id=t2.shipid ", 
    1336                                                                          "WHERE t1.id>0 AND t1.owner=",id," AND t2.battleid=",this.id); 
    1337                                 if( !aship.isEmpty() ) { 
    1338                                         forceSide = aship.getInt("side"); 
     1338                                BattleShip aship = (BattleShip)db.createQuery("from BattleShip where id>0 and ship.owner=? and battleid=?") 
     1339                                        .setEntity(0, auser) 
     1340                                        .setInteger(1, this.id) 
     1341                                        .setMaxResults(1) 
     1342                                        .uniqueResult(); 
     1343                                 
     1344                                if( aship != null ) { 
     1345                                        forceSide = aship.getSide(); 
    13391346                                } 
    13401347                                else { 
     
    13471354                                        } 
    13481355                                        else { 
    1349                                                 SQLResultRow shipcount = database.first("SELECT count(*) count FROM ships t1 JOIN ship_types t2 ON t1.type=t2.id ", 
    1350                                                                                                  "WHERE t1.id>0 AND t1.owner=",id," AND t1.x=",this.x," AND t1.y=",this.y," AND ", 
    1351                                                                                                  "t1.system=",this.system," AND t1.battle=0 AND t2.class IN (11,13)"); 
    1352                                                 if( shipcount.getInt("count") > 0 ) { 
     1356                                                long shipcount = ((Number)db.createQuery("select count(*) from Ship " + 
     1357                                                                "where owner= :user and x= :x and y= :y and system= :sys and " + 
     1358                                                                        "battle=0 and shiptype.class in (11,13)") 
     1359                                                                .setEntity("user", auser) 
     1360                                                                .setInteger("x", this.x) 
     1361                                                                .setInteger("y", this.y) 
     1362                                                                .setInteger("sys", this.system) 
     1363                                                                .iterate().next()).longValue(); 
     1364                                                if( shipcount > 0 ) { 
    13531365                                                        this.guest = true; 
    13541366                                                } 
     
    18221834                 
    18231835                Context context = ContextMap.getContext(); 
    1824                 Database db = context.getDatabase(); 
    1825                  
    1826                 SQLResultRow row = db.first("SELECT id FROM battles WHERE id="+this.id); 
     1836                Database database = context.getDatabase(); 
     1837                org.hibernate.Session db = context.getDB(); 
     1838                 
     1839                SQLResultRow row = database.first("SELECT id FROM battles WHERE id="+this.id); 
    18271840                if( row.isEmpty() ) { 
    18281841                        LOG.warn("Mehrfacher Aufruf von Battle.endBattle festgestellt", new Throwable()); 
     
    18311844                 
    18321845                if( executeScripts ) { 
    1833                         String onendhandler = db.first("SELECT onend FROM battles WHERE id=",this.id).getString("onend"); 
     1846                        String onendhandler = database.first("SELECT onend FROM battles WHERE id=",this.id).getString("onend"); 
    18341847                        if( onendhandler.length() > 0 ) {                        
    18351848                                ScriptParser scriptparser = context.get(ContextCommon.class).getScriptParser(ScriptParser.NameSpace.QUEST); 
     
    18481861                } 
    18491862 
    1850                 db.update("DELETE FROM battles_ships WHERE battleid=",this.id); 
    1851                 db.update("UPDATE ships SET battle=0,battleAction=0 WHERE id>0 AND battle=",this.id); 
    1852                 db.update("DELETE FROM battles WHERE id=",this.id); 
     1863                db.createQuery("delete from BattleShip where battleid=?") 
     1864                        .setInteger(0, this.id) 
     1865                        .executeUpdate(); 
     1866                db.createQuery("update Ship set battle=0,battleAction=0 where id>0 and battle=?") 
     1867                        .setInteger(0, this.id) 
     1868                        .executeUpdate(); 
     1869                 
     1870                database.update("DELETE FROM battles WHERE id=",this.id); 
    18531871 
    18541872                Common.writeLog("battles/battle_id"+this.id+".log", "</battle>"); 
     
    18571875                new File(Configuration.getSetting("LOXPATH")+"battles/battle_id"+this.id+".log").renameTo(new File(newlog)); 
    18581876                 
    1859                 db.update("UPDATE ships_lost SET battle=0,battlelog='",newlog,"' WHERE battle=",this.id); 
    1860  
    1861                 if( this.ally[0] != 0 ) { 
    1862                         if( side1points > 0 ) { 
    1863                                 db.update("UPDATE ally SET wonBattles=wonBattles + "+side1points+" WHERE id=",this.ally[0]); 
     1877                db.createQuery("update ShipLost set battle=0,battleLog=? where battle=?") 
     1878                        .setString(0, newlog) 
     1879                        .setInteger(1, this.id) 
     1880                        .executeUpdate(); 
     1881 
     1882                int[] points = new int[] {side1points, side2points}; 
     1883                 
     1884                for( int i=0; i < points.length; i++ ) { 
     1885                        if( this.ally[i] != 0 ) { 
     1886                                Ally ally = (Ally)db.get(Ally.class, this.ally[i]); 
     1887                                if( points[i] > 0 ) { 
     1888                                        ally.setWonBattles((short)(ally.getWonBattles()+points[i])); 
     1889                                }  
     1890                                else { 
     1891                                        ally.setLostBattles((short)(ally.getLostBattles()-points[i])); 
     1892                                } 
     1893                        } 
     1894                        User comm = (User)db.get(User.class, this.commander[i]); 
     1895                        if( points[i] > 0 ) { 
     1896                                comm.setWonBattles((short)(comm.getWonBattles()+points[i])); 
    18641897                        }  
    18651898                        else { 
    1866                                 db.update("UPDATE ally SET lostBattles=lostBattles + ",-side1points," WHERE id=",this.ally[0]); 
    1867                         } 
    1868                 } 
    1869                 if( side1points > 0 ) { 
    1870                         db.update("UPDATE users SET wonBattles=wonBattles + "+side1points+" WHERE id=",this.commander[0]); 
    1871                 }  
    1872                 else { 
    1873                         db.update("UPDATE users SET lostBattles=lostBattles + ",-side1points," WHERE id=",this.commander[0]); 
    1874                 } 
    1875  
    1876                 if( this.ally[1] != 0 ) { 
    1877                         if( side2points > 0 ) { 
    1878                                 db.update("UPDATE ally SET wonBattles=wonBattles + "+side2points+" WHERE id=",this.ally[1]); 
    1879                         }  
    1880                         else { 
    1881                                 db.update("UPDATE ally SET lostBattles=lostBattles + ",-side2points," WHERE id=",this.ally[1]); 
    1882                         } 
    1883                 } 
    1884                 if( side2points > 0 ) { 
    1885                         db.update("UPDATE ally SET wonBattles=wonBattles + "+side2points+" WHERE id=",this.commander[1]); 
    1886                 }  
    1887                 else { 
    1888                         db.update("UPDATE ally SET lostBattles=lostBattles + ",-side2points," WHERE id=",this.commander[1]); 
     1899                                comm.setLostBattles((short)(comm.getLostBattles()-points[i])); 
     1900                        } 
    18891901                } 
    18901902