1
0
mirror of https://github.com/Rogiel/l2jserver2 synced 2025-12-05 23:22:47 +00:00

Implements database structure automatic generation

This commit is contained in:
2011-12-25 14:34:14 -02:00
parent 3fc66cecdc
commit b2e84280ed
77 changed files with 44063 additions and 42113 deletions

View File

@@ -1,4 +1,5 @@
<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"> <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> <modelVersion>4.0.0</modelVersion>
<parent> <parent>
<groupId>com.l2jserver</groupId> <groupId>com.l2jserver</groupId>
@@ -110,10 +111,31 @@
<artifactId>commons-math</artifactId> <artifactId>commons-math</artifactId>
<version>2.2</version> <version>2.2</version>
</dependency> </dependency>
<!-- database -->
<dependency> <dependency>
<groupId>com.mysema.querydsl</groupId> <groupId>com.mysema.querydsl</groupId>
<artifactId>querydsl-sql</artifactId> <artifactId>querydsl-sql</artifactId>
<version>2.3.0</version> <version>2.3.0</version>
</dependency> </dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.18</version>
<type>jar</type>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.3.162</version>
<type>jar</type>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
<version>10.8.2.2</version>
<scope>runtime</scope>
</dependency>
</dependencies> </dependencies>
</project> </project>

View File

@@ -247,16 +247,17 @@ public class XMLConfigurationService extends AbstractService implements
* the output type * the output type
* @return the untransformed value * @return the untransformed value
*/ */
@SuppressWarnings({ "rawtypes", "unchecked" })
private Object untransform(String value, Class<?> type) { private Object untransform(String value, Class<?> type) {
if (value == null) if (value == null)
return null; return null;
if (type == String.class) if (type == String.class)
return value; return value;
final Transformer<?> transformer = TransformerFactory final Transformer transformer = TransformerFactory
.getTransfromer(type); .getTransfromer(type);
if (transformer == null) if (transformer == null)
return null; return null;
return transformer.untransform(value); return transformer.untransform(type, value);
} }
/** /**
@@ -278,7 +279,7 @@ public class XMLConfigurationService extends AbstractService implements
.getTransfromer(type); .getTransfromer(type);
if (transformer == null) if (transformer == null)
return null; return null;
return transformer.transform(value); return transformer.transform(type, value);
} }
/** /**

View File

@@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with l2jserver2. If not, see <http://www.gnu.org/licenses/>. * along with l2jserver2. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.l2jserver.service.database.jdbc; package com.l2jserver.service.database.sql;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.l2jserver.model.Model; import com.l2jserver.model.Model;
@@ -32,20 +32,20 @@ import com.l2jserver.service.database.DatabaseService;
* @param <I> * @param <I>
* the object ID type * the object ID type
*/ */
public abstract class AbstractJDBCDAO<T extends Model<?>, I extends ID<?>> public abstract class AbstractSQLDAO<T extends Model<?>, I extends ID<?>>
extends AbstractDAO<T, I> { extends AbstractDAO<T, I> {
/** /**
* The JDBC Database Service * The JDBC Database Service
*/ */
protected final AbstractJDBCDatabaseService database; protected final AbstractSQLDatabaseService database;
/** /**
* @param database * @param database
* the database service * the database service
*/ */
@Inject @Inject
protected AbstractJDBCDAO(DatabaseService database) { protected AbstractSQLDAO(DatabaseService database) {
super(database); super(database);
this.database = (AbstractJDBCDatabaseService) database; this.database = (AbstractSQLDatabaseService) database;
} }
} }

View File

@@ -14,16 +14,19 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with l2jserver2. If not, see <http://www.gnu.org/licenses/>. * along with l2jserver2. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.l2jserver.service.database.jdbc; package com.l2jserver.service.database.sql;
import java.lang.reflect.InvocationTargetException; import java.io.BufferedReader;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.sql.Connection; import java.sql.Connection;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Statement;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import javax.inject.Provider;
import javax.sql.DataSource; import javax.sql.DataSource;
import org.apache.commons.dbcp.ConnectionFactory; import org.apache.commons.dbcp.ConnectionFactory;
@@ -52,18 +55,20 @@ import com.l2jserver.service.core.threading.AbstractTask;
import com.l2jserver.service.core.threading.AsyncFuture; import com.l2jserver.service.core.threading.AsyncFuture;
import com.l2jserver.service.core.threading.ScheduledAsyncFuture; import com.l2jserver.service.core.threading.ScheduledAsyncFuture;
import com.l2jserver.service.core.threading.ThreadService; import com.l2jserver.service.core.threading.ThreadService;
import com.l2jserver.service.core.vfs.VFSService;
import com.l2jserver.service.database.DAOResolver; import com.l2jserver.service.database.DAOResolver;
import com.l2jserver.service.database.DataAccessObject; import com.l2jserver.service.database.DataAccessObject;
import com.l2jserver.service.database.DatabaseException; import com.l2jserver.service.database.DatabaseException;
import com.l2jserver.service.database.DatabaseService; import com.l2jserver.service.database.DatabaseService;
import com.l2jserver.service.database.dao.DatabaseRow; import com.l2jserver.service.database.dao.DatabaseRow;
import com.l2jserver.service.database.dao.Mapper; import com.l2jserver.service.database.dao.Mapper;
import com.l2jserver.service.database.sql.ddl.QueryFactory;
import com.l2jserver.service.database.sql.ddl.TableFactory;
import com.l2jserver.service.database.sql.ddl.struct.Table;
import com.l2jserver.util.factory.CollectionFactory; import com.l2jserver.util.factory.CollectionFactory;
import com.mysema.query.sql.AbstractSQLQuery; import com.mysema.query.sql.AbstractSQLQuery;
import com.mysema.query.sql.Configuration;
import com.mysema.query.sql.RelationalPathBase; import com.mysema.query.sql.RelationalPathBase;
import com.mysema.query.sql.SQLQueryFactory; import com.mysema.query.sql.SQLQueryFactory;
import com.mysema.query.sql.SQLTemplates;
import com.mysema.query.sql.dml.SQLDeleteClause; import com.mysema.query.sql.dml.SQLDeleteClause;
import com.mysema.query.sql.dml.SQLInsertClause; import com.mysema.query.sql.dml.SQLInsertClause;
import com.mysema.query.sql.dml.SQLUpdateClause; import com.mysema.query.sql.dml.SQLUpdateClause;
@@ -90,7 +95,7 @@ import com.mysema.query.types.Path;
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public abstract class AbstractJDBCDatabaseService extends AbstractService public abstract class AbstractSQLDatabaseService extends AbstractService
implements DatabaseService { implements DatabaseService {
/** /**
* The configuration object * The configuration object
@@ -100,21 +105,30 @@ public abstract class AbstractJDBCDatabaseService extends AbstractService
* The logger * The logger
*/ */
private final Logger log = LoggerFactory private final Logger log = LoggerFactory
.getLogger(AbstractJDBCDatabaseService.class); .getLogger(AbstractSQLDatabaseService.class);
/** /**
* The cache service * The cache service
*/ */
private final CacheService cacheService; protected final CacheService cacheService;
/** /**
* The thread service * The thread service
*/ */
private final ThreadService threadService; protected final ThreadService threadService;
/**
* The VFS Service
*/
protected final VFSService vfsService;
/** /**
* The {@link DAOResolver} instance * The {@link DAOResolver} instance
*/ */
private final DAOResolver daoResolver; private final DAOResolver daoResolver;
/**
* The database engine instance (provides drivers and other factories
* classes)
*/
private DatabaseEngine engine;
/** /**
* The database connection pool * The database connection pool
*/ */
@@ -152,11 +166,8 @@ public abstract class AbstractJDBCDatabaseService extends AbstractService
*/ */
private final Type<?>[] sqlTypes; private final Type<?>[] sqlTypes;
private SQLTemplates queryTemplates;
private Configuration queryConfig;
/** /**
* Configuration interface for {@link AbstractJDBCDatabaseService}. * Configuration interface for {@link AbstractSQLDatabaseService}.
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
@@ -177,50 +188,19 @@ public abstract class AbstractJDBCDatabaseService extends AbstractService
void setJdbcUrl(String jdbcUrl); void setJdbcUrl(String jdbcUrl);
/** /**
* @return the jdbc driver class * @return the database engine class
*/ */
@ConfigurationPropertyGetter(defaultValue = "com.jdbc.jdbc.Driver") @ConfigurationPropertyGetter(defaultValue = "com.l2jserver.service.database.sql.MySQLDatabaseEngine")
@ConfigurationXPath("/configuration/services/database/jdbc/driver") @ConfigurationXPath("/configuration/services/database/jdbc/engine")
Class<?> getDriver(); Class<? extends DatabaseEngine> getDatabaseEngineClass();
/** /**
* @param driver * @param driver
* the new jdbc driver * the new database engine class
*/ */
@ConfigurationPropertySetter @ConfigurationPropertySetter
@ConfigurationXPath("/configuration/services/database/jdbc/driver") @ConfigurationXPath("/configuration/services/database/jdbc/engine")
void setDriver(Class<?> driver); void setDatabaseEngineClass(Class<? extends DatabaseEngine> driver);
/**
* @return the sql template class
*/
@ConfigurationPropertyGetter(defaultValue = "com.mysema.query.sql.MySQLTemplates")
@ConfigurationXPath("/configuration/services/database/jdbc/templates")
Class<? extends SQLTemplates> getSQLTemplatesClass();
/**
* @param templatesClass
* the new sql template class
*/
@ConfigurationPropertySetter
@ConfigurationXPath("/configuration/services/database/jdbc/templates")
void setSQLTemplatesClass(Class<? extends SQLTemplates> templatesClass);
/**
* @return the sql template class
*/
@ConfigurationPropertyGetter(defaultValue = "com.mysema.query.sql.mysql.MySQLQueryFactory")
@ConfigurationXPath("/configuration/services/database/jdbc/queryFactory")
Class<? extends SQLQueryFactory<?, ?, ?, ?, ?, ?>> getSQLQueryFactoryClass();
/**
* @param factoryClass
* the new sql query factory class
*/
@ConfigurationPropertySetter
@ConfigurationXPath("/configuration/services/database/jdbc/queryFactory")
void setSQLQueryFactoryClass(
Class<? extends SQLQueryFactory<?, ?, ?, ?, ?, ?>> factoryClass);
/** /**
* @return the jdbc database username * @return the jdbc database username
@@ -252,6 +232,21 @@ public abstract class AbstractJDBCDatabaseService extends AbstractService
@ConfigurationXPath("/configuration/services/database/jdbc/password") @ConfigurationXPath("/configuration/services/database/jdbc/password")
void setPassword(String password); void setPassword(String password);
/**
* @return the update schema state
*/
@ConfigurationPropertyGetter(defaultValue = "true")
@ConfigurationXPath("/configuration/services/database/jdbc/updateSchema")
String getUpdateSchema();
/**
* @param updateSchema
* the new uodate schema state
*/
@ConfigurationPropertySetter
@ConfigurationXPath("/configuration/services/database/jdbc/updateSchema")
void setUpdateSchema(String updateSchema);
/** /**
* @return the maximum number of active connections * @return the maximum number of active connections
*/ */
@@ -305,24 +300,34 @@ public abstract class AbstractJDBCDatabaseService extends AbstractService
* the cache service * the cache service
* @param threadService * @param threadService
* the thread service * the thread service
* @param vfsService
* the vfs service
* @param daoResolver * @param daoResolver
* the {@link DataAccessObject DAO} resolver * the {@link DataAccessObject DAO} resolver
* @param types * @param types
* the SQL mapping types * the SQL mapping types
*/ */
@Inject @Inject
public AbstractJDBCDatabaseService(ConfigurationService configService, public AbstractSQLDatabaseService(ConfigurationService configService,
CacheService cacheService, ThreadService threadService, CacheService cacheService, ThreadService threadService,
DAOResolver daoResolver, Type<?>... types) { VFSService vfsService, DAOResolver daoResolver, Type<?>... types) {
config = configService.get(JDBCDatabaseConfiguration.class); config = configService.get(JDBCDatabaseConfiguration.class);
this.cacheService = cacheService; this.cacheService = cacheService;
this.threadService = threadService; this.threadService = threadService;
this.vfsService = vfsService;
this.daoResolver = daoResolver; this.daoResolver = daoResolver;
this.sqlTypes = types; this.sqlTypes = types;
} }
@Override @Override
protected void doStart() throws ServiceStartException { protected void doStart() throws ServiceStartException {
try {
engine = config.getDatabaseEngineClass().newInstance();
} catch (InstantiationException | IllegalAccessException e) {
throw new ServiceStartException(
"DatabaseEngine instance not found", e);
}
connectionPool = new GenericObjectPool(null); connectionPool = new GenericObjectPool(null);
connectionPool.setMaxActive(config.getMaxActiveConnections()); connectionPool.setMaxActive(config.getMaxActiveConnections());
connectionPool.setMinIdle(config.getMinIdleConnections()); connectionPool.setMinIdle(config.getMinIdleConnections());
@@ -331,6 +336,8 @@ public abstract class AbstractJDBCDatabaseService extends AbstractService
// test if connections are active while idle // test if connections are active while idle
connectionPool.setTestWhileIdle(true); connectionPool.setTestWhileIdle(true);
// DriverManager.registerDriver(driver)
connectionFactory = new DriverManagerConnectionFactory( connectionFactory = new DriverManagerConnectionFactory(
config.getJdbcUrl(), config.getUsername(), config.getPassword()); config.getJdbcUrl(), config.getUsername(), config.getPassword());
poolableConnectionFactory = new PoolableConnectionFactory( poolableConnectionFactory = new PoolableConnectionFactory(
@@ -339,16 +346,19 @@ public abstract class AbstractJDBCDatabaseService extends AbstractService
dataSource = new PoolingDataSource(connectionPool); dataSource = new PoolingDataSource(connectionPool);
try { try {
queryTemplates = config.getSQLTemplatesClass() final Connection conn = dataSource.getConnection();
.getConstructor(Boolean.TYPE).newInstance(true); try {
} catch (InstantiationException | IllegalAccessException ensureDatabaseSchema(conn);
| IllegalArgumentException | InvocationTargetException } finally {
| NoSuchMethodException | SecurityException e) { conn.close();
throw new ServiceStartException(e); }
} catch (Exception e) {
throw new ServiceStartException("Couldn't update database schema",
e);
} }
queryConfig = new Configuration(queryTemplates);
for (final Type<?> type : sqlTypes) { for (final Type<?> type : sqlTypes) {
queryConfig.register(type); engine.registerType(type);
} }
// cache must be large enough for all world objects, to avoid // cache must be large enough for all world objects, to avoid
@@ -384,6 +394,112 @@ public abstract class AbstractJDBCDatabaseService extends AbstractService
}); });
} }
/**
* Makes sure the database schema is up-to-date with the external database
*
* @param conn
* the connection to be used
* @throws SQLException
* if any {@link SQLException} occur
* @throws IOException
* if any {@link IOException} occur
*/
protected abstract void ensureDatabaseSchema(Connection conn)
throws SQLException, IOException;
/**
*
* @param conn
* the connection to be used
* @param table
* the {@link RelationalPathBase} table
* @return <code>true</code> if a new table was created, <code>false</code>
* otherwise.
* @throws SQLException
* if any {@link SQLException} occur
*/
protected boolean updateSchema(Connection conn, RelationalPathBase<?> table)
throws SQLException {
final Table expected = TableFactory.createTable(table);
String query = null;
boolean create = false;
try {
final Table current = TableFactory.createTable(conn,
engine.getTemplate(), table.getTableName());
query = QueryFactory.alterTableQueryUpdate(expected, current,
engine.getTemplate());
} catch (SQLException e) {
// table may not exist
query = QueryFactory.createTableQuery(expected,
engine.getTemplate());
create = true;
}
if ((engine.getTemplate().supportsAlterTable() && !create) || create)
executeSQL(conn, query);
return create;
}
/**
* Imports an entire SQL file into the database. If the file consists of
* several SQL statements, they will be splitted and executed separated.
*
* @param conn
* the SQL connection
* @param sqlPath
* the path for the SQL file
* @throws IOException
* if any error occur while reading the file
* @throws SQLException
* if any error occur while executing the statements
*/
protected void importSQL(Connection conn, java.nio.file.Path sqlPath)
throws IOException, SQLException {
BufferedReader reader = Files.newBufferedReader(sqlPath,
Charset.defaultCharset());
final StringBuilder builder = new StringBuilder();
String line;
conn.setAutoCommit(false);
try {
while ((line = reader.readLine()) != null) {
builder.append(line).append("\n");
if (line.trim().endsWith(";")) {
executeSQL(conn, builder.substring(0, builder.length() - 2));
builder.setLength(0);
}
}
conn.commit();
} catch (SQLException | IOException e) {
conn.rollback();
throw e;
} finally {
conn.setAutoCommit(true);
}
}
/**
* Executes the SQL code in the databases
*
* @param conn
* the SQL connection
* @param sql
* the SQL query
* @return (see {@link Statement#execute(String)})
* @throws SQLException
* if any error occur while executing the sql query
*/
protected boolean executeSQL(Connection conn, String sql)
throws SQLException {
final Statement st = conn.createStatement();
try {
return st.execute(sql);
} catch (SQLException e) {
log.warn("Error exectuing query {}", sql);
throw e;
} finally {
st.close();
}
}
@Override @Override
public int transaction(TransactionExecutor executor) { public int transaction(TransactionExecutor executor) {
Preconditions.checkNotNull(executor, "executor"); Preconditions.checkNotNull(executor, "executor");
@@ -442,7 +558,6 @@ public abstract class AbstractJDBCDatabaseService extends AbstractService
boolean inTransaction = true; boolean inTransaction = true;
Connection conn = transactionalConnection.get(); Connection conn = transactionalConnection.get();
if (conn == null) { if (conn == null) {
System.out.println("new connection!");
log.debug( log.debug(
"Transactional connection for {} is not set, creating new connection", "Transactional connection for {} is not set, creating new connection",
query); query);
@@ -455,14 +570,7 @@ public abstract class AbstractJDBCDatabaseService extends AbstractService
conn.setAutoCommit(false); conn.setAutoCommit(false);
} }
try { try {
final Connection retConn = conn; return query.query(engine.createSQLQueryFactory(conn));
final SQLQueryFactory<? extends AbstractSQLQuery<?>, ?, ?, ?, ?, ?> factory = createQueryFactory(new Provider<Connection>() {
@Override
public Connection get() {
return retConn;
}
});
return query.query(factory);
} finally { } finally {
if (!inTransaction) { if (!inTransaction) {
conn.commit(); conn.commit();
@@ -485,21 +593,6 @@ public abstract class AbstractJDBCDatabaseService extends AbstractService
} }
} }
@SuppressWarnings("unchecked")
private SQLQueryFactory<? extends AbstractSQLQuery<?>, ?, ?, ?, ?, ?> createQueryFactory(
Provider<Connection> provider) {
try {
return (SQLQueryFactory<? extends AbstractSQLQuery<?>, ?, ?, ?, ?, ?>) config
.getSQLQueryFactoryClass()
.getConstructor(Configuration.class, Provider.class)
.newInstance(queryConfig, provider);
} catch (InstantiationException | IllegalAccessException
| IllegalArgumentException | InvocationTargetException
| NoSuchMethodException | SecurityException e) {
return null;
}
}
@Override @Override
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public <I extends ID<?>, O extends Model<?>> O getCachedObject(I id) { public <I extends ID<?>, O extends Model<?>> O getCachedObject(I id) {
@@ -811,7 +904,7 @@ public abstract class AbstractJDBCDatabaseService extends AbstractService
protected final O perform(AbstractSQLQuery<?> select) { protected final O perform(AbstractSQLQuery<?> select) {
final List<Object[]> results = select.limit(1).list(entity.all()); final List<Object[]> results = select.limit(1).list(entity.all());
if (results.size() == 1) { if (results.size() == 1) {
return mapper.map(entity, new JDBCDatabaseRow(results.get(0), return mapper.map(entity, new SQLDatabaseRow(results.get(0),
entity)); entity));
} else { } else {
return null; return null;
@@ -834,7 +927,7 @@ public abstract class AbstractJDBCDatabaseService extends AbstractService
@Override @Override
protected final List<O> perform(AbstractSQLQuery<?> select) { protected final List<O> perform(AbstractSQLQuery<?> select) {
final List<Object[]> results = select.list(entity.all()); final List<Object[]> results = select.list(entity.all());
final JDBCDatabaseRow row = new JDBCDatabaseRow(entity); final SQLDatabaseRow row = new SQLDatabaseRow(entity);
final List<O> objects = CollectionFactory.newList(); final List<O> objects = CollectionFactory.newList();
for (final Object[] data : results) { for (final Object[] data : results) {
row.setRow(data); row.setRow(data);

View File

@@ -0,0 +1,57 @@
/*
* This file is part of l2jserver2 <l2jserver2.com>.
*
* l2jserver2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* l2jserver2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with l2jserver2. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.service.database.sql;
import java.sql.Connection;
import java.sql.Driver;
import java.sql.SQLException;
import com.l2jserver.service.database.sql.ddl.QueryTemplate;
import com.mysema.query.sql.AbstractSQLQuery;
import com.mysema.query.sql.SQLQueryFactory;
import com.mysema.query.sql.types.Type;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public interface DatabaseEngine {
/**
* @return an newly created {@link Driver} instance
* @throws SQLException
* any sql exception thrown by the driver
*/
Driver newDriver() throws SQLException;
/**
* @param conn
* the connection
* @return the {@link SQLQueryFactory} instance for the given connection
*/
SQLQueryFactory<? extends AbstractSQLQuery<?>, ?, ?, ?, ?, ?> createSQLQueryFactory(
Connection conn);
/**
* @param type
* the type to be registered
*/
void registerType(Type<?> type);
/**
* @return the {@link QueryTemplate} used to create and alter tables
*/
QueryTemplate getTemplate();
}

View File

@@ -0,0 +1,70 @@
/*
* This file is part of l2jserver2 <l2jserver2.com>.
*
* l2jserver2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* l2jserver2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with l2jserver2. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.service.database.sql;
import java.sql.Connection;
import java.sql.Driver;
import java.sql.SQLException;
import javax.inject.Provider;
import org.apache.derby.jdbc.EmbeddedDriver;
import com.l2jserver.service.database.sql.ddl.QueryTemplate;
import com.l2jserver.service.database.sql.ddl.template.DerbyTemplate;
import com.mysema.query.sql.AbstractSQLQuery;
import com.mysema.query.sql.Configuration;
import com.mysema.query.sql.SQLQueryFactory;
import com.mysema.query.sql.SQLQueryFactoryImpl;
import com.mysema.query.sql.types.Type;
/**
* This database provider gives access to MySQL5 databases
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class DerbyDatabaseEngine implements DatabaseEngine {
private final DerbyTemplate template = new DerbyTemplate();
private final Configuration configuration = new Configuration(template);
@Override
public SQLQueryFactory<? extends AbstractSQLQuery<?>, ?, ?, ?, ?, ?> createSQLQueryFactory(
final Connection conn) {
return new SQLQueryFactoryImpl(configuration, new Provider<Connection>() {
@Override
public Connection get() {
return conn;
}
});
}
@Override
public void registerType(Type<?> type) {
configuration.register(type);
}
@Override
public QueryTemplate getTemplate() {
return template;
}
@Override
public Driver newDriver() throws SQLException {
return new EmbeddedDriver();
}
}

View File

@@ -0,0 +1,70 @@
/*
* This file is part of l2jserver2 <l2jserver2.com>.
*
* l2jserver2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* l2jserver2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with l2jserver2. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.service.database.sql;
import java.sql.Connection;
import java.sql.SQLException;
import javax.inject.Provider;
import org.h2.Driver;
import com.l2jserver.service.database.sql.ddl.QueryTemplate;
import com.l2jserver.service.database.sql.ddl.template.H2Template;
import com.mysema.query.sql.AbstractSQLQuery;
import com.mysema.query.sql.Configuration;
import com.mysema.query.sql.SQLQueryFactory;
import com.mysema.query.sql.SQLQueryFactoryImpl;
import com.mysema.query.sql.types.Type;
/**
* This database provider gives access to MySQL5 databases
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class H2DatabaseEngine implements DatabaseEngine {
private final H2Template template = new H2Template();
private final Configuration configuration = new Configuration(template);
@Override
public SQLQueryFactory<? extends AbstractSQLQuery<?>, ?, ?, ?, ?, ?> createSQLQueryFactory(
final Connection conn) {
return new SQLQueryFactoryImpl(configuration,
new Provider<Connection>() {
@Override
public Connection get() {
return conn;
}
});
}
@Override
public void registerType(Type<?> type) {
configuration.register(type);
}
@Override
public QueryTemplate getTemplate() {
return template;
}
@Override
public Driver newDriver() throws SQLException {
return new Driver();
}
}

View File

@@ -0,0 +1,68 @@
/*
* This file is part of l2jserver2 <l2jserver2.com>.
*
* l2jserver2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* l2jserver2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with l2jserver2. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.service.database.sql;
import java.sql.Connection;
import java.sql.Driver;
import java.sql.SQLException;
import javax.inject.Provider;
import com.l2jserver.service.database.sql.ddl.QueryTemplate;
import com.l2jserver.service.database.sql.ddl.template.MySQLTemplate;
import com.mysema.query.sql.AbstractSQLQuery;
import com.mysema.query.sql.Configuration;
import com.mysema.query.sql.SQLQueryFactory;
import com.mysema.query.sql.mysql.MySQLQueryFactory;
import com.mysema.query.sql.types.Type;
/**
* This database provider gives access to MySQL5 databases
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class MySQLDatabaseEngine implements DatabaseEngine {
private final QueryTemplate template = new MySQLTemplate();
private final Configuration configuration = new Configuration(template);
@Override
public SQLQueryFactory<? extends AbstractSQLQuery<?>, ?, ?, ?, ?, ?> createSQLQueryFactory(
final Connection conn) {
return new MySQLQueryFactory(configuration, new Provider<Connection>() {
@Override
public Connection get() {
return conn;
}
});
}
@Override
public void registerType(Type<?> type) {
configuration.register(type);
}
@Override
public QueryTemplate getTemplate() {
return template;
}
@Override
public Driver newDriver() throws SQLException {
return new com.mysql.jdbc.Driver();
}
}

View File

@@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with l2jserver2. If not, see <http://www.gnu.org/licenses/>. * along with l2jserver2. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.l2jserver.service.database.jdbc; package com.l2jserver.service.database.sql;
import java.util.List; import java.util.List;
@@ -26,7 +26,7 @@ import com.mysema.query.types.Path;
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
* *
*/ */
public class JDBCDatabaseRow implements DatabaseRow { public class SQLDatabaseRow implements DatabaseRow {
@SuppressWarnings("unused") @SuppressWarnings("unused")
private final RelationalPathBase<?> entity; private final RelationalPathBase<?> entity;
private final List<Path<?>> paths; private final List<Path<?>> paths;
@@ -39,7 +39,7 @@ public class JDBCDatabaseRow implements DatabaseRow {
* @param entity * @param entity
* the entity * the entity
*/ */
public JDBCDatabaseRow(Object[] row, RelationalPathBase<?> entity) { public SQLDatabaseRow(Object[] row, RelationalPathBase<?> entity) {
this.row = row; this.row = row;
this.entity = entity; this.entity = entity;
paths = entity.getColumns(); paths = entity.getColumns();
@@ -49,7 +49,7 @@ public class JDBCDatabaseRow implements DatabaseRow {
* @param entity * @param entity
* the entity * the entity
*/ */
public JDBCDatabaseRow(RelationalPathBase<?> entity) { public SQLDatabaseRow(RelationalPathBase<?> entity) {
this.entity = entity; this.entity = entity;
paths = entity.getColumns(); paths = entity.getColumns();
} }

View File

@@ -0,0 +1,241 @@
/*
* This file is part of l2jserver2 <l2jserver2.com>.
*
* l2jserver2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* l2jserver2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with l2jserver2. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.service.database.sql.ddl;
import java.util.List;
import com.l2jserver.service.database.sql.ddl.struct.Column;
import com.l2jserver.service.database.sql.ddl.struct.Column.ColumnType;
import com.l2jserver.service.database.sql.ddl.struct.ForeignKey;
import com.l2jserver.service.database.sql.ddl.struct.PrimaryKey;
import com.l2jserver.service.database.sql.ddl.struct.Table;
import com.l2jserver.util.factory.CollectionFactory;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>
*
*/
public class QueryFactory {
public static String createTableQuery(Table table, QueryTemplate template) {
final StringBuilder builder = new StringBuilder();
builder.append(template.getCreateTable())
.append(template.quoteIdentifier(table.getName()))
.append(" (\n").toString();
for (final Column column : table.getColumnList()) {
builder.append("\t");
createColumnDefinition(builder, template, column, false);
builder.append(",\n");
}
if (table.getPrimaryKey() != null) {
builder.append("\t");
generatePrimaryKeyDefinition(builder, template, table,
table.getPrimaryKey());
builder.append(",\n");
}
if (template.supportsForeignKeys()) {
for (final ForeignKey fk : table.getForeignKeys()) {
builder.append("\t");
generateForeignKeyDefinition(builder, template, fk);
builder.append(",\n");
}
}
builder.setLength(builder.length() - 2);
builder.append("\n)");
return builder.toString();
}
public static String alterTableQueryDelta(Table expected, Table current,
QueryTemplate template) {
// detect missing columns
final List<Column> addColumns = CollectionFactory.newList();
final List<Column> updateColumns = CollectionFactory.newList();
for (final Column expectedColumn : expected.getColumnList()) {
final Column missingColumn = current.getColumn(expectedColumn
.getName());
if (missingColumn == null)
addColumns.add(expectedColumn);
else
updateColumns.add(expectedColumn);
}
// detect wrong columns
final List<Column> dropColumns = CollectionFactory.newList();
for (final Column unexpectedColumn : current.getColumnList()) {
final Column expectedColumn = expected.getColumn(unexpectedColumn
.getName());
if (expectedColumn == null)
dropColumns.add(unexpectedColumn);
}
final StringBuilder builder = new StringBuilder();
builder.append(template.getAlterTable())
.append(template.quoteIdentifier(expected.getName()))
.append("\n").toString();
for (final Column column : addColumns) {
builder.append("\t").append(template.getAddColumn());
createColumnDefinition(builder, template, column, true);
builder.append(",\n");
}
for (final Column column : dropColumns) {
builder.append("\t").append(template.getDropColumn())
.append(template.quoteIdentifier(column.getName()))
.append(",\n");
}
for (final Column column : updateColumns) {
builder.append("\t").append(template.getAlterColumn());
if (template.supportsColumnRename())
builder.append(template.quoteIdentifier(column.getName()))
.append(" ");
createColumnDefinition(builder, template, column, true);
builder.append(",\n");
}
builder.setLength(builder.length() - 2);
return builder.toString();
}
public static String alterTableQueryUpdate(Table expected, Table current,
QueryTemplate template) {
// detect missing columns
final List<Column> addColumns = CollectionFactory.newList();
final List<Column> updateColumns = CollectionFactory.newList();
for (final Column expectedColumn : expected.getColumnList()) {
final Column missingColumn = current.getColumn(expectedColumn
.getName());
if (missingColumn == null)
addColumns.add(expectedColumn);
else
updateColumns.add(expectedColumn);
}
final StringBuilder builder = new StringBuilder();
builder.append(template.getAlterTable())
.append(template.quoteIdentifier(expected.getName()))
.append("\n").toString();
for (final Column column : addColumns) {
builder.append("\t").append(template.getAddColumn());
createColumnDefinition(builder, template, column, true);
builder.append(",\n");
}
for (final Column column : updateColumns) {
builder.append("\t").append(template.getAlterColumn());
if (template.supportsColumnRename())
builder.append(template.quoteIdentifier(column.getName()))
.append(" ");
createColumnDefinition(builder, template, column, true);
builder.append(",\n");
}
builder.setLength(builder.length() - 2);
return builder.toString();
}
public static String alterTableQueryMissing(Table expected, Table current,
QueryTemplate template) {
// detect missing columns
final List<Column> addColumns = CollectionFactory.newList();
for (final Column expectedColumn : expected.getColumnList()) {
final Column missingColumn = current.getColumn(expectedColumn
.getName());
if (missingColumn == null)
addColumns.add(expectedColumn);
}
if (addColumns.isEmpty())
return null;
final StringBuilder builder = new StringBuilder();
builder.append(template.getAlterTable())
.append(template.quoteIdentifier(expected.getName()))
.append("\n").toString();
for (final Column column : addColumns) {
builder.append("\t").append(template.getAddColumn());
createColumnDefinition(builder, template, column, true);
builder.append(",\n");
}
builder.setLength(builder.length() - 2);
return builder.toString();
}
private static void createColumnDefinition(StringBuilder builder,
QueryTemplate template, Column column, boolean alter) {
builder.append(template.quoteIdentifier(column.getName())).append(" ");
if ((alter && template.supportsColumnChangeTypes()) || !alter) {
builder.append(template.getDatabaseType(column.getType()));
if (column.getType() == ColumnType.ENUM && template.supportsEnum()) {
builder.append("(");
if (!column.getEnumValues().isEmpty()) {
for (final String val : column.getEnumValues()) {
builder.append(template.quoteValue(val)).append(",");
}
builder.setLength(builder.length() - 1);
}
builder.append(")");
} else if (template.getTypeSizeRequirement(column.getType())
&& (column.getSize() > 0 || column.getEnumValues() != null)) {
int size = column.getSize();
if (column.getEnumValues() != null) {
for (final String val : column.getEnumValues()) {
if (val.length() > column.getSize())
// redefine size
size = val.length();
}
}
builder.append("(").append(size).append(")");
}
}
if (column.isNullable() == false) {
builder.append(template.getNotNull());
}
if (column.isAutoIncrement() && template.supportsAutoIncrement()) {
builder.append(template.getAutoIncrement());
} else if (column.hasDefaultValue()) {
builder.append(" DEFAULT ");
if (column.getDefaultValue() == null) {
builder.append("NULL");
} else {
builder.append(template.quoteValue(column.getDefaultValue()));
}
}
}
private static void generatePrimaryKeyDefinition(StringBuilder builder,
QueryTemplate template, Table table, PrimaryKey pk) {
builder.append("CONSTRAINT ")
.append(template.quoteIdentifier(table.getName() + "-"
+ pk.getColumn().getName())).append(" PRIMARY KEY(")
.append(template.quoteIdentifier(pk.getColumn().getName()))
.append(")");
// builder.append("PRIMARY KEY (")
// .append(template.quoteIdentifier(pk.getColumn().getName()))
// .append(")");
}
private static void generateForeignKeyDefinition(StringBuilder builder,
QueryTemplate template, ForeignKey fk) {
builder.append("CONSTRAINT ")
.append(template.quoteIdentifier(fk.getName())).append(" KEY(");
for (final Column column : fk.getColumns()) {
builder.append(template.quoteIdentifier(column.getName())).append(
", ");
}
builder.setLength(builder.length() - 2);
builder.append(")");
}
}

View File

@@ -0,0 +1,83 @@
/*
* This file is part of l2jserver2 <l2jserver2.com>.
*
* l2jserver2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* l2jserver2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with l2jserver2. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.service.database.sql.ddl;
import com.l2jserver.service.database.sql.ddl.struct.Column.ColumnType;
import com.mysema.query.sql.SQLTemplates;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>
*
*/
public abstract class QueryTemplate extends SQLTemplates {
/**
* @param quoteStr
* the quote string
* @param escape
* the escape char
* @param useQuotes
* whether to use quotes or not
*/
protected QueryTemplate(String quoteStr, char escape, boolean useQuotes) {
super(quoteStr, escape, useQuotes);
}
// String quoteTableName(String name);
// String quoteColumnName(String name);
// String quoteValue(String value);
//
// String getCreateTable(String tableName);
// String getColumnDefinition(String name, ColumnType type, int size,
// boolean nullable);
public abstract String getDatabaseType(ColumnType type);
public abstract boolean getTypeSizeRequirement(ColumnType type);
public abstract boolean supportsEnum();
public abstract boolean supportsAutoIncrement();
public abstract boolean supportsForeignKeys();
public abstract boolean supportsColumnChangeTypes();
public abstract boolean supportsColumnRename();
public abstract boolean supportsAlterTable();
public String quoteValue(String defaultValue) {
return new StringBuilder("'").append(defaultValue).append("'")
.toString();
}
public String getAlterTable() {
return "alter table ";
}
public String getAddColumn() {
return "add column ";
}
public String getDropColumn() {
return "drop column ";
}
public String getAlterColumn() {
return "alter column ";
}
}

View File

@@ -0,0 +1,234 @@
/*
* This file is part of l2jserver2 <l2jserver2.com>.
*
* l2jserver2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* l2jserver2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with l2jserver2. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.service.database.sql.ddl;
import java.lang.reflect.Field;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Types;
import java.util.Date;
import java.util.List;
import java.util.Map;
import com.l2jserver.service.database.sql.ddl.annotation.ColumnAutoIncrement;
import com.l2jserver.service.database.sql.ddl.annotation.ColumnDefault;
import com.l2jserver.service.database.sql.ddl.annotation.ColumnNullable;
import com.l2jserver.service.database.sql.ddl.annotation.ColumnSize;
import com.l2jserver.service.database.sql.ddl.struct.Column;
import com.l2jserver.service.database.sql.ddl.struct.Column.ColumnType;
import com.l2jserver.service.database.sql.ddl.struct.ForeignKey;
import com.l2jserver.service.database.sql.ddl.struct.PrimaryKey;
import com.l2jserver.service.database.sql.ddl.struct.Table;
import com.l2jserver.util.ClassUtils;
import com.l2jserver.util.factory.CollectionFactory;
import com.mysema.query.sql.RelationalPathBase;
import com.mysema.query.types.Path;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>
*
*/
public class TableFactory {
/**
* Creates an {@link Table} object from an {@link RelationalPathBase}
*
* @param tablePath
* the table path
* @return the {@link Table} object
*/
public static Table createTable(RelationalPathBase<?> tablePath) {
final Map<String, Column> columns = CollectionFactory.newMap();
for (final Path<?> path : tablePath.all()) {
final Column col = createColumn(tablePath, path);
columns.put(col.getName(), col);
}
return new Table(tablePath.getTableName(), columns, createPK(tablePath,
columns), createFKs(tablePath, columns));
}
/**
* Reads an table from the database and returns the parsed object.
* <p>
* Note that this method does not parse everything: default values, enum
* types, primary and foreign keys are not parsed.
*
* @param conn
* the JDBC {@link Connection}
* @param template the query template
* @param tableName
* the table name
* @return the parsed table
* @throws SQLException
* if any sql error occur
*/
public static Table createTable(Connection conn, QueryTemplate template,
String tableName) throws SQLException {
Statement st = conn.createStatement();
try {
st.execute(new StringBuilder(template.getSelect()).append("*")
.append(template.getFrom())
.append(template.quoteIdentifier(tableName)).toString());
final ResultSet rs = st.getResultSet();
ResultSetMetaData metaData = rs.getMetaData();
final Map<String, Column> columns = CollectionFactory.newMap();
for (int i = 1; i <= metaData.getColumnCount(); i++) {
columns.put(metaData.getColumnName(i),
new Column(metaData.getColumnName(i),
getColumnType(metaData.getColumnType(i)),
false, metaData.getColumnDisplaySize(i), false,
null));
}
return new Table(metaData.getTableName(1), columns, null, null);
} finally {
st.close();
}
}
/**
* Creates the foreign key list
*
* @param tablePath
* the table object
* @param columns
* the columns
* @return the foreign key list
*/
private static List<ForeignKey> createFKs(RelationalPathBase<?> tablePath,
Map<String, Column> columns) {
final List<ForeignKey> fks = CollectionFactory.newList();
for (final com.mysema.query.sql.ForeignKey<?> fk : tablePath
.getForeignKeys()) {
StringBuilder name = new StringBuilder();
final List<Column> cols = CollectionFactory.newList();
for (final Path<?> path : fk.getLocalColumns()) {
String colName = path.getMetadata().getExpression().toString();
cols.add(columns.get(colName));
name.append(colName).append("-");
}
name.setLength(name.length() - 1);
fks.add(new ForeignKey(name.toString(), cols));
}
return fks;
}
private static PrimaryKey createPK(RelationalPathBase<?> tablePath,
Map<String, Column> columns) {
return new PrimaryKey(columns.get(tablePath.getPrimaryKey()
.getLocalColumns().get(0).getMetadata().getExpression()
.toString()));
}
private static Column createColumn(RelationalPathBase<?> tablePath,
Path<?> path) {
final String columnName = path.getMetadata().getExpression().toString();
final ColumnType columnType = getColumnType(path.getType());
final Field field = ClassUtils.getFieldWithValue(tablePath, path);
// settings
int columnSize = -1;
boolean columnNullable = false;
boolean hasDefaultValue = false;
String defaultValue = null;
if (field != null) {
final ColumnSize size = field.getAnnotation(ColumnSize.class);
if (size != null) {
columnSize = size.value();
}
final ColumnAutoIncrement autoInc = field
.getAnnotation(ColumnAutoIncrement.class);
if (autoInc != null) {
return new Column(columnName, columnSize, true);
}
final ColumnNullable nullable = field
.getAnnotation(ColumnNullable.class);
if (nullable == null) {
columnNullable = false;
} else {
columnNullable = true;
}
final ColumnDefault def = field.getAnnotation(ColumnDefault.class);
if (def == null && nullable != null) {
hasDefaultValue = true;
defaultValue = null;
} else if (def != null) {
hasDefaultValue = true;
defaultValue = def.value();
}
}
if (columnType == ColumnType.ENUM) {
@SuppressWarnings("unchecked")
Class<? extends Enum<?>> enumClass = (Class<? extends Enum<?>>) path
.getType();
Enum<?>[] enums = enumClass.getEnumConstants();
final List<String> enumValues = CollectionFactory.newList();
for (final Enum<?> e : enums) {
enumValues.add(e.name());
}
return new Column(columnName, columnNullable, enumValues,
hasDefaultValue, defaultValue);
}
return new Column(columnName, columnType, columnNullable, columnSize,
hasDefaultValue, defaultValue);
}
private static ColumnType getColumnType(Class<?> type) {
if (ClassUtils.isSubclass(type, String.class))
return ColumnType.STRING;
else if (type.isEnum())
return ColumnType.ENUM;
else if (ClassUtils.isSubclass(type, Integer.class))
return ColumnType.INTEGER;
else if (ClassUtils.isSubclass(type, Long.class))
return ColumnType.INTEGER;
else if (ClassUtils.isSubclass(type, Double.class))
return ColumnType.DOUBLE;
else if (ClassUtils.isSubclass(type, Float.class))
return ColumnType.DOUBLE;
else if (ClassUtils.isSubclass(type, Date.class))
return ColumnType.TIMESTAMP;
return null;
}
private static ColumnType getColumnType(int jdbcType) {
switch (jdbcType) {
case Types.INTEGER:
return ColumnType.INTEGER;
case Types.VARCHAR:
return ColumnType.STRING;
case Types.TIMESTAMP:
return ColumnType.TIMESTAMP;
case Types.DOUBLE:
return ColumnType.TIMESTAMP;
case Types.CHAR:
return ColumnType.ENUM;
default:
return null;
}
}
}

View File

@@ -0,0 +1,36 @@
/*
* This file is part of l2jserver2 <l2jserver2.com>.
*
* l2jserver2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* l2jserver2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with l2jserver2. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.service.database.sql.ddl.annotation;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import com.mysema.query.sql.RelationalPath;
/**
* This annotation defines the attributes for the {@link RelationalPath}
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface ColumnAutoIncrement {
}

View File

@@ -0,0 +1,37 @@
/*
* This file is part of l2jserver2 <l2jserver2.com>.
*
* l2jserver2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* l2jserver2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with l2jserver2. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.service.database.sql.ddl.annotation;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import com.mysema.query.sql.RelationalPath;
/**
* This annotation defines the attributes for the {@link RelationalPath}
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface ColumnDefault {
String value() default "NULL";
}

View File

@@ -0,0 +1,36 @@
/*
* This file is part of l2jserver2 <l2jserver2.com>.
*
* l2jserver2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* l2jserver2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with l2jserver2. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.service.database.sql.ddl.annotation;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import com.mysema.query.sql.RelationalPath;
/**
* This annotation defines the attributes for the {@link RelationalPath}
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface ColumnNullable {
}

View File

@@ -0,0 +1,37 @@
/*
* This file is part of l2jserver2 <l2jserver2.com>.
*
* l2jserver2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* l2jserver2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with l2jserver2. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.service.database.sql.ddl.annotation;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import com.mysema.query.sql.RelationalPath;
/**
* This annotation defines the attributes for the {@link RelationalPath}
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface ColumnSize {
int value();
}

View File

@@ -0,0 +1,183 @@
/*
* This file is part of l2jserver2 <l2jserver2.com>.
*
* l2jserver2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* l2jserver2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with l2jserver2. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.service.database.sql.ddl.struct;
import java.util.List;
import com.l2jserver.util.factory.CollectionFactory;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class Column {
private final String name;
private final ColumnType type;
public enum ColumnType {
STRING, ENUM, INTEGER, DOUBLE, TIMESTAMP;
}
private boolean nullable = true;
private int size = 0;
private boolean hasDefaultValue = false;
private String defaultValue = null;
private List<String> enumValues = CollectionFactory.newList();
private boolean autoIncrement;
/**
* @param name
* the column name
* @param type
* the column type
*/
public Column(String name, ColumnType type) {
this.name = name;
this.type = type;
}
/**
* @param name
* the column name
* @param size
* the column maximum value size
* @param autoIncrement
* if the column is auto incrementable
*/
public Column(String name, Integer size, boolean autoIncrement) {
this.name = name;
this.type = ColumnType.INTEGER;
this.nullable = false;
this.size = size;
this.hasDefaultValue = false;
this.autoIncrement = autoIncrement;
}
/**
* @param name
* the column name
* @param type
* the column type
* @param nullable
* if the column can be nulled
* @param size
* the column maximum value size
* @param hasDefaultValue
* if the column has an default value
* @param defaultValue
* the columns default value
*/
public Column(String name, ColumnType type, Boolean nullable, Integer size,
boolean hasDefaultValue, String defaultValue) {
super();
this.name = name;
this.type = type;
this.nullable = nullable;
this.size = size;
this.hasDefaultValue = hasDefaultValue;
this.defaultValue = defaultValue;
}
/**
* @param name
* the column name
* @param nullable
* if the column can have null values
* @param enumValues
* the enum values
* @param hasDefaultValue
* if the column has an default value
* @param defaultValue
* the column default value
*/
public Column(String name, Boolean nullable, List<String> enumValues,
boolean hasDefaultValue, String defaultValue) {
super();
this.name = name;
this.type = ColumnType.ENUM;
this.nullable = nullable;
this.hasDefaultValue = hasDefaultValue;
this.defaultValue = defaultValue;
this.enumValues.addAll(enumValues);
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @return the nullable
*/
public Boolean isNullable() {
return nullable;
}
/**
* @return the size
*/
public Integer getSize() {
return size;
}
/**
* @return the type
*/
public ColumnType getType() {
return type;
}
/**
* @return the hasDefaultValue
*/
public boolean hasDefaultValue() {
return hasDefaultValue;
}
/**
* @return the defaultValue
*/
public String getDefaultValue() {
return defaultValue;
}
/**
* @return the enumValues
*/
public List<String> getEnumValues() {
return enumValues;
}
/**
* @return the autoIncrement
*/
public boolean isAutoIncrement() {
return autoIncrement;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder().append(name).append(" ")
.append(type.name());
if (size > 0)
builder.append("(").append(size).append(")");
if (nullable == false)
builder.append(" NOT NULL");
return builder.toString();
}
}

View File

@@ -0,0 +1,54 @@
/*
* This file is part of l2jserver2 <l2jserver2.com>.
*
* l2jserver2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* l2jserver2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with l2jserver2. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.service.database.sql.ddl.struct;
import java.util.Collections;
import java.util.List;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>
*
*/
public class ForeignKey {
private final String name;
private final List<Column> columns;
/**
* @param name
* the key name
* @param columns
* the key columns
*/
public ForeignKey(String name, List<Column> columns) {
this.name = name;
this.columns = columns;
}
/**
* @return the columns
*/
public List<Column> getColumns() {
return Collections.unmodifiableList(columns);
}
/**
* @return the name
*/
public String getName() {
return name;
}
}

View File

@@ -0,0 +1,40 @@
/*
* This file is part of l2jserver2 <l2jserver2.com>.
*
* l2jserver2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* l2jserver2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with l2jserver2. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.service.database.sql.ddl.struct;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class PrimaryKey {
private final Column column;
/**
* @param column
* the primary key column
*/
public PrimaryKey(Column column) {
super();
this.column = column;
}
/**
* @return the column
*/
public Column getColumn() {
return column;
}
}

View File

@@ -0,0 +1,118 @@
/*
* This file is part of l2jserver2 <l2jserver2.com>.
*
* l2jserver2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* l2jserver2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with l2jserver2. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.service.database.sql.ddl.struct;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import com.l2jserver.util.factory.CollectionFactory;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>
*
*/
public class Table {
private final String name;
private final Map<String, Column> columns = CollectionFactory.newMap();
private final PrimaryKey primaryKey;
private final List<ForeignKey> foreignKeys = CollectionFactory.newList();
public Table(String name, Map<String, Column> columns,
PrimaryKey primaryKey, List<ForeignKey> foreignKeys) {
this.name = name;
this.columns.putAll(columns);
this.primaryKey = primaryKey;
if (foreignKeys != null)
this.foreignKeys.addAll(foreignKeys);
}
public Table(String name, PrimaryKey primaryKey) {
this.name = name;
this.primaryKey = primaryKey;
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @return the columns
*/
public Map<String, Column> getColumns() {
return Collections.unmodifiableMap(columns);
}
/**
* @return the columns
*/
public Collection<Column> getColumnList() {
return columns.values();
}
/**
* Adds a new column
*
* @param column
* the column object
* @return the same column
*/
public Column addColumn(Column column) {
columns.put(column.getName(), column);
return column;
}
public Column getColumn(String name) {
for (final Column column : columns.values()) {
if (name.equals(column.getName()))
return column;
}
return null;
}
/**
* @return the primaryKey
*/
public PrimaryKey getPrimaryKey() {
return primaryKey;
}
/**
* @return the foreignKeys
*/
public List<ForeignKey> getForeignKeys() {
return Collections.unmodifiableList(foreignKeys);
}
@Override
public String toString() {
final StringBuilder builder = new StringBuilder();
builder.append("CREATE TABLE ").append(name).append(" (\n");
for (final Column column : columns.values()) {
builder.append("\t").append(column.toString()).append(",\n");
}
builder.setLength(builder.length() - 2);
builder.append("\n)");
return builder.toString();
}
}

View File

@@ -0,0 +1,127 @@
/*
* This file is part of l2jserver2 <l2jserver2.com>.
*
* l2jserver2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* l2jserver2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with l2jserver2. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.service.database.sql.ddl.template;
import com.l2jserver.service.database.sql.ddl.QueryTemplate;
import com.l2jserver.service.database.sql.ddl.struct.Column.ColumnType;
import com.mysema.query.QueryMetadata;
import com.mysema.query.QueryModifiers;
import com.mysema.query.sql.support.SerializationContext;
import com.mysema.query.types.Ops;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class DerbyTemplate extends QueryTemplate {
private String limitOffsetTemplate = "\noffset {1s} rows fetch next {0s} rows only";
private String limitTemplate = "\nfetch first {0s} rows only";
private String offsetTemplate = "\noffset {0s} rows";
public DerbyTemplate() {
super("\"", '\\', true);
addClass2TypeMappings("smallint", Byte.class);
setAutoIncrement(" generated always as identity");
add(Ops.CONCAT, "varchar({0} || {1})");
add(Ops.MathOps.ROUND, "floor({0})");
add(Ops.DateTimeOps.DAY_OF_MONTH, "day({0})");
add(NEXTVAL, "next value for {0s}");
// case for eq
add(Ops.CASE_EQ, "case {1} end");
add(Ops.CASE_EQ_WHEN, "when {0} = {1} then {2} {3}");
add(Ops.CASE_EQ_ELSE, "else {0}");
}
protected void serializeModifiers(QueryMetadata metadata,
SerializationContext context) {
QueryModifiers mod = metadata.getModifiers();
if (mod.getLimit() == null) {
context.handle(offsetTemplate, mod.getOffset());
} else if (mod.getOffset() == null) {
context.handle(limitTemplate, mod.getLimit());
} else {
context.handle(limitOffsetTemplate, mod.getLimit(), mod.getOffset());
}
}
@Override
public String getDatabaseType(ColumnType type) {
switch (type) {
case ENUM:
return "varchar";
case DOUBLE:
return "double";
case INTEGER:
return "int";
case STRING:
return "varchar";
case TIMESTAMP:
return "timestamp";
default:
return "varchar";
}
}
@Override
public boolean getTypeSizeRequirement(ColumnType type) {
switch (type) {
case DOUBLE:
case TIMESTAMP:
case INTEGER:
return false;
case ENUM:
case STRING:
return true;
default:
return true;
}
}
@Override
public boolean supportsEnum() {
return false;
}
@Override
public boolean supportsAutoIncrement() {
return true;
}
@Override
public boolean supportsForeignKeys() {
return false;
}
@Override
public boolean supportsColumnChangeTypes() {
return false;
}
@Override
public boolean supportsColumnRename() {
return false;
}
@Override
public boolean supportsAlterTable() {
return false;
}
}

View File

@@ -0,0 +1,97 @@
/*
* This file is part of l2jserver2 <l2jserver2.com>.
*
* l2jserver2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* l2jserver2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with l2jserver2. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.service.database.sql.ddl.template;
import com.l2jserver.service.database.sql.ddl.QueryTemplate;
import com.l2jserver.service.database.sql.ddl.struct.Column.ColumnType;
import com.mysema.query.types.Ops;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class H2Template extends QueryTemplate {
public H2Template() {
super("\"", '\\', true);
setNativeMerge(true);
add(Ops.MathOps.ROUND, "round({0},0)");
add(Ops.TRIM, "trim(both from {0})");
add(Ops.CONCAT, "concat({0},{1})");
}
@Override
public String getDatabaseType(ColumnType type) {
switch (type) {
case ENUM:
return "varchar";
case DOUBLE:
return "double";
case INTEGER:
return "integer";
case STRING:
return "varchar";
case TIMESTAMP:
return "timestamp";
default:
return "varchar";
}
}
@Override
public boolean getTypeSizeRequirement(ColumnType type) {
switch (type) {
case DOUBLE:
case TIMESTAMP:
return false;
case ENUM:
case INTEGER:
case STRING:
return true;
default:
return true;
}
}
@Override
public boolean supportsEnum() {
return false;
}
@Override
public boolean supportsAutoIncrement() {
return true;
}
@Override
public boolean supportsForeignKeys() {
return false;
}
@Override
public boolean supportsColumnChangeTypes() {
return true;
}
@Override
public boolean supportsColumnRename() {
return false;
}
@Override
public boolean supportsAlterTable() {
return false;
}
}

View File

@@ -0,0 +1,167 @@
/*
* This file is part of l2jserver2 <l2jserver2.com>.
*
* l2jserver2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* l2jserver2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with l2jserver2. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.service.database.sql.ddl.template;
import java.math.BigDecimal;
import com.l2jserver.service.database.sql.ddl.QueryTemplate;
import com.l2jserver.service.database.sql.ddl.struct.Column.ColumnType;
import com.mysema.query.types.Ops;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class MySQLTemplate extends QueryTemplate {
public MySQLTemplate() {
super("`", '\\', true);
addClass2TypeMappings("bool", Boolean.class);
addClass2TypeMappings("int", Integer.class);
addClass2TypeMappings("decimal", Double.class, Float.class,
BigDecimal.class);
// addClass2TypeMappings("text", String.class);
add(Ops.CONCAT, "concat({0}, {1})", 0);
add(Ops.MATCHES, "{0} regexp {1}");
add(Ops.DateTimeOps.YEAR_MONTH, "extract(year_month from {0})");
// like without escape
add(Ops.LIKE, "{0} like {1}");
add(Ops.ENDS_WITH, "{0} like {%1}");
add(Ops.ENDS_WITH_IC, "{0l} like {%%1}");
add(Ops.STARTS_WITH, "{0} like {1%}");
add(Ops.STARTS_WITH_IC, "{0l} like {1%%}");
add(Ops.STRING_CONTAINS, "{0} like {%1%}");
add(Ops.STRING_CONTAINS_IC, "{0l} like {%%1%%}");
}
// @Override
// public String quoteTableName(String name) {
// return new StringBuilder().append("`").append(name).append("`")
// .toString();
// }
//
// @Override
// public String quoteColumnName(String name) {
// return new StringBuilder().append("`").append(name).append("`")
// .toString();
// }
//
// @Override
// public String quoteValue(String value) {
// return new StringBuilder().append("'").append(value).append("'")
// .toString();
// }
//
// @Override
// public String getCreateTable(String tableName) {
// return new StringBuilder().append("CREATE TABLE `").append(tableName)
// .append("` (").toString();
// }
//
// @Override
// public String getColumnDefinition(String name, ColumnType type, int size,
// boolean nullable) {
// final StringBuilder builder = new StringBuilder();
// builder.append("`").append(name).append("` ")
// .append(getDatabaseType(type));
// if (getTypeSizeRequirement(type) && size > 0)
// builder.append("(").append(size).append(")");
// if (nullable) {
// builder.append(" NOT NULL");
// }
// return builder.toString();
// }
@Override
public String getDatabaseType(ColumnType type) {
switch (type) {
case ENUM:
return "enum";
case DOUBLE:
return "double";
case INTEGER:
return "int";
case STRING:
return "varchar";
case TIMESTAMP:
return "timestamp";
default:
return "varchar";
}
}
@Override
public boolean getTypeSizeRequirement(ColumnType type) {
switch (type) {
case ENUM:
case DOUBLE:
case TIMESTAMP:
return false;
case INTEGER:
case STRING:
return true;
default:
return true;
}
}
@Override
public String getAddColumn() {
return "add ";
}
@Override
public String getDropColumn() {
return "drop ";
}
@Override
public String getAlterColumn() {
return "change ";
}
@Override
public boolean supportsEnum() {
return true;
}
@Override
public boolean supportsAutoIncrement() {
return true;
}
@Override
public boolean supportsForeignKeys() {
return true;
}
@Override
public boolean supportsColumnChangeTypes() {
return true;
}
@Override
public boolean supportsColumnRename() {
return true;
}
@Override
public boolean supportsAlterTable() {
return true;
}
}

View File

@@ -16,6 +16,8 @@
*/ */
package com.l2jserver.util; package com.l2jserver.util;
import java.lang.reflect.Field;
/** /**
* This class contains utilities that are used when we are working with classes * This class contains utilities that are used when we are working with classes
* *
@@ -90,4 +92,32 @@ public class ClassUtils {
return packageName.equals(classPackage); return packageName.equals(classPackage);
} }
} }
/**
* Recursively searches for an {@link Field} within an given {@link Class}
* that is instance of <code>object</code> for an field with the given
* <code>value</code>
*
* @param object
* the object to look for the value
* @param value
* the value to be looked for
* @return the field that has the correct value, if any.
*/
public static Field getFieldWithValue(Object object, Object value) {
final Class<?> clazz = object.getClass();
for (final Field field : clazz.getDeclaredFields()) {
boolean accessible = field.isAccessible();
try {
field.setAccessible(true);
if (field.get(object) == value)
return field;
} catch (IllegalArgumentException | IllegalAccessException e) {
continue;
} finally {
field.setAccessible(accessible);
}
}
return null;
}
} }

View File

@@ -29,22 +29,30 @@ public interface Transformer<T> {
/** /**
* Transform the object in a string * Transform the object in a string
* *
* @param type
* the type this transformer transforms. Useful when it can
* transform several types at once (such as an enum)
* @param value * @param value
* the object * the object
* @return the string of the object * @return the string of the object
* @throws TransformException * @throws TransformException
* if any error occur while transforming * if any error occur while transforming
*/ */
String transform(T value) throws TransformException; String transform(Class<? extends T> type, T value)
throws TransformException;
/** /**
* Untransforms the string back to an object * Untransforms the string back to an object
* *
* @param value * @param value
* the string * the string
* @param type
* the type this transformer transforms. Useful when it can
* transform several types at once (such as an enum)
* @return the object * @return the object
* @throws TransformException * @throws TransformException
* if any error occur while transforming * if any error occur while transforming
*/ */
T untransform(String value) throws TransformException; T untransform(Class<? extends T> type, String value)
throws TransformException;
} }

View File

@@ -30,12 +30,12 @@ public class BooleanTransformer implements Transformer<Boolean> {
public static final BooleanTransformer SHARED_INSTANCE = new BooleanTransformer(); public static final BooleanTransformer SHARED_INSTANCE = new BooleanTransformer();
@Override @Override
public String transform(Boolean value) { public String transform(Class<? extends Boolean> type, Boolean value) {
return (value ? "true" : "false"); return (value ? "true" : "false");
} }
@Override @Override
public Boolean untransform(String value) { public Boolean untransform(Class<? extends Boolean> type, String value) {
return Boolean.parseBoolean(value); return Boolean.parseBoolean(value);
} }

View File

@@ -30,12 +30,12 @@ public class ByteTransformer implements Transformer<Byte> {
public static final ByteTransformer SHARED_INSTANCE = new ByteTransformer(); public static final ByteTransformer SHARED_INSTANCE = new ByteTransformer();
@Override @Override
public String transform(Byte value) { public String transform(Class<? extends Byte> type, Byte value) {
return Double.toString(value); return Double.toString(value);
} }
@Override @Override
public Byte untransform(String value) { public Byte untransform(Class<? extends Byte> type, String value) {
return Byte.decode(value); return Byte.decode(value);
} }

View File

@@ -31,12 +31,12 @@ public class ClassTransformer implements Transformer<Class<?>> {
public static final ClassTransformer SHARED_INSTANCE = new ClassTransformer(); public static final ClassTransformer SHARED_INSTANCE = new ClassTransformer();
@Override @Override
public String transform(Class<?> value) { public String transform(Class<? extends Class<?>> type, Class<?> value) {
return value.getName(); return value.getName();
} }
@Override @Override
public Class<?> untransform(String value) { public Class<?> untransform(Class<? extends Class<?>> type, String value) {
try { try {
return Class.forName(value); return Class.forName(value);
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {

View File

@@ -30,12 +30,12 @@ public class DoubleTransformer implements Transformer<Double> {
public static final DoubleTransformer SHARED_INSTANCE = new DoubleTransformer(); public static final DoubleTransformer SHARED_INSTANCE = new DoubleTransformer();
@Override @Override
public String transform(Double value) { public String transform(Class<? extends Double> type, Double value) {
return Double.toString(value); return Double.toString(value);
} }
@Override @Override
public Double untransform(String value) { public Double untransform(Class<? extends Double> type, String value) {
return Double.parseDouble(value); return Double.parseDouble(value);
} }

View File

@@ -0,0 +1,48 @@
/*
* This file is part of l2jserver2 <l2jserver2.com>.
*
* l2jserver2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* l2jserver2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with l2jserver2. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.util.transformer.impl;
import com.l2jserver.util.transformer.TransformException;
import com.l2jserver.util.transformer.Transformer;
/**
* Transform an {@link Enum} into an string.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class EnumTransformer implements Transformer<Enum<?>> {
/**
* This transformer shared instance
*/
public static final EnumTransformer SHARED_INSTANCE = new EnumTransformer();
@Override
public String transform(Class<? extends Enum<?>> type, Enum<?> value) {
return value.name();
}
@Override
public Enum<?> untransform(Class<? extends Enum<?>> type, String value)
throws TransformException {
for (final Enum<?> e : type.getEnumConstants()) {
if (e.name().equals(value))
return e;
}
throw new TransformException("Enum constant " + value
+ " not found for " + type);
}
}

View File

@@ -37,12 +37,12 @@ public class FileTransformer implements Transformer<File> {
private final File root = new File("./"); private final File root = new File("./");
@Override @Override
public String transform(File value) { public String transform(Class<? extends File> type, File value) {
return value.getAbsolutePath(); return value.getAbsolutePath();
} }
@Override @Override
public File untransform(String value) { public File untransform(Class<? extends File> type, String value) {
return new File(root, value); return new File(root, value);
} }

View File

@@ -30,12 +30,12 @@ public class FloatTransformer implements Transformer<Float> {
public static final FloatTransformer SHARED_INSTANCE = new FloatTransformer(); public static final FloatTransformer SHARED_INSTANCE = new FloatTransformer();
@Override @Override
public String transform(Float value) { public String transform(Class<? extends Float> type, Float value) {
return Double.toString(value); return Double.toString(value);
} }
@Override @Override
public Float untransform(String value) { public Float untransform(Class<? extends Float> type, String value) {
return Float.parseFloat(value); return Float.parseFloat(value);
} }

View File

@@ -34,15 +34,18 @@ public class InetSocketAddressTransformer implements
public static final InetSocketAddressTransformer SHARED_INSTANCE = new InetSocketAddressTransformer(); public static final InetSocketAddressTransformer SHARED_INSTANCE = new InetSocketAddressTransformer();
@Override @Override
public String transform(InetSocketAddress value) { public String transform(Class<? extends InetSocketAddress> type,
InetSocketAddress value) {
return value.getHostName() + ":" + value.getPort(); return value.getHostName() + ":" + value.getPort();
} }
@Override @Override
public InetSocketAddress untransform(String value) { public InetSocketAddress untransform(
Class<? extends InetSocketAddress> type, String value) {
final String[] pieces = value.split(":"); final String[] pieces = value.split(":");
if (pieces.length != 2) if (pieces.length != 2)
throw new TransformException("InetSocketAddress must have format ip:port"); throw new TransformException(
"InetSocketAddress must have format ip:port");
return new InetSocketAddress(pieces[0], Integer.parseInt(pieces[1])); return new InetSocketAddress(pieces[0], Integer.parseInt(pieces[1]));
} }

View File

@@ -30,12 +30,12 @@ public class IntegerTransformer implements Transformer<Integer> {
public static final IntegerTransformer SHARED_INSTANCE = new IntegerTransformer(); public static final IntegerTransformer SHARED_INSTANCE = new IntegerTransformer();
@Override @Override
public String transform(Integer value) { public String transform(Class<? extends Integer> type, Integer value) {
return Integer.toString(value); return Integer.toString(value);
} }
@Override @Override
public Integer untransform(String value) { public Integer untransform(Class<? extends Integer> type, String value) {
return Integer.decode(value); return Integer.decode(value);
} }

View File

@@ -30,12 +30,12 @@ public class LongTransformer implements Transformer<Long> {
public static final LongTransformer SHARED_INSTANCE = new LongTransformer(); public static final LongTransformer SHARED_INSTANCE = new LongTransformer();
@Override @Override
public String transform(Long value) { public String transform(Class<? extends Long> type, Long value) {
return Long.toString(value); return Long.toString(value);
} }
@Override @Override
public Long untransform(String value) { public Long untransform(Class<? extends Long> type, String value) {
return Long.decode(value); return Long.decode(value);
} }

View File

@@ -33,14 +33,14 @@ public class PathTransformer implements Transformer<Path> {
public static final PathTransformer SHARED_INSTANCE = new PathTransformer(); public static final PathTransformer SHARED_INSTANCE = new PathTransformer();
@Override @Override
public String transform(Path value) { public String transform(Class<? extends Path> type, Path value) {
if (value == null) if (value == null)
return ""; return "";
return value.toString(); return value.toString();
} }
@Override @Override
public Path untransform(String value) { public Path untransform(Class<? extends Path> type, String value) {
return Paths.get(value); return Paths.get(value);
} }
} }

View File

@@ -30,12 +30,12 @@ public class ShortTransformer implements Transformer<Short> {
public static final ShortTransformer SHARED_INSTANCE = new ShortTransformer(); public static final ShortTransformer SHARED_INSTANCE = new ShortTransformer();
@Override @Override
public String transform(Short value) { public String transform(Class<? extends Short> type, Short value) {
return Short.toString(value); return Short.toString(value);
} }
@Override @Override
public Short untransform(String value) { public Short untransform(Class<? extends Short> type, String value) {
return Short.decode(value); return Short.decode(value);
} }

View File

@@ -32,12 +32,12 @@ public class URITransformer implements Transformer<URI> {
public static final URITransformer SHARED_INSTANCE = new URITransformer(); public static final URITransformer SHARED_INSTANCE = new URITransformer();
@Override @Override
public String transform(URI value) { public String transform(Class<? extends URI> type, URI value) {
return value.toString(); return value.toString();
} }
@Override @Override
public URI untransform(String value) { public URI untransform(Class<? extends URI> type, String value) {
return URI.create(value); return URI.create(value);
} }
} }

View File

@@ -35,12 +35,12 @@ public class URLTransformer implements Transformer<URL> {
public static final URLTransformer SHARED_INSTANCE = new URLTransformer(); public static final URLTransformer SHARED_INSTANCE = new URLTransformer();
@Override @Override
public String transform(URL value) { public String transform(Class<? extends URL> type, URL value) {
return value.toString(); return value.toString();
} }
@Override @Override
public URL untransform(String value) { public URL untransform(Class<? extends URL> type, String value) {
try { try {
return new URL(value); return new URL(value);
} catch (MalformedURLException e) { } catch (MalformedURLException e) {

View File

@@ -75,6 +75,7 @@ public class BitSetIDAllocatorTest {
public void testRelease() { public void testRelease() {
final int id = allocator.allocate(); final int id = allocator.allocate();
allocator.release(id); allocator.release(id);
assertEquals(0, allocator.getAllocatedIDs());
} }
@Test(expected = IDAllocatorException.class) @Test(expected = IDAllocatorException.class)

View File

@@ -1 +1,2 @@
/log /log
/derby.log

View File

@@ -21,21 +21,15 @@
<database> <database>
<jdbc> <jdbc>
<!-- Defines the connection URL used by JDBC to connect to the database. --> <!-- Defines the connection URL used by JDBC to connect to the database. -->
<url>jdbc:mysql://localhost/l2jserver2</url> <url>jdbc:derby:data/database/derby;create=true</url>
<!-- The driver used to connect to the database. Please note that the <!-- The engine used to connect to the database. -->
driver library must be available in the JVM classpath. --> <engine>com.l2jserver.service.database.sql.DerbyDatabaseEngine</engine>
<driver>com.mysql.jdbc.Driver</driver>
<!-- The SQLTemplates provides several low-level SQL management. Templates <!-- Whether or not the service should try to update and create missing
are database dependent. --> tables at startup. This should be disabled after the first server start as
<templates>com.mysema.query.sql.MySQLTemplates</templates> it could cause data corruption. -->
<updateSchema>true</updateSchema>
<!-- The query factory provides an class that allows to convert Java
code to SQL code and parses database results into more easily managed Java
code. -->
<queryFactory>com.mysema.query.sql.mysql.MySQLQueryFactory
</queryFactory>
<!-- The username used to login into the database. NOTE: Try not use <!-- The username used to login into the database. NOTE: Try not use
"root" in production servers for security reasons. --> "root" in production servers for security reasons. -->

File diff suppressed because it is too large Load Diff

View File

@@ -23,19 +23,14 @@
<!-- Defines the connection URL used by JDBC to connect to the database. --> <!-- Defines the connection URL used by JDBC to connect to the database. -->
<url>jdbc:mysql://localhost/l2jserver2</url> <url>jdbc:mysql://localhost/l2jserver2</url>
<!-- The driver used to connect to the database. Please note that the <!-- The engine used to connect to the database. -->
driver library must be available in the JVM classpath. --> <engine>com.l2jserver.service.database.sql.MySQLDatabaseEngine
<driver>com.mysql.jdbc.Driver</driver> </engine>
<!-- The SQLTemplates provides several low-level SQL management. Templates
are database dependent. -->
<templates>com.mysema.query.sql.MySQLTemplates</templates>
<!-- The query factory provides an class that allows to convert Java <!-- Whether or not the service should try to update and create missing
code to SQL code and parses database results into more easily managed Java tables at startup. This should be disabled after the first server start as
code. --> it could cause data corruption. -->
<queryFactory>com.mysema.query.sql.mysql.MySQLQueryFactory <updateSchema>true</updateSchema>
</queryFactory>
<!-- The username used to login into the database. NOTE: Try not use <!-- The username used to login into the database. NOTE: Try not use
"root" in production servers for security reasons. --> "root" in production servers for security reasons. -->

View File

@@ -1,8 +0,0 @@
CREATE TABLE `actor_skill` (
`actor_id` int(10) NOT NULL,
`skill_id` int(10) NOT NULL,
`level` int(2) NOT NULL DEFAULT '1',
PRIMARY KEY (`actor_id`,`skill_id`),
KEY `actor_id` (`actor_id`),
KEY `skill_id` (`skill_id`)
);

View File

@@ -1,26 +0,0 @@
CREATE TABLE `character` (
`character_id` int(12) NOT NULL,
`account_id` varchar(50) NOT NULL,
`clan_id` int(10) DEFAULT NULL,
`name` varchar(50) NOT NULL,
`race` enum('HUMAN','ELF','DARK_ELF','ORC','DWARF','KAMAEL') NOT NULL,
`class` enum('HUMAN_FIGHTER','WARRIOR','GLADIATOR','WARLORD','KNIGHT','PALADIN','DARK_AVENGER','ROGUE','TREASURE_HUNTER','HAWKEYE','DUELIST','DREADNOUGHT','PHOENIX_KNIGHT','HELL_KNIGHT','SAGITTARIUS','ADVENTURER','HUMAN_MYSTIC','WIZARD','SORCEROR','NECROMANCER','WARLOCK','CLERIC','BISHOP','PROPHET','ARCHMAGE','SOULTAKER','ARCANA_LORD','CARDINAL','HIEROPHANT','ELVEN_FIGHTER','ELVEN_KNIGHT','TEMPLE_KNIGHT','SWORD_SINGER','ELVEN_SCOUT','PLAINS_WALKER','SILVER_RANGER','EVA_TEMPLAR','SWORD_MUSE','WIND_RIDER','MOONLIGHT_SENTINEL','ELVEN_MYSTIC','ELVEN_WIZARD','SPELLSINGER','ELEMENTAL_SUMMONER','ORACLE','ELDER','MYSTIC_MUSE','ELEMENTAL_MASTER','EVA_SAINT','DARK_FIGHTER','PALUS_KNIGHT','SHILLIEN_KNIGHT','BLADEDANCER','ASSASSIN','ABYSS_WALKER','PHANTOM_RANGER','SHILLIEN_TEMPLAR','SPECTRAL_DANCER','GHOST_HUNTER','GHOST_SENTINEL','DARK_MYSTIC','DARK_WIZARD','SPELLHOWLER','PHANTOM_SUMMONER','SHILLIEN_ORACLE','SHILLIEN_ELDER','STORM_SCREAMER','SPECTRAL_MASTER','SHILLIEAN_SAINT','ORC_FIGHTER','ORC_RAIDER','DESTROYER','ORC_MONK','TYRANT','TITAN','GRAND_KHAUATARI','ORC_MYSTIC','ORC_SHAMAN','OVERLORD','WARCRYER','DOMINATOR','DOOMCRYER','DWARVEN_FIGHTER','SCAVENGER','BOUNTY_HUNTER','ARTISAN','WARSMITH','FORTUNE_SEEKER','MAESTRO','MALE_SOLDIER','TROOPER','BERSEKER','MALE_SOULBREAKER','DOOMBRINGER','MALE_SOULDHOUND','FEMALE_SOLDIER','WARDER','FEMALE_SOULBREAKER','ARBALESTER','FEMALE_SOULDHOUND','TRICKSTER','INSPECTOR','JUDICATOR') NOT NULL DEFAULT 'HUMAN_FIGHTER',
`sex` enum('MALE','FEMALE') NOT NULL,
`level` int(3) NOT NULL,
`experience` int(15) NOT NULL,
`sp` int(15) NOT NULL,
`hp` double NOT NULL,
`mp` double NOT NULL,
`cp` double NOT NULL,
`point_x` int(10) NOT NULL,
`point_y` int(10) NOT NULL,
`point_z` int(10) NOT NULL,
`point_angle` double NOT NULL,
`appearance_hair_style` enum('STYLE_A','STYLE_B','STYLE_C','STYLE_D','STYLE_E') NOT NULL DEFAULT 'STYLE_A',
`appearance_hair_color` enum('COLOR_A','COLOR_B','COLOR_C','COLOR_D') NOT NULL DEFAULT 'COLOR_A',
`apperance_face` enum('FACE_A','FACE_B','FACE_C') NOT NULL DEFAULT 'FACE_A',
PRIMARY KEY (`character_id`),
KEY `account_id` (`account_id`),
KEY `name` (`name`),
KEY `clan_id` (`clan_id`)
);

View File

@@ -1,5 +0,0 @@
CREATE TABLE `character_friend` (
`character_id` int(10) NOT NULL,
`character_id_friend` int(10) NOT NULL,
PRIMARY KEY (`character_id`,`character_id_friend`)
);

View File

@@ -1,15 +0,0 @@
CREATE TABLE `character_shortcut` (
`shortcut_id` int(10) NOT NULL AUTO_INCREMENT,
`character_id` int(10) NOT NULL,
`slot` int(2) NOT NULL,
`page` int(1) NOT NULL,
`type` enum('ITEM','SKILL','ACTION','MACRO','RECIPE','TPBOOKMARK') NOT NULL,
`object_id` int(10) NOT NULL,
`level` int(2) DEFAULT NULL,
`character_type` int(10) DEFAULT NULL,
PRIMARY KEY (`shortcut_id`),
UNIQUE KEY `character_id-slot-page` (`character_id`,`slot`,`page`),
KEY `character_id` (`character_id`),
KEY `character_id-page` (`character_id`,`page`),
KEY `character_id-type` (`character_id`,`type`)
);

View File

@@ -1,6 +0,0 @@
CREATE TABLE `clan` (
`clan_id` int(10) NOT NULL,
`character_id_leader` int(10) NOT NULL,
PRIMARY KEY (`clan_id`),
KEY `character_id_leader` (`character_id_leader`)
);

View File

@@ -1,14 +0,0 @@
CREATE TABLE `item` (
`item_id` int(12) NOT NULL,
`template_id` int(10) NOT NULL,
`character_id` int(12) DEFAULT NULL,
`location` enum('GROUND','PAPERDOLL','INVENTORY','WAREHOUSE') DEFAULT NULL,
`paperdoll` enum('UNDERWEAR','HEAD','HAIR1','HAIR2','NECK','RIGHT_HAND','CHEST','LEFT_HAND','RIGHT_EAR','LEFT_EAR','GLOVES','LEGS','FEET','RIGHT_FINGER','LEFT_FINGER','LEFT_BRACELET','RIGHT_BRACELET','DECORATION_1','DECORATION_2','DECORATION_3','DECORATION_4','DECORATION_5','DECORATION_6','CLOAK,BELT') DEFAULT NULL,
`count` int(10) NOT NULL,
`coord_x` int(10) DEFAULT NULL,
`coord_y` int(10) DEFAULT NULL,
`coord_z` int(10) DEFAULT NULL,
PRIMARY KEY (`item_id`),
KEY `character_id` (`character_id`),
KEY `template_id` (`template_id`)
);

View File

@@ -1,9 +0,0 @@
CREATE TABLE `log_chat` (
`message_id` int(12) NOT NULL AUTO_INCREMENT,
`type` enum('ALL','SHOUT','TELL','PARTY','CLAN','GM','PETITION_PLAYER','PETITION_GM','TRADE','ALLIANCE','ANNOUNCEMENT','BOAT','L2FRIEND','MSNCHAT','PARTYMATCH_ROOM','PARTYROOM_COMMANDER','PARTYROOM_ALL','HERO_VOICE','CRITICAL_ANNOUNCE','SCREEN_ANNOUNCE','BATTLEFIELD','MPCC_ROOM') NOT NULL,
`channel_id` int(12) NOT NULL,
`sender` int(12) NOT NULL,
`date` TIMESTAMP NOT NULL,
`message` text NOT NULL,
PRIMARY KEY (`message_id`)
);

File diff suppressed because it is too large Load Diff

View File

@@ -1,10 +0,0 @@
INSERT INTO `character` (`character_id`, `account_id`, `clan_id`, `name`, `race`, `class`, `sex`, `level`, `experience`, `sp`, `point_x`, `point_y`, `point_z`, `point_angle`, `appearance_hair_style`, `appearance_hair_color`, `apperance_face`) VALUES
(268437456, 'rogiel', NULL, 'Rogiel', 'HUMAN', 'HUMAN_FIGHTER', 'MALE', 1, 0, 0, -71338, 258271, -3104, 0, 'STYLE_B', 'COLOR_B', 'FACE_B'),
(268437457, 'rogiel2', NULL, 'Rogiel2', 'HUMAN', 'HUMAN_FIGHTER', 'MALE', 0, 0, 0, 0, 0, 0, 0, 'STYLE_A', 'COLOR_A', 'FACE_A');
INSERT INTO `item` (`item_id`, `template_id`, `character_id`, `location`, `paperdoll`, `count`, `coord_x`, `coord_y`, `coord_z`) VALUES
(268635457, 57, 268437456, 'INVENTORY', NULL, 200000000, NULL, NULL, NULL),
(268635459, 57, NULL, 'GROUND', NULL, 100, 147459, 24434, -1992),
(268635460, 1, 268437456, 'INVENTORY', NULL, 1, NULL, NULL, NULL);

View File

@@ -62,27 +62,6 @@
<type>jar</type> <type>jar</type>
<scope>runtime</scope> <scope>runtime</scope>
</dependency> </dependency>
<!-- database -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.18</version>
<type>jar</type>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.3.162</version>
<type>jar</type>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
<version>10.8.2.2</version>
<scope>runtime</scope>
</dependency>
<!-- cache --> <!-- cache -->
<dependency> <dependency>
<groupId>net.sf.ehcache</groupId> <groupId>net.sf.ehcache</groupId>

View File

@@ -26,10 +26,6 @@
<directory>${project.basedir}/distribution/global</directory> <directory>${project.basedir}/distribution/global</directory>
<outputDirectory>/</outputDirectory> <outputDirectory>/</outputDirectory>
</fileSet> </fileSet>
<fileSet>
<directory>${project.basedir}/distribution/sql</directory>
<outputDirectory>/</outputDirectory>
</fileSet>
</fileSets> </fileSets>
<files> <files>
<file> <file>

View File

@@ -26,10 +26,6 @@
<directory>${project.basedir}/distribution/global</directory> <directory>${project.basedir}/distribution/global</directory>
<outputDirectory>/</outputDirectory> <outputDirectory>/</outputDirectory>
</fileSet> </fileSet>
<fileSet>
<directory>${project.basedir}/distribution/sql</directory>
<outputDirectory>/</outputDirectory>
</fileSet>
</fileSets> </fileSets>
<files> <files>
<file> <file>

View File

@@ -25,10 +25,6 @@
<directory>${project.basedir}/distribution/global</directory> <directory>${project.basedir}/distribution/global</directory>
<outputDirectory>/</outputDirectory> <outputDirectory>/</outputDirectory>
</fileSet> </fileSet>
<fileSet>
<directory>${project.basedir}/distribution/sql</directory>
<outputDirectory>/</outputDirectory>
</fileSet>
</fileSets> </fileSets>
<files> <files>
<file> <file>

View File

@@ -16,6 +16,10 @@
*/ */
package com.l2jserver.service.database; package com.l2jserver.service.database;
import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.l2jserver.model.game.CharacterShortcut.ShortcutType; import com.l2jserver.model.game.CharacterShortcut.ShortcutType;
import com.l2jserver.model.template.actor.ActorSex; import com.l2jserver.model.template.actor.ActorSex;
@@ -31,7 +35,16 @@ import com.l2jserver.service.cache.CacheService;
import com.l2jserver.service.configuration.ConfigurationService; import com.l2jserver.service.configuration.ConfigurationService;
import com.l2jserver.service.core.LoggingService; import com.l2jserver.service.core.LoggingService;
import com.l2jserver.service.core.threading.ThreadService; import com.l2jserver.service.core.threading.ThreadService;
import com.l2jserver.service.database.jdbc.AbstractJDBCDatabaseService; import com.l2jserver.service.core.vfs.VFSService;
import com.l2jserver.service.database.model.QActorSkill;
import com.l2jserver.service.database.model.QCharacter;
import com.l2jserver.service.database.model.QCharacterFriend;
import com.l2jserver.service.database.model.QCharacterShortcut;
import com.l2jserver.service.database.model.QClan;
import com.l2jserver.service.database.model.QItem;
import com.l2jserver.service.database.model.QLogChat;
import com.l2jserver.service.database.model.QNPC;
import com.l2jserver.service.database.sql.AbstractSQLDatabaseService;
import com.l2jserver.service.game.chat.ChatMessageType; import com.l2jserver.service.game.chat.ChatMessageType;
import com.l2jserver.service.game.template.TemplateService; import com.l2jserver.service.game.template.TemplateService;
import com.mysema.query.sql.types.EnumByNameType; import com.mysema.query.sql.types.EnumByNameType;
@@ -41,28 +54,28 @@ import com.mysema.query.sql.types.EnumByNameType;
* to JDBC. * to JDBC.
* *
* <h1>Internal specification</h1> <h2>The * <h1>Internal specification</h1> <h2>The
* {@link com.l2jserver.service.database.jdbc.AbstractJDBCDatabaseService.Query * {@link com.l2jserver.service.database.sql.AbstractSQLDatabaseService.Query
* Query} object</h2> * Query} object</h2>
* *
* If you wish to implement a new {@link DataAccessObject} you should try not * If you wish to implement a new {@link DataAccessObject} you should try not
* use * use
* {@link com.l2jserver.service.database.jdbc.AbstractJDBCDatabaseService.Query * {@link com.l2jserver.service.database.sql.AbstractSQLDatabaseService.Query
* Query} object directly because it only provides low level access to the JDBC * Query} object directly because it only provides low level access to the JDBC
* architecture. Instead, you could use an specialized class, like * architecture. Instead, you could use an specialized class, like
* {@link com.l2jserver.service.database.jdbc.AbstractJDBCDatabaseService.InsertQuery * {@link com.l2jserver.service.database.sql.AbstractSQLDatabaseService.InsertQuery
* InsertUpdateQuery} , * InsertUpdateQuery} ,
* {@link com.l2jserver.service.database.jdbc.AbstractJDBCDatabaseService.SelectListQuery * {@link com.l2jserver.service.database.sql.AbstractSQLDatabaseService.SelectListQuery
* SelectListQuery} or * SelectListQuery} or
* {@link com.l2jserver.service.database.jdbc.AbstractJDBCDatabaseService.SelectSingleQuery * {@link com.l2jserver.service.database.sql.AbstractSQLDatabaseService.SelectSingleQuery
* SelectSingleQuery} . If you do need low level access, feel free to use the * SelectSingleQuery} . If you do need low level access, feel free to use the
* {@link com.l2jserver.service.database.jdbc.AbstractJDBCDatabaseService.Query * {@link com.l2jserver.service.database.sql.AbstractSQLDatabaseService.Query
* Query} class directly. * Query} class directly.
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
@Depends({ LoggingService.class, CacheService.class, @Depends({ LoggingService.class, CacheService.class,
ConfigurationService.class, TemplateService.class, ThreadService.class }) ConfigurationService.class, TemplateService.class, ThreadService.class })
public class GameServerJDBCDatabaseService extends AbstractJDBCDatabaseService public class GameServerJDBCDatabaseService extends AbstractSQLDatabaseService
implements DatabaseService { implements DatabaseService {
/** /**
* @param configService * @param configService
@@ -71,17 +84,20 @@ public class GameServerJDBCDatabaseService extends AbstractJDBCDatabaseService
* the cache service * the cache service
* @param threadService * @param threadService
* the thread service * the thread service
* @param vfsService
* the vfs service
* @param daoResolver * @param daoResolver
* the {@link DataAccessObject DAO} resolver * the {@link DataAccessObject DAO} resolver
*/ */
@Inject @Inject
public GameServerJDBCDatabaseService(ConfigurationService configService, public GameServerJDBCDatabaseService(ConfigurationService configService,
CacheService cacheService, ThreadService threadService, CacheService cacheService, ThreadService threadService,
DAOResolver daoResolver) { VFSService vfsService, DAOResolver daoResolver) {
super( super(
configService, configService,
cacheService, cacheService,
threadService, threadService,
vfsService,
daoResolver, daoResolver,
new EnumByNameType<CharacterRace>(CharacterRace.class), new EnumByNameType<CharacterRace>(CharacterRace.class),
new EnumByNameType<CharacterClass>(CharacterClass.class), new EnumByNameType<CharacterClass>(CharacterClass.class),
@@ -94,4 +110,18 @@ public class GameServerJDBCDatabaseService extends AbstractJDBCDatabaseService
new EnumByNameType<InventoryPaperdoll>(InventoryPaperdoll.class), new EnumByNameType<InventoryPaperdoll>(InventoryPaperdoll.class),
new EnumByNameType<ChatMessageType>(ChatMessageType.class)); new EnumByNameType<ChatMessageType>(ChatMessageType.class));
} }
@Override
protected void ensureDatabaseSchema(Connection conn) throws SQLException, IOException {
updateSchema(conn, QActorSkill.actorSkill);
updateSchema(conn, QCharacter.character);
updateSchema(conn, QCharacterFriend.characterFriend);
updateSchema(conn, QCharacterShortcut.characterShortcut);
updateSchema(conn, QClan.clan);
updateSchema(conn, QItem.item);
updateSchema(conn, QLogChat.logChat);
if (updateSchema(conn, QNPC.npc)) {
importSQL(conn, vfsService.resolve("data/sql/npc.sql"));
}
}
} }

View File

@@ -26,13 +26,13 @@ import com.l2jserver.model.dao.ChatMessageDAO;
import com.l2jserver.model.dao.ClanDAO; import com.l2jserver.model.dao.ClanDAO;
import com.l2jserver.model.dao.ItemDAO; import com.l2jserver.model.dao.ItemDAO;
import com.l2jserver.model.dao.NPCDAO; import com.l2jserver.model.dao.NPCDAO;
import com.l2jserver.service.database.jdbc.JDBCCharacterDAO; import com.l2jserver.service.database.sql.SQLCharacterDAO;
import com.l2jserver.service.database.jdbc.JDBCCharacterFriendDAO; import com.l2jserver.service.database.sql.SQLCharacterFriendDAO;
import com.l2jserver.service.database.jdbc.JDBCCharacterShortcutDAO; import com.l2jserver.service.database.sql.SQLCharacterShortcutDAO;
import com.l2jserver.service.database.jdbc.JDBCChatMessageDAO; import com.l2jserver.service.database.sql.SQLChatMessageDAO;
import com.l2jserver.service.database.jdbc.JDBCClanDAO; import com.l2jserver.service.database.sql.SQLClanDAO;
import com.l2jserver.service.database.jdbc.JDBCItemDAO; import com.l2jserver.service.database.sql.SQLItemDAO;
import com.l2jserver.service.database.jdbc.JDBCNPCDAO; import com.l2jserver.service.database.sql.SQLNPCDAO;
/** /**
* Google Guice {@link Module} for JDBC DAOs * Google Guice {@link Module} for JDBC DAOs
@@ -42,20 +42,20 @@ import com.l2jserver.service.database.jdbc.JDBCNPCDAO;
public class JDBCDAOModule extends AbstractModule { public class JDBCDAOModule extends AbstractModule {
@Override @Override
protected void configure() { protected void configure() {
bind(CharacterDAO.class).to(JDBCCharacterDAO.class) bind(CharacterDAO.class).to(SQLCharacterDAO.class)
.in(Scopes.SINGLETON); .in(Scopes.SINGLETON);
bind(CharacterFriendDAO.class).to(JDBCCharacterFriendDAO.class).in( bind(CharacterFriendDAO.class).to(SQLCharacterFriendDAO.class).in(
Scopes.SINGLETON); Scopes.SINGLETON);
bind(CharacterShortcutDAO.class).to(JDBCCharacterShortcutDAO.class).in( bind(CharacterShortcutDAO.class).to(SQLCharacterShortcutDAO.class).in(
Scopes.SINGLETON); Scopes.SINGLETON);
bind(NPCDAO.class).to(JDBCNPCDAO.class).in(Scopes.SINGLETON); bind(NPCDAO.class).to(SQLNPCDAO.class).in(Scopes.SINGLETON);
bind(ItemDAO.class).to(JDBCItemDAO.class).in(Scopes.SINGLETON); bind(ItemDAO.class).to(SQLItemDAO.class).in(Scopes.SINGLETON);
bind(ClanDAO.class).to(JDBCClanDAO.class).in(Scopes.SINGLETON); bind(ClanDAO.class).to(SQLClanDAO.class).in(Scopes.SINGLETON);
// logs // logs
bind(ChatMessageDAO.class).to(JDBCChatMessageDAO.class).in( bind(ChatMessageDAO.class).to(SQLChatMessageDAO.class).in(
Scopes.SINGLETON); Scopes.SINGLETON);
// DAO Resolver // DAO Resolver

View File

@@ -3,6 +3,7 @@ package com.l2jserver.service.database.model;
import static com.mysema.query.types.PathMetadataFactory.forVariable; import static com.mysema.query.types.PathMetadataFactory.forVariable;
import com.l2jserver.model.game.Skill; import com.l2jserver.model.game.Skill;
import com.l2jserver.service.database.sql.ddl.annotation.ColumnSize;
import com.mysema.query.sql.PrimaryKey; import com.mysema.query.sql.PrimaryKey;
import com.mysema.query.sql.RelationalPathBase; import com.mysema.query.sql.RelationalPathBase;
import com.mysema.query.types.Path; import com.mysema.query.types.Path;
@@ -19,12 +20,15 @@ public class QActorSkill extends RelationalPathBase<Skill> {
public static final QActorSkill actorSkill = new QActorSkill("actor_skill"); public static final QActorSkill actorSkill = new QActorSkill("actor_skill");
@ColumnSize(10)
public final NumberPath<Integer> actorId = createNumber("actor_id", public final NumberPath<Integer> actorId = createNumber("actor_id",
Integer.class); Integer.class);
@ColumnSize(4)
public final NumberPath<Integer> level = createNumber("level", public final NumberPath<Integer> level = createNumber("level",
Integer.class); Integer.class);
@ColumnSize(6)
public final NumberPath<Integer> skillId = createNumber("skill_id", public final NumberPath<Integer> skillId = createNumber("skill_id",
Integer.class); Integer.class);

View File

@@ -5,10 +5,14 @@ import static com.mysema.query.types.PathMetadataFactory.forVariable;
import com.l2jserver.model.template.actor.ActorSex; import com.l2jserver.model.template.actor.ActorSex;
import com.l2jserver.model.template.character.CharacterClass; import com.l2jserver.model.template.character.CharacterClass;
import com.l2jserver.model.template.character.CharacterRace; import com.l2jserver.model.template.character.CharacterRace;
import com.l2jserver.model.world.Clan;
import com.l2jserver.model.world.L2Character; import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.character.CharacterAppearance.CharacterFace; import com.l2jserver.model.world.character.CharacterAppearance.CharacterFace;
import com.l2jserver.model.world.character.CharacterAppearance.CharacterHairColor; import com.l2jserver.model.world.character.CharacterAppearance.CharacterHairColor;
import com.l2jserver.model.world.character.CharacterAppearance.CharacterHairStyle; import com.l2jserver.model.world.character.CharacterAppearance.CharacterHairStyle;
import com.l2jserver.service.database.sql.ddl.annotation.ColumnNullable;
import com.l2jserver.service.database.sql.ddl.annotation.ColumnSize;
import com.mysema.query.sql.ForeignKey;
import com.mysema.query.sql.PrimaryKey; import com.mysema.query.sql.PrimaryKey;
import com.mysema.query.sql.RelationalPathBase; import com.mysema.query.sql.RelationalPathBase;
import com.mysema.query.types.Path; import com.mysema.query.types.Path;
@@ -27,40 +31,49 @@ public class QCharacter extends RelationalPathBase<L2Character> {
public static final QCharacter character = new QCharacter("l2character"); public static final QCharacter character = new QCharacter("l2character");
@ColumnSize(10)
public final NumberPath<Integer> characterId = createNumber("character_id", public final NumberPath<Integer> characterId = createNumber("character_id",
Integer.class); Integer.class);
@ColumnSize(50)
public final StringPath accountId = createString("account_id"); public final StringPath accountId = createString("account_id");
@ColumnSize(10)
@ColumnNullable
public final NumberPath<Integer> clanId = createNumber("clan_id", public final NumberPath<Integer> clanId = createNumber("clan_id",
Integer.class); Integer.class);
@ColumnSize(100)
public final StringPath name = createString("name"); public final StringPath name = createString("name");
public final EnumPath<CharacterRace> race = createEnum("race", public final EnumPath<CharacterRace> race = createEnum("race",
CharacterRace.class); CharacterRace.class);
public final EnumPath<ActorSex> sex = createEnum("sex", ActorSex.class); public final EnumPath<ActorSex> sex = createEnum("sex", ActorSex.class);
public final EnumPath<CharacterClass> characterClass = createEnum("class", public final EnumPath<CharacterClass> characterClass = createEnum("class",
CharacterClass.class); CharacterClass.class);
@ColumnSize(4)
public final NumberPath<Integer> level = createNumber("level", public final NumberPath<Integer> level = createNumber("level",
Integer.class); Integer.class);
@ColumnSize(10)
public final NumberPath<Long> experience = createNumber("experience", public final NumberPath<Long> experience = createNumber("experience",
Long.class); Long.class);
@ColumnSize(10)
public final NumberPath<Integer> sp = createNumber("sp", Integer.class); public final NumberPath<Integer> sp = createNumber("sp", Integer.class);
public final NumberPath<Double> cp = createNumber("cp", Double.class); public final NumberPath<Double> cp = createNumber("cp", Double.class);
public final NumberPath<Double> hp = createNumber("hp", Double.class); public final NumberPath<Double> hp = createNumber("hp", Double.class);
public final NumberPath<Double> mp = createNumber("mp", Double.class); public final NumberPath<Double> mp = createNumber("mp", Double.class);
public final NumberPath<Double> pointAngle = createNumber("point_angle", @ColumnSize(10)
Double.class);
public final NumberPath<Integer> pointX = createNumber("point_x", public final NumberPath<Integer> pointX = createNumber("point_x",
Integer.class); Integer.class);
@ColumnSize(10)
public final NumberPath<Integer> pointY = createNumber("point_y", public final NumberPath<Integer> pointY = createNumber("point_y",
Integer.class); Integer.class);
@ColumnSize(10)
public final NumberPath<Integer> pointZ = createNumber("point_z", public final NumberPath<Integer> pointZ = createNumber("point_z",
Integer.class); Integer.class);
public final NumberPath<Double> pointAngle = createNumber("point_angle",
Double.class);
public final EnumPath<CharacterHairColor> appearanceHairColor = createEnum( public final EnumPath<CharacterHairColor> appearanceHairColor = createEnum(
"appearance_hair_color", CharacterHairColor.class); "appearance_hair_color", CharacterHairColor.class);
@@ -70,6 +83,7 @@ public class QCharacter extends RelationalPathBase<L2Character> {
"apperance_face", CharacterFace.class); "apperance_face", CharacterFace.class);
public final PrimaryKey<L2Character> primary = createPrimaryKey(characterId); public final PrimaryKey<L2Character> primary = createPrimaryKey(characterId);
public final ForeignKey<Clan> clanIdKey = createForeignKey(clanId, "");
public QCharacter(String variable) { public QCharacter(String variable) {
super(L2Character.class, forVariable(variable), "null", "character"); super(L2Character.class, forVariable(variable), "null", "character");

View File

@@ -3,6 +3,7 @@ package com.l2jserver.service.database.model;
import static com.mysema.query.types.PathMetadataFactory.forVariable; import static com.mysema.query.types.PathMetadataFactory.forVariable;
import com.l2jserver.model.game.CharacterFriend; import com.l2jserver.model.game.CharacterFriend;
import com.l2jserver.service.database.sql.ddl.annotation.ColumnSize;
import com.mysema.query.sql.PrimaryKey; import com.mysema.query.sql.PrimaryKey;
import com.mysema.query.types.Path; import com.mysema.query.types.Path;
import com.mysema.query.types.PathMetadata; import com.mysema.query.types.PathMetadata;
@@ -20,8 +21,10 @@ public class QCharacterFriend extends
public static final QCharacterFriend characterFriend = new QCharacterFriend( public static final QCharacterFriend characterFriend = new QCharacterFriend(
"character_friend"); "character_friend");
@ColumnSize(10)
public final NumberPath<Integer> characterId = createNumber("character_id", public final NumberPath<Integer> characterId = createNumber("character_id",
Integer.class); Integer.class);
@ColumnSize(10)
public final NumberPath<Integer> characterIdFriend = createNumber( public final NumberPath<Integer> characterIdFriend = createNumber(
"character_id_friend", Integer.class); "character_id_friend", Integer.class);

View File

@@ -4,52 +4,68 @@ import static com.mysema.query.types.PathMetadataFactory.forVariable;
import com.l2jserver.model.game.CharacterShortcut; import com.l2jserver.model.game.CharacterShortcut;
import com.l2jserver.model.game.CharacterShortcut.ShortcutType; import com.l2jserver.model.game.CharacterShortcut.ShortcutType;
import com.l2jserver.service.database.sql.ddl.annotation.ColumnAutoIncrement;
import com.l2jserver.service.database.sql.ddl.annotation.ColumnNullable;
import com.l2jserver.service.database.sql.ddl.annotation.ColumnSize;
import com.mysema.query.sql.PrimaryKey; import com.mysema.query.sql.PrimaryKey;
import com.mysema.query.types.Path; import com.mysema.query.types.Path;
import com.mysema.query.types.PathMetadata; import com.mysema.query.types.PathMetadata;
import com.mysema.query.types.path.EnumPath; import com.mysema.query.types.path.EnumPath;
import com.mysema.query.types.path.NumberPath; import com.mysema.query.types.path.NumberPath;
/** /**
* Maps <code>character_shortcut</code> table into type-safe java objects * Maps <code>character_shortcut</code> table into type-safe java objects
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class QCharacterShortcut extends com.mysema.query.sql.RelationalPathBase<CharacterShortcut> { public class QCharacterShortcut extends
private static final long serialVersionUID = 1450964558; com.mysema.query.sql.RelationalPathBase<CharacterShortcut> {
private static final long serialVersionUID = 1450964558;
public static final QCharacterShortcut characterShortcut = new QCharacterShortcut("character_shortcut"); public static final QCharacterShortcut characterShortcut = new QCharacterShortcut(
"character_shortcut");
public final NumberPath<Integer> characterId = createNumber("character_id", Integer.class); @ColumnSize(10)
@ColumnAutoIncrement
public final NumberPath<Integer> shortcutId = createNumber("shortcut_id",
Integer.class);
public final NumberPath<Integer> characterType = createNumber("character_type", Integer.class); @ColumnSize(10)
public final NumberPath<Integer> characterId = createNumber("character_id",
Integer.class);
@ColumnSize(10)
@ColumnNullable
public final NumberPath<Integer> characterType = createNumber(
"character_type", Integer.class);
@ColumnSize(3)
@ColumnNullable
public final NumberPath<Integer> level = createNumber("level",
Integer.class);
@ColumnSize(10)
public final NumberPath<Integer> objectId = createNumber("object_id",
Integer.class);
@ColumnSize(2)
public final NumberPath<Integer> page = createNumber("page", Integer.class);
@ColumnSize(2)
public final NumberPath<Integer> slot = createNumber("slot", Integer.class);
public final NumberPath<Integer> level = createNumber("level", Integer.class); public final EnumPath<ShortcutType> type = createEnum("type",
ShortcutType.class);
public final NumberPath<Integer> objectId = createNumber("object_id", Integer.class); public final PrimaryKey<CharacterShortcut> primary = createPrimaryKey(shortcutId);
public final NumberPath<Integer> page = createNumber("page", Integer.class); public QCharacterShortcut(String variable) {
super(CharacterShortcut.class, forVariable(variable), "null",
"character_shortcut");
}
public final NumberPath<Integer> shortcutId = createNumber("shortcut_id", Integer.class); public QCharacterShortcut(Path<? extends CharacterShortcut> entity) {
super(entity.getType(), entity.getMetadata(), "null",
"character_shortcut");
}
public final NumberPath<Integer> slot = createNumber("slot", Integer.class); public QCharacterShortcut(PathMetadata<?> metadata) {
super(CharacterShortcut.class, metadata, "null", "character_shortcut");
public final EnumPath<ShortcutType> type = createEnum("type", ShortcutType.class); }
public final PrimaryKey<CharacterShortcut> primary = createPrimaryKey(shortcutId);
public QCharacterShortcut(String variable) {
super(CharacterShortcut.class, forVariable(variable), "null", "character_shortcut");
}
public QCharacterShortcut(Path<? extends CharacterShortcut> entity) {
super(entity.getType(), entity.getMetadata(), "null", "character_shortcut");
}
public QCharacterShortcut(PathMetadata<?> metadata) {
super(CharacterShortcut.class, metadata, "null", "character_shortcut");
}
} }

View File

@@ -3,39 +3,41 @@ package com.l2jserver.service.database.model;
import static com.mysema.query.types.PathMetadataFactory.forVariable; import static com.mysema.query.types.PathMetadataFactory.forVariable;
import com.l2jserver.model.world.Clan; import com.l2jserver.model.world.Clan;
import com.l2jserver.service.database.sql.ddl.annotation.ColumnSize;
import com.mysema.query.sql.PrimaryKey; import com.mysema.query.sql.PrimaryKey;
import com.mysema.query.types.Path; import com.mysema.query.types.Path;
import com.mysema.query.types.PathMetadata; import com.mysema.query.types.PathMetadata;
import com.mysema.query.types.path.NumberPath; import com.mysema.query.types.path.NumberPath;
/** /**
* Maps <code>clan</code> table into type-safe java objects * Maps <code>clan</code> table into type-safe java objects
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class QClan extends com.mysema.query.sql.RelationalPathBase<Clan> { public class QClan extends com.mysema.query.sql.RelationalPathBase<Clan> {
private static final long serialVersionUID = 1592083511; private static final long serialVersionUID = 1592083511;
public static final QClan clan = new QClan("clan"); public static final QClan clan = new QClan("clan");
public final NumberPath<Integer> characterIdLeader = createNumber("character_id_leader", Integer.class); @ColumnSize(10)
public final NumberPath<Integer> clanId = createNumber("clan_id",
Integer.class);
@ColumnSize(10)
public final NumberPath<Integer> characterIdLeader = createNumber(
"character_id_leader", Integer.class);
public final NumberPath<Integer> clanId = createNumber("clan_id", Integer.class); public final PrimaryKey<Clan> primary = createPrimaryKey(clanId);
public final PrimaryKey<Clan> primary = createPrimaryKey(clanId); public QClan(String variable) {
super(Clan.class, forVariable(variable), "null", "clan");
}
public QClan(String variable) { public QClan(Path<? extends Clan> entity) {
super(Clan.class, forVariable(variable), "null", "clan"); super(entity.getType(), entity.getMetadata(), "null", "clan");
} }
public QClan(Path<? extends Clan> entity) { public QClan(PathMetadata<?> metadata) {
super(entity.getType(), entity.getMetadata(), "null", "clan"); super(Clan.class, metadata, "null", "clan");
} }
public QClan(PathMetadata<?> metadata) {
super(Clan.class, metadata, "null", "clan");
}
} }

View File

@@ -5,6 +5,9 @@ import static com.mysema.query.types.PathMetadataFactory.forVariable;
import com.l2jserver.model.world.Item; import com.l2jserver.model.world.Item;
import com.l2jserver.model.world.character.CharacterInventory.InventoryPaperdoll; import com.l2jserver.model.world.character.CharacterInventory.InventoryPaperdoll;
import com.l2jserver.model.world.character.CharacterInventory.ItemLocation; import com.l2jserver.model.world.character.CharacterInventory.ItemLocation;
import com.l2jserver.service.database.sql.ddl.annotation.ColumnDefault;
import com.l2jserver.service.database.sql.ddl.annotation.ColumnNullable;
import com.l2jserver.service.database.sql.ddl.annotation.ColumnSize;
import com.mysema.query.sql.PrimaryKey; import com.mysema.query.sql.PrimaryKey;
import com.mysema.query.types.Path; import com.mysema.query.types.Path;
import com.mysema.query.types.PathMetadata; import com.mysema.query.types.PathMetadata;
@@ -21,33 +24,40 @@ public class QItem extends com.mysema.query.sql.RelationalPathBase<Item> {
public static final QItem item = new QItem("item"); public static final QItem item = new QItem("item");
@ColumnSize(10)
public final NumberPath<Integer> itemId = createNumber("item_id",
Integer.class);
@ColumnSize(5)
public final NumberPath<Integer> templateId = createNumber("template_id",
Integer.class);
@ColumnSize(10)
@ColumnNullable
public final NumberPath<Integer> characterId = createNumber("character_id", public final NumberPath<Integer> characterId = createNumber("character_id",
Integer.class); Integer.class);
@ColumnSize(10)
@ColumnNullable
public final NumberPath<Integer> coordX = createNumber("coord_x", public final NumberPath<Integer> coordX = createNumber("coord_x",
Integer.class); Integer.class);
@ColumnSize(10)
@ColumnNullable
public final NumberPath<Integer> coordY = createNumber("coord_y", public final NumberPath<Integer> coordY = createNumber("coord_y",
Integer.class); Integer.class);
@ColumnSize(10)
@ColumnNullable
public final NumberPath<Integer> coordZ = createNumber("coord_z", public final NumberPath<Integer> coordZ = createNumber("coord_z",
Integer.class); Integer.class);
@ColumnSize(10)
public final NumberPath<Long> count = createNumber("count", Long.class);
public final NumberPath<Long> count = createNumber("count", @ColumnDefault("INVENTORY")
Long.class);
public final NumberPath<Integer> itemId = createNumber("item_id",
Integer.class);
public final EnumPath<ItemLocation> location = createEnum("location", public final EnumPath<ItemLocation> location = createEnum("location",
ItemLocation.class); ItemLocation.class);
@ColumnNullable
public final EnumPath<InventoryPaperdoll> paperdoll = createEnum( public final EnumPath<InventoryPaperdoll> paperdoll = createEnum(
"paperdoll", InventoryPaperdoll.class); "paperdoll", InventoryPaperdoll.class);
public final NumberPath<Integer> templateId = createNumber("template_id",
Integer.class);
public final PrimaryKey<Item> primary = createPrimaryKey(itemId); public final PrimaryKey<Item> primary = createPrimaryKey(itemId);
public QItem(String variable) { public QItem(String variable) {

View File

@@ -5,6 +5,9 @@ import static com.mysema.query.types.PathMetadataFactory.forVariable;
import java.util.Date; import java.util.Date;
import com.l2jserver.model.server.ChatMessage; import com.l2jserver.model.server.ChatMessage;
import com.l2jserver.service.database.sql.ddl.annotation.ColumnAutoIncrement;
import com.l2jserver.service.database.sql.ddl.annotation.ColumnNullable;
import com.l2jserver.service.database.sql.ddl.annotation.ColumnSize;
import com.l2jserver.service.game.chat.ChatMessageType; import com.l2jserver.service.game.chat.ChatMessageType;
import com.mysema.query.sql.PrimaryKey; import com.mysema.query.sql.PrimaryKey;
import com.mysema.query.types.Path; import com.mysema.query.types.Path;
@@ -24,19 +27,25 @@ public class QLogChat extends com.mysema.query.sql.RelationalPathBase<ChatMessag
public static final QLogChat logChat = new QLogChat("log_chat"); public static final QLogChat logChat = new QLogChat("log_chat");
@ColumnSize(10)
@ColumnAutoIncrement
public final NumberPath<Integer> messageId = createNumber("message_id",
Integer.class);
@ColumnSize(10)
@ColumnNullable
public final NumberPath<Integer> channelId = createNumber("channel_id", public final NumberPath<Integer> channelId = createNumber("channel_id",
Integer.class); Integer.class);
@ColumnSize(10)
@ColumnNullable
public final NumberPath<Integer> sender = createNumber("sender",
Integer.class);
public final DateTimePath<Date> date = createDateTime("date", Date.class); public final DateTimePath<Date> date = createDateTime("date", Date.class);
@ColumnSize(255)
public final StringPath message = createString("message"); public final StringPath message = createString("message");
public final NumberPath<Integer> messageId = createNumber("message_id",
Integer.class);
public final NumberPath<Integer> sender = createNumber("sender",
Integer.class);
public final EnumPath<ChatMessageType> type = createEnum("type", public final EnumPath<ChatMessageType> type = createEnum("type",
ChatMessageType.class); ChatMessageType.class);

View File

@@ -3,53 +3,60 @@ package com.l2jserver.service.database.model;
import static com.mysema.query.types.PathMetadataFactory.forVariable; import static com.mysema.query.types.PathMetadataFactory.forVariable;
import com.l2jserver.model.world.NPC; import com.l2jserver.model.world.NPC;
import com.l2jserver.service.database.sql.ddl.annotation.ColumnSize;
import com.mysema.query.sql.PrimaryKey; import com.mysema.query.sql.PrimaryKey;
import com.mysema.query.types.Path; import com.mysema.query.types.Path;
import com.mysema.query.types.PathMetadata; import com.mysema.query.types.PathMetadata;
import com.mysema.query.types.path.NumberPath; import com.mysema.query.types.path.NumberPath;
/** /**
* Maps <code>npc</code> table into type-safe java objects * Maps <code>npc</code> table into type-safe java objects
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class QNPC extends com.mysema.query.sql.RelationalPathBase<NPC> { public class QNPC extends com.mysema.query.sql.RelationalPathBase<NPC> {
private static final long serialVersionUID = 2129578208; private static final long serialVersionUID = 2129578208;
public static final QNPC npc = new QNPC("npc"); public static final QNPC npc = new QNPC("npc");
public final NumberPath<Double> hp = createNumber("hp", Double.class); @ColumnSize(10)
public final NumberPath<Integer> npcId = createNumber("npc_id",
Integer.class);
@ColumnSize(4)
public final NumberPath<Integer> npcTemplateId = createNumber(
"npc_template_id", Integer.class);
public final NumberPath<Double> mp = createNumber("mp", Double.class); public final NumberPath<Double> hp = createNumber("hp", Double.class);
public final NumberPath<Double> mp = createNumber("mp", Double.class);
public final NumberPath<Integer> npcId = createNumber("npc_id", Integer.class); public final NumberPath<Double> pointAngle = createNumber("point_angle",
Double.class);
@ColumnSize(10)
public final NumberPath<Integer> pointX = createNumber("point_x",
Integer.class);
@ColumnSize(10)
public final NumberPath<Integer> pointY = createNumber("point_y",
Integer.class);
@ColumnSize(10)
public final NumberPath<Integer> pointZ = createNumber("point_z",
Integer.class);
public final NumberPath<Integer> npcTemplateId = createNumber("npc_template_id", Integer.class); @ColumnSize(8)
public final NumberPath<Long> respawnTime = createNumber("respawn_time",
Long.class);
public final NumberPath<Double> pointAngle = createNumber("point_angle", Double.class); public final PrimaryKey<NPC> primary = createPrimaryKey(npcId);
public final NumberPath<Integer> pointX = createNumber("point_x", Integer.class); public QNPC(String variable) {
super(NPC.class, forVariable(variable), "null", "npc");
}
public final NumberPath<Integer> pointY = createNumber("point_y", Integer.class); public QNPC(Path<? extends NPC> entity) {
super(entity.getType(), entity.getMetadata(), "null", "npc");
}
public final NumberPath<Integer> pointZ = createNumber("point_z", Integer.class); public QNPC(PathMetadata<?> metadata) {
super(NPC.class, metadata, "null", "npc");
public final NumberPath<Long> respawnTime = createNumber("respawn_time", Long.class); }
public final PrimaryKey<NPC> primary = createPrimaryKey(npcId);
public QNPC(String variable) {
super(NPC.class, forVariable(variable), "null", "npc");
}
public QNPC(Path<? extends NPC> entity) {
super(entity.getType(), entity.getMetadata(), "null", "npc");
}
public QNPC(PathMetadata<?> metadata) {
super(NPC.class, metadata, "null", "npc");
}
} }

View File

@@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with l2jserver2. If not, see <http://www.gnu.org/licenses/>. * along with l2jserver2. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.l2jserver.service.database.jdbc; package com.l2jserver.service.database.sql;
import java.util.List; import java.util.List;
@@ -26,13 +26,14 @@ import com.l2jserver.model.id.object.CharacterID;
import com.l2jserver.model.world.Clan; import com.l2jserver.model.world.Clan;
import com.l2jserver.model.world.L2Character; import com.l2jserver.model.world.L2Character;
import com.l2jserver.service.database.DatabaseService; import com.l2jserver.service.database.DatabaseService;
import com.l2jserver.service.database.jdbc.AbstractJDBCDatabaseService.DeleteQuery;
import com.l2jserver.service.database.jdbc.AbstractJDBCDatabaseService.InsertQuery;
import com.l2jserver.service.database.jdbc.AbstractJDBCDatabaseService.SelectListQuery;
import com.l2jserver.service.database.jdbc.AbstractJDBCDatabaseService.SelectSingleQuery;
import com.l2jserver.service.database.jdbc.AbstractJDBCDatabaseService.UpdateQuery;
import com.l2jserver.service.database.mapper.CharacterMapper; import com.l2jserver.service.database.mapper.CharacterMapper;
import com.l2jserver.service.database.model.QCharacter; import com.l2jserver.service.database.model.QCharacter;
import com.l2jserver.service.database.sql.AbstractSQLDAO;
import com.l2jserver.service.database.sql.AbstractSQLDatabaseService.DeleteQuery;
import com.l2jserver.service.database.sql.AbstractSQLDatabaseService.InsertQuery;
import com.l2jserver.service.database.sql.AbstractSQLDatabaseService.SelectListQuery;
import com.l2jserver.service.database.sql.AbstractSQLDatabaseService.SelectSingleQuery;
import com.l2jserver.service.database.sql.AbstractSQLDatabaseService.UpdateQuery;
import com.mysema.query.sql.AbstractSQLQuery; import com.mysema.query.sql.AbstractSQLQuery;
import com.mysema.query.sql.dml.SQLDeleteClause; import com.mysema.query.sql.dml.SQLDeleteClause;
import com.mysema.query.sql.dml.SQLInsertClause; import com.mysema.query.sql.dml.SQLInsertClause;
@@ -43,7 +44,7 @@ import com.mysema.query.sql.dml.SQLUpdateClause;
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class JDBCCharacterDAO extends AbstractJDBCDAO<L2Character, CharacterID> public class SQLCharacterDAO extends AbstractSQLDAO<L2Character, CharacterID>
implements CharacterDAO { implements CharacterDAO {
/** /**
* The {@link L2Character} mapper * The {@link L2Character} mapper
@@ -57,7 +58,7 @@ public class JDBCCharacterDAO extends AbstractJDBCDAO<L2Character, CharacterID>
* the character mapper * the character mapper
*/ */
@Inject @Inject
public JDBCCharacterDAO(DatabaseService database, CharacterMapper mapper) { public SQLCharacterDAO(DatabaseService database, CharacterMapper mapper) {
super(database); super(database);
this.mapper = mapper; this.mapper = mapper;
} }

View File

@@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with l2jserver2. If not, see <http://www.gnu.org/licenses/>. * along with l2jserver2. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.l2jserver.service.database.jdbc; package com.l2jserver.service.database.sql;
import java.util.List; import java.util.List;
@@ -26,12 +26,13 @@ import com.l2jserver.model.id.FriendID;
import com.l2jserver.model.world.L2Character; import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.character.CharacterFriendList; import com.l2jserver.model.world.character.CharacterFriendList;
import com.l2jserver.service.database.DatabaseService; import com.l2jserver.service.database.DatabaseService;
import com.l2jserver.service.database.jdbc.AbstractJDBCDatabaseService.DeleteQuery;
import com.l2jserver.service.database.jdbc.AbstractJDBCDatabaseService.InsertQuery;
import com.l2jserver.service.database.jdbc.AbstractJDBCDatabaseService.SelectListQuery;
import com.l2jserver.service.database.jdbc.AbstractJDBCDatabaseService.SelectSingleQuery;
import com.l2jserver.service.database.mapper.CharacterFriendMapper; import com.l2jserver.service.database.mapper.CharacterFriendMapper;
import com.l2jserver.service.database.model.QCharacterFriend; import com.l2jserver.service.database.model.QCharacterFriend;
import com.l2jserver.service.database.sql.AbstractSQLDAO;
import com.l2jserver.service.database.sql.AbstractSQLDatabaseService.DeleteQuery;
import com.l2jserver.service.database.sql.AbstractSQLDatabaseService.InsertQuery;
import com.l2jserver.service.database.sql.AbstractSQLDatabaseService.SelectListQuery;
import com.l2jserver.service.database.sql.AbstractSQLDatabaseService.SelectSingleQuery;
import com.mysema.query.sql.AbstractSQLQuery; import com.mysema.query.sql.AbstractSQLQuery;
import com.mysema.query.sql.dml.SQLDeleteClause; import com.mysema.query.sql.dml.SQLDeleteClause;
import com.mysema.query.sql.dml.SQLInsertClause; import com.mysema.query.sql.dml.SQLInsertClause;
@@ -41,8 +42,8 @@ import com.mysema.query.sql.dml.SQLInsertClause;
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class JDBCCharacterFriendDAO extends public class SQLCharacterFriendDAO extends
AbstractJDBCDAO<CharacterFriend, FriendID> implements AbstractSQLDAO<CharacterFriend, FriendID> implements
CharacterFriendDAO { CharacterFriendDAO {
/** /**
* The {@link CharacterFriend} mapper * The {@link CharacterFriend} mapper
@@ -56,7 +57,7 @@ public class JDBCCharacterFriendDAO extends
* the character friend mapper * the character friend mapper
*/ */
@Inject @Inject
public JDBCCharacterFriendDAO(DatabaseService database, public SQLCharacterFriendDAO(DatabaseService database,
CharacterFriendMapper mapper) { CharacterFriendMapper mapper) {
super(database); super(database);
this.mapper = mapper; this.mapper = mapper;

View File

@@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with l2jserver2. If not, see <http://www.gnu.org/licenses/>. * along with l2jserver2. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.l2jserver.service.database.jdbc; package com.l2jserver.service.database.sql;
import java.util.List; import java.util.List;
@@ -26,13 +26,14 @@ import com.l2jserver.model.game.CharacterShortcut;
import com.l2jserver.model.id.CharacterShortcutID; import com.l2jserver.model.id.CharacterShortcutID;
import com.l2jserver.model.world.L2Character; import com.l2jserver.model.world.L2Character;
import com.l2jserver.service.database.DatabaseService; import com.l2jserver.service.database.DatabaseService;
import com.l2jserver.service.database.jdbc.AbstractJDBCDatabaseService.DeleteQuery;
import com.l2jserver.service.database.jdbc.AbstractJDBCDatabaseService.InsertQuery;
import com.l2jserver.service.database.jdbc.AbstractJDBCDatabaseService.SelectListQuery;
import com.l2jserver.service.database.jdbc.AbstractJDBCDatabaseService.SelectSingleQuery;
import com.l2jserver.service.database.jdbc.AbstractJDBCDatabaseService.UpdateQuery;
import com.l2jserver.service.database.mapper.CharacterShortcutMapper; import com.l2jserver.service.database.mapper.CharacterShortcutMapper;
import com.l2jserver.service.database.model.QCharacterShortcut; import com.l2jserver.service.database.model.QCharacterShortcut;
import com.l2jserver.service.database.sql.AbstractSQLDAO;
import com.l2jserver.service.database.sql.AbstractSQLDatabaseService.DeleteQuery;
import com.l2jserver.service.database.sql.AbstractSQLDatabaseService.InsertQuery;
import com.l2jserver.service.database.sql.AbstractSQLDatabaseService.SelectListQuery;
import com.l2jserver.service.database.sql.AbstractSQLDatabaseService.SelectSingleQuery;
import com.l2jserver.service.database.sql.AbstractSQLDatabaseService.UpdateQuery;
import com.mysema.query.sql.AbstractSQLQuery; import com.mysema.query.sql.AbstractSQLQuery;
import com.mysema.query.sql.dml.SQLDeleteClause; import com.mysema.query.sql.dml.SQLDeleteClause;
import com.mysema.query.sql.dml.SQLInsertClause; import com.mysema.query.sql.dml.SQLInsertClause;
@@ -43,8 +44,8 @@ import com.mysema.query.sql.dml.SQLUpdateClause;
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class JDBCCharacterShortcutDAO extends public class SQLCharacterShortcutDAO extends
AbstractJDBCDAO<CharacterShortcut, CharacterShortcutID> implements AbstractSQLDAO<CharacterShortcut, CharacterShortcutID> implements
CharacterShortcutDAO { CharacterShortcutDAO {
private final CharacterShortcutMapper mapper; private final CharacterShortcutMapper mapper;
@@ -55,7 +56,7 @@ public class JDBCCharacterShortcutDAO extends
* the {@link CharacterShortcut} mapper * the {@link CharacterShortcut} mapper
*/ */
@Inject @Inject
public JDBCCharacterShortcutDAO(DatabaseService database, public SQLCharacterShortcutDAO(DatabaseService database,
CharacterShortcutMapper mapper) { CharacterShortcutMapper mapper) {
super(database); super(database);
this.mapper = mapper; this.mapper = mapper;

View File

@@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with l2jserver2. If not, see <http://www.gnu.org/licenses/>. * along with l2jserver2. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.l2jserver.service.database.jdbc; package com.l2jserver.service.database.sql;
import java.util.Collection; import java.util.Collection;
@@ -25,13 +25,14 @@ import com.l2jserver.model.dao.ChatMessageDAO;
import com.l2jserver.model.id.ChatMessageID; import com.l2jserver.model.id.ChatMessageID;
import com.l2jserver.model.server.ChatMessage; import com.l2jserver.model.server.ChatMessage;
import com.l2jserver.service.database.DatabaseService; import com.l2jserver.service.database.DatabaseService;
import com.l2jserver.service.database.jdbc.AbstractJDBCDatabaseService.DeleteQuery;
import com.l2jserver.service.database.jdbc.AbstractJDBCDatabaseService.InsertQuery;
import com.l2jserver.service.database.jdbc.AbstractJDBCDatabaseService.SelectListQuery;
import com.l2jserver.service.database.jdbc.AbstractJDBCDatabaseService.SelectSingleQuery;
import com.l2jserver.service.database.jdbc.AbstractJDBCDatabaseService.UpdateQuery;
import com.l2jserver.service.database.mapper.ChatMessageMapper; import com.l2jserver.service.database.mapper.ChatMessageMapper;
import com.l2jserver.service.database.model.QLogChat; import com.l2jserver.service.database.model.QLogChat;
import com.l2jserver.service.database.sql.AbstractSQLDAO;
import com.l2jserver.service.database.sql.AbstractSQLDatabaseService.DeleteQuery;
import com.l2jserver.service.database.sql.AbstractSQLDatabaseService.InsertQuery;
import com.l2jserver.service.database.sql.AbstractSQLDatabaseService.SelectListQuery;
import com.l2jserver.service.database.sql.AbstractSQLDatabaseService.SelectSingleQuery;
import com.l2jserver.service.database.sql.AbstractSQLDatabaseService.UpdateQuery;
import com.mysema.query.sql.AbstractSQLQuery; import com.mysema.query.sql.AbstractSQLQuery;
import com.mysema.query.sql.dml.SQLDeleteClause; import com.mysema.query.sql.dml.SQLDeleteClause;
import com.mysema.query.sql.dml.SQLInsertClause; import com.mysema.query.sql.dml.SQLInsertClause;
@@ -42,8 +43,8 @@ import com.mysema.query.sql.dml.SQLUpdateClause;
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class JDBCChatMessageDAO extends public class SQLChatMessageDAO extends
AbstractJDBCDAO<ChatMessage, ChatMessageID> implements ChatMessageDAO { AbstractSQLDAO<ChatMessage, ChatMessageID> implements ChatMessageDAO {
private final ChatMessageMapper mapper; private final ChatMessageMapper mapper;
/** /**
@@ -53,7 +54,7 @@ public class JDBCChatMessageDAO extends
* the mapper * the mapper
*/ */
@Inject @Inject
public JDBCChatMessageDAO(DatabaseService database, ChatMessageMapper mapper) { public SQLChatMessageDAO(DatabaseService database, ChatMessageMapper mapper) {
super(database); super(database);
this.mapper = mapper; this.mapper = mapper;
} }

View File

@@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with l2jserver2. If not, see <http://www.gnu.org/licenses/>. * along with l2jserver2. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.l2jserver.service.database.jdbc; package com.l2jserver.service.database.sql;
import java.util.Collection; import java.util.Collection;
@@ -25,13 +25,14 @@ import com.l2jserver.model.dao.ClanDAO;
import com.l2jserver.model.id.object.ClanID; import com.l2jserver.model.id.object.ClanID;
import com.l2jserver.model.world.Clan; import com.l2jserver.model.world.Clan;
import com.l2jserver.service.database.DatabaseService; import com.l2jserver.service.database.DatabaseService;
import com.l2jserver.service.database.jdbc.AbstractJDBCDatabaseService.DeleteQuery;
import com.l2jserver.service.database.jdbc.AbstractJDBCDatabaseService.InsertQuery;
import com.l2jserver.service.database.jdbc.AbstractJDBCDatabaseService.SelectListQuery;
import com.l2jserver.service.database.jdbc.AbstractJDBCDatabaseService.SelectSingleQuery;
import com.l2jserver.service.database.jdbc.AbstractJDBCDatabaseService.UpdateQuery;
import com.l2jserver.service.database.mapper.ClanMapper; import com.l2jserver.service.database.mapper.ClanMapper;
import com.l2jserver.service.database.model.QClan; import com.l2jserver.service.database.model.QClan;
import com.l2jserver.service.database.sql.AbstractSQLDAO;
import com.l2jserver.service.database.sql.AbstractSQLDatabaseService.DeleteQuery;
import com.l2jserver.service.database.sql.AbstractSQLDatabaseService.InsertQuery;
import com.l2jserver.service.database.sql.AbstractSQLDatabaseService.SelectListQuery;
import com.l2jserver.service.database.sql.AbstractSQLDatabaseService.SelectSingleQuery;
import com.l2jserver.service.database.sql.AbstractSQLDatabaseService.UpdateQuery;
import com.mysema.query.sql.AbstractSQLQuery; import com.mysema.query.sql.AbstractSQLQuery;
import com.mysema.query.sql.dml.SQLDeleteClause; import com.mysema.query.sql.dml.SQLDeleteClause;
import com.mysema.query.sql.dml.SQLInsertClause; import com.mysema.query.sql.dml.SQLInsertClause;
@@ -42,7 +43,7 @@ import com.mysema.query.sql.dml.SQLUpdateClause;
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class JDBCClanDAO extends AbstractJDBCDAO<Clan, ClanID> implements public class SQLClanDAO extends AbstractSQLDAO<Clan, ClanID> implements
ClanDAO { ClanDAO {
private final ClanMapper mapper; private final ClanMapper mapper;
@@ -53,7 +54,7 @@ public class JDBCClanDAO extends AbstractJDBCDAO<Clan, ClanID> implements
* the mapper * the mapper
*/ */
@Inject @Inject
public JDBCClanDAO(DatabaseService database, final ClanMapper mapper) { public SQLClanDAO(DatabaseService database, final ClanMapper mapper) {
super(database); super(database);
this.mapper = mapper; this.mapper = mapper;
} }

View File

@@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with l2jserver2. If not, see <http://www.gnu.org/licenses/>. * along with l2jserver2. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.l2jserver.service.database.jdbc; package com.l2jserver.service.database.sql;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
@@ -27,13 +27,14 @@ import com.l2jserver.model.world.Item;
import com.l2jserver.model.world.L2Character; import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.character.CharacterInventory.ItemLocation; import com.l2jserver.model.world.character.CharacterInventory.ItemLocation;
import com.l2jserver.service.database.DatabaseService; import com.l2jserver.service.database.DatabaseService;
import com.l2jserver.service.database.jdbc.AbstractJDBCDatabaseService.DeleteQuery;
import com.l2jserver.service.database.jdbc.AbstractJDBCDatabaseService.InsertQuery;
import com.l2jserver.service.database.jdbc.AbstractJDBCDatabaseService.SelectListQuery;
import com.l2jserver.service.database.jdbc.AbstractJDBCDatabaseService.SelectSingleQuery;
import com.l2jserver.service.database.jdbc.AbstractJDBCDatabaseService.UpdateQuery;
import com.l2jserver.service.database.mapper.ItemMapper; import com.l2jserver.service.database.mapper.ItemMapper;
import com.l2jserver.service.database.model.QItem; import com.l2jserver.service.database.model.QItem;
import com.l2jserver.service.database.sql.AbstractSQLDAO;
import com.l2jserver.service.database.sql.AbstractSQLDatabaseService.DeleteQuery;
import com.l2jserver.service.database.sql.AbstractSQLDatabaseService.InsertQuery;
import com.l2jserver.service.database.sql.AbstractSQLDatabaseService.SelectListQuery;
import com.l2jserver.service.database.sql.AbstractSQLDatabaseService.SelectSingleQuery;
import com.l2jserver.service.database.sql.AbstractSQLDatabaseService.UpdateQuery;
import com.mysema.query.sql.AbstractSQLQuery; import com.mysema.query.sql.AbstractSQLQuery;
import com.mysema.query.sql.dml.SQLDeleteClause; import com.mysema.query.sql.dml.SQLDeleteClause;
import com.mysema.query.sql.dml.SQLInsertClause; import com.mysema.query.sql.dml.SQLInsertClause;
@@ -44,7 +45,7 @@ import com.mysema.query.sql.dml.SQLUpdateClause;
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class JDBCItemDAO extends AbstractJDBCDAO<Item, ItemID> implements public class SQLItemDAO extends AbstractSQLDAO<Item, ItemID> implements
ItemDAO { ItemDAO {
private final ItemMapper mapper; private final ItemMapper mapper;
@@ -55,7 +56,7 @@ public class JDBCItemDAO extends AbstractJDBCDAO<Item, ItemID> implements
* the mapper * the mapper
*/ */
@Inject @Inject
public JDBCItemDAO(DatabaseService database, ItemMapper mapper) { public SQLItemDAO(DatabaseService database, ItemMapper mapper) {
super(database); super(database);
this.mapper = mapper; this.mapper = mapper;
} }

View File

@@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with l2jserver2. If not, see <http://www.gnu.org/licenses/>. * along with l2jserver2. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.l2jserver.service.database.jdbc; package com.l2jserver.service.database.sql;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
@@ -27,13 +27,14 @@ import com.l2jserver.model.id.object.NPCID;
import com.l2jserver.model.id.template.NPCTemplateID; import com.l2jserver.model.id.template.NPCTemplateID;
import com.l2jserver.model.world.NPC; import com.l2jserver.model.world.NPC;
import com.l2jserver.service.database.DatabaseService; import com.l2jserver.service.database.DatabaseService;
import com.l2jserver.service.database.jdbc.AbstractJDBCDatabaseService.DeleteQuery;
import com.l2jserver.service.database.jdbc.AbstractJDBCDatabaseService.InsertQuery;
import com.l2jserver.service.database.jdbc.AbstractJDBCDatabaseService.SelectListQuery;
import com.l2jserver.service.database.jdbc.AbstractJDBCDatabaseService.SelectSingleQuery;
import com.l2jserver.service.database.jdbc.AbstractJDBCDatabaseService.UpdateQuery;
import com.l2jserver.service.database.mapper.NPCMapper; import com.l2jserver.service.database.mapper.NPCMapper;
import com.l2jserver.service.database.model.QNPC; import com.l2jserver.service.database.model.QNPC;
import com.l2jserver.service.database.sql.AbstractSQLDAO;
import com.l2jserver.service.database.sql.AbstractSQLDatabaseService.DeleteQuery;
import com.l2jserver.service.database.sql.AbstractSQLDatabaseService.InsertQuery;
import com.l2jserver.service.database.sql.AbstractSQLDatabaseService.SelectListQuery;
import com.l2jserver.service.database.sql.AbstractSQLDatabaseService.SelectSingleQuery;
import com.l2jserver.service.database.sql.AbstractSQLDatabaseService.UpdateQuery;
import com.mysema.query.sql.AbstractSQLQuery; import com.mysema.query.sql.AbstractSQLQuery;
import com.mysema.query.sql.dml.SQLDeleteClause; import com.mysema.query.sql.dml.SQLDeleteClause;
import com.mysema.query.sql.dml.SQLInsertClause; import com.mysema.query.sql.dml.SQLInsertClause;
@@ -44,7 +45,7 @@ import com.mysema.query.sql.dml.SQLUpdateClause;
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class JDBCNPCDAO extends AbstractJDBCDAO<NPC, NPCID> implements NPCDAO { public class SQLNPCDAO extends AbstractSQLDAO<NPC, NPCID> implements NPCDAO {
private final NPCMapper mapper; private final NPCMapper mapper;
/** /**
@@ -54,7 +55,7 @@ public class JDBCNPCDAO extends AbstractJDBCDAO<NPC, NPCID> implements NPCDAO {
* the mapper * the mapper
*/ */
@Inject @Inject
public JDBCNPCDAO(DatabaseService database, NPCMapper mapper) { public SQLNPCDAO(DatabaseService database, NPCMapper mapper) {
super(database); super(database);
this.mapper = mapper; this.mapper = mapper;
} }

View File

@@ -7,7 +7,7 @@ import com.l2jserver.service.configuration.XMLConfigurationService;
import com.l2jserver.service.core.Log4JLoggingService; import com.l2jserver.service.core.Log4JLoggingService;
import com.l2jserver.service.core.LoggingService; import com.l2jserver.service.core.LoggingService;
import com.l2jserver.service.database.DatabaseService; import com.l2jserver.service.database.DatabaseService;
import com.l2jserver.service.database.LoginServerJDBCDatabaseService; import com.l2jserver.service.database.LoginServerSQLDatabaseService;
public class ServiceModule extends AbstractModule { public class ServiceModule extends AbstractModule {
@Override @Override
@@ -17,7 +17,7 @@ public class ServiceModule extends AbstractModule {
Scopes.SINGLETON); Scopes.SINGLETON);
bind(ConfigurationService.class).to(XMLConfigurationService.class) bind(ConfigurationService.class).to(XMLConfigurationService.class)
.in(Scopes.SINGLETON); .in(Scopes.SINGLETON);
bind(DatabaseService.class).to(LoginServerJDBCDatabaseService.class) bind(DatabaseService.class).to(LoginServerSQLDatabaseService.class)
.in(Scopes.SINGLETON); .in(Scopes.SINGLETON);
} }
} }

View File

@@ -16,40 +16,44 @@
*/ */
package com.l2jserver.service.database; package com.l2jserver.service.database;
import java.sql.Connection;
import java.sql.SQLException;
import com.l2jserver.service.AbstractService.Depends; import com.l2jserver.service.AbstractService.Depends;
import com.l2jserver.service.cache.CacheService; import com.l2jserver.service.cache.CacheService;
import com.l2jserver.service.configuration.ConfigurationService; import com.l2jserver.service.configuration.ConfigurationService;
import com.l2jserver.service.core.LoggingService; import com.l2jserver.service.core.LoggingService;
import com.l2jserver.service.core.threading.ThreadService; import com.l2jserver.service.core.threading.ThreadService;
import com.l2jserver.service.database.jdbc.AbstractJDBCDatabaseService; import com.l2jserver.service.core.vfs.VFSService;
import com.l2jserver.service.database.sql.AbstractSQLDatabaseService;
/** /**
* This is an implementation of {@link DatabaseService} that provides an layer * This is an implementation of {@link DatabaseService} that provides an layer
* to JDBC. * to JDBC.
* *
* <h1>Internal specification</h1> <h2>The * <h1>Internal specification</h1> <h2>The
* {@link com.l2jserver.service.database.jdbc.AbstractJDBCDatabaseService.Query * {@link com.l2jserver.service.database.sql.AbstractSQLDatabaseService.Query
* Query} object</h2> * Query} object</h2>
* *
* If you wish to implement a new {@link DataAccessObject} you should try not * If you wish to implement a new {@link DataAccessObject} you should try not
* use * use
* {@link com.l2jserver.service.database.jdbc.AbstractJDBCDatabaseService.Query * {@link com.l2jserver.service.database.sql.AbstractSQLDatabaseService.Query
* Query} object directly because it only provides low level access to the JDBC * Query} object directly because it only provides low level access to the JDBC
* architecture. Instead, you could use an specialized class, like * architecture. Instead, you could use an specialized class, like
* {@link com.l2jserver.service.database.jdbc.AbstractJDBCDatabaseService.InsertQuery * {@link com.l2jserver.service.database.sql.AbstractSQLDatabaseService.InsertQuery
* InsertUpdateQuery} , * InsertUpdateQuery} ,
* {@link com.l2jserver.service.database.jdbc.AbstractJDBCDatabaseService.SelectListQuery * {@link com.l2jserver.service.database.sql.AbstractSQLDatabaseService.SelectListQuery
* SelectListQuery} or * SelectListQuery} or
* {@link com.l2jserver.service.database.jdbc.AbstractJDBCDatabaseService.SelectSingleQuery * {@link com.l2jserver.service.database.sql.AbstractSQLDatabaseService.SelectSingleQuery
* SelectSingleQuery} . If you do need low level access, feel free to use the * SelectSingleQuery} . If you do need low level access, feel free to use the
* {@link com.l2jserver.service.database.jdbc.AbstractJDBCDatabaseService.Query * {@link com.l2jserver.service.database.sql.AbstractSQLDatabaseService.Query
* Query} class directly. * Query} class directly.
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
@Depends({ LoggingService.class, CacheService.class, @Depends({ LoggingService.class, CacheService.class,
ConfigurationService.class, ThreadService.class }) ConfigurationService.class, ThreadService.class })
public class LoginServerJDBCDatabaseService extends AbstractJDBCDatabaseService public class LoginServerSQLDatabaseService extends AbstractSQLDatabaseService
implements DatabaseService { implements DatabaseService {
/** /**
* @param configService * @param configService
@@ -58,12 +62,19 @@ public class LoginServerJDBCDatabaseService extends AbstractJDBCDatabaseService
* the cache service * the cache service
* @param threadService * @param threadService
* the thread service * the thread service
* @param vfsService
* the vfs service
* @param daoResolver * @param daoResolver
* the {@link DataAccessObject DAO} resolver * the {@link DataAccessObject DAO} resolver
*/ */
public LoginServerJDBCDatabaseService(ConfigurationService configService, public LoginServerSQLDatabaseService(ConfigurationService configService,
CacheService cacheService, ThreadService threadService, CacheService cacheService, ThreadService threadService,
DAOResolver daoResolver) { VFSService vfsService, DAOResolver daoResolver) {
super(configService, cacheService, threadService, daoResolver); super(configService, cacheService, threadService, vfsService,
daoResolver);
}
@Override
protected void ensureDatabaseSchema(Connection conn) throws SQLException {
} }
} }

View File

@@ -0,0 +1,33 @@
/*
* This file is part of l2jserver2 <l2jserver2.com>.
*
* l2jserver2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* l2jserver2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with l2jserver2. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.tool.ddl;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>
*
*/
public class GenerateSQLFiles {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}