/*
* Namespace Summary
* Copyright (C) 2005+ Bogdan Damian Constantin
* E-Mail: damianbcpetro@gmail.com
* WEB: http://www.sourceforge.net/projects/dataholder
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License 2.1 or later, as
* published by the Free Software Foundation. See the included License.txt
* or http://www.gnu.org/copyleft/lesser.html for details.
*
*/
using System;
using System.Data;
using System.Data.Common;
using DataHolder.DataPersistence.DBAProvider.Properties;
namespace DataHolder.DataPersistence.DBAProvider{
/// <summary>
/// Summary description for DBAGenericDataProperty. DBAGenericDataPropertiesHolder
/// </summary>
public class PersistenceProperty
{
public PersistenceProperty(DBDataSource lDBDataSource, PersistenceFieldCollection lPersistenceFieldCollection, UpdateRowSource _UpdatedRowSource)
{
this.l_DBDataSource = lDBDataSource;
this.l_PersistenceFieldCollection = lPersistenceFieldCollection;
this.l_UpdatedRowSource = _UpdatedRowSource;
}
public PersistenceProperty(DBDataSource lDBDataSource, Type DataType, UpdateRowSource _UpdatedRowSource)
{
DataHolder.Containers.Property.PropertyCollection pc = DataHolder.Containers.GenericData.TCollection.GetProperties(DataType);
l_PersistenceFieldCollection = new PersistenceFieldCollection();
foreach(DataHolder.Containers.Property.GenericDataProperty prop in pc)
if(prop is DataHolder.Containers.Property.Property)
l_PersistenceFieldCollection.Add(new TablePersistenceField(prop.PropertyName, 0,prop.PropertyName, null) );
this.l_DBDataSource = lDBDataSource;
this.l_UpdatedRowSource = _UpdatedRowSource;
}
public PersistenceProperty(DBDataSource lDBDataSource, PersistenceFieldCollection lPersistenceFieldCollection):this(lDBDataSource, lPersistenceFieldCollection, UpdateRowSource.FirstReturnedRecord)
{
this.l_DBDataSource = lDBDataSource;
this.l_PersistenceFieldCollection = lPersistenceFieldCollection;
}
protected DBDataSource l_DBDataSource;
public DBDataSource DBDataSource
{
get
{
return l_DBDataSource;
}
}
protected PersistenceFieldCollection l_PersistenceFieldCollection;
public PersistenceFieldCollection PersistenceFieldCollection
{
get
{
return l_PersistenceFieldCollection;
}
}
protected UpdateRowSource l_UpdatedRowSource;
public UpdateRowSource UpdatedRowSource
{
get
{
return l_UpdatedRowSource;
}
}
public int [] GetSelectColumnMapping(Containers.GenericData ge, IDataReader dr)
{
int [] CacheColumnIndex = new int[ge.Properties.Count];
for(int i = 0; i < ge.Properties.Count; i++)
{
CacheColumnIndex[i] = -1;
if(ge.Properties[i] is Interfaces.IDBGenericProperty)
{
int mapIndex = this.PersistenceFieldCollection.IndexOfPropertyColumn(ge.Properties[i].PropertyName);
if(mapIndex >= 0)
CacheColumnIndex[i] = dr.GetOrdinal(this.PersistenceFieldCollection[mapIndex].RecordSetName);
}
}
return CacheColumnIndex;
}
public int [] GetSaveColumnMapping(Containers.GenericData ge, IDataParameterCollection paramcoll)
{
int [] CacheColumnIndex = new int[paramcoll.Count];
for(int i = 0; i < paramcoll.Count; i++)
{
IDataParameter param = (IDataParameter)paramcoll[i];
int index = ge.Properties.IndexOf(param.SourceColumn);
if(ge.Properties[index] is Interfaces.IDBGenericProperty)
CacheColumnIndex[i] = index;
else if(param.Direction == ParameterDirection.Input
|| param.Direction == ParameterDirection.InputOutput)
throw new Exception( param.SourceColumn + " source column not found for parameter" + param.ParameterName + " in type " + ge.GetType().FullName);
}
return CacheColumnIndex;
}
}
}
|