public void AddDimensionLevelTest() { Dimension target = new Dimension(); Dimension d = new Dimension(); target.AddDimensionLevel(d); Assert.AreEqual(d, target.GetCoarserDimensionLevel()[0]); }
public void AddDimensionLevelTest1() { Dimension target = new Dimension(); List <Dimension> l = new List <Dimension>() { new Dimension() }; target.AddDimensionLevel(l); Assert.AreEqual(l[0], target.GetCoarserDimensionLevel()[0]); }
/// <summary> /// This takes a tablename (most likely "FACT") and loads all foreign keys, which should point to a dimension (Table + column). /// It creates a List of Dimensions and adds a dimension for each row the Database returns. It then goes on recursively /// and grabs the Table + Column of the "next" Table, meaning the one you end up at, if you roll up the cube. /// Note that in this piece of code a dimension may have MULTIPLE sub-ListOfDimensions, which should not exist in the model, /// but IF they do, it's not a problem at this point (but rather a GUI-problem) /// </summary> /// <param name="tablename">The Name of the Table whose ListOfDimensions are to be found.</param> /// <returns>A list of ListOfDimensions which, most likely, contain even more ListOfDimensions themselves.</returns> /// <author>Jannik Arndt, Bernd Nottbeck</author> public List <Dimension> GetDimensionsOf(String tablename) { DataTable referencedTables; DataTable dimensionContentDataTable; List <Dimension> resultingListOfDimensions = new List <Dimension>(); try { Open(); // every table row is a dimension referencedTables = GetReferencingDataTable(tablename); foreach (DataRow referencedTableRow in referencedTables.Rows) { // create a dimension-object (see MetaWorker.Dimension) Dimension newDimension = new Dimension(referencedTableRow["FromColumn"].ToString(), referencedTableRow["FromConstraint"].ToString(), referencedTableRow["FromTable"].ToString(), referencedTableRow["FromColumn"].ToString(), referencedTableRow["ToConstraint"].ToString(), referencedTableRow["ToTable"].ToString(), referencedTableRow["ToColumn"].ToString()); // Load the content of this table dimensionContentDataTable = GetTableContent(referencedTableRow["ToTable"].ToString()); // create DimensionContent-Objects and add them to the current dimension foreach (DataRow dimensionContentRow in dimensionContentDataTable.Rows) { string description = ""; if (dimensionContentRow.ItemArray.Count() > 2) { description = dimensionContentRow[2].ToString(); } newDimension.DimensionContentsList.Add(new DimensionContent(dimensionContentRow[0].ToString(), dimensionContentRow[1].ToString(), description)); } // save the DimensionColumnNames for generated DB-querys newDimension.DimensionColumnNames = new DimensionColumnNames(dimensionContentDataTable.Columns[0].ColumnName, dimensionContentDataTable.Columns[1].ColumnName, dimensionContentDataTable.Columns[2].ColumnName); dimensionContentDataTable.Reset(); // now recursively find all sub-ListOfDimensions of this Table and add them to the current dimension newDimension.AddDimensionLevel(GetDimensionsOf(referencedTableRow["ToTable"].ToString())); // add the current dimension to the list that will be returned eventually resultingListOfDimensions.Add(newDimension); } return(resultingListOfDimensions); } finally { Close(); } }
public void GetLevelTest() { Dimension target = new Dimension(); Dimension d1 = new Dimension(); Dimension d2 = new Dimension(); d1.AddDimensionLevel(d2); target.AddDimensionLevel(d1); List <Dimension> actual = target.GetLevel(); Assert.AreEqual(actual.Count, 3); }
public List <Dimension> GetDimensionsOf(string tablename) { // the tempTable is used to store the Database-results DataTable tempTable = new DataTable(); DataTable tempTable2 = new DataTable(); // this list will be filled and returned List <Dimension> dimensions = new List <Dimension>(); try { Open(); // see http://swp.offis.uni-oldenburg.de:8082/display/MPMDoku/Metadaten-Repository for sql-explanation MySqlCommand getMetaDataSQL = new MySqlCommand( "SELECT constraint_name as FromConstraint, table_name as FromTable, column_name as FromColumn, constraint_name as ToConstraint, " + "referenced_table_name as ToTable, referenced_column_name as ToColumn " + "FROM information_schema.key_column_usage " + "WHERE constraint_schema = '" + DBWorker.getParams().Database + "' AND constraint_name != 'PRIMARY' AND table_name = '" + tablename + "' AND referenced_table_name != 'CASE';", Connection); MySqlDataAdapter metaDataAdapter = new MySqlDataAdapter(getMetaDataSQL); // Fill the temporally used Table metaDataAdapter.Fill(tempTable); // every Database-row is a dimension foreach (DataRow row in tempTable.Rows) { // create a dimension-object (see MetaWorker.Dimension) Dimension d = new Dimension(row["FromColumn"].ToString(), row["FromConstraint"].ToString(), row["FromTable"].ToString(), row["FromColumn"].ToString(), row["ToConstraint"].ToString(), row["ToTable"].ToString(), row["ToColumn"].ToString()); // Now get the Data than can be filtered later: MySqlCommand getContentSQL = new MySqlCommand("SELECT * FROM `" + row["ToTable"].ToString() + "` LIMIT 100", Connection); /* * This SQL-Command seems pretty unsafe, why so? Well, Oracle lets you use parameters for the WHERE-part of the query, * however you can't do the same thing for the FROM-part. God knows why. */ MySqlDataAdapter contentAdapter = new MySqlDataAdapter(getContentSQL); // Fill the temporally used Table contentAdapter.Fill(tempTable2); // create DimensionContent-Objects and add them to the current dimension foreach (DataRow row2 in tempTable2.Rows) { string desc = ""; if (row2.ItemArray.Count() > 2) { desc = row2[2].ToString(); } d.DimensionContentsList.Add(new DimensionContent(row2[0].ToString(), row2[1].ToString(), desc)); } // save the DimensionColumnNames for generated DB-querys d.DimensionColumnNames = new DimensionColumnNames(tempTable2.Columns[0].ColumnName, tempTable2.Columns[1].ColumnName, tempTable2.Columns[2].ColumnName); tempTable2.Reset(); // now recursively find all sub-ListOfDimensions of this Table and add them to the current dimension d.AddDimensionLevel(GetDimensionsOf(row["ToTable"].ToString())); // add the current dimension to the list that will be returned eventually dimensions.Add(d); } return(dimensions); } finally { Close(); } }
public List<Dimension> GetDimensionsOf(string tablename) { // the tempTable is used to store the Database-results DataTable tempTable = new DataTable(); DataTable tempTable2 = new DataTable(); // this list will be filled and returned List<Dimension> dimensions = new List<Dimension>(); try { Open(); // see http://swp.offis.uni-oldenburg.de:8082/display/MPMDoku/Metadaten-Repository for sql-explanation MySqlCommand getMetaDataSQL = new MySqlCommand( "SELECT constraint_name as FromConstraint, table_name as FromTable, column_name as FromColumn, constraint_name as ToConstraint, " + "referenced_table_name as ToTable, referenced_column_name as ToColumn " + "FROM information_schema.key_column_usage " + "WHERE constraint_schema = '" + DBWorker.getParams().Database + "' AND constraint_name != 'PRIMARY' AND table_name = '" + tablename + "' AND referenced_table_name != 'CASE';", Connection); MySqlDataAdapter metaDataAdapter = new MySqlDataAdapter(getMetaDataSQL); // Fill the temporally used Table metaDataAdapter.Fill(tempTable); // every Database-row is a dimension foreach (DataRow row in tempTable.Rows) { // create a dimension-object (see MetaWorker.Dimension) Dimension d = new Dimension(row["FromColumn"].ToString(), row["FromConstraint"].ToString(), row["FromTable"].ToString(), row["FromColumn"].ToString(), row["ToConstraint"].ToString(), row["ToTable"].ToString(), row["ToColumn"].ToString()); // Now get the Data than can be filtered later: MySqlCommand getContentSQL = new MySqlCommand("SELECT * FROM `" + row["ToTable"].ToString() + "` LIMIT 100", Connection); /* * This SQL-Command seems pretty unsafe, why so? Well, Oracle lets you use parameters for the WHERE-part of the query, * however you can't do the same thing for the FROM-part. God knows why. */ MySqlDataAdapter contentAdapter = new MySqlDataAdapter(getContentSQL); // Fill the temporally used Table contentAdapter.Fill(tempTable2); // create DimensionContent-Objects and add them to the current dimension foreach (DataRow row2 in tempTable2.Rows) { string desc = ""; if (row2.ItemArray.Count() > 2) desc = row2[2].ToString(); d.DimensionContentsList.Add(new DimensionContent(row2[0].ToString(), row2[1].ToString(), desc)); } // save the DimensionColumnNames for generated DB-querys d.DimensionColumnNames = new DimensionColumnNames(tempTable2.Columns[0].ColumnName, tempTable2.Columns[1].ColumnName, tempTable2.Columns[2].ColumnName); tempTable2.Reset(); // now recursively find all sub-ListOfDimensions of this Table and add them to the current dimension d.AddDimensionLevel(GetDimensionsOf(row["ToTable"].ToString())); // add the current dimension to the list that will be returned eventually dimensions.Add(d); } return dimensions; } finally { Close(); } }