factories
This is really just one class containing several factories. One factory method is generated for each table generated in the system.
factories.cs
//////////////////////////////////////////////////////////////////////////////////
// WARNING: This file contains generated code that can be replaced at any time
// it's generated as a PARTIAL CLASS, so if you need to extend the class
// implement your extensions in an alternate class that won't be overwritten.
//////////////////////////////////////////////////////////////////////////////////
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Assets.SQLINQ.SQLite.Net;
using Assets.SQLINQ.SQLite.Patterns;
using Assets.Data.Tables;
using Assets.Data.DataDomain;
namespace Assets.Data.Utility {
public static partial class Factory {
/// <summary>
/// Call this once at the start of the execution of your code, it does not have to be
/// called each time you load a database. It's used to identify the methods to get an
/// instance from the database for an OID. And how to convert table class instances (records)
/// to domain class instances. Basically resolving the subtypes.
/// </summary>
public static void Initialize() {
// Test to see if the ReadFactory is initialized, if so, exit
if ( Repository.IsInitialized )
return;
// Initialize Factories for transforming tables to objects
Repository.AddGetOIDMethod<PlanetTable>( PlanetTable.GetByOID );
Repository.AddGetOIDMethod<SettlementTable>( SettlementTable.GetByOID );
Repository.AddGetOIDMethod<DistrictTable>( DistrictTable.GetByOID );
// Initialize Factories for transforming tables to objects
Repository.AddReadFactory<PlanetTable>( PlanetReadFactory );
Repository.AddReadFactory<SettlementTable>( SettlementReadFactory );
Repository.AddReadFactory<DistrictTable>( DistrictReadFactory );
}// Initialize
/// <summary>
/// This creates the database by making all the tables. Call once during a table creation.
/// </summary>
public static void MakeDatabase() {
PlanetTable.CreateTable();
SettlementTable.CreateTable();
DistrictTable.CreateTable();
}
/// <summary>
/// Reads an IBaseTable row and generates Planet. The architecture guarantees that
/// aRow is of type PlanetTable.
/// </summary>
private static Planet PlanetReadFactory(IBaseTable aRow) {
PlanetTable ROW = aRow as PlanetTable;
switch( ROW.SubType ) {
case Planet.cSubType:
return new Planet(
ROW.OID
, ROW.Name
);
}
return null;
}
/// <summary>
/// Reads an IBaseTable row and generates Settlement. The architecture guarantees that
/// aRow is of type SettlementTable.
/// </summary>
private static Settlement SettlementReadFactory(IBaseTable aRow) {
SettlementTable ROW = aRow as SettlementTable;
switch( ROW.SubType ) {
case Settlement.cSubType:
return new Settlement(
ROW.OID
, ROW.Name
, ROW.ThePlanetOID
, ROW.TheDistrictOID
);
case Town.cSubType:
return new Town(
ROW.OID
, ROW.Name
, ROW.ThePlanetOID
, ROW.TheDistrictOID
, ROW.MayorName
, ROW.TheTypeOfTown
);
case City.cSubType:
return new City(
ROW.OID
, ROW.Name
, ROW.ThePlanetOID
, ROW.TheDistrictOID
, ROW.MayorName
, ROW.TheTypeOfTown
, ROW.Motto
);
}
return null;
}
/// <summary>
/// Reads an IBaseTable row and generates District. The architecture guarantees that
/// aRow is of type DistrictTable.
/// </summary>
private static District DistrictReadFactory(IBaseTable aRow) {
DistrictTable ROW = aRow as DistrictTable;
switch( ROW.SubType ) {
case District.cSubType:
return new District(
ROW.OID
, ROW.Name
);
}
return null;
}
}
}
// WARNING: This file contains generated code that can be replaced at any time
// it's generated as a PARTIAL CLASS, so if you need to extend the class
// implement your extensions in an alternate class that won't be overwritten.
//////////////////////////////////////////////////////////////////////////////////
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Assets.SQLINQ.SQLite.Net;
using Assets.SQLINQ.SQLite.Patterns;
using Assets.Data.Tables;
using Assets.Data.DataDomain;
namespace Assets.Data.Utility {
public static partial class Factory {
/// <summary>
/// Call this once at the start of the execution of your code, it does not have to be
/// called each time you load a database. It's used to identify the methods to get an
/// instance from the database for an OID. And how to convert table class instances (records)
/// to domain class instances. Basically resolving the subtypes.
/// </summary>
public static void Initialize() {
// Test to see if the ReadFactory is initialized, if so, exit
if ( Repository.IsInitialized )
return;
// Initialize Factories for transforming tables to objects
Repository.AddGetOIDMethod<PlanetTable>( PlanetTable.GetByOID );
Repository.AddGetOIDMethod<SettlementTable>( SettlementTable.GetByOID );
Repository.AddGetOIDMethod<DistrictTable>( DistrictTable.GetByOID );
// Initialize Factories for transforming tables to objects
Repository.AddReadFactory<PlanetTable>( PlanetReadFactory );
Repository.AddReadFactory<SettlementTable>( SettlementReadFactory );
Repository.AddReadFactory<DistrictTable>( DistrictReadFactory );
}// Initialize
/// <summary>
/// This creates the database by making all the tables. Call once during a table creation.
/// </summary>
public static void MakeDatabase() {
PlanetTable.CreateTable();
SettlementTable.CreateTable();
DistrictTable.CreateTable();
}
/// <summary>
/// Reads an IBaseTable row and generates Planet. The architecture guarantees that
/// aRow is of type PlanetTable.
/// </summary>
private static Planet PlanetReadFactory(IBaseTable aRow) {
PlanetTable ROW = aRow as PlanetTable;
switch( ROW.SubType ) {
case Planet.cSubType:
return new Planet(
ROW.OID
, ROW.Name
);
}
return null;
}
/// <summary>
/// Reads an IBaseTable row and generates Settlement. The architecture guarantees that
/// aRow is of type SettlementTable.
/// </summary>
private static Settlement SettlementReadFactory(IBaseTable aRow) {
SettlementTable ROW = aRow as SettlementTable;
switch( ROW.SubType ) {
case Settlement.cSubType:
return new Settlement(
ROW.OID
, ROW.Name
, ROW.ThePlanetOID
, ROW.TheDistrictOID
);
case Town.cSubType:
return new Town(
ROW.OID
, ROW.Name
, ROW.ThePlanetOID
, ROW.TheDistrictOID
, ROW.MayorName
, ROW.TheTypeOfTown
);
case City.cSubType:
return new City(
ROW.OID
, ROW.Name
, ROW.ThePlanetOID
, ROW.TheDistrictOID
, ROW.MayorName
, ROW.TheTypeOfTown
, ROW.Motto
);
}
return null;
}
/// <summary>
/// Reads an IBaseTable row and generates District. The architecture guarantees that
/// aRow is of type DistrictTable.
/// </summary>
private static District DistrictReadFactory(IBaseTable aRow) {
DistrictTable ROW = aRow as DistrictTable;
switch( ROW.SubType ) {
case District.cSubType:
return new District(
ROW.OID
, ROW.Name
);
}
return null;
}
}
}