Exemplo n.º 1
0
 /// <summary>
 /// Constructor selecting the provider based on the namespace of the supplied type.
 /// </summary>
 public PersistenceBroker(Type type)
 {
     provider = ProviderFactory.GetProvider(type);
 }
Exemplo n.º 2
0
 /// <summary>
 /// This method constructs a PersistenceBroker instance. The specified provider (database
 /// engine name) and connection string will be used to instantiate the desired backend
 /// engine used by this broker.
 /// </summary>
 /// <param name="providerName">The database engine name</param>
 /// <param name="connectionString">The connection string for connecting to the database</param>
 public PersistenceBroker(string providerName, string connectionString)
 {
     // determine backend engine and instatiate it
     provider = ProviderFactory.GetProvider(null, providerName, connectionString);
 }
Exemplo n.º 3
0
 /// <summary>
 /// Constructor using the supplied provider (or using DefaultProvider settings if null is passed).
 /// </summary>
 public PersistenceBroker(IGentleProvider provider)
 {
     this.provider = provider != null ? provider : ProviderFactory.GetProvider(null, null);
 }
Exemplo n.º 4
0
        /// <summary>
        /// Permanently remove an object.
        /// </summary>
        /// <param name="type">The type of object</param>
        /// <param name="key">The key indentifying the object</param>
        public static void Remove(Type type, Key key)
        {
            IGentleProvider provider = ProviderFactory.GetProvider(type);

            provider.Broker.Remove(type, key);
        }
Exemplo n.º 5
0
 /// <summary>
 /// This method constructs a PersistenceBroker instance. The specified provider (database
 /// engine name) and connection string will be used to instantiate the desired backend
 /// engine used by this broker. The name will be used to uniquely distinguish this instance
 /// from other providers, and can be used to later obtain a reference to the cached instance
 /// by calling <see cref="ProviderFactory.GetNamedProvider"/>.
 /// </summary>
 /// <param name="name">The unique name to associate with this provider/broker pair.</param>
 /// <param name="providerName">The database engine name</param>
 /// <param name="connectionString">The connection string for connecting to the database</param>
 public PersistenceBroker(string name, string providerName, string connectionString)
 {
     provider = ProviderFactory.GetProvider(name, providerName, connectionString);
 }
Exemplo n.º 6
0
        /// <summary>
        /// Insert an object. This updates the identity property of objects with
        /// autogenerated primary keys.
        /// </summary>
        /// <param name="obj">The object to insert</param>
        public static void Insert(object obj)
        {
            IGentleProvider provider = ProviderFactory.GetProvider(obj.GetType());

            provider.Broker.Insert(obj);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Permanently remove an object.
        /// </summary>
        /// <param name="obj">The object to persist</param>
        public static void Remove(object obj)
        {
            IGentleProvider provider = ProviderFactory.GetProvider(obj.GetType());

            provider.Broker.Remove(obj);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Persist (insert or update) an object.
        /// Updates the Id property of AutoPersistent objects on insert.
        /// </summary>
        /// <param name="entity">The object to persist</param>
        public static void Persist(IEntity entity)
        {
            IGentleProvider provider = ProviderFactory.GetProvider(entity.GetType());

            provider.Broker.Persist(entity);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Retrieve a list of objects of a given type, optionally using the key as constraints.
        /// The key must contain column names and values (they will not be translated from
        /// property names to column names).
        /// </summary>
        /// <typeparam name="T">The type of objects to retrieve</typeparam>
        /// <param name="key">The key containing any constraints</param>
        /// <param name="result">An optional existing container in which to store the created objects. If
        /// this parameter is null a new IList instance will be created.</param>
        /// <returns>A collection of object instances</returns>
        public static IList <T> RetrieveList <T>(Key key, IList <T> result)
        {
            IGentleProvider provider = ProviderFactory.GetProvider(typeof(T));

            return(provider.Broker.RetrieveList <T>(key, result));
        }
Exemplo n.º 10
0
        /// <summary>
        /// Retrieve a list of objects of a given type, optionally using the key as constraints.
        /// The key must contain column names and values (they will not be translated from
        /// property names to column names).
        /// </summary>
        /// <param name="type">The type of objects to retrieve</param>
        /// <param name="key">The key containing any constraints</param>
        /// <param name="result">An optional existing container in which to store the created objects. If
        /// this parameter is null a new IList instance will be created.</param>
        /// <returns>A collection of object instances</returns>
        public static IList RetrieveList(Type type, Key key, IList result)
        {
            IGentleProvider provider = ProviderFactory.GetProvider(type);

            return(provider.Broker.RetrieveList(type, key, result));
        }
Exemplo n.º 11
0
        /// <summary>
        /// Retrieve an object given its type and key. This method returns null if no
        /// record matches the query.
        /// </summary>
        /// <typeparam name="T">The type of objects to retrieve</typeparam>
        /// <param name="key">The key of the object to retrieve</param>
        /// <returns>The created object instance or null if no records were retrieved.</returns>
        public static T TryRetrieveInstance <T>(Key key)
        {
            IGentleProvider provider = ProviderFactory.GetProvider(typeof(T));

            return(provider.Broker.TryRetrieveInstance <T>(key));
        }
Exemplo n.º 12
0
        /// <summary>
        /// Retrieve an object given its type and key. This method returns null if no
        /// record matches the query.
        /// </summary>
        /// <param name="type">The type of object to create</param>
        /// <param name="key">The key of the object to retrieve</param>
        /// <returns>The created object instance or null if no records were retrieved.</returns>
        public static object TryRetrieveInstance(Type type, Key key)
        {
            IGentleProvider provider = ProviderFactory.GetProvider(type);

            return(provider.Broker.TryRetrieveInstance(type, key));
        }