XML dumps code clean-up
* Moved empire summary generator to a separate package, moved all empire summary data classes to a sub-package of the former * All row mappers for empire summary contents have been moved to separate classes with default access * Added comments to the component and to the mapper classes
This commit is contained in:
parent
2adc754a2c
commit
426a1fdfd4
24 changed files with 557 additions and 254 deletions
|
@ -1,240 +0,0 @@
|
|||
package com.deepclone.lw.beans.bt;
|
||||
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
|
||||
import com.deepclone.lw.beans.bt.esdata.*;
|
||||
import com.deepclone.lw.interfaces.bt.EmpireSummary;
|
||||
import com.thoughtworks.xstream.XStream;
|
||||
|
||||
|
||||
|
||||
public class EmpireSummaryBean
|
||||
implements EmpireSummary
|
||||
{
|
||||
|
||||
private JdbcTemplate dTemplate;
|
||||
|
||||
private final XStream xStream;
|
||||
|
||||
private final RowMapper< DebugInformation > mMainInfo;
|
||||
private final RowMapper< ResearchInformation > mResearch;
|
||||
private final RowMapper< PlanetInformation > mPlanet;
|
||||
private final RowMapper< QueueItemInformation > mQueueItem;
|
||||
private final RowMapper< BuildingsInformation > mBuildings;
|
||||
private final RowMapper< FleetInformation > mFleet;
|
||||
private final RowMapper< ShipsInformation > mShips;
|
||||
|
||||
|
||||
public EmpireSummaryBean( )
|
||||
{
|
||||
this.xStream = new XStream( );
|
||||
this.xStream.processAnnotations( new Class< ? >[] {
|
||||
AccountInformation.class , AllianceInformation.class , BuildingsInformation.class ,
|
||||
DebugInformation.class , EmpireInformation.class , FleetInformation.class , MovementInformation.class ,
|
||||
PlanetInformation.class , QueueInformation.class , QueueItemInformation.class ,
|
||||
ResearchInformation.class , ShipsInformation.class , SystemInformation.class
|
||||
} );
|
||||
|
||||
this.mMainInfo = new RowMapper< DebugInformation >( ) {
|
||||
@Override
|
||||
public DebugInformation mapRow( ResultSet rs , int rowNum )
|
||||
throws SQLException
|
||||
{
|
||||
DebugInformation di = new DebugInformation( );
|
||||
|
||||
di.getSystem( ).setNextTick( rs.getLong( "next_tick" ) );
|
||||
di.getSystem( ).setCurrentTick( (Long) rs.getObject( "current_tick" ) );
|
||||
|
||||
di.getAccount( ).setId( rs.getInt( "account_id" ) );
|
||||
di.getAccount( ).setAddress( rs.getString( "account_address" ) );
|
||||
di.getAccount( ).setGameCredits( rs.getInt( "game_credits" ) );
|
||||
di.getAccount( ).setStatus( rs.getString( "account_status" ) );
|
||||
di.getAccount( ).setLanguage( rs.getString( "account_language" ) );
|
||||
|
||||
di.getEmpire( ).setId( rs.getInt( "empire_id" ) );
|
||||
di.getEmpire( ).setName( rs.getString( "empire_name" ) );
|
||||
di.getEmpire( ).setCash( rs.getDouble( "cash" ) );
|
||||
|
||||
String allianceTag = rs.getString( "alliance_tag" );
|
||||
if ( allianceTag != null ) {
|
||||
AllianceInformation alliance = new AllianceInformation( );
|
||||
alliance.setId( rs.getInt( "alliance_id" ) );
|
||||
alliance.setTag( allianceTag );
|
||||
alliance.setPending( rs.getBoolean( "alliance_pending" ) );
|
||||
di.getEmpire( ).setAlliance( alliance );
|
||||
}
|
||||
|
||||
return di;
|
||||
}
|
||||
};
|
||||
this.mResearch = new RowMapper< ResearchInformation >( ) {
|
||||
@Override
|
||||
public ResearchInformation mapRow( ResultSet rs , int rowNum )
|
||||
throws SQLException
|
||||
{
|
||||
ResearchInformation ri = new ResearchInformation( );
|
||||
ri.setId( rs.getInt( "line_id" ) );
|
||||
ri.setCurrentLevel( rs.getInt( "level" ) );
|
||||
ri.setLevelName( rs.getString( "name" ) );
|
||||
ri.setAccumulated( rs.getDouble( "accumulated" ) );
|
||||
return ri;
|
||||
}
|
||||
};
|
||||
this.mPlanet = new RowMapper< PlanetInformation >( ) {
|
||||
@Override
|
||||
public PlanetInformation mapRow( ResultSet rs , int rowNum )
|
||||
throws SQLException
|
||||
{
|
||||
PlanetInformation pi = new PlanetInformation( );
|
||||
pi.setId( rs.getInt( "planet_id" ) );
|
||||
pi.setPopulation( rs.getDouble( "population" ) );
|
||||
pi.setCurrentHappiness( rs.getDouble( "current_happiness" ) );
|
||||
pi.setTargetHappiness( rs.getDouble( "target_happiness" ) );
|
||||
pi.getCivilianQueue( ).setAccMoney( rs.getDouble( "civ_money" ) );
|
||||
pi.getCivilianQueue( ).setAccWork( rs.getDouble( "civ_work" ) );
|
||||
pi.getMilitaryQueue( ).setAccMoney( rs.getDouble( "mil_money" ) );
|
||||
pi.getMilitaryQueue( ).setAccWork( rs.getDouble( "mil_work" ) );
|
||||
return pi;
|
||||
}
|
||||
};
|
||||
this.mQueueItem = new RowMapper< QueueItemInformation >( ) {
|
||||
@Override
|
||||
public QueueItemInformation mapRow( ResultSet rs , int rowNum )
|
||||
throws SQLException
|
||||
{
|
||||
QueueItemInformation qii = new QueueItemInformation( );
|
||||
qii.setPlanetId( rs.getInt( "planet_id" ) );
|
||||
qii.setMilitary( rs.getBoolean( "military" ) );
|
||||
qii.setId( rs.getInt( "item_id" ) );
|
||||
qii.setName( rs.getString( "item_name" ) );
|
||||
qii.setDestroy( rs.getBoolean( "destroy" ) );
|
||||
qii.setAmount( rs.getInt( "amount" ) );
|
||||
return qii;
|
||||
}
|
||||
};
|
||||
this.mBuildings = new RowMapper< BuildingsInformation >( ) {
|
||||
@Override
|
||||
public BuildingsInformation mapRow( ResultSet rs , int rowNum )
|
||||
throws SQLException
|
||||
{
|
||||
BuildingsInformation bi = new BuildingsInformation( );
|
||||
bi.setPlanetId( rs.getInt( "planet_id" ) );
|
||||
bi.setId( rs.getInt( "building_id" ) );
|
||||
bi.setName( rs.getString( "building_name" ) );
|
||||
bi.setAmount( rs.getInt( "amount" ) );
|
||||
bi.setDamage( rs.getDouble( "damage" ) );
|
||||
return bi;
|
||||
}
|
||||
};
|
||||
this.mFleet = new RowMapper< FleetInformation >( ) {
|
||||
@Override
|
||||
public FleetInformation mapRow( ResultSet rs , int rowNum )
|
||||
throws SQLException
|
||||
{
|
||||
FleetInformation fi = new FleetInformation( );
|
||||
fi.setId( rs.getLong( "fleet_id" ) );
|
||||
fi.setName( rs.getString( "fleet_name" ) );
|
||||
fi.setStatus( rs.getString( "status" ) );
|
||||
fi.setAttacking( rs.getBoolean( "attacking" ) );
|
||||
fi.setLocationId( rs.getInt( "location_id" ) );
|
||||
fi.setLocationName( rs.getString( "location_name" ) );
|
||||
|
||||
Integer sourceId = (Integer) rs.getObject( "source_id" );
|
||||
if ( sourceId != null ) {
|
||||
MovementInformation mi = new MovementInformation( );
|
||||
mi.setSourceId( sourceId );
|
||||
mi.setSourceName( rs.getString( "source_name" ) );
|
||||
mi.setTimeLeft( rs.getInt( "time_left" ) );
|
||||
mi.setStateTimeLeft( rs.getInt( "state_time_left" ) );
|
||||
mi.setNearId( (Integer) rs.getObject( "ref_point_id" ) );
|
||||
mi.setNearName( rs.getString( "ref_point_name" ) );
|
||||
mi.setOutwards( (Boolean) rs.getObject( "outwards" ) );
|
||||
mi.setPastRefPoint( (Boolean) rs.getObject( "past_ref_point" ) );
|
||||
mi.setStartX( (Float) rs.getObject( "start_x" ) );
|
||||
mi.setStartY( (Float) rs.getObject( "start_y" ) );
|
||||
fi.setMovement( mi );
|
||||
}
|
||||
|
||||
return fi;
|
||||
}
|
||||
};
|
||||
this.mShips = new RowMapper< ShipsInformation >( ) {
|
||||
@Override
|
||||
public ShipsInformation mapRow( ResultSet rs , int rowNum )
|
||||
throws SQLException
|
||||
{
|
||||
ShipsInformation si = new ShipsInformation( );
|
||||
si.setFleetId( rs.getLong( "fleet_id" ) );
|
||||
si.setId( rs.getInt( "ship_id" ) );
|
||||
si.setName( rs.getString( "ship_name" ) );
|
||||
si.setAmount( rs.getInt( "amount" ) );
|
||||
si.setDamage( rs.getDouble( "damage" ) );
|
||||
return si;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@Autowired( required = true )
|
||||
public void setDataSource( DataSource dataSource )
|
||||
{
|
||||
this.dTemplate = new JdbcTemplate( dataSource );
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getSummary( int empireId )
|
||||
{
|
||||
String sql = "SELECT * FROM bugs.dump_main_view WHERE empire_id = ?";
|
||||
DebugInformation di = this.dTemplate.queryForObject( sql , this.mMainInfo , empireId );
|
||||
|
||||
sql = "SELECT * FROM bugs.dump_research_view WHERE empire_id = ?";
|
||||
for ( ResearchInformation ri : this.dTemplate.query( sql , this.mResearch , empireId ) ) {
|
||||
di.getResearch( ).add( ri );
|
||||
}
|
||||
|
||||
sql = "SELECT * FROM bugs.dump_planets_view WHERE empire_id = ?";
|
||||
Map< Integer , PlanetInformation > planets = new HashMap< Integer , PlanetInformation >( );
|
||||
for ( PlanetInformation pi : this.dTemplate.query( sql , this.mPlanet , empireId ) ) {
|
||||
di.getPlanets( ).add( pi );
|
||||
planets.put( pi.getId( ) , pi );
|
||||
}
|
||||
|
||||
sql = "SELECT * FROM bugs.dump_queues_view WHERE empire_id = ? ORDER BY queue_order";
|
||||
for ( QueueItemInformation qii : this.dTemplate.query( sql , this.mQueueItem , empireId ) ) {
|
||||
PlanetInformation pi = planets.get( qii.getPlanetId( ) );
|
||||
QueueInformation qi = ( qii.isMilitary( ) ? pi.getMilitaryQueue( ) : pi.getCivilianQueue( ) );
|
||||
qi.getItems( ).add( qii );
|
||||
}
|
||||
|
||||
sql = "SELECT * FROM bugs.dump_buildings_view WHERE empire_id = ?";
|
||||
for ( BuildingsInformation bi : this.dTemplate.query( sql , this.mBuildings , empireId ) ) {
|
||||
planets.get( bi.getPlanetId( ) ).getBuildings( ).add( bi );
|
||||
}
|
||||
|
||||
sql = "SELECT * FROM bugs.dump_fleets_view WHERE empire_id = ?";
|
||||
Map< Long , FleetInformation > fleets = new HashMap< Long , FleetInformation >( );
|
||||
for ( FleetInformation fi : this.dTemplate.query( sql , this.mFleet , empireId ) ) {
|
||||
di.getFleets( ).add( fi );
|
||||
fleets.put( fi.getId( ) , fi );
|
||||
}
|
||||
|
||||
sql = "SELECT * FROM bugs.dump_ships_view WHERE empire_id = ?";
|
||||
for ( ShipsInformation si : this.dTemplate.query( sql , this.mShips , empireId ) ) {
|
||||
fleets.get( si.getFleetId( ) ).getShips( ).add( si );
|
||||
}
|
||||
|
||||
return this.xStream.toXML( di );
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
package com.deepclone.lw.beans.bt.es;
|
||||
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
|
||||
import com.deepclone.lw.beans.bt.es.data.BuildingsInformation;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Building information row mapper
|
||||
*
|
||||
* <p>
|
||||
* Map rows from <code>bugs.dump_buildings_view</code> into {@link BuildingsInformation} instances.
|
||||
*
|
||||
* @author <a href="mailto:tseeker@legacyworlds.com">E. Benoît</a>
|
||||
*
|
||||
*/
|
||||
final class BuildingsInformationMapper
|
||||
implements RowMapper< BuildingsInformation >
|
||||
{
|
||||
|
||||
/**
|
||||
* Map a row from <code>bugs.dump_buildings_view</code>
|
||||
*
|
||||
* <p>
|
||||
* Generate and initialise a {@link BuildingsInformation} instance using the row's fields.
|
||||
*/
|
||||
@Override
|
||||
public BuildingsInformation mapRow( ResultSet rs , int rowNum )
|
||||
throws SQLException
|
||||
{
|
||||
BuildingsInformation bi = new BuildingsInformation( );
|
||||
bi.setPlanetId( rs.getInt( "planet_id" ) );
|
||||
bi.setId( rs.getInt( "building_id" ) );
|
||||
bi.setName( rs.getString( "building_name" ) );
|
||||
bi.setAmount( rs.getInt( "amount" ) );
|
||||
bi.setDamage( rs.getDouble( "damage" ) );
|
||||
return bi;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
package com.deepclone.lw.beans.bt.es;
|
||||
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
|
||||
import com.deepclone.lw.beans.bt.es.data.AllianceInformation;
|
||||
import com.deepclone.lw.beans.bt.es.data.DebugInformation;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Top-level empire summary row mapper
|
||||
*
|
||||
* <p>
|
||||
* This class maps an entry from the database's main empire summary view,
|
||||
* <code>bugs.dump_main_view</code>, into a top-level {@link DebugInformation} instance.
|
||||
*
|
||||
* @author <a href="mailto:tseeker@legacyworlds.com">E. Benoît</a>
|
||||
*
|
||||
*/
|
||||
final class DebugInformationMapper
|
||||
implements RowMapper< DebugInformation >
|
||||
{
|
||||
/**
|
||||
* Map a row from <code>bugs.dump_main_view</code> into a {@link DebugInformation} instance
|
||||
*
|
||||
* <p>
|
||||
* Converts the row into a {@link DebugInformation} instance containing system information,
|
||||
* account information and empire information. If the row contains alliance information, add an
|
||||
* {@link AllianceInformation} record to the empire information.
|
||||
*/
|
||||
@Override
|
||||
public DebugInformation mapRow( ResultSet rs , int rowNum )
|
||||
throws SQLException
|
||||
{
|
||||
DebugInformation di = new DebugInformation( );
|
||||
|
||||
di.getSystem( ).setNextTick( rs.getLong( "next_tick" ) );
|
||||
di.getSystem( ).setCurrentTick( (Long) rs.getObject( "current_tick" ) );
|
||||
|
||||
di.getAccount( ).setId( rs.getInt( "account_id" ) );
|
||||
di.getAccount( ).setAddress( rs.getString( "account_address" ) );
|
||||
di.getAccount( ).setGameCredits( rs.getInt( "game_credits" ) );
|
||||
di.getAccount( ).setStatus( rs.getString( "account_status" ) );
|
||||
di.getAccount( ).setLanguage( rs.getString( "account_language" ) );
|
||||
|
||||
di.getEmpire( ).setId( rs.getInt( "empire_id" ) );
|
||||
di.getEmpire( ).setName( rs.getString( "empire_name" ) );
|
||||
di.getEmpire( ).setCash( rs.getDouble( "cash" ) );
|
||||
|
||||
String allianceTag = rs.getString( "alliance_tag" );
|
||||
if ( allianceTag != null ) {
|
||||
AllianceInformation alliance = new AllianceInformation( );
|
||||
alliance.setId( rs.getInt( "alliance_id" ) );
|
||||
alliance.setTag( allianceTag );
|
||||
alliance.setPending( rs.getBoolean( "alliance_pending" ) );
|
||||
di.getEmpire( ).setAlliance( alliance );
|
||||
}
|
||||
|
||||
return di;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,161 @@
|
|||
package com.deepclone.lw.beans.bt.es;
|
||||
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
|
||||
import com.deepclone.lw.beans.bt.es.data.AccountInformation;
|
||||
import com.deepclone.lw.beans.bt.es.data.AllianceInformation;
|
||||
import com.deepclone.lw.beans.bt.es.data.BuildingsInformation;
|
||||
import com.deepclone.lw.beans.bt.es.data.DebugInformation;
|
||||
import com.deepclone.lw.beans.bt.es.data.EmpireInformation;
|
||||
import com.deepclone.lw.beans.bt.es.data.FleetInformation;
|
||||
import com.deepclone.lw.beans.bt.es.data.MovementInformation;
|
||||
import com.deepclone.lw.beans.bt.es.data.PlanetInformation;
|
||||
import com.deepclone.lw.beans.bt.es.data.QueueInformation;
|
||||
import com.deepclone.lw.beans.bt.es.data.QueueItemInformation;
|
||||
import com.deepclone.lw.beans.bt.es.data.ResearchInformation;
|
||||
import com.deepclone.lw.beans.bt.es.data.ShipsInformation;
|
||||
import com.deepclone.lw.beans.bt.es.data.SystemInformation;
|
||||
import com.deepclone.lw.interfaces.bt.EmpireSummary;
|
||||
import com.thoughtworks.xstream.XStream;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Empire XML summary generator
|
||||
*
|
||||
* <p>
|
||||
* This component is used by the bug tracking system to generate XML dumps of an empire's state. It
|
||||
* reads the necessary data from the database, convert it to XML dump record classes then serialises
|
||||
* the whole thing through XStream.
|
||||
*
|
||||
* @author <a href="mailto:tseeker@legacyworlds.com">E. Benoît</a>
|
||||
*/
|
||||
public class EmpireSummaryBean
|
||||
implements EmpireSummary
|
||||
{
|
||||
/** JDBC access interface */
|
||||
private JdbcTemplate dTemplate;
|
||||
|
||||
/** XStream instance used to serialise XML dumps */
|
||||
private final XStream xStream;
|
||||
|
||||
/** Top-level row mapper */
|
||||
private final DebugInformationMapper mMainInfo;
|
||||
|
||||
/** Empire research row mapper */
|
||||
private final ResearchInformationMapper mResearch;
|
||||
|
||||
/** Empire-owned planet row mapper */
|
||||
private final PlanetInformationMapper mPlanet;
|
||||
|
||||
/** Planet construction queue item row mapper */
|
||||
private final QueueItemInformationMapper mQueueItem;
|
||||
|
||||
/** Planet buildings information mapper */
|
||||
private final BuildingsInformationMapper mBuildings;
|
||||
|
||||
/** Fleet information row mapper */
|
||||
private final FleetInformationMapper mFleet;
|
||||
|
||||
/** Fleet ships row mapper */
|
||||
private final ShipsInformationMapper mShips;
|
||||
|
||||
|
||||
/**
|
||||
* Set up the {@link XStream} instance that generates the dumps as well as the necessary row
|
||||
* mappers.
|
||||
*/
|
||||
public EmpireSummaryBean( )
|
||||
{
|
||||
this.xStream = new XStream( );
|
||||
this.xStream.processAnnotations( new Class< ? >[] {
|
||||
AccountInformation.class , AllianceInformation.class , BuildingsInformation.class ,
|
||||
DebugInformation.class , EmpireInformation.class , FleetInformation.class , MovementInformation.class ,
|
||||
PlanetInformation.class , QueueInformation.class , QueueItemInformation.class ,
|
||||
ResearchInformation.class , ShipsInformation.class , SystemInformation.class
|
||||
} );
|
||||
|
||||
this.mMainInfo = new DebugInformationMapper( );
|
||||
this.mResearch = new ResearchInformationMapper( );
|
||||
this.mPlanet = new PlanetInformationMapper( );
|
||||
this.mQueueItem = new QueueItemInformationMapper( );
|
||||
this.mBuildings = new BuildingsInformationMapper( );
|
||||
this.mFleet = new FleetInformationMapper( );
|
||||
this.mShips = new ShipsInformationMapper( );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Dependency injector that sets the data source
|
||||
*
|
||||
* @param dataSource
|
||||
* the data source
|
||||
*/
|
||||
@Autowired( required = true )
|
||||
public void setDataSource( DataSource dataSource )
|
||||
{
|
||||
this.dTemplate = new JdbcTemplate( dataSource );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generate an empire's XML summary
|
||||
*
|
||||
* <p>
|
||||
* Retrieve all information from the database, convert that information into XML dump record
|
||||
* instances through row mappers, then convert the top-level record into XML using the
|
||||
* component's {@link XStream} instance.
|
||||
*/
|
||||
@Override
|
||||
public String getSummary( int empireId )
|
||||
{
|
||||
String sql = "SELECT * FROM bugs.dump_main_view WHERE empire_id = ?";
|
||||
DebugInformation di = this.dTemplate.queryForObject( sql , this.mMainInfo , empireId );
|
||||
|
||||
sql = "SELECT * FROM bugs.dump_research_view WHERE empire_id = ?";
|
||||
for ( ResearchInformation ri : this.dTemplate.query( sql , this.mResearch , empireId ) ) {
|
||||
di.getResearch( ).add( ri );
|
||||
}
|
||||
|
||||
sql = "SELECT * FROM bugs.dump_planets_view WHERE empire_id = ?";
|
||||
Map< Integer , PlanetInformation > planets = new HashMap< Integer , PlanetInformation >( );
|
||||
for ( PlanetInformation pi : this.dTemplate.query( sql , this.mPlanet , empireId ) ) {
|
||||
di.getPlanets( ).add( pi );
|
||||
planets.put( pi.getId( ) , pi );
|
||||
}
|
||||
|
||||
sql = "SELECT * FROM bugs.dump_queues_view WHERE empire_id = ? ORDER BY queue_order";
|
||||
for ( QueueItemInformation qii : this.dTemplate.query( sql , this.mQueueItem , empireId ) ) {
|
||||
PlanetInformation pi = planets.get( qii.getPlanetId( ) );
|
||||
QueueInformation qi = ( qii.isMilitary( ) ? pi.getMilitaryQueue( ) : pi.getCivilianQueue( ) );
|
||||
qi.getItems( ).add( qii );
|
||||
}
|
||||
|
||||
sql = "SELECT * FROM bugs.dump_buildings_view WHERE empire_id = ?";
|
||||
for ( BuildingsInformation bi : this.dTemplate.query( sql , this.mBuildings , empireId ) ) {
|
||||
planets.get( bi.getPlanetId( ) ).getBuildings( ).add( bi );
|
||||
}
|
||||
|
||||
sql = "SELECT * FROM bugs.dump_fleets_view WHERE empire_id = ?";
|
||||
Map< Long , FleetInformation > fleets = new HashMap< Long , FleetInformation >( );
|
||||
for ( FleetInformation fi : this.dTemplate.query( sql , this.mFleet , empireId ) ) {
|
||||
di.getFleets( ).add( fi );
|
||||
fleets.put( fi.getId( ) , fi );
|
||||
}
|
||||
|
||||
sql = "SELECT * FROM bugs.dump_ships_view WHERE empire_id = ?";
|
||||
for ( ShipsInformation si : this.dTemplate.query( sql , this.mShips , empireId ) ) {
|
||||
fleets.get( si.getFleetId( ) ).getShips( ).add( si );
|
||||
}
|
||||
|
||||
return this.xStream.toXML( di );
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
package com.deepclone.lw.beans.bt.es;
|
||||
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
|
||||
import com.deepclone.lw.beans.bt.es.data.FleetInformation;
|
||||
import com.deepclone.lw.beans.bt.es.data.MovementInformation;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Fleet information row mapper
|
||||
*
|
||||
* <p>
|
||||
* This class is responsible for mapping rows from <code>bugs.dump_fleets_view</code> into
|
||||
* {@link FleetInformation} instances.
|
||||
*
|
||||
* @author <a href="mailto:tseeker@legacyworlds.com">E. Benoît</a>
|
||||
*
|
||||
*/
|
||||
final class FleetInformationMapper
|
||||
implements RowMapper< FleetInformation >
|
||||
{
|
||||
|
||||
/**
|
||||
* Map a row from <code>bugs.dump_fleets_view</code>
|
||||
*
|
||||
* <p>
|
||||
* Generate a {@link FleetInformation} instance from the row's contents. If the row indicates
|
||||
* that the fleet is moving, add a {@link MovementInformation} instance to the fleet information
|
||||
* record.
|
||||
*/
|
||||
@Override
|
||||
public FleetInformation mapRow( ResultSet rs , int rowNum )
|
||||
throws SQLException
|
||||
{
|
||||
FleetInformation fi = new FleetInformation( );
|
||||
fi.setId( rs.getLong( "fleet_id" ) );
|
||||
fi.setName( rs.getString( "fleet_name" ) );
|
||||
fi.setStatus( rs.getString( "status" ) );
|
||||
fi.setAttacking( rs.getBoolean( "attacking" ) );
|
||||
fi.setLocationId( rs.getInt( "location_id" ) );
|
||||
fi.setLocationName( rs.getString( "location_name" ) );
|
||||
|
||||
Integer sourceId = (Integer) rs.getObject( "source_id" );
|
||||
if ( sourceId != null ) {
|
||||
MovementInformation mi = new MovementInformation( );
|
||||
mi.setSourceId( sourceId );
|
||||
mi.setSourceName( rs.getString( "source_name" ) );
|
||||
mi.setTimeLeft( rs.getInt( "time_left" ) );
|
||||
mi.setStateTimeLeft( rs.getInt( "state_time_left" ) );
|
||||
mi.setNearId( (Integer) rs.getObject( "ref_point_id" ) );
|
||||
mi.setNearName( rs.getString( "ref_point_name" ) );
|
||||
mi.setOutwards( (Boolean) rs.getObject( "outwards" ) );
|
||||
mi.setPastRefPoint( (Boolean) rs.getObject( "past_ref_point" ) );
|
||||
mi.setStartX( (Float) rs.getObject( "start_x" ) );
|
||||
mi.setStartY( (Float) rs.getObject( "start_y" ) );
|
||||
fi.setMovement( mi );
|
||||
}
|
||||
|
||||
return fi;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
package com.deepclone.lw.beans.bt.es;
|
||||
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
|
||||
import com.deepclone.lw.beans.bt.es.data.PlanetInformation;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Top-level planet information row mapper
|
||||
*
|
||||
* <p>
|
||||
* This class maps rows from <code>bugs.dump_planets_view</code> into {@link PlanetInformation}
|
||||
* instances.
|
||||
*
|
||||
* @author <a href="mailto:tseeker@legacyworlds.com">E. Benoît</a>
|
||||
*
|
||||
*/
|
||||
final class PlanetInformationMapper
|
||||
implements RowMapper< PlanetInformation >
|
||||
{
|
||||
|
||||
/**
|
||||
* Map a row from <code>bugs.dump_planets_view</code>
|
||||
*
|
||||
* <p>
|
||||
* Create a new {@link PlanetInformation} instance from the row's contents. The instance's
|
||||
* civilian and military construction queues, while left mostly uninitialised, will have their
|
||||
* money and work accumulators set.
|
||||
*/
|
||||
@Override
|
||||
public PlanetInformation mapRow( ResultSet rs , int rowNum )
|
||||
throws SQLException
|
||||
{
|
||||
PlanetInformation pi = new PlanetInformation( );
|
||||
pi.setId( rs.getInt( "planet_id" ) );
|
||||
pi.setPopulation( rs.getDouble( "population" ) );
|
||||
pi.setCurrentHappiness( rs.getDouble( "current_happiness" ) );
|
||||
pi.setTargetHappiness( rs.getDouble( "target_happiness" ) );
|
||||
pi.getCivilianQueue( ).setAccMoney( rs.getDouble( "civ_money" ) );
|
||||
pi.getCivilianQueue( ).setAccWork( rs.getDouble( "civ_work" ) );
|
||||
pi.getMilitaryQueue( ).setAccMoney( rs.getDouble( "mil_money" ) );
|
||||
pi.getMilitaryQueue( ).setAccWork( rs.getDouble( "mil_work" ) );
|
||||
return pi;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
package com.deepclone.lw.beans.bt.es;
|
||||
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
|
||||
import com.deepclone.lw.beans.bt.es.data.QueueItemInformation;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Generic row mapper for construction queue items
|
||||
*
|
||||
* <p>
|
||||
* This class is responsible for mapping rows from <code>bugs.dump_queues_view</code> into
|
||||
* {@link QueueItemInformation} instances. These instances will be added to the right queue later.
|
||||
*
|
||||
* @author <a href="mailto:tseeker@legacyworlds.com">E. Benoît</a>
|
||||
*
|
||||
*/
|
||||
final class QueueItemInformationMapper
|
||||
implements RowMapper< QueueItemInformation >
|
||||
{
|
||||
|
||||
/**
|
||||
* Map a row from <code>bugs.dump_queues_view</code>
|
||||
*
|
||||
* <p>
|
||||
* Create a {@link QueueItemInformation} instance from the row's contents.
|
||||
*/
|
||||
@Override
|
||||
public QueueItemInformation mapRow( ResultSet rs , int rowNum )
|
||||
throws SQLException
|
||||
{
|
||||
QueueItemInformation qii = new QueueItemInformation( );
|
||||
qii.setPlanetId( rs.getInt( "planet_id" ) );
|
||||
qii.setMilitary( rs.getBoolean( "military" ) );
|
||||
qii.setId( rs.getInt( "item_id" ) );
|
||||
qii.setName( rs.getString( "item_name" ) );
|
||||
qii.setDestroy( rs.getBoolean( "destroy" ) );
|
||||
qii.setAmount( rs.getInt( "amount" ) );
|
||||
return qii;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
package com.deepclone.lw.beans.bt.es;
|
||||
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
|
||||
import com.deepclone.lw.beans.bt.es.data.ResearchInformation;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Research information row mapper
|
||||
*
|
||||
* <p>
|
||||
* This class maps rows from <code>bugs.dump_research_view</code> into {@link ResearchInformation}
|
||||
* instances.
|
||||
*
|
||||
* @author <a href="mailto:tseeker@legacyworlds.com">E. Benoît</a>
|
||||
*
|
||||
*/
|
||||
final class ResearchInformationMapper
|
||||
implements RowMapper< ResearchInformation >
|
||||
{
|
||||
|
||||
/**
|
||||
* Map a <code>bugs.dump_research_view</code> row
|
||||
*
|
||||
* <p>
|
||||
* Create a {@link ResearchInformation} instance from the row's contents.
|
||||
*/
|
||||
@Override
|
||||
public ResearchInformation mapRow( ResultSet rs , int rowNum )
|
||||
throws SQLException
|
||||
{
|
||||
ResearchInformation ri = new ResearchInformation( );
|
||||
ri.setId( rs.getInt( "line_id" ) );
|
||||
ri.setCurrentLevel( rs.getInt( "level" ) );
|
||||
ri.setLevelName( rs.getString( "name" ) );
|
||||
ri.setAccumulated( rs.getDouble( "accumulated" ) );
|
||||
return ri;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
package com.deepclone.lw.beans.bt.es;
|
||||
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
|
||||
import com.deepclone.lw.beans.bt.es.data.ShipsInformation;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Fleet ships information row mapper
|
||||
*
|
||||
* <p>
|
||||
* This class is responsible for creating {@link ShipsInformation} instances from the contents of
|
||||
* <code>bugs.dump_ships_view</code>.
|
||||
*
|
||||
* @author <a href="mailto:tseeker@legacyworlds.com">E. Benoît</a>
|
||||
*
|
||||
*/
|
||||
final class ShipsInformationMapper
|
||||
implements RowMapper< ShipsInformation >
|
||||
{
|
||||
|
||||
/**
|
||||
* Map a row from <code>bugs.dump_ships_view</code>
|
||||
*
|
||||
* <p>
|
||||
* Generate a {@link ShipsInformation} instance and initialise its fields based on the row's
|
||||
* contents.
|
||||
*/
|
||||
@Override
|
||||
public ShipsInformation mapRow( ResultSet rs , int rowNum )
|
||||
throws SQLException
|
||||
{
|
||||
ShipsInformation si = new ShipsInformation( );
|
||||
si.setFleetId( rs.getLong( "fleet_id" ) );
|
||||
si.setId( rs.getInt( "ship_id" ) );
|
||||
si.setName( rs.getString( "ship_name" ) );
|
||||
si.setAmount( rs.getInt( "amount" ) );
|
||||
si.setDamage( rs.getDouble( "damage" ) );
|
||||
return si;
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package com.deepclone.lw.beans.bt.esdata;
|
||||
package com.deepclone.lw.beans.bt.es.data;
|
||||
|
||||
|
||||
import java.io.Serializable;
|
|
@ -1,4 +1,4 @@
|
|||
package com.deepclone.lw.beans.bt.esdata;
|
||||
package com.deepclone.lw.beans.bt.es.data;
|
||||
|
||||
|
||||
import java.io.Serializable;
|
|
@ -1,4 +1,4 @@
|
|||
package com.deepclone.lw.beans.bt.esdata;
|
||||
package com.deepclone.lw.beans.bt.es.data;
|
||||
|
||||
|
||||
import java.io.Serializable;
|
|
@ -1,4 +1,4 @@
|
|||
package com.deepclone.lw.beans.bt.esdata;
|
||||
package com.deepclone.lw.beans.bt.es.data;
|
||||
|
||||
|
||||
import java.io.Serializable;
|
|
@ -1,4 +1,4 @@
|
|||
package com.deepclone.lw.beans.bt.esdata;
|
||||
package com.deepclone.lw.beans.bt.es.data;
|
||||
|
||||
|
||||
import java.io.Serializable;
|
|
@ -1,4 +1,4 @@
|
|||
package com.deepclone.lw.beans.bt.esdata;
|
||||
package com.deepclone.lw.beans.bt.es.data;
|
||||
|
||||
|
||||
import java.io.Serializable;
|
|
@ -1,4 +1,4 @@
|
|||
package com.deepclone.lw.beans.bt.esdata;
|
||||
package com.deepclone.lw.beans.bt.es.data;
|
||||
|
||||
|
||||
import java.io.Serializable;
|
|
@ -1,4 +1,4 @@
|
|||
package com.deepclone.lw.beans.bt.esdata;
|
||||
package com.deepclone.lw.beans.bt.es.data;
|
||||
|
||||
|
||||
import java.io.Serializable;
|
|
@ -1,4 +1,4 @@
|
|||
package com.deepclone.lw.beans.bt.esdata;
|
||||
package com.deepclone.lw.beans.bt.es.data;
|
||||
|
||||
|
||||
import java.io.Serializable;
|
|
@ -1,4 +1,4 @@
|
|||
package com.deepclone.lw.beans.bt.esdata;
|
||||
package com.deepclone.lw.beans.bt.es.data;
|
||||
|
||||
|
||||
import java.io.Serializable;
|
|
@ -1,4 +1,4 @@
|
|||
package com.deepclone.lw.beans.bt.esdata;
|
||||
package com.deepclone.lw.beans.bt.es.data;
|
||||
|
||||
|
||||
import java.io.Serializable;
|
|
@ -1,4 +1,4 @@
|
|||
package com.deepclone.lw.beans.bt.esdata;
|
||||
package com.deepclone.lw.beans.bt.es.data;
|
||||
|
||||
|
||||
import java.io.Serializable;
|
|
@ -1,4 +1,4 @@
|
|||
package com.deepclone.lw.beans.bt.esdata;
|
||||
package com.deepclone.lw.beans.bt.es.data;
|
||||
|
||||
|
||||
import java.io.Serializable;
|
|
@ -3,6 +3,6 @@
|
|||
xsi:schemaLocation="
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
|
||||
|
||||
<bean id="empireSummary" class="com.deepclone.lw.beans.bt.EmpireSummaryBean" />
|
||||
<bean id="empireSummary" class="com.deepclone.lw.beans.bt.es.EmpireSummaryBean" />
|
||||
|
||||
</beans>
|
||||
|
|
|
@ -1,9 +1,30 @@
|
|||
package com.deepclone.lw.interfaces.bt;
|
||||
|
||||
|
||||
/**
|
||||
* Empire XML summary generator
|
||||
*
|
||||
* <p>
|
||||
* This interface corresponds to the component which generates XML dumps of an empire's state to be
|
||||
* included in bug reports.
|
||||
*
|
||||
* @author <a href="mailto:tseeker@legacyworlds.com">E. Benoît</a>
|
||||
*/
|
||||
public interface EmpireSummary
|
||||
{
|
||||
|
||||
/**
|
||||
* Generate an empire's XML summary
|
||||
*
|
||||
* <p>
|
||||
* This method retrieves all necessary data from the database and converts it into an XML dump
|
||||
* to be used in the bug report.
|
||||
*
|
||||
* @param empireId
|
||||
* the empire's identifier
|
||||
*
|
||||
* @return the XML summary of the empire's current state
|
||||
*/
|
||||
public String getSummary( int empireId );
|
||||
|
||||
}
|
||||
|
|
Reference in a new issue