The Library class
|
||
using System;
using System.Data;
using Persistate;
namespace Library.Model
{
// This Library partial class has been generated by Persistate. Do
// not modify as the entire file is recreated on each generation.
[System.Diagnostics.DebuggerDisplay("Library {NominativeText}")]
public partial class Library : Persistent
{
private static ObjectClass objClass = null; // set at start of session
/// <summary> Sets the objClass field for this class. </summary>
public new static void SetObjectClass() {
ObjectClass.SetTargetTypeObjectClass(ref objClass);
}
/// <summary> Gets the ObjectClass object associated with this object. </summary>
public override ObjectClass Class {
get { return objClass; }
}
/// <summary> Gets the ObjectClass object associated with this class. </summary>
public new static ObjectClass ItsObjectClass {
get { return objClass; }
}
/// <summary> Creates a new Library with default property values </summary>
public Library() : this(true, true) {
}
/// <exclude />
/// <summary> Creates a new Library with optional default property values </summary>
public Library(bool initScalars, bool initCollections) : base(false, false) {
InitialiseMembers(initScalars, initCollections);
}
/// <exclude />
/// <summary> Creates a new Library with its reference and parent. </summary>
protected Library(Reference thisObj, IReference parentObj)
: base(thisObj, parentObj) {}
/// <summary> Gets the class flags for the Library class. </summary>
public override FlagSet ClassFlags {
get { return new FlagSet(FlagSet.CloneOnMutate |FlagSet.UseCache |FlagSet.Singleton |FlagSet.SaveInConfiguration); }
}
/// <exclude />
/// <summary> Creates a new Library from data read from persistent storage. </summary>
public new static Library CreateFromDatabase(Database db, IDataReader dr, Reference thisObj, Persistent parentObj) {
Library obj = new Library(thisObj, parentObj);
obj.FillFromDatabase(db, dr);
return obj;
}
/// <exclude />
/// <summary> Populates this object from data read from persistent storage. </summary>
public override void FillFromDatabase(Database db__, IDataReader dr__) {
base.FillFromDatabase(db__, dr__);
}
/// <exclude />
/// <summary> Populates persistent storage update parameters from this object. </summary>
public override bool SaveToDatabase(Database db__, Reference id__, object context__) {
bool reSave__;
do {
db__.SetParameter("id", id__);
db__.SetParameter("parent", ParentReference);
db__.SetParameter("oldVersion", PreviousVersion == null
? VersionNumber - 1 : PreviousVersion.VersionNumber);
db__.SetParameter("newVersion", VersionNumber);
if (!db__.SaveObject(context__, objClass, out reSave__))
return false;
} while (reSave__); // save again if an update conflict on first try was resolved
return true;
}
/// <exclude />
/// <summary> Creates a new Library from a Persistate.Message. </summary>
public new static Library CreateFromMessage(Message message, Reference thisObj, IReference parentObj) {
Library obj = new Library(thisObj, parentObj);
obj.FillFromMessage(message);
return obj;
}
/// <exclude />
/// <summary> Sets a single member value for a given slot from a message. </summary>
protected override void SetMemberFromMessage(int slot__, int length__, Message message__) {
switch (slot__) {
default: base.SetMemberFromMessage(slot__, length__, message__); break;
}
}
/// <exclude />
/// <summary> Populates a Persistate.Message from this object. </summary>
protected override void SaveToMessage(Message message__, bool topLevel__) {
base.SaveToMessage(message__, false);
if (topLevel__)
message__.Append(-1);
}
/// <exclude />
/// <summary> Initialises members of a Library object to default values. </summary>
public override void InitialiseMembers(bool initScalars__, bool initCollections__) {
base.InitialiseMembers(initScalars__, initCollections__);
if (initScalars__) {
}
if (initCollections__) {
genres = Genre.Collection(this, GenresFlagSet, 6, false);
}
}
/// <exclude />
/// <summary> Removes this Library and all objects under it from persistent storage. </summary>
public override void DePersist() {
foreach (Genre obj in Genres)
obj.DePersistFrom(Genres);
base.DePersist();
}
/// <exclude />
/// <summary> calls a method for every node in the persistent tree under this object. </summary>
public override bool CallTree(CallTreeData callTreeData__, int slot__) {
if (callTreeData__.RootFirst && !base.CallTree(callTreeData__, slot__))
return false;
Authors.CallTree(callTreeData__, 2);
Publications.CallTree(callTreeData__, 3);
Borrowers.CallTree(callTreeData__, 4);
Lends.CallTree(callTreeData__, 5);
Genres.CallTree(callTreeData__, 6);
if (!callTreeData__.RootFirst)
base.CallTree(callTreeData__, slot__);
return true;
}
/// <summary> Gets the value of the member property with a particular slot number. </summary>
/// <param name="slot__"> The member slot number. </param>
/// <returns> An object containing the value of the member with the given slot. </returns>
public override object GetMemberValue(int slot__) {
switch (slot__) {
case 1: return Name;
case 2: return Authors;
case 3: return Publications;
case 4: return Borrowers;
case 5: return Lends;
case 6: return Genres;
case 7: return MonthlyLendStatistics;
default: return base.GetMemberValue(slot__);
}
}
/// <summary> Sets the value of the member property with a particularn slot number. </summary>
/// <param name="slot__"> The member slot number. </param>
/// <param name="value__"> The new value to set into the member with the given slot. </param>
public override void SetMemberValue(int slot__, object value__) {
switch (slot__) {
default: base.SetMemberValue(slot__, value__); break;
}
}
/// <summary> Gets the value of the field backing the member with a particular slot number. </summary>
/// <param name="slot__"> The member slot number. </param>
/// <returns> An object containing the value of the field with the given slot. </returns>
public override object GetFieldValue(int slot__) {
switch (slot__) {
case 6: return genres;
default: return base.GetFieldValue(slot__);
}
}
/// <summary> Sets the value of the field backing the member with a particular slot number. </summary>
/// <param name="slot__"> The member slot number. </param>
/// <param name="value__"> The new value to set into the field with the given slot. </param>
public override void SetFieldValue(int slot__, object value__) {
switch (slot__) {
default: base.SetFieldValue(slot__, value__); break;
}
}
/// <summary> Creates a Library collection to contain transient objects. </summary>
/// <returns> An empty IndexedList(Library) collection. </returns>
public new static IndexedList<Library> Collection() {
return new IndexedList<Library>(ItsObjectClass, null, FlagSet.Associated, 0, false, 1, 0);
}
/// <summary> Creates a Library collection to contain persistent objects. </summary>
/// <param name="parent"> The parent object of the collection. </param>
/// <param name="flags"> A FlagSet containing the collection flags. </param>
/// <param name="slot"> The slot of its parent member containing the collection. </param>
/// <param name="getData"> If true, objects belonging in the collection are fetched from persistent storage. </param>
/// <returns> An IndexedList(Library) containing the new collection. </returns>
public new static IndexedList<Library> Collection(Persistent parent, FlagSet flags, int slot, bool getData) {
return new IndexedList<Library>(ItsObjectClass, parent, flags, slot, getData, 1, 0);
}
// Property for name
/// <summary> Property for name. </summary>
public String Name {
get { return "The Library"; }
}
// Property for authors
private SessionSpecific<IndexedList<Author>> authors;
private static readonly FlagSet AuthorsFlagSet = FlagSet.MultipleObject |FlagSet.MultipleMany |FlagSet.UseLinkTable;
/// <summary> Property for authors. </summary>
public IndexedList<Author> Authors {
get {
IndexedList<Author> collection = authors.Value;
if (collection == null) {
collection = Author.Collection(this, AuthorsFlagSet, 2, false);
authors.Value = collection;
}
return collection;
}
}
/// <summary> Finds the Authors with a particular Forename. </summary>
/// <param name="key"> The Forename to search for. </param>
/// <returns> A collection containing the Authors with the given Forename. </returns>
public IndexedList<Author> AuthorsWithForename(object key) {
IndexedList<Author> collection = Authors;
collection.Clear();
return GetChildren(collection, Author.ItsObjectClass, "Forename", key);
}
/// <summary> Finds the Authors with a particular Surname. </summary>
/// <param name="key"> The Surname to search for. </param>
/// <returns> A collection containing the Authors with the given Surname. </returns>
public IndexedList<Author> AuthorsWithSurname(object key) {
IndexedList<Author> collection = Authors;
collection.Clear();
return GetChildren(collection, Author.ItsObjectClass, "Surname", key);
}
/// <summary> Obtains a set of Authors which match a set of keys. /// </summary>
/// <param name="keys">One key should be supplied for each discriminative
/// member of the Author class.</param>
/// <returns>A list of Choice objects, one for each matched Author.</returns>
public IndexedList<Choice> AuthorsLike(params object[] keys) {
IndexedList<Choice> collection = Choice.Collection(this, AuthorsFlagSet, 2, false);
return GetChildren(collection, Author.ItsObjectClass, "discriminate", keys);
}
// Property for publications
private SessionSpecific<IndexedList<Publication>> publications;
private static readonly FlagSet PublicationsFlagSet = FlagSet.Diverse |FlagSet.MultipleObject |FlagSet.MultipleMany |FlagSet.UseLinkTable;
/// <summary> Property for publications. </summary>
public IndexedList<Publication> Publications {
get {
IndexedList<Publication> collection = publications.Value;
if (collection == null) {
collection = Publication.Collection(this, PublicationsFlagSet, 3, false);
publications.Value = collection;
}
return collection;
}
}
/// <summary> Finds the Publications with a particular Title. </summary>
/// <param name="key"> The Title to search for. </param>
/// <returns> A collection containing the Publications with the given Title. </returns>
public IndexedList<Publication> PublicationsWithTitle(object key) {
IndexedList<Publication> collection = Publications;
collection.Clear();
return GetChildren(collection, Publication.ItsObjectClass, "Title", key);
}
/// <summary> Obtains the Publication with a particular IsbnNumber. </summary>
/// <param name="key">The IsbnNumber to find.</param>
/// <returns>The found Publication or null if none was found.</returns>
public Publication PublicationWithIsbnNumber(object key) {
IndexedList<Publication> collection = Publications;
collection.Clear();
GetChildren(collection, Publication.ItsObjectClass, "IsbnNumber", key);
return (collection.Count > 0 ? collection[0] : null);
}
/// <summary> Obtains a set of Publications which match a set of keys. /// </summary>
/// <param name="searchClass">The class of objects to search for. This
/// should be the Publication class or a class derived from it.</param>
/// <param name="keys">One key should be supplied for each discriminative
/// member of the search class.</param>
/// <returns>A list of Choice objects, one for each matched object.</returns>
public IndexedList<Choice> PublicationsLike(ObjectClass searchClass, params object[] keys) {
IndexedList<Choice> results = Choice.Collection(this, PublicationsFlagSet, 3, false);
return GetChildren(results, searchClass, "discriminate", keys);
}
// Property for borrowers
private SessionSpecific<IndexedList<Borrower>> borrowers;
private static readonly FlagSet BorrowersFlagSet = FlagSet.MultipleObject |FlagSet.MultipleMany |FlagSet.UseLinkTable;
/// <summary> Property for borrowers. </summary>
public IndexedList<Borrower> Borrowers {
get {
IndexedList<Borrower> collection = borrowers.Value;
if (collection == null) {
collection = Borrower.Collection(this, BorrowersFlagSet, 4, false);
borrowers.Value = collection;
}
return collection;
}
}
/// <summary> Finds the Borrowers with a particular PostalAddress. </summary>
/// <param name="key"> The PostalAddress to search for. </param>
/// <returns> A collection containing the Borrowers with the given PostalAddress. </returns>
public IndexedList<Borrower> BorrowersWithPostalAddress(object key) {
IndexedList<Borrower> collection = Borrowers;
collection.Clear();
return GetChildren(collection, Borrower.ItsObjectClass, "PostalAddress", key);
}
/// <summary> Finds the Borrowers with a particular Forename. </summary>
/// <param name="key"> The Forename to search for. </param>
/// <returns> A collection containing the Borrowers with the given Forename. </returns>
public IndexedList<Borrower> BorrowersWithForename(object key) {
IndexedList<Borrower> collection = Borrowers;
collection.Clear();
return GetChildren(collection, Borrower.ItsObjectClass, "Forename", key);
}
/// <summary> Finds the Borrowers with a particular Surname. </summary>
/// <param name="key"> The Surname to search for. </param>
/// <returns> A collection containing the Borrowers with the given Surname. </returns>
public IndexedList<Borrower> BorrowersWithSurname(object key) {
IndexedList<Borrower> collection = Borrowers;
collection.Clear();
return GetChildren(collection, Borrower.ItsObjectClass, "Surname", key);
}
/// <summary> Obtains a set of Borrowers which match a set of keys. /// </summary>
/// <param name="keys">One key should be supplied for each discriminative
/// member of the Borrower class.</param>
/// <returns>A list of Choice objects, one for each matched Borrower.</returns>
public IndexedList<Choice> BorrowersLike(params object[] keys) {
IndexedList<Choice> collection = Choice.Collection(this, BorrowersFlagSet, 4, false);
return GetChildren(collection, Borrower.ItsObjectClass, "discriminate", keys);
}
// Property for lends
private SessionSpecific<IndexedList<Lend>> lends;
private static readonly FlagSet LendsFlagSet = FlagSet.MultipleObject |FlagSet.MultipleMany;
/// <summary> Property for lends. </summary>
public IndexedList<Lend> Lends {
get {
IndexedList<Lend> collection = lends.Value;
if (collection == null) {
collection = Lend.Collection(this, LendsFlagSet, 5, false);
lends.Value = collection;
}
return collection;
}
}
/// <summary> Finds the Lends with a particular Publication. </summary>
/// <param name="key"> The Publication to search for. </param>
/// <returns> A collection containing the Lends with the given Publication. </returns>
public IndexedList<Lend> LendsWithPublication(object key) {
IndexedList<Lend> collection = Lends;
collection.Clear();
return GetChildren(collection, Lend.ItsObjectClass, "Publication", key);
}
/// <summary> Finds the Lends with a particular Borrower. </summary>
/// <param name="key"> The Borrower to search for. </param>
/// <returns> A collection containing the Lends with the given Borrower. </returns>
public IndexedList<Lend> LendsWithBorrower(object key) {
IndexedList<Lend> collection = Lends;
collection.Clear();
return GetChildren(collection, Lend.ItsObjectClass, "Borrower", key);
}
/// <summary> Obtains a set of Lends which match a set of keys. /// </summary>
/// <param name="keys">One key should be supplied for each discriminative
/// member of the Lend class.</param>
/// <returns>A list of Choice objects, one for each matched Lend.</returns>
public IndexedList<Choice> LendsLike(params object[] keys) {
IndexedList<Choice> collection = Choice.Collection(this, LendsFlagSet, 5, false);
return GetChildren(collection, Lend.ItsObjectClass, "discriminate", keys);
}
// Property for genres
private IndexedList<Genre> genres = null;
private static readonly FlagSet GenresFlagSet = FlagSet.MultipleObject;
/// <summary> Property for genres. </summary>
public IndexedList<Genre> Genres {
get {
if (genres == null)
genres = Genre.Collection(this, GenresFlagSet, 6, true);
return genres;
}
}
/// <summary> Gets the number of items in the Genres collection. </summary>
public int GenresCount {
get { return Genres.Count; }
}
// Property for monthly lend statistics
private SessionSpecific<IndexedList<MonthlyLendStatistic>> monthlyLendStatistics;
private static readonly FlagSet MonthlyLendStatisticsFlagSet = FlagSet.MultipleObject;
/// <summary> Property for monthly lend statistics. </summary>
public IndexedList<MonthlyLendStatistic> MonthlyLendStatistics {
get {
IndexedList<MonthlyLendStatistic> collection = monthlyLendStatistics.Value;
if (collection == null) {
collection = MonthlyLendStatistic.Collection(this, MonthlyLendStatisticsFlagSet, 7, false);
monthlyLendStatistics.Value = collection;
}
return collection;
}
}
/// <summary> Retrieves selected objects into the MonthlyLendStatistics collection. </summary>
/// <param name="from"> The value for the from parameter. </param>
/// <param name="to"> The value for the to parameter. </param>
/// <returns> The MonthlyLendStatistics collection, now containing the selected objects. </returns>
public IndexedList<MonthlyLendStatistic> SelectMonthlyLendStatistics(DateTime from, DateTime to) {
IndexedList<MonthlyLendStatistic> collection = MonthlyLendStatistics;
collection.Clear();
GetSelected(collection, MonthlyLendStatistic.ItsObjectClass, from, to);
return collection;
}
/// <summary> Key value for name index. </summary>
public const int NameKey = 0;
/// <summary> Returns property value for given key number. </summary>
/// <param name="keyNum__"> The key number to use. </param>
/// <returns> an object containing the value of the property indicated by the given key. </returns>
public override object GetKey(int keyNum__) {
switch (keyNum__) {
case NameKey: return Name;
default: return base.GetKey(keyNum__);
}
}
/// <summary> Gets a string containing values of nominative properties. </summary>
public override string NominativeText {
get { return Utl.Join(AnnotationSeparator, base.NominativeText, Name); }
}
/// <summary> Gets a string containing values of discriminative properties. </summary>
public override string DiscriminativeText {
get { return Utl.Join(AnnotationSeparator, base.DiscriminativeText, Name); }
}
}
}