Changeset ae27f31c209666431d2bb6c69fca39c2317d5ac6

Show
Ignore:
Timestamp:
11/01/07 14:24:36 (1 year ago)
Author:
Christopher Jung <bktheg@web.de>
git-committer:
Christopher Jung <bktheg@web.de> 1193923476 +0100
git-parent:

[e5372a22e6462be61c59ccfa89c4c509c4c42828]

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

npc-menue auf hibernate umgestellt

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • src/net/driftingsouls/ds2/server/entities/OrderShip.java

    r6422552 rae27f31  
    2020 
    2121import javax.persistence.Entity; 
     22import javax.persistence.FetchType; 
    2223import javax.persistence.Id; 
     24import javax.persistence.OneToOne; 
     25import javax.persistence.PrimaryKeyJoinColumn; 
    2326import javax.persistence.Table; 
     27 
     28import net.driftingsouls.ds2.server.ships.ShipType; 
    2429 
    2530import org.hibernate.annotations.Immutable; 
     
    3641        @Id 
    3742        private int type; 
     43        @OneToOne(fetch=FetchType.LAZY) 
     44        @PrimaryKeyJoinColumn 
     45        private ShipType shipType; 
    3846        private int cost; 
    3947         
     
    5866         * @return Der Schiffstyp 
    5967         */ 
    60         public int getType() { 
    61                 return type; 
     68        public ShipType getShipType() { 
     69                return this.shipType; 
    6270        } 
    6371         
    64          
     72        /** 
     73         * Gibt die ID des Eintrags zurueck 
     74         * @return Die ID 
     75         */ 
     76        public int getId() { 
     77                return this.type; 
     78        } 
    6579} 
  • src/net/driftingsouls/ds2/server/modules/NPCOrderController.java

    r7375108 rae27f31  
    88import net.driftingsouls.ds2.server.ContextCommon; 
    99import net.driftingsouls.ds2.server.Location; 
     10import net.driftingsouls.ds2.server.bases.Base; 
    1011import net.driftingsouls.ds2.server.comm.PM; 
    1112import net.driftingsouls.ds2.server.config.Faction; 
     
    1415import net.driftingsouls.ds2.server.config.Rassen; 
    1516import net.driftingsouls.ds2.server.entities.FactionShopOrder; 
     17import net.driftingsouls.ds2.server.entities.Order; 
     18import net.driftingsouls.ds2.server.entities.OrderOffizier; 
     19import net.driftingsouls.ds2.server.entities.OrderShip; 
    1620import net.driftingsouls.ds2.server.entities.User; 
    1721import net.driftingsouls.ds2.server.framework.Common; 
    1822import net.driftingsouls.ds2.server.framework.Configuration; 
    1923import net.driftingsouls.ds2.server.framework.Context; 
    20 import net.driftingsouls.ds2.server.framework.db.Database; 
    21 import net.driftingsouls.ds2.server.framework.db.SQLQuery; 
    22 import net.driftingsouls.ds2.server.framework.db.SQLResultRow; 
    2324import net.driftingsouls.ds2.server.framework.pipeline.generators.Action; 
    2425import net.driftingsouls.ds2.server.framework.pipeline.generators.ActionType; 
     
    363364        @Action(ActionType.DEFAULT) 
    364365        public void changeOrderLocationAction() { 
    365                 Database db = getDatabase(); 
     366                org.hibernate.Session db = getDB(); 
    366367                TemplateEngine t = this.getTemplateEngine(); 
    367368                User user = (User)this.getUser(); 
     
    374375                String ordermessage = ""; 
    375376         
    376                 SQLResultRow ships = db.first("SELECT s.id FROM ships s JOIN ship_types st ON s.type=st.id " + 
    377                                 "WHERE st.class="+ShipClasses.STATION.ordinal()+" AND s.id>0 " + 
    378                                         "AND s.x="+loc.getX()+" AND s.y="+loc.getY()+" AND s.system="+loc.getSystem()+" AND s.owner="+user.getID()); 
    379                  
    380                 SQLResultRow bases = db.first("SELECT id FROM bases WHERE owner="+user.getID()+" AND " + 
    381                                 "s.x="+loc.getX()+" AND s.y="+loc.getY()+" AND s.system="+loc.getSystem()); 
    382                  
    383                 if( !bases.isEmpty() || !ships.isEmpty() ) { 
     377                Ship ship = (Ship)db.createQuery("from Ship as s " + 
     378                                "where s.shiptype.shipClass= :cls AND s.id>0 " + 
     379                                        "and s.x= :x and s.y= :y and s.system= :sys and s.owner= :user") 
     380                        .setInteger("cls", ShipClasses.STATION.ordinal()) 
     381                        .setEntity("user", user) 
     382                        .setInteger("x", loc.getX()) 
     383                        .setInteger("y", loc.getY()) 
     384                        .setInteger("sys", loc.getSystem()) 
     385                        .setMaxResults(1) 
     386                        .uniqueResult(); 
     387                 
     388                Base base = (Base)db.createQuery("from Base where owner= :user and " + 
     389                                "x= :x and y= :y and system= :sys") 
     390                        .setEntity("user", user) 
     391                        .setInteger("x", loc.getX()) 
     392                        .setInteger("y", loc.getY()) 
     393                        .setInteger("sys", loc.getSystem()) 
     394                        .setMaxResults(1) 
     395                        .uniqueResult(); 
     396                 
     397                if( (base != null) || (ship != null) ) { 
    384398                        user.setNpcOrderLocation(loc.toString()); 
    385399                         
     
    403417        @Action(ActionType.DEFAULT) 
    404418        public void orderAction() { 
    405                 Database db = getDatabase(); 
     419                org.hibernate.Session db = getDB(); 
    406420                TemplateEngine t = this.getTemplateEngine(); 
    407421                User user = (User)this.getUser(); 
     
    420434                 
    421435                if( order > 0 ) { 
    422                         costs = count*db.first("SELECT cost FROM orders_ships WHERE type=",order).getInt("cost"); 
     436                        OrderShip orderShip = (OrderShip)db.get(OrderShip.class, order); 
     437                        costs = count*orderShip.getCost(); 
    423438                } 
    424439                else if( order < 0 ) { 
    425                         costs = count*db.first("SELECT cost FROM orders_offiziere WHERE id=",(-order)).getInt("cost"); 
     440                        OrderOffizier orderOffi = (OrderOffizier)db.get(OrderOffizier.class, -order); 
     441                        costs = count*orderOffi.getCost(); 
    426442                } 
    427443                 
     
    440456                                } 
    441457                                for( int i=0; i < count; i++ ) { 
    442                                         db.update("INSERT INTO orders (type,tick,user) VALUES (",order,",3,",user.getID(),")"); 
     458                                        Order orderObj = new Order(user.getID(), order); 
     459                                        orderObj.setTick(3); 
     460                                        db.persist(orderObj); 
    443461                                } 
    444462                                 
     
    461479        @Action(ActionType.DEFAULT) 
    462480        public void defaultAction() { 
    463                 Database db = getDatabase(); 
     481                org.hibernate.Session db = getDB(); 
    464482                TemplateEngine t = this.getTemplateEngine(); 
    465483                User user = (User)this.getUser(); 
     
    469487                t.setVar( "npcorder.ordermenu", 1 ); 
    470488 
    471                 SQLQuery order = db.query("SELECT type FROM orders WHERE user=",user.getID()); 
    472                 while( order.next() ) { 
    473                         Common.safeIntInc(orders, order.getInt("type")); 
    474                 } 
    475                 order.free(); 
     489                List orderList = db.createQuery("from Order where user= :user") 
     490                        .setInteger("user", user.getID()) 
     491                        .list(); 
     492                for( Iterator iter=orderList.iterator(); iter.hasNext(); ) { 
     493                        Order order = (Order)iter.next(); 
     494                        Common.safeIntInc(orders, order.getType()); 
     495                } 
    476496 
    477497                /* 
     
    483503                t.setBlock("_NPCORDER", "ships.listitem", "ships.list"); 
    484504 
    485                 SQLQuery ship = db.query("SELECT t1.*,t2.nickname name,t2.class FROM orders_ships t1 JOIN ship_types t2 ON t1.type=t2.id ORDER BY t2.class,t1.type"); 
    486                 while( ship.next() ) { 
     505                List shipOrders = db.createQuery("from OrderShip order by shipType.shipClass,shipType").list(); 
     506                for( Iterator iter=shipOrders.iterator(); iter.hasNext(); ) { 
     507                        OrderShip ship = (OrderShip)iter.next(); 
     508                         
    487509                        t.start_record(); 
    488510                         
    489                         if( ship.getInt("class") != oldclass ) { 
     511                        if( ship.getShipType().getShipClass() != oldclass ) { 
    490512                                t.setVar(       "ship.newclass",                1, 
    491                                                         "ship.newclass.name",   ShipTypes.getShipClass(ship.getInt("class")).getSingular() ); 
     513                                                        "ship.newclass.name",   ShipTypes.getShipClass(ship.getShipType().getShipClass()).getSingular() ); 
    492514                                 
    493                                 oldclass = ship.getInt("class"); 
    494                         } 
    495                          
    496                         if( orders.containsKey(ship.getInt("type")) ) { 
    497                                 orders.put(ship.getInt("type"), 0); 
    498                         } 
    499                          
    500                         t.setVar(       "ship.name",            ship.getString("name"), 
    501                                                 "ship.type",            ship.getInt("type"), 
    502                                                 "ship.cost",            ship.getInt("cost"), 
    503                                                 "ship.ordercount",      orders.get(ship.getInt("type")) ); 
     515                                oldclass = ship.getShipType().getShipClass(); 
     516                        } 
     517                         
     518                        if( !orders.containsKey(ship.getId()) ) { 
     519                                orders.put(ship.getId(), 0); 
     520                        } 
     521                         
     522                        t.setVar(       "ship.name",            ship.getShipType().getNickname(), 
     523                                                "ship.type",            ship.getId(), 
     524                                                "ship.cost",            ship.getCost(), 
     525                                                "ship.ordercount",      orders.get(ship.getId()) ); 
    504526                                                                 
    505527                        t.parse("ships.list", "ships.listitem", true); 
     
    508530                        t.clear_record(); 
    509531                } 
    510                 ship.free(); 
    511532                 
    512533                /* 
     
    516537                t.setBlock("_NPCORDER", "offiziere.listitem", "offiziere.list"); 
    517538                 
    518                 SQLQuery offizier = db.query("SELECT * FROM orders_offiziere WHERE cost > 0 ORDER BY id"); 
    519                 while( offizier.next() ) { 
    520                         if( orders.containsKey(-offizier.getInt("id")) ) { 
    521                                 orders.put(-offizier.getInt("id"), 0); 
    522                         } 
    523                          
    524                         t.setVar(       "offizier.name",                offizier.getString("name"), 
    525                                                 "offizier.rang",                offizier.getInt("rang"), 
    526                                                 "offizier.cost",                offizier.getInt("cost"), 
    527                                                 "offizier.id",                  -offizier.getInt("id"), 
    528                                                 "offizier.ordercount",  orders.get(offizier.getInt("id")) ); 
     539                List offizierOrders = db.createQuery("from OrderOffizier where cost > 0 order by id").list(); 
     540                for( Iterator iter=offizierOrders.iterator(); iter.hasNext(); ) { 
     541                        OrderOffizier offizier = (OrderOffizier)iter.next(); 
     542                         
     543                        if( !orders.containsKey(-offizier.getId()) ) { 
     544                                orders.put(-offizier.getId(), 0); 
     545                        } 
     546                         
     547                        t.setVar(       "offizier.name",                offizier.getName(), 
     548                                                "offizier.rang",                offizier.getRang(), 
     549                                                "offizier.cost",                offizier.getCost(), 
     550                                                "offizier.id",                  -offizier.getId(), 
     551                                                "offizier.ordercount",  orders.get(offizier.getId()) ); 
    529552                                                                 
    530553                        t.parse("offiziere.list", "offiziere.listitem", true); 
    531554                } 
    532                 offizier.free(); 
    533555        } 
    534556}