Changeset 1a410f838ead72f7a7aa1511bd76834c65f540c3

Show
Ignore:
Timestamp:
08/05/07 11:14:29 (1 year ago)
Author:
Christopher Jung <bktheg@web.de>
git-committer:
Christopher Jung <bktheg@web.de> 1186305269 +0200
git-parent:

[eca51daa0bf6310e3131f51567756e89ecc5c9c5]

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

KS: Weitere Umstellungen auf Hibernate

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • src/net/driftingsouls/ds2/server/modules/ks/KSMenuAttackMuniSelectAction.java

    rc5d039a r1a410f8  
    2121import java.util.HashMap; 
    2222import java.util.HashSet; 
     23import java.util.Iterator; 
    2324import java.util.List; 
    2425import java.util.Map; 
     
    3435import net.driftingsouls.ds2.server.config.Weapon; 
    3536import net.driftingsouls.ds2.server.config.Weapons; 
     37import net.driftingsouls.ds2.server.entities.Ammo; 
    3638import net.driftingsouls.ds2.server.entities.User; 
    3739import net.driftingsouls.ds2.server.framework.Common; 
    3840import net.driftingsouls.ds2.server.framework.Context; 
    3941import net.driftingsouls.ds2.server.framework.ContextMap; 
    40 import net.driftingsouls.ds2.server.framework.db.Database; 
    41 import net.driftingsouls.ds2.server.framework.db.SQLQuery; 
    4242import net.driftingsouls.ds2.server.ships.ShipTypeData; 
    4343import net.driftingsouls.ds2.server.ships.ShipTypes; 
     
    200200                 
    201201                Context context = ContextMap.getContext(); 
    202                 Database db = context.getDatabase(); 
     202                org.hibernate.Session db = context.getDB(); 
    203203                 
    204204                BattleShip ownShip = battle.getOwnShip(); 
     
    264264                        Set<Integer> ammoids = new HashSet<Integer>(); 
    265265 
    266                         SQLQuery ammoid = db.query("SELECT id FROM ammo " + 
    267                                         "WHERE type IN ('",Common.implode("','", Weapons.get().weapon(weapon).getAmmoType())+"')"); 
    268                         while( ammoid.next() ) { 
    269                                 ammoids.add(ammoid.getInt("id")); 
     266                        Iterator ammoIter = db.createQuery("from Ammo " + 
     267                                        "where type in ("+Common.implode("','", Weapons.get().weapon(weapon).getAmmoType())+"')") 
     268                                .iterate(); 
     269 
     270                        while( ammoIter.hasNext() ) { 
     271                                Ammo ammo = (Ammo)ammoIter.next(); 
     272                                ammoids.add(ammo.getId()); 
    270273                        } 
    271                         ammoid.free(); 
    272274 
    273275                        // Munition 
  • src/net/driftingsouls/ds2/server/modules/ks/KSUndockAllAction.java

    r2c96489 r1a410f8  
    1919package net.driftingsouls.ds2.server.modules.ks; 
    2020 
     21import java.util.Iterator; 
     22 
    2123import net.driftingsouls.ds2.server.ContextCommon; 
    2224import net.driftingsouls.ds2.server.battles.Battle; 
     
    2527import net.driftingsouls.ds2.server.framework.Context; 
    2628import net.driftingsouls.ds2.server.framework.ContextMap; 
    27 import net.driftingsouls.ds2.server.framework.db.Database; 
    28 import net.driftingsouls.ds2.server.framework.db.SQLResultRow; 
     29import net.driftingsouls.ds2.server.ships.Ship; 
    2930 
    3031/** 
     
    4546        public int validate(Battle battle) { 
    4647                BattleShip ownShip = battle.getOwnShip(); 
    47                 Database db = ContextMap.getContext().getDatabase(); 
     48                org.hibernate.Session db = ContextMap.getContext().getDB(); 
    4849                 
    49                 SQLResultRow dock = db.first("SELECT id FROM ships WHERE docked IN ('l ",ownShip.getId(),"','",ownShip.getId(),"')"); 
    50                 if( !dock.isEmpty() ) { 
     50                boolean dock = db.createQuery("from Ship where docked in (?,?)") 
     51                        .setString(0, "l "+ownShip.getId()) 
     52                        .setString(1, Integer.toString(ownShip.getId())) 
     53                        .iterate().hasNext(); 
     54                 
     55                if( dock ) { 
    5156                        return RESULT_OK; 
    5257                } 
     
    6772                 
    6873                Context context = ContextMap.getContext(); 
    69                 Database db = context.getDatabase(); 
     74                org.hibernate.Session db = context.getDB(); 
    7075                BattleShip ownShip = battle.getOwnShip(); 
    7176                 
     
    7479                ownShip.getShip().setBattleAction(true); 
    7580                 
    76                 db.update("UPDATE ships SET docked='',battleAction=1 WHERE docked IN ('l ",ownShip.getId(),"','",ownShip.getId(),"')"); 
     81                int counter = 0; 
     82                 
     83                final Iterator shipIter = db.createQuery("from Ship where docked in (?,?)") 
     84                        .setString(0, "l "+ownShip.getId()) 
     85                        .setString(1, Integer.toString(ownShip.getId())) 
     86                        .iterate(); 
     87                while( shipIter.hasNext() ) { 
     88                        Ship aship = (Ship)shipIter.next(); 
     89                         
     90                        if( aship.getDocked().charAt(0) == 'l' ) { 
     91                                ownShip.getShip().dock(Ship.DockMode.START, aship); 
     92                        } 
     93                        else { 
     94                                ownShip.getShip().dock(Ship.DockMode.UNDOCK, aship); 
     95                        } 
     96                        aship.setBattleAction(true); 
     97                         
     98                        counter++; 
     99                } 
    77100 
    78                 battle.logme(db.affectedRows()+" Schiffe wurden abgedockt"); 
    79                 battle.logenemy(db.affectedRows()+" Schiffe wurden von der "+Battle.log_shiplink(ownShip.getShip())+" abgedockt\n"); 
     101                battle.logme(counter+" Schiffe wurden abgedockt"); 
     102                battle.logenemy(counter+" Schiffe wurden von der "+Battle.log_shiplink(ownShip.getShip())+" abgedockt\n"); 
    80103 
    81104                battle.setPoints(battle.getOwnSide(), battle.getPoints(battle.getOwnSide()) - 1);