Empire resources in XML dumps
* Added dump view for empire resources * Added empire resource information storage class and associated row mapper * Integrated empire resource information into the summary generator
This commit is contained in:
parent
ce6d86d344
commit
9b346a80c2
9 changed files with 542 additions and 15 deletions
legacyworlds-server-beans-bt/src/main/java/com/deepclone/lw/beans/bt/es
|
@ -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.EmpireResourceInformation;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Empire resource row mapper
|
||||
*
|
||||
* <p>
|
||||
* This class is responsible for transforming rows from <code>bugs.dump_emp_resources_view</code>
|
||||
* into {@link EmpireResourceInformation} instances.
|
||||
*
|
||||
* @author <a href="mailto:tseeker@legacyworlds.com">E. Benoît</a>
|
||||
*/
|
||||
final class EmpireResourceInformationMapper
|
||||
implements RowMapper< EmpireResourceInformation >
|
||||
{
|
||||
|
||||
/**
|
||||
* Map a row from <code>bugs.dump_emp_resources_view</code>
|
||||
*
|
||||
* <p>
|
||||
* Create a new {@link EmpireResourceInformation} instance and set its fields using the row's
|
||||
* contents.
|
||||
*/
|
||||
@Override
|
||||
public EmpireResourceInformation mapRow( ResultSet rs , int rowNum )
|
||||
throws SQLException
|
||||
{
|
||||
EmpireResourceInformation empRes = new EmpireResourceInformation( );
|
||||
|
||||
empRes.setResource( rs.getString( "resource_name" ) );
|
||||
empRes.setOwed( rs.getDouble( "empres_owed" ) );
|
||||
empRes.setPossessed( rs.getDouble( "empres_possessed" ) );
|
||||
|
||||
return empRes;
|
||||
}
|
||||
|
||||
}
|
|
@ -2,6 +2,7 @@ package com.deepclone.lw.beans.bt.es;
|
|||
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
@ -14,6 +15,7 @@ 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.EmpireResourceInformation;
|
||||
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;
|
||||
|
@ -51,6 +53,9 @@ public class EmpireSummaryBean
|
|||
/** SQL query that accesses the main empire dump view */
|
||||
private static final String Q_EMPIRE = SQL_START + "main" + SQL_END;
|
||||
|
||||
/** SQL query that accesses the resources dump view */
|
||||
private static final String Q_RESOURCES = SQL_START + "emp_resources" + SQL_END;
|
||||
|
||||
/** SQL query that accesses the research dump view */
|
||||
private static final String Q_RESEARCH = SQL_START + "research" + SQL_END;
|
||||
|
||||
|
@ -81,6 +86,9 @@ public class EmpireSummaryBean
|
|||
/** Top-level row mapper */
|
||||
private final DebugInformationMapper mMainInfo;
|
||||
|
||||
/** Empire resources row mapper */
|
||||
private final EmpireResourceInformationMapper mResources;
|
||||
|
||||
/** Empire research row mapper */
|
||||
private final ResearchInformationMapper mResearch;
|
||||
|
||||
|
@ -119,6 +127,7 @@ public class EmpireSummaryBean
|
|||
} );
|
||||
|
||||
this.mMainInfo = new DebugInformationMapper( );
|
||||
this.mResources = new EmpireResourceInformationMapper( );
|
||||
this.mResearch = new ResearchInformationMapper( );
|
||||
this.mPlanet = new PlanetInformationMapper( );
|
||||
this.mPlanetResources = new ResourceRowMapper( );
|
||||
|
@ -154,6 +163,7 @@ public class EmpireSummaryBean
|
|||
public String getSummary( int empireId )
|
||||
{
|
||||
DebugInformation empireDump = this.dTemplate.queryForObject( Q_EMPIRE , this.mMainInfo , empireId );
|
||||
this.getResources( empireId , empireDump );
|
||||
this.getResearch( empireId , empireDump );
|
||||
|
||||
this.getPlanets( empireId , empireDump );
|
||||
|
@ -163,6 +173,27 @@ public class EmpireSummaryBean
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Extract resources information
|
||||
*
|
||||
* <p>
|
||||
* Read the list of empire resources from the appropriate view and add the extracted entries to
|
||||
* the empire's list of resources.
|
||||
*
|
||||
* @param empireId
|
||||
* the empire's identifier
|
||||
* @param empireDump
|
||||
* the top-level instance
|
||||
*/
|
||||
private void getResources( int empireId , DebugInformation empireDump )
|
||||
{
|
||||
List< EmpireResourceInformation > resources = empireDump.getEmpire( ).getResources( );
|
||||
for ( EmpireResourceInformation empRes : this.dTemplate.query( Q_RESOURCES , this.mResources , empireId ) ) {
|
||||
resources.add( empRes );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get research information
|
||||
*
|
||||
|
|
|
@ -2,79 +2,140 @@ package com.deepclone.lw.beans.bt.es.data;
|
|||
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
import com.thoughtworks.xstream.annotations.XStreamAsAttribute;
|
||||
|
||||
|
||||
|
||||
@XStreamAlias( "empire" )
|
||||
/**
|
||||
* Empire information record for XML dumps
|
||||
*
|
||||
* <p>
|
||||
* This class regroups all "main" empire information in XML dumps. This includes the empire's name
|
||||
* and identifier, details about the alliance, and the list of resources.
|
||||
*
|
||||
* @author <a href="mailto:tseeker@legacyworlds.com">E. Benoît</a>
|
||||
*/
|
||||
@SuppressWarnings( "serial" )
|
||||
public class EmpireInformation
|
||||
implements Serializable
|
||||
{
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** The empire's numeric identifier */
|
||||
@XStreamAsAttribute
|
||||
@XStreamAlias( "id" )
|
||||
private int id;
|
||||
private Integer id;
|
||||
|
||||
/** The empire's name */
|
||||
@XStreamAsAttribute
|
||||
@XStreamAlias( "name" )
|
||||
private String name;
|
||||
|
||||
/** The empire's cash */
|
||||
@XStreamAsAttribute
|
||||
@XStreamAlias( "cash" )
|
||||
private double cash;
|
||||
private Double cash;
|
||||
|
||||
/**
|
||||
* The alliance the empire belongs to or has requested membership of (or <code>null</code> if
|
||||
* the empire is neither in an alliance nor requesting to join one)
|
||||
*/
|
||||
private AllianceInformation alliance;
|
||||
|
||||
/** The empire's resources */
|
||||
private final ArrayList< EmpireResourceInformation > resources = new ArrayList< EmpireResourceInformation >( );
|
||||
|
||||
public int getId( )
|
||||
|
||||
/** @return the empire's numeric identifier */
|
||||
public Integer getId( )
|
||||
{
|
||||
return id;
|
||||
return this.id;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the empire's numeric identifier
|
||||
*
|
||||
* @param id
|
||||
* the empire's numeric identifier
|
||||
*/
|
||||
public void setId( int id )
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
|
||||
/** @return the empire's name */
|
||||
public String getName( )
|
||||
{
|
||||
return name;
|
||||
return this.name;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the empire's name
|
||||
*
|
||||
* @param name
|
||||
* the empire's name
|
||||
*/
|
||||
public void setName( String name )
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
||||
public double getCash( )
|
||||
/** @return the amount of cash possessed by the empire */
|
||||
public Double getCash( )
|
||||
{
|
||||
return cash;
|
||||
return this.cash;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the amount of cash possessed by the empire
|
||||
*
|
||||
* @param cash
|
||||
* the amount of cash possessed by the empire
|
||||
*/
|
||||
public void setCash( double cash )
|
||||
{
|
||||
this.cash = cash;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the alliance the empire belongs to or has requested membership of, or
|
||||
* <code>null</code> if the empire is neither in an alliance nor requesting to join one
|
||||
*/
|
||||
public AllianceInformation getAlliance( )
|
||||
{
|
||||
return alliance;
|
||||
return this.alliance;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the information about the alliance
|
||||
*
|
||||
* @param alliance
|
||||
* the information about the alliance
|
||||
*/
|
||||
public void setAlliance( AllianceInformation alliance )
|
||||
{
|
||||
this.alliance = alliance;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Access the list of resources
|
||||
*
|
||||
* @return the list of resources, even if none was set in the file the instance was loaded from.
|
||||
*/
|
||||
public List< EmpireResourceInformation > getResources( )
|
||||
{
|
||||
if ( this.resources == null ) {
|
||||
return Collections.emptyList( );
|
||||
}
|
||||
return this.resources;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,103 @@
|
|||
package com.deepclone.lw.beans.bt.es.data;
|
||||
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
import com.thoughtworks.xstream.annotations.XStreamAsAttribute;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Empire resources XML dump record
|
||||
*
|
||||
* <p>
|
||||
* This class is used to store information about an empire's resources in debugging XML dumps. Each
|
||||
* instance indicates the amount possessed or owed for a given type of resources.
|
||||
*
|
||||
* @author <a href="mailto:tseeker@legacyworlds.com">E. Benoît</a>
|
||||
*/
|
||||
@XStreamAlias( "resource" )
|
||||
@SuppressWarnings( "serial" )
|
||||
public class EmpireResourceInformation
|
||||
implements Serializable
|
||||
{
|
||||
|
||||
/** The type of resources */
|
||||
@XStreamAlias( "id" )
|
||||
@XStreamAsAttribute
|
||||
private String resource;
|
||||
|
||||
/** The amount of resources possessed */
|
||||
@XStreamAsAttribute
|
||||
private Double possessed;
|
||||
|
||||
/** The amount of resources owed */
|
||||
@XStreamAsAttribute
|
||||
private Double owed;
|
||||
|
||||
|
||||
/** @return the type of resources */
|
||||
public String getResource( )
|
||||
{
|
||||
return this.resource;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the type of resources
|
||||
*
|
||||
* @param resource
|
||||
* the type of resources
|
||||
*
|
||||
* @throws InvalidDumpContentsException
|
||||
* if the specified resource type is <code>null</code>
|
||||
*/
|
||||
public void setResource( String resource )
|
||||
throws InvalidDumpContentsException
|
||||
{
|
||||
if ( resource == null ) {
|
||||
throw new InvalidDumpContentsException( this.getClass( ) , "resource" );
|
||||
}
|
||||
this.resource = resource;
|
||||
}
|
||||
|
||||
|
||||
/** @return the amount of resources possessed */
|
||||
public Double getPossessed( )
|
||||
{
|
||||
return this.possessed;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the amount of resources possessed
|
||||
*
|
||||
* @param possessed
|
||||
* the amount of resources possessed
|
||||
*/
|
||||
public void setPossessed( Double possessed )
|
||||
{
|
||||
this.possessed = possessed;
|
||||
}
|
||||
|
||||
|
||||
/** @return the amount of resources owed */
|
||||
public Double getOwed( )
|
||||
{
|
||||
return this.owed;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the amount of resources owed
|
||||
*
|
||||
* @param owed
|
||||
* the amount of resources owed
|
||||
*/
|
||||
public void setOwed( Double owed )
|
||||
{
|
||||
this.owed = owed;
|
||||
}
|
||||
|
||||
}
|
Reference in a new issue