Changeset fdd9b7da5f3efa70d6ba2e2ede6d0cb28403831c

Show
Ignore:
Timestamp:
07/01/07 09:50:24 (1 year ago)
Author:
Christopher Jung <bktheg@web.de>
git-committer:
Christopher Jung <bktheg@web.de> 1183276224 +0200
git-parent:

[4a172a397d76d3496affe3466ffca8e2a53daaa5]

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

Weitere Anpassungen an Hibernate

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • src/net/driftingsouls/ds2/server/werften/ShipWerft.java

    r6b67f71 rfdd9b7d  
    390390         
    391391        @Override 
    392         public boolean dismantleShip(int dismantle, boolean testonly) {        
    393                 boolean result = super.dismantleShip(dismantle, testonly); 
     392        public boolean dismantleShip(Ship ship, boolean testonly) {    
     393                boolean result = super.dismantleShip(ship, testonly); 
    394394                 
    395395                this.ship.recalculateShipStatus(); 
  • src/net/driftingsouls/ds2/server/werften/WerftGUI.java

    rc9078b0 rfdd9b7d  
    2121import java.util.ArrayList; 
    2222import java.util.HashMap; 
     23import java.util.Iterator; 
    2324import java.util.List; 
    2425import java.util.Map; 
     
    2627import net.driftingsouls.ds2.server.Location; 
    2728import net.driftingsouls.ds2.server.Offizier; 
     29import net.driftingsouls.ds2.server.bases.Base; 
    2830import net.driftingsouls.ds2.server.cargo.Cargo; 
    2931import net.driftingsouls.ds2.server.cargo.ItemCargoEntry; 
     
    4345import net.driftingsouls.ds2.server.framework.Context; 
    4446import net.driftingsouls.ds2.server.framework.ContextMap; 
    45 import net.driftingsouls.ds2.server.framework.db.Database; 
    46 import net.driftingsouls.ds2.server.framework.db.SQLQuery; 
    4747import net.driftingsouls.ds2.server.framework.db.SQLResultRow; 
    4848import net.driftingsouls.ds2.server.framework.templates.TemplateEngine; 
     
    7878         */ 
    7979        public String execute( WerftObject werft ) { 
    80                 Database db = context.getDatabase(); 
     80                org.hibernate.Session db = context.getDB(); 
    8181         
    8282                int build = context.getRequest().getParameterInt("build"); 
     
    142142                                        t.parse("werftgui.linkedbase.list", "werftgui.linkedbase.listitem", true); 
    143143                 
    144                                         SQLQuery base = db.query("SELECT id,name FROM bases ", 
    145                                                                 "WHERE x=",werft.getX()," AND y=",werft.getY()," AND system=",werft.getSystem()," AND owner=",werft.getOwner()," ORDER BY id"); 
    146                                         while( base.next() ) { 
    147                                                 t.set_var(      "linkedbase.selected",  (linkedbaseID == base.getInt("id")), 
    148                                                                         "linkedbase.value",             base.getInt("id"), 
    149                                                                         "linkedbase.name",              base.getString("name")+" ("+base.getInt("id")+")" ); 
     144                                        List bases = db.createQuery("from Base " + 
     145                                                                "where x=? and y=? and system=? and owner=? order by id") 
     146                                                                .setInteger(0, werft.getX()) 
     147                                                                .setInteger(1, werft.getY()) 
     148                                                                .setInteger(2, werft.getSystem()) 
     149                                                                .setInteger(3, werft.getOwner()) 
     150                                                                .list(); 
     151                                        for( Iterator iter=bases.iterator(); iter.hasNext(); ) { 
     152                                                Base base = (Base)iter.next(); 
     153                                                 
     154                                                t.set_var(      "linkedbase.selected",  (linkedbaseID == base.getID()), 
     155                                                                        "linkedbase.value",             base.getID(), 
     156                                                                        "linkedbase.name",              base.getName()+" ("+base.getID()+")" ); 
    150157                                                t.parse("werftgui.linkedbase.list", "werftgui.linkedbase.listitem", true); 
    151158                                        } 
    152                                         base.free(); 
    153159                                } 
    154160                        } 
     
    159165 
    160166        private void out_wsShipList(WerftObject werft) { 
    161                 Database db = context.getDatabase(); 
     167                org.hibernate.Session db = context.getDB(); 
    162168 
    163169                t.set_var("werftgui.wsshiplist", 1); 
    164170                t.set_block("_WERFT.WERFTGUI", "wsshiplist.listitem", "wsshiplist.list"); 
    165171                 
    166                 SQLQuery ship = db.query("SELECT t1.id,t1.name,t1.type,t1.status,t1.engine,t1.sensors,t1.comm,t1.weapons,t1.hull,t1.owner,t2.name AS ownername,t2.id AS userid ", 
    167                                                                 "FROM ships t1 JOIN users t2 ON t1.owner=t2.id ", 
    168                                                                 "WHERE t1.id>0 AND t1.x BETWEEN ",(werft.getX()-werft.getSize())," AND ",(werft.getX()+werft.getSize())," AND t1.y BETWEEN ",(werft.getY()-werft.getSize())," AND ",(werft.getY()+werft.getSize())," AND t1.system=",werft.getSystem()," AND !LOCATE('l ',t1.docked) AND t1.battle=0 ORDER BY t2.id,t1.id"); 
    169          
    170                 while( ship.next() ) { 
    171                         if( (werft.getWerftType() == WerftObject.SHIP) && (((ShipWerft)werft).getShipID() == ship.getInt("id")) ) { 
     172                List ships = db.createQuery("from Ship s inner join fetch s.owner as u " + 
     173                                                                "where s.id>0 and (s.x between ? and ?) and (s.y between ? and ?) and s.system=? and " + 
     174                                                                "locate('l ',s.docked)=0 and s.battle=0 order by u.id,s.id") 
     175                                                                .setInteger(0, werft.getX()-werft.getSize()) 
     176                                                                .setInteger(1, werft.getX()+werft.getSize()) 
     177                                                                .setInteger(2, werft.getY()-werft.getSize()) 
     178                                                                .setInteger(3, werft.getY()+werft.getSize()) 
     179                                                                .setInteger(4, werft.getSystem()) 
     180                                                                .list(); 
     181         
     182                for( Iterator iter=ships.iterator(); iter.hasNext(); ) { 
     183                        Ship ship = (Ship)iter.next(); 
     184                         
     185                        if( (werft.getWerftType() == WerftObject.SHIP) && (((ShipWerft)werft).getShip() == ship) ) { 
    172186                                continue;        
    173187                        } 
    174188                         
    175                         ShipTypeData shiptype = Ship.getShipType( ship.getRow() ); 
    176                          
    177                         if( (ship.getInt("hull") < shiptype.getHull()) || (ship.getInt("engine") < 100) || 
    178                                 (ship.getInt("sensors") < 100) || (ship.getInt("comm") < 100) || (ship.getInt("weapons") < 100) ) { 
     189                        ShipTypeData shiptype = ship.getTypeData(); 
     190                         
     191                        if( (ship.getHull() < shiptype.getHull()) || (ship.getEngine() < 100) || 
     192                                (ship.getSensors() < 100) || (ship.getComm() < 100) || (ship.getWeapons() < 100) ) { 
    179193                                t.set_var("ship.needsrepair", 1); 
    180194                        } 
     
    183197                        } 
    184198                         
    185                         String ownername = Common._title(ship.getString("ownername")); 
    186                         if( ownername.length() == 0 ) { 
    187                                 ownername = "Unbekannter Spieler ("+ship.getInt("owner")+")";  
    188                         } 
     199                        String ownername = Common._title(ship.getOwner().getName()); 
    189200                                                 
    190                         t.set_var(      "ship.id",                      ship.getInt("id"), 
    191                                                 "ship.name",            ship.getString("name"), 
     201                        t.set_var(      "ship.id",                      ship.getId(), 
     202                                                "ship.name",            ship.getName(), 
    192203                                                "ship.owner.name",      ownername ); 
    193204                                                                 
    194205                        t.parse("wsshiplist.list", "wsshiplist.listitem", true); 
    195206                } 
    196                 ship.free(); 
    197207        } 
    198208 
     
    318328        private void out_ws(WerftObject werft, int ws) { 
    319329                Context context = ContextMap.getContext(); 
    320                 Database db = context.getDatabase(); 
     330                org.hibernate.Session db = context.getDB(); 
    321331 
    322332                User user = (User)context.getActiveUser(); 
    323333                String sess = context.getSession(); 
    324334                 
    325                 SQLResultRow ship = db.first("SELECT * FROM ships WHERE id>0 AND id=",ws); 
    326                 if( ship.isEmpty() ) { 
     335                Ship ship = (Ship)db.get(Ship.class, ws); 
     336                if( (ship == null) || (ship.getId() < 0) ) { 
    327337                        context.addError("Das angegebene Schiff existiert nicht", werft.getUrlBase()+"&amp;sess="+sess);                 
    328338                        return; 
     
    332342                        return; 
    333343                } 
    334                 if( !Location.fromResult(ship).sameSector(0, new Location(werft.getSystem(), werft.getX(), werft.getY()), werft.getSize()) ) { 
     344                if( !ship.getLocation().sameSector(0, new Location(werft.getSystem(), werft.getX(), werft.getY()), werft.getSize()) ) { 
    335345                        context.addError("Das Schiff befindet sich nicht im selben Sektor wie die Werft", werft.getUrlBase()+"&amp;sess="+sess);                 
    336346                        return; 
    337347                } 
    338348                 
    339                 if( ship.getInt("battle") != 0 ) { 
     349                if( ship.getBattle() != 0 ) { 
    340350                        context.addError("Das Schiff befindet sich in einer Schlacht", werft.getUrlBase()+"&amp;sess="+sess);                    
    341351                        return; 
    342352                } 
    343353                 
    344                 ShipTypeData shipType = Ship.getShipType(ship); 
     354                ShipTypeData shipType = ship.getTypeData(); 
    345355                 
    346356                t.set_var(      "werftgui.ws",                  1, 
    347                                         "ship.id",                              ship.getInt("id"), 
    348                                         "ship.name",                    ship.getString("name"), 
    349                                         "ship.own",                             (ship.getInt("owner") == user.getID()), 
    350                                         "ship.owner.id",                ship.getInt("owner"), 
     357                                        "ship.id",                              ship.getId(), 
     358                                        "ship.name",                    ship.getName(), 
     359                                        "ship.own",                             (ship.getOwner() == user), 
     360                                        "ship.owner.id",                ship.getOwner(), 
    351361                                        "ship.type.modules",    shipType.getTypeModules() ); 
    352362         
    353                 if( ship.getInt("owner") != user.getID() ) { 
    354                         User owner = (User)context.getDB().get(User.class, ship.getInt("owner")); 
     363                if( ship.getOwner() != user ) { 
     364                        User owner = ship.getOwner(); 
    355365                        t.set_var("ship.owner.name", Common._title(owner.getName())); 
    356366                } 
     
    360370                        String conf = context.getRequest().getParameterString("conf"); 
    361371                         
    362                         this.out_repairShip( ship.getInt("id"), werft, conf ); 
     372                        this.out_repairShip( ship, werft, conf ); 
    363373                } 
    364374                else if( action.equals("dismantle") ) { 
    365375                        String conf = context.getRequest().getParameterString("conf"); 
    366376                         
    367                         this.out_dismantleShip( ship.getInt("id"), werft, conf ); 
     377                        this.out_dismantleShip( ship, werft, conf ); 
    368378                } 
    369379                else if( action.equals("module") ) { 
    370                         this.out_moduleShip( ship.getInt("id"), werft ); 
     380                        this.out_moduleShip( ship, werft ); 
    371381                } 
    372382                else { 
     
    391401        } 
    392402 
    393         private void out_ws_info(SQLResultRow ship) { 
    394                 ShipTypeData shipType = Ship.getShipType(ship); 
     403        private void out_ws_info(Ship ship) { 
     404                ShipTypeData shipType = ship.getTypeData(); 
    395405                 
    396406                t.set_var(      "werftgui.ws.showinfo",         1, 
    397                                         "ship.name",                            ship.getString("name"), 
     407                                        "ship.name",                            ship.getName(), 
    398408                                        "ship.type.id",                         shipType.getTypeId(), 
    399409                                        "ship.type.picture",            shipType.getPicture(), 
    400                                         "ship.id",                                      ship.getInt("id"), 
    401                                         "ship.hull",                            ship.getInt("hull"), 
     410                                        "ship.id",                                      ship.getId(), 
     411                                        "ship.hull",                            ship.getHull(), 
    402412                                        "ship.type.hull",                       shipType.getHull(), 
    403                                         "ship.hull.color",                      this.genSubColor(ship.getInt("hull"), shipType.getHull()), 
    404                                         "ship.panzerung",                       Math.round(shipType.getPanzerung()*(double)ship.getInt("hull")/shipType.getHull()), 
    405                                         "ship.shields",                         ship.getInt("shields"), 
     413                                        "ship.hull.color",                      this.genSubColor(ship.getHull(), shipType.getHull()), 
     414                                        "ship.panzerung",                       Math.round(shipType.getPanzerung()*(double)ship.getHull()/shipType.getHull()), 
     415                                        "ship.shields",                         ship.getShields(), 
    406416                                        "ship.type.shields",            shipType.getShields(), 
    407                                         "ship.shields.color",           this.genSubColor(ship.getInt("shields"), shipType.getShields()), 
    408                                         "ship.engine",                          ship.getInt("engine"), 
     417                                        "ship.shields.color",           this.genSubColor(ship.getShields(), shipType.getShields()), 
     418                                        "ship.engine",                          ship.getEngine(), 
    409419                                        "ship.type.engine",                     ( shipType.getCost() > 0 ? 100 : 0 ), 
    410                                         "ship.engine.color",            this.genSubColor(ship.getInt("engine"), 100), 
    411                                         "ship.weapons",                         ship.getInt("engine"), 
     420                                        "ship.engine.color",            this.genSubColor(ship.getEngine(), 100), 
     421                                        "ship.weapons",                         ship.getWeapons(), 
    412422                                        "ship.type.weapons",            ( shipType.isMilitary() ? 100 : 0 ), 
    413                                         "ship.weapons.color",           this.genSubColor(ship.getInt("weapons"), 100), 
    414                                         "ship.comm",                            ship.getInt("comm"), 
     423                                        "ship.weapons.color",           this.genSubColor(ship.getWeapons(), 100), 
     424                                        "ship.comm",                            ship.getComm(), 
    415425                                        "ship.type.comm",                       100, 
    416                                         "ship.comm.color",                      this.genSubColor(ship.getInt("comm"), 100), 
    417                                         "ship.sensors",                         ship.getInt("sensors"), 
     426                                        "ship.comm.color",                      this.genSubColor(ship.getComm(), 100), 
     427                                        "ship.sensors",                         ship.getSensors(), 
    418428                                        "ship.type.sensors",            100, 
    419                                         "ship.sensors.color",           this.genSubColor(ship.getInt("sensors"), 100), 
    420                                         "ship.crew",                            ship.getInt("crew"), 
     429                                        "ship.sensors.color",           this.genSubColor(ship.getSensors(), 100), 
     430                                        "ship.crew",                            ship.getCrew(), 
    421431                                        "ship.type.crew",                       shipType.getCrew(), 
    422                                         "ship.crew.color",                      this.genSubColor(ship.getInt("crew"), shipType.getCrew()), 
    423                                         "ship.e",                                       ship.getInt("e"), 
     432                                        "ship.crew.color",                      this.genSubColor(ship.getCrew(), shipType.getCrew()), 
     433                                        "ship.e",                                       ship.getEnergy(), 
    424434                                        "ship.type.e",                          shipType.getEps(), 
    425                                         "ship.e.color",                         this.genSubColor(ship.getInt("e"), shipType.getEps()), 
    426                                         "ship.heat",                            ship.getInt("s") ); 
    427          
    428                 Offizier offizier = Offizier.getOffizierByDest('s', ship.getInt("id")); 
     435                                        "ship.e.color",                         this.genSubColor(ship.getEnergy(), shipType.getEps()), 
     436                                        "ship.heat",                            ship.getHeat() ); 
     437         
     438                Offizier offizier = Offizier.getOffizierByDest('s', ship.getId()); 
    429439                if( offizier != null ) { 
    430440                        t.set_var(      "ship.offizier.id",                     offizier.getID(), 
     
    435445        } 
    436446 
    437         private void out_moduleShip(int shipID, WerftObject werft) { 
     447        private void out_moduleShip(Ship ship, WerftObject werft) { 
    438448                Context context = ContextMap.getContext(); 
    439                 org.hibernate.Session db = context.getDB(); 
    440449                String sess = context.getSession(); 
    441450                User user = (User)context.getActiveUser(); 
     
    444453                int slot = context.getRequest().getParameterInt("slot"); 
    445454                String moduleaction = context.getRequest().getParameterString("moduleaction"); 
    446          
    447                 Ship ship = (Ship)db.get(Ship.class, shipID); 
    448455         
    449456                //Gehoert das Schiff dem User? 
     
    527534        } 
    528535 
    529         private void out_dismantleShip(int dismantle, WerftObject werft, String conf) { 
     536        private void out_dismantleShip(Ship ship, WerftObject werft, String conf) { 
    530537                Context context = ContextMap.getContext(); 
    531                 org.hibernate.Session db = context.getDB(); 
    532538                String sess = context.getSession(); 
    533539                User user = (User)context.getActiveUser(); 
    534                  
    535                 Ship ship = (Ship)db.get(Ship.class, dismantle); 
    536540                 
    537541                //Gehoert das Schiff dem User? 
     
    570574                } 
    571575 
    572                 boolean ok = werft.dismantleShip(dismantle, !conf.equals("ok")); 
     576                boolean ok = werft.dismantleShip(ship, !conf.equals("ok")); 
    573577                if( !ok ) { 
    574578                        t.set_var("ws.dismantle.error", werft.MESSAGE.getMessage() ); 
     
    582586        } 
    583587 
    584         private void out_repairShip(int repair, WerftObject werft, String conf) { 
     588        private void out_repairShip(Ship ship, WerftObject werft, String conf) { 
    585589                Context context = ContextMap.getContext(); 
    586                 org.hibernate.Session db = context.getDB(); 
    587                  
    588                 Ship ship = (Ship)db.get(Ship.class, repair); 
     590                 
    589591                if( (ship == null) || (ship.getId() < 0) ) { 
    590592                        context.addError("Das angegebene Schiff existiert nicht oder geh&ouml;rt nicht ihnen"); 
  • src/net/driftingsouls/ds2/server/werften/WerftObject.java

    r6b67f71 rfdd9b7d  
    830830         * nur das demontieren selbst.{@link DSObject#MESSAGE} enthaelt die Hinweistexte 
    831831         *  
    832          * @param dismantle Die ID des zu demontierenden Schiffes 
     832         * @param ship Das zu demontierende Schiff 
    833833         * @param testonly Soll nur geprueft (true) oder wirklich demontiert werden (false)? 
    834834         * @return true, wenn kein Fehler aufgetreten ist 
    835835         */ 
    836         public boolean dismantleShip(int dismantle, boolean testonly) {        
     836        public boolean dismantleShip(Ship ship, boolean testonly) {    
    837837                org.hibernate.Session db = ContextMap.getContext().getDB(); 
    838838                 
    839839                StringBuilder output = MESSAGE.get(); 
    840840         
    841                 Ship sd = (Ship)db.get(Ship.class, dismantle); 
    842                 if( sd.getId() < 0 ) { 
     841                if( ship.getId() < 0 ) { 
    843842                        ContextMap.getContext().addError("Das angegebene Schiff existiert nicht"); 
    844843                        return false; 
    845844                } 
    846845                 
    847                 Cargo scargo = sd.getCargo(); 
     846                Cargo scargo = ship.getCargo(); 
    848847                 
    849848                Cargo cargo = this.getCargo(false); 
     
    851850                long maxcargo = this.getMaxCargo(false); 
    852851         
    853                 Cargo cost = this.getDismantleCargo( sd ); 
     852                Cargo cost = this.getDismantleCargo( ship ); 
    854853                 
    855854                Cargo newcargo = (Cargo)cargo.clone(); 
     
    866865                } 
    867866         
    868                 if( this.getCrew() + sd.getCrew() > this.getMaxCrew() ) { 
     867                if( this.getCrew() + ship.getCrew() > this.getMaxCrew() ) { 
    869868                        output.append("Nicht gengend Platz f&uuml;r die Crew\n"); 
    870869                        ok = false; 
     
    874873                 
    875874                List offiziere = db.createQuery("from Offizier where dest=?") 
    876                         .setString(0, "s "+dismantle
     875                        .setString(0, "s "+ship.getId()
    877876                        .list(); 
    878877                 
     
    888887                        this.setCargo(newcargo, false); 
    889888         
    890                         this.setCrew(this.getCrew()+sd.getCrew()); 
     889                        this.setCrew(this.getCrew()+ship.getCrew()); 
    891890                        for( Iterator iter=offiziere.iterator(); iter.hasNext(); ) { 
    892891                                Offizier offi = (Offizier)iter.next(); 
     
    894893                        } 
    895894         
    896                         sd.destroy(); 
     895                        ship.destroy(); 
    897896                } 
    898897