Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r78563 - in sandbox/icl/libs/xplore/br1/sqlbrowser: . Dag gen
From: afojgo_at_[hidden]
Date: 2012-05-23 18:50:08


Author: jofaber
Date: 2012-05-23 18:50:06 EDT (Wed, 23 May 2012)
New Revision: 78563
URL: http://svn.boost.org/trac/boost/changeset/78563

Log:
Generated first DB of 10.000 Titles.
Binary files modified:
   sandbox/icl/libs/xplore/br1/sqlbrowser/Generatic1.db
Text files modified:
   sandbox/icl/libs/xplore/br1/sqlbrowser/Dag/DbType.h | 3
   sandbox/icl/libs/xplore/br1/sqlbrowser/TypeExtensibleDag.sql | 10 +
   sandbox/icl/libs/xplore/br1/sqlbrowser/TypeExtensibleDag_cpp.sql | 368 ---------------------------------------
   sandbox/icl/libs/xplore/br1/sqlbrowser/browser.cpp | 1
   sandbox/icl/libs/xplore/br1/sqlbrowser/gen/DbGenerator.cpp | 149 +++++++++++++++-
   sandbox/icl/libs/xplore/br1/sqlbrowser/gen/DbGenerator.h | 52 ++++
   sandbox/icl/libs/xplore/br1/sqlbrowser/gen/NameGenerator.cpp | 4
   sandbox/icl/libs/xplore/br1/sqlbrowser/gen/NameGenerator.h | 1
   sandbox/icl/libs/xplore/br1/sqlbrowser/gen/NumberGenerator.h | 7
   9 files changed, 211 insertions(+), 384 deletions(-)

Modified: sandbox/icl/libs/xplore/br1/sqlbrowser/Dag/DbType.h
==============================================================================
--- sandbox/icl/libs/xplore/br1/sqlbrowser/Dag/DbType.h (original)
+++ sandbox/icl/libs/xplore/br1/sqlbrowser/Dag/DbType.h 2012-05-23 18:50:06 EDT (Wed, 23 May 2012)
@@ -23,7 +23,8 @@
 namespace dag { namespace db
 {
 
-typedef unsigned int tKey;
+//JODO typedef unsigned int tKey;
+typedef int tKey;
 typedef QVector<tKey> tKeySequence;
 typedef QVector<QVariant> tVariVector;
 typedef QString tString;

Modified: sandbox/icl/libs/xplore/br1/sqlbrowser/Generatic1.db
==============================================================================
Binary files. No diff available.

Modified: sandbox/icl/libs/xplore/br1/sqlbrowser/TypeExtensibleDag.sql
==============================================================================
--- sandbox/icl/libs/xplore/br1/sqlbrowser/TypeExtensibleDag.sql (original)
+++ sandbox/icl/libs/xplore/br1/sqlbrowser/TypeExtensibleDag.sql 2012-05-23 18:50:06 EDT (Wed, 23 May 2012)
@@ -412,3 +412,13 @@
                                          and MotherAlbum.refEdgeType = 5 -- 5: Album contains Recording
   left outer join Album on MotherAlbum.refSourceVertex = Album.Key
 
+
+-- -----------------------------------------------------------------------------
+-- Select from Edges
+select refTargetVertex, group_concat(ArtistName.value) as Artist, ArtistYear.value as YoB, TitleName.value as Title
+from Edge
+ inner join VarCharObject as ArtistName on ArtistName.refObject = Edge.refSourceVertex
+ left outer join IntObject as ArtistYear on ArtistYear.refObject = Edge.refSourceVertex
+ left outer join VarCharObject as TitleName on TitleName.refObject = Edge.refTargetVertex
+group by refTargetVertex
+order by Title

Modified: sandbox/icl/libs/xplore/br1/sqlbrowser/TypeExtensibleDag_cpp.sql
==============================================================================
--- sandbox/icl/libs/xplore/br1/sqlbrowser/TypeExtensibleDag_cpp.sql (original)
+++ sandbox/icl/libs/xplore/br1/sqlbrowser/TypeExtensibleDag_cpp.sql 2012-05-23 18:50:06 EDT (Wed, 23 May 2012)
@@ -52,368 +52,8 @@
 exec("insert into Attribute values (32, 2, 'Position')");
 
 
-insert into Object values (0);
-
-insert into Object values (1);
-insert into Attribute values (1, "Name");
-insert into VarCharObject values (1, 1, "Charlie Haden");
-
-insert into Object values (2);
-insert into VarCharObject values (2, 1, "Kenny Barron");
-
-insert into Object values (3);
-insert into VarCharObject values (3, 1, "Jonny Green");
-
-insert into Object values (4);
-insert into VarCharObject values (4, 1, "Twighlight Song");
-
-insert into Object values (5);
-insert into VarCharObject values (5, 1, "Body & Soul");
-
-insert into Object values (6);
-insert into VarCharObject values (6, 1, "composed in 1995");
-
-insert into Object values (7);
-insert into VarCharObject values (7, 1, "composed in 1930");
-
-insert into Object values (8);
-insert into VarCharObject values (8, 1, "N&tC: Twighlight Song");
-
-insert into Object values (9);
-insert into VarCharObject values (9, 1, "N&tC: Body & Soul");
-
-insert into Object values (10);
-insert into VarCharObject values (10, 1, "Night & the City");
-
-
-insert into Vertex values (0, 0, 0);
-insert into Vertex values (1, 1, 1);
-insert into Vertex values (2, 1, 2);
-insert into Vertex values (3, 1, 3);
-insert into Vertex values (4, 2, 4);
-insert into Vertex values (5, 2, 5);
-insert into Vertex values (8, 3, 8);
-insert into Vertex values (9, 3, 9);
-insert into Vertex values (10, 3, 10);
-
-insert into Edge values (1, 1, 1, 4, 6);
--- 2:key 1:composed 3:J.Green 5:Body&Soul 7:comp1930
-insert into Edge values (2, 1, 3, 5, 7);
-
--- 3:key 2:performed 2:K.Barron 10:N&tC 11:rec1996
-insert into Edge values (3, 2, 2, 10, 11);
--- 4:key 7:performed 1:C.Haden 10:N&tC
-insert into Edge values (4, 2, 1, 10, 11);
-
-insert into Object values (11);
-insert into VarCharObject values (11, 1, "recoreded 1996");
-
-
--- -------------------------------------
--- Dag Related Architecture Linking All
--- D R A C U L A
--- -------------------------------------------------------
--- Dag Related Architecture Using Links All over the place
--- D R A C U L A
-
--- -----------------------------------------------------------------------------
--- Check for EdgeTypes
-"create view EdgeTypeCheck as "
-"select "
-" (select ObjectType.name from ObjectType where ObjectType.key = EdgeType.refSourceType) as SrcT, "
-" (select ObjectType.name from ObjectType where ObjectType.key = EdgeType.refRelationType) as RelT, "
-" ObjectType.name as TrgT, "
-" EdgeType.name "
-"from EdgeType "
-" inner join ObjectType on EdgeType.refTargetType = ObjectType.key"
-
--- -----------------------------------------------------------------------------
--- Named Objects
-create view NamedObjects as
-select Object.key as Obj, VarCharObject.value as Name
-from Object
- inner join VarCharObject on VarCharObject.refObject = Object.key
-
--- -----------------------------------------------------------------------------
--- Named Objects 1:1 Attributes joined horizontally.
-select Object.key as Obj, Name.value as Name, YearOfCrea.value as YoC, Position.value as Pos, Duration.value as Dur
-from Object
- inner join VarCharObject as Name on Name.refObject = Object.key and Name.refAttribute = 1
- left outer join IntObject as YearOfCrea on YearOfCrea.refObject = Object.key and YearOfCrea.refAttribute = 2
- left outer join VarCharObject as Duration on Duration.refObject = Object.key and Duration.refAttribute = 3
- left outer join VarCharObject as Position on Position.refObject = Object.key and Position.refAttribute = 4
- -- and so on ...
-
--- -----------------------------------------------------------------------------
--- Named Objects and Types 1:1 Attributes joined horizontally.
-select Object.key as Obj, Vertex.refObjectType as Type, Name.value as Name, YearOfCrea.value as YoC, Position.value as Pos, Duration.value as Dur
-from Object
- inner join Vertex on Vertex.refObject = Object.key and Type = 3
- inner join VarCharObject as Name on Name.refObject = Object.key and Name.refAttribute = 1
- left outer join IntObject as YearOfCrea on YearOfCrea.refObject = Object.key and YearOfCrea.refAttribute = 2
- left outer join VarCharObject as Duration on Duration.refObject = Object.key and Duration.refAttribute = 3
- left outer join VarCharObject as Position on Position.refObject = Object.key and Position.refAttribute = 4
-
-
--- -----------------------------------------------------------------------------
--- Vertexes
-select Vertex.key as Vtx, Object.key as Obj, ObjectType.Name as Type , Attribute.Name as Attr,
- VarCharObject.Value as Name, IntObject.value as Year
-from Object
- inner join Vertex on Vertex.refObject = Object.key
- inner join ObjectType on Vertex.refObjectType = ObjectType.key
- inner join Attribute on VarCharObject.refAttribute = Attribute.key
- inner join VarCharObject on VarCharObject.refObject = Object.key
- left outer join IntObject on IntObject.refObject = Object.key
-
--- -----------------------------------------------------------------------------
--- Edge-Objects and associated values
-select Edge.key as Edg, Object.key as Obj, EdgeType.Name as Type , Attribute.Name as Attr,
- VarCharObject.Value as Name, IntObject.value as Year
-from Object
- inner join Edge on Edge.refObject = Object.key
- inner join EdgeType on Edge.refEdgeType = EdgeType.key
- inner join Attribute on VarCharObject.refAttribute = Attribute.key
- inner join VarCharObject on VarCharObject.refObject = Object.key
- left outer join IntObject on IntObject.refObject = Object.key
-
--- -----------------------------------------------------------------------------
--- Edges
-select Edge.key as Edg, Object.key as Obj, EdgeType.Name as Type,
- VarCharObject.value as Name, IntObject.value as Year
-from Object
- inner join Edge on Edge.refObject = Object.key
- inner join EdgeType on Edge.refEdgeType = EdgeType.key
- inner join VarCharObject on VarCharObject.refObject = Object.key
- left outer join IntObject on IntObject.refObject = Object.key
-
 -- -----------------------------------------------------------------------------
--- EdgesMinimal
-create view EdgesMinimal as
-select SrcName.Value as Source, EdgeType.Name as Type, TrgName.Value as Target
-from Object
- inner join Edge on Edge.refObject = Object.key
- inner join EdgeType on Edge.refEdgeType = EdgeType.key
- inner join VarCharObject on VarCharObject.refObject = Object.key
- inner join VarCharObject as SrcName on Edge.refSourceVertex = SrcName.refObject
- inner join VarCharObject as TrgName on Edge.refTargetVertex = TrgName.refObject
-
--- -----------------------------------------------------------------------------
--- EdgesComplete
-select Edge.key as Edg, Object.key as Obj, EdgeType.Name as Type,
- VarCharObject.value as Name, IntObject.value as Year,
- Edge.refSourceVertex as Src, SrcName.Value,
- Edge.refTargetVertex as Trg, TrgName.Value
-from Object
- inner join Edge on Edge.refObject = Object.key
- inner join EdgeType on Edge.refEdgeType = EdgeType.key
- inner join VarCharObject on VarCharObject.refObject = Object.key
- inner join VarCharObject as SrcName on Edge.refSourceVertex = SrcName.refObject
- inner join VarCharObject as TrgName on Edge.refTargetVertex = TrgName.refObject
- left outer join IntObject on IntObject.refObject = Object.key
-
--- -----------------------------------------------------------------------------
--- Edges 2.
---
-select refSourceVertex as Src, VarCharObject.value as Source,
- (select EdgeType.name from EdgeType where EdgeType.key = Edge.refEdgeType) as Relation,
- (select IntObject.value
- from Edge
- inner join Object on Object.key = Edge.refObject
- inner join IntObject on Object.key = IntObject.refObject
- ) as Year,
- (select VarCharObject.value
- from Edge
- inner join Vertex on Vertex.key = Edge.refTargetVertex
- inner join Object on Object.key = Vertex.refObject
- inner join VarCharObject on Object.key = VarCharObject.refObject
- ) as Target
-from Edge
- inner join Vertex on Vertex.key = Edge.refSourceVertex
- inner join Object on Object.key = Vertex.refObject
- inner join VarCharObject on Object.key = VarCharObject.refObject
-
-
--- -----------------------------------------------------------------------------
--- Fields
-
-
--- -----------------------------------------------------------------------------
--- Artists
-select Vertex.key as Vtx, Object.key as Obj, VarCharObject.value as Name, IntObject.value as YoBirth
-from Vertex
- inner join Object on Object.key = Vertex.refObject
- inner join VarCharObject on Object.key = VarCharObject.refObject and VarCharObject.refAttribute = 1
- inner join IntObject on Object.key = IntObject.refObject and IntObject.refAttribute = 2
-where
- Vertex.refObjectType = 1
-
-
-
--- -----------------------------------------------------------------------------
--- Recordings alias Tracks
-select Object.key as Obj, Vertex.refObjectType as TKey, ObjectType.Name as Type,
- Name.value as Name, YearOfCrea.value as YoC, Position.value as Pos, Duration.value as Dur
-from Object
- inner join Vertex on Vertex.refObject = Object.key
- inner join ObjectType on Vertex.refObjectType = ObjectType.key and ObjectType.key = 3
- inner join VarCharObject as Name on Name.refObject = Object.key and Name.refAttribute = 1
- left outer join IntObject as YearOfCrea on YearOfCrea.refObject = Object.key and YearOfCrea.refAttribute = 2
- left outer join VarCharObject as Duration on Duration.refObject = Object.key and Duration.refAttribute = 3
- left outer join VarCharObject as Position on Position.refObject = Object.key and Position.refAttribute = 4
-
-
--- -----------------------------------------------------------------------------
--- Tracks, incluing album attributes via sub-selects
-select Object.key as Obj, Vertex.refObjectType as Tp, ObjectType.Name as Type,
- Name.value as Name, YearOfCrea.value as YoC, Position.value as Pos, Duration.value as Dur,
- (select Edge.refSourceVertex from Edge where refTargetVertex = Object.key and refEdgeType = 5) as Alb,
- (select VarCharObject.value from VarCharObject where VarCharObject.refObject = (select Edge.refSourceVertex from Edge where refTargetVertex = Object.key and refEdgeType = 5) and VarCharObject.refAttribute = 1) as Album,
- (select IntObject.value from IntObject where IntObject.refObject = (select Edge.refSourceVertex from Edge where refTargetVertex = Object.key and refEdgeType = 5) and IntObject.refAttribute = 2) as YoC
-from Object
- inner join Vertex on Vertex.refObject = Object.key
- inner join ObjectType on Vertex.refObjectType = ObjectType.key and ObjectType.key = 3
- inner join VarCharObject as Name on Name.refObject = Object.key and Name.refAttribute = 1
- left outer join IntObject as YearOfCrea on YearOfCrea.refObject = Object.key and YearOfCrea.refAttribute = 2
- left outer join VarCharObject as Duration on Duration.refObject = Object.key and Duration.refAttribute = 3
- left outer join VarCharObject as Position on Position.refObject = Object.key and Position.refAttribute = 4
-
--- -----------------------------------------------------------------------------
--- Tracks, incluing album attributes via joins
-select Object.key as Obj, Vertex.refObjectType as Tp, ObjectType.Name as Type,
- Name.value as Name, Position.value as Pos, Duration.value as Dur,
- (select Edge.refSourceVertex from Edge where refTargetVertex = Object.key and refEdgeType = 5) as Alb,
- Album_Name.value as Album, Album_Year.value as YoC
-from Object
- inner join Vertex on Vertex.refObject = Object.key
- inner join ObjectType on Vertex.refObjectType = ObjectType.key and ObjectType.key = 3
- inner join VarCharObject as Name on Name.refObject = Object.key and Name.refAttribute = 1
- left outer join VarCharObject as Duration on Duration.refObject = Object.key and Duration.refAttribute = 3
- left outer join VarCharObject as Position on Position.refObject = Object.key and Position.refAttribute = 4
- left outer join VarCharObject as Album_Name
- on Album_Name.refObject = (select Edge.refSourceVertex from Edge where refTargetVertex = Object.key and refEdgeType = 5)
- and Album_Name.refAttribute = 1
- left outer join IntObject as Album_Year
- on Album_Year.refObject = (select Edge.refSourceVertex from Edge where refTargetVertex = Object.key and refEdgeType = 5)
- and Album_Year.refAttribute = 2
-
-
--- -----------------------------------------------------------------------------
--- Tracks, including album attributes via joins
-select Object.key as Obj, Vertex.refObjectType as Tp, ObjectType.Name as Type
- , Name.value as Name, Position.value as Pos, Duration.value as Dur
- , (select Edge.refSourceVertex from Edge where refTargetVertex = Object.key and refEdgeType = 5) as Alb
- , Album_Name.value as Album, Album_Year.value as YoC
- , Performer_Name.value as Performer
-from Object
- inner join Vertex on Vertex.refObject = Object.key
- inner join ObjectType on Vertex.refObjectType = ObjectType.key and ObjectType.key = 3
- inner join VarCharObject as Name on Name.refObject = Object.key and Name.refAttribute = 1
- left outer join VarCharObject as Duration on Duration.refObject = Object.key and Duration.refAttribute = 3
- left outer join VarCharObject as Position on Position.refObject = Object.key and Position.refAttribute = 4
- left outer join VarCharObject as Album_Name
- on Album_Name.refObject = (select Edge.refSourceVertex from Edge where refTargetVertex = Object.key and refEdgeType = 5)
- and Album_Name.refAttribute = 1
- left outer join IntObject as Album_Year
- on Album_Year.refObject = (select Edge.refSourceVertex from Edge where refTargetVertex = Object.key and refEdgeType = 5)
- and Album_Year.refAttribute = 2
- left outer join VarCharObject as Performer_Name
- on Performer_Name.refObject = (select Edge.refSourceVertex from Edge where refTargetVertex = 12 and refEdgeType = 2)
-
-
--- -----------------------------------------------------------------------------
--- Recordings alias Tracks, incluing album attributes via joins
-(select Edge.refTargetVertex, group_concat(VarCharObject.value) as Performers
- from Edge
- inner join VarCharObject on Edge.refSourceVertex = VarCharObject.refObject
- where refTargetVertex = 12 and refEdgeType = 2)
-
--- -----------------------------------------------------------------------------
--- Tracks, including album attributes via joins
-select Object.key as Obj, Vertex.refObjectType as Tp, ObjectType.Name as Type
- , Name.value as Name, Position.value as Pos, Duration.value as Dur
- , (select Edge.refSourceVertex from Edge where refTargetVertex = Object.key and refEdgeType = 5) as Alb
- , Album_Name.value as Album, Album_Year.value as YoC
- , Performer_Name.value as Performer
- , (select Edge.refTargetVertex, group_concat(VarCharObject.value) as Performers
- from Edge
- inner join VarCharObject on Edge.refSourceVertex = VarCharObject.refObject
- where refTargetVertex = 12 and refEdgeType = 2)
-
-from Object
- inner join Vertex on Vertex.refObject = Object.key
- inner join ObjectType on Vertex.refObjectType = ObjectType.key and ObjectType.key = 3
- inner join VarCharObject as Name on Name.refObject = Object.key and Name.refAttribute = 1
- left outer join VarCharObject as Duration on Duration.refObject = Object.key and Duration.refAttribute = 3
- left outer join VarCharObject as Position on Position.refObject = Object.key and Position.refAttribute = 4
- left outer join VarCharObject as Album_Name
- on Album_Name.refObject = (select Edge.refSourceVertex from Edge where refTargetVertex = Object.key and refEdgeType = 5)
- and Album_Name.refAttribute = 1
- left outer join IntObject as Album_Year
- on Album_Year.refObject = (select Edge.refSourceVertex from Edge where refTargetVertex = Object.key and refEdgeType = 5)
- and Album_Year.refAttribute = 2
- left outer join VarCharObject as Performer_Name
- on Performer_Name.refObject = (select Edge.refSourceVertex from Edge where refTargetVertex = 12 and refEdgeType = 2)
-
-
--- -----------------------------------------------------------------------------
--- Tracks, including album attributes via joins (*)
-select Object.key as Obj, Vertex.refObjectType as Tp, ObjectType.Name as Type
- , Name.value as Name, Position.value as Pos, Duration.value as Dur
- , (select Edge.refSourceVertex from Edge where refTargetVertex = Object.key and refEdgeType = 5) as Alb
- , Album_Name.value as Album, Album_Year.value as YoC
- , Performer_Name.value as Performer
- , (select group_concat(VarCharObject.value)
- from Edge
- inner join VarCharObject on Edge.refSourceVertex = VarCharObject.refObject
- where refTargetVertex = (select Edge.refSourceVertex from Edge
- where refTargetVertex = Object.key and refEdgeType = 5)
- and refEdgeType = 2
- ) as AlbumArtists
-from Object
- inner join Vertex on Vertex.refObject = Object.key
- inner join ObjectType on Vertex.refObjectType = ObjectType.key and ObjectType.key = 3
- inner join VarCharObject as Name on Name.refObject = Object.key and Name.refAttribute = 1
- left outer join VarCharObject as Duration on Duration.refObject = Object.key and Duration.refAttribute = 3
- left outer join VarCharObject as Position on Position.refObject = Object.key and Position.refAttribute = 4
- left outer join VarCharObject as Album_Name
- on Album_Name.refObject = (select Edge.refSourceVertex from Edge where refTargetVertex = Object.key and refEdgeType = 5)
- and Album_Name.refAttribute = 1
- left outer join IntObject as Album_Year
- on Album_Year.refObject = (select Edge.refSourceVertex from Edge where refTargetVertex = Object.key and refEdgeType = 5)
- and Album_Year.refAttribute = 2
- left outer join VarCharObject as Performer_Name
- on Performer_Name.refObject = (select Edge.refSourceVertex from Edge where refTargetVertex = 12 and refEdgeType = 2)
-
-
--- -----------------------------------------------------------------------------
--- Experimental views: Checking how we can structure selects based on Edges
--- using Sql-Views to make them more managable.
--- -----------------------------------------------------------------------------
--- View Album
-create view Album as
-select -- Edge.refSourceVertex as ArtistKey,
- Vertex.key as Key, AlbumTitle.value as Name, group_concat(Performer.value) as Artists, YearOfCreation.value as YoC
-from Vertex
- inner join Edge on Edge.refTargetVertex = Vertex.key
- and Edge.refEdgeType = 2 -- 2: Artist (performs on) Album
- left outer join VarCharObject as AlbumTitle on AlbumTitle.refObject = vertex.key and AlbumTitle.refAttribute = 1
- left outer join VarCharObject as Performer on Performer.refObject = Edge.refSourceVertex
- left outer join IntObject as YearOfCreation on YearOfCreation.refObject = Vertex.key
-group by Vertex.key
-
--- -----------------------------------------------------------------------------
--- View Track
--- create view Track as
-select -- Edge.refSourceVertex as ArtistKey,
- Vertex.key as TrkKey, TrackName.value
- , MotherAlbum.refSourceVertex as MAlbKey, Album.Key as AlbKey
- , Album.Name as AlbumName, Album.Artists as AlbumArtists
-from Vertex
- inner join VarCharObject as TrackName on TrackName.refObject = Vertex.key
- and TrackName.refAttribute = 1
- and Vertex.refObjectType = 3
- left outer join Edge as MotherAlbum on MotherAlbum.refTargetVertex = Vertex.key
- and MotherAlbum.refEdgeType = 5 -- 5: Album contains Recording
- left outer join Album on MotherAlbum.refSourceVertex = Album.Key
-
+-- 1.000 Artist, 10.000 Titles with Names and YoCs
+-- ca. 01:50 h time of generation
+-- Final size: 1.215 kB. 1,215 MB
+-- 111 Bytes per object.
\ No newline at end of file

Modified: sandbox/icl/libs/xplore/br1/sqlbrowser/browser.cpp
==============================================================================
--- sandbox/icl/libs/xplore/br1/sqlbrowser/browser.cpp (original)
+++ sandbox/icl/libs/xplore/br1/sqlbrowser/browser.cpp 2012-05-23 18:50:06 EDT (Wed, 23 May 2012)
@@ -171,6 +171,7 @@
 {
     //return execScript(); // Execute a script containing of multiple sql-statements
     //return casualTests();
+ emit statusMessage(tr("Generating DB ..."));
     return generateDb();
 }
 

Modified: sandbox/icl/libs/xplore/br1/sqlbrowser/gen/DbGenerator.cpp
==============================================================================
--- sandbox/icl/libs/xplore/br1/sqlbrowser/gen/DbGenerator.cpp (original)
+++ sandbox/icl/libs/xplore/br1/sqlbrowser/gen/DbGenerator.cpp 2012-05-23 18:50:06 EDT (Wed, 23 May 2012)
@@ -6,14 +6,28 @@
 #include <QtGui>
 #include <QString>
 #include <QMessageBox>
+#include "gen/NumberGenerator.h"
 #include "gen/DbGenerator.h"
 
 using namespace gen;
+using namespace boost::icl;
 
 
-bool DbGenerator::generate()
+void DbGenerator::configure()
+{
+ m_iArtists = 1000;
+ m_iTitles = 10000;
+}
+
+void DbGenerator::clear()
 {
     m_aFailingSql = tString();
+ m_aArtists.clear();
+ m_aTitles.clear();
+}
+
+bool DbGenerator::generate()
+{
 
     if(!m_aDb.open())
     {
@@ -22,10 +36,12 @@
     }
 
     //------------------------------------------
- clean();
+ clearDb();
     generateTables();
-
     generateTypeData();
+
+ generateObjects();
+ generateRelationships();
     //------------------------------------------
 
     if(m_aFailingSql.isEmpty())
@@ -35,7 +51,7 @@
 }
 
 
-bool DbGenerator::exec(const char* sql)
+bool DbGenerator::exec(const tString& sql)
 {
     if(!m_aQuery.exec(sql))
     {
@@ -59,7 +75,7 @@
 
 
 
-void DbGenerator::clean()
+void DbGenerator::clearDb()
 {
 
     exec("drop view Album" );
@@ -150,12 +166,125 @@
     );
 }
 
+void DbGenerator::generateObjects()
+{
+ generateArtists(m_iArtists);
+ generateTitles(m_iTitles);
+}
+
+void DbGenerator::generateRelationships()
+{
+ generateArtistComposedTitle();
+}
+
+
+dag::db::tKey DbGenerator::insertObject()
+{
+ exec("insert into Object values (NULL)");
+ return m_aQuery.lastInsertId().toInt();
+}
+
+void DbGenerator::insertVertex(tKey aKey, tObjectType eType)
+{
+ exec(tString("insert into Vertex values (%1, %2)").arg(aKey).arg(eType));
+}
+
+void DbGenerator::insertEdge(tKey aEdgeKey, tKey aEdgeTypeKey, tKey aSrcKey, tKey aTrgKey)
+{
+ exec(tString("insert into Edge values (%1, %2, %3, %4)")
+ .arg(aEdgeKey).arg(aEdgeTypeKey).arg(aSrcKey).arg(aTrgKey));
+}
+
+void DbGenerator::insertVarCharObject(tKey aKey, tAttribute eAttr, const tString& value)
+{
+ exec(tString("insert into VarCharObject values (%1, %2, '%3')").arg(aKey).arg(eAttr).arg(value));
+}
+
+void DbGenerator::insertIntObject(tKey aKey, tAttribute eAttr, int value)
+{
+ exec(tString("insert into IntObject values (%1, %2, %3)").arg(aKey).arg(eAttr).arg(value));
+}
 
-void DbGenerator::generateArtist()
+dag::db::tKey DbGenerator::generateArtist()
 {
- tKey aKey = generateObject();
- generateVertex(aKey, a_artist);
- generateVarCharObject(aKey, A_Name, m_aSomeName());
- generateIntObject(aKey, A_Year, gen::IntGenerator(1940, 1990)());
+ tKey aKey = insertObject();
+ insertVertex(aKey, a_artist);
+ insertVarCharObject(aKey, A_Name, m_aSomeName("A_"));
+ insertIntObject(aKey, A_Year, gen::IntGenerator(1940, 1990)());
+ return aKey;
 }
 
+
+dag::db::tKey DbGenerator::generateTitle()
+{
+ tKey aKey = insertObject();
+ insertVertex(aKey, a_title);
+ insertVarCharObject(aKey, A_Name, m_aSomeName("T_"));
+ insertIntObject(aKey, A_Year, gen::IntGenerator(1960, 2012)());
+ return aKey;
+}
+
+void DbGenerator::generateArtists(int count)
+{
+ for(int idx=0; idx<count; idx++)
+ m_aArtists.add(generateArtist());
+}
+
+void DbGenerator::generateTitles(int count)
+{
+ for(int idx=0; idx<count; idx++)
+ m_aTitles.add(generateTitle());
+}
+
+
+void DbGenerator::generateArtistComposedTitle()
+{
+ tKey aKey = insertObject();
+ makeComposersRange();
+
+ //Every title needs at least one composer.
+ for( tKeySet::element_iterator it = elements_begin(m_aTitles)
+ ; it != elements_end(m_aTitles); ++it)
+ {
+ assignComposers(*it);
+ }
+
+}
+
+void DbGenerator::makeComposersRange()
+{
+ //Not all artists are composers
+ tInterval artistsRange = hull(m_aArtists);
+ tKey fst = first(artistsRange);
+ tKey lst = fst + size(artistsRange)/2;
+ m_aComposersRange = tInterval::closed(fst, lst);
+}
+
+void DbGenerator::assignComposers(tKey aTitle)
+{
+ gen::IntGenerator someArtist(m_aComposersRange);
+ tKey aArtist1 = someArtist();
+
+ tKey aEdgeKey1 = insertObject();
+ insertEdge(aEdgeKey1, R_artist_composed_title, aArtist1, aTitle);
+
+ if(IntGenerator(1,3)() == 3)
+ {
+ tKey aArtist2 = someArtist();
+ if(aArtist2 != aArtist1)
+ {
+ tKey aEdgeKey2 = insertObject();
+ insertEdge(aEdgeKey2, R_artist_composed_title, aArtist2, aTitle);
+ if(IntGenerator(1,3)() == 3)
+ {
+ tKey aEdgeKey3 = insertObject();
+ tKey aArtist3 = someArtist();
+ if(aArtist3 != aArtist1 && aArtist3 != aArtist2)
+ insertEdge(aEdgeKey3, R_artist_composed_title, aArtist3, aTitle);
+ }
+
+ }
+ }
+}
+
+

Modified: sandbox/icl/libs/xplore/br1/sqlbrowser/gen/DbGenerator.h
==============================================================================
--- sandbox/icl/libs/xplore/br1/sqlbrowser/gen/DbGenerator.h (original)
+++ sandbox/icl/libs/xplore/br1/sqlbrowser/gen/DbGenerator.h 2012-05-23 18:50:06 EDT (Wed, 23 May 2012)
@@ -6,6 +6,7 @@
 #pragma once
 
 
+#include <boost/icl/interval_set.hpp>
 
 #include <QtSql>
 #include <QSqlDatabase.h>
@@ -23,6 +24,8 @@
     typedef dag::db::tKey tKey;
     typedef unsigned int tObjectType;
     typedef unsigned int tAttribute;
+ typedef boost::icl::interval_set<tKey> tKeySet;
+ typedef tKeySet::interval_type tInterval;
 
     enum {
         a_text = 1
@@ -49,6 +52,14 @@
     };
 
     enum {
+ R_artist_composed_title = 1
+ , R_artist_performed_record = 2
+ , R_title_recorded_as_record = 3
+ , R_record_located_at_url = 4
+ , R_album_contains_record = 5
+ };
+
+ enum {
         minSyllables = 2
       , maxSyllables = 5
     };
@@ -56,18 +67,28 @@
     DbGenerator(const QSqlDatabase& db):
         m_aDb(db), m_aQuery("", m_aDb)
       , m_aSomeName(minSyllables, maxSyllables)
- {}
+ {
+ configure();
+ }
 
+ void clear();
+ void clearDb();
     bool generate();
- void clean();
     void generateTables();
-
     void generateTypeData();
-
     void generateTypeViews();
 
+ void generateObjects();
+ void generateRelationships();
+
+ void generateArtists(int);
+ void generateTitles(int);
+
+ void generateArtistComposedTitle();
+
 private:
- bool exec(const char* sql);
+ void configure();
+ bool exec(const tString& sql);
 
     //void generateTypeData();
     void generateTypeTraits();
@@ -75,18 +96,31 @@
     void generateEdgeTypes();
     void generateAttributes();
 
- tKey generateObject();
- void generateVertex(tKey aKey, tObjectType eObjectType);
- void generateVarCharObject(tKey aKey, );
+ tKey insertObject();
+ void insertVertex(tKey aKey, tObjectType eObjectType);
+ void insertVarCharObject(tKey aKey, tAttribute eAttr, const tString& value);
+ void insertIntObject(tKey aKey, tAttribute eAttr, int value);
+ void insertEdge(tKey aEdgeKey, tKey aEdgeTypeKey, tKey aSrcKey, tKey aTrgKey);
+
+ tKey generateArtist();
+ tKey generateTitle();
 
- void generateArtist();
+ void makeComposersRange();
+ void assignComposers(tKey aTitle);
 
 private:
+ int m_iArtists;
+ int m_iTitles;
+
     QSqlDatabase m_aDb;
     QSqlQuery m_aQuery;
     QSqlError m_aLastError;
     tString m_aFailingSql;
     NameGenerator m_aSomeName;
+
+ tKeySet m_aArtists;
+ tInterval m_aComposersRange;
+ tKeySet m_aTitles;
 };
 
 } // namespace data

Modified: sandbox/icl/libs/xplore/br1/sqlbrowser/gen/NameGenerator.cpp
==============================================================================
--- sandbox/icl/libs/xplore/br1/sqlbrowser/gen/NameGenerator.cpp (original)
+++ sandbox/icl/libs/xplore/br1/sqlbrowser/gen/NameGenerator.cpp 2012-05-23 18:50:06 EDT (Wed, 23 May 2012)
@@ -90,3 +90,7 @@
     return someName;
 }
 
+tString NameGenerator::operator()(const tString& prefix)const
+{
+ return prefix + (*this)();
+}

Modified: sandbox/icl/libs/xplore/br1/sqlbrowser/gen/NameGenerator.h
==============================================================================
--- sandbox/icl/libs/xplore/br1/sqlbrowser/gen/NameGenerator.h (original)
+++ sandbox/icl/libs/xplore/br1/sqlbrowser/gen/NameGenerator.h 2012-05-23 18:50:06 EDT (Wed, 23 May 2012)
@@ -26,6 +26,7 @@
         : m_aPrefix(), m_aDist(min, max){}
 
     tString operator()()const;
+ tString operator()(const tString& prefix)const;
 
 
     static int syllablesBeginCount();

Modified: sandbox/icl/libs/xplore/br1/sqlbrowser/gen/NumberGenerator.h
==============================================================================
--- sandbox/icl/libs/xplore/br1/sqlbrowser/gen/NumberGenerator.h (original)
+++ sandbox/icl/libs/xplore/br1/sqlbrowser/gen/NumberGenerator.h 2012-05-23 18:50:06 EDT (Wed, 23 May 2012)
@@ -10,6 +10,8 @@
 #include <boost/random/uniform_int_distribution.hpp>
 #include <boost/random/uniform_real_distribution.hpp>
 
+#include <boost/icl/interval.hpp>
+
 #include <QString.h>
 
 namespace gen
@@ -26,7 +28,12 @@
 class IntGenerator
 {
 public:
+ //typedef boost::icl::interval_type_default<int>::type tInterval;
+ typedef boost::icl::interval_type_default<int>::type tInterval;
+
     IntGenerator(int min, int max): m_aDist(min, max){}
+ explicit IntGenerator(const tInterval& range):
+ m_aDist(first(range), last(range)){}
 
     int operator()()const { return m_aDist(g_aRandomGenerator); }
 


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk