Changeset 7039b5daa7deebbc52c8a5569501ded48fc16df2

Show
Ignore:
Timestamp:
07/13/07 17:39:04 (1 year ago)
Author:
Christopher Jung <bktheg@web.de>
git-committer:
Christopher Jung <bktheg@web.de> 1184341144 +0200
git-parent:

[0aa707321195c645c29ce2074d0cdd0e0354685f]

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

Transaktionssystem geaendert

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • src/net/driftingsouls/ds2/server/tick/regular/BaseTick.java

    r7680662 r7039b5d  
    5858        @Override 
    5959        protected void prepare() { 
    60                 getDB().setFlushMode(FlushMode.MANUAL); 
     60                //getDB().setFlushMode(FlushMode.MANUAL); 
    6161                 
    6262                // Aktuelle Warenkurse fuer die Kommandozentrale laden 
     
    334334                        getDB().merge(base); 
    335335                } 
     336                if( !getDB().contains(base.getOwner()) ) { 
     337                        getDB().merge(base.getOwner()); 
     338                } 
    336339        } 
    337340 
     
    357360                log(""); 
    358361                 
    359                 int index = 0; 
    360                  
    361                 for( Iterator iter = bases.iterator(); iter.hasNext(); ) { 
    362                         Base base = (Base)iter.next(); 
    363                          
    364                         // Muessen ggf noch alte Userdaten geschrieben und neue geladen werden? 
    365                         if( base.getOwner().getID() != this.lastowner ) { 
    366                                 log(base.getOwner().getID()+":"); 
    367                                 if( this.pmcache.length() != 0 ) { 
    368                                         PM.send(getContext(),-1, this.lastowner, "Basis-Tick", this.pmcache.toString(),false); 
    369                                         this.pmcache.setLength(0); 
    370                                
    371                                                                  
    372                                 this.usercargo = new Cargo( Cargo.Type.STRING, base.getOwner().getCargo()); 
    373                        
    374                          
    375                         this.lastowner = base.getOwner().getID(); 
    376                         try {          
     362                try { 
     363                 
     364                       for( Iterator iter = bases.iterator(); iter.hasNext(); ) { 
     365                               Base base = (Base)iter.next(); 
     366                                
     367                               // Muessen ggf noch alte Userdaten geschrieben und neue geladen werden? 
     368                               if( base.getOwner().getID() != this.lastowner ) { 
     369                                       log(base.getOwner().getID()+":"); 
     370                                       if( this.pmcache.length() != 0 ) { 
     371                                               PM.send(getContext(),-1, this.lastowner, "Basis-Tick", this.pmcache.toString(),false); 
     372                                               this.pmcache.setLength(0); 
     373                                       
     374                                                                        
     375                                       this.usercargo = new Cargo( Cargo.Type.STRING, base.getOwner().getCargo()); 
     376                               
     377                                
     378                               this.lastowner = base.getOwner().getID(); 
     379                               
    377380                                // Nun wollen wir die Basis mal berechnen.... 
    378381                                this.tickBase(base); 
    379382                                base.getOwner().setCargo(this.usercargo.save()); 
    380                                  
    381                                 getDB().flush(); 
    382                                 getContext().commit(); 
    383                         } 
    384                         catch( Exception e ) { 
    385                                 getContext().rollback(); 
    386                                 getDB().clear(); 
    387                                  
    388                                 this.log("Base "+base.getID()+" failed: "+e); 
    389                                 e.printStackTrace(); 
    390                                 Common.mailThrowable(e, "BaseTick Exception", "Base: "+base.getID()); 
    391                                  
    392                                 // Im Fehlerfall noch einmal versuchen 
    393                                 try { 
    394                                         base = (Base)getDB().get(Base.class, base.getID()); 
    395                                         this.tickBase(base); 
    396                                         base.getOwner().setCargo(this.usercargo.save()); 
    397                                          
    398                                         getDB().flush(); 
    399                                         getContext().commit(); 
    400                                 } 
    401                                 catch( Exception f ) { 
    402                                         getContext().rollback(); 
    403                                         getDB().clear(); 
    404                                          
    405                                         this.log("#2 Base "+base.getID()+" failed: "+f); 
    406                                         f.printStackTrace(); 
    407                                         Common.mailThrowable(f, "BaseTick #2 Exception", "Base: "+base.getID()); 
    408                                 } 
    409                         } 
    410                         finally { 
     383 
    411384                                getDB().evict(base); 
    412385                        } 
    413386                         
    414                         if( index++ % 50 == 0 ) { 
    415                                 getDB().flush(); 
    416                                 getDB().clear(); 
    417                         } 
    418                 } 
    419                  
    420                 // ggf noch vorhandene Userdaten schreiben 
    421                 if( this.pmcache.length() != 0 ) { 
    422                         PM.send(getContext(),-1, this.lastowner, "Basis-Tick", this.pmcache.toString(), false); 
    423                         this.pmcache.setLength(0); 
    424                 } 
    425                  
    426                 // Die neuen GTU-Verkaufsstats schreiben 
    427                 for( Integer sys : this.gtustatslist.keySet() ) { 
    428                         Cargo gtustat = this.gtustatslist.get(sys); 
    429                         SQLResultRow statid = db.first("SELECT id FROM stats_verkaeufe WHERE tick='",this.tick,"' AND place='asti' AND system='",sys,"'"); 
    430                         if( statid.isEmpty() ) { 
    431                                 db.update("INSERT INTO stats_verkaeufe (tick,place,system,stats) VALUES (",this.tick,",'asti',",sys,",'",gtustat.save(),"')"); 
    432                         } 
    433                         else {           
    434                                 db.update("UPDATE stats_verkaeufe SET stats='",gtustat.save(),"' WHERE id='",statid,"'"); 
    435                         } 
     387                        // ggf noch vorhandene Userdaten schreiben 
     388                        if( this.pmcache.length() != 0 ) { 
     389                                PM.send(getContext(),-1, this.lastowner, "Basis-Tick", this.pmcache.toString(), false); 
     390                                this.pmcache.setLength(0); 
     391                        } 
     392                         
     393                        // Die neuen GTU-Verkaufsstats schreiben 
     394                        for( Integer sys : this.gtustatslist.keySet() ) { 
     395                                Cargo gtustat = this.gtustatslist.get(sys); 
     396                                SQLResultRow statid = db.first("SELECT id FROM stats_verkaeufe WHERE tick='",this.tick,"' AND place='asti' AND system='",sys,"'"); 
     397                                if( statid.isEmpty() ) { 
     398                                        db.update("INSERT INTO stats_verkaeufe (tick,place,system,stats) VALUES (",this.tick,",'asti',",sys,",'",gtustat.save(),"')"); 
     399                                } 
     400                                else {           
     401                                        db.update("UPDATE stats_verkaeufe SET stats='",gtustat.save(),"' WHERE id='",statid,"'"); 
     402                                } 
     403                        } 
     404                 
     405                } 
     406                catch( Exception e ) {                   
     407                        this.log("Base Tick failed: "+e); 
     408                        e.printStackTrace(); 
     409                        Common.mailThrowable(e, "BaseTick Exception", ""); 
    436410                } 
    437411                 
    438412                // User-Accs wieder entsperren 
    439413                unblock(0); 
    440                  
    441                 getDB().setFlushMode(FlushMode.AUTO); 
    442414        } 
    443415