UniDirectionalAssociationMap.cs :  » Persistence-Frameworks » Persist.NET » Persist » Maps » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Persistence Frameworks » Persist.NET 
Persist.NET » Persist » Maps » UniDirectionalAssociationMap.cs
// Persist library : Persistence layer
// Copyright (C) 2003 Vincent Daron
// 
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
// 
// This library 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
// Lesser General Public License for more details.
// 
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

using System;
using System.Collections;

using Persist.Criteria;
using Persist.Statements;

namespace Persist.Maps{

   /// <summary>
   /// This class contains information about an association map.
   /// </summary>
   public class UniDirectionalAssociationMap
   {
      /// <summary>
      /// Cardinality of the Association map
      /// </summary>
      public enum CardinalityEnum
      {
         /// <summary>
         /// 1..1 Assocation
         /// </summary>
         ONE_TO_ONE,
         /// <summary>
         /// 1..* Association
         /// </summary>
         ONE_TO_MANY
      };

      private CardinalityEnum cardinality = CardinalityEnum.ONE_TO_ONE;
      private bool saveAutomatic = false;
      private bool deleteAutomatic = false;
      private bool retrieveAutomatic = false;
      private ClassMap forClass = null;
      private AttributeMap target = null;
      private ArrayList entries = new ArrayList();
      private bool inverse = false;
      private string targetName = null;

      /// <summary>
      /// Creates UniDirectionalAssociationMap.
      /// </summary>
      public UniDirectionalAssociationMap()
      {
      }

      /// <summary>
      /// Adds new entry to this association map.
      /// </summary>
      /// <param name="entry">the Entry</param>
      public void AddEntry(UDAMapEntry entry)
      {
         entries.Add(entry);
      }

      /// <summary>
      /// Cardinality of the association.
      /// </summary>
      public CardinalityEnum Cardinality
      {
         get
         {
            return cardinality;
         }
         set
         {
            cardinality = value;
         }
      }

      /// <summary>
      /// Returns entry with the given index.
      /// </summary>
      /// <param name="index">Entry Index</param>
      /// <returns>the Entry</returns>
      public UDAMapEntry GetEntry(int index)
      {
         return (UDAMapEntry)entries[index];
      }

      /// <summary>
      /// The Desitnation ClassMap of the Assocation
      /// </summary>
      public ClassMap ForClass
      {
         get
         {
            return forClass;
         }
         set
         {
            forClass = value;
         }
      }

      /// <summary>
      /// Returns number of entries.
      /// </summary>
      public int EntriesCount
      {
         get
         {
            return entries.Count;
         }
      }

      /// <summary>
      /// the Target Attribute of the association
      /// </summary>
      public AttributeMap Target
      {
         get
         {
            return target;
         }
         set
         {
            target = value;
         }
      }

      /// <summary>
      /// Returns the name of the target for this attribute map.
      /// </summary>
      public string TargetName
      {
         get
         {
            return targetName;
         }
         set
         {
            targetName = value;
         }
      }

      /// <summary>
      /// Returns true if this association is inversed.
      /// </summary>
      public bool IsInverse
      {
         get
         {
            return inverse;
         }
         set
         {
            inverse = value;
         }
      }

      /// <summary>
      /// Specified if the childs must be deleted when the parent is deleted
      /// </summary>
      public bool IsDeleteAutomatic
      {
         get
         {
            return deleteAutomatic;
         }
         set
         {
            deleteAutomatic = value;
         }
      }

      /// <summary>
      /// Specified if the child(s) must be retreived automatically when the parent is retrieved
      /// </summary>
      public bool IsRetrieveAutomatic
      {
         get
         {
            return retrieveAutomatic;
         }
         set
         {
            retrieveAutomatic = value;
         }
      }

      /// <summary>
      /// Specified if the child(s) must be saved automatically when the parent is saved
      /// </summary>
      public bool IsSaveAutomatic
      {
         get
         {
            return saveAutomatic;
         }
         set
         {
            saveAutomatic = value;
         }
      }

      /// <summary>
      /// Return the Criteria of this Association
      /// </summary>
      /// <param name="orderAttrs">Sort order of the retrieve</param>
      /// <returns>the Criteria</returns>
//      internal RetrieveCriteria GetCriteria(Order[] orderAttrs)
//      {
//         RetrieveCriteria criteria = new RetrieveCriteria(forClass);
//         if(isInverse)
//         {
//            for(int i = 0; i < entries.Count; i++)
//            {
//               criteria.WhereCondition.AddAndCriteria(criteria.GetEqualToCriteria(GetEntry(i).From.Name));
//            }
//         }
//         else
//         {
//            for(int i = 0; i < entries.Count; i++)
//            {
//               criteria.WhereCondition.AddAndCriteria(criteria.GetEqualToCriteria(GetEntry(i).To.Name));
//            }
//         }
//
//         if(orderAttrs != null)
//         {
//            for(int i = 0; i < orderAttrs.Length; i++)
//            {
//               criteria.AddOrderAttribute(orderAttrs[i].Name,orderAttrs[i].Ascend);
//            }
//         }
//         return criteria;
//      }

      internal RetrieveStatement GetStatement(Order[] orderAttrs)
      {
         RetrieveStatement criteriaStatement = new RetrieveStatement(forClass);
         if(IsInverse)
         {
            for(int i = 0; i < entries.Count; i++)
            {
               criteriaStatement.WhereCondition.AddAndCriteria(criteriaStatement.GetEqualToCriteria(GetEntry(i).From.Name));
            }
         }
         else
         {
            for(int i = 0; i < entries.Count; i++)
            {
               criteriaStatement.WhereCondition.AddAndCriteria(criteriaStatement.GetEqualToCriteria(GetEntry(i).To.Name));
            }
         }

         if(orderAttrs != null)
         {
            for(int i = 0; i < orderAttrs.Length; i++)
            {
               criteriaStatement.AddOrderAttribute(orderAttrs[i].Name,orderAttrs[i].Ascend);
            }
         }
         return criteriaStatement;
      }

      /// <summary>
      /// Return a parameter collection for the association criteria
      /// </summary>
      /// <param name="obj">the PersistentObject where the value have to be readed</param>
      /// <returns></returns>
      internal ICollection GetStatementParameters(PersistentObject obj)
      {
         ArrayList statementParameters = new ArrayList();
         if(IsInverse)
         {
            for(int i = 0; i < entries.Count; i++)
            {
               statementParameters.Add(GetEntry(i).To.GetValue(obj));
            }
         }
         else
         {
            for(int i = 0; i < entries.Count; i++)
            {
               statementParameters.Add(GetEntry(i).From.GetValue(obj));
            }
         }

         return statementParameters;
      }
   }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.