Changeset 537
- Timestamp:
- 09/03/08 20:32:02 (16 years ago)
- Location:
- trunk/sources
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.CEDMA.DB.Interfaces/HeuristicLab.CEDMA.DB.Interfaces.csproj
r416 r537 4 4 <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> 5 5 <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> 6 <ProductVersion>9.0. 21022</ProductVersion>6 <ProductVersion>9.0.30729</ProductVersion> 7 7 <SchemaVersion>2.0</SchemaVersion> 8 8 <ProjectGuid>{4F9BB789-D561-436B-B226-2BF44B7D0804}</ProjectGuid> … … 55 55 <ItemGroup> 56 56 <Compile Include="AgentEntry.cs" /> 57 <Compile Include="ItemEntry.cs" /> 57 58 <Compile Include="OperatorEntry.cs" /> 58 59 <Compile Include="ProcessStatus.cs" /> -
trunk/sources/HeuristicLab.CEDMA.DB.Interfaces/IDatabase.cs
r503 r537 26 26 using System.ServiceModel; 27 27 using System.Data; 28 using System.Linq.Expressions; 28 29 29 30 namespace HeuristicLab.CEDMA.DB.Interfaces { … … 80 81 81 82 [OperationContract] 82 OperatorEntry GetOperator(long agentId);83 OperatorEntry GetOperator(long id); 83 84 85 [OperationContract] 86 IList<ItemEntry> GetOntologyItems(); 87 88 [OperationContract] 89 IList<ItemEntry> GetItems(Guid predicate, Guid property); 90 91 [OperationContract] 92 void LinkItems(ItemEntry subject, ItemEntry predicate, ItemEntry property); 84 93 } 85 94 } -
trunk/sources/HeuristicLab.CEDMA.DB/Database.cs
r503 r537 66 66 using(DbCommand cmd = cnn.CreateCommand()) { 67 67 cmd.CommandText = "CREATE TABLE Operator (ID integer primary key autoincrement, Name text, RawData Blob)"; 68 cmd.Transaction = t; 69 cmd.ExecuteNonQuery(); 70 } 71 using(DbCommand cmd = cnn.CreateCommand()) { 72 cmd.CommandText = "CREATE TABLE Item (guid GUID primary key, RawData Blob)"; 73 cmd.Transaction = t; 74 cmd.ExecuteNonQuery(); 75 } 76 using(DbCommand cmd = cnn.CreateCommand()) { 77 cmd.CommandText = "CREATE TABLE Statement (subject GUID, predicate GUID, property GUID)"; 68 78 cmd.Transaction = t; 69 79 cmd.ExecuteNonQuery(); … … 619 629 } 620 630 #endregion 631 632 public IList<ItemEntry> GetOntologyItems() { 633 List<ItemEntry> ontologies = new List<ItemEntry>(); 634 List<ItemEntry> items = new List<ItemEntry>(); 635 rwLock.EnterReadLock(); 636 try { 637 using(DbConnection cnn = new SQLiteConnection(connectionString)) { 638 cnn.Open(); 639 using(DbCommand c = cnn.CreateCommand()) { 640 c.CommandText = "Select guid, rawdata from Item,(select subject from Statement where subject=property) where subject=guid"; 641 using(DbDataReader r = c.ExecuteReader()) { 642 while(r.Read()) { 643 ItemEntry ontology = new ItemEntry(); 644 ontology.Guid = r.GetGuid(0); 645 ontology.RawData = (byte[])r.GetValue(1); 646 ontologies.Add(ontology); 647 } 648 } 649 } 650 foreach(ItemEntry ontology in ontologies) { 651 using(DbCommand c = cnn.CreateCommand()) { 652 c.CommandText = "Select guid, rawdata from Item,(select property from Statement where subject=@ontology) where guid=property"; 653 DbParameter ontologyParam = c.CreateParameter(); 654 ontologyParam.ParameterName = "@ontology"; 655 ontologyParam.Value = ontology.Guid.ToString(); 656 c.Parameters.Add(ontologyParam); 657 using(DbDataReader r = c.ExecuteReader()) { 658 while(r.Read()) { 659 ItemEntry item = new ItemEntry(); 660 item.Guid = r.GetGuid(0); 661 item.RawData = (byte[])r.GetValue(1); 662 items.Add(item); 663 } 664 } 665 } 666 } 667 } 668 } finally { 669 rwLock.ExitReadLock(); 670 } 671 return items; 672 } 673 674 public IList<ItemEntry> GetItems(Guid predicate, Guid property) { 675 List<ItemEntry> items = new List<ItemEntry>(); 676 rwLock.EnterReadLock(); 677 try { 678 using(DbConnection cnn = new SQLiteConnection(connectionString)) { 679 cnn.Open(); 680 using(DbCommand c = cnn.CreateCommand()) { 681 c.CommandText = "Select guid, rawdata from Item,(select subject from Statement where predicate=@Predicate and property=@Property) where subject=guid"; 682 DbParameter predParam = c.CreateParameter(); 683 predParam.ParameterName = "@Predicate"; 684 predParam.Value = predicate; 685 c.Parameters.Add(predParam); 686 DbParameter propertyParam = c.CreateParameter(); 687 propertyParam.ParameterName = "@Property"; 688 propertyParam.Value = property; 689 c.Parameters.Add(propertyParam); 690 using(DbDataReader r = c.ExecuteReader()) { 691 r.Read(); 692 ItemEntry item = new ItemEntry(); 693 item.Guid = r.GetGuid(0); 694 item.RawData = (byte[])r.GetValue(1); 695 items.Add(item); 696 } 697 } 698 } 699 } finally { 700 rwLock.ExitReadLock(); 701 } 702 return items; 703 } 704 705 public void LinkItems(ItemEntry subject, ItemEntry predicate, ItemEntry property) { 706 rwLock.EnterWriteLock(); 707 try { 708 using(SQLiteConnection cnn = new SQLiteConnection(connectionString)) { 709 cnn.Open(); 710 using(SQLiteTransaction t = cnn.BeginTransaction()) { 711 ItemEntry[] items = new ItemEntry[] { subject, predicate, property }; 712 foreach(ItemEntry item in items) { 713 long n = 0; 714 using(SQLiteCommand c = cnn.CreateCommand()) { 715 c.Transaction = t; 716 c.CommandText = "select count(guid) from item where guid=@guid"; 717 DbParameter guidParam = c.CreateParameter(); 718 guidParam.ParameterName = "@guid"; 719 guidParam.Value = item.Guid.ToString(); 720 c.Parameters.Add(guidParam); 721 n = (long)c.ExecuteScalar(); 722 } 723 if(n == 0) using(SQLiteCommand c = cnn.CreateCommand()) { 724 c.Transaction = t; 725 c.CommandText = "insert into item (Guid, RawData) values (@Guid, @RawData)"; 726 DbParameter guidParam = c.CreateParameter(); 727 guidParam.ParameterName = "@Guid"; 728 guidParam.Value = item.Guid.ToString(); 729 c.Parameters.Add(guidParam); 730 DbParameter rawDataParam = c.CreateParameter(); 731 rawDataParam.ParameterName = "@RawData"; 732 rawDataParam.Value = item.RawData; 733 c.Parameters.Add(rawDataParam); 734 c.ExecuteNonQuery(); 735 } 736 } 737 using(SQLiteCommand c = cnn.CreateCommand()) { 738 c.Transaction = t; 739 c.CommandText = "insert into Statement (Subject, Predicate, Property) values (@Subject, @Predicate, @Property)"; 740 DbParameter subjectParam = c.CreateParameter(); 741 subjectParam.ParameterName = "@Subject"; 742 subjectParam.Value = subject.Guid.ToString(); 743 c.Parameters.Add(subjectParam); 744 DbParameter predParam = c.CreateParameter(); 745 predParam.ParameterName = "@Predicate"; 746 predParam.Value = predicate.Guid.ToString(); 747 c.Parameters.Add(predParam); 748 DbParameter propertyParam = c.CreateParameter(); 749 propertyParam.ParameterName = "@Property"; 750 propertyParam.Value = property.Guid.ToString(); 751 c.Parameters.Add(propertyParam); 752 c.ExecuteNonQuery(); 753 } 754 t.Commit(); 755 } 756 } 757 } finally { 758 rwLock.ExitWriteLock(); 759 } 760 } 621 761 } 622 762 }
Note: See TracChangeset
for help on using the changeset viewer.