1
0
mirror of https://github.com/Rogiel/l2jserver2 synced 2026-01-28 21:52:48 +00:00

Base AI, new Cache system, DAO changes and better geometry handling

Signed-off-by: Rogiel <rogiel@rogiel.com>
This commit is contained in:
2011-05-27 02:49:15 -03:00
parent aabe375b49
commit 73f51e53c0
95 changed files with 3079 additions and 1884 deletions

View File

@@ -0,0 +1,50 @@
/*
* This file is part of l2jserver <l2jserver.com>.
*
* l2jserver 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.
*
* l2jserver 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 l2jserver. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.db;
import com.google.inject.AbstractModule;
import com.google.inject.Module;
import com.google.inject.Scopes;
import com.l2jserver.db.dao.CharacterDAO;
import com.l2jserver.db.dao.CharacterFriendDAO;
import com.l2jserver.db.dao.ClanDAO;
import com.l2jserver.db.dao.ItemDAO;
import com.l2jserver.db.dao.NPCDAO;
import com.l2jserver.db.dao.h2.H2CharacterDAO;
import com.l2jserver.db.dao.h2.H2CharacterFriendDAO;
import com.l2jserver.db.dao.h2.H2ClanDAO;
import com.l2jserver.db.dao.h2.H2ItemDAO;
import com.l2jserver.db.dao.h2.H2NPCDAO;
/**
* Google Guice {@link Module} for H2 DAOs
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class H2DAOModule extends AbstractModule {
@Override
protected void configure() {
bind(CharacterDAO.class).to(H2CharacterDAO.class).in(Scopes.SINGLETON);
bind(CharacterFriendDAO.class).to(H2CharacterFriendDAO.class).in(
Scopes.SINGLETON);
bind(NPCDAO.class).to(H2NPCDAO.class).in(Scopes.SINGLETON);
bind(ItemDAO.class).to(H2ItemDAO.class).in(Scopes.SINGLETON);
bind(ClanDAO.class).to(H2ClanDAO.class).in(Scopes.SINGLETON);
}
}

View File

@@ -0,0 +1,51 @@
/*
* This file is part of l2jserver <l2jserver.com>.
*
* l2jserver 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.
*
* l2jserver 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 l2jserver. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.db;
import com.google.inject.AbstractModule;
import com.google.inject.Module;
import com.google.inject.Scopes;
import com.l2jserver.db.dao.CharacterDAO;
import com.l2jserver.db.dao.CharacterFriendDAO;
import com.l2jserver.db.dao.ClanDAO;
import com.l2jserver.db.dao.ItemDAO;
import com.l2jserver.db.dao.NPCDAO;
import com.l2jserver.db.dao.mysql5.MySQL5CharacterDAO;
import com.l2jserver.db.dao.mysql5.MySQL5CharacterFriendDAO;
import com.l2jserver.db.dao.mysql5.MySQL5ClanDAO;
import com.l2jserver.db.dao.mysql5.MySQL5ItemDAO;
import com.l2jserver.db.dao.mysql5.MySQL5NPCDAO;
/**
* Google Guice {@link Module} for MySQL5 DAOs
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class MySQL5DAOModule extends AbstractModule {
@Override
protected void configure() {
bind(CharacterDAO.class).to(MySQL5CharacterDAO.class).in(
Scopes.SINGLETON);
bind(CharacterFriendDAO.class).to(MySQL5CharacterFriendDAO.class).in(
Scopes.SINGLETON);
bind(NPCDAO.class).to(MySQL5NPCDAO.class).in(Scopes.SINGLETON);
bind(ItemDAO.class).to(MySQL5ItemDAO.class).in(Scopes.SINGLETON);
bind(ClanDAO.class).to(MySQL5ClanDAO.class).in(Scopes.SINGLETON);
}
}

View File

@@ -0,0 +1,41 @@
/*
* This file is part of l2jserver <l2jserver.com>.
*
* l2jserver 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.
*
* l2jserver 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 l2jserver. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.db.dao.h2;
import com.l2jserver.db.dao.CharacterDAO;
import com.l2jserver.db.dao.jdbc.JDBCCharacterDAO;
import com.l2jserver.model.id.object.provider.CharacterIDProvider;
import com.l2jserver.model.id.object.provider.ClanIDProvider;
import com.l2jserver.model.id.provider.AccountIDProvider;
import com.l2jserver.model.id.template.provider.CharacterTemplateIDProvider;
import com.l2jserver.service.database.DatabaseService;
/**
* {@link CharacterDAO} implementation for MySQL5
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class H2CharacterDAO extends JDBCCharacterDAO implements
CharacterDAO {
public H2CharacterDAO(DatabaseService database,
CharacterIDProvider idFactory,
CharacterTemplateIDProvider templateIdFactory,
AccountIDProvider accountIdFactory, ClanIDProvider clanIdFactory) {
super(database, idFactory, templateIdFactory, accountIdFactory,
clanIdFactory);
}
}

View File

@@ -0,0 +1,36 @@
/*
* This file is part of l2jserver <l2jserver.com>.
*
* l2jserver 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.
*
* l2jserver 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 l2jserver. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.db.dao.h2;
import com.l2jserver.db.dao.CharacterFriendDAO;
import com.l2jserver.db.dao.jdbc.JDBCCharacterFriendDAO;
import com.l2jserver.model.id.object.provider.CharacterIDProvider;
import com.l2jserver.model.id.provider.FriendIDProvider;
import com.l2jserver.service.database.DatabaseService;
/**
* {@link CharacterFriendDAO} implementation for MySQL5
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class H2CharacterFriendDAO extends JDBCCharacterFriendDAO implements
CharacterFriendDAO {
public H2CharacterFriendDAO(DatabaseService database,
FriendIDProvider idProvider, CharacterIDProvider charIdProvider) {
super(database, idProvider, charIdProvider);
}
}

View File

@@ -0,0 +1,36 @@
/*
* This file is part of l2jserver <l2jserver.com>.
*
* l2jserver 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.
*
* l2jserver 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 l2jserver. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.db.dao.h2;
import com.l2jserver.db.dao.CharacterDAO;
import com.l2jserver.db.dao.ClanDAO;
import com.l2jserver.db.dao.jdbc.JDBCClanDAO;
import com.l2jserver.model.id.object.provider.CharacterIDProvider;
import com.l2jserver.model.id.object.provider.ClanIDProvider;
import com.l2jserver.service.database.DatabaseService;
/**
* {@link CharacterDAO} implementation for MySQL5
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class H2ClanDAO extends JDBCClanDAO implements ClanDAO {
public H2ClanDAO(DatabaseService database,
ClanIDProvider clanIdFactory, CharacterIDProvider idFactory) {
super(database, clanIdFactory, idFactory);
}
}

View File

@@ -0,0 +1,37 @@
/*
* This file is part of l2jserver <l2jserver.com>.
*
* l2jserver 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.
*
* l2jserver 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 l2jserver. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.db.dao.h2;
import com.l2jserver.db.dao.ItemDAO;
import com.l2jserver.db.dao.jdbc.JDBCItemDAO;
import com.l2jserver.model.id.object.provider.CharacterIDProvider;
import com.l2jserver.model.id.object.provider.ItemIDProvider;
import com.l2jserver.model.id.template.provider.ItemTemplateIDProvider;
import com.l2jserver.service.database.DatabaseService;
/**
* {@link ItemDAO} implementation for MySQL5
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class H2ItemDAO extends JDBCItemDAO implements ItemDAO {
public H2ItemDAO(DatabaseService database, ItemIDProvider idFactory,
ItemTemplateIDProvider templateIdFactory,
CharacterIDProvider charIdFactory) {
super(database, idFactory, templateIdFactory, charIdFactory);
}
}

View File

@@ -0,0 +1,36 @@
/*
* This file is part of l2jserver <l2jserver.com>.
*
* l2jserver 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.
*
* l2jserver 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 l2jserver. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.db.dao.h2;
import com.l2jserver.db.dao.CharacterDAO;
import com.l2jserver.db.dao.NPCDAO;
import com.l2jserver.db.dao.jdbc.JDBCNPCDAO;
import com.l2jserver.model.id.object.provider.NPCIDProvider;
import com.l2jserver.model.id.template.provider.NPCTemplateIDProvider;
import com.l2jserver.service.database.DatabaseService;
/**
* {@link CharacterDAO} implementation for MySQL5
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class H2NPCDAO extends JDBCNPCDAO implements NPCDAO {
public H2NPCDAO(DatabaseService database, NPCIDProvider idProvider,
NPCTemplateIDProvider templateIdProvider) {
super(database, idProvider, templateIdProvider);
}
}

View File

@@ -0,0 +1,48 @@
/*
* This file is part of l2jserver <l2jserver.com>.
*
* l2jserver 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.
*
* l2jserver 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 l2jserver. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.db.dao.jdbc;
import com.google.inject.Inject;
import com.l2jserver.model.Model;
import com.l2jserver.model.id.ID;
import com.l2jserver.service.database.AbstractDAO;
import com.l2jserver.service.database.DatabaseService;
import com.l2jserver.service.database.JDBCDatabaseService;
/**
* {@link AbstractDAO} for JDBC DAO implementation
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*
* @param <T>
* the object for the DAO
* @param <I>
* the object ID type
*/
public abstract class AbstractJDBCDAO<T extends Model<?>, I extends ID<?>>
extends AbstractDAO<T, I> {
/**
* The MySQL Database Service
*/
protected final JDBCDatabaseService database;
@Inject
protected AbstractJDBCDAO(DatabaseService database) {
super(database);
this.database = (JDBCDatabaseService) database;
}
}

View File

@@ -0,0 +1,420 @@
/*
* This file is part of l2jserver <l2jserver.com>.
*
* l2jserver 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.
*
* l2jserver 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 l2jserver. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.db.dao.jdbc;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
import java.util.List;
import com.google.inject.Inject;
import com.l2jserver.db.dao.CharacterDAO;
import com.l2jserver.model.id.AccountID;
import com.l2jserver.model.id.object.CharacterID;
import com.l2jserver.model.id.object.ClanID;
import com.l2jserver.model.id.object.provider.CharacterIDProvider;
import com.l2jserver.model.id.object.provider.ClanIDProvider;
import com.l2jserver.model.id.provider.AccountIDProvider;
import com.l2jserver.model.id.template.CharacterTemplateID;
import com.l2jserver.model.id.template.provider.CharacterTemplateIDProvider;
import com.l2jserver.model.template.CharacterTemplate;
import com.l2jserver.model.world.Actor.ActorRace;
import com.l2jserver.model.world.Actor.ActorSex;
import com.l2jserver.model.world.Clan;
import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.character.CharacterAppearance;
import com.l2jserver.model.world.character.CharacterAppearance.CharacterFace;
import com.l2jserver.model.world.character.CharacterAppearance.CharacterHairColor;
import com.l2jserver.model.world.character.CharacterAppearance.CharacterHairStyle;
import com.l2jserver.model.world.character.CharacterClass;
import com.l2jserver.service.database.DatabaseService;
import com.l2jserver.service.database.JDBCDatabaseService.CachedMapper;
import com.l2jserver.service.database.JDBCDatabaseService.InsertUpdateQuery;
import com.l2jserver.service.database.JDBCDatabaseService.Mapper;
import com.l2jserver.service.database.JDBCDatabaseService.SelectListQuery;
import com.l2jserver.service.database.JDBCDatabaseService.SelectSingleQuery;
import com.l2jserver.util.geometry.Point3D;
/**
* {@link CharacterDAO} implementation for JDBC
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class JDBCCharacterDAO extends
AbstractJDBCDAO<L2Character, CharacterID> implements CharacterDAO {
/**
* The {@link CharacterID} factory
*/
private final CharacterIDProvider idFactory;
/**
* The {@link CharacterTemplateID} factory
*/
private final CharacterTemplateIDProvider templateIdFactory;
/**
* The {@link AccountID} factory
*/
private final AccountIDProvider accountIdFactory;
/**
* The {@link ClanID} factory
*/
private final ClanIDProvider clanIdFactory;
/**
* Character table name
*/
public static final String TABLE = "character";
// FIELDS
public static final String CHAR_ID = "character_id";
public static final String ACCOUNT_ID = "account_id";
public static final String CLAN_ID = "clan_id";
public static final String NAME = "name";
public static final String RACE = "race";
public static final String CLASS = "class";
public static final String SEX = "sex";
public static final String LEVEL = "level";
public static final String EXPERIENCE = "experience";
public static final String SP = "sp";
public static final String HP = "hp";
public static final String MP = "mp";
public static final String CP = "cp";
public static final String POINT_X = "point_x";
public static final String POINT_Y = "point_y";
public static final String POINT_Z = "point_z";
public static final String POINT_ANGLE = "point_angle";
public static final String APPEARANCE_HAIR_STYLE = "appearance_hair_style";
public static final String APPEARANCE_HAIR_COLOR = "appearance_hair_color";
public static final String APPEARANCE_FACE = "apperance_face";
@Inject
public JDBCCharacterDAO(DatabaseService database,
final CharacterIDProvider idFactory,
CharacterTemplateIDProvider templateIdFactory,
AccountIDProvider accountIdFactory, ClanIDProvider clanIdFactory) {
super(database);
this.idFactory = idFactory;
this.templateIdFactory = templateIdFactory;
this.accountIdFactory = accountIdFactory;
this.clanIdFactory = clanIdFactory;
}
/**
* The mapper for {@link CharacterID}
*/
private final Mapper<CharacterID> idMapper = new Mapper<CharacterID>() {
@Override
public CharacterID map(ResultSet rs) throws SQLException {
return idFactory.createID(rs.getInt(CHAR_ID));
}
};
/**
* The {@link Mapper} for {@link L2Character}
*/
private final Mapper<L2Character> mapper = new CachedMapper<L2Character, CharacterID>(
database, idMapper) {
@Override
protected L2Character map(CharacterID id, ResultSet rs)
throws SQLException {
final CharacterClass charClass = CharacterClass.valueOf(rs
.getString(CLASS));
final CharacterTemplateID templateId = templateIdFactory
.createID(charClass.id);
final CharacterTemplate template = templateId.getTemplate();
final L2Character character = template.create();
character.setID(id);
character.setAccountID(accountIdFactory.createID(rs
.getString(ACCOUNT_ID)));
if (rs.getString(CLAN_ID) != null)
character.setClanID(clanIdFactory.createID(rs.getInt(CLAN_ID)));
character.setName(rs.getString(NAME));
character.setRace(ActorRace.valueOf(rs.getString(RACE)));
character.setCharacterClass(CharacterClass.valueOf(rs
.getString(CLASS)));
character.setSex(ActorSex.valueOf(rs.getString(SEX)));
character.setLevel(rs.getInt(LEVEL));
character.setExperience(rs.getLong(EXPERIENCE));
character.setSP(rs.getInt(SP));
character.setHP(rs.getDouble(HP));
character.setMP(rs.getDouble(MP));
character.setCP(rs.getDouble(CP));
character.setPoint(Point3D.fromXYZA(rs.getInt(POINT_X),
rs.getInt(POINT_Y), rs.getInt(POINT_Z),
rs.getDouble(POINT_ANGLE)));
// appearance
character.getAppearance().setHairStyle(
CharacterHairStyle.valueOf(rs
.getString(APPEARANCE_HAIR_STYLE)));
character.getAppearance().setHairColor(
CharacterHairColor.valueOf(rs
.getString(APPEARANCE_HAIR_COLOR)));
character.getAppearance().setFace(
CharacterFace.valueOf(rs.getString(APPEARANCE_FACE)));
return character;
}
};
@Override
public L2Character select(final CharacterID id) {
return database.query(new SelectSingleQuery<L2Character>() {
@Override
protected String query() {
return "SELECT * FROM `" + TABLE + "` WHERE `" + CHAR_ID
+ "` = ?";
}
@Override
protected void parametize(PreparedStatement st) throws SQLException {
st.setInt(1, id.getID());
}
@Override
protected Mapper<L2Character> mapper() {
return mapper;
}
});
}
@Override
public void load(final Clan clan) {
clan.getMembers().load(
database.query(new SelectListQuery<CharacterID>() {
@Override
protected String query() {
return "SELECT `" + CHAR_ID + "` FROM `" + TABLE
+ "` WHERE `" + CLAN_ID + "` = ?";
}
@Override
protected void parametize(PreparedStatement st)
throws SQLException {
st.setInt(1, clan.getID().getID());
}
@Override
protected Mapper<CharacterID> mapper() {
return idMapper;
}
}));
}
@Override
public L2Character selectByName(final String name) {
return database.query(new SelectSingleQuery<L2Character>() {
@Override
protected String query() {
return "SELECT * FROM `" + TABLE + "` WHERE `" + NAME + "` = ?";
}
@Override
protected void parametize(PreparedStatement st) throws SQLException {
st.setString(1, name);
}
@Override
protected Mapper<L2Character> mapper() {
return mapper;
}
});
}
@Override
public List<L2Character> selectByAccount(final AccountID account) {
return database.query(new SelectListQuery<L2Character>() {
@Override
protected String query() {
return "SELECT * FROM `" + TABLE + "` WHERE `" + ACCOUNT_ID
+ "` = ?";
}
@Override
protected void parametize(PreparedStatement st) throws SQLException {
st.setString(1, account.getID());
}
@Override
protected Mapper<L2Character> mapper() {
return mapper;
}
});
}
@Override
public List<CharacterID> selectIDs() {
return database.query(new SelectListQuery<CharacterID>() {
@Override
protected String query() {
return "SELECT `" + CHAR_ID + "` FROM `" + TABLE + "`";
}
@Override
protected Mapper<CharacterID> mapper() {
return idMapper;
}
});
}
@Override
public boolean insert(L2Character character) {
return database.query(new InsertUpdateQuery<L2Character>(character) {
@Override
protected String query() {
return "INSERT INTO `" + TABLE + "` (`" + CHAR_ID + "`,`"
+ ACCOUNT_ID + "`,`" + CLAN_ID + "`,`" + NAME + "`,`"
+ RACE + "`,`" + CLASS + "`,`" + SEX + "`,`" + LEVEL
+ "`,`" + EXPERIENCE + "`,`" + SP + "`,`" + HP + "`,`"
+ MP + "`,`" + CP + "`,`" + POINT_X + "`,`" + POINT_Y
+ "`,`" + POINT_Z + "`,`" + POINT_ANGLE + "`,`"
+ APPEARANCE_HAIR_STYLE + "`,`" + APPEARANCE_HAIR_COLOR
+ "`,`" + APPEARANCE_FACE
+ "`) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
}
@Override
protected void parametize(PreparedStatement st,
L2Character character) throws SQLException {
final CharacterAppearance appearance = character
.getAppearance();
int i = 1;
st.setInt(i++, character.getID().getID());
st.setString(i++, character.getAccountID().getID());
if (character.getClanID() != null)
st.setInt(i++, character.getClanID().getID());
else
st.setNull(i++, Types.INTEGER);
st.setString(i++, character.getName());
st.setString(i++, character.getRace().name());
st.setString(i++, character.getCharacterClass().name());
st.setString(i++, character.getSex().name());
st.setInt(i++, character.getLevel());
st.setLong(i++, character.getExperience());
st.setInt(i++, character.getSP());
st.setDouble(i++, character.getHP());
st.setDouble(i++, character.getMP());
st.setDouble(i++, character.getCP());
st.setInt(i++, character.getPoint().getX());
st.setInt(i++, character.getPoint().getY());
st.setInt(i++, character.getPoint().getZ());
st.setDouble(i++, character.getPoint().getAngle());
// appearance
st.setString(i++, appearance.getHairStyle().name());
st.setString(i++, appearance.getHairColor().name());
st.setString(i++, appearance.getFace().name());
}
}) > 0;
}
@Override
public boolean update(L2Character character) {
return database.query(new InsertUpdateQuery<L2Character>(character) {
@Override
protected String query() {
return "UPDATE `" + TABLE + "` SET " + ACCOUNT_ID + "` = ?,`"
+ CLAN_ID + "` = ?,`" + NAME + "` = ?,`" + RACE
+ "` = ?,`" + CLASS + "` = ?,`" + SEX + "` = ?,`"
+ LEVEL + "` = ?,`" + EXPERIENCE + "` = ?,`" + SP
+ "` = ?,`" + HP + "` = ?,`" + MP + "` = ?,`" + CP
+ "` = ?,`" + POINT_X + "` = ?,`" + POINT_Y + "` = ?,`"
+ POINT_Z + "` = ?,`" + POINT_ANGLE + "` = ?,`"
+ APPEARANCE_HAIR_STYLE + "` = ?,`"
+ APPEARANCE_HAIR_COLOR + "` = ?,`" + APPEARANCE_FACE
+ "` = ? WHERE `" + CHAR_ID + "` = ?";
}
@Override
protected void parametize(PreparedStatement st,
L2Character character) throws SQLException {
final CharacterAppearance appearance = character
.getAppearance();
int i = 1;
// SET
st.setString(i++, character.getAccountID().getID());
if (character.getClanID() != null)
st.setInt(i++, character.getClanID().getID());
else
st.setNull(i++, Types.INTEGER);
st.setString(i++, character.getName());
st.setString(i++, character.getRace().name());
st.setString(i++, character.getCharacterClass().name());
st.setString(i++, character.getSex().name());
st.setInt(i++, character.getLevel());
st.setLong(i++, character.getExperience());
st.setInt(i++, character.getSP());
st.setDouble(i++, character.getHP());
st.setDouble(i++, character.getMP());
st.setDouble(i++, character.getCP());
// position
st.setInt(i++, character.getPoint().getX());
st.setInt(i++, character.getPoint().getY());
st.setInt(i++, character.getPoint().getZ());
st.setDouble(i++, character.getPoint().getAngle());
// appearance
st.setString(i++, appearance.getHairStyle().name());
st.setString(i++, appearance.getHairColor().name());
st.setString(i++, appearance.getFace().name());
// WHERE
st.setInt(i++, character.getID().getID());
}
}) > 0;
}
@Override
public boolean delete(L2Character character) {
return database.query(new InsertUpdateQuery<L2Character>(character) {
@Override
protected String query() {
return "DELETE FROM `" + TABLE + "` WHERE `" + CHAR_ID
+ "` = ?";
}
@Override
protected void parametize(PreparedStatement st,
L2Character character) throws SQLException {
st.setInt(1, character.getID().getID());
}
}) > 0;
}
}

View File

@@ -0,0 +1,222 @@
/*
* This file is part of l2jserver <l2jserver.com>.
*
* l2jserver 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.
*
* l2jserver 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 l2jserver. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.db.dao.jdbc;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import com.google.inject.Inject;
import com.l2jserver.db.dao.CharacterFriendDAO;
import com.l2jserver.model.game.CharacterFriend;
import com.l2jserver.model.id.FriendID;
import com.l2jserver.model.id.object.CharacterID;
import com.l2jserver.model.id.object.provider.CharacterIDProvider;
import com.l2jserver.model.id.provider.FriendIDProvider;
import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.character.CharacterFriendList;
import com.l2jserver.service.database.DatabaseService;
import com.l2jserver.service.database.JDBCDatabaseService.CachedMapper;
import com.l2jserver.service.database.JDBCDatabaseService.InsertUpdateQuery;
import com.l2jserver.service.database.JDBCDatabaseService.Mapper;
import com.l2jserver.service.database.JDBCDatabaseService.SelectListQuery;
import com.l2jserver.service.database.JDBCDatabaseService.SelectSingleQuery;
/**
* {@link CharacterFriendDAO} implementation for JDBC
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class JDBCCharacterFriendDAO extends
AbstractJDBCDAO<CharacterFriend, FriendID> implements
CharacterFriendDAO {
/**
* The {@link FriendID} provider
*/
private final FriendIDProvider idProvider;
/**
* The {@link CharacterID} provider
*/
private final CharacterIDProvider charIdProvider;
/**
* Character table name
*/
public static final String TABLE = "character_friend";
// FIELDS
public static final String CHAR_ID = JDBCCharacterDAO.CHAR_ID;
public static final String CHAR_ID_FRIEND = JDBCCharacterDAO.CHAR_ID
+ "_friend";
@Inject
public JDBCCharacterFriendDAO(DatabaseService database,
final FriendIDProvider idProvider,
CharacterIDProvider charIdProvider) {
super(database);
this.idProvider = idProvider;
this.charIdProvider = charIdProvider;
}
/**
* The {@link Mapper} for {@link FriendID}
*/
private final Mapper<FriendID> idMapper = new Mapper<FriendID>() {
@Override
public FriendID map(ResultSet rs) throws SQLException {
final CharacterID characterId = charIdProvider.createID(rs
.getInt(CHAR_ID));
final CharacterID friendId = charIdProvider.createID(rs
.getInt(CHAR_ID_FRIEND));
return idProvider.createID(characterId, friendId);
}
};
/**
* The {@link Mapper} for {@link CharacterFriend}
*/
private final Mapper<CharacterFriend> mapper = new CachedMapper<CharacterFriend, FriendID>(
database, idMapper) {
@Override
protected CharacterFriend map(FriendID id, ResultSet rs)
throws SQLException {
return new CharacterFriend(id);
}
};
@Override
public CharacterFriend select(final FriendID id) {
return database.query(new SelectSingleQuery<CharacterFriend>() {
@Override
protected String query() {
return "SELECT * FROM `" + TABLE + "` WHERE `" + CHAR_ID
+ "` = ? AND `" + CHAR_ID_FRIEND + "` = ?";
}
@Override
protected void parametize(PreparedStatement st) throws SQLException {
st.setInt(1, id.getID1().getID());
st.setInt(2, id.getID2().getID());
}
@Override
protected Mapper<CharacterFriend> mapper() {
return mapper;
}
});
}
@Override
public void load(final L2Character character) {
final List<CharacterFriend> list = database
.query(new SelectListQuery<CharacterFriend>() {
@Override
protected String query() {
return "SELECT * FROM `" + TABLE + "` WHERE `"
+ CHAR_ID + "` = ?";
}
@Override
protected void parametize(PreparedStatement st)
throws SQLException {
st.setInt(1, character.getID().getID());
}
@Override
protected Mapper<CharacterFriend> mapper() {
return mapper;
}
});
character.getFriendList().load(list);
}
@Override
public List<FriendID> selectIDs() {
return database.query(new SelectListQuery<FriendID>() {
@Override
protected String query() {
return "SELECT * FROM `" + TABLE + "`";
}
@Override
protected Mapper<FriendID> mapper() {
return idMapper;
}
});
}
@Override
public boolean insert(CharacterFriend friend) {
return database.query(new InsertUpdateQuery<CharacterFriend>(friend) {
@Override
protected String query() {
return "INSERT INTO `" + TABLE + "` (`" + CHAR_ID + "`,`"
+ CHAR_ID_FRIEND + "`) VALUES(?,?)";
}
@Override
protected void parametize(PreparedStatement st,
CharacterFriend friend) throws SQLException {
st.setInt(1, friend.getCharacterID().getID());
st.setInt(2, friend.getFriendID().getID());
}
}) > 0;
}
@Override
public boolean update(CharacterFriend friend) {
// it is not possible update friend objects, because they are only a ID
// pair and IDs are immutable
return false;
}
@Override
public boolean delete(CharacterFriend friend) {
return database.query(new InsertUpdateQuery<CharacterFriend>(friend) {
@Override
protected String query() {
return "DELETE FROM `" + TABLE + "` WHERE `" + CHAR_ID
+ "` = ?,`" + CHAR_ID_FRIEND + "` = ?";
}
@Override
protected void parametize(PreparedStatement st,
CharacterFriend friend) throws SQLException {
st.setInt(1, friend.getCharacterID().getID());
st.setInt(2, friend.getFriendID().getID());
}
}) > 0;
}
@Override
public boolean save(final CharacterFriendList friends) {
for (final CharacterFriend friend : friends) {
if (!save(friend))
return false;
}
return true;
}
@Override
public boolean delete(final CharacterFriendList friends) {
for (final CharacterFriend friend : friends) {
if (!delete(friend))
return false;
}
return true;
}
}

View File

@@ -0,0 +1,171 @@
/*
* This file is part of l2jserver <l2jserver.com>.
*
* l2jserver 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.
*
* l2jserver 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 l2jserver. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.db.dao.jdbc;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import com.google.inject.Inject;
import com.l2jserver.db.dao.CharacterDAO;
import com.l2jserver.db.dao.ClanDAO;
import com.l2jserver.model.id.object.CharacterID;
import com.l2jserver.model.id.object.ClanID;
import com.l2jserver.model.id.object.provider.CharacterIDProvider;
import com.l2jserver.model.id.object.provider.ClanIDProvider;
import com.l2jserver.model.world.Clan;
import com.l2jserver.service.database.DatabaseService;
import com.l2jserver.service.database.JDBCDatabaseService.CachedMapper;
import com.l2jserver.service.database.JDBCDatabaseService.InsertUpdateQuery;
import com.l2jserver.service.database.JDBCDatabaseService.Mapper;
import com.l2jserver.service.database.JDBCDatabaseService.SelectListQuery;
import com.l2jserver.service.database.JDBCDatabaseService.SelectSingleQuery;
/**
* {@link CharacterDAO} implementation for JDBC
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class JDBCClanDAO extends AbstractJDBCDAO<Clan, ClanID> implements
ClanDAO {
/**
* The {@link ClanID} factory
*/
private final ClanIDProvider idFactory;
/**
* The {@link CharacterID} factory
*/
@SuppressWarnings("unused")
private final CharacterIDProvider charIdFactory;
/**
* Character table name
*/
public static final String TABLE = "clan";
// FIELDS
public static final String CLAN_ID = "clan_id";
public static final String CHAR_ID_LEADER = "character_id_leader";
@Inject
public JDBCClanDAO(DatabaseService database,
ClanIDProvider clanIdFactory, final CharacterIDProvider idFactory) {
super(database);
this.idFactory = clanIdFactory;
this.charIdFactory = idFactory;
}
/**
* The {@link Mapper} for {@link ClanID}
*/
private final Mapper<ClanID> idMapper = new Mapper<ClanID>() {
@Override
public ClanID map(ResultSet rs) throws SQLException {
return idFactory.createID(rs.getInt(CLAN_ID));
}
};
/**
* The {@link Mapper} for {@link Clan}
*/
private final Mapper<Clan> mapper = new CachedMapper<Clan, ClanID>(
database, idMapper) {
@Override
protected Clan map(ClanID id, ResultSet rs) throws SQLException {
final Clan clan = new Clan();
clan.setID(id);
return clan;
}
};
@Override
public Clan select(final ClanID id) {
return database.query(new SelectSingleQuery<Clan>() {
@Override
protected String query() {
return "SELECT * FROM `" + TABLE + "` WHERE `" + CLAN_ID
+ "` = ?";
}
@Override
protected void parametize(PreparedStatement st) throws SQLException {
st.setInt(1, id.getID());
}
@Override
protected Mapper<Clan> mapper() {
return mapper;
}
});
}
@Override
public List<ClanID> selectIDs() {
return database.query(new SelectListQuery<ClanID>() {
@Override
protected String query() {
return "SELECT * FROM `" + TABLE + "`";
}
@Override
protected Mapper<ClanID> mapper() {
return idMapper;
}
});
}
@Override
public boolean insert(Clan clan) {
return database.query(new InsertUpdateQuery<Clan>(clan) {
@Override
protected String query() {
return "INSERT INTO `" + TABLE + "` (`" + CLAN_ID
+ "`) VALUES(?)";
}
@Override
protected void parametize(PreparedStatement st, Clan clan)
throws SQLException {
int i = 1;
st.setInt(i++, clan.getID().getID());
}
}) > 0;
}
@Override
public boolean update(Clan clan) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean delete(Clan clan) {
return database.query(new InsertUpdateQuery<Clan>(clan) {
@Override
protected String query() {
return "DELETE FROM `" + TABLE + "` WHERE `" + CLAN_ID
+ "` = ?";
}
@Override
protected void parametize(PreparedStatement st, Clan clan)
throws SQLException {
st.setInt(1, clan.getID().getID());
}
}) > 0;
}
}

View File

@@ -0,0 +1,223 @@
/*
* This file is part of l2jserver <l2jserver.com>.
*
* l2jserver 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.
*
* l2jserver 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 l2jserver. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.db.dao.jdbc;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import com.google.inject.Inject;
import com.l2jserver.db.dao.ItemDAO;
import com.l2jserver.model.id.object.CharacterID;
import com.l2jserver.model.id.object.ItemID;
import com.l2jserver.model.id.object.provider.CharacterIDProvider;
import com.l2jserver.model.id.object.provider.ItemIDProvider;
import com.l2jserver.model.id.template.ItemTemplateID;
import com.l2jserver.model.id.template.provider.ItemTemplateIDProvider;
import com.l2jserver.model.template.ItemTemplate;
import com.l2jserver.model.world.Item;
import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.character.CharacterInventory;
import com.l2jserver.model.world.character.CharacterInventory.InventoryLocation;
import com.l2jserver.model.world.character.CharacterInventory.InventoryPaperdoll;
import com.l2jserver.service.database.DatabaseService;
import com.l2jserver.service.database.JDBCDatabaseService.CachedMapper;
import com.l2jserver.service.database.JDBCDatabaseService.InsertUpdateQuery;
import com.l2jserver.service.database.JDBCDatabaseService.Mapper;
import com.l2jserver.service.database.JDBCDatabaseService.SelectListQuery;
import com.l2jserver.service.database.JDBCDatabaseService.SelectSingleQuery;
import com.l2jserver.util.geometry.Coordinate;
/**
* {@link ItemDAO} implementation for JDBC
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class JDBCItemDAO extends AbstractJDBCDAO<Item, ItemID> implements
ItemDAO {
/**
* The {@link ItemID} factory
*/
private final ItemIDProvider idFactory;
/**
* The {@link ItemTemplateID} factory
*/
private final ItemTemplateIDProvider templateIdFactory;
/**
* The {@link CharacterID} factory
*/
private final CharacterIDProvider charIdFactory;
/**
* Character table name
*/
public static final String TABLE = "item";
// FIELDS
public static final String ITEM_ID = "item_id";
public static final String TEMPLATE_ID = "template_id";
public static final String CHAR_ID = JDBCCharacterDAO.CHAR_ID;
public static final String LOCATION = "location";
public static final String PAPERDOLL = "paperdoll";
public static final String COUNT = "count";
public static final String COORD_X = "coord_x";
public static final String COORD_Y = "coord_y";
public static final String COORD_Z = "coord_z";
@Inject
public JDBCItemDAO(DatabaseService database,
final ItemIDProvider idFactory,
ItemTemplateIDProvider templateIdFactory,
CharacterIDProvider charIdFactory) {
super(database);
this.idFactory = idFactory;
this.templateIdFactory = templateIdFactory;
this.charIdFactory = charIdFactory;
}
/**
* The {@link Mapper} for {@link ItemID}
*/
private final Mapper<ItemID> idMapper = new Mapper<ItemID>() {
@Override
public ItemID map(ResultSet rs) throws SQLException {
return idFactory.createID(rs.getInt(ITEM_ID));
}
};
/**
* The {@link Mapper} instance
*/
private final Mapper<Item> mapper = new CachedMapper<Item, ItemID>(
database, idMapper) {
@Override
public Item map(ItemID id, ResultSet rs) throws SQLException {
final ItemTemplateID templateId = templateIdFactory.createID(rs
.getInt(TEMPLATE_ID));
final ItemTemplate template = templateId.getTemplate();
final Item item = template.create();
item.setID(id);
if (rs.getObject(CHAR_ID) != null)
item.setOwnerID(charIdFactory.createID(rs.getInt(CHAR_ID)));
if (rs.getObject(LOCATION) != null)
item.setLocation(InventoryLocation.valueOf(rs
.getString(LOCATION)));
if (rs.getObject(PAPERDOLL) != null)
item.setPaperdoll(InventoryPaperdoll.valueOf(rs
.getString(PAPERDOLL)));
item.setCount(rs.getInt(COUNT));
if (rs.getObject(COORD_X) != null && rs.getObject(COORD_Y) != null
&& rs.getObject(COORD_Z) != null)
item.setPosition(Coordinate.fromXYZ(rs.getInt(COORD_X),
rs.getInt(COORD_Y), rs.getInt(COORD_Z)));
return item;
}
};
@Override
public Item select(final ItemID id) {
return database.query(new SelectSingleQuery<Item>() {
@Override
protected String query() {
return "SELECT * FROM `" + TABLE + "` WHERE `" + ITEM_ID
+ "` = ?";
}
@Override
protected void parametize(PreparedStatement st) throws SQLException {
st.setInt(1, id.getID());
}
@Override
protected Mapper<Item> mapper() {
return mapper;
}
});
}
@Override
public int loadInventory(final L2Character character) {
final CharacterInventory inventory = character.getInventory();
final List<Item> items = database.query(new SelectListQuery<Item>() {
@Override
protected String query() {
return "SELECT * FROM `" + TABLE + "` WHERE `" + CHAR_ID
+ "` = ?";
}
@Override
protected void parametize(PreparedStatement st) throws SQLException {
st.setInt(1, character.getID().getID());
}
@Override
protected Mapper<Item> mapper() {
return mapper;
}
});
inventory.load(items);
return items.size();
}
@Override
public List<ItemID> selectIDs() {
return database.query(new SelectListQuery<ItemID>() {
@Override
protected String query() {
return "SELECT `" + ITEM_ID + "` FROM `" + TABLE + "`";
}
@Override
protected Mapper<ItemID> mapper() {
return idMapper;
}
});
}
@Override
public boolean insert(Item item) {
throw new UnsupportedOperationException(
"Saving items is not yet implemented!");
}
@Override
public boolean update(Item item) {
return false;
}
@Override
public boolean delete(Item item) {
return database.query(new InsertUpdateQuery<Item>(item) {
@Override
protected String query() {
return "DELETE FROM `" + TABLE + "` WHERE `" + ITEM_ID
+ "` = ?";
}
@Override
protected void parametize(PreparedStatement st, Item item)
throws SQLException {
st.setInt(1, item.getID().getID());
}
}) > 0;
}
}

View File

@@ -0,0 +1,267 @@
/*
* This file is part of l2jserver <l2jserver.com>.
*
* l2jserver 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.
*
* l2jserver 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 l2jserver. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.db.dao.jdbc;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.inject.Inject;
import com.l2jserver.db.dao.CharacterDAO;
import com.l2jserver.db.dao.NPCDAO;
import com.l2jserver.model.id.object.NPCID;
import com.l2jserver.model.id.object.provider.NPCIDProvider;
import com.l2jserver.model.id.template.NPCTemplateID;
import com.l2jserver.model.id.template.provider.NPCTemplateIDProvider;
import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC;
import com.l2jserver.service.database.DatabaseService;
import com.l2jserver.service.database.JDBCDatabaseService.CachedMapper;
import com.l2jserver.service.database.JDBCDatabaseService.InsertUpdateQuery;
import com.l2jserver.service.database.JDBCDatabaseService.Mapper;
import com.l2jserver.service.database.JDBCDatabaseService.SelectListQuery;
import com.l2jserver.service.database.JDBCDatabaseService.SelectSingleQuery;
import com.l2jserver.util.geometry.Point3D;
/**
* {@link CharacterDAO} implementation for JDBC
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class JDBCNPCDAO extends AbstractJDBCDAO<NPC, NPCID> implements
NPCDAO {
private final Logger log = LoggerFactory.getLogger(this.getClass());
/**
* The {@link NPCID} provider
*/
private final NPCIDProvider idProvider;
/**
* The {@link NPCTemplateID} provider
*/
private final NPCTemplateIDProvider templateIdProvider;
/**
* Character table name
*/
public static final String TABLE = "npc";
// FIELDS
public static final String NPC_ID = "npc_id";
public static final String NPC_TEMPLATE_ID = "npc_template_id";
public static final String POINT_X = "point_x";
public static final String POINT_Y = "point_y";
public static final String POINT_Z = "point_z";
public static final String POINT_ANGLE = "point_angle";
@Inject
public JDBCNPCDAO(DatabaseService database,
final NPCIDProvider idProvider,
NPCTemplateIDProvider templateIdProvider) {
super(database);
this.idProvider = idProvider;
this.templateIdProvider = templateIdProvider;
}
/**
* The {@link Mapper} for {@link NPCID}
*/
private final Mapper<NPCID> idMapper = new Mapper<NPCID>() {
@Override
public NPCID map(ResultSet rs) throws SQLException {
if (rs.getString(NPC_ID) == null)
return null;
return idProvider.createID(rs.getInt(NPC_ID));
}
};
/**
* The {@link Mapper} for {@link NPC}
*/
private final Mapper<NPC> mapper = new CachedMapper<NPC, NPCID>(database,
idMapper) {
@Override
protected NPC map(NPCID id, ResultSet rs) throws SQLException {
NPCTemplateID templateId = templateIdProvider.createID(rs
.getInt(NPC_TEMPLATE_ID));
NPCTemplate template = templateId.getTemplate();
if (template == null) {
// set default npc instance, for now!
// RoxxyGatekeeperTemplate - 30006
log.warn("No template found for {}", templateId);
return null;
}
final NPC npc = template.create();
npc.setID(id);
npc.setPoint(Point3D.fromXYZA(rs.getInt(POINT_X), rs.getInt(POINT_Y),
rs.getInt(POINT_Z), rs.getDouble(POINT_ANGLE)));
return npc;
}
};
@Override
public NPC select(final NPCID id) {
return database.query(new SelectSingleQuery<NPC>() {
@Override
protected String query() {
return "SELECT * FROM `" + TABLE + "` WHERE `" + NPC_ID
+ "` = ?";
}
@Override
protected void parametize(PreparedStatement st) throws SQLException {
st.setInt(1, id.getID());
}
@Override
protected Mapper<NPC> mapper() {
return mapper;
}
});
}
@Override
public List<NPC> loadAll() {
return database.query(new SelectListQuery<NPC>() {
@Override
protected String query() {
return "SELECT * FROM `" + TABLE + "`";
}
@Override
protected Mapper<NPC> mapper() {
return mapper;
}
});
}
@Override
public List<NPC> selectByTemplate(final NPCTemplateID template) {
return database.query(new SelectListQuery<NPC>() {
@Override
protected String query() {
return "SELECT * FROM `" + TABLE + "` WHERE `"
+ NPC_TEMPLATE_ID + "` = ?";
}
@Override
protected void parametize(PreparedStatement st) throws SQLException {
st.setInt(1, template.getID());
}
@Override
protected Mapper<NPC> mapper() {
return mapper;
}
});
}
@Override
public List<NPCID> selectIDs() {
return database.query(new SelectListQuery<NPCID>() {
@Override
protected String query() {
return "SELECT `" + NPC_ID + "` FROM `" + TABLE + "`";
}
@Override
protected Mapper<NPCID> mapper() {
return idMapper;
}
});
}
@Override
public boolean insert(NPC npc) {
return database.query(new InsertUpdateQuery<NPC>(npc) {
@Override
protected String query() {
return "INSERT INTO `" + TABLE + "` (`" + NPC_ID + "`,`"
+ NPC_TEMPLATE_ID + "`,`" + POINT_X + "`,`" + POINT_Y
+ "`,`" + POINT_Z + "`,`" + POINT_ANGLE
+ "`) VALUES(?,?,?,?,?,?)";
}
@Override
protected void parametize(PreparedStatement st, NPC npc)
throws SQLException {
int i = 1;
st.setInt(i++, npc.getID().getID());
st.setInt(i++, npc.getTemplateID().getID());
st.setInt(i++, npc.getPoint().getX());
st.setInt(i++, npc.getPoint().getY());
st.setInt(i++, npc.getPoint().getZ());
st.setDouble(i++, npc.getPoint().getAngle());
}
}) > 0;
}
@Override
public boolean update(NPC npc) {
return database.query(new InsertUpdateQuery<NPC>(npc) {
@Override
protected String query() {
return "UPDATE `" + TABLE + "` SET " + NPC_TEMPLATE_ID
+ "` = ?,`" + POINT_X + "` = ?,`" + POINT_Y + "` = ?,`"
+ POINT_Z + "` = ?,`" + POINT_ANGLE + "` = ? WHERE `"
+ NPC_ID + "` = ?";
}
@Override
protected void parametize(PreparedStatement st, NPC npc)
throws SQLException {
int i = 1;
// SET
st.setInt(i++, npc.getTemplateID().getID());
st.setInt(i++, npc.getPoint().getX());
st.setInt(i++, npc.getPoint().getY());
st.setInt(i++, npc.getPoint().getZ());
st.setDouble(i++, npc.getPoint().getAngle());
// WHERE
st.setInt(i++, npc.getID().getID());
}
}) > 0;
}
@Override
public boolean delete(NPC npc) {
return database.query(new InsertUpdateQuery<NPC>(npc) {
@Override
protected String query() {
return "DELETE FROM `" + TABLE + "` WHERE `" + NPC_ID + "` = ?";
}
@Override
protected void parametize(PreparedStatement st, NPC npc)
throws SQLException {
st.setInt(1, npc.getID().getID());
}
}) > 0;
}
}

View File

@@ -0,0 +1,41 @@
/*
* This file is part of l2jserver <l2jserver.com>.
*
* l2jserver 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.
*
* l2jserver 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 l2jserver. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.db.dao.mysql5;
import com.l2jserver.db.dao.CharacterDAO;
import com.l2jserver.db.dao.jdbc.JDBCCharacterDAO;
import com.l2jserver.model.id.object.provider.CharacterIDProvider;
import com.l2jserver.model.id.object.provider.ClanIDProvider;
import com.l2jserver.model.id.provider.AccountIDProvider;
import com.l2jserver.model.id.template.provider.CharacterTemplateIDProvider;
import com.l2jserver.service.database.DatabaseService;
/**
* {@link CharacterDAO} implementation for MySQL5
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class MySQL5CharacterDAO extends JDBCCharacterDAO implements
CharacterDAO {
public MySQL5CharacterDAO(DatabaseService database,
CharacterIDProvider idFactory,
CharacterTemplateIDProvider templateIdFactory,
AccountIDProvider accountIdFactory, ClanIDProvider clanIdFactory) {
super(database, idFactory, templateIdFactory, accountIdFactory,
clanIdFactory);
}
}

View File

@@ -0,0 +1,36 @@
/*
* This file is part of l2jserver <l2jserver.com>.
*
* l2jserver 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.
*
* l2jserver 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 l2jserver. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.db.dao.mysql5;
import com.l2jserver.db.dao.CharacterFriendDAO;
import com.l2jserver.db.dao.jdbc.JDBCCharacterFriendDAO;
import com.l2jserver.model.id.object.provider.CharacterIDProvider;
import com.l2jserver.model.id.provider.FriendIDProvider;
import com.l2jserver.service.database.DatabaseService;
/**
* {@link CharacterFriendDAO} implementation for MySQL5
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class MySQL5CharacterFriendDAO extends JDBCCharacterFriendDAO implements
CharacterFriendDAO {
public MySQL5CharacterFriendDAO(DatabaseService database,
FriendIDProvider idProvider, CharacterIDProvider charIdProvider) {
super(database, idProvider, charIdProvider);
}
}

View File

@@ -0,0 +1,36 @@
/*
* This file is part of l2jserver <l2jserver.com>.
*
* l2jserver 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.
*
* l2jserver 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 l2jserver. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.db.dao.mysql5;
import com.l2jserver.db.dao.CharacterDAO;
import com.l2jserver.db.dao.ClanDAO;
import com.l2jserver.db.dao.jdbc.JDBCClanDAO;
import com.l2jserver.model.id.object.provider.CharacterIDProvider;
import com.l2jserver.model.id.object.provider.ClanIDProvider;
import com.l2jserver.service.database.DatabaseService;
/**
* {@link CharacterDAO} implementation for MySQL5
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class MySQL5ClanDAO extends JDBCClanDAO implements ClanDAO {
public MySQL5ClanDAO(DatabaseService database,
ClanIDProvider clanIdFactory, CharacterIDProvider idFactory) {
super(database, clanIdFactory, idFactory);
}
}

View File

@@ -0,0 +1,37 @@
/*
* This file is part of l2jserver <l2jserver.com>.
*
* l2jserver 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.
*
* l2jserver 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 l2jserver. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.db.dao.mysql5;
import com.l2jserver.db.dao.ItemDAO;
import com.l2jserver.db.dao.jdbc.JDBCItemDAO;
import com.l2jserver.model.id.object.provider.CharacterIDProvider;
import com.l2jserver.model.id.object.provider.ItemIDProvider;
import com.l2jserver.model.id.template.provider.ItemTemplateIDProvider;
import com.l2jserver.service.database.DatabaseService;
/**
* {@link ItemDAO} implementation for MySQL5
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class MySQL5ItemDAO extends JDBCItemDAO implements ItemDAO {
public MySQL5ItemDAO(DatabaseService database, ItemIDProvider idFactory,
ItemTemplateIDProvider templateIdFactory,
CharacterIDProvider charIdFactory) {
super(database, idFactory, templateIdFactory, charIdFactory);
}
}

View File

@@ -0,0 +1,36 @@
/*
* This file is part of l2jserver <l2jserver.com>.
*
* l2jserver 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.
*
* l2jserver 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 l2jserver. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.db.dao.mysql5;
import com.l2jserver.db.dao.CharacterDAO;
import com.l2jserver.db.dao.NPCDAO;
import com.l2jserver.db.dao.jdbc.JDBCNPCDAO;
import com.l2jserver.model.id.object.provider.NPCIDProvider;
import com.l2jserver.model.id.template.provider.NPCTemplateIDProvider;
import com.l2jserver.service.database.DatabaseService;
/**
* {@link CharacterDAO} implementation for MySQL5
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class MySQL5NPCDAO extends JDBCNPCDAO implements NPCDAO {
public MySQL5NPCDAO(DatabaseService database, NPCIDProvider idProvider,
NPCTemplateIDProvider templateIdProvider) {
super(database, idProvider, templateIdProvider);
}
}