|
From: <sv...@de...> - 2005-05-20 23:38:56
|
Author: marcelo
Date: 2005-05-20 19:38:39 -0400 (Fri, 20 May 2005)
New Revision: 1125
Modified:
humano2/branches/datareader/components/viewTools/ViewTools.cs
humano2/branches/datareader/components/webTools/Adapter.cs
humano2/branches/datareader/core/db/absComplex.cs
humano2/branches/datareader/core/db/absConnection.cs
humano2/branches/datareader/core/db/absCrud.cs
humano2/branches/datareader/core/db/mssql/mssqlComplex.cs
humano2/branches/datareader/core/db/mssql/mssqlConnection.cs
humano2/branches/datareader/core/db/mssql/mssqlCrud.cs
humano2/branches/datareader/core/db/pgsql/pgsqlComplex.cs
humano2/branches/datareader/core/db/pgsql/pgsqlConnection.cs
humano2/branches/datareader/core/db/pgsql/pgsqlCrud.cs
humano2/branches/datareader/core/schema/mssql/mssql-1-metadata.sql
humano2/branches/datareader/web/builder/site/buildattribute.aspx.cs
Log:
* First mayor commit in making the platform multi DB compliant. not done,=
just commiting in case HD dies
Modified: humano2/branches/datareader/components/viewTools/ViewTools.cs
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- humano2/branches/datareader/components/viewTools/ViewTools.cs 2005-05=
-20 23:38:32 UTC (rev 1124)
+++ humano2/branches/datareader/components/viewTools/ViewTools.cs 2005-05=
-20 23:38:39 UTC (rev 1125)
@@ -19,7 +19,6 @@
=20
using Humano2.Core;
using Humano2.Core.Db;
-using Humano2.Core;
=20
namespace Humano2.Components.ViewTools
{
@@ -889,18 +888,22 @@
tableName =3D Complex.TableName(IdClass);
columnName =3D "id_entity";
}
+ int classtype =3D Complex.getClassIdofInstance(columnIndex);
+ if (classtype !=3D 13)
+ {
+ order.Append("upper(" + tableName + "." + columnName + ") ");
=20
- order.Append("upper(" + tableName + "." + columnName + ") ");
- parameter =3D parameters[1].ToString();
- if(parameter =3D=3D "0")
- {
- order.Append("asc ");
+ parameter =3D parameters[1].ToString();
+ if(parameter =3D=3D "0")
+ {
+ order.Append("asc ");
+ }
+ else
+ {
+ order.Append("desc ");
+ }
+ order.Append(", ");
}
- else
- {
- order.Append("desc ");
- }
- order.Append(", ");
}
order.Remove(order.Length-2,2);
order.Append(" ");
Modified: humano2/branches/datareader/components/webTools/Adapter.cs
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- humano2/branches/datareader/components/webTools/Adapter.cs 2005-05-20=
23:38:32 UTC (rev 1124)
+++ humano2/branches/datareader/components/webTools/Adapter.cs 2005-05-20=
23:38:39 UTC (rev 1125)
@@ -1143,7 +1143,7 @@
=09
string[] fila =3D {"0,66", // get id_entity and the names of the colu=
mns.
("34|4|'" + domainId.ToString() + "'|1|0;" + // Where the class is p=
art of the domain.
- "125|4|'f'|0|0"), // The class is not hidden (isHidden is false)
+ "125|4|'0'|0|0"), // The class is not hidden (isHidden is false) /=
/changed to BIT "125|4|'f'|0|0"
"", // No group by
"", // No Havings
"", // No order by
@@ -1414,16 +1414,17 @@
public void SetAttributeAsPrimary(int primaryId, int classId, int d=
omainId)
{
// Remove the isPrimary label from all attributes. =20
- complex.SetNoAttributesAsPrimary(classId);
+ complex.SetAttributeAsPrimary(classId,primaryId);
=20
- DataTable dt =3D new DataTable();
- dt.Columns.Add("isPrimary");
- DataRow dr =3D dt.NewRow();
- dr["isPrimary"] =3D true;
- dt.Rows.Add(dr);
-
- crud.Domain =3D domainId;
- crud.Update(primaryId, dt);
+//
+// DataTable dt =3D new DataTable();
+// dt.Columns.Add("isPrimary");
+// DataRow dr =3D dt.NewRow();
+// dr["isPrimary"] =3D "1";
+// dt.Rows.Add(dr);
+//
+// crud.Domain =3D domainId;
+// crud.Update(primaryId, dt);
}
=20
public bool ClassHasView(int classId)
@@ -1514,8 +1515,8 @@
Logger.Log("ChangeAttributesOfView: ", LogLevel.Trace);
DataTable dt =3D new DataTable();
crud.Domain =3D idDomain;
- string query =3D @"select ""id_entity"", ""columns"" from ""view"" wh=
ere ""idClassView"" =3D "+classId+" order by id_entity limit 1";
- DataTable view =3D complex.doSelect(query);
+
+ DataTable view =3D complex.getColsforView(classId);
=09
string[] row;
string col1=3D"";
Modified: humano2/branches/datareader/core/db/absComplex.cs
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- humano2/branches/datareader/core/db/absComplex.cs 2005-05-20 23:38:32=
UTC (rev 1124)
+++ humano2/branches/datareader/core/db/absComplex.cs 2005-05-20 23:38:39=
UTC (rev 1125)
@@ -46,7 +46,8 @@
///<param name=3D"names">The 'name' of classes in the meta model.</par=
am>
abstract public string[] convertAttribSysNameToName(int idEntity=
, string[] names);
=20
- =20
+ abstract public DataTable getColsforView(int classid);
+
/// <summary>
/// Crea una tabla temporal para realizar el paginado de una consulta =
por ViewTools
/// </summary>
@@ -73,7 +74,7 @@
/// Set all of the attributes of the class to isPrimary =3D false.
/// </summary>
/// <param name=3D"classId">The instance Id of the class.</param>
- abstract public void SetNoAttributesAsPrimary(int classId);
+ abstract public void SetAttributeAsPrimary(int classId, int primary=
Id);
=20
/// <summary>
/// Returns the Id of the view that is the default view for this class=
.
Modified: humano2/branches/datareader/core/db/absConnection.cs
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- humano2/branches/datareader/core/db/absConnection.cs 2005-05-20 23:38=
:32 UTC (rev 1124)
+++ humano2/branches/datareader/core/db/absConnection.cs 2005-05-20 23:38=
:39 UTC (rev 1125)
@@ -51,6 +51,14 @@
{
return dbCon;
}
+
+ public IDbTransaction getTransactionObj()
+ {
+ if ( dbTransRefCount > 0 )
+ return dbTrans;
+ else=20
+ return null;
+ }
=09
///<summary>Hace un select en la base de datos.</summary>
///<param name=3D"query">El SQL a ejecutarse</param>
@@ -69,6 +77,11 @@
=20
return dt;
}
+
+ virtual public DataSet doSelect(string query, DataSet ds)
+ {
+ return ds;
+ }
=09
///<summary>Realiza comandos en la base de datos que no retornen.</sum=
mary>
///<param name=3D"query">El SQL para la base de datos.</param>
Modified: humano2/branches/datareader/core/db/absCrud.cs
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- humano2/branches/datareader/core/db/absCrud.cs 2005-05-20 23:38:32 UT=
C (rev 1124)
+++ humano2/branches/datareader/core/db/absCrud.cs 2005-05-20 23:38:39 UT=
C (rev 1125)
@@ -135,7 +135,6 @@
///<exception cref=3D"DataTableException">El datatable es en formato i=
ncorrecto.</exception>
virtual public int Create(int idEntityType, DataTable data)
{
- conn.BeginTransaction();
checkDataTableSingleRow(data);
DataSet structure =3D readTypeStructure(idEntityType);
=09
@@ -143,6 +142,7 @@
DataSet dataset =3D new DataSet();
dataset.Tables.Add(data);
=09
+ conn.BeginTransaction();
ArrayList idEntities =3D createAccordingToType(idEntityType, structur=
e, "main", dataset);
conn.Commit();
return Convert.ToInt32(idEntities[0]);
@@ -206,13 +206,10 @@
///<exception cref=3D"Humano2.Core.Db.SystemDataImmutableException">Cu=
ando un ID es parte del modelo base y no puede ser eliminado.</exception>
virtual public int Update(int idEntity, DataSet data, bool allowDelete=
d)
{
- conn.BeginTransaction();
=09
checkDataSet(data);
=20
int changedColNr =3D updateAccordingToType(idEntity, data);
-
- conn.Commit();
return changedColNr;
}
=09
@@ -474,7 +471,7 @@
///<exception cref=3D"DataTableException">El datatable es en formato i=
ncorrecto.</exception>
protected DataSet createAttributeSetDefaults(DataRow workRow, DataSet =
typeStr, string baseAttributeType)
{
- int newAttribId =3D getUniqueId();
+ //int newAttribId =3D getUniqueId();
=09
if(!workRow.Table.Columns.Contains("classId"))
{
@@ -489,12 +486,12 @@
//Si no tiene attibutos, por defecto isPrimary deber ser true.
if(numberOfAttributesInClass(ds, classId) =3D=3D 0)
{
- addMissingColumnToDataTable(workRow, "isPrimary", true);
+ addMissingColumnToDataTable(workRow, "isPrimary", "1");
} else {
- addMissingColumnToDataTable(workRow, "isPrimary", false);
+ addMissingColumnToDataTable(workRow, "isPrimary", "0");
}
//Agrega el nombre fisico de la columna al DataTable.
- addMissingColumnToDataTable(workRow, "sysAttName", genColumnSysName(n=
ewAttribId));
+ addMissingColumnToDataTable(workRow, "sysAttName", genColumnSysName(c=
lassId,workRow["attName"].ToString()));
=20
// Switch sobre los diferentes tipos de datos basicos.
// Si no dan algunas valores, setealos al por defecto.
@@ -534,7 +531,7 @@
///<summary>Setup autogenerated values and test for data concistency f=
or a </summary>
///<exception cref=3D"DataTableException">El datatable es en formato i=
ncorrecto.</exception>
protected void createClassSetup(DataRow workRow) {
- int newClassId =3D getUniqueId();
+ //int newClassId =3D getUniqueId();
=09
if(!workRow.Table.Columns.Contains("parentId"))
{
@@ -547,7 +544,7 @@
=09
//Agregar datos que son fijos/generado por el systema.
addMissingColumnToDataTable(workRow, "classType", (int) MetaModelCons=
ts.classTypeSolucionData);
- addMissingColumnToDataTable(workRow, "sysName", genTableSysName(Domai=
n, newClassId));
+ addMissingColumnToDataTable(workRow, "sysName", genTableSysName(Domai=
n, workRow["name"].ToString()));
}
=20
///<summary>Agrega una columna a un datatable</summary>
@@ -624,6 +621,8 @@
}
=09
int idEntity =3D createEntity(idEntityType);
+
+ // call addMissingColumnToDataTable(workRow, "sysName", genTableSysNam=
e(Domain, idEntity));
for(int t =3D 0; t < instNames.Count; t++)
{
=09
@@ -740,6 +739,7 @@
=09
//System.Console.WriteLine("WorkRow Selected");
=09
+ conn.BeginTransaction();
if( isAttribute(structure) )
{
updateAttribute(idEntity, workRow, currentData, clsId, structure);
@@ -750,7 +750,7 @@
changedColsNr =3D updateInstance(idEntity, workRow, data, currentData=
, clsId, structure);
=20
//System.Console.WriteLine("Post update instance.");
- =09
+ conn.Commit();
return changedColsNr;
}
=09
@@ -1161,7 +1161,7 @@
instValues.Add(new ArrayList());
}
=09
- // See if the column modDate exists. if it is not set, set it to now(=
)
+ // See if the column modDate exists. if it is not set, set it to getd=
ate()
string delDateName =3D escapeColumn("modDate");
int delDateIndex =3D ((ArrayList) instColumns[entityIndex]).IndexOf(d=
elDateName);
if( delDateIndex =3D=3D -1)
@@ -1531,17 +1531,21 @@
}
=09
///<summary>generate the fisical table sysName in the database</summar=
y>
- protected string genTableSysName(int domainId, int idEntity)
+ protected string genTableSysName(int domainId, string className)
{
+ string classSysName;
+ classSysName =3D genClassSysName(domainId, className);
//Mas uno para cuadrar idEntity con tableName.
- return String.Format("d{0}c{1}", domainId, idEntity+1);
+ return classSysName;
}
=20
///<summary>generate the fisical column sysName in the database</summa=
ry>
- protected string genColumnSysName(int idEntity)
+ protected string genColumnSysName(int classID, string attName)
{
+ string attSysName;
+ attSysName =3D genAttSysName(classID, attName);
//Mas uno para cuadrar idEntity con la nombre de column fisica.
- return String.Format("col{0}", idEntity+1);
+ return attSysName;
}
=09
///<summary>generate the column name for a temporary column.</summary>
@@ -1576,6 +1580,10 @@
///<returns>A unique Id.</returns>
abstract protected int getUniqueId();
=20
+ abstract protected string genClassSysName(int domainId, string classNa=
me);
+
+ abstract protected string genAttSysName(int classId, string attName);
+
///<summary>Create a new instance in the MetaModel.</summary>
///<remarks>This is a support function, use create to properly create =
an instance.</remarks>
///<param name=3D"clsId">The entityId of the class of the to be create=
d instance.</param>
Modified: humano2/branches/datareader/core/db/mssql/mssqlComplex.cs
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- humano2/branches/datareader/core/db/mssql/mssqlComplex.cs 2005-05-20 =
23:38:32 UTC (rev 1124)
+++ humano2/branches/datareader/core/db/mssql/mssqlComplex.cs 2005-05-20 =
23:38:39 UTC (rev 1125)
@@ -53,7 +53,6 @@
a.""classId"" =3D " + classId.ToString() + @" order by a.""order"=
", a.""attName""";
=09
res =3D this.doSelect(query);
-
return res;
}
=20
@@ -69,10 +68,14 @@
=09
query =3D @"select name from class where id_entity =3D " + classId.To=
String(); =09
res =3D this.doSelect(query);
-
return res;
}
=20
+ public override DataTable getColsforView(int classId)
+ {
+ string query =3D @"select top 1 ""id_entity"", ""columns"" from ""vie=
w"" where ""idClassView"" =3D "+classId+" order by id_entity";
+ return doSelect(query);
+ }
///<summary>Get the structure of a view.</summary>
///<param name=3D"viewId">The id of the view.</param>
///<returns>a datatable with the information about the view.</returns>
@@ -81,7 +84,6 @@
string query =3D "select id_entity, \"columns\", \"where\", \"groupby=
\", \"having\", \"order\", \"idClassView\", \"viewName\" "+=20
"from \"view\" where id_entity =3D " + viewId;
DataTable res =3D this.doSelect(query);
-
return res; =09
}
=09
@@ -165,7 +167,7 @@
from class c, entity e
where
c.id_entity =3D e.id_entity and
- c.""isHidden"" =3D 'f' and
+ c.""isHidden"" =3D '0' and
e.""delDate"" is null and
e.""domainId"" in (" + domain.ToString() + @", 10) order by c.""c=
lassType"" DESC, c.name";
=09
@@ -258,7 +260,7 @@
=09
NameValueCollection res =3D new NameValueCollection();
=09
- foreach (DataRow tblRow in data.Rows)
+ foreach (DataRow tblRow in data.Rows)
{
string key =3D tblRow[0].ToString();
string value =3D tblRow[1].ToString();
@@ -275,7 +277,7 @@
/// <returns>number of views. 0 if no views are asociated.</returns>
public override int NumberOfViewsForClass(int classId)
{
- string query =3D "select count(id_entity) from view where \"idClassVi=
ew\" =3D " + classId;
+ string query =3D "select count(id_entity) from [view] where \"idClass=
View\" =3D " + classId;
return Convert.ToInt32( doScalar( query ) );
}
=09
@@ -283,11 +285,16 @@
/// Set all of the attributes of the class to isPrimary =3D false.
/// </summary>
/// <param name=3D"classId">The instance Id of the class.</param>
- public override void SetNoAttributesAsPrimary(int classId)
+ public override void SetAttributeAsPrimary(int classId, int primary=
Id)
{
- string query =3D "update attribute set \"isPrimary\" =3D 'f' where=
\"classId\" =3D "+classId;
- conn.doCommand(query);
- }
+ string query =3D "update attribute set \"isPrimary\" =3D '0' where \"=
classId\" =3D "+classId;
+ conn.doCommand(query);
+ if (primaryId !=3D 0)
+ {
+ query =3D "update attribute set \"isPrimary\" =3D '1' where \"id_en=
tity\" =3D "+primaryId;
+ conn.doCommand(query);
+ }
+ }
=20
/// <summary>
/// Returns the Id of the view that is the default view for this class=
.
@@ -296,7 +303,7 @@
/// <returns>the id of the view that should be shown.</returns>
public override int getDefaultViewId(int classId)
{
- string query =3D "select \"id_entity\" from view where \"where\" is n=
ull and \"idClassView\" =3D " + classId;
+ string query =3D "select \"id_entity\" from [view] where \"where\" is=
null and \"idClassView\" =3D " + classId;
return Convert.ToInt32( doScalar( query ) );
}
=09
@@ -342,11 +349,15 @@
}
=20
string tName;
- string strSql =3D "SELECT c.sysName, c.id_entity, c.parentId " +
- "FROM entity e, class c " +=20
- "WHERE e.id_entity=3D" + colId + " " +
- "AND e.class=3Dc.id_entity";
- DataTable dt =3D conn.doSelect(strSql);
+ DataTable dt =3D this.doSelect(
+ @"select
+ class.""sysName"",
+ class.id_entity,
+ class.""parentId""
+ from entity, class
+ where
+ entity.id_entity =3D " + colId + @" and
+ entity.class =3D class.id_entity");
=09
if(dt.Rows.Count>0)
{=09
@@ -356,7 +367,7 @@
}
else
{
- tName =3D InstanceType(Convert.ToInt32(dt.Rows[0]["id_entity"]));
+ tName =3D InstanceType(Convert.ToInt32(dt.Rows[0]["parentId"]));
}
}
else
@@ -368,6 +379,7 @@
Logger.Log("InstanceType Add("+colId+","+tName+")", LogLevel.Trace);
cache.InstanceTypeCache.Add(colId,tName);
}
+ dt.Dispose();
return tName;
}
=20
@@ -377,23 +389,30 @@
string[] var;
string name;
string type;
+ int loop;
=09
tableName =3D "tempTable" + System.Guid.NewGuid().ToString();
tableName =3D tableName.Replace("-","");
=09
table.Append("drop table "+ tableName + ";");
- =09
- table.Append("create temp table "+ tableName +" (");
+ table.Append("select max(\"row\") from "+ tableName + ";");
+ table.Append("create table dbo."+ tableName +" (");
+ loop =3D 0;
foreach(string col in args)
{
var =3D col.Split(",".ToCharArray());
- name =3D var[0].Replace(".","_");
- name =3D name.Replace("\"","");
- name =3D "\"" + name + "\"";
+ name =3D var[0];
+ name =3D name.Substring(name.IndexOf(".")+1);
+ if ((loop > 0) && (name =3D=3D "id_entity")) name =3D name + loop.To=
String();
+ //name =3D var[0].Replace(".","_");
+ //name =3D name.Replace("\"","");
+ //name =3D "\"" + name + "\"";
type =3D core.Crud.AttributeTypeMapping(var[2].ToString());
+ if (type =3D=3D null) type =3D var[2].ToString();
table.Append(name + " " + type + ",");
+ loop++;
}
- table.Append("row serial);\n");
+ table.Append("\"row\" Serial);\n");
table.Append("insert into " + tableName + " (" );
=09
return table.ToString();
@@ -416,19 +435,13 @@
}
=09
string tName;
-// tName =3Dconn.doScalar(
-// @"select c."sysName"
-// from class c,attribute a
-// where (c.id_entity =3D a."classId"" and
-// a.id_entity =3D " + id + @") or
-// c.id_entity =3D " + id + @"
-// GROUP BY c.""sysName""").ToString();
- string strSql =3D "SELECT c.sysName " +=20
- "FROM class c, attribute a " +=20
- "WHERE (c.id_entity=3Da.classId AND a.id_entity=3D" + id + ") " +
- "OR c.id_entity=3D" + id + " " +=20
- "GROUP BY c.sysName";
- tName =3D conn.doScalar(strSql).ToString();
+ tName =3Dconn.doScalar(
+ @"select c.""sysName""
+ from class c,attribute a
+ where (c.id_entity =3D a.""classId"" and
+ a.id_entity =3D " + id + @") or
+ c.id_entity =3D " + id + @"
+ GROUP BY c.""sysName""").ToString();
=20
//Logger.Log("TableNameClean Add("+id+","+tName+")", LogLevel.Trace);
cache.TableNameCache.Add(id,tName);
@@ -551,7 +564,6 @@
a.id_entity =3D p.id_entity and
p.""parentPertinence"" =3D " + idColumn.ToString() + @" and
a.""classId"" =3D (select ""to"" from ""pertinence"" where ""perti=
nence"".id_entity =3D " + idColumn.ToString() + @")");
-
DataTable res =3D new DataTable();
DataColumn col =3D new DataColumn("index");
res.Columns.Add(col);
@@ -563,9 +575,9 @@
res.Columns.Add(col);
=20
int i =3D 1;
- foreach (DataRow tblRow in dt.Rows)
+ foreach(DataRow dbRow in dt.Rows)
{
- string[] row =3D {i.ToString(),tblRow[0].ToString(),tblRow[1].ToStri=
ng(),tblRow[2].ToString()};
+ string[] row =3D {i.ToString(),dbRow[0].ToString(),dbRow[1].ToString=
(),dbRow[2].ToString()};
res.Rows.Add(row);
i++;
}
@@ -583,7 +595,6 @@
res =3D GetNMRelations(Convert.ToInt32(dt.Rows[0][0]));
}
}
-
return res;
}
=20
@@ -598,9 +609,7 @@
{
string query =3D String.Format("select * from \"{0}\" x, entity e whe=
re \"{1}\" =3D {2} and x.id_entity =3D e.id_entity and e.\"delDate\" is n=
ull", tableSysName,
colSysName, valor);
- =09
- DataTable dt =3D doSelect(query);=20
- return dt;
+ return doSelect(query);
}
=09
///<summary>Testea si es una clase definicio</summary>
@@ -616,42 +625,55 @@
return false;
}
=09
- ///<summary>Convierta los 'attName' a los 'sysAttName' de un class</su=
mmary>
- ///<param name=3D"idEntity">Id del class cual contiene los columnnames=
</param>
- ///<param name=3D"names">Nombres con 'attName' de las columnas.</param=
>
- ///<returns>Las nombres 'attSysName' en el mismo orden que se ingreso =
'attName'.</returns>
+ ///<summary>Converts the 'attName' to the 'sysAttName' of a class</sum=
mary>
+ ///<param name=3D"idEntity">Id of class that contains the columnnames<=
/param>
+ ///<param name=3D"names">Names with 'attName' of the columns.</param>
+ ///<returns>The names 'attSysName' in the same order than the order of=
insertion in 'attName'.</returns>
override public string[] convertAttribNameToSysName(int idEntity, stri=
ng[] names)
{
- string namesList =3D utils.ConcatForSqlIn(names);
- string query =3D String.Format("select \"attName\", \"sysAttName\" fr=
om attribute where \"classId\" =3D {0} and \"attName\" in ({1})",
- idEntity, namesList);
- =09
- DataTable data =3D conn.doSelect(query);
- =09
- string[] sysNames =3D new string[names.Length];
- // camina sobre los resultados, y devuelve los "sysName" en el mismo =
orden de cual recibimos los "name"
- foreach (DataRow tblRow in data.Rows)
- {
- for(int i =3D 0; i < names.Length; i++)
- {
- if( names[i] =3D=3D Convert.ToString(tblRow["attName"]) )
- {
- sysNames[i] =3D Convert.ToString(tblRow["sysAttName"]);
- break;
- }
- }
- }
-=20
- return sysNames;
+ return convertAttrib(idEntity, names, "attName", "sysAttName");
}
- =20
- =20
- //TODO look at pgsql version
- override public string[] convertAttribSysNameToName(int =
idEntity, string[] names)
- {
- return null;
- }
+ =20
+ ///<summary>Converts the 'sysAttName' to the 'attName' o=
f a class</summary>
+ override public string[] convertAttribSysNameToName(int idEntity, stri=
ng[] names)
+ {
+ return convertAttrib(idEntity, names, "sysAttName", "attName");
+ }
=20
+ ///<summary>Convert the 'from' to the 'to' (name of attr=
ibute ) in the class.</summary>
+ ///<param name=3D"idEntity">Id of class that contains the columnnames<=
/param>
+ ///<param name=3D"names">Names with 'from' of the columns.</param>
+ ///<returns>The names 'to' in the same order than the order of inserti=
on in 'from'.</returns>
+ private string [] convertAttrib(int idEntity, string [] names, =
string from, string to)
+ {
+ string namesList =3D utils.ConcatForSqlIn(names);
+ string query =3D String.Format( "select \""=20
+ + to =20
+ + "\",\""
+ + from=20
+ + "\" from attribute where =
\""=20
+ + from + "\" in ({0})",
+ namesList);
+ =20
+ //Console.Write("query: " + query +"\n");
+ DataTable res =3D conn.doSelect(query);
+ =20
+ string[] resNames =3D new string[names.Length];
+ // camina sobre los resultados, y devuelve los "sysName" en=
el mismo orden de cual recibimos los "name"
+ foreach(DataRow dbRow in res.Rows)
+ {
+ for(int i =3D 0; i < names.Length; i++)
+ {
+ if( names[i] =3D=3D Convert.ToString(dbRow[from]) )
+ {
+ resNames[i] =3D Convert.ToString(dbRow[to]);
+ break;
+ }
+ }
+ }
+ return resNames;
+ }
+
///<summary>Devuelve la nombre de la tabla donde se guarde los datos.<=
/summary>
///<param name=3D"idEntity">El id del entity</param>
///<returns>Nombre de la tabla.</returns>
@@ -670,6 +692,7 @@
}
=20
#region Import flat file functions
+
/// <summary>creates the table which will be used to red from for the =
import process.</summary>
/// <param name=3D"colDefs">2 dimensional array wich contains Column n=
ame/Column definition.</param>
/// <param name=3D"tableName">The name of the table to be created.</pa=
ram>
@@ -677,7 +700,7 @@
{
string sql;
int i;
- sql =3D "create table \"" + tableName +"\" (\r\n";
+ sql =3D "create table dbo.\"" + tableName +"\" (\r\n";
for (i=3D0;i<colDefs.Length/3;i++)
{
sql =3D sql + "\"" + colDefs[i,1] + "\" " + colDefs[i,0] +",\r\n";
@@ -696,7 +719,7 @@
string sql =3D "update \"" + tableName +"\" set id_entity =3D null";
conn.doCommand(sql);
=20
- sql =3D "alter table \"" + tableName +"\" add column h2anchor Varchar=
(36) null";
+ sql =3D "alter table \"" + tableName +"\" add h2anchor Varchar(36) n=
ull";
conn.doCommand(sql);
}
=20
@@ -706,10 +729,10 @@
/// <param name=3D"tableName">A string</param>
override public void addIDCol(string tableName)
{
- string sql =3D "alter table \"" + tableName +"\" add column id_entity=
numeric null";
+ string sql =3D "alter table \"" + tableName +"\" add id_entity numer=
ic null";
conn.doCommand(sql);
=20
- sql =3D "alter table \"" + tableName +"\" add column h2anchor Varchar=
(36) null";
+ sql =3D "alter table \"" + tableName +"\" add h2anchor Varchar(36) n=
ull";
conn.doCommand(sql);
}
=20
@@ -745,7 +768,7 @@
override public void resolveSimplePertinence(string tableName, string =
tblCol, string classTableName, string attDisp)
{
string sql =3D "BEGIN;\r\n";
- sql =3D sql + "alter table \"" + tableName + "\" add column \"" + tbl=
Col +"h2ID\" integer null;\r\n";
+ sql =3D sql + "alter table \"" + tableName + "\" add \"" + tblCol +"=
h2ID\" integer null;\r\n";
sql =3D sql + "update \"" + tableName + "\" set \"" + tblCol +"h2ID\"=
=3D \"" + classTableName +"\".id_entity "
+ " from \"" + classTableName +"\" where \"" + tableName + "\".\"" +=
tblCol+"\" =3D \"" + classTableName +"\"." +attDisp+";\r\n";
sql =3D sql + "COMMIT;\r\n";
@@ -811,13 +834,11 @@
conn.BeginTransaction();
=20
string sql =3D "insert into entity (\"domainId\", class, \"createDate=
\", \"modDate\",status) " +
- " select " + domainId + "," + classId +", now(),now(), h2anchor from=
\"" +tableName +"\"; \r\n";
+ " select " + domainId + "," + classId +", getdate(),getdate(), h2anc=
hor from \"" +tableName +"\"; \r\n";
=20
sql =3D sql + "update \"" + tableName + "\" set id_entity =3D entity.=
id_entity " +
"from entity where \"" + tableName + "\".h2anchor =3D entity.status;=
\r\n";
=09
-
-
for (int i=3D0;i<clasesArr.Length/2;i++)
{
sql =3D sql + clasesArr[i,0] + "\r\n\t" + clasesArr[i,1] + "\r\n" ;
@@ -873,7 +894,17 @@
/// <return>The attribute of the pertinence attribute or "" if a=
ttributeId is not a pertinence attribute</returns>
override public string GetPertinenceForAttribute(string attribut=
eId)
{
- return "";
+ string req =3D "select \"id_entity\" from attribute where \"=
classId\" in (select \"to\" from pertinence where id_entity =3D " + Conve=
rt.ToInt32(attributeId) + ")";
+ =20
+ DataTable dt =3D doSelect(req);
+ if( (dt =3D=3D null) || (dt.Rows.Count =3D=3D 0))
+ {
+ return ""; =20
+ }
+ else
+ {
+ return Convert.ToString(dt.Rows[0]["id_entity"]); //Get =
the pertinence attribute
+ }
}
=20
/// <summary>
@@ -883,7 +914,18 @@
/// <return>user attribute name</returns>
override public string ConvertSysAttNameToUserAttName(string sys=
AttName)
{
- return "";
+ string req =3D "select \"attName\" from attribute where \"sy=
sAttName\" =3D '" + sysAttName +"'";
+ string res =3D "";
+ DataTable dt =3D doSelect(req);
+ try
+ {
+ res =3D Convert.ToString(dt.Rows[0]["attName"]);
+ }
+ catch
+ {
+ Logger.Log("ConvertSysAttName: there is no userAttName f=
or sysAttName: " + sysAttName,LogLevel.Trace);
+ }
+ return res;
}
=20
/// <summary>
@@ -893,14 +935,42 @@
/// <return>true if attribute is primary</returns>
override public bool IsPrimary(string sysAttName)
{
- return false; =20
+ string req =3D "select \"isPrimary\" from attribute where \"=
sysAttName\" =3D '" + sysAttName + "'";
+ string res =3D "";
+ DataTable dt =3D doSelect(req);
+ try
+ {
+ res =3D Convert.ToString(dt.Rows[0]["isPrimary"]);
+ }
+ catch
+ {
+ //Logger.Log("IsPrimary: problem when executing query fo=
r isPrimary flag ",LogLevel.Trace);
+ }
+ =20
+ //Logger.Log("IsPrimary: res=3D " + res,LogLevel.Trace);
+ bool isPrimary =3D (res =3D=3D "1");
+ =20
+ return isPrimary;
}
=20
override public bool IsSelfLookUp(string sysAttName)
{
- bool isPrimary =3D true;
+ string req =3D "select \"isSelfLookup\" from attribute where \"sysAtt=
Name\" =3D '" + sysAttName + "'";
+ string res =3D "";
+ DataTable dt =3D doSelect(req);
+ try
+ {
+ res =3D Convert.ToString(dt.Rows[0]["isSelfLookup"]);
+ }
+ catch
+ {
+ //Logger.Log("isSelfLookup: problem when executing query for isSelfL=
ookup flag ",LogLevel.Trace);
+ }
=20
- return isPrimary;
+ //Logger.Log("isSelfLookup: res=3D " + res,LogLevel.Trace);
+ bool IsSelfLookUp =3D (res =3D=3D "True");
+ =20
+ return IsSelfLookUp;
}
=20
/// <summary>
@@ -910,7 +980,24 @@
/// <return>true if attribute is primary</returns>
override public string [] GetParamsView(int id)
{
- return null; =20
+ string idStr =3D Convert.ToString(id);
+ string req =3D "select \"groupby\", \"columns\",\"where\",\"=
order\" from [view] where id_entity=3D" + idStr;
+ string [] res =3D new string[4];
+ =20
+ DataTable dt =3D doSelect(req);
+ try
+ {
+ res[0] =3D Convert.ToString(dt.Rows[0]["columns"]);
+ res[1] =3D Convert.ToString(dt.Rows[0]["where"]);
+ res[2] =3D Convert.ToString(dt.Rows[0]["order"]);
+ res[3] =3D Convert.ToString(dt.Rows[0]["groupby"]);
+ }
+ catch
+ {
+ Logger.Log("GetParamsView: failed query ",LogLevel.Trac=
e);
+ }
+ =20
+ return res;
}
=20
/// <summary>
@@ -920,7 +1007,25 @@
/// <return>params of the report</returns>
override public string [] GetParamsReport(int id)
{
- return null; =20
+ string idStr =3D Convert.ToString(id);
+ string req =3D "select \"columns\",\"where\",\"order\",\"gr=
oupby\",\"having\",\"idClassReport\" from report where id_entity=3D" + id=
Str;
+ string [] res =3D new string[6];
+ =20
+ DataTable dt =3D doSelect(req);
+ try
+ {
+ res[0] =3D Convert.ToString(dt.Rows[0]["columns"]);
+ res[1] =3D Convert.ToString(dt.Rows[0]["where"]);
+ res[2] =3D Convert.ToString(dt.Rows[0]["order"]);
+ res[3] =3D Convert.ToString(dt.Rows[0]["groupby"]);
+ res[4] =3D Convert.ToString(dt.Rows[0]["having"]);
+ res[5] =3D Convert.ToString(dt.Rows[0]["idClassReport"])=
;
+ }
+ catch
+ {
+ Logger.Log("GetParams Report: failed query ",LogLevel.T=
race);
+ }
+ return res;
}
=20
/// <summary>
@@ -940,17 +1045,17 @@
ArrayList alterSql =3D new ArrayList();
=20
int i =3D0;
- foreach (DataRow tblRow in tmpTable.Rows)
+ foreach(DataRow dRow in tmpTable.Rows)
{
- int attribClass =3D Convert.ToInt32(tblRow[classIdCol[0]]);
- string colname =3D tblRow[classIdCol[0]].ToString();
+ int attribClass =3D Convert.ToInt32(dRow[classIdCol[0]]);
+ string colname =3D dRow[classIdCol[0]].ToString();
string classTable =3D getTableName(attribClass);
switch (classId)
{
case(8): //attribute
//this atribute should be obtained from the tmpReader
int max =3D 50;
- alterSql.Add("alter table \"" + classTable +"\" add column \"" + t=
blRow[classIdCol[1]] + "\" Varchar(" + max + ") null");
+ alterSql.Add("alter table \"" + classTable +"\" add \"" + dRow[cl=
assIdCol[1]] + "\" Varchar(" + max + ") null");
break;
case(87): //currency:
case(9): //numeric
@@ -959,9 +1064,9 @@
int rightSide =3D 2;
int ttlSize =3D leftSide + rightSide;
if (rightSide =3D=3D 0)
- alterSql.Add("alter table \"" + classTable +"\" add column \"" + =
tblRow[classIdCol[1]] + "\" Integer null");
+ alterSql.Add("alter table \"" + classTable +"\" add \"" + dRow[c=
lassIdCol[1]] + "\" Integer null");
else
- alterSql.Add("alter table \"" + classTable +"\" add column \"" + =
tblRow[classIdCol[1]] + "\" Numeric("+ttlSize+","+rightSide+") null");
+ alterSql.Add("alter table \"" + classTable +"\" add \"" + dRow[c=
lassIdCol[1]] + "\" Numeric("+ttlSize+","+rightSide+") null");
break;
}
=20
@@ -974,6 +1079,7 @@
}
=20
#endregion=09
+
/// <summary>
/// Method buildTable
/// </summary>
@@ -1000,12 +1106,17 @@
return dt;
}
=20
+ /// <summary>
+ /// Get all class depending for the class
+ /// </summary>
+ /// <param name=3D"id_entity"></param>
+ /// <returns></returns>
public override DataTable getPertinenceByIdClass(int id_entity)
{
string query;
DataTable res;
=09
- query =3D @"select=20
+ query =3D @"select distinct
c.id_entity,c.name=20
from=20
pertinence p=20
@@ -1023,10 +1134,10 @@
string query;
DataTable res;
=09
- query =3D @"select * from attribute a
+ query =3D @"select a.id_entity from attribute a
inner join class c on c.""id_entity"" =3D a.""classId""
inner join pertinence p on p.""owner""=3Da.""id_entity""
- where a.""classId""=3D" + id_entity.ToString();
+ where a.""classId""=3D" + id_entity.ToString() + @" and p.""to"" =3D=
" + from ;
=09
res =3D this.doSelect(query);
return res;
@@ -1035,9 +1146,19 @@
=20
public override int ConvertSysAttNameToIdAttName(string sysAttName)
{
- return -1;
- }
+ string req =3D "select \"id_entity\" from attribute where \"sysAttNam=
e\" =3D '" + sysAttName +"'";
+ int res =3D -1;
+ DataTable dt =3D doSelect(req);
+ try
+ {
+ res =3D Convert.ToInt32(dt.Rows[0]["id_entity"]);
+ }
+ catch
+ {
+ Logger.Log("ConvertSysAttName: there is no userAttName for sysAttNam=
e: " + sysAttName,LogLevel.Trace);
+ }
+ return res;
+ } =20
=20
- =20
}
}
Modified: humano2/branches/datareader/core/db/mssql/mssqlConnection.cs
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- humano2/branches/datareader/core/db/mssql/mssqlConnection.cs 2005-05-=
20 23:38:32 UTC (rev 1124)
+++ humano2/branches/datareader/core/db/mssql/mssqlConnection.cs 2005-05-=
20 23:38:39 UTC (rev 1125)
@@ -21,6 +21,9 @@
public class mssqlConnection: absConnection
{
public mssqlConnection() : base() { }
+
+// protected SqlTransaction dbTrans =3D null;
+
///<summary>
///Conecta con la base de datos. Esta funcion deja dbCon con
///una connection a la base datos lista para ser utilizada.
@@ -33,6 +36,17 @@
return c;
}
=09
+// override public void BeginTransaction()
+// {
+// if(dbTransRefCount =3D=3D 0)
+// {
+// Open();
+// //System.Console.WriteLine( "Beginning transaccion." );
+// dbTrans =3D dbCon.BeginTransaction();
+// }
+// dbTransRefCount++;
+// }
+//
///<summary>Hace un select en la base de datos.</summary>
///<param name=3D"query">El SQL a ejecutarse</param>
///<returns>Los resultado del select</returns>
@@ -46,11 +60,17 @@
Humano2.Core.Db.DbUtils du =3D new DbUtils();
DataTable dt =3D new DataTable();
=09
- try=20
+ try=20
{
dbCmd.CommandText =3D query;
+ if (dbTransRefCount > 0 )
+ {
+ dbCmd.Transaction =3D ( (SqlTransaction) dbTrans) ;
+ }
SqlDataReader res =3D dbCmd.ExecuteReader( );
du.IDbReader2DataTable(dt, res);
+ res.Close();
+ dbCmd.Dispose();
Close();
return dt;
}
@@ -63,6 +83,19 @@
=20
}
=09
+ override public DataSet doSelect(string query,DataSet ds)
+ {
+ Open();
+ SqlConnection conn =3D ( (SqlConnection) dbCon );
+ =09
+ SqlDataAdapter da =3D new SqlDataAdapter(query,conn);
+ da.Fill(ds);
+ da.Dispose();
+ Close();
+ return ds;
+
+ }
+
///<summary>Realiza comandos en la base de datos que no retornen.</sum=
mary>
///<param name=3D"query">El SQL para la base de datos.</param>
///<returns>Cantidad de filas afectado por el comando.</returns>
@@ -74,7 +107,22 @@
SqlConnection conn =3D ( (SqlConnection) dbCon );
SqlCommand dbCmd =3D conn.CreateCommand( );
dbCmd.CommandText =3D query;
- int res =3D dbCmd.ExecuteNonQuery( );
+ if (dbTransRefCount > 0 )
+ {
+ dbCmd.Transaction =3D ( (SqlTransaction) dbTrans) ;
+ }
+ int res ;
+ try=20
+ {
+ res =3D dbCmd.ExecuteNonQuery( );
+ }
+ catch(Exception ex)
+ {
+ Logger.Log("Error executing query:\r\n" + query, LogLevel.Trace);
+ throw new Exception("Error executing query:\r\n" + query + "\n\r" +e=
x.Message,ex.InnerException);
+ }
+
+ dbCmd.Dispose();
Close();
return res;
}
@@ -89,16 +137,34 @@
Open();
SqlConnection conn =3D ( (SqlConnection) dbCon );
SqlCommand dbCmd =3D conn.CreateCommand( );
+ =09
dbCmd.CommandText =3D query;
- IDataReader dr =3D dbCmd.ExecuteReader( );
+ if (dbTransRefCount > 0 )
+ {
+ dbCmd.Transaction =3D ( (SqlTransaction) dbTrans) ;
+ }
+ SqlDataReader dr ;
+ try=20
+ {
+ dr =3D dbCmd.ExecuteReader( );
+ }
+ catch(Exception ex)
+ {
+ Logger.Log("Error executing query:\r\n" + query, LogLevel.Trace);
+ throw new Exception("Error executing query:\r\n" + query + "\n\r" +e=
x.Message,ex.InnerException);
+ }
//Close();
=09
if( dr.Read( ) && !Convert.IsDBNull( dr[0] ) )
{
tmpObj =3D dr[0];
+ dr.Close();
+ dbCmd.Dispose();
Close();
return tmpObj;
}
+ dr.Close();
+ dbCmd.Dispose();
Close();
return null;
}
@@ -140,8 +206,8 @@
/// <param name=3D"attsArr">A string[,]</param>
virtual public void fillTable(DataTable srcTable, string fillTable, Da=
taSet dsAtts, string[,] attsArr)
{
- SqlConnection conn =3D ( (SqlConnection) dbCon );
- =09
+ Open();
+ SqlConnection conn =3D ( (SqlConnection) dbCon );=09
SqlDataAdapter da =3D new SqlDataAdapter ( );
DataTable tgtTable =3D new DataTable( );
DataSet ds =3D new DataSet( );
@@ -185,10 +251,13 @@
=09
tgtTable.TableName =3D fillTable;
tgtTable =3D srcTable.Copy( );
+ SqlCommandBuilder SqlCB =3D new SqlCommandBuilder( da );
da.Fill( tgtTable );
tgtTable =3D srcTable.Copy( );
ds.Tables.Add( tgtTable );
+ string strXml =3D ds.GetXml( );
da.Update( tgtTable );
+ Close();
}
=09
///<summary>Recibe las opciones de Config y genera el connection strin=
g.</summary>
Modified: humano2/branches/datareader/core/db/mssql/mssqlCrud.cs
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- humano2/branches/datareader/core/db/mssql/mssqlCrud.cs 2005-05-20 23:=
38:32 UTC (rev 1124)
+++ humano2/branches/datareader/core/db/mssql/mssqlCrud.cs 2005-05-20 23:=
38:39 UTC (rev 1125)
@@ -45,7 +45,7 @@
map.Add( "pertinence", "integer" );
map.Add( "numeric", "numeric" );
map.Add( "boolean", "boolean" );
- map.Add( "dateTime", "timestamp" );
+ map.Add( "dateTime", "datetime" );
return map;
}
=09
@@ -70,7 +70,7 @@
throw new NoExistException( "The id_entity " + idEntity + " doesn't =
exist for read." );
}
=09
- conn.BeginTransaction();
+ conn.Open();
=09
//Estructuras y variables usadas en la funcion
DataSet ds =3D new DataSet( ); //El DataSet a retornar
@@ -118,6 +118,9 @@
query =3D String.Format( "select * from entity where id_entity =3D ({=
0})", idEntity );
dbCmd.CommandText =3D query;
da.SelectCommand =3D dbCmd;
+ =09
+ da.SelectCommand.Transaction =3D (SqlTransaction) conn.getTransaction=
Obj() ;
+ =09
da.Fill( ds, "entity" );
=09
//Devuelve la informacion sobre los clases cual esta en la tabla "cla=
ss".
@@ -297,19 +300,268 @@
dt.PrimaryKey =3D dc;
}
=09
- conn.Commit();
+ conn.Close();
=09
return ds;
=09
}
=09
+ /// <summary>
+ /// FIXME Modular funcion generica
+ /// </summary>
+ /// <param name=3D"idEntity"></param>
+ /// <param name=3D"withDeletes"></param>
+ /// <param name=3D"idAttributes"></param>
+ /// <returns></returns>
override public DataSet ReadStructure(int idEntity, bool withDeletes,s=
tring idAttributes)
{
- DataSet ds =3D new DataSet( );//El DataSet a retornar
+ if( !IsActive( idEntity ) )
+ {
+ throw new NoExistException( "The id_entity " + idEntity + " doesn't =
exist for read." );
+ }
+ conn.Open();
+ // conn.BeginTransaction();
+ =09
+ //Estructuras y variables usadas en la funcion
+ DataSet ds =3D new DataSet( ); //El DataSet a retornar
+ SqlCommand dbCmd =3D null; //
+ SqlDataAdapter da =3D new SqlDataAdapter( ); //Esttructuras para la c=
onexion con la BD
+ dbCmd =3D new SqlCommand( ); //
+ string query =3D null;
+ =09
+ // Cast-down a tipo mas potente.
+ SqlConnection msConn =3D ( (SqlConnection) conn.getConnObj() );
+ //Inicializo el command
+ dbCmd.Connection =3D msConn;
+ =09
+ //Buscar todos los attributos del tipo y sus padres.
+ //Para ello hay que considerar los casos en la idEntity pertenece a u=
na clase o una instancia
+ =09
+ //Lista de id's de herencia de la clase.
+ ArrayList idList =3D new ArrayList( );
+ string idListStr =3D "";
+ int[] Inh =3D getInheritanceIfIsInstance( idEntity );
+ idList.AddRange( Inh );
+ =09
+ //Verifico cual es el id de la clase base.
+ int idParent;
+ if( Inh.Length =3D=3D 0 )
+ {
+ idParent =3D idEntity;
+ idList.AddRange( getInheritanceOfType( idEntity ) );
+ }
+ else
+ {
+ idParent =3D Inh[0];
+ }
+ =09
+ =09
+ //Lo transformo a string en formato para poder usarlo en los select's
+ foreach( Object id in idList )
+ {
+ idListStr +=3D "," + id.ToString( );
+ }
+ idListStr =3D idListStr.Remove( 0, 1 );
+ =09
+ //Ingreso las tablas base
+ //Devuelve la informacion basica sobre el idEntity.
+ query =3D String.Format( "select * from entity where id_entity =3D ({=
0})", idEntity );
+ dbCmd.CommandText =3D query;
+ da.SelectCommand =3D dbCmd;
+ da.Fill( ds, "entity" );
+ =09
+ //Devuelve la informacion sobre los clases cual esta en la tabla "cla=
ss".
+ query =3D String.Format( "select * from class where id_entity in ({0}=
)", idListStr );
+ dbCmd.CommandText =3D query;
+ da.Fill( ds, "class" );
+ =09
+ string addQuery=3D"";
+ if(idAttributes.Length !=3D 0 )
+ {
+ =09
+ addQuery+=3D" and a.id_entity in(" + idAttributes + ")";
+ }=09
+
+ //Ahora obtengo la tabla arttribute con una fila para cada uno de mis=
attributos
+ //Pero recordar que es necesario buscar la herencia de cada uno de lo=
s attributos
+ //en el for de mas abajo.
+ if(withDeletes)
+ {
+ query =3D String.Format(@"select a.*,c.""sysName"" as ""refClassSysN=
ame"" ,d.""xslt"" as ""refXslt"" " +
+ @"from attribute a
+ INNER JOIN entity e ON a.id_entity =3D e.id_entity
+ INNER JOIN class c ON e.class =3D c.id_entity
+ LEFT JOIN ""displayAttribute"" d ON d.id_entity =3D a.""dis=
play""" +
+ @"where a.""classId"" in ({0})" + addQuery,
+ idListStr);
+ }=20
+ else=20
+ {
+ query =3D String.Format(@"select a.*,c.""sysName"" as ""refClassSysN=
ame"" ,d.""xslt"" as ""refXslt"" " +
+ @"from attribute a
+ INNER JOIN entity e ON a.id_entity =3D e.id_entity
+ INNER JOIN class c ON e.class =3D c.id_entity and e.""d=
elDate"" is null
+ LEFT JOIN ""displayAttribute"" d ON d.id_entity =3D a.""dis=
play""" +
+ @"where a.""classId"" in ({0})" + addQuery + @"
+ order by a.""order"", a.""attName""",
+ idListStr);
+ =09
+ }
+ =09
+ //Realizo la query y el llenado del DataSet
+ dbCmd.CommandText =3D query;
+ da.Fill( ds, "attribute" );
+ =09
+ //Son bastante autoexplicativas estas variables.
+ int index;
+ string attIds =3D null, attClassName;
+ ArrayList attInheritance;
+ DataRowCollection drc =3D ds.Tables["attribute"].Copy( ).Rows;
+ =09
+ //Una array con todos los atributos y sFillus herencias
+ ArrayList attList =3D new ArrayList( );
+ =09
+ // Camina por todos los tablas atributo buscando su herencia
+ while( drc.Count > 0 )
+ {
+ //La info sobre a el atributo
+ attClassName =3D (String)drc[0]["refClassSysName"];
+ attInheritance =3D getInheritanceByName( attClassName, "attribute" )=
;
+ =09
+ //Agrego la herencia a la lista a buscar
+ for( index =3D drc.Count - 1; index >=3D 0; index-- )
+ {
+ if( (String)drc[index]["refClassSysName"] =3D=3D attClassName )
+ {
+ string[] att =3D new string[2];
+ att[0] =3D Convert.ToString( drc[index]["id_entity"] );
+ att[1] =3D attClassName;
+ //Lo grego a la lista
+ attList.Add( att );
+ =09
+ //Agrego su herencia
+ foreach( object table in attInheritance )
+ {
+ string[] inh =3D new string[2];
+ inh[0] =3D att[0];
+ inh[1] =3D (String)table;
+ attList.Add( inh );
+ }
+ drc.RemoveAt( index );
+ }
+ }
+ }
+ =09
+ =09
+ //Creo el select para la consulta
+ string[] attTable;
+ while( attList.Count > 0 )
+ {
+ //La info sobre a el atributo
+ attTable =3D (string[])attList[0];
+ attIds =3D attTable[0];
+ attClassName =3D attTable[1];
+ attList.RemoveAt( 0 );
+ =09
+ for( index =3D attList.Count - 1; index >=3D 0; index-- )
+ {
+ attTable =3D (string[])attList[index];
+ if( attTable[1] =3D=3D attClassName )
+ {
+ attIds +=3D "," + attTable[0];
+ attList.RemoveAt( index );
+ }
+ }
+ =09
+ query =3D String.Format( @"select * from ""{0}"" where id_entity in =
({1})", attClassName, attIds );
+ dbCmd.CommandText =3D query;
+ da.Fill( ds, attClassName );
+ }
+ =09
+ //Ahora recuperamos las option para los choice y para los atributos c=
hoice de cada atributo
+ {
+ ArrayList optionGroups =3D new ArrayList( );
+ =09
+ if( ds.Tables.Contains( "choice" ) )
+ {
+ DataTable choice =3D ds.Tables["choice"];
+ =09
+ //Para los attributos choice de la tabla
+ for( int i=3D0;i < choice.Rows.Count;i++ )
+ {
+ if( !optionGroups.Contains( (Int32)choice.Rows[i]["groupType"] ) )
+ {
+ optionGroups.Add( (Int32)choice.Rows[i]["groupType"] );
+ }
+ }
+ }
+ =09
+ //-_-
+ //Para los attributos choice de los attributos de la tabla pedida
+ =09
+ //Obtenemos las tablas que se descuelgan de la tabla pedida
+ string sysNameTables =3D "";
+ for( int i=3D0;i < ds.Tables.Count;i++ )
+ {
+ if( sysNameTables =3D=3D "" )
+ {
+ sysNameTables =3D "'" + ds.Tables[i].TableName + "'";
+ }
+ else
+ {
+ sysNameTables +=3D ",'" + ds.Tables[i].TableName + "'";
+ }
+ }
+ =09
+ //La query para optener los option
+ query =3D @"select ch.""groupType""
+ from ""attribute"" as a,
+ ""class"" as c,
+ ""choice"" as ch
+ where c.""sysName"" in (" + sysNameTables + @") and
+ a.""classId"" =3D c.id_entity and
+ ch.id_entity =3D a.id_entity
+ group by ch.""groupType""";
+ =09
+ =09
+ string groups =3D "";
+ //Creamos la query
+ foreach( int group in optionGroups )
+ {
+ if( groups =3D=3D "" )
+ {
+ groups =3D group.ToString( );
+ }
+ else
+ {
+ groups +=3D "," + group.ToString( );
+ }
+ }
+ =09
+ if( groups =3D=3D "" )
+ {
+ groups =3D "null";
+ }
+ =09
+ query =3D String.Format( @"select * from ""option"" where ""group"" i=
n ({0}) or ""group"" in ({1})", groups, query );
+ dbCmd.CommandText =3D query;
+ da.Fill( ds, "option" );
+ }
+ =09
+ DataColumn[] dc;
+ foreach( DataTable dt in ds.Tables )
+ {
+ dc =3D new DataColumn[1];
+ dc[0] =3D dt.Columns["id_entity"];
+ dt.PrimaryKey =3D dc;
+ }
+ =09
+ //conn.Commit();
+ conn.Close();
+ =09
return ds;
}
=20
-
/// <summary>
/// Method ReadData
/// </summary>
@@ -344,9 +596,9 @@
inheritanceToString( idEntity ) );
=09
//Realizo la consulta
- DataTable dtAtt =3D conn.doSelect( query ) ;
+ DataTable dtAtt =3D conn.doSelect( query ); // NpgsqlDataReader drA=
tt =3D ( (NpgsqlDataReader) conn.doSelect( query ) );
//Reader para almacenar los valores de cada at tributo obtenido
- DataTable dtData;
+ DataSet dsData; //NpgsqlDataReader drData;
=09
//ToDel: dbLog.WriteToLog(query,"Init Query");
=09
@@ -354,26 +606,25 @@
StringCollection attType =3D new StringCollection( );
ArrayList attId =3D new ArrayList( );
query =3D "";
- foreach (DataRow attRow in dtAtt.Rows)
+ foreach(DataRow drAtt in dtAtt.Rows) // while( drAtt.Read( ) )
{
- =09
//Para verificar si un atribito hereda de pertinence
bool isParentPertinence =3D false;
//Si el atributo tiene herencia, verifico si hereda de un pertinence
- if( attRow[5] !=3D "" && (Int32)attRow["inheritance"] !=3D (Int32)Me=
taModelConsts.EntitiesAttribute )
+ if( drAtt[5] !=3D DBNull.Value && (Int32)drAtt["inheritance"] !=3D (=
Int32)MetaModelConsts.EntitiesAttribute ) //( !drAtt.IsDBNull( 5 ) && (In=
t32)drAtt["inheritance"] !=3D (Int32)MetaModelConsts.EntitiesAttribute )
{
- ArrayList idParentList =3D new ArrayList( getInheritance( (Int32)at=
tRow["id"] ) );
+ ArrayList idParentList =3D new ArrayList( getInheritance( (Int32)dr=
Att["id"] ) );
if( idParentList.Contains( (Int32)MetaModelConsts.EntitiesPertinenc=
e ) )
{
isParentPertinence =3D true;
}
}
=09
- //ToDel: dbLog.WriteToLog(attRow.ToString(),"Init Query");
+ //ToDel: dbLog.WriteToLog(drAtt.ToString(),"Init Query");
//verifico si el attributo es virtual, si no lo es lo agrego a la co=
nsulta
- if( (String)attRow["typeName"] =3D=3D "pertinence" || isParentPertin=
ence )
+ if( (String)drAtt["typeName"] =3D=3D "pertinence" || isParentPertine=
nce )
{
- DataTable drMetaData;
+ DataTable dtMetaData; // NpgsqlDataReader drMetaData;
//Busco la relacion y donde se encuentra.
string metaQuery =3D (
@" select co.""sysName"" as ""classOwnerName"",
@@ -387,45 +638,45 @@
where co.id_entity =3D a.""classId"" and
a.id_entity =3D p.owner and
p.""to"" =3D ct.id_entity and
- p.id_entity =3D " + attRow["id"].ToString( ) );
+ p.id_entity =3D " + drAtt["id"].ToString( ) );
=09
//ToDel: dbLog.c(metaQuery,"pertenence");
- drMetaData =3D conn.doSelect( metaQuery );
-
- //drMetaData.Read( );
+ dtMetaData =3D conn.doSelect( metaQuery ); //(NpgsqlDataReader)con=
n.doSelect( metaQuery );
+ // drMetaData.Read( );
//Recuperamos las tablas con sus respectivos link
- string ownerName =3D drMetaData.Rows[0]["ownerName"].ToString( );
- string ownerId =3D drMetaData.Rows[0]["ownerId"].ToString( );
- string className =3D drMetaData.Rows[0]["classOwnerName"].ToStrin=
g( );
- string classId =3D drMetaData.Rows[0]["classOwnerId"].ToString(=
);
- string classDName =3D drMetaData.Rows[0]["classDestinyName"].ToStr=
ing( );
- string classDId =3D drMetaData.Rows[0]["classDestinyId"].ToStrin=
g( );
+ string ownerName =3D dtMetaData.Rows[0]["ownerName"].ToString( );
+ string ownerId =3D dtMetaData.Rows[0]["ownerId"].ToString( );
+ string className =3D dtMetaData.Rows[0]["classOwnerName"].ToStrin=
g( );
+ string classId =3D dtMetaData.Rows[0]["classOwnerId"].ToString(=
);
+ string classDName =3D dtMetaData.Rows[0]["classDestinyName"].ToStr=
ing( );
+ string classDId =3D dtMetaData.Rows[0]["classDestinyId"].ToStrin=
g( );
=09
- drMetaData.Dispose();
+ //dtMetaData.Dispose( );
=09
+ =09
//Obtengo los datos segun el tipo de ralacion.
#region n:m
//Caso n:m
//dbLog.WriteToLog("|"+(String)drMetaData["ratio"]+"|","ratio");
=09
- if( (String)drMetaData.Rows[0]["ratio"] =3D=3D "n:m" )
+ if( (String)dtMetaData.Rows[0]["ratio"] =3D=3D "n:m" )
{
//Obtengo las tablas a las cuales se hace referencia
metaQuery =3D mnInfoQuery( classId, ownerId );
=09
//dbLog.WriteToLog(metaQuery,"n:m");
- drMetaData =3D conn.doSelect( metaQuery );
+ dtMetaData =3D conn.doSelect(metaQuery); //drMetaData =3D (Npgsql=
DataReader)conn.doSelect( metaQuery );
=09
- foreach(DataRow drow in drMetaData.Rows)
+ foreach(DataRow drMetaData in dtMetaData.Rows) //while( drMetaDat=
a.Read( ) )
{
// Recupero el valor para el atributo
- query +=3D ( @" ; select cd.id_entity , cd.""" + drow["displayCol=
umn"] + @"""" +
- @" from """ + drow["classDestinyName"] +
+ query +=3D ( @" ; select cd.id_entity , cd.""" + drMetaData["disp=
layColumn"] + @"""" +
+ @" from """ + drMetaData["classDestinyName"] +
@"""cd, """ + className + @""" p" +
@" where p.""" + ownerName + @""" =3D " + idEntity + @" and
- p.""" + drow["attName"] + @""" =3D cd.id_entity" + "\n" );
- attType.Add( (String)attRow["typeName"] );
- attId.Add( attRow["id"] );
+ p.""" + drMetaData["attName"] + @""" =3D cd.id_entity" + "\n" );
+ attType.Add( (String)drAtt["typeName"] );
+ attId.Add( drAtt["id"] );
}
}
#endregion
@@ -436,7 +687,7 @@
string DisplayColumn =3D (String)conn.doScalar(
@"select ""sysAttName""
from attribute
- where ""isPrimary"" =3D true and
+ where ""isPrimary"" =3D 1 and
""classId"" =3D " + classDId );
=09
// Recupero el valor para el atributo
@@ -445,35 +696,37 @@
""" + classDName + @""" as ""to"" " +
@" where owner.""" + ownerName + @""" =3D ""to"".id_entity and
owner.id_entity =3D " + idEntity + "\n" );
- attType.Add( (String)attRow["typeName"] );
- attId.Add( attRow["id"] );
+ attType.Add( (String)drAtt["typeName"] );
+ attId.Add( drAtt["id"] );
=09
}
#endregion
}
- else if( (Boolean)attRow["isVirtual"] )
+ else if( (Boolean)drAtt["isVirtual"] )
{/* Solo para capturar los virtuals*/}
else
{
// Recupero el valor para el atributo
- query +=3D ( @" ; select """ + attRow["attName"] + @"""" +
- @" from """ + attRow["className"] + @"""" +
+ query +=3D ( @" ; select """ + drAtt["attName"] + @"""" +
+ @" from """ + drAtt["className"] + @"""" +
@" where ""id_entity"" =3D " + idEntity + "\n" );
- attType.Add( (String)attRow["typeName"] );
- attId.Add( attRow["id"] );
+ attType.Add( (String)drAtt["typeName"] );
+ attId.Add( drAtt["id"] );
}
}
=09
//ToDel: dbLog.WriteToLog(query,"Big query");
=09
//realizo la consulta
- dtData =3D conn.doSelect( query );
+ query =3D query.Substring(2);
+ dsData =3D conn.doSelect( query,new DataSet() );
=09
- foreach (DataRow drow in dtData.Rows)
+ foreach(DataTable dTable in dsData.Tables)
+ {
+ foreach(DataRow drData in dTable.Rows) // while( drData.Read( ) )
{
- =09
//Recupero el valor a menos que sea nulo
- if( drow[0].ToString() =3D=3D null )
+ if(drData[0] !=3D DBNull.Value) // ( !drData.IsDBNull( 0 ) )
{
=09
//Si no existe la tabla para el tipo la creo
@@ -481,26 +734,28 @@
{
dt =3D new DataTable( attType[0] );
dt.Columns.Add( "id_entity", typeof(int) );
- dt.Columns.Add( "data", drow[0].GetType( ) );
+ dt.Columns.Add( "data", drData[0].GetType( ) );
if( attType[0] =3D=3D "pertinence" )
{
- dt.Columns.Add( "refData", drow[1].GetType( ) );
+ dt.Columns.Add( "refData", drData[1].GetType( ) );
}
ds.Tables.Add( dt );
}
=09
dr =3D ds.Tables[attType[0]].NewRow( );
dr[0] =3D attId[0];
- dr[1] =3D drow[0];
+ dr[1] =3D drData[0];
if( attType[0] =3D=3D "pertinence" )
{
- dr[2] =3D dr[1];
+ dr[2] =3D drData[1];
}
ds.Tables[attType[0]].Rows.Add( dr );
}
}
attId.RemoveAt( 0 );
attType.RemoveAt( 0 );
+ }//while(drData.NextResult( ));
+
return ds;
}
=09
@@ -521,9 +776,202 @@
/// <param name=3D"idEntity">An int</param>
/// <param name=3D"withDeletes">A bool</param>
/// <returns>A DataSet</returns>
- override public DataSet ReadData(int idEntity,bool withDeletes,string =
idsAtt)
+ override public DataSet ReadData(int idEntity, bool withDeletes,string=
idsAtt)
{
- throw new DriverException( "Not Implemented" );
+ //Verifico si existe el tipo, sino retorno una exeption
+ if( !IsActive( idEntity ) )
+ {
+ throw new NoExistException( "The id_entity " + idEntity + " doesn't =
exist for read." );
+ }
+ =09
+ //Containers de Datos
+ DataSet ds =3D new DataSet( "DataRead" );
+ DataTable dt;
+ DataRow dr;
+ string queryInAtt=3D"";
+ if (idsAtt !=3D"")
+ {
+ queryInAtt=3D "and a.id_entity in("+idsAtt+")";
+ }
+ =09
+
+ // Buscar todos los attributos del tipo.
+ string query =3D String.Format( @"select a.""id_entity"" as ""id"",
+ a.""sysAttName"" as ""attName"",
+ a.""isVirtual"" as ""isVirtual"",
+ ca.""sysName"" as ""typeName"",
+ cp.""sysName"" as ""className"",
+ cd.""parentId"" as ""inheritance""
...
[truncated message content] |