Changeset f082126a9f1dc7b76a2f6e356719d06f76b9a94b

Show
Ignore:
Timestamp:
11/03/07 10:38:24 (1 year ago)
Author:
Christopher Jung <bktheg@web.de>
git-committer:
Christopher Jung <bktheg@web.de> 1194082704 +0100
git-parent:

[eaeb89e9679becda21dbd8911decf2fb72394e2a]

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

Hack zugunsten einer richtigen Loesung entfernt

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • db/tables/ships.sql

    r144f38e rf082126  
    44  `name` varchar(50) NOT NULL default 'noname', 
    55  `type` int(11) NOT NULL default '0', 
     6  `modules` int(11), 
    67  `cargo` text NOT NULL, 
    78  `x` int(11) NOT NULL default '1', 
     
    5657ALTER TABLE ships ADD CONSTRAINT ships_fk_ship_fleets FOREIGN KEY (fleet) REFERENCES ship_fleets(id); 
    5758ALTER TABLE ships ADD CONSTRAINT ships_fk_battles FOREIGN KEY (battle) REFERENCES battles(id); 
     59-- Keine Constraint fuer modules! 
    5860 
    5961INSERT INTO `ships` (`id`, `owner`, `name`, `type`, `cargo`, `x`, `y`, `system`, `status`, `crew`, `e`, `s`, `hull`, `shields`, `heat`, `engine`, `weapons`, `comm`, `sensors`, `docked`, `alarm`, `fleet`, `destsystem`, `destx`, `desty`, `destcom`, `bookmark`, `battle`, `battleAction`, `jumptarget`, `autodeut`, `history`, `script`, `scriptexedata`, `oncommunicate`, `lock`, `visibility`, `onmove`, `respawn`) VALUES (2, -1, 'Frachter', 27, '0,0,0,0,50,0,0,0,0,0,0,0,0,0,0,0,0,0,', 1, 1, 0, 'noconsign', 50, 80, 0, 5000, 0, '', 100, 100, 100, 100, '', 0, null, 0, 0, 0, '', 0, null, 0, '', 1, '', NULL, NULL, NULL, NULL, NULL, NULL, NULL); 
  • db/updates.xml

    r91e50d3 rf082126  
    423423                ALTER TABLE user_moneytransfer CHANGE `count` `count` bigint(20) unsigned NOT NULL default '0'; 
    424424        ]]></update> 
     425        <update type="structure" datum="2007-10-28"><![CDATA[ 
     426                ALTER TABLE `ships` ADD `modules` INT AFTER `type`; 
     427                UPDATE ships SET modules=(SELECT id FROM ships_modules WHERE ships_modules.id=ships.id); 
     428        ]]></update> 
    425429</updates> 
  • src/net/driftingsouls/ds2/server/ships/Ship.java

    re5372a2 rf082126  
    3535import javax.persistence.ManyToOne; 
    3636import javax.persistence.OneToOne; 
    37 import javax.persistence.PrimaryKeyJoinColumn; 
    3837import javax.persistence.Table; 
    3938 
     
    7978import org.apache.commons.lang.StringUtils; 
    8079import org.apache.commons.lang.math.RandomUtils; 
    81 import org.hibernate.ObjectNotFoundException; 
    8280import org.hibernate.annotations.GenericGenerator; 
    8381import org.hibernate.annotations.Type; 
     
    9997        @GenericGenerator(name="ds-shipid", strategy = "net.driftingsouls.ds2.server.ships.ShipIdGenerator") 
    10098        private int id; 
    101         // HACK: Die Beziehung ist eigendlich optional, jedoch 
    102         // fuehrt dies dazu, dass Hibernate bei jedem Schiff pruefen muss, 
    103         // ob das Feld null ist oder nicht, was wiederum zu jeweils einer weiteren 
    104         // Query pro Schiff fuehrt. 
    105         // Durch das setzen von optional auf false verwendet Hibernate proxy-Objekte. 
    106         // Da der Sourcecode jedoch nur auf das Objekt zugreift, wenn sicher ist, dass es 
    107         // auch einen Moduleintrag dazu gibt (status-Feld), sollte dieser Hack (hoffentlich) 
    108         // unproblematisch sein. 
    109         @OneToOne(fetch=FetchType.LAZY,mappedBy="ship",optional=false) 
    110         @PrimaryKeyJoinColumn 
     99        @OneToOne(fetch=FetchType.LAZY) 
     100        @JoinColumn(name="modules", nullable=true) 
    111101        private ShipModules modules; 
    112102        @ManyToOne(fetch=FetchType.LAZY) 
     
    922912                } 
    923913 
    924                 try { 
    925                         ShipModules modules = (ShipModules)db.get(ShipModules.class, this.id); 
    926                         if( modules != null ) { 
    927                                 status.add("tblmodules"); 
    928                         } 
    929                 } 
    930                 catch( ObjectNotFoundException e ) { 
    931                         // Keine Modultabelle vorhanden - ignorieren 
    932                         // (Teil des Hacks um modules 
     914                ShipModules modules = (ShipModules)db.get(ShipModules.class, this.id); 
     915                if( modules != null ) { 
     916                        status.add("tblmodules"); 
    933917                } 
    934918 
     
    11181102                ShipModules shipModules = null; 
    11191103                if( this.status.indexOf("tblmodules") == -1 ) { 
    1120                         shipModules = new ShipModules(this.id); 
     1104                        shipModules = new ShipModules(this); 
    11211105                        db.persist(shipModules); 
    11221106 
     
    11261110                        else { 
    11271111                                this.status = "tblmodules";      
    1128                         }                        
     1112                        } 
     1113                         
     1114                        this.modules = shipModules; 
    11291115                } 
    11301116                else { 
     
    12721258                else { 
    12731259                        db.delete(shipModules); 
     1260                         
     1261                        this.modules = null; 
    12741262 
    12751263                        String[] status = StringUtils.split(this.status, ' '); 
  • src/net/driftingsouls/ds2/server/ships/ShipModules.java

    r390f9f1 rf082126  
    2626import javax.persistence.PrimaryKeyJoinColumn; 
    2727import javax.persistence.Table; 
    28  
    29 import net.driftingsouls.ds2.server.framework.ContextMap; 
    3028 
    3129/** 
     
    9593         * <p>Konstruktor</p> 
    9694         * Erstellt einen neuen Schiffsmoduleintrag fuer das angegebene Schiff 
    97          * @param id Die ID des Schiffes 
    98          */ 
    99         public ShipModules(int id) { 
    100                 this.id = id
    101                 this.ship = (Ship)ContextMap.getContext().getDB().get(Ship.class, id)
     95         * @param ship Das Schiff 
     96         */ 
     97        public ShipModules(Ship ship) { 
     98                this.id = ship.getId()
     99                this.ship = ship
    102100                this.flags = ""; 
    103101                this.weapons = "";