diff --git a/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/EmpireSummaryBean.java b/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/EmpireSummaryBean.java deleted file mode 100644 index 4b18651..0000000 --- a/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/EmpireSummaryBean.java +++ /dev/null @@ -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 ); - } - -} diff --git a/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/BuildingsInformationMapper.java b/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/BuildingsInformationMapper.java new file mode 100644 index 0000000..3a233c9 --- /dev/null +++ b/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/BuildingsInformationMapper.java @@ -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 + * + *
+ * Map rows from bugs.dump_buildings_view
into {@link BuildingsInformation} instances.
+ *
+ * @author E. Benoît
+ *
+ */
+final class BuildingsInformationMapper
+ implements RowMapper< BuildingsInformation >
+{
+
+ /**
+ * Map a row from bugs.dump_buildings_view
+ *
+ *
+ * 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; + } +} \ No newline at end of file diff --git a/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/DebugInformationMapper.java b/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/DebugInformationMapper.java new file mode 100644 index 0000000..b8a5399 --- /dev/null +++ b/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/DebugInformationMapper.java @@ -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 + * + *
+ * This class maps an entry from the database's main empire summary view,
+ * bugs.dump_main_view
, into a top-level {@link DebugInformation} instance.
+ *
+ * @author E. Benoît
+ *
+ */
+final class DebugInformationMapper
+ implements RowMapper< DebugInformation >
+{
+ /**
+ * Map a row from bugs.dump_main_view
into a {@link DebugInformation} instance
+ *
+ *
+ * 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; + } +} \ No newline at end of file diff --git a/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/EmpireSummaryBean.java b/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/EmpireSummaryBean.java new file mode 100644 index 0000000..d61469b --- /dev/null +++ b/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/EmpireSummaryBean.java @@ -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 + * + *
+ * 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 E. Benoît + */ +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 + * + *
+ * 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 ); + } + +} diff --git a/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/FleetInformationMapper.java b/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/FleetInformationMapper.java new file mode 100644 index 0000000..46b433f --- /dev/null +++ b/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/FleetInformationMapper.java @@ -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 + * + *
+ * This class is responsible for mapping rows from bugs.dump_fleets_view
into
+ * {@link FleetInformation} instances.
+ *
+ * @author E. Benoît
+ *
+ */
+final class FleetInformationMapper
+ implements RowMapper< FleetInformation >
+{
+
+ /**
+ * Map a row from bugs.dump_fleets_view
+ *
+ *
+ * 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; + } +} \ No newline at end of file diff --git a/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/PlanetInformationMapper.java b/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/PlanetInformationMapper.java new file mode 100644 index 0000000..87ebd06 --- /dev/null +++ b/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/PlanetInformationMapper.java @@ -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 + * + *
+ * This class maps rows from bugs.dump_planets_view
into {@link PlanetInformation}
+ * instances.
+ *
+ * @author E. Benoît
+ *
+ */
+final class PlanetInformationMapper
+ implements RowMapper< PlanetInformation >
+{
+
+ /**
+ * Map a row from bugs.dump_planets_view
+ *
+ *
+ * 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; + } +} \ No newline at end of file diff --git a/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/QueueItemInformationMapper.java b/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/QueueItemInformationMapper.java new file mode 100644 index 0000000..0d21815 --- /dev/null +++ b/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/QueueItemInformationMapper.java @@ -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 + * + *
+ * This class is responsible for mapping rows from bugs.dump_queues_view
into
+ * {@link QueueItemInformation} instances. These instances will be added to the right queue later.
+ *
+ * @author E. Benoît
+ *
+ */
+final class QueueItemInformationMapper
+ implements RowMapper< QueueItemInformation >
+{
+
+ /**
+ * Map a row from bugs.dump_queues_view
+ *
+ *
+ * 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; + } +} \ No newline at end of file diff --git a/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/ResearchInformationMapper.java b/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/ResearchInformationMapper.java new file mode 100644 index 0000000..c2cc5da --- /dev/null +++ b/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/ResearchInformationMapper.java @@ -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 + * + *
+ * This class maps rows from bugs.dump_research_view
into {@link ResearchInformation}
+ * instances.
+ *
+ * @author E. Benoît
+ *
+ */
+final class ResearchInformationMapper
+ implements RowMapper< ResearchInformation >
+{
+
+ /**
+ * Map a bugs.dump_research_view
row
+ *
+ *
+ * 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; + } +} \ No newline at end of file diff --git a/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/ShipsInformationMapper.java b/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/ShipsInformationMapper.java new file mode 100644 index 0000000..730d054 --- /dev/null +++ b/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/ShipsInformationMapper.java @@ -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 + * + *
+ * This class is responsible for creating {@link ShipsInformation} instances from the contents of
+ * bugs.dump_ships_view
.
+ *
+ * @author E. Benoît
+ *
+ */
+final class ShipsInformationMapper
+ implements RowMapper< ShipsInformation >
+{
+
+ /**
+ * Map a row from bugs.dump_ships_view
+ *
+ *
+ * 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;
+ }
+}
\ No newline at end of file
diff --git a/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/esdata/AccountInformation.java b/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/data/AccountInformation.java
similarity index 96%
rename from legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/esdata/AccountInformation.java
rename to legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/data/AccountInformation.java
index d6496e8..0fae3b3 100644
--- a/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/esdata/AccountInformation.java
+++ b/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/data/AccountInformation.java
@@ -1,4 +1,4 @@
-package com.deepclone.lw.beans.bt.esdata;
+package com.deepclone.lw.beans.bt.es.data;
import java.io.Serializable;
diff --git a/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/esdata/AllianceInformation.java b/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/data/AllianceInformation.java
similarity index 95%
rename from legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/esdata/AllianceInformation.java
rename to legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/data/AllianceInformation.java
index e156b4b..56368fb 100644
--- a/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/esdata/AllianceInformation.java
+++ b/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/data/AllianceInformation.java
@@ -1,4 +1,4 @@
-package com.deepclone.lw.beans.bt.esdata;
+package com.deepclone.lw.beans.bt.es.data;
import java.io.Serializable;
diff --git a/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/esdata/BuildingsInformation.java b/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/data/BuildingsInformation.java
similarity index 96%
rename from legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/esdata/BuildingsInformation.java
rename to legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/data/BuildingsInformation.java
index 61a9415..75416fc 100644
--- a/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/esdata/BuildingsInformation.java
+++ b/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/data/BuildingsInformation.java
@@ -1,4 +1,4 @@
-package com.deepclone.lw.beans.bt.esdata;
+package com.deepclone.lw.beans.bt.es.data;
import java.io.Serializable;
diff --git a/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/esdata/DebugInformation.java b/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/data/DebugInformation.java
similarity index 97%
rename from legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/esdata/DebugInformation.java
rename to legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/data/DebugInformation.java
index 847fcb1..76074b8 100644
--- a/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/esdata/DebugInformation.java
+++ b/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/data/DebugInformation.java
@@ -1,4 +1,4 @@
-package com.deepclone.lw.beans.bt.esdata;
+package com.deepclone.lw.beans.bt.es.data;
import java.io.Serializable;
diff --git a/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/esdata/EmpireInformation.java b/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/data/EmpireInformation.java
similarity index 95%
rename from legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/esdata/EmpireInformation.java
rename to legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/data/EmpireInformation.java
index 94825fe..ff5f984 100644
--- a/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/esdata/EmpireInformation.java
+++ b/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/data/EmpireInformation.java
@@ -1,4 +1,4 @@
-package com.deepclone.lw.beans.bt.esdata;
+package com.deepclone.lw.beans.bt.es.data;
import java.io.Serializable;
diff --git a/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/esdata/FleetInformation.java b/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/data/FleetInformation.java
similarity index 97%
rename from legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/esdata/FleetInformation.java
rename to legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/data/FleetInformation.java
index d049007..3030e5a 100644
--- a/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/esdata/FleetInformation.java
+++ b/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/data/FleetInformation.java
@@ -1,4 +1,4 @@
-package com.deepclone.lw.beans.bt.esdata;
+package com.deepclone.lw.beans.bt.es.data;
import java.io.Serializable;
diff --git a/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/esdata/MovementInformation.java b/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/data/MovementInformation.java
similarity index 97%
rename from legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/esdata/MovementInformation.java
rename to legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/data/MovementInformation.java
index b3f20a0..36e9f69 100644
--- a/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/esdata/MovementInformation.java
+++ b/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/data/MovementInformation.java
@@ -1,4 +1,4 @@
-package com.deepclone.lw.beans.bt.esdata;
+package com.deepclone.lw.beans.bt.es.data;
import java.io.Serializable;
diff --git a/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/esdata/PlanetInformation.java b/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/data/PlanetInformation.java
similarity index 97%
rename from legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/esdata/PlanetInformation.java
rename to legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/data/PlanetInformation.java
index e2c10a9..de9c6b6 100644
--- a/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/esdata/PlanetInformation.java
+++ b/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/data/PlanetInformation.java
@@ -1,4 +1,4 @@
-package com.deepclone.lw.beans.bt.esdata;
+package com.deepclone.lw.beans.bt.es.data;
import java.io.Serializable;
diff --git a/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/esdata/QueueInformation.java b/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/data/QueueInformation.java
similarity index 95%
rename from legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/esdata/QueueInformation.java
rename to legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/data/QueueInformation.java
index 3aacd7a..a4e7401 100644
--- a/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/esdata/QueueInformation.java
+++ b/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/data/QueueInformation.java
@@ -1,4 +1,4 @@
-package com.deepclone.lw.beans.bt.esdata;
+package com.deepclone.lw.beans.bt.es.data;
import java.io.Serializable;
diff --git a/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/esdata/QueueItemInformation.java b/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/data/QueueItemInformation.java
similarity index 96%
rename from legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/esdata/QueueItemInformation.java
rename to legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/data/QueueItemInformation.java
index a96a3d2..9e432e8 100644
--- a/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/esdata/QueueItemInformation.java
+++ b/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/data/QueueItemInformation.java
@@ -1,4 +1,4 @@
-package com.deepclone.lw.beans.bt.esdata;
+package com.deepclone.lw.beans.bt.es.data;
import java.io.Serializable;
diff --git a/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/esdata/ResearchInformation.java b/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/data/ResearchInformation.java
similarity index 96%
rename from legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/esdata/ResearchInformation.java
rename to legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/data/ResearchInformation.java
index 69d9f63..fc4746c 100644
--- a/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/esdata/ResearchInformation.java
+++ b/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/data/ResearchInformation.java
@@ -1,4 +1,4 @@
-package com.deepclone.lw.beans.bt.esdata;
+package com.deepclone.lw.beans.bt.es.data;
import java.io.Serializable;
diff --git a/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/esdata/ShipsInformation.java b/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/data/ShipsInformation.java
similarity index 96%
rename from legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/esdata/ShipsInformation.java
rename to legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/data/ShipsInformation.java
index 047ddfd..8a7229c 100644
--- a/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/esdata/ShipsInformation.java
+++ b/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/data/ShipsInformation.java
@@ -1,4 +1,4 @@
-package com.deepclone.lw.beans.bt.esdata;
+package com.deepclone.lw.beans.bt.es.data;
import java.io.Serializable;
diff --git a/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/esdata/SystemInformation.java b/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/data/SystemInformation.java
similarity index 94%
rename from legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/esdata/SystemInformation.java
rename to legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/data/SystemInformation.java
index 1d51bca..4a98a10 100644
--- a/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/esdata/SystemInformation.java
+++ b/legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es/data/SystemInformation.java
@@ -1,4 +1,4 @@
-package com.deepclone.lw.beans.bt.esdata;
+package com.deepclone.lw.beans.bt.es.data;
import java.io.Serializable;
diff --git a/legacyworlds-server-beans-bt/src/main/resources/configuration/bt/empire-summary-bean.xml b/legacyworlds-server-beans-bt/src/main/resources/configuration/bt/empire-summary-bean.xml
index bb9f28c..a268802 100644
--- a/legacyworlds-server-beans-bt/src/main/resources/configuration/bt/empire-summary-bean.xml
+++ b/legacyworlds-server-beans-bt/src/main/resources/configuration/bt/empire-summary-bean.xml
@@ -3,6 +3,6 @@
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
-
+ * This interface corresponds to the component which generates XML dumps of an empire's state to be + * included in bug reports. + * + * @author E. Benoît + */ public interface EmpireSummary { + /** + * Generate an empire's XML summary + * + *
+ * 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 ); }