Project: * Clean-up (Eclipse cruft, unused files, etc...) * Git-specific changes * Maven POMs clean-up and changes for the build system * Version set to 1.0.0-0 in the development branches * Maven plug-ins updated to latest versions * Very partial dev. documentation added

This commit is contained in:
Emmanuel BENOîT 2011-12-09 08:07:33 +01:00
parent c74e30d5ba
commit 0665a760de
1439 changed files with 1020 additions and 1649 deletions
legacyworlds-server-beans-naming/src
main
test
java
resources

View file

@ -0,0 +1,98 @@
package com.deepclone.lw.beans.naming;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import com.deepclone.lw.cmd.admin.adata.Administrator;
import com.deepclone.lw.cmd.admin.naming.GetNamesResponse;
import com.deepclone.lw.cmd.admin.naming.NameType;
import com.deepclone.lw.cmd.admin.naming.NamesSummaryResponse;
import com.deepclone.lw.cmd.admin.naming.NamesSummaryResponse.Entry;
import com.deepclone.lw.interfaces.naming.NamesManager;
import com.deepclone.lw.interfaces.naming.NamingDAO;
@Transactional
public class NamesManagerBean
implements NamesManager
{
private NamingDAO namingDao;
@Autowired( required = true )
public void setNamingDao( NamingDAO namingDao )
{
this.namingDao = namingDao;
}
@Override
public NamesSummaryResponse getSummary( Administrator admin )
{
List< Entry > entries = new LinkedList< Entry >( );
for ( Map.Entry< NameType , Long > entry : this.namingDao.countNames( ).entrySet( ) ) {
entries.add( new Entry( entry.getKey( ) , entry.getValue( ) ) );
}
return new NamesSummaryResponse( admin , entries );
}
@Override
public GetNamesResponse getNames( Administrator admin , NameType type )
{
return new GetNamesResponse( admin , type , this.namingDao.getNames( type ) );
}
@Override
public void validateMapNames( Administrator admin , int[] ids )
{
for ( int id : ids ) {
this.namingDao.validateMapName( admin.getId( ) , id );
}
}
@Override
public void allowMapNameChanges( Administrator admin , int[] ids )
{
for ( int id : ids ) {
this.namingDao.allowMapNameChange( admin.getId( ) , id );
}
}
@Override
public void rejectMapNames( Administrator admin , int[] ids , boolean ban )
{
for ( int id : ids ) {
this.namingDao.rejectMapName( admin.getId( ) , id , ban );
}
}
@Override
public void rejectEmpireNames( Administrator admin , int[] ids , boolean ban )
{
for ( int id : ids ) {
this.namingDao.rejectEmpireName( admin.getId( ) , id , ban );
}
}
@Override
public void rejectAllianceNames( Administrator admin , int[] ids )
{
for ( int id : ids ) {
this.namingDao.rejectAllianceName( admin.getId( ) , id );
}
}
}

View file

@ -0,0 +1,215 @@
package com.deepclone.lw.beans.naming;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
import com.deepclone.lw.cmd.admin.naming.Name;
import com.deepclone.lw.cmd.admin.naming.NameType;
import com.deepclone.lw.interfaces.naming.NamingDAO;
import com.deepclone.lw.sqld.accounts.Account;
import com.deepclone.lw.utils.StoredProc;
public class NamingDAOBean
implements NamingDAO
{
private static final String sCountNames = "SELECT * FROM naming.names_status_view ORDER BY status";
private static class CountRow
{
String status;
long count;
}
private SimpleJdbcTemplate dTemplate;
private StoredProc fGetEmpire;
private StoredProc fRenamePlanet;
private StoredProc fValidateMapName;
private StoredProc fAllowMapRename;
private StoredProc fRejectMapName;
private StoredProc fRejectEmpireName;
private StoredProc fRejectAllianceName;
private final RowMapper< Name > mName;
private final RowMapper< CountRow > mCount;
public NamingDAOBean( )
{
this.mName = new RowMapper< Name >( ) {
@Override
public Name mapRow( ResultSet rs , int rowNum )
throws SQLException
{
return new Name( rs.getInt( "id" ) , rs.getString( "name" ) , rs.getString( "extra" ) , NameType
.valueOf( rs.getString( "status" ) ) );
}
};
this.mCount = new RowMapper< CountRow >( ) {
@Override
public CountRow mapRow( ResultSet rs , int rowNum )
throws SQLException
{
CountRow cRow = new CountRow( );
cRow.count = rs.getLong( "count" );
cRow.status = rs.getString( "status" );
return cRow;
}
};
}
@Autowired( required = true )
public void setDataSource( DataSource dataSource )
{
this.dTemplate = new SimpleJdbcTemplate( dataSource );
this.fGetEmpire = new StoredProc( dataSource , "emp" , "get_current" );
this.fGetEmpire.addParameter( "account_id" , Types.INTEGER );
this.fGetEmpire.addOutput( "empire_id" , Types.INTEGER );
this.fRenamePlanet = new StoredProc( dataSource , "verse" , "rename_planet" );
this.fRenamePlanet.addParameter( "planet_id" , Types.INTEGER );
this.fRenamePlanet.addParameter( "new_name" , Types.VARCHAR );
this.fRenamePlanet.addOutput( "err_code" , Types.INTEGER );
this.fValidateMapName = new StoredProc( dataSource , "naming" , "validate_map_name" );
this.fValidateMapName.addParameter( "admin_id" , Types.INTEGER );
this.fValidateMapName.addParameter( "name_id" , Types.INTEGER );
this.fAllowMapRename = new StoredProc( dataSource , "naming" , "allow_map_name_change" );
this.fAllowMapRename.addParameter( "admin_id" , Types.INTEGER );
this.fAllowMapRename.addParameter( "name_id" , Types.INTEGER );
this.fRejectMapName = new StoredProc( dataSource , "naming" , "reject_map_name" );
this.fRejectMapName.addParameter( "admin_id" , Types.INTEGER );
this.fRejectMapName.addParameter( "name_id" , Types.INTEGER );
this.fRejectMapName.addParameter( "ban_name" , Types.BOOLEAN );
this.fRejectEmpireName = new StoredProc( dataSource , "naming" , "reject_empire_name" );
this.fRejectEmpireName.addParameter( "admin_id" , Types.INTEGER );
this.fRejectEmpireName.addParameter( "name_id" , Types.INTEGER );
this.fRejectEmpireName.addParameter( "ban_name" , Types.BOOLEAN );
this.fRejectAllianceName = new StoredProc( dataSource , "naming" , "reject_alliance_name" );
this.fRejectAllianceName.addParameter( "admin_id" , Types.INTEGER );
this.fRejectAllianceName.addParameter( "alliance_id" , Types.INTEGER );
}
@Override
public List< String > getEmpireNames( int account )
{
String sql = "SELECT name FROM naming.empire_names WHERE owner_id = ? ORDER BY name";
RowMapper< String > mapper = new RowMapper< String >( ) {
@Override
public String mapRow( ResultSet rs , int rowNum )
throws SQLException
{
return rs.getString( "name" );
}
};
return this.dTemplate.query( sql , mapper , account );
}
@Override
public Integer getCurrentEmpire( Account account )
{
return (Integer) this.fGetEmpire.execute( account.getId( ) ).get( "empire_id" );
}
@Override
public int renamePlanet( int id , String name )
{
return (Integer) this.fRenamePlanet.execute( id , name ).get( "err_code" );
}
@Override
public Map< NameType , Long > countNames( )
{
Map< NameType , Long > result = new HashMap< NameType , Long >( );
for ( NameType t : NameType.values( ) ) {
result.put( t , 0L );
}
for ( CountRow qr : this.dTemplate.query( sCountNames , this.mCount ) ) {
NameType type = NameType.valueOf( qr.status );
result.put( type , qr.count );
}
result.put( NameType.MAP_CHANGED , result.get( NameType.MAP_PENDING ) + result.get( NameType.MAP_VALIDATED ) );
return result;
}
@Override
public List< Name > getNames( NameType type )
{
String sql = "SELECT * FROM naming.names_view WHERE status ";
if ( type == NameType.MAP_CHANGED ) {
sql += "IN ('MAP_PENDING','MAP_VALIDATED')";
} else {
sql += "= '" + type + "'";
}
if ( type == NameType.ALLIANCE || type == NameType.EMPIRE ) {
sql += " ORDER BY id DESC";
} else {
sql += " ORDER BY name";
}
return this.dTemplate.query( sql , this.mName );
}
@Override
public void validateMapName( int administrator , int name )
{
this.fValidateMapName.execute( administrator , name );
}
@Override
public void allowMapNameChange( int administrator , int name )
{
this.fAllowMapRename.execute( administrator , name );
}
@Override
public void rejectMapName( int administrator , int name , boolean ban )
{
this.fRejectMapName.execute( administrator , name , ban );
}
@Override
public void rejectEmpireName( int administrator , int empire , boolean ban )
{
this.fRejectEmpireName.execute( administrator , empire , ban );
}
@Override
public void rejectAllianceName( int administrator , int alliance )
{
this.fRejectAllianceName.execute( administrator , alliance );
}
}

View file

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<import resource="naming/names-manager-bean.xml" />
<import resource="naming/naming-dao-bean.xml" />
</beans>

View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="namesManager" class="com.deepclone.lw.beans.naming.NamesManagerBean" />
</beans>

View file

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="namingDAO" class="com.deepclone.lw.beans.naming.NamingDAOBean" />
</beans>