Skip to content

Commit

Permalink
More database conversions, also more todo items added and commented o…
Browse files Browse the repository at this point in the history
…ut DBDrop command as this needs to be implmented in a fluent hibernate manner
  • Loading branch information
jaddie committed Jul 20, 2013
1 parent 4fd777b commit bed6236
Show file tree
Hide file tree
Showing 18 changed files with 219 additions and 120 deletions.
15 changes: 9 additions & 6 deletions Services/WCell.RealmServer/Commands/DBCommands.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using WCell.Core.Database;
using WCell.Util.Commands;
using HibernateCfg = NHibernate.Cfg.Configuration;
using WCell.Intercommunication.DataTypes;
using System;

namespace WCell.RealmServer.Commands
{
Expand Down Expand Up @@ -31,9 +31,10 @@ protected override void Initialize()

public override void Process(CmdTrigger<RealmServerCmdArgs> trigger)
{
trigger.Reply("Recreating Database Schema...");
DatabaseUtil.CreateSchema();
trigger.Reply("Done.");
throw new NotImplementedException("Needs re-implementing as per database rewrite");
/*trigger.Reply("Recreating Database Schema...");
//DatabaseUtil.CreateSchema(); TODO: Database: Re-implement
trgger.Reply("Done.");*/
}
}

Expand All @@ -48,13 +49,15 @@ protected override void Initialize()

public override void Process(CmdTrigger<RealmServerCmdArgs> trigger)
{
var settings = DatabaseUtil.Settings;
throw new NotImplementedException("Needs re-implementing as per database rewrite");
//TODO: Database: Re-implement
/*var settings = DatabaseUtil.Settings;
var session = DatabaseUtil.Session;
trigger.Reply("DB Provider: " + settings.Dialect.GetType().Name);
trigger.Reply(" State: " + session.Connection.State);
trigger.Reply(" Database: " + session.Connection.Database);
trigger.Reply(" Connection String: " + session.Connection.ConnectionString);
trigger.Reply(" Connection String: " + session.Connection.ConnectionString);*/
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
using System;
using Castle.ActiveRecord;
using WCell.Constants.World;
using WCell.Core.Database;
using WCell.RealmServer.Global;
using WCell.Util;

namespace WCell.RealmServer.Instances
{
public class InstanceBinding : WCellRecord<InstanceBinding>, IMapId
public class InstanceBinding : IMapId
{
private int m_DifficultyIndex;

Expand All @@ -25,28 +23,25 @@ public uint InstanceId
set { _InstanceId = (int)value; }
}

[PrimaryKey]

public MapId MapId
{
get;
set;
}

[PrimaryKey]
private int _InstanceId
{
get;
set;
}

[Property(NotNull = true)]
public uint DifficultyIndex
{
get { return (uint)m_DifficultyIndex; }
set { m_DifficultyIndex = (int)value; }
}

[Property(NotNull = true)]
public DateTime BindTime
{
get;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
using System;
using Castle.ActiveRecord;
using WCell.Constants.Pets;
using WCell.RealmServer.Database;
using WCell.RealmServer.Spells;

namespace WCell.RealmServer.NPCs.Pets
namespace WCell.RealmServer.Database.Entities.Pets
{
public class PetSpell //: ActiveRecordBase<PetSpell>
public class PetSpell
{
public static readonly PetSpell[] EmptyArray = new PetSpell[0];

[PrimaryKey(PrimaryKeyType.GuidComb, "PetSpellId")]
public long Guid
{
get;
Expand All @@ -25,14 +23,12 @@ public Spell Spell
set { m_Spell = value; }
}

[Property("SpellId", NotNull = true)]
public int SpellId
{
get { return m_Spell != null ? (int)m_Spell.Id : 0; }
set { m_Spell = SpellHandler.Get((uint)value); }
}

[Field("PetSpellState", NotNull = true)]
private int _petSpellState;

public PetSpellState State
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
using System;
using Castle.ActiveRecord;
using WCell.Core.Database;
using System.Collections.Generic;

namespace WCell.RealmServer.Database
namespace WCell.RealmServer.Database.Entities
{
[ActiveRecord(Access = PropertyAccess.Property)]
public class QuestRecord : WCellRecord<QuestRecord>
public class QuestRecord
{
private static readonly NHIdGenerator _idGenerator =
new NHIdGenerator(typeof(QuestRecord), "QuestRecordId");
//private static readonly NHIdGenerator _idGenerator = new NHIdGenerator(typeof(QuestRecord), "QuestRecordId");

/// <summary>
/// Returns the next unique Id for a new Record
Expand All @@ -18,10 +15,10 @@ public static long NextId()
return _idGenerator.Next();
}

[Field("QuestTemplateId", NotNull = true, Access = PropertyAccess.FieldCamelcase)]
//[Field("QuestTemplateId", NotNull = true, Access = PropertyAccess.FieldCamelcase)]
private long _questTemplateId;

[Field("OwnerId", NotNull = true, Access = PropertyAccess.FieldCamelcase)]
//[Field("OwnerId", NotNull = true, Access = PropertyAccess.FieldCamelcase)]
private long _ownerId;

public QuestRecord(uint qId, uint ownerId)
Expand All @@ -35,7 +32,7 @@ public QuestRecord()
{
}

[PrimaryKey(PrimaryKeyType.Assigned)]
//[PrimaryKey(PrimaryKeyType.Assigned)]
public long QuestRecordId
{
get;
Expand All @@ -54,21 +51,21 @@ public uint QuestTemplateId
set { _questTemplateId = value; }
}

[Property(NotNull = true)]
//[Property(NotNull = true)]
public int Slot
{
get;
set;
}

[Property(NotNull = false)]
//[Property(NotNull = false)]
public DateTime? TimeUntil
{
get;
set;
}

[Property(NotNull = false)]
//[Property(NotNull = false)]
/// <summary>
/// Amounts of interactions
/// </summary>
Expand All @@ -78,7 +75,7 @@ public uint[] Interactions
set;
}

[Property(NotNull = false)]
//[Property(NotNull = false)]
/// <summary>
/// Visited AreaTriggers
/// </summary>
Expand All @@ -88,9 +85,9 @@ public bool[] VisitedATs
set;
}

public static QuestRecord[] GetQuestRecordForCharacter(uint chrId)
public static IEnumerable<QuestRecord> GetQuestRecordForCharacter(uint chrId)
{
return FindAllByProperty("_ownerId", (long)chrId);
return RealmWorldDBMgr.DatabaseProvider.FindAll<QuestRecord>(x => x.OwnerId == (long)chrId);
}
}
}
45 changes: 45 additions & 0 deletions Services/WCell.RealmServer/Database/Entities/ReputationRecord.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System;
using System.Collections.Generic;
using WCell.Constants.Factions;
using WCell.Database;

namespace WCell.RealmServer.Database.Entities
{
public class ReputationRecord
{
public long RecordId
{
get;
set;
}

public long OwnerId
{
get;
set;
}

public FactionReputationIndex ReputationIndex
{
get;
set;
}

public int Value
{
get;
set;
}

public ReputationFlags Flags
{
get;
set;
}

public static IEnumerable<ReputationRecord> Load(long chrRecordId)
{
return RealmWorldDBMgr.DatabaseProvider.FindAll<ReputationRecord>(x => x.OwnerId == chrRecordId);
}
}
}
24 changes: 5 additions & 19 deletions Services/WCell.RealmServer/Database/GuildMember.cs
Original file line number Diff line number Diff line change
@@ -1,41 +1,31 @@
using System;
using Castle.ActiveRecord;
using WCell.Core.Database;
using System.Collections.Generic;
using WCell.RealmServer.Database;
using WCell.RealmServer.Database.Entities;
using WCell.RealmServer.Entities;

namespace WCell.RealmServer.Guilds
namespace WCell.RealmServer.Database.Entities
{
[ActiveRecord("GuildMember", Access = PropertyAccess.Property)]
public partial class GuildMember : WCellRecord<GuildMember>
public partial class GuildMember
{
[PrimaryKey(PrimaryKeyType.Assigned)]
public long CharacterLowId
{
get;
private set;
}

[Field("Name", NotNull = true)]
private string _name;

[Field("LastLvl", NotNull = true)]
private int _lastLevel;

[Field("LastLogin", NotNull = true)]
private DateTime _lastLogin;

[Field("LastZone", NotNull = true)]
private int _lastZoneId;

[Field("Class", NotNull = true)]
private int _class;

[Field("Rank", NotNull = true)]
private int _rankId;

[Field("GuildId", NotNull = true)]
private int m_GuildId;

public uint GuildId
Expand All @@ -44,24 +34,20 @@ public uint GuildId
set { m_GuildId = (int)value; }
}

[Field("PublicNote")]
private string _publicNote;

[Field("OfficerNote")]
private string _officerNote;

[Field("BankRemainingMoneyAllowance")]
private int _remainingMoneyAllowance;

[Field("BankMoneyAllowanceResetTime", NotNull = true)]
private DateTime _moneyAllowanceResetTime;

/// <summary>
/// Loads all members of the given guild from the DB
/// </summary>
public static GuildMember[] FindAll(uint guildId)
public static IEnumerable<GuildMember> FindAll(uint guildId)
{
return FindAllByProperty("m_GuildId", (int)guildId);
return RealmWorldDBMgr.DatabaseProvider.FindAll<GuildMember>(x => x.m_GuildId == (int)guildId);
}

public GuildMember(CharacterRecord chr, Database.Entities.Guild guild, GuildRank rank)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ public class GuildBankLogEntryMap : ClassMap<GuildBankLogEntry>
public GuildBankLogEntryMap()
{
CompositeId().KeyProperty(x => x.GuildId).KeyProperty(x => x.BankLogEntryRecordId);
Map(x => x.BankLog);
Map(x => x.BankLog); //TODO: This should be a relation?
Map(Reveal.Member<GuildBankLogEntry>("bankLogEntryType"));
Map(Reveal.Member<GuildBankLogEntry>("actorEntityLowId"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class GuildBankTabItemMappingMap : ClassMap<GuildBankTabItemMapping>
public GuildBankTabItemMappingMap()
{
Id(x => x.Guid).GeneratedBy.Assigned();
Map(x => x.BankTab); //TODO How can we to BelongsTo with fluent
Map(x => x.BankTab); //TODO How can we do BelongsTo with fluent
Map(x => x.TabSlot);
Map(x => x.LastModifiedOn); //TODO: Work out if we should be using backing field instead (this is just a thought unrelated to this).
}
Expand Down
29 changes: 29 additions & 0 deletions Services/WCell.RealmServer/Database/Mappings/GuildMemberMap.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FluentNHibernate;
using FluentNHibernate.Mapping;
using WCell.RealmServer.Database.Entities;

namespace WCell.RealmServer.Database.Mappings
{
public class GuildMemberMap : ClassMap<GuildMember>
{
public GuildMemberMap()
{
Id(x => x.CharacterLowId).GeneratedBy.Assigned();
Map(x => Reveal.Member<GuildMember>("_name")).Not.Nullable().Column("Name");
Map(x => Reveal.Member<GuildMember>("_lastLevel")).Not.Nullable().Column("LastLvl");
Map(x => Reveal.Member<GuildMember>("_lastLogin")).Not.Nullable().Column("LastLogin");
Map(x => Reveal.Member<GuildMember>("_lastZoneId")).Not.Nullable().Column("LastZone");
Map(x => Reveal.Member<GuildMember>("_class")).Not.Nullable().Column("Class");
Map(x => Reveal.Member<GuildMember>("_rankId")).Not.Nullable().Column("Rank");
Map(x => Reveal.Member<GuildMember>("m_GuildId")).Not.Nullable().Column("GuildId");
Map(x => Reveal.Member<GuildMember>("_publicNote")).Column("PublicNote");
Map(x => Reveal.Member<GuildMember>("_officerNote")).Column("OfficerNote");
Map(x => Reveal.Member<GuildMember>("_remainingMoneyAllowance")).Column("BankRemainingMoneyAllowance");
Map(x => Reveal.Member<GuildMember>("_moneyAllowanceResetTime")).Not.Nullable().Column("BankMoneyAllowanceResetTime");
}
}
}
23 changes: 23 additions & 0 deletions Services/WCell.RealmServer/Database/Mappings/InstanceBindingMap.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using FluentNHibernate;
using FluentNHibernate.Mapping;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WCell.RealmServer.Instances;

namespace WCell.RealmServer.Database.Mappings
{
public class InstanceBindingMap : ClassMap<InstanceBinding>
{
public InstanceBindingMap()
{
Id(x => x.MapId);
Id(x => Reveal.Member<int>("_InstanceId"));
Map(x => x.DifficultyIndex).Not.Nullable();
Map(x => x.BindTime).Not.Nullable();


}
}
}
Loading

0 comments on commit bed6236

Please sign in to comment.