Changeset 41e492ffe2a142d78e5aa841c2c7bfb4f6f8415b

Show
Ignore:
Timestamp:
01/06/07 15:23:42 (2 years ago)
Author:
Christopher Jung <bktheg@web.de>
git-committer:
Christopher Jung <bktheg@web.de> 1168093422 +0100
git-parent:

[63b8c37bb0b8fc90910a7274b674e7fda327e2d4]

git-author:
Christopher Jung <bktheg@web.de> 1168093422 +0100
Message:

Die Schiffsbibliothek verwendet nun immer die Datenbankverbindung des Kontexts

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • src/net/driftingsouls/ds2/server/ships/Ships.java

    r906b63b r41e492f  
    109109        public static final ThreadLocalMessage MESSAGE = new ThreadLocalMessage(); 
    110110         
    111         private static Database db = new Database(); 
    112          
    113111        private static Map<Integer,SQLResultRow> shiptypes = new HashMap<Integer,SQLResultRow>(); 
    114112        private static Map<Location,Integer> nebel = Collections.synchronizedMap(new CacheMap<Location,Integer>(1000)); 
     
    308306                } 
    309307                else { 
     308                        Database db = ContextMap.getContext().getDatabase(); 
    310309                        picture = User.getDefaultImagePath(db)+picture; 
    311310                } 
     
    332331                return getShipType(shipdata, false); 
    333332        } 
    334          
    335         private static PreparedQuery pqGetModuleRow = db.prepare("SELECT nickname,picture,ru,rd,ra,rm,eps,cost,hull,panzerung,cargo,heat,crew,weapons,maxheat,torpedodef,shields,size,jdocks,adocks,sensorrange,hydro,deutfactor,recost,flags,werft,ow_werft FROM ships_modules WHERE id>0 AND id= ? "); 
    336          
     333 
    337334        /** 
    338335         * Gibt die Typen-Daten des angegebenen Schiffs zurueck  
     
    344341        public static SQLResultRow getShipType( SQLResultRow shipdata, boolean plaindata ) { 
    345342                int shiptype = shipdata.getInt("type"); 
     343                 
    346344                if( shipdata.getString("status").indexOf("tblmodules") != -1 ) { 
    347                         shipdata = pqGetModuleRow.pfirst(shipdata.getInt("id")); 
     345                        Database db = ContextMap.getContext().getDatabase(); 
     346                        shipdata = db.prepare("SELECT nickname,picture,ru,rd,ra,rm,eps,cost,hull,panzerung,cargo,heat,crew,weapons,maxheat,torpedodef,shields,size,jdocks,adocks,sensorrange,hydro,deutfactor,recost,flags,werft,ow_werft " + 
     347                                        "FROM ships_modules " + 
     348                                        "WHERE id>0 AND id= ? ") 
     349                                .first(shipdata.getInt("id")); 
    348350                } 
    349351                else { 
     
    353355                return getShipType(shiptype, shipdata, plaindata); 
    354356        } 
    355          
    356         private static PreparedQuery pqGetShipInfos = db.prepare("SELECT type,status FROM ships WHERE id>0 AND id= ?"); 
    357          
     357                 
    358358        private static SQLResultRow getShipType( int shiptype, boolean isShip, boolean plaindata ) { 
    359359                if( isShip ) { 
    360360                        // TODO: Schiffscache implementieren! 
    361                         SQLResultRow shipdata = pqGetShipInfos.pfirst(shiptype); 
     361                         
     362                        Database db = ContextMap.getContext().getDatabase(); 
     363                        SQLResultRow shipdata = db.prepare("SELECT type,status FROM ships WHERE id>0 AND id= ?") 
     364                                .first(shiptype); 
    362365                         
    363366                        if( shipdata.getString("status").indexOf("tblmodules") != -1 ) { 
    364                                 shipdata = pqGetModuleRow.pfirst(shiptype); 
     367                                shipdata = db.prepare("SELECT nickname,picture,ru,rd,ra,rm,eps,cost,hull,panzerung,cargo,heat,crew,weapons,maxheat,torpedodef,shields,size,jdocks,adocks,sensorrange,hydro,deutfactor,recost,flags,werft,ow_werft " + 
     368                                                "FROM ships_modules " + 
     369                                                "WHERE id>0 AND id= ? ") 
     370                                        .first(shiptype); 
    365371                        } 
    366372                        else { 
     
    374380                return getShipType(shiptype, null, plaindata); 
    375381        } 
    376          
    377         private static PreparedQuery pqGetShipType = db.prepare("SELECT *,LOCATE('=',weapons) as military FROM ship_types WHERE id= ? "); 
    378382         
    379383        private static SQLResultRow getShipType( int shiptype, SQLResultRow shipdata, boolean plaindata ) { 
    380384                synchronized (shiptypes) { 
    381385                        if( !shiptypes.containsKey(shiptype) ) { 
    382                                 shiptypes.put(shiptype, pqGetShipType.pfirst(shiptype)); 
     386                                Database db = ContextMap.getContext().getDatabase(); 
     387                                SQLResultRow row = db.prepare("SELECT *,LOCATE('=',weapons) as military FROM ship_types WHERE id= ? ") 
     388                                        .first(shiptype); 
     389                                 
     390                                shiptypes.put(shiptype, row); 
    383391                        } 
    384392                } 
     
    25542562                return getNebula(new Location(ship.getInt("system"), ship.getInt("x"), ship.getInt("y"))); 
    25552563        } 
    2556          
    2557         private static PreparedQuery pqGetNebula = db.prepare("SELECT id,type FROM nebel WHERE system= ? AND x= ? AND y= ? "); 
    2558          
     2564                 
    25592565        /** 
    25602566         * Gibt den Nebeltyp an der angegebenen Position zurueck. Sollte sich an der Position kein 
     
    25652571        public static synchronized int getNebula(Location loc) { 
    25662572                if( !nebel.containsKey(loc) ) { 
    2567                         SQLResultRow neb = pqGetNebula.pfirst(loc.getSystem(), loc.getX(), loc.getY()); 
     2573                        Database db = ContextMap.getContext().getDatabase(); 
     2574                         
     2575                        SQLResultRow neb = db.prepare("SELECT id,type FROM nebel WHERE system= ? AND x= ? AND y= ? "). 
     2576                                first(loc.getSystem(), loc.getX(), loc.getY()); 
    25682577                        if( neb.isEmpty() ) { 
    25692578                                nebel.put(loc, -1);