Compare commits
93 commits
Author | SHA1 | Date | |
---|---|---|---|
d246f221f0 | |||
d7b14e3de9 | |||
af33d44b2a | |||
3a0f5bbb78 | |||
dc9ef2292d | |||
9e84f333e7 | |||
cf8dee6ec9 | |||
1dd1da5ae3 | |||
75c5245764 | |||
c8f19a4c06 | |||
7e3d8a558a | |||
aaec345957 | |||
a6562052d3 | |||
8f2fd29c71 | |||
0c67d1e799 | |||
ff78c6a2d6 | |||
071257786c | |||
ab04752169 | |||
96c296e9d5 | |||
070d55dc05 | |||
76a01cbf1c | |||
6dcd59d7bc | |||
154f215e24 | |||
9a7bc03171 | |||
c7949e41cc | |||
a14601df37 | |||
c9d8a077bd | |||
1dcde71dff | |||
b15acadc1b | |||
e01eab9c09 | |||
f4e38e4943 | |||
8c0b4abd1e | |||
1f3c7a9202 | |||
c5464212bc | |||
26fe4b926d | |||
af57e7d3b5 | |||
3b2ec4bb64 | |||
1ae9a15f6e | |||
4f083830f2 | |||
b90491ca73 | |||
cb65a6e643 | |||
96670d45be | |||
bf6bea5a79 | |||
f3aa563758 | |||
afa1224391 | |||
c94958a058 | |||
cb2553d1e5 | |||
fd117f6f7b | |||
e64f847ec3 | |||
51b529a09f | |||
d38576a5cf | |||
92dd01ffce | |||
b4903d78e4 | |||
35d8891fe3 | |||
597429fadf | |||
56eddcc4f0 | |||
ba6a1e2b41 | |||
44b6ec1920 | |||
b9bc5e038c | |||
a4bce68b17 | |||
4e27875d87 | |||
775426347a | |||
|
f4a16aa431 | ||
3637b6e1d1 | |||
9b346a80c2 | |||
ce6d86d344 | |||
95e6019c12 | |||
426a1fdfd4 | |||
2adc754a2c | |||
a981d1653e | |||
30a1080e6e | |||
24f40c5549 | |||
74b6f2ab09 | |||
038bba896a | |||
c18bdc2d1f | |||
04e550709a | |||
b49bc1a44f | |||
37555841ce | |||
afc66166e0 | |||
3e109b13bc | |||
e50775ec76 | |||
b054a379a9 | |||
e7d2072813 | |||
d4945d8e21 | |||
66c72ef718 | |||
d768766214 | |||
bed784a8e1 | |||
4e1bb91780 | |||
631f49fb86 | |||
be3106c463 | |||
f682594cbd | |||
0665a760de | |||
c74e30d5ba |
1905 changed files with 50725 additions and 7261 deletions
8
.gitignore
vendored
Normal file
8
.gitignore
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
target
|
||||
.settings
|
||||
.classpath
|
||||
.project
|
||||
legacyworlds-server-main/data-source.xml
|
||||
legacyworlds-server-data/db-structure/db-config.txt
|
||||
*.log
|
||||
full-debug*.zip
|
17
.project
17
.project
|
@ -1,17 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>legacyworlds</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.maven.ide.eclipse.maven2Builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.maven.ide.eclipse.maven2Nature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
|
@ -1,51 +0,0 @@
|
|||
#!/bin/sh
|
||||
|
||||
cd `dirname $0`/..
|
||||
SRCDIR=`pwd`
|
||||
if [ "x$1" = "x" ]; then
|
||||
OUTDIR="$SRCDIR";
|
||||
else
|
||||
OUTDIR="$1";
|
||||
fi
|
||||
|
||||
echo "Building Legacy Worlds..."
|
||||
mvn clean || { echo "Maven clean-up failed"; exit 1; };
|
||||
mvn package || { echo "Maven build failed"; exit 1; };
|
||||
|
||||
echo "Copying files..."
|
||||
|
||||
TEMPDIR=`mktemp -d`
|
||||
mkdir $TEMPDIR/legacyworlds
|
||||
mkdir $TEMPDIR/legacyworlds/server
|
||||
mkdir $TEMPDIR/legacyworlds/server/data
|
||||
mkdir $TEMPDIR/legacyworlds/web
|
||||
mkdir $TEMPDIR/legacyworlds/sql
|
||||
|
||||
# Database and initial data
|
||||
cp -Rapv legacyworlds-server/legacyworlds-server-data/db-structure/database.sql $TEMPDIR/legacyworlds/sql
|
||||
cp -Rapv legacyworlds-server/legacyworlds-server-data/db-structure/db-config.txt $TEMPDIR/legacyworlds/sql/db-config-example.txt
|
||||
cp -Rapv legacyworlds-server/legacyworlds-server-data/db-structure/parts $TEMPDIR/legacyworlds/sql
|
||||
cp -Rapv legacyworlds-server/legacyworlds-server-main/data/* $TEMPDIR/legacyworlds/server/data
|
||||
# Server
|
||||
cp -Rapv legacyworlds-server/legacyworlds-server-main/target/*.jar $TEMPDIR/legacyworlds/server
|
||||
cp -Rapv legacyworlds-server/legacyworlds-server-main/target/lib $TEMPDIR/legacyworlds/server
|
||||
cp -Rapv legacyworlds-server/legacyworlds-server-main/data-source.xml $TEMPDIR/legacyworlds/server/data-source-example.xml
|
||||
# Tools
|
||||
cp -Rapv build-tools/server-config-example.sh $TEMPDIR/legacyworlds
|
||||
cp -Rapv build-tools/start-server.sh $TEMPDIR/legacyworlds
|
||||
cp -Rapv build-tools/stop-server.sh $TEMPDIR/legacyworlds
|
||||
cp -Rapv build-tools/execute-clit.sh $TEMPDIR/legacyworlds
|
||||
cp -Rapv build-tools/deploy.sh $TEMPDIR/legacyworlds
|
||||
# Web sites
|
||||
cp -Rapv legacyworlds-web/legacyworlds-web-*/target/*.war $TEMPDIR/legacyworlds/web
|
||||
|
||||
echo "Preparing archive..."
|
||||
cd $TEMPDIR
|
||||
find $TEMPDIR/legacyworlds -type d -name .svn | xargs rm -rf
|
||||
tar cvjf $OUTDIR/legacyworlds.tar.bz2 legacyworlds || { echo "Archive generation failed"; exit 1; };
|
||||
|
||||
echo "Removing temporary directory..."
|
||||
cd $SRCDIR
|
||||
rm -rf $TEMPDIR
|
||||
|
||||
echo "All done. Legacy Worlds archive: $OUTDIR/legacyworlds.tar.bz2"
|
|
@ -1,34 +0,0 @@
|
|||
#!/bin/sh
|
||||
|
||||
COREDIR="$1"
|
||||
if [ "x$COREDIR" = "x" ] || ! [ -d "$COREDIR" ]; then
|
||||
echo "Syntax: $0 main_dir tomcat_dir web_dir"
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
TOMCATDIR="$2"
|
||||
if [ "x$TOMCATDIR" = "x" ] || ! [ -d "$TOMCATDIR" ]; then
|
||||
echo "Syntax: $0 main_dir tomcat_dir web_dir"
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
WEBDIR="$3"
|
||||
if [ "x$WEBDIR" = "x" ] || ! [ -d "$WEBDIR" ]; then
|
||||
echo "Syntax: $0 main_dir tomcat_dir web_dir"
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
|
||||
cd `dirname $0`
|
||||
SRCDIR=`pwd`
|
||||
cp -Rap server web *-*.sh $COREDIR
|
||||
|
||||
cd "$TOMCATDIR"
|
||||
if [ -L "lwmain.war" ]; then
|
||||
rm -f lwmain.war lwadmin.war
|
||||
fi
|
||||
ln -s "$COREDIR/web/legacyworlds-web-main-"*.war lwmain.war
|
||||
ln -s "$COREDIR/web/legacyworlds-web-admin-"*.war lwadmin.war
|
||||
|
||||
cd $WEBDIR
|
||||
unzip -o $COREDIR/web/legacyworlds-web-main-*.war "css/*" "js/*" "pjirc/*" "img/*"
|
58
build/post-build.d/10-database-tests.sh
Normal file
58
build/post-build.d/10-database-tests.sh
Normal file
|
@ -0,0 +1,58 @@
|
|||
#!/bin/bash
|
||||
|
||||
cd legacyworlds-server-data/db-structure
|
||||
if ! [ -f db-config.txt ]; then
|
||||
cat > db-config.txt <<EOF
|
||||
admin=$USER
|
||||
db=tests
|
||||
user=tests
|
||||
password=tests
|
||||
EOF
|
||||
fi
|
||||
export TEST_DATABASE="`grep ^db= db-config.txt | sed -e s/.*=//`"
|
||||
export TEST_USER="`grep ^user= db-config.txt | sed -e s/.*=//`"
|
||||
|
||||
echo
|
||||
echo
|
||||
echo "======================================================================"
|
||||
echo "LOADING DATABASE DEFINITION ..."
|
||||
echo "======================================================================"
|
||||
echo
|
||||
echo
|
||||
psql -vQUIET=1 -vON_ERROR_STOP=1 -e --file database.sql || exit 1
|
||||
|
||||
if ! [ -d tests/admin ] && ! [ -d tests/user ]; then
|
||||
echo
|
||||
echo
|
||||
echo "WARNING: no unit tests to run"
|
||||
echo
|
||||
echo
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo
|
||||
echo
|
||||
echo "======================================================================"
|
||||
echo "LOADING TEST FRAMEWORK ..."
|
||||
echo "======================================================================"
|
||||
echo
|
||||
echo
|
||||
psql -vQUIET=1 -f tests/pgtap.sql $TEST_DATABASE || exit 1
|
||||
|
||||
echo
|
||||
echo
|
||||
echo "======================================================================"
|
||||
echo "RUNNING DATABASE TESTS ..."
|
||||
echo "======================================================================"
|
||||
echo
|
||||
echo
|
||||
cd tests
|
||||
if [ -d admin ]; then
|
||||
pg_prove -d $TEST_DATABASE `find admin/ -type f -name '*.sql'` || exit 1
|
||||
fi
|
||||
if [ -d user ]; then
|
||||
pg_prove -U $TEST_USER -d $TEST_DATABASE `find user/ -type f -name '*.sql'` || exit 1
|
||||
fi
|
||||
if [ -x dirty/run-dirty-tests.sh ]; then
|
||||
( cd dirty; exec ./run-dirty-tests.sh ) || exit 1
|
||||
fi
|
51
build/post-build.d/20-import-tools.sh
Normal file
51
build/post-build.d/20-import-tools.sh
Normal file
|
@ -0,0 +1,51 @@
|
|||
#!/bin/bash
|
||||
|
||||
TESTDIR=`mktemp -d`
|
||||
cp -Rapv legacyworlds-server-DIST/target/legacyworlds/legacyworlds-server-* $TESTDIR
|
||||
|
||||
|
||||
cd $TESTDIR/legacyworlds-server-*/sql
|
||||
cat > db-config.txt <<EOF
|
||||
admin=$USER
|
||||
db=tests
|
||||
user=tests
|
||||
password=tests
|
||||
EOF
|
||||
psql -vQUIET=1 -vON_ERROR_STOP=1 -e --file database.sql || exit 1
|
||||
cd ..
|
||||
|
||||
cat > data-source.xml <<EOF
|
||||
<?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 name="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
|
||||
<property name="driverClassName" value="org.postgresql.Driver" />
|
||||
<property name="url" value="jdbc:postgresql:tests" />
|
||||
<property name="username" value="tests" />
|
||||
<property name="password" value="tests" />
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
EOF
|
||||
|
||||
java legacyworlds-server-main-*.jar --run-tool ImportText data/i18n-text.xml || exit 1
|
||||
java legacyworlds-server-main-*.jar --run-tool ImportEvents data/event-definitions.xml || exit 1
|
||||
java legacyworlds-server-main-*.jar --run-tool ImportResources data/resources.xml || exit 1
|
||||
java legacyworlds-server-main-*.jar --run-tool ImportTechs data/techs.xml || exit 1
|
||||
java legacyworlds-server-main-*.jar --run-tool ImportTechGraph data/tech-graph.xml || exit 1
|
||||
java legacyworlds-server-main-*.jar --run-tool ImportBuildables data/buildables.xml || exit 1
|
||||
|
||||
java legacyworlds-server-main-*.jar &
|
||||
sleep 10
|
||||
if ! ps ux | grep -q 'java -jar legacyworlds-server-main'; then
|
||||
exit 1;
|
||||
fi
|
||||
java legacyworlds-server-main-*.jar --run-tool Stop || {
|
||||
killall java
|
||||
exit 1;
|
||||
}
|
||||
|
||||
java -jar legacyworlds-server-main-1.0.0-0.jar --run-tool CreateUser 'test@example.org 12blah34bleh en' || exit 1
|
||||
java -jar legacyworlds-server-main-1.0.0-0.jar --run-tool CreateSuperuser 'test@example.org Turlututu' || exit 1
|
67
legacyworlds-server-DIST/pom.xml
Normal file
67
legacyworlds-server-DIST/pom.xml
Normal file
|
@ -0,0 +1,67 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<artifactId>legacyworlds-server</artifactId>
|
||||
<groupId>com.deepclone.lw</groupId>
|
||||
<version>1.0.0</version>
|
||||
<relativePath>../legacyworlds-server/pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>legacyworlds-server-DIST</artifactId>
|
||||
<version>${legacyworlds.version.main}.${legacyworlds.version.release}-${legacyworlds.version.build}</version>
|
||||
|
||||
<packaging>pom</packaging>
|
||||
<name>Legacy Worlds - Server - Packaging</name>
|
||||
<description>This Maven module is responsible for creating the Legacy Worlds server's packaging.</description>
|
||||
|
||||
|
||||
<!-- Depend solely on the server's JAR, other dependencies will update automatically -->
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.deepclone.lw</groupId>
|
||||
<artifactId>legacyworlds-server-main</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<!-- Clean the target directory before generating the distribution -->
|
||||
<plugin>
|
||||
<artifactId>maven-clean-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>clean-before-assembly</id>
|
||||
<phase>initialize</phase>
|
||||
<goals>
|
||||
<goal>clean</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<!-- Use the assembly plug-in to generate the distribution -->
|
||||
<plugin>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>distribution-assembly</id>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>single</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<attach>false</attach>
|
||||
<finalName>legacyworlds-server-${project.version}</finalName>
|
||||
<descriptors>
|
||||
<descriptor>src/server.xml</descriptor>
|
||||
</descriptors>
|
||||
<appendAssemblyId>false</appendAssemblyId>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
|
||||
</build>
|
||||
</project>
|
79
legacyworlds-server-DIST/src/server.xml
Normal file
79
legacyworlds-server-DIST/src/server.xml
Normal file
|
@ -0,0 +1,79 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<assembly
|
||||
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
|
||||
|
||||
<!-- Legacy Worlds server assembly -->
|
||||
|
||||
<id>legacyworlds-server</id>
|
||||
<formats>
|
||||
<format>dir</format>
|
||||
</formats>
|
||||
<includeBaseDirectory>false</includeBaseDirectory>
|
||||
|
||||
<dependencySets>
|
||||
|
||||
<!-- The server's main archive -->
|
||||
<dependencySet>
|
||||
<useProjectArtifact>false</useProjectArtifact>
|
||||
<outputDirectory>.</outputDirectory>
|
||||
<unpack>false</unpack>
|
||||
<includes>
|
||||
<include>com.deepclone.lw:legacyworlds-server-main:jar</include>
|
||||
</includes>
|
||||
</dependencySet>
|
||||
|
||||
<!-- Libraries - both internal and external dependencies -->
|
||||
<dependencySet>
|
||||
<useProjectArtifact>false</useProjectArtifact>
|
||||
<outputDirectory>lib</outputDirectory>
|
||||
<unpack>false</unpack>
|
||||
<includes>
|
||||
<include>*:jar</include>
|
||||
</includes>
|
||||
<excludes>
|
||||
<exclude>com.deepclone.lw:legacyworlds-server-main:jar</exclude>
|
||||
</excludes>
|
||||
</dependencySet>
|
||||
|
||||
</dependencySets>
|
||||
|
||||
<fileSets>
|
||||
|
||||
<!-- Database definitions -->
|
||||
<fileSet>
|
||||
<directory>../legacyworlds-server-data/db-structure</directory>
|
||||
<outputDirectory>sql</outputDirectory>
|
||||
<includes>
|
||||
<include>*.sql</include>
|
||||
<include>parts/**</include>
|
||||
<include>db-config.sample.txt</include>
|
||||
</includes>
|
||||
</fileSet>
|
||||
|
||||
<!-- Default data -->
|
||||
<fileSet>
|
||||
<directory>../legacyworlds-server-main/data</directory>
|
||||
<outputDirectory>data</outputDirectory>
|
||||
<includes>
|
||||
<include>i18n/**</include>
|
||||
<include>**.xml</include>
|
||||
</includes>
|
||||
</fileSet>
|
||||
|
||||
</fileSets>
|
||||
|
||||
<files>
|
||||
|
||||
<!-- Data source configuration -->
|
||||
<file>
|
||||
<source>../legacyworlds-server-main/data-source.sample.xml</source>
|
||||
<fileMode>0600</fileMode>
|
||||
<outputDirectory>.</outputDirectory>
|
||||
</file>
|
||||
|
||||
</files>
|
||||
|
||||
|
||||
</assembly>
|
|
@ -4,12 +4,12 @@
|
|||
<parent>
|
||||
<artifactId>legacyworlds-server-beans</artifactId>
|
||||
<groupId>com.deepclone.lw</groupId>
|
||||
<version>5.99.1</version>
|
||||
<version>1.0.0</version>
|
||||
<relativePath>../legacyworlds-server-beans/pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<groupId>com.deepclone.lw</groupId>
|
||||
<artifactId>legacyworlds-server-beans-accounts</artifactId>
|
||||
<name>Legacy Worlds account management</name>
|
||||
<version>5.99.1</version>
|
||||
<name>Legacy Worlds - Server - Components - Accounts</name>
|
||||
<version>${legacyworlds.version.main}.${legacyworlds.version.release}-${legacyworlds.version.build}</version>
|
||||
<description>This package contains the beans responsible for managing accounts, including registration, inactivity checks, bans and authentication.</description>
|
||||
</project>
|
|
@ -11,8 +11,8 @@ import javax.sql.DataSource;
|
|||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.dao.EmptyResultDataAccessException;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
|
||||
|
||||
import com.deepclone.lw.cmd.admin.users.SessionTerminationType;
|
||||
import com.deepclone.lw.cmd.admin.users.UserSession;
|
||||
|
@ -25,7 +25,7 @@ public class UserSessionDAOBean
|
|||
implements UserSessionDAO , InitializingBean
|
||||
{
|
||||
|
||||
private SimpleJdbcTemplate dTemplate;
|
||||
private JdbcTemplate dTemplate;
|
||||
|
||||
private final RowMapper< UserSession > mSession;
|
||||
|
||||
|
@ -66,7 +66,7 @@ public class UserSessionDAOBean
|
|||
@Autowired( required = true )
|
||||
public void setDataSource( DataSource dataSource )
|
||||
{
|
||||
this.dTemplate = new SimpleJdbcTemplate( dataSource );
|
||||
this.dTemplate = new JdbcTemplate( dataSource );
|
||||
|
||||
this.fSessionStart = new StoredProc( dataSource , "users" , "sessions_login" );
|
||||
this.fSessionStart.addParameter( "credentials_id" , Types.INTEGER );
|
||||
|
@ -84,7 +84,7 @@ public class UserSessionDAOBean
|
|||
@Override
|
||||
public void afterPropertiesSet( )
|
||||
{
|
||||
this.dTemplate.getJdbcOperations( ).execute( "SELECT users.sessions_server_restart()" );
|
||||
this.dTemplate.execute( "SELECT users.sessions_server_restart()" );
|
||||
}
|
||||
|
||||
|
|
@ -11,8 +11,8 @@ import javax.sql.DataSource;
|
|||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.dao.EmptyResultDataAccessException;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
|
||||
|
||||
import com.deepclone.lw.cmd.admin.users.AccountBanEntry;
|
||||
import com.deepclone.lw.cmd.admin.users.AccountListEntry;
|
||||
|
@ -55,7 +55,7 @@ public class UsersDAOBean
|
|||
private final AccountListMapper< AccountListEntry > mAccountList;
|
||||
private final AccountListMapper< AccountViewEntry > mAccountView;
|
||||
|
||||
private SimpleJdbcTemplate dTemplate;
|
||||
private JdbcTemplate dTemplate;
|
||||
|
||||
private StoredProc fCreateAccount;
|
||||
private StoredProc fMailFailure;
|
||||
|
@ -181,7 +181,7 @@ public class UsersDAOBean
|
|||
@Autowired( required = true )
|
||||
public void setDataSource( DataSource dataSource )
|
||||
{
|
||||
this.dTemplate = new SimpleJdbcTemplate( dataSource );
|
||||
this.dTemplate = new JdbcTemplate( dataSource );
|
||||
|
||||
this.fCreateAccount = new StoredProc( dataSource , "users" , "create_credentials" );
|
||||
this.fCreateAccount.addParameter( "address" , Types.VARCHAR );
|
||||
|
@ -426,7 +426,7 @@ public class UsersDAOBean
|
|||
@Override
|
||||
public void expireRequests( )
|
||||
{
|
||||
this.dTemplate.getJdbcOperations( ).execute( "SELECT users.expire_requests( )" );
|
||||
this.dTemplate.execute( "SELECT users.expire_requests( )" );
|
||||
}
|
||||
|
||||
|
||||
|
@ -469,7 +469,7 @@ public class UsersDAOBean
|
|||
@Override
|
||||
public void processVacations( )
|
||||
{
|
||||
this.dTemplate.getJdbcOperations( ).execute( "SELECT users.process_vacations( )" );
|
||||
this.dTemplate.execute( "SELECT users.process_vacations( )" );
|
||||
}
|
||||
|
||||
|
||||
|
@ -529,7 +529,7 @@ public class UsersDAOBean
|
|||
@Override
|
||||
public void deleteOldAccounts( )
|
||||
{
|
||||
this.dTemplate.getJdbcOperations( ).execute( "SELECT users.delete_old_accounts( )" );
|
||||
this.dTemplate.execute( "SELECT users.delete_old_accounts( )" );
|
||||
}
|
||||
|
||||
|
|
@ -13,8 +13,8 @@ import javax.sql.DataSource;
|
|||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.dao.EmptyResultDataAccessException;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
|
||||
|
||||
import com.deepclone.lw.cmd.admin.adata.AdminOverview;
|
||||
import com.deepclone.lw.interfaces.admin.AdminDAO;
|
||||
|
@ -34,7 +34,7 @@ public class AdminDAOBean
|
|||
private static final String sGetAdminByName = "SELECT * FROM admin.admins_view WHERE lower( name ) = ?";
|
||||
private static final String sListAdministrators = "SELECT * FROM admin.admins_view ORDER BY active DESC , name";
|
||||
|
||||
private SimpleJdbcTemplate dTemplate;
|
||||
private JdbcTemplate dTemplate;
|
||||
|
||||
private final RowMapper< AdminRecord > mAdminRecord;
|
||||
private final RowMapper< AdminOverview > mAdminOverview;
|
||||
|
@ -89,7 +89,7 @@ public class AdminDAOBean
|
|||
@Autowired( required = true )
|
||||
public void setDataSource( DataSource dataSource )
|
||||
{
|
||||
this.dTemplate = new SimpleJdbcTemplate( dataSource );
|
||||
this.dTemplate = new JdbcTemplate( dataSource );
|
||||
|
||||
this.fCreateAdmin = new StoredProc( dataSource , "admin" , "create_admin" );
|
||||
this.fCreateAdmin.addParameter( "address" , Types.VARCHAR );
|
|
@ -12,8 +12,8 @@ import javax.sql.DataSource;
|
|||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.dao.EmptyResultDataAccessException;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
|
||||
|
||||
import com.deepclone.lw.cmd.admin.bans.ArchivedBanRequest;
|
||||
import com.deepclone.lw.cmd.admin.bans.BanRequest;
|
||||
|
@ -51,7 +51,7 @@ public class BansDAOBean
|
|||
}
|
||||
}
|
||||
|
||||
private SimpleJdbcTemplate dTemplate;
|
||||
private JdbcTemplate dTemplate;
|
||||
|
||||
private final BanRequestMapper< BanRequest > mPending;
|
||||
private final BanRequestMapper< BanRequest > mArchived;
|
||||
|
@ -122,7 +122,7 @@ public class BansDAOBean
|
|||
@Autowired( required = true )
|
||||
public void setDataSource( DataSource dataSource )
|
||||
{
|
||||
this.dTemplate = new SimpleJdbcTemplate( dataSource );
|
||||
this.dTemplate = new JdbcTemplate( dataSource );
|
||||
|
||||
this.fRequestBanAddress = new StoredProc( dataSource , "admin" , "request_ban_on_address" );
|
||||
this.fRequestBanAddress.addParameter( "admin_id" , Types.INTEGER );
|
||||
|
@ -251,14 +251,14 @@ public class BansDAOBean
|
|||
@Override
|
||||
public void expireBanRequests( )
|
||||
{
|
||||
this.dTemplate.getJdbcOperations( ).execute( "SELECT admin.expire_ban_requests( )" );
|
||||
this.dTemplate.execute( "SELECT admin.expire_ban_requests( )" );
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void expireWarnings( )
|
||||
{
|
||||
this.dTemplate.getJdbcOperations( ).execute( "SELECT admin.expire_warnings( )" );
|
||||
this.dTemplate.execute( "SELECT admin.expire_warnings( )" );
|
||||
}
|
||||
|
||||
|
|
@ -12,8 +12,8 @@ import javax.sql.DataSource;
|
|||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.dao.EmptyResultDataAccessException;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
import org.springframework.transaction.TransactionStatus;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
@ -70,7 +70,7 @@ public class PreferenceDefinitionsBean
|
|||
private SystemLogger logger;
|
||||
private Translator translator;
|
||||
|
||||
private SimpleJdbcTemplate dTemplate;
|
||||
private JdbcTemplate dTemplate;
|
||||
|
||||
private StoredProc uocGroup;
|
||||
private StoredProc uocDef;
|
||||
|
@ -95,7 +95,7 @@ public class PreferenceDefinitionsBean
|
|||
@Autowired( required = true )
|
||||
public void setDataSource( DataSource dataSource )
|
||||
{
|
||||
this.dTemplate = new SimpleJdbcTemplate( dataSource );
|
||||
this.dTemplate = new JdbcTemplate( dataSource );
|
||||
|
||||
this.uocGroup = new StoredProc( dataSource , "defs" , "uoc_preference_group" );
|
||||
this.uocGroup.addParameter( "name" , Types.VARCHAR );
|
|
@ -12,8 +12,8 @@ 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 org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
|
||||
|
||||
import com.deepclone.lw.interfaces.prefs.AccountPreferences;
|
||||
import com.deepclone.lw.interfaces.prefs.Preference;
|
||||
|
@ -30,7 +30,7 @@ public class PreferencesDAOBean
|
|||
implements PreferencesDAO
|
||||
{
|
||||
|
||||
private SimpleJdbcTemplate dTemplate;
|
||||
private JdbcTemplate dTemplate;
|
||||
private PreferenceTypesRegistry registry;
|
||||
private StoredProc fReset;
|
||||
private StoredProc fSetPref;
|
||||
|
@ -39,7 +39,7 @@ public class PreferencesDAOBean
|
|||
@Autowired( required = true )
|
||||
public void setDataSource( DataSource dataSource )
|
||||
{
|
||||
this.dTemplate = new SimpleJdbcTemplate( dataSource );
|
||||
this.dTemplate = new JdbcTemplate( dataSource );
|
||||
|
||||
this.fReset = new StoredProc( dataSource , "users" , "reset_preferences" );
|
||||
this.fReset.addParameter( "a_id" , Types.INTEGER );
|
|
@ -0,0 +1,26 @@
|
|||
<?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.1.xsd">
|
||||
|
||||
<bean id="accountCleanup" class="com.deepclone.lw.beans.acm.AccountCleanupBean" />
|
||||
<bean id="accountManagement" class="com.deepclone.lw.beans.acm.AccountManagementBean" />
|
||||
<bean id="adminDao" class="com.deepclone.lw.beans.admin.AdminDAOBean" />
|
||||
<bean id="administration" class="com.deepclone.lw.beans.admin.AdministrationBean" />
|
||||
<bean id="adminRecap" class="com.deepclone.lw.beans.admin.AdminRecapBean" />
|
||||
<bean id="bansDao" class="com.deepclone.lw.beans.admin.BansDAOBean" />
|
||||
<bean id="bansProcessor" class="com.deepclone.lw.beans.admin.BansProcessorBean" />
|
||||
<bean id="defaultPreferences" class="com.deepclone.lw.beans.prefs.DefaultPreferencesBean" />
|
||||
<bean id="ipBan" class="com.deepclone.lw.beans.admin.IpBanBean" />
|
||||
<bean id="preferenceDefinitions" class="com.deepclone.lw.beans.prefs.PreferenceDefinitionsBean" />
|
||||
<bean id="preferencesDAO" class="com.deepclone.lw.beans.prefs.PreferencesDAOBean" />
|
||||
<bean id="preferenceTypesRegistry"
|
||||
class="com.deepclone.lw.beans.prefs.PreferenceTypesRegistryBean" />
|
||||
<bean id="quitProcessor" class="com.deepclone.lw.beans.acm.QuitProcessorBean" />
|
||||
<bean id="requestsExpiration" class="com.deepclone.lw.beans.acm.RequestsExpirationBean" />
|
||||
<bean id="usersDAO" class="com.deepclone.lw.beans.acm.UsersDAOBean" />
|
||||
<bean id="userSessionDao" class="com.deepclone.lw.beans.acm.UserSessionDAOBean" />
|
||||
<bean id="vacationProcessor" class="com.deepclone.lw.beans.acm.VacationProcessorBean" />
|
||||
|
||||
</beans>
|
0
legacyworlds-server-beans-accounts/src/test/java/.empty
Normal file
0
legacyworlds-server-beans-accounts/src/test/java/.empty
Normal file
|
@ -4,7 +4,8 @@
|
|||
<parent>
|
||||
<artifactId>legacyworlds-server-beans</artifactId>
|
||||
<groupId>com.deepclone.lw</groupId>
|
||||
<version>5.99.1</version>
|
||||
<version>1.0.0</version>
|
||||
<relativePath>../legacyworlds-server-beans/pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
|
@ -12,14 +13,16 @@
|
|||
<dependency>
|
||||
<groupId>com.thoughtworks.xstream</groupId>
|
||||
<artifactId>xstream</artifactId>
|
||||
<version>${com.thoughtworks.xstream.version}</version>
|
||||
<type>jar</type>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>postgresql</groupId>
|
||||
<artifactId>postgresql</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<groupId>com.deepclone.lw</groupId>
|
||||
<artifactId>legacyworlds-server-beans-bt</artifactId>
|
||||
<version>5.99.1</version>
|
||||
<name>Legacy Worlds bug tracking system</name>
|
||||
<name>Legacy Worlds - Server - Components - Bug tracking system</name>
|
||||
<version>${legacyworlds.version.main}.${legacyworlds.version.release}-${legacyworlds.version.build}</version>
|
||||
</project>
|
|
@ -11,9 +11,8 @@ import javax.sql.DataSource;
|
|||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.dao.EmptyResultDataAccessException;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
|
||||
|
||||
import com.deepclone.lw.cmd.admin.adata.Administrator;
|
||||
import com.deepclone.lw.cmd.bt.data.*;
|
||||
import com.deepclone.lw.interfaces.bt.BugsDAO;
|
||||
|
@ -25,7 +24,7 @@ public class BugsDAOBean
|
|||
implements BugsDAO
|
||||
{
|
||||
|
||||
private SimpleJdbcTemplate dTemplate;
|
||||
private JdbcTemplate dTemplate;
|
||||
|
||||
private final RowMapper< BugReport > mBugReport;
|
||||
private final RowMapper< BugEvent > mBugEvent;
|
||||
|
@ -129,7 +128,7 @@ public class BugsDAOBean
|
|||
@Autowired( required = true )
|
||||
public void setDataSource( DataSource dataSource )
|
||||
{
|
||||
this.dTemplate = new SimpleJdbcTemplate( dataSource );
|
||||
this.dTemplate = new JdbcTemplate( dataSource );
|
||||
|
||||
this.fPostUserReport = new StoredProc( dataSource , "bugs" , "post_player_report" );
|
||||
this.fPostUserReport.addParameter( "empire_id" , Types.INTEGER );
|
|
@ -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,52 @@
|
|||
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. If a mining priority is present, set it, otherwise leave the field to its default
|
||||
* <code>null</code> value.
|
||||
*/
|
||||
@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" ) );
|
||||
|
||||
int priority = rs.getInt( "mining_priority" );
|
||||
if ( !rs.wasNull( ) ) {
|
||||
empRes.setMiningPriority( priority );
|
||||
}
|
||||
|
||||
return empRes;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,359 @@
|
|||
package com.deepclone.lw.beans.bt.es;
|
||||
|
||||
|
||||
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.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.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;
|
||||
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.ResearchGraphInformation;
|
||||
import com.deepclone.lw.beans.bt.es.data.ResearchInformation;
|
||||
import com.deepclone.lw.beans.bt.es.data.ResearchLineInformation;
|
||||
import com.deepclone.lw.beans.bt.es.data.ResourceDeltaInformation;
|
||||
import com.deepclone.lw.beans.bt.es.data.ResourceProviderInformation;
|
||||
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
|
||||
{
|
||||
/** Beginning of all dump SQL queries */
|
||||
private static final String SQL_START = "SELECT * FROM bugs.dump_";
|
||||
|
||||
/** Ending of (almost) all dump SQL queries */
|
||||
private static final String SQL_END = "_view WHERE empire_id = ?";
|
||||
|
||||
/** 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;
|
||||
|
||||
/** SQL query that accesses the empire's planets dump view */
|
||||
private static final String Q_PLANETS = SQL_START + "planets" + SQL_END;
|
||||
|
||||
/** SQL query that accesses the planetary resources dump view */
|
||||
private static final String Q_PLANET_RESOURCES = SQL_START + "planet_resources" + SQL_END;
|
||||
|
||||
/** SQL query that accesses the build queues dump view */
|
||||
private static final String Q_BUILD_QUEUES = SQL_START + "queues" + SQL_END + " ORDER BY queue_order";
|
||||
|
||||
/** SQL query that accesses the buildings dump view */
|
||||
private static final String Q_BUILDINGS = SQL_START + "buildings" + SQL_END;
|
||||
|
||||
/** SQL query that accesses the fleets dump view */
|
||||
private static final String Q_FLEETS = SQL_START + "fleets" + SQL_END;
|
||||
|
||||
/** SQL query that accesses the ships dump view */
|
||||
private static final String Q_SHIPS = SQL_START + "ships" + SQL_END;
|
||||
|
||||
/** 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 resources row mapper */
|
||||
private final EmpireResourceInformationMapper mResources;
|
||||
|
||||
/** Empire research row mapper */
|
||||
private final ResearchInformationMapper mResearch;
|
||||
|
||||
/** Empire-owned planet row mapper */
|
||||
private final PlanetInformationMapper mPlanet;
|
||||
|
||||
/** Planet resources row mapper */
|
||||
private final ResourceRowMapper mPlanetResources;
|
||||
|
||||
/** 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 ,
|
||||
ResearchLineInformation.class , ResearchGraphInformation.class , ResourceDeltaInformation.class ,
|
||||
ResourceProviderInformation.class , ShipsInformation.class , SystemInformation.class
|
||||
} );
|
||||
|
||||
this.mMainInfo = new DebugInformationMapper( );
|
||||
this.mResources = new EmpireResourceInformationMapper( );
|
||||
this.mResearch = new ResearchInformationMapper( );
|
||||
this.mPlanet = new PlanetInformationMapper( );
|
||||
this.mPlanetResources = new ResourceRowMapper( );
|
||||
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 )
|
||||
{
|
||||
DebugInformation empireDump = this.dTemplate.queryForObject( Q_EMPIRE , this.mMainInfo , empireId );
|
||||
this.getResources( empireId , empireDump );
|
||||
this.getResearch( empireId , empireDump );
|
||||
|
||||
this.getPlanets( empireId , empireDump );
|
||||
this.getFleets( empireId , empireDump );
|
||||
|
||||
return this.xStream.toXML( empireDump );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
* <p>
|
||||
* Read all research-related information from the appropriate dump view, and add corresponding
|
||||
* entries to the top-level instance.
|
||||
*
|
||||
* @param empireId
|
||||
* the empire's identifier
|
||||
* @param empireDump
|
||||
* the top-level instance
|
||||
*/
|
||||
private void getResearch( int empireId , DebugInformation empireDump )
|
||||
{
|
||||
for ( ResearchInformation ri : this.dTemplate.query( Q_RESEARCH , this.mResearch , empireId ) ) {
|
||||
empireDump.getResearch( ).add( ri );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get empire planets and related information
|
||||
*
|
||||
* <p>
|
||||
* Read the planet list and basic planet information from the appropriate dump view, then read
|
||||
* all extra information (resources, build queues, buildings).
|
||||
*
|
||||
* @param empireId
|
||||
* the empire's identifier
|
||||
* @param empireDump
|
||||
* the top-level instance
|
||||
*/
|
||||
private void getPlanets( int empireId , DebugInformation empireDump )
|
||||
{
|
||||
HashMap< Integer , PlanetInformation > planets = new HashMap< Integer , PlanetInformation >( );
|
||||
for ( PlanetInformation planet : this.dTemplate.query( Q_PLANETS , this.mPlanet , empireId ) ) {
|
||||
empireDump.getPlanets( ).add( planet );
|
||||
planets.put( planet.getId( ) , planet );
|
||||
}
|
||||
|
||||
this.getPlanetResources( empireId , planets );
|
||||
this.getBuildQueues( empireId , planets );
|
||||
this.getBuildings( empireId , planets );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add resources information to planets
|
||||
*
|
||||
* <p>
|
||||
* Access resources information for the empire's planets and add the records to each planet.
|
||||
*
|
||||
* @param empireId
|
||||
* the empire's identifier
|
||||
* @param planets
|
||||
* a map associating planet records with their identifier
|
||||
*/
|
||||
private void getPlanetResources( int empireId , Map< Integer , PlanetInformation > planets )
|
||||
{
|
||||
for ( PlanetResourceRow resRow : this.dTemplate.query( Q_PLANET_RESOURCES , this.mPlanetResources , empireId ) ) {
|
||||
PlanetInformation planet = planets.get( resRow.getPlanetId( ) );
|
||||
planet.getResourceDeltas( ).add( resRow.getDelta( ) );
|
||||
|
||||
ResourceProviderInformation resProv = resRow.getProvider( );
|
||||
if ( resProv != null ) {
|
||||
planet.getResourceProviders( ).add( resProv );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add build queue information to planet records
|
||||
*
|
||||
* <p>
|
||||
* Access the contents of build queues and add the records to the corresponding planets.
|
||||
*
|
||||
* @param empireId
|
||||
* the empire's identifier
|
||||
* @param planets
|
||||
* the map of planets by identifier
|
||||
*/
|
||||
private void getBuildQueues( int empireId , Map< Integer , PlanetInformation > planets )
|
||||
{
|
||||
for ( QueueItemInformation queueItem : this.dTemplate.query( Q_BUILD_QUEUES , this.mQueueItem , empireId ) ) {
|
||||
PlanetInformation planet = planets.get( queueItem.getPlanetId( ) );
|
||||
|
||||
QueueInformation queue;
|
||||
if ( queueItem.isMilitary( ) ) {
|
||||
queue = planet.getMilitaryQueue( );
|
||||
} else {
|
||||
queue = planet.getCivilianQueue( );
|
||||
}
|
||||
|
||||
queue.getItems( ).add( queueItem );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add buildings information to planet records
|
||||
*
|
||||
* <p>
|
||||
* Access the contents of the buildings dump view and add the building records to the
|
||||
* corresponding planets.
|
||||
*
|
||||
* @param empireId
|
||||
* the empire's identifier
|
||||
* @param planets
|
||||
* the map of planets by identifier
|
||||
*/
|
||||
private void getBuildings( int empireId , Map< Integer , PlanetInformation > planets )
|
||||
{
|
||||
for ( BuildingsInformation bi : this.dTemplate.query( Q_BUILDINGS , this.mBuildings , empireId ) ) {
|
||||
planets.get( bi.getPlanetId( ) ).getBuildings( ).add( bi );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieve information about the empire's fleets
|
||||
*
|
||||
* <p>
|
||||
* Access the list of fleets, add the records to the top-level instance, then retrieve all
|
||||
* necessary information.
|
||||
*
|
||||
* @param empireId
|
||||
* the empire's identifier
|
||||
* @param empireDump
|
||||
* the top-level empire dump
|
||||
*/
|
||||
private void getFleets( int empireId , DebugInformation empireDump )
|
||||
{
|
||||
Map< Long , FleetInformation > fleets = new HashMap< Long , FleetInformation >( );
|
||||
for ( FleetInformation fi : this.dTemplate.query( Q_FLEETS , this.mFleet , empireId ) ) {
|
||||
empireDump.getFleets( ).add( fi );
|
||||
fleets.put( fi.getId( ) , fi );
|
||||
}
|
||||
this.getShips( empireId , fleets );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add ships information to fleet records
|
||||
*
|
||||
* <p>
|
||||
* Retrieve information about ships and add the records to the corresponding fleets.
|
||||
*
|
||||
* @param empireId
|
||||
* the empire's identifier
|
||||
* @param fleets
|
||||
* the map of fleets by identifier
|
||||
*/
|
||||
private void getShips( int empireId , Map< Long , FleetInformation > fleets )
|
||||
{
|
||||
for ( ShipsInformation si : this.dTemplate.query( Q_SHIPS , this.mShips , empireId ) ) {
|
||||
fleets.get( si.getFleetId( ) ).getShips( ).add( si );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -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,96 @@
|
|||
package com.deepclone.lw.beans.bt.es;
|
||||
|
||||
|
||||
import com.deepclone.lw.beans.bt.es.data.ResourceDeltaInformation;
|
||||
import com.deepclone.lw.beans.bt.es.data.ResourceProviderInformation;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Planet resource row information
|
||||
*
|
||||
* <p>
|
||||
* Planet resources and resource providers are both extracted from the same
|
||||
* <code>bugs.planet_resources_view</code> rows. Because of that, this class is used to transmit the
|
||||
* information (as a {@link ResourceDeltaInformation} instance and an optional
|
||||
* {@link ResourceProviderInformation} instance) from the row mapper to the summary creation
|
||||
* component.
|
||||
*
|
||||
* @author <a href="mailto:tseeker@legacyworlds.com">E. Benoît</a>
|
||||
*/
|
||||
class PlanetResourceRow
|
||||
{
|
||||
|
||||
/** Identifier of the planet */
|
||||
private final int planetId;
|
||||
|
||||
/** Resource delta information */
|
||||
private final ResourceDeltaInformation delta = new ResourceDeltaInformation( );
|
||||
|
||||
/** Resource provider information */
|
||||
private ResourceProviderInformation provider;
|
||||
|
||||
|
||||
/**
|
||||
* Initialise the instance by setting the planet identifier
|
||||
*
|
||||
* @param planetId
|
||||
* the planet's identifier
|
||||
*/
|
||||
public PlanetResourceRow( int planetId )
|
||||
{
|
||||
this.planetId = planetId;
|
||||
}
|
||||
|
||||
|
||||
/** @return the planet's identifier */
|
||||
public int getPlanetId( )
|
||||
{
|
||||
return this.planetId;
|
||||
}
|
||||
|
||||
|
||||
/** @return the resource delta information record */
|
||||
public ResourceDeltaInformation getDelta( )
|
||||
{
|
||||
return this.delta;
|
||||
}
|
||||
|
||||
|
||||
/** @return the resource provider information record */
|
||||
public ResourceProviderInformation getProvider( )
|
||||
{
|
||||
return this.provider;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the resource provider information record
|
||||
*
|
||||
* @param provider
|
||||
* the resource provider information record
|
||||
*/
|
||||
public void setProvider( ResourceProviderInformation provider )
|
||||
{
|
||||
this.provider = provider;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the name of the resource
|
||||
*
|
||||
* <p>
|
||||
* This method should be called once the rest of the record(s) has been initialised. It will set
|
||||
* the resource name on both the delta and the provider (if the latter exists).
|
||||
*
|
||||
* @param resource
|
||||
* the name of the resource
|
||||
*/
|
||||
public void setResource( String resource )
|
||||
{
|
||||
this.delta.setResource( resource );
|
||||
if ( this.provider != null ) {
|
||||
this.provider.setResource( resource );
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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,49 @@
|
|||
package com.deepclone.lw.beans.bt.es;
|
||||
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.postgresql.util.PGobject;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
|
||||
import com.deepclone.lw.beans.bt.es.data.ResearchGraphInformation;
|
||||
import com.deepclone.lw.beans.bt.es.data.ResearchInformation;
|
||||
import com.deepclone.lw.beans.bt.es.data.TechnologyState;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Research information row mapper
|
||||
*
|
||||
* <p>
|
||||
* This class maps rows from <code>bugs.dump_research_view</code> into
|
||||
* {@link ResearchGraphInformation} 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 ResearchGraphInformation} instance from the row's contents.
|
||||
*/
|
||||
@Override
|
||||
public ResearchInformation mapRow( ResultSet rs , int rowNum )
|
||||
throws SQLException
|
||||
{
|
||||
ResearchGraphInformation ri = new ResearchGraphInformation( );
|
||||
ri.setName( rs.getString( "name" ) );
|
||||
ri.setState( TechnologyState.valueOf( ( (PGobject) rs.getObject( "state" ) ).toString( ) ) );
|
||||
if ( ri.getState( ) == TechnologyState.RESEARCH ) {
|
||||
ri.setPoints( rs.getDouble( "points" ) );
|
||||
ri.setPriority( rs.getInt( "priority" ) );
|
||||
}
|
||||
return ri;
|
||||
}
|
||||
}
|
|
@ -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.ResourceProviderInformation;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Mapper which extract planet resources and resource providers information
|
||||
*
|
||||
* <p>
|
||||
* This class maps rows from <code>bugs.dump_planet_resources_view</code> into
|
||||
* {@link PlanetResourceRow} instances.
|
||||
*
|
||||
* @author <a href="mailto:tseeker@legacyworlds.com">E. Benoît</a>
|
||||
*
|
||||
*/
|
||||
class ResourceRowMapper
|
||||
implements RowMapper< PlanetResourceRow >
|
||||
{
|
||||
|
||||
/**
|
||||
* Map a row from <code>bugs.dump_planet_resources_view</code>
|
||||
*
|
||||
* <p>
|
||||
* Generate the {@link PlanetResourceRow} instance with the correct planet identifier, resource
|
||||
* name, income and upkeep. If there is also a resource provider, attach a
|
||||
* {@link ResourceProviderInformation} instance to the result, and set its mining priority if
|
||||
* one exists.
|
||||
*/
|
||||
@Override
|
||||
public PlanetResourceRow mapRow( ResultSet rs , int rowNum )
|
||||
throws SQLException
|
||||
{
|
||||
PlanetResourceRow row = new PlanetResourceRow( rs.getInt( "planet_id" ) );
|
||||
|
||||
row.getDelta( ).setIncome( rs.getDouble( "pres_income" ) );
|
||||
row.getDelta( ).setUpkeep( rs.getDouble( "pres_upkeep" ) );
|
||||
|
||||
double pCapacity = rs.getDouble( "resprov_quantity_max" );
|
||||
if ( !rs.wasNull( ) ) {
|
||||
ResourceProviderInformation rpi = new ResourceProviderInformation( );
|
||||
rpi.setMaximalQuantity( pCapacity );
|
||||
rpi.setCurrentQuantity( rs.getDouble( "resprov_quantity" ) );
|
||||
rpi.setDifficulty( rs.getDouble( "resprov_difficulty" ) );
|
||||
rpi.setRecovery( rs.getDouble( "resprov_recovery" ) );
|
||||
|
||||
int miningPriority = rs.getInt( "mining_priority" );
|
||||
if ( !rs.wasNull( ) ) {
|
||||
rpi.setMiningPriority( miningPriority );
|
||||
}
|
||||
|
||||
row.setProvider( rpi );
|
||||
}
|
||||
|
||||
row.setResource( rs.getString( "resource_name" ) );
|
||||
return row;
|
||||
}
|
||||
|
||||
}
|
|
@ -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,8 +1,8 @@
|
|||
package com.deepclone.lw.beans.bt.esdata;
|
||||
package com.deepclone.lw.beans.bt.es.data;
|
||||
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.LinkedList;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
|
@ -19,7 +19,7 @@ public class DebugInformation
|
|||
|
||||
@XStreamAsAttribute
|
||||
@XStreamAlias( "dump-version" )
|
||||
private int version = 1;
|
||||
private int version = 2;
|
||||
|
||||
private SystemInformation system = new SystemInformation( );
|
||||
|
||||
|
@ -28,13 +28,13 @@ public class DebugInformation
|
|||
private EmpireInformation empire = new EmpireInformation( );
|
||||
|
||||
@XStreamAlias( "research" )
|
||||
private List< ResearchInformation > research = new LinkedList< ResearchInformation >( );
|
||||
private List< ResearchInformation > research = new ArrayList< ResearchInformation >( );
|
||||
|
||||
@XStreamAlias( "planets" )
|
||||
private List< PlanetInformation > planets = new LinkedList< PlanetInformation >( );
|
||||
private List< PlanetInformation > planets = new ArrayList< PlanetInformation >( );
|
||||
|
||||
@XStreamAlias( "fleets" )
|
||||
private List< FleetInformation > fleets = new LinkedList< FleetInformation >( );
|
||||
private List< FleetInformation > fleets = new ArrayList< FleetInformation >( );
|
||||
|
||||
|
||||
public int getVersion( )
|
|
@ -0,0 +1,141 @@
|
|||
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.XStreamAsAttribute;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 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
|
||||
{
|
||||
|
||||
/** The empire's numeric identifier */
|
||||
@XStreamAsAttribute
|
||||
private Integer id;
|
||||
|
||||
/** The empire's name */
|
||||
@XStreamAsAttribute
|
||||
private String name;
|
||||
|
||||
/** The empire's cash */
|
||||
@XStreamAsAttribute
|
||||
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 >( );
|
||||
|
||||
|
||||
/** @return the empire's numeric identifier */
|
||||
public Integer getId( )
|
||||
{
|
||||
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 this.name;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the empire's name
|
||||
*
|
||||
* @param name
|
||||
* the empire's name
|
||||
*/
|
||||
public void setName( String name )
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
||||
/** @return the amount of cash possessed by the empire */
|
||||
public Double getCash( )
|
||||
{
|
||||
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 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,134 @@
|
|||
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, as well as the
|
||||
* mining priority if it is a natural resource.
|
||||
*
|
||||
* @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;
|
||||
|
||||
/**
|
||||
* The mining priority for this type of resource, or <code>null</code> if it is not a natural
|
||||
* resource
|
||||
*/
|
||||
@XStreamAlias( "mining-priority" )
|
||||
@XStreamAsAttribute
|
||||
private Integer miningPriority;
|
||||
|
||||
|
||||
/** @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;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the mining priority for this type of resource, or <code>null</code> if it is not a
|
||||
* natural resource
|
||||
*/
|
||||
public Integer getMiningPriority( )
|
||||
{
|
||||
return this.miningPriority;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the mining priority for this type of resource
|
||||
*
|
||||
* @param miningPriority
|
||||
* the mining priority for this type of resource
|
||||
*/
|
||||
public void setMiningPriority( int miningPriority )
|
||||
{
|
||||
this.miningPriority = miningPriority;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package com.deepclone.lw.beans.bt.esdata;
|
||||
package com.deepclone.lw.beans.bt.es.data;
|
||||
|
||||
|
||||
import java.io.Serializable;
|
|
@ -0,0 +1,60 @@
|
|||
package com.deepclone.lw.beans.bt.es.data;
|
||||
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Invalid dump contents exception
|
||||
*
|
||||
* <p>
|
||||
* This runtime exception is thrown by the debugging data record classes when one of the fields is
|
||||
* set to an incorrect value.
|
||||
*
|
||||
* @author <a href="mailto:tseeker@legacyworlds.com">E. Benoît</a>
|
||||
*
|
||||
*/
|
||||
public final class InvalidDumpContentsException
|
||||
extends RuntimeException
|
||||
{
|
||||
/** Serialisation identifier */
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** Class in which the error was caused */
|
||||
private final Class< ? extends Serializable > recordType;
|
||||
|
||||
/** Name of the field to which invalid contents were assigned */
|
||||
private final String field;
|
||||
|
||||
|
||||
/**
|
||||
* Initialise the exception by setting the record and field
|
||||
*
|
||||
* @param type
|
||||
* the type of the XML dump record
|
||||
* @param field
|
||||
* the field to which invalid contents were assigned
|
||||
*/
|
||||
InvalidDumpContentsException( Class< ? extends Serializable > type , String field )
|
||||
{
|
||||
super( "Invalid contents for field " + field + " of record " + type.getSimpleName( ) );
|
||||
this.recordType = type;
|
||||
this.field = field;
|
||||
}
|
||||
|
||||
|
||||
/** @return the type of the XML dump record */
|
||||
public Class< ? extends Serializable > getRecordType( )
|
||||
{
|
||||
return this.recordType;
|
||||
}
|
||||
|
||||
|
||||
/** @return the field to which invalid contents were assigned */
|
||||
public String getField( )
|
||||
{
|
||||
return this.field;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package com.deepclone.lw.beans.bt.esdata;
|
||||
package com.deepclone.lw.beans.bt.es.data;
|
||||
|
||||
|
||||
import java.io.Serializable;
|
|
@ -0,0 +1,210 @@
|
|||
package com.deepclone.lw.beans.bt.es.data;
|
||||
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
import com.thoughtworks.xstream.annotations.XStreamAsAttribute;
|
||||
import com.thoughtworks.xstream.annotations.XStreamImplicit;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Planet XML record
|
||||
*
|
||||
* <p>
|
||||
* This class is used in XML dumps to represent the information about a planet. It includes a few
|
||||
* basic values, as well as information about buildings, queues and resources.
|
||||
*
|
||||
* <p>
|
||||
* This record exists since version 1 (B6M1) of XML dumps. However, the following changes were made
|
||||
* later.
|
||||
* <ul>
|
||||
* <li>Version 2 (B6M2):
|
||||
* <ul>
|
||||
* <li>resource providers added,
|
||||
* </ul>
|
||||
* </ul>
|
||||
*
|
||||
* @author <a href="mailto:tseeker@legacyworlds.com">E. Benoît</a>
|
||||
*
|
||||
*/
|
||||
@XStreamAlias( "planet" )
|
||||
@SuppressWarnings( "serial" )
|
||||
public class PlanetInformation
|
||||
implements Serializable
|
||||
{
|
||||
|
||||
/** Planet identifier */
|
||||
@XStreamAsAttribute
|
||||
private Integer id;
|
||||
|
||||
/** Planet name */
|
||||
@XStreamAsAttribute
|
||||
private String name;
|
||||
|
||||
/** Current population of the planet */
|
||||
@XStreamAlias( "population" )
|
||||
private Double population;
|
||||
|
||||
/** Current happiness of the planet's population */
|
||||
@XStreamAlias( "current-happiness" )
|
||||
private Double currentHappiness;
|
||||
|
||||
/** Target happiness of the planet's population */
|
||||
@XStreamAlias( "target-happiness" )
|
||||
private double targetHappiness;
|
||||
|
||||
/** List of buildings */
|
||||
@XStreamAlias( "buildings" )
|
||||
private final List< BuildingsInformation > buildings = new ArrayList< BuildingsInformation >( );
|
||||
|
||||
/** Civilian construction queue */
|
||||
@XStreamAlias( "civ-queue" )
|
||||
private final QueueInformation civilianQueue = new QueueInformation( );
|
||||
|
||||
/** Military construction queue */
|
||||
@XStreamAlias( "mil-queue" )
|
||||
private final QueueInformation militaryQueue = new QueueInformation( );
|
||||
|
||||
/** Planet resource deltas */
|
||||
@XStreamImplicit
|
||||
private final ArrayList< ResourceDeltaInformation > resourceDeltas = new ArrayList< ResourceDeltaInformation >( );
|
||||
|
||||
/** List of resource providers */
|
||||
@XStreamImplicit( itemFieldName = "resource-provider" )
|
||||
private final ArrayList< ResourceProviderInformation > resourceProviders = new ArrayList< ResourceProviderInformation >( );
|
||||
|
||||
|
||||
/** @return the planet's identifier */
|
||||
public Integer getId( )
|
||||
{
|
||||
return this.id;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the planet's identifier
|
||||
*
|
||||
* @param id
|
||||
* the planet's identifier
|
||||
*/
|
||||
public void setId( int id )
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
|
||||
/** @return the planet's name */
|
||||
public String getName( )
|
||||
{
|
||||
return this.name;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the planet's name
|
||||
*
|
||||
* @param name
|
||||
* the planet's name
|
||||
*/
|
||||
public void setName( String name )
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
||||
/** @return the planet's current population */
|
||||
public Double getPopulation( )
|
||||
{
|
||||
return this.population;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the planet's current population
|
||||
*
|
||||
* @param population
|
||||
* the planet's current population
|
||||
*/
|
||||
public void setPopulation( double population )
|
||||
{
|
||||
this.population = population;
|
||||
}
|
||||
|
||||
|
||||
/** @return the current happiness of the planet's population */
|
||||
public Double getCurrentHappiness( )
|
||||
{
|
||||
return this.currentHappiness;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the current happiness of the planet's population
|
||||
*
|
||||
* @param currentHappiness
|
||||
* the current happiness of the planet's population
|
||||
*/
|
||||
public void setCurrentHappiness( double currentHappiness )
|
||||
{
|
||||
this.currentHappiness = currentHappiness;
|
||||
}
|
||||
|
||||
|
||||
/** @return the target happiness of the planet's population */
|
||||
public Double getTargetHappiness( )
|
||||
{
|
||||
return this.targetHappiness;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the target happiness of the planet's population
|
||||
*
|
||||
* @param targetHappiness
|
||||
* the target happiness of the planet's population
|
||||
*/
|
||||
public void setTargetHappiness( double targetHappiness )
|
||||
{
|
||||
this.targetHappiness = targetHappiness;
|
||||
}
|
||||
|
||||
|
||||
/** @return the list of buildings constructed on the planet */
|
||||
public List< BuildingsInformation > getBuildings( )
|
||||
{
|
||||
return this.buildings;
|
||||
}
|
||||
|
||||
|
||||
/** @return the civilian construction queue */
|
||||
public QueueInformation getCivilianQueue( )
|
||||
{
|
||||
return this.civilianQueue;
|
||||
}
|
||||
|
||||
|
||||
/** @return the military construction queue */
|
||||
public QueueInformation getMilitaryQueue( )
|
||||
{
|
||||
return this.militaryQueue;
|
||||
}
|
||||
|
||||
|
||||
/** @return the list of resource delta records */
|
||||
public ArrayList< ResourceDeltaInformation > getResourceDeltas( )
|
||||
{
|
||||
return this.resourceDeltas;
|
||||
}
|
||||
|
||||
|
||||
/** @return the list of resource provider records */
|
||||
public ArrayList< ResourceProviderInformation > getResourceProviders( )
|
||||
{
|
||||
return this.resourceProviders;
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
|
@ -0,0 +1,136 @@
|
|||
package com.deepclone.lw.beans.bt.es.data;
|
||||
|
||||
|
||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
import com.thoughtworks.xstream.annotations.XStreamAsAttribute;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Technology from the technology graph and associated state information
|
||||
*
|
||||
* <p>
|
||||
* This class represents the state of a technology from the B6M2+ technology graph for the empire
|
||||
* being dumped.
|
||||
*
|
||||
* @author <a href="mailto:tseeker@legacyworlds.com">E. Benoît</a>
|
||||
*/
|
||||
@SuppressWarnings( "serial" )
|
||||
@XStreamAlias( "technology" )
|
||||
public class ResearchGraphInformation
|
||||
extends ResearchInformation
|
||||
{
|
||||
|
||||
/** The technology's name */
|
||||
@XStreamAsAttribute
|
||||
private String name;
|
||||
|
||||
/** The technology's state */
|
||||
@XStreamAsAttribute
|
||||
private TechnologyState state;
|
||||
|
||||
/**
|
||||
* The amount of accumulated research points, or <code>null</code> if the technology has been
|
||||
* researched
|
||||
*/
|
||||
@XStreamAsAttribute
|
||||
private Double points;
|
||||
|
||||
/** The research priority, or <code>null</code> if the technology has been researched */
|
||||
@XStreamAsAttribute
|
||||
private Integer priority;
|
||||
|
||||
|
||||
/**
|
||||
* Gets the technology's name.
|
||||
*
|
||||
* @return the technology's name
|
||||
*/
|
||||
public String getName( )
|
||||
{
|
||||
return this.name;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the technology's name.
|
||||
*
|
||||
* @param name
|
||||
* the technology's new name
|
||||
*/
|
||||
public void setName( String name )
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the technology's state.
|
||||
*
|
||||
* @return the technology's state
|
||||
*/
|
||||
public TechnologyState getState( )
|
||||
{
|
||||
return this.state;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the technology's state.
|
||||
*
|
||||
* @param state
|
||||
* the technology's new state
|
||||
*/
|
||||
public void setState( TechnologyState state )
|
||||
{
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the amount of accumulated research points
|
||||
*
|
||||
* @return the amount of accumulated research points, or <code>null</code> if the technology has
|
||||
* been researched
|
||||
*/
|
||||
public Double getPoints( )
|
||||
{
|
||||
return this.points;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the amount of accumulated research points
|
||||
*
|
||||
* @param points
|
||||
* the amount of accumulated research points
|
||||
*/
|
||||
public void setPoints( Double points )
|
||||
{
|
||||
this.points = points;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the research priority
|
||||
*
|
||||
* @return the research priority, or <code>null</code> if the technology has been researched
|
||||
*/
|
||||
public Integer getPriority( )
|
||||
{
|
||||
return this.priority;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the research priority
|
||||
*
|
||||
* @param priority
|
||||
* the new research priority
|
||||
*/
|
||||
public void setPriority( Integer priority )
|
||||
{
|
||||
this.priority = priority;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package com.deepclone.lw.beans.bt.es.data;
|
||||
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Empty, base research record
|
||||
*
|
||||
* <p>
|
||||
* This class used to contain B6M1 research line entries; however, in order to support B6M2
|
||||
* technologies while maintaining XML compatibility, it has been replaced with an empty class which
|
||||
* servces as the base class for both old and new records.
|
||||
*
|
||||
* @author <a href="mailto:tseeker@legacyworlds.com">E. Benoît</a>
|
||||
*
|
||||
*/
|
||||
@SuppressWarnings( "serial" )
|
||||
public abstract class ResearchInformation
|
||||
implements Serializable
|
||||
|
||||
{
|
||||
// EMPTY
|
||||
}
|
|
@ -0,0 +1,137 @@
|
|||
package com.deepclone.lw.beans.bt.es.data;
|
||||
|
||||
|
||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
import com.thoughtworks.xstream.annotations.XStreamAsAttribute;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Research line information
|
||||
*
|
||||
* <p>
|
||||
* This class defines data stored in the dumps for B6M1 research lines. It is no longer actively
|
||||
* used as of B6M2, but is kept around so the XML files can still be used if necessary.
|
||||
*
|
||||
* @author <a href="mailto:tseeker@legacyworlds.com">E. Benoît</a>
|
||||
*/
|
||||
@XStreamAlias( "research-line" )
|
||||
public class ResearchLineInformation
|
||||
extends ResearchInformation
|
||||
{
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** Identifier of the technology line */
|
||||
@XStreamAsAttribute
|
||||
@XStreamAlias( "line" )
|
||||
private int id;
|
||||
|
||||
/** Current level for that line */
|
||||
@XStreamAsAttribute
|
||||
@XStreamAlias( "level" )
|
||||
private int currentLevel;
|
||||
|
||||
/** Name of the last level */
|
||||
@XStreamAsAttribute
|
||||
@XStreamAlias( "name" )
|
||||
private String levelName;
|
||||
|
||||
/** Accumulated points towards the next level */
|
||||
@XStreamAsAttribute
|
||||
@XStreamAlias( "accumulated-points" )
|
||||
private double accumulated;
|
||||
|
||||
|
||||
/**
|
||||
* Gets the identifier of the technology line.
|
||||
*
|
||||
* @return the identifier of the technology line
|
||||
*/
|
||||
public int getId( )
|
||||
{
|
||||
return this.id;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the identifier of the technology line.
|
||||
*
|
||||
* @param id
|
||||
* the new identifier of the technology line
|
||||
*/
|
||||
public void setId( int id )
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the current level for that line.
|
||||
*
|
||||
* @return the current level for that line
|
||||
*/
|
||||
public int getCurrentLevel( )
|
||||
{
|
||||
return this.currentLevel;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the current level for that line.
|
||||
*
|
||||
* @param currentLevel
|
||||
* the new level for that line
|
||||
*/
|
||||
public void setCurrentLevel( int currentLevel )
|
||||
{
|
||||
this.currentLevel = currentLevel;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the name of the last level.
|
||||
*
|
||||
* @return the name of the last level
|
||||
*/
|
||||
public String getLevelName( )
|
||||
{
|
||||
return this.levelName;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the name of the last level.
|
||||
*
|
||||
* @param levelName
|
||||
* the new name of the last level
|
||||
*/
|
||||
public void setLevelName( String levelName )
|
||||
{
|
||||
this.levelName = levelName;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the accumulated points towards the next level.
|
||||
*
|
||||
* @return the accumulated points towards the next level
|
||||
*/
|
||||
public double getAccumulated( )
|
||||
{
|
||||
return this.accumulated;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the accumulated points towards the next level.
|
||||
*
|
||||
* @param accumulated
|
||||
* the new accumulated points towards the next level
|
||||
*/
|
||||
public void setAccumulated( double accumulated )
|
||||
{
|
||||
this.accumulated = accumulated;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,109 @@
|
|||
package com.deepclone.lw.beans.bt.es.data;
|
||||
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
import com.thoughtworks.xstream.annotations.XStreamAsAttribute;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Resource delta information
|
||||
*
|
||||
* <p>
|
||||
* This class represents records which contain a resource's delta - that is, the income and upkeep
|
||||
* for some type of resource.
|
||||
*
|
||||
* @author <a href="mailto:tseeker@legacyworlds.com">E. Benoît</a>
|
||||
*/
|
||||
@SuppressWarnings( "serial" )
|
||||
@XStreamAlias( "resource-delta" )
|
||||
public class ResourceDeltaInformation
|
||||
implements Serializable
|
||||
{
|
||||
|
||||
/** Identifier of the resource */
|
||||
@XStreamAlias( "id" )
|
||||
@XStreamAsAttribute
|
||||
private String resource;
|
||||
|
||||
/** Income for that type of resource */
|
||||
@XStreamAsAttribute
|
||||
private Double income;
|
||||
|
||||
/** Upkeep for that type of resource */
|
||||
@XStreamAsAttribute
|
||||
private Double upkeep;
|
||||
|
||||
|
||||
/** @return the resource's identifier */
|
||||
public String getResource( )
|
||||
{
|
||||
return this.resource;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the resource's identifier
|
||||
*
|
||||
* @param resource
|
||||
* the resource's identifier
|
||||
*
|
||||
* @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 income for that type of resource, or <code>null</code> if no income information
|
||||
* is available
|
||||
*/
|
||||
public Double getIncome( )
|
||||
{
|
||||
return this.income;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the income for that type of resource
|
||||
*
|
||||
* @param income
|
||||
* the income for that type of resource
|
||||
*/
|
||||
public void setIncome( double income )
|
||||
{
|
||||
this.income = income;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the upkeep for that type of resource, or <code>null</code> if no upkeep information
|
||||
* is available
|
||||
*/
|
||||
public Double getUpkeep( )
|
||||
{
|
||||
return this.upkeep;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the upkeep for that type of resource
|
||||
*
|
||||
* @param upkeep
|
||||
* the upkeep for that type of resource
|
||||
*/
|
||||
public void setUpkeep( double upkeep )
|
||||
{
|
||||
this.upkeep = upkeep;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,179 @@
|
|||
package com.deepclone.lw.beans.bt.es.data;
|
||||
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
import com.thoughtworks.xstream.annotations.XStreamAsAttribute;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Resource provider XML record
|
||||
*
|
||||
* <p>
|
||||
* This class represents the information about a resource provider that will be serialised to the
|
||||
* debugging XML dump when a player posts a bug report.
|
||||
*
|
||||
* <p>
|
||||
* This record exists since version 2 (B6M2) of XML dumps.
|
||||
*
|
||||
* @author <a href="mailto:tseeker@legacyworlds.com">E. Benoît</a>
|
||||
*/
|
||||
@SuppressWarnings( "serial" )
|
||||
public class ResourceProviderInformation
|
||||
implements Serializable
|
||||
{
|
||||
|
||||
/** Identifier of the resource */
|
||||
@XStreamAsAttribute
|
||||
private String resource;
|
||||
|
||||
/** Maximal quantity in the provider */
|
||||
@XStreamAsAttribute
|
||||
@XStreamAlias( "max" )
|
||||
private Double maximalQuantity;
|
||||
|
||||
/** Current quantity in the provider */
|
||||
@XStreamAsAttribute
|
||||
@XStreamAlias( "current" )
|
||||
private Double currentQuantity;
|
||||
|
||||
/** Extraction difficulty */
|
||||
@XStreamAsAttribute
|
||||
private Double difficulty;
|
||||
|
||||
/** Recovery rate */
|
||||
@XStreamAsAttribute
|
||||
private Double recovery;
|
||||
|
||||
/** Planet-specific mining priority */
|
||||
@XStreamAlias( "mining-priority" )
|
||||
@XStreamAsAttribute
|
||||
private Integer miningPriority;
|
||||
|
||||
|
||||
/** @return the resource's identifier */
|
||||
public String getResource( )
|
||||
{
|
||||
return this.resource;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the resource's identifier
|
||||
*
|
||||
* @param resource
|
||||
* the resource's identifier
|
||||
*
|
||||
* @throws InvalidDumpContentsException
|
||||
* if the resource's identifier 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 provider's total capacity */
|
||||
public Double getMaximalQuantity( )
|
||||
{
|
||||
return this.maximalQuantity;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the maximal quantity of resources in the provider
|
||||
*
|
||||
* @param maximalQuantity
|
||||
* the provider's total capacity
|
||||
*/
|
||||
public void setMaximalQuantity( double maximalQuantity )
|
||||
{
|
||||
this.maximalQuantity = maximalQuantity;
|
||||
}
|
||||
|
||||
|
||||
/** @return the current quantity of resources in the provider */
|
||||
public Double getCurrentQuantity( )
|
||||
{
|
||||
return this.currentQuantity;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the current quantity of resources in the provider
|
||||
*
|
||||
* @param currentQuantity
|
||||
* the current quantity of resources in the provider
|
||||
*/
|
||||
public void setCurrentQuantity( double currentQuantity )
|
||||
{
|
||||
this.currentQuantity = currentQuantity;
|
||||
}
|
||||
|
||||
|
||||
/** @return the provider's extraction difficulty */
|
||||
public Double getDifficulty( )
|
||||
{
|
||||
return this.difficulty;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the provider's extraction difficulty
|
||||
*
|
||||
* @param difficulty
|
||||
* the provider's extraction difficulty
|
||||
*/
|
||||
public void setDifficulty( double difficulty )
|
||||
{
|
||||
this.difficulty = difficulty;
|
||||
}
|
||||
|
||||
|
||||
/** @return the provider's recovery rate */
|
||||
public Double getRecovery( )
|
||||
{
|
||||
return this.recovery;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the provider's recovery rate
|
||||
*
|
||||
* @param recovery
|
||||
* the provider's recovery rate
|
||||
*/
|
||||
public void setRecovery( double recovery )
|
||||
{
|
||||
this.recovery = recovery;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the planet-specific mining priority, or <code>null</code> if the empire's global
|
||||
* settings are in used
|
||||
*/
|
||||
public Integer getMiningPriority( )
|
||||
{
|
||||
return this.miningPriority;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the planet-specific mining priority
|
||||
*
|
||||
* @param miningPriority
|
||||
* the planet-specific mining priority
|
||||
*/
|
||||
public void setMiningPriority( int miningPriority )
|
||||
{
|
||||
this.miningPriority = miningPriority;
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
|
@ -0,0 +1,20 @@
|
|||
package com.deepclone.lw.beans.bt.es.data;
|
||||
|
||||
|
||||
/**
|
||||
* State of a (B6M2+) technology
|
||||
*
|
||||
* @author <a href="mailto:tseeker@legacyworlds.com">E. Benoît</a>
|
||||
*/
|
||||
public enum TechnologyState {
|
||||
|
||||
/** The technology is being researched */
|
||||
RESEARCH ,
|
||||
|
||||
/** The technology needs to be implemented */
|
||||
PENDING ,
|
||||
|
||||
/** The technology has been researched and implemented */
|
||||
KNOWN
|
||||
|
||||
}
|
|
@ -2,8 +2,11 @@
|
|||
<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">
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
|
||||
|
||||
<bean id="adminBugs" class="com.deepclone.lw.beans.bt.AdminBugsBean" />
|
||||
<bean id="bugsDAO" class="com.deepclone.lw.beans.bt.BugsDAOBean" />
|
||||
<bean id="empireSummary" class="com.deepclone.lw.beans.bt.es.EmpireSummaryBean" />
|
||||
<bean id="playerBugs" class="com.deepclone.lw.beans.bt.PlayerBugsBean" />
|
||||
|
||||
</beans>
|
0
legacyworlds-server-beans-bt/src/test/java/.empty
Normal file
0
legacyworlds-server-beans-bt/src/test/java/.empty
Normal file
0
legacyworlds-server-beans-bt/src/test/resources/.empty
Normal file
0
legacyworlds-server-beans-bt/src/test/resources/.empty
Normal file
|
@ -4,12 +4,12 @@
|
|||
<parent>
|
||||
<artifactId>legacyworlds-server-beans</artifactId>
|
||||
<groupId>com.deepclone.lw</groupId>
|
||||
<version>5.99.1</version>
|
||||
<version>1.0.0</version>
|
||||
<relativePath>../legacyworlds-server-beans/pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<groupId>com.deepclone.lw</groupId>
|
||||
<artifactId>legacyworlds-server-beans-eventlog</artifactId>
|
||||
<version>5.99.1</version>
|
||||
<name>Legacy Worlds event log</name>
|
||||
<name>Legacy Worlds - Server - Components - Logging</name>
|
||||
<description>This package is responsible for all logging in Legacy Worlds through three different beans (system event logger, admin event logger and user event logger).</description>
|
||||
<version>${legacyworlds.version.main}.${legacyworlds.version.release}-${legacyworlds.version.build}</version>
|
||||
</project>
|
|
@ -13,8 +13,8 @@ import javax.sql.DataSource;
|
|||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.dao.EmptyResultDataAccessException;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
import org.springframework.transaction.TransactionStatus;
|
||||
import org.springframework.transaction.support.TransactionCallback;
|
||||
|
@ -39,7 +39,7 @@ public class LogReaderBean
|
|||
implements LogReader
|
||||
{
|
||||
|
||||
private SimpleJdbcTemplate dTemplate;
|
||||
private JdbcTemplate dTemplate;
|
||||
private TransactionTemplate tTemplate;
|
||||
|
||||
private final RowMapper< LogEntry > mLogEntry;
|
||||
|
@ -88,7 +88,7 @@ public class LogReaderBean
|
|||
@Autowired( required = true )
|
||||
public void setDataSource( DataSource dataSource )
|
||||
{
|
||||
this.dTemplate = new SimpleJdbcTemplate( dataSource );
|
||||
this.dTemplate = new JdbcTemplate( dataSource );
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
<?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.1.xsd">
|
||||
|
||||
<bean id="adminErrorMail" class="com.deepclone.lw.beans.eventlog.AdminErrorMailBean" />
|
||||
<bean id="logCleaner" class="com.deepclone.lw.beans.eventlog.LogCleanerBean" />
|
||||
<bean id="logger" class="com.deepclone.lw.beans.eventlog.LoggerBean" />
|
||||
<bean id="logReader" class="com.deepclone.lw.beans.eventlog.LogReaderBean" />
|
||||
<bean id="logWriter" class="com.deepclone.lw.beans.eventlog.LogWriterBean" />
|
||||
|
||||
</beans>
|
0
legacyworlds-server-beans-eventlog/src/test/java/.empty
Normal file
0
legacyworlds-server-beans-eventlog/src/test/java/.empty
Normal file
15
legacyworlds-server-beans-events/pom.xml
Normal file
15
legacyworlds-server-beans-events/pom.xml
Normal file
|
@ -0,0 +1,15 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<artifactId>legacyworlds-server-beans</artifactId>
|
||||
<groupId>com.deepclone.lw</groupId>
|
||||
<version>1.0.0</version>
|
||||
<relativePath>../legacyworlds-server-beans/pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>legacyworlds-server-beans-events</artifactId>
|
||||
<version>${legacyworlds.version.main}.${legacyworlds.version.release}-${legacyworlds.version.build}</version>
|
||||
<name>Legacy Worlds - Server - Components - Events</name>
|
||||
<description>This package defines the components used to process and handle game events.</description>
|
||||
</project>
|
0
legacyworlds-server-beans-events/src/main/java/.empty
Normal file
0
legacyworlds-server-beans-events/src/main/java/.empty
Normal file
|
@ -0,0 +1,113 @@
|
|||
package com.deepclone.lw.beans.events;
|
||||
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
import org.springframework.transaction.support.TransactionTemplate;
|
||||
|
||||
import com.deepclone.lw.interfaces.sys.Ticker;
|
||||
import com.deepclone.lw.interfaces.sys.Ticker.Frequency;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Events processor component
|
||||
*
|
||||
* <p>
|
||||
* This component acquires the necessary dependencies to create an {@link EventProcessorTask}, does
|
||||
* so, and registers it with the ticker. It clears the reference to the task when destroyed.
|
||||
*
|
||||
* @author <a href="mailto:tseeker@legacyworlds.com">E. Benoît</a>
|
||||
*
|
||||
*/
|
||||
class EventProcessorBean
|
||||
implements InitializingBean , DisposableBean
|
||||
{
|
||||
|
||||
/** The ticker */
|
||||
private Ticker ticker;
|
||||
|
||||
/** The Spring transaction template */
|
||||
private TransactionTemplate tTemplate;
|
||||
|
||||
/** The database interface */
|
||||
private DataSource dataSource;
|
||||
|
||||
/** The task */
|
||||
private Runnable task;
|
||||
|
||||
|
||||
/**
|
||||
* Dependency injector that sets the ticker component
|
||||
*
|
||||
* @param ticker
|
||||
* the ticker component
|
||||
*/
|
||||
@Autowired( required = true )
|
||||
public void setTicker( Ticker ticker )
|
||||
{
|
||||
this.ticker = ticker;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Dependency injector that sets the transaction manager
|
||||
*
|
||||
* <p>
|
||||
* Creates the transaction template from the transaction manager
|
||||
*
|
||||
* @param tManager
|
||||
* the Spring transaction manager
|
||||
*/
|
||||
@Autowired( required = true )
|
||||
public void setTransactionManager( PlatformTransactionManager tManager )
|
||||
{
|
||||
this.tTemplate = new TransactionTemplate( tManager );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Dependency injector that sets the database interface
|
||||
*
|
||||
* @param dataSource
|
||||
* the database interface
|
||||
*/
|
||||
@Autowired( required = true )
|
||||
public void setDataSource( DataSource dataSource )
|
||||
{
|
||||
this.dataSource = dataSource;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Initialise and register the event processing task
|
||||
*
|
||||
* <p>
|
||||
* When the component's dependencies have been injected, this method creates the
|
||||
* {@link EventProcessorTask} instance and registers it to the ticker.
|
||||
*/
|
||||
@Override
|
||||
public void afterPropertiesSet( )
|
||||
{
|
||||
this.task = new EventProcessorTask( this.tTemplate , this.dataSource );
|
||||
this.ticker.registerTask( Frequency.HIGH , "Events processor" , this.task );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Clear the task reference
|
||||
*
|
||||
* <p>
|
||||
* Remove the reference to the {@link EventProcessorTask} instance, allowing the ticker to clean
|
||||
* up.
|
||||
*/
|
||||
@Override
|
||||
public void destroy( )
|
||||
{
|
||||
this.task = null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,86 @@
|
|||
package com.deepclone.lw.beans.events;
|
||||
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.springframework.transaction.TransactionStatus;
|
||||
import org.springframework.transaction.support.TransactionCallback;
|
||||
import org.springframework.transaction.support.TransactionTemplate;
|
||||
|
||||
import com.deepclone.lw.utils.StoredProc;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Event processing task
|
||||
*
|
||||
* <p>
|
||||
* This class implements the task responsible for regular database event processing calls. It is
|
||||
* registered as a high-frequency ticker task by {@link EventProcessorBean}.
|
||||
*
|
||||
* @author <a href="mailto:tseeker@legacyworlds.com">E. Benoît</a>
|
||||
*/
|
||||
class EventProcessorTask
|
||||
implements Runnable
|
||||
{
|
||||
|
||||
/** The Spring transaction template */
|
||||
private final TransactionTemplate tTemplate;
|
||||
|
||||
/** The stored procedure that implements event processing */
|
||||
private final StoredProc eqProcess;
|
||||
|
||||
|
||||
/**
|
||||
* Initialise the transaction template and stored procedure interface
|
||||
*
|
||||
* @param tTemplate
|
||||
* the transaction template
|
||||
* @param dataSource
|
||||
* the database interface
|
||||
*/
|
||||
public EventProcessorTask( TransactionTemplate tTemplate , DataSource dataSource )
|
||||
{
|
||||
this.tTemplate = tTemplate;
|
||||
this.eqProcess = new StoredProc( dataSource , "events" , "eq_process" );
|
||||
this.eqProcess.addOutput( "_result" , java.sql.Types.BOOLEAN );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* When the task executes, it will call <code>events.eq_process()</code> repeatedly until the
|
||||
* stored procedure returns <code>false</code>. Each call is made in a separate transaction.
|
||||
*/
|
||||
@Override
|
||||
public void run( )
|
||||
{
|
||||
boolean hasMore;
|
||||
do {
|
||||
hasMore = this.processBatch( );
|
||||
} while ( hasMore );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Process a batch of events
|
||||
*
|
||||
* <p>
|
||||
* This method spawns a transaction in which the <code>events.eq_process()</code> stored
|
||||
* procedure is called.
|
||||
*
|
||||
* @return <code>true</code> if events were processed, <code>false</code> if the queues were
|
||||
* empty.
|
||||
*/
|
||||
private boolean processBatch( )
|
||||
{
|
||||
return this.tTemplate.execute( new TransactionCallback< Boolean >( ) {
|
||||
|
||||
@Override
|
||||
public Boolean doInTransaction( TransactionStatus status )
|
||||
{
|
||||
return (Boolean) EventProcessorTask.this.eqProcess.execute( ).get( "_result" );
|
||||
}
|
||||
|
||||
} );
|
||||
}
|
||||
}
|
|
@ -2,8 +2,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">
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
|
||||
|
||||
<bean id="bansDao" class="com.deepclone.lw.beans.admin.BansDAOBean" />
|
||||
<bean id="eventProcessor" class="com.deepclone.lw.beans.events.EventProcessorBean" />
|
||||
|
||||
</beans>
|
0
legacyworlds-server-beans-events/src/test/java/.empty
Normal file
0
legacyworlds-server-beans-events/src/test/java/.empty
Normal file
Some files were not shown because too many files have changed in this diff Show more
Reference in a new issue