Changeset fb878682f8828fd5291efd8c1bd70a39419ef685

Show
Ignore:
Timestamp:
08/18/07 14:09:23 (1 year ago)
Author:
Christopher Jung <bktheg@web.de>
git-committer:
Christopher Jung <bktheg@web.de> 1187438963 +0200
git-parent:

[e626046e9f98e3c6c6244e98898a9ff2d8ab1e7d]

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

Die ID eines Werftschlangeneintrags ist nun nicht mehr aus Position und Werft zusammengesetzt sondern ein kuenstlicher Schluessel

Files:

Legend:

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

    r89d279c rfb87868  
    11CREATE TABLE `werft_queues` ( 
    2   werft int NOT NULL, 
    3   `position` int NOT NULL, 
     2  `id` int(10) unsigned NOT NULL auto_increment, 
     3  `werft` int(11) NOT NULL, 
     4  `position` int(11) NOT NULL, 
    45  `building` int(11) default NULL, 
    56  `item` smallint(6) NOT NULL default '-1', 
     
    78  `flagschiff` tinyint(1) unsigned NOT NULL default '0', 
    89  `costsPerTick` varchar(300) NOT NULL default '0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,', 
    9   `energyPerTick` int NOT NULL default '0', 
    10   `slots` INT NOT NULL DEFAULT '1', 
    11   `scheduled` TINYINT( 1 ) NOT NULL DEFAULT '0', 
    12   PRIMARY KEY  (`werft`,`position`) 
    13 ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 
     10  `energyPerTick` int(11) NOT NULL default '0', 
     11  `slots` int(11) NOT NULL default '1', 
     12  `scheduled` tinyint(1) NOT NULL default '0', 
     13  PRIMARY KEY  (`id`), 
     14  UNIQUE KEY `queueentry` (`werft`,`position`), 
     15  KEY `werft_queues_fk_ship_types` (`building`), 
     16  KEY `werft` (`werft`) 
     17) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8; 
    1418 
    1519ALTER TABLE werft_queues ADD CONSTRAINT werft_queues_fk_werften FOREIGN KEY (werft) REFERENCES werften(id); 
  • db/updates.xml

    r9689aa5 rfb87868  
    377377                ALTER TABLE `werften` ADD `komplex` TINYINT( 1 ) NOT NULL DEFAULT '0'; 
    378378        ]]></update> 
     379        <update type="structure" datum="2007-08-18"><![CDATA[ 
     380                ALTER TABLE `werft_queues` ADD INDEX ( `werft` ); 
     381                ALTER TABLE `werft_queues` DROP PRIMARY KEY; 
     382                ALTER TABLE `werft_queues` ADD `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST; 
     383                ALTER TABLE `werft_queues` ADD UNIQUE `queueentry` ( `werft` , `position` ); 
     384        ]]></update> 
    379385</updates> 
  • src/net/driftingsouls/ds2/server/werften/WerftObject.java

    r9689aa5 rfb87868  
    9292        private boolean buildFlagschiff = false; 
    9393        private int type = 0; 
    94         @ManyToOne(fetch=FetchType.LAZY
     94        @ManyToOne(fetch=FetchType.EAGER
    9595        @JoinColumn(name="linkedWerft", nullable=true) 
    9696        private WerftKomplex linkedWerft = null; 
     
    118118        public WerftQueueEntry[] getScheduledQueueEntries() { 
    119119                org.hibernate.Session db = ContextMap.getContext().getDB(); 
    120                 List list = db.createQuery("from WerftQueueEntry where id.werft=? and scheduled=1 order by id.position") 
     120                List list = db.createQuery("from WerftQueueEntry where werft=? and scheduled=1 order by position") 
    121121                        .setInteger(0, this.getWerftID()) 
    122122                        .list(); 
     
    137137                org.hibernate.Session db = ContextMap.getContext().getDB(); 
    138138                 
    139                 return db.createQuery("from WerftQueueEntry where id.werft=?") 
     139                return db.createQuery("from WerftQueueEntry where werft=?") 
    140140                        .setInteger(0, this.getWerftID()) 
    141141                        .iterate().hasNext(); 
     
    157157                org.hibernate.Session db = ContextMap.getContext().getDB(); 
    158158                 
    159                 return ((Number)db.createQuery("select sum(slots) from WerftQueueEntry where id.werft=? and scheduled=1") 
     159                return ((Number)db.createQuery("select sum(slots) from WerftQueueEntry where werft=? and scheduled=1") 
    160160                        .setInteger(0, this.getWerftID()) 
    161161                        .iterate().next()).intValue(); 
     
    226226         */ 
    227227        protected void onFinishedBuildProcess(int shipid) { 
     228                this.entries = null; 
    228229                rescheduleQueue(); 
    229230        } 
     
    259260        public void clearQueue() { 
    260261                org.hibernate.Session db = ContextMap.getContext().getDB(); 
    261                 db.createQuery("delete from WerftQueueEntry where id.werft=?") 
     262                db.createQuery("delete from WerftQueueEntry where werft=?") 
    262263                        .setInteger(0, this.getWerftID()) 
    263264                        .executeUpdate(); 
     
    14211422                org.hibernate.Session db = ContextMap.getContext().getDB(); 
    14221423                 
    1423                 List queue = db.createQuery("from WerftQueueEntry where id.werft=? order by id.position asc") 
     1424                List queue = db.createQuery("from WerftQueueEntry where werft=? order by position asc") 
    14241425                        .setInteger(0, this.getWerftID()) 
    14251426                        .list(); 
     
    14421443         */ 
    14431444        public void cancelBuild(WerftQueueEntry entry) { 
    1444                 if( entry.getWerft() != this ) { 
     1445                if( entry.getWerft().getWerftID() != this.getWerftID() ) { 
    14451446                        throw new IllegalArgumentException("Das WerftQueue-Objekt gehoert nicht zu dieser Werft"); 
    14461447                } 
     
    14531454                db.delete(entry); 
    14541455                 
    1455                 db.createQuery("update WerftQueueEntry set id.position=id.position-1 where id.werft=? and id.position>?") 
    1456                         .setInteger(0, this.id
     1456                final Iterator entryIter = db.createQuery("from WerftQueueEntry where werft=? and position>? order by position") 
     1457                        .setEntity(0, entry.getWerft()
    14571458                        .setInteger(1, entry.getPosition()) 
    1458                         .executeUpdate(); 
     1459                        .iterate(); 
     1460                while( entryIter.hasNext() ) { 
     1461                        WerftQueueEntry aEntry = (WerftQueueEntry)entryIter.next(); 
     1462                        aEntry.setPosition(aEntry.getPosition()-1); 
     1463                } 
    14591464                 
    14601465                this.entries = null; 
     1466                this.rescheduleQueue(); 
    14611467        } 
    14621468         
     
    15111517                org.hibernate.Session db = ContextMap.getContext().getDB(); 
    15121518                 
    1513                 return (WerftQueueEntry)db.createQuery("from WerftQueueEntry where id.werft=? and id.position=?") 
     1519                return (WerftQueueEntry)db.createQuery("from WerftQueueEntry where werft=? and position=?") 
    15141520                        .setInteger(0, this.getWerftID()) 
    15151521                        .setInteger(1, position) 
  • src/net/driftingsouls/ds2/server/werften/WerftQueueEntry.java

    r27c1104 rfb87868  
    1919package net.driftingsouls.ds2.server.werften; 
    2020 
    21 import java.io.Serializable
     21import java.util.Iterator
    2222import java.util.List; 
    2323 
    2424import javax.persistence.Column; 
    25 import javax.persistence.Embeddable; 
    2625import javax.persistence.Entity; 
    2726import javax.persistence.FetchType; 
     27import javax.persistence.GeneratedValue; 
    2828import javax.persistence.Id; 
    2929import javax.persistence.JoinColumn; 
     
    3131import javax.persistence.Table; 
    3232import javax.persistence.Transient; 
    33  
    34 import org.hibernate.annotations.Type; 
    3533 
    3634import net.driftingsouls.ds2.server.ContextCommon; 
     
    4947import net.driftingsouls.ds2.server.ships.ShipTypeData; 
    5048 
     49import org.hibernate.annotations.Type; 
     50 
    5151/** 
    5252 * Ein Eintrag in der WerftQueue 
     
    6262        @Transient 
    6363        public final ContextLocalMessage MESSAGE = new ContextLocalMessage(); 
    64          
    65         /** 
    66          * Der Primaerschluessel eines WerftQueue-Eintrags 
    67          * 
    68          */ 
    69         @Embeddable 
    70         public static class Key implements Serializable { 
    71                 private static final long serialVersionUID = 3383104836435402919L; 
    72                  
    73                 private int werft; 
    74                 private int position; 
    75                  
    76                 /** 
    77                  * Konstruktor 
    78                  * 
    79                  */ 
    80                 public Key() { 
    81                         // EMPTY 
    82                 } 
    83                  
    84                 /** 
    85                  * Erstellt einen neuen Schluessel 
    86                  * @param werft Die Werft 
    87                  * @param position Die Position 
    88                  */ 
    89                 public Key(WerftObject werft, int position) { 
    90                         this.werft = werft.getWerftID(); 
    91                         this.position = position; 
    92                 } 
    93  
    94                 /** 
    95                  * Gibt die Position zurueck 
    96                  * @return Die Position 
    97                  */ 
    98                 public int getPosition() { 
    99                         return position; 
    100                 } 
    101  
    102                 /** 
    103                  * Gibt die Werft zurueck 
    104                  * @return Die Werft 
    105                  */ 
    106                 public WerftObject getWerft() { 
    107                         return (WerftObject)ContextMap.getContext().getDB().get(WerftObject.class,werft); 
    108                 } 
    109  
    110                 @Override 
    111                 public int hashCode() { 
    112                         int result = 1; 
    113                         result = 31 * result + position; 
    114                         result = 31 * result + werft; 
    115                          
    116                         return result; 
    117                 } 
    118  
    119                 @Override 
    120                 public boolean equals(Object obj) { 
    121                         if( this == obj ) { 
    122                                 return true; 
    123                         } 
    124                         if( (obj == null) || (getClass() != obj.getClass()) ) {  
    125                                 return false; 
    126                         } 
    127                          
    128                         final Key other = (Key)obj; 
    129                         if( position != other.position ) { 
    130                                 return false; 
    131                         } 
    132                         else if( werft != other.werft ) { 
    133                                 return false; 
    134                         } 
    135                         return true; 
    136                 } 
    137         } 
    138          
    139         @Id 
    140         private Key id; 
     64                 
     65        @Id @GeneratedValue 
     66        private int id; 
     67        @ManyToOne(fetch=FetchType.EAGER) 
     68        @JoinColumn(name="werft", nullable=false) 
     69        private WerftObject werft; 
     70        private int position; 
    14171        @ManyToOne(fetch=FetchType.LAZY) 
    14272        @JoinColumn(name="building", nullable=false) 
     
    171101         */ 
    172102        public WerftQueueEntry(WerftObject werft, ShipType building, int remaining, int slots) { 
    173                 this.id = new Key(werft, getNextEmptyPosition(werft)); 
     103                this.werft = werft; 
     104                this.position = getNextEmptyPosition(werft); 
    174105                this.building = building; 
    175106                this.buildItem = -1; 
     
    195126                org.hibernate.Session db = ContextMap.getContext().getDB(); 
    196127                 
    197                 Integer position = (Integer)db.createQuery("select max(wq.id.position) from WerftQueueEntry as wq where wq.id.werft=?") 
     128                Integer position = (Integer)db.createQuery("select max(wq.position) from WerftQueueEntry as wq where wq.werft=?") 
    198129                        .setInteger(0, werft.getWerftID()) 
    199130                        .iterate().next(); 
     
    203134                } 
    204135                return position+1; 
     136        } 
     137         
     138        /** 
     139         * Gibt die Id zurueck 
     140         * @return Die Id 
     141         */ 
     142        public int getId() { 
     143                return this.id; 
    205144        } 
    206145         
     
    228167         */ 
    229168        public WerftObject getWerft() { 
    230                 return this.id.getWerft()
     169                return this.werft
    231170        } 
    232171         
     
    236175         */ 
    237176        public int getPosition() { 
    238                 return this.id.getPosition(); 
    239         } 
    240  
     177                return this.position; 
     178        } 
     179 
     180        /** 
     181         * Setzt die Position des Eintrags innerhalb der Bauschlange. Jede Position 
     182         * darf nur einmal vergeben sein. 
     183         * @param position Die Position innerhalb der Bauschlange 
     184         */ 
     185        public void setPosition(int position) { 
     186                this.position = position; 
     187        } 
     188         
    241189        /** 
    242190         * Gibt zurueck, ob es sich bei dem Bau um ein Flagschiff handelt 
     
    386334                ShipTypeData shipd = this.getBuildShipType(); 
    387335 
    388                 WerftObject werft = id.getWerft(); 
    389                 int x = werft.getX(); 
    390                 int y = werft.getY(); 
    391                 int system = werft.getSystem(); 
     336                int x = this.werft.getX(); 
     337                int y = this.werft.getY(); 
     338                int system = this.werft.getSystem(); 
    392339                                         
    393340                Cargo cargo = new Cargo(); 
    394                 User auser = werft.getOwner(); 
     341                User auser = this.werft.getOwner(); 
    395342                 
    396343                String currentTime = Common.getIngameTime(context.get(ContextCommon.class).getTick()); 
     
    428375                // Item benutzen 
    429376                if( this.getRequiredItem() > -1 ) { 
    430                         cargo = werft.getCargo(true); 
     377                        cargo = this.werft.getCargo(true); 
    431378                        List<ItemCargoEntry> itemlist = cargo.getItem(this.getRequiredItem()); 
    432379                        boolean ok = false; 
     
    439386                         
    440387                        if( !ok ) { 
    441                                 User user = werft.getOwner(); 
     388                                User user = this.werft.getOwner(); 
    442389                                 
    443390                                Cargo allyitems = null; 
     
    468415                                         
    469416                                        if( source.equals("local") ) { 
    470                                                 werft.setCargo(cargo, true); 
     417                                                this.werft.setCargo(cargo, true); 
    471418                                        } 
    472419                                        else { 
    473420                                                db.createQuery("update Ally as a set a.items=? where a.id=?") 
    474421                                                        .setString(0, allyitems.getData(Cargo.Type.ITEMSTRING)) 
    475                                                         .setInteger(1, werft.getOwner().getAlly().getId()) 
     422                                                        .setInteger(1, this.werft.getOwner().getAlly().getId()) 
    476423                                                        .executeUpdate(); 
    477424                                        } 
     
    483430                 
    484431                if( this.isBuildFlagschiff() ) { 
    485                         werft.setBuildFlagschiff(false); 
     432                        this.werft.setBuildFlagschiff(false); 
    486433                } 
    487434                 
    488435                db.delete(this); 
    489                 db.createQuery("update WerftQueueEntry set id.position=id.position-1 where id.werft=?") 
    490                         .setInteger(0, werft.getWerftID()) 
    491                         .executeUpdate(); 
    492                  
    493                 werft.onFinishedBuildProcess(id); 
     436                final Iterator entryIter = db.createQuery("from WerftQueueEntry where werft=? and position>? order by position") 
     437                        .setEntity(0, this.werft) 
     438                        .setInteger(1, this.position) 
     439                        .iterate(); 
     440                while( entryIter.hasNext() ) { 
     441                        WerftQueueEntry entry = (WerftQueueEntry)entryIter.next(); 
     442                        entry.setPosition(entry.getPosition()-1); 
     443                } 
     444         
     445                this.werft.onFinishedBuildProcess(id); 
    494446                 
    495447                return id; 
     
    507459                        return true; 
    508460                } 
    509                  
    510                 WerftObject werft = id.getWerft(); 
    511                  
     461                         
    512462                // Pruefen, ob ein evt notwendiges Item vorhanden ist 
    513463                if( this.getRequiredItem() > -1 ) { 
    514                         Cargo cargo = new Cargo(werft.getCargo(true)); 
    515                         User user = werft.getOwner(); 
     464                        Cargo cargo = new Cargo(this.werft.getCargo(true)); 
     465                        User user = this.werft.getOwner(); 
    516466                         
    517467                        if( user.getAlly() != null ) { 
     
    528478                // Pruefen, ob die anfallenden Baukosten bezahlt werden koennen 
    529479                if( !this.getCostsPerTick().isEmpty() ) { 
    530                         Cargo cargo = new Cargo(werft.getCargo(false)); 
     480                        Cargo cargo = new Cargo(this.werft.getCargo(false)); 
    531481                        ResourceList reslist = this.costsPerTick.compare(cargo, false); 
    532482                        for( ResourceEntry res : reslist ) { 
     
    538488                 
    539489                if( this.getEnergyPerTick() != 0 ) { 
    540                         if( werft.getEnergy() < this.getEnergyPerTick() ) { 
     490                        if( this.werft.getEnergy() < this.getEnergyPerTick() ) { 
    541491                                return false; 
    542492                        } 
     
    547497         
    548498        private void substractBuildCosts() { 
    549                 WerftObject werft = id.getWerft(); 
    550                  
    551499                if( !this.getCostsPerTick().isEmpty() ) {        
    552                         Cargo cargo = werft.getCargo(false); 
     500                        Cargo cargo = this.werft.getCargo(false); 
    553501                        cargo.substractCargo(this.getCostsPerTick()); 
    554                         werft.setCargo(cargo, false); 
     502                        this.werft.setCargo(cargo, false); 
    555503                } 
    556504                 
    557505                if( this.getEnergyPerTick() != 0 ) { 
    558                         werft.setEnergy(werft.getEnergy() - this.getEnergyPerTick()); 
     506                        this.werft.setEnergy(this.werft.getEnergy() - this.getEnergyPerTick()); 
    559507                } 
    560508        }