Resources information on planet list

* Added resource information records to the planet list's response.

* Added a database view and the corresponding row mapper and DAO method
which can be used as the data source for the planet list's resource
information. For now this view always returns 0 for both civilian and
military investments.

* Added new tab to display resource information on the planet list page.
The old version of the economy tab will be kept until the corresponding
data no longer exists.

* The following SQL scripts must be re-executed to upgrade a database:
  -> 040-functions/167-planet-list.sql
This commit is contained in:
Emmanuel BENOîT 2012-02-15 14:45:43 +01:00
parent bf6bea5a79
commit 96670d45be
15 changed files with 1079 additions and 31 deletions
legacyworlds-server-beans-resources/src/main/java/com/deepclone/lw/beans/game/resources

View file

@ -0,0 +1,65 @@
package com.deepclone.lw.beans.game.resources;
import com.deepclone.lw.cmd.player.gdata.PlanetListResourceRecord;
/**
* Intermediary class for planet list resource records extraction
*
* <p>
* This class is used as an intermediary to extract {@link PlanetListResourceRecord} instances from
* <code>emp.plist_resources_view</code>. It contains the instance itself, and an additional field
* which indicates the planet's identifier.
*
* <p>
* Instances of this class are returned by {@link PlanetListResourceRecordMapper} and then processed
* to generate the map returned by {@link ResourcesInformationDAOBean#getPlanetListData(int)}.
*
* @author <a href="mailto:tseeker@legacyworlds.com">E. Benoît</a>
*
*/
class FullPlanetListRecord
{
/** The planet's identifier */
private int planetId;
/** The resource record */
private final PlanetListResourceRecord record = new PlanetListResourceRecord( );
/**
* Gets the planet's identifier.
*
* @return the planet's identifier
*/
public int getPlanetId( )
{
return this.planetId;
}
/**
* Sets the planet's identifier.
*
* @param planetId
* the new planet's identifier
*/
public void setPlanetId( int planetId )
{
this.planetId = planetId;
}
/**
* Gets the resource record.
*
* @return the resource record
*/
public PlanetListResourceRecord getRecord( )
{
return this.record;
}
}

View file

@ -0,0 +1,72 @@
package com.deepclone.lw.beans.game.resources;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.springframework.jdbc.core.RowMapper;
import com.deepclone.lw.cmd.player.gdata.PlanetListResourceRecord;
/**
* Planet list resource records mapper
*
* <p>
* This class is responsible for mapping rows from <code>emp.plist_resources_view</code> into
* {@link FullPlanetListRecord} instances.
*
* @author <a href="mailto:tseeker@legacyworlds.com">E. Benoît</a>
*/
class PlanetListResourceRecordMapper
implements RowMapper< FullPlanetListRecord >
{
/**
* Map a row from <code>emp.plist_resources_view</code>
*
* <p>
* Convert a row from <code>emp.plist_resources_view</code> into a {@link FullPlanetListRecord}
* instance. The resulting instance will have both its planet identifier and actual record set
* according to the row's contents.
*/
@Override
public FullPlanetListRecord mapRow( ResultSet rs , int rowNum )
throws SQLException
{
FullPlanetListRecord fullRecord = new FullPlanetListRecord( );
fullRecord.setPlanetId( rs.getInt( "planet_id" ) );
this.extractRecord( fullRecord.getRecord( ) , rs );
return fullRecord;
}
/**
* Extract the contents of the actual record
*
* <p>
* This method extracts the contents of the record that will be sent to the client from the
* result set.
*
* @param record
* the planet list resource record to update
* @param rs
* the result set to extract information from
*
* @throws SQLException
* if a SQLException is encountered getting column values
*/
private void extractRecord( PlanetListResourceRecord record , ResultSet rs )
throws SQLException
{
record.setName( rs.getString( "resource_name" ) );
record.setIncome( rs.getLong( "pres_income" ) );
record.setUpkeep( rs.getLong( "pres_upkeep" ) );
record.setCivInvestment( rs.getLong( "civ_investment" ) );
record.setMilInvestment( rs.getLong( "mil_investment" ) );
}
}

View file

@ -1,13 +1,17 @@
package com.deepclone.lw.beans.game.resources;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
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.cmd.player.gdata.PlanetListResourceRecord;
import com.deepclone.lw.cmd.player.gdata.empire.EmpireResourceRecord;
import com.deepclone.lw.cmd.player.gdata.planets.PlanetResourceRecord;
import com.deepclone.lw.interfaces.game.resources.ResourcesInformationDAO;
@ -37,12 +41,18 @@ class ResourcesInformationDAOBean
/** SQL query that fetches an empire's resources information */
private static final String Q_EMPIRE_RESOURCES = "SELECT * FROM emp.resources_view WHERE empire_id = ?";
/** SQL query that fetches the resource records for an empire's planet list */
private static final String Q_PLIST_RESOURCES = "SELECT * FROM emp.plist_resources_view WHERE empire_id = ?";
/** Row mapper for planet resources */
private final PlanetResourceMapper mPlanetResource;
/** Row mapper for empire resources */
private final EmpireResourceMapper mEmpireResource;
/** Row mapper for planet list records */
private final PlanetListResourceRecordMapper mPlanetListRecord;
/** Spring JDBC interface */
private JdbcTemplate dTemplate;
@ -52,6 +62,7 @@ class ResourcesInformationDAOBean
{
this.mPlanetResource = new PlanetResourceMapper( );
this.mEmpireResource = new EmpireResourceMapper( );
this.mPlanetListRecord = new PlanetListResourceRecordMapper( );
}
@ -96,4 +107,34 @@ class ResourcesInformationDAOBean
return this.dTemplate.query( Q_EMPIRE_RESOURCES , this.mEmpireResource , empire );
}
/**
* Run the planet list resources query and extract the data
*
* <p>
* This implementation queries <code>emp.plist_resources_view</code> to obtain the planet list's
* records, then maps the resulting rows using the intermediary {@link FullPlanetListRecord}
* class, and finally associates records to the corresponding planet identifiers.
*/
@Override
public Map< Integer , List< PlanetListResourceRecord > > getPlanetListData( int empire )
{
Map< Integer , List< PlanetListResourceRecord > > result;
result = new HashMap< Integer , List< PlanetListResourceRecord > >( );
List< FullPlanetListRecord > queryOutput;
queryOutput = this.dTemplate.query( Q_PLIST_RESOURCES , this.mPlanetListRecord , empire );
for ( FullPlanetListRecord fullRecord : queryOutput ) {
List< PlanetListResourceRecord > records = result.get( fullRecord.getPlanetId( ) );
if ( records == null ) {
records = new LinkedList< PlanetListResourceRecord >( );
result.put( fullRecord.getPlanetId( ) , records );
}
records.add( fullRecord.getRecord( ) );
}
return result;
}
}