Changeset f082126a9f1dc7b76a2f6e356719d06f76b9a94b
- Timestamp:
- 11/03/07 10:38:24 (1 year ago)
- git-parent:
- Files:
-
- db/tables/ships.sql (modified) (2 diffs)
- db/updates.xml (modified) (1 diff)
- src/net/driftingsouls/ds2/server/ships/Ship.java (modified) (7 diffs)
- src/net/driftingsouls/ds2/server/ships/ShipModules.java (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
db/tables/ships.sql
r144f38e rf082126 4 4 `name` varchar(50) NOT NULL default 'noname', 5 5 `type` int(11) NOT NULL default '0', 6 `modules` int(11), 6 7 `cargo` text NOT NULL, 7 8 `x` int(11) NOT NULL default '1', … … 56 57 ALTER TABLE ships ADD CONSTRAINT ships_fk_ship_fleets FOREIGN KEY (fleet) REFERENCES ship_fleets(id); 57 58 ALTER TABLE ships ADD CONSTRAINT ships_fk_battles FOREIGN KEY (battle) REFERENCES battles(id); 59 -- Keine Constraint fuer modules! 58 60 59 61 INSERT 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 423 423 ALTER TABLE user_moneytransfer CHANGE `count` `count` bigint(20) unsigned NOT NULL default '0'; 424 424 ]]></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> 425 429 </updates> src/net/driftingsouls/ds2/server/ships/Ship.java
re5372a2 rf082126 35 35 import javax.persistence.ManyToOne; 36 36 import javax.persistence.OneToOne; 37 import javax.persistence.PrimaryKeyJoinColumn;38 37 import javax.persistence.Table; 39 38 … … 79 78 import org.apache.commons.lang.StringUtils; 80 79 import org.apache.commons.lang.math.RandomUtils; 81 import org.hibernate.ObjectNotFoundException;82 80 import org.hibernate.annotations.GenericGenerator; 83 81 import org.hibernate.annotations.Type; … … 99 97 @GenericGenerator(name="ds-shipid", strategy = "net.driftingsouls.ds2.server.ships.ShipIdGenerator") 100 98 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) 111 101 private ShipModules modules; 112 102 @ManyToOne(fetch=FetchType.LAZY) … … 922 912 } 923 913 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"); 933 917 } 934 918 … … 1118 1102 ShipModules shipModules = null; 1119 1103 if( this.status.indexOf("tblmodules") == -1 ) { 1120 shipModules = new ShipModules(this .id);1104 shipModules = new ShipModules(this); 1121 1105 db.persist(shipModules); 1122 1106 … … 1126 1110 else { 1127 1111 this.status = "tblmodules"; 1128 } 1112 } 1113 1114 this.modules = shipModules; 1129 1115 } 1130 1116 else { … … 1272 1258 else { 1273 1259 db.delete(shipModules); 1260 1261 this.modules = null; 1274 1262 1275 1263 String[] status = StringUtils.split(this.status, ' '); src/net/driftingsouls/ds2/server/ships/ShipModules.java
r390f9f1 rf082126 26 26 import javax.persistence.PrimaryKeyJoinColumn; 27 27 import javax.persistence.Table; 28 29 import net.driftingsouls.ds2.server.framework.ContextMap;30 28 31 29 /** … … 95 93 * <p>Konstruktor</p> 96 94 * Erstellt einen neuen Schiffsmoduleintrag fuer das angegebene Schiff 97 * @param id Die ID des Schiffes98 */ 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; 102 100 this.flags = ""; 103 101 this.weapons = "";
