Removed old research system
* Removed all tables, views and functions * Removed references to old system in Java code, including old import tool * Replaced XML dump code
This commit is contained in:
parent
070d55dc05
commit
96c296e9d5
22 changed files with 345 additions and 705 deletions
legacyworlds-server-main
|
@ -1,23 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<technologies xmlns="http://www.deepclone.com/lw/b6/m1/techs" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.deepclone.com/lw/b6/m1/techs techs.xsd">
|
||||
|
||||
<tech-line name="milTech" description="milTechDescription">
|
||||
<level name="cruisersTech" description="cruisersTechDescription"
|
||||
points="25000" cost="10000" />
|
||||
<level name="bCruisersTech" description="bCruisersTechDescription"
|
||||
points="900000" cost="400000" />
|
||||
<level name="dreadnoughtsTech" description="dreadnoughtsTechDescription"
|
||||
points="2250000" cost="1012500" />
|
||||
</tech-line>
|
||||
|
||||
<tech-line name="civTech" description="civTechDescription">
|
||||
<level name="indFactTech" description="indFactTechDescription"
|
||||
points="10000" cost="5000" />
|
||||
<level name="reanimationTech" description="reanimationTechDescription"
|
||||
points="562500" cost="281250" />
|
||||
<level name="superTurretTech" description="superTurretTechDescription"
|
||||
points="1350000" cost="607500" />
|
||||
</tech-line>
|
||||
|
||||
</technologies>
|
|
@ -1,28 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<xs:schema xmlns="http://www.deepclone.com/lw/b6/m1/techs" targetNamespace="http://www.deepclone.com/lw/b6/m1/techs"
|
||||
xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
|
||||
|
||||
<xs:element name="technologies">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
<xs:element name="tech-line" type="tech-line" minOccurs="1" maxOccurs="unbounded" />
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
|
||||
<xs:complexType name="tech-line">
|
||||
<xs:sequence>
|
||||
<xs:element name="level" type="tech-level" minOccurs="1" maxOccurs="unbounded" />
|
||||
</xs:sequence>
|
||||
<xs:attribute name="name" use="required" type="xs:token" />
|
||||
<xs:attribute name="description" use="required" type="xs:token" />
|
||||
</xs:complexType>
|
||||
|
||||
<xs:complexType name="tech-level">
|
||||
<xs:attribute name="name" use="required" type="xs:token" />
|
||||
<xs:attribute name="description" use="required" type="xs:token" />
|
||||
<xs:attribute name="points" use="required" type="xs:positiveInteger" />
|
||||
<xs:attribute name="cost" use="required" type="xs:positiveInteger" />
|
||||
</xs:complexType>
|
||||
|
||||
</xs:schema>
|
|
@ -1,217 +0,0 @@
|
|||
package com.deepclone.lw.cli;
|
||||
|
||||
|
||||
import java.io.*;
|
||||
import java.sql.Types;
|
||||
import java.util.List;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.AbstractApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.context.support.FileSystemXmlApplicationContext;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
import org.springframework.transaction.TransactionStatus;
|
||||
import org.springframework.transaction.support.TransactionCallback;
|
||||
import org.springframework.transaction.support.TransactionTemplate;
|
||||
|
||||
import com.deepclone.lw.utils.StoredProc;
|
||||
import com.thoughtworks.xstream.XStream;
|
||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
import com.thoughtworks.xstream.annotations.XStreamAsAttribute;
|
||||
import com.thoughtworks.xstream.annotations.XStreamImplicit;
|
||||
|
||||
|
||||
|
||||
public class ImportTechs
|
||||
extends CLITool
|
||||
{
|
||||
|
||||
private final Logger logger = Logger.getLogger( ImportTechs.class );
|
||||
|
||||
@XStreamAlias( "technologies" )
|
||||
@SuppressWarnings( "serial" )
|
||||
public static class Techs
|
||||
implements Serializable
|
||||
{
|
||||
@XStreamImplicit( itemFieldName = "tech-line" )
|
||||
public List< TechLine > lines;
|
||||
}
|
||||
|
||||
@SuppressWarnings( "serial" )
|
||||
public static class TechLine
|
||||
implements Serializable
|
||||
{
|
||||
@XStreamAsAttribute
|
||||
public String name;
|
||||
|
||||
@XStreamAsAttribute
|
||||
public String description;
|
||||
|
||||
@XStreamImplicit( itemFieldName = "level" )
|
||||
public List< TechLevel > levels;
|
||||
}
|
||||
|
||||
@SuppressWarnings( "serial" )
|
||||
public static class TechLevel
|
||||
implements Serializable
|
||||
{
|
||||
@XStreamAsAttribute
|
||||
public String name;
|
||||
|
||||
@XStreamAsAttribute
|
||||
public String description;
|
||||
|
||||
@XStreamAsAttribute
|
||||
public int points;
|
||||
|
||||
@XStreamAsAttribute
|
||||
public int cost;
|
||||
}
|
||||
|
||||
private File file;
|
||||
private TransactionTemplate tTemplate;
|
||||
private StoredProc uocLine;
|
||||
private StoredProc uocLevel;
|
||||
|
||||
|
||||
private XStream initXStream( )
|
||||
{
|
||||
XStream xstream = new XStream( );
|
||||
xstream.processAnnotations( Techs.class );
|
||||
return xstream;
|
||||
}
|
||||
|
||||
|
||||
private Techs loadData( )
|
||||
{
|
||||
FileInputStream fis;
|
||||
try {
|
||||
fis = new FileInputStream( this.file );
|
||||
} catch ( FileNotFoundException e ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
XStream xstream = this.initXStream( );
|
||||
return (Techs) xstream.fromXML( fis );
|
||||
} catch ( Exception e ) {
|
||||
e.printStackTrace( );
|
||||
return null;
|
||||
} finally {
|
||||
try {
|
||||
fis.close( );
|
||||
} catch ( IOException e ) {
|
||||
// EMPTY
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private ClassPathXmlApplicationContext createContext( )
|
||||
{
|
||||
// Load data source and Hibernate properties
|
||||
String[] dataConfig = {
|
||||
this.getDataSource( )
|
||||
};
|
||||
FileSystemXmlApplicationContext ctx = new FileSystemXmlApplicationContext( dataConfig );
|
||||
ctx.refresh( );
|
||||
|
||||
// Load beans
|
||||
String[] cfg = {
|
||||
"configuration/transactions.xml"
|
||||
};
|
||||
return new ClassPathXmlApplicationContext( cfg , true , ctx );
|
||||
}
|
||||
|
||||
|
||||
private void getBeans( ApplicationContext ctx )
|
||||
{
|
||||
PlatformTransactionManager tManager = ctx.getBean( PlatformTransactionManager.class );
|
||||
this.tTemplate = new TransactionTemplate( tManager );
|
||||
|
||||
DataSource dataSource = ctx.getBean( DataSource.class );
|
||||
this.uocLine = new StoredProc( dataSource , "tech" , "uoc_line" );
|
||||
this.uocLine.addParameter( "tln" , Types.VARCHAR );
|
||||
this.uocLine.addParameter( "tld" , Types.VARCHAR );
|
||||
|
||||
this.uocLevel = new StoredProc( dataSource , "tech" , "uoc_level" );
|
||||
this.uocLevel.addParameter( "tech_line" , Types.VARCHAR );
|
||||
this.uocLevel.addParameter( "level" , Types.INTEGER );
|
||||
this.uocLevel.addParameter( "name" , Types.VARCHAR );
|
||||
this.uocLevel.addParameter( "desc" , Types.VARCHAR );
|
||||
this.uocLevel.addParameter( "points" , Types.INTEGER );
|
||||
this.uocLevel.addParameter( "cost" , Types.INTEGER );
|
||||
}
|
||||
|
||||
|
||||
private void importTechnologies( Techs data )
|
||||
{
|
||||
for ( TechLine line : data.lines ) {
|
||||
this.uocLine.execute( line.name , line.description );
|
||||
|
||||
int i = 1;
|
||||
for ( TechLevel level : line.levels ) {
|
||||
this.uocLevel.execute( line.name , i , level.name , level.description , level.points , level.cost );
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void run( )
|
||||
{
|
||||
final Techs data = this.loadData( );
|
||||
if ( data == null ) {
|
||||
System.err.println( "could not read data" );
|
||||
return;
|
||||
}
|
||||
|
||||
AbstractApplicationContext ctx = this.createContext( );
|
||||
this.getBeans( ctx );
|
||||
boolean rv = this.tTemplate.execute( new TransactionCallback< Boolean >( ) {
|
||||
|
||||
@Override
|
||||
public Boolean doInTransaction( TransactionStatus status )
|
||||
{
|
||||
boolean rv;
|
||||
try {
|
||||
importTechnologies( data );
|
||||
rv = true;
|
||||
} catch ( RuntimeException e ) {
|
||||
logger.error( e.getMessage( ) );
|
||||
rv = false;
|
||||
}
|
||||
if ( !rv ) {
|
||||
status.setRollbackOnly( );
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
} );
|
||||
|
||||
if ( rv ) {
|
||||
this.logger.info( "Import successful" );
|
||||
}
|
||||
|
||||
this.tTemplate = null;
|
||||
ToolBase.destroyContext( ctx );
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean setOptions( String... options )
|
||||
{
|
||||
if ( options.length != 1 ) {
|
||||
return false;
|
||||
}
|
||||
this.file = new File( options[ 0 ] );
|
||||
if ( ! ( this.file.isFile( ) && this.file.canRead( ) ) ) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
Reference in a new issue