| 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 | |
|---|
| 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 | |
|---|
| 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", ""); |
|---|