Changeset 2179 for branches/HeuristicLab.Modeling Database Backend/sources
- Timestamp:
- 07/23/09 11:01:40 (16 years ago)
- Location:
- branches/HeuristicLab.Modeling Database Backend/sources/HeuristicLab.Modeling.SQLiteBackend/3.2
- Files:
-
- 1 deleted
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Modeling Database Backend/sources/HeuristicLab.Modeling.SQLiteBackend/3.2/Algorithm.cs
r2178 r2179 1 1 using System; 2 2 using System.Collections.Generic; 3 using System.Linq; 3 4 using System.Data.Linq; 4 5 using System.Data.Linq.Mapping; … … 9 10 public class Algorithm { 10 11 public Algorithm() { 11 models = new EntitySet<Model>(attach_Model, detach_Model); 12 } 13 14 public Algorithm(string name) 15 : this() { 16 this.name = name; 17 } 18 19 public Algorithm(string name, string description) 20 : this(name) { 21 this.description = description; 12 22 } 13 23 14 24 private int id; 15 [Column(Storage = "id", DbType = "integer", IsPrimaryKey = true, IsDbGenerated = true, UpdateCheck = UpdateCheck.Never)]25 [Column(Storage = "id", IsPrimaryKey = true, IsDbGenerated = true)] 16 26 public int Id { 17 27 get { return this.id; } … … 20 30 21 31 private string name; 22 [Column(Storage = "name", DbType = "VarChar(50) NOT NULL",CanBeNull = false)]32 [Column(Storage = "name", CanBeNull = false)] 23 33 public string Name { 24 34 get { return this.name; } … … 27 37 28 38 private string description; 29 [Column(Storage = "description", DbType = "VarChar(200) NOT NULL",CanBeNull = true)]39 [Column(Storage = "description", CanBeNull = true)] 30 40 public string Description { 31 41 get { return this.description; } … … 33 43 } 34 44 35 private EntitySet<Model> models; 36 [Association(Storage = "models", ThisKey = "Id", OtherKey = "AlgorithmId")] 37 public EntitySet<Model> Models { 45 public IEnumerable<Model> ModelsCreatedByThisAlgorithm { 38 46 get { 39 if (models.HasLoadedOrAssignedValues) 40 return models; 41 return null; 47 using (ModelingDataContext ctx = new ModelingDataContext()) { 48 var x = from model in ctx.Models 49 where model.Algorithm == this 50 select model; 51 return x.AsEnumerable(); 52 } 42 53 } 43 set {44 models.Assign(value);45 }46 }47 48 private void attach_Model(Model model) {49 model.Algorithm = this;50 }51 52 private void detach_Model(Model model) {53 model.Algorithm = null;54 54 } 55 55 } -
branches/HeuristicLab.Modeling Database Backend/sources/HeuristicLab.Modeling.SQLiteBackend/3.2/HeuristicLab.Modeling.SQLiteBackend-3.2.csproj
r2178 r2179 73 73 <RequiredTargetFramework>3.5</RequiredTargetFramework> 74 74 </Reference> 75 <Reference Include="System.Data.SQLite, Version=1.0.63.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=AMD64"> 76 <SpecificVersion>False</SpecificVersion> 77 <HintPath>C:\Program Files (x86)\SQLite.NET\bin\x64\System.Data.SQLite.DLL</HintPath> 78 </Reference> 75 79 <Reference Include="System.Xml.Linq"> 76 80 <RequiredTargetFramework>3.5</RequiredTargetFramework> -
branches/HeuristicLab.Modeling Database Backend/sources/HeuristicLab.Modeling.SQLiteBackend/3.2/InputVariable.cs
r2178 r2179 13 13 } 14 14 15 public InputVariable(Model model, Variable variable) :base() {16 this.modelId = model.Id;15 public InputVariable(Model model, Variable variable) 16 : base() { 17 17 this.model.Entity = model; 18 this.variableId = variable.Id;19 18 this.variable.Entity = variable; 20 19 } 21 20 22 21 private int variableId; 23 [Column(Storage = "variableId", DbType = "Int not null",IsPrimaryKey = true)]24 public int TargetVariableId {22 [Column(Storage = "variableId", IsPrimaryKey = true)] 23 public int VariableId { 25 24 get { return this.variableId; } 26 25 private set { 27 26 if (variableId != value) { 27 if (variable.HasLoadedOrAssignedValue) 28 throw new ForeignKeyReferenceAlreadyHasValueException(); 28 29 variableId = value; 29 30 } … … 32 33 33 34 private EntityRef<Variable> variable; 34 [Association(Storage ="variable", ThisKey="variableId", OtherKey="Id", IsForeignKey=true)]35 [Association(Storage = "variable", ThisKey = "VariableId", OtherKey = "Id", IsForeignKey = true)] 35 36 public Variable Variable { 36 37 get { return variable.Entity; } … … 38 39 39 40 private int modelId; 40 [Column(Storage = "modelId", DbType = "Int not null",IsPrimaryKey = true)]41 [Column(Storage = "modelId", IsPrimaryKey = true)] 41 42 public int ModelId { 42 43 get { return this.modelId; } 43 44 private set { 44 45 if (modelId != value) { 46 if (model.HasLoadedOrAssignedValue) 47 throw new ForeignKeyReferenceAlreadyHasValueException(); 45 48 modelId = value; 46 49 } … … 49 52 50 53 private EntityRef<Model> model; 51 [Association(Storage = "model", ThisKey = " modelId", OtherKey = "Id", IsForeignKey = true)]54 [Association(Storage = "model", ThisKey = "ModelId", OtherKey = "Id", IsForeignKey = true)] 52 55 public Model Model { 53 56 get { return model.Entity; } -
branches/HeuristicLab.Modeling Database Backend/sources/HeuristicLab.Modeling.SQLiteBackend/3.2/InputVariableResult.cs
r2178 r2179 1 1 using System; 2 2 using System.Collections.Generic; 3 using System.Linq; 3 using System.Data.Linq; 4 using System.Data.Linq.Mapping; 4 5 using System.Text; 5 6 6 7 namespace HeuristicLab.Modeling.SQLiteBackend { 8 [Table(Name="InputVariableResult")] 7 9 public class InputVariableResult { 10 public InputVariableResult() { 11 this.model = default(EntityRef<Model>); 12 this.variable = default(EntityRef<Variable>); 13 this.result = default(EntityRef<Result>); 14 } 15 16 private int variableId; 17 [Column(Storage = "variableId", IsPrimaryKey = true)] 18 public int VariableId { 19 get { return this.variableId; } 20 private set { 21 if (variableId != value) { 22 if (variable.HasLoadedOrAssignedValue) 23 throw new ForeignKeyReferenceAlreadyHasValueException(); 24 variableId = value; 25 } 26 } 27 } 28 29 private EntityRef<Variable> variable; 30 [Association(Storage = "variable", ThisKey = "VariableId", OtherKey = "Id", IsForeignKey = true)] 31 public Variable Variable { 32 get { return variable.Entity; } 33 } 34 35 private int modelId; 36 [Column(Storage = "modelId", IsPrimaryKey = true)] 37 public int ModelId { 38 get { return this.modelId; } 39 private set { 40 if (modelId != value) { 41 if (model.HasLoadedOrAssignedValue) 42 throw new ForeignKeyReferenceAlreadyHasValueException(); 43 modelId = value; 44 } 45 } 46 } 47 48 private EntityRef<Model> model; 49 [Association(Storage = "model", ThisKey = "ModelId", OtherKey = "Id", IsForeignKey = true)] 50 public Model Model { 51 get { return model.Entity; } 52 } 53 54 private int resultId; 55 [Column(Storage = "resultId", IsPrimaryKey = true)] 56 public int ResultId { 57 get { return this.resultId; } 58 private set { 59 if (resultId != value) { 60 if (result.HasLoadedOrAssignedValue) 61 throw new ForeignKeyReferenceAlreadyHasValueException(); 62 resultId = value; 63 } 64 } 65 } 66 67 private EntityRef<Result> result; 68 [Association(Storage = "result", ThisKey = "ResultId", OtherKey = "Id", IsForeignKey = true)] 69 public Result Result { 70 get { return result.Entity; } 71 } 8 72 } 9 73 } -
branches/HeuristicLab.Modeling Database Backend/sources/HeuristicLab.Modeling.SQLiteBackend/3.2/Model.cs
r2178 r2179 6 6 using System.Text; 7 7 8 namespace HeuristicLab.Modeling.SQLiteBackend { 9 [Table(Name ="Model")]8 namespace HeuristicLab.Modeling.SQLiteBackend { 9 [Table(Name = "Model")] 10 10 public class Model { 11 11 public Model() { … … 14 14 } 15 15 16 public Model(Variable targetVariable, Algorithm algorithm, object data) 17 : this() { 18 this.TargetVariable = targetVariable; 19 this.Algorithm = algorithm; 20 this.data = data; 21 } 22 16 23 private int id; 17 [Column(Storage = "id", DbType = "integer", IsPrimaryKey = true, IsDbGenerated = true, UpdateCheck = UpdateCheck.Never)]24 [Column(Storage = "id", IsPrimaryKey = true, IsDbGenerated = true)] 18 25 public int Id { 19 26 get { return this.id; } … … 22 29 23 30 private object data; 24 [Column(Storage = "data", DbType = " text", CanBeNull = false)]31 [Column(Storage = "data", DbType = "varbinary(8000)", CanBeNull = false)] 25 32 public object Data { 26 33 get { return this.data; } … … 29 36 30 37 private int algorithmId; 31 [Column(Storage ="algorithmId", DbType="Int not null")]38 [Column(Storage = "algorithmId", CanBeNull = false)] 32 39 public int AlgorithmId { 33 get { return this.algorithmId; }34 private set { 35 if (algorithmId != value) {36 if (algorithm.HasLoadedOrAssignedValue)40 get { return this.algorithmId; } 41 private set { 42 if (algorithmId != value) { 43 if (algorithm.HasLoadedOrAssignedValue) 37 44 throw new ForeignKeyReferenceAlreadyHasValueException(); 38 algorithmId = value;45 algorithmId = value; 39 46 } 40 47 } 41 48 } 42 49 43 44 50 private EntityRef<Algorithm> algorithm; 45 [Association(Storage ="algorithm",ThisKey="AlgorithmId",OtherKey="Id",IsForeignKey=true)]51 [Association(Storage = "algorithm", ThisKey = "AlgorithmId", OtherKey = "Id", IsForeignKey = true)] 46 52 public Algorithm Algorithm { 47 53 get { return this.algorithm.Entity; } … … 49 55 Algorithm previousValue = algorithm.Entity; 50 56 if (previousValue != value || (!algorithm.HasLoadedOrAssignedValue)) { 51 if (previousValue == null) {57 if (previousValue != null) { 52 58 algorithm.Entity = null; 53 previousValue.Models.Remove(this);54 59 } 55 60 algorithm.Entity = value; 56 61 if (value != null) { 57 value.Models.Add(this);58 62 algorithmId = value.Id; 59 } else 60 throw new NullReferenceException("Null not allowed as value for Model.Algorithm"); 63 } 61 64 } 62 65 } … … 64 67 65 68 private int targetVariableId; 66 [Column(Storage = "targetVariableId", DbType = "Int not null")]69 [Column(Storage = "targetVariableId", CanBeNull = false)] 67 70 public int TargetVariableId { 68 71 get { return this.targetVariableId; } … … 83 86 Variable previousValue = targetVariable.Entity; 84 87 if (previousValue != value || (!targetVariable.HasLoadedOrAssignedValue)) { 85 if (previousValue == null) {88 if (previousValue != null) { 86 89 targetVariable.Entity = null; 87 previousValue.ModelsPredictingThisVariable.Remove(this);88 90 } 89 91 targetVariable.Entity = value; 90 92 if (value != null) { 91 value.ModelsPredictingThisVariable.Add(this);92 93 targetVariableId = value.Id; 93 } else 94 throw new NullReferenceException("Null not allowed as value for Model.TargetVariable"); 94 } 95 95 } 96 96 } 97 97 } 98 98 99 public IEnumerable<Variable> inputVariables {99 public IEnumerable<Variable> InputVariables { 100 100 get { 101 101 using (ModelingDataContext ctx = new ModelingDataContext()) { … … 107 107 } 108 108 } 109 110 public Dictionary<string, double> ResultValues { 111 get { 112 using (ModelingDataContext ctx = new ModelingDataContext()) { 113 var x = (from modelResult in ctx.ModelResults 114 where modelResult.Model == this 115 select modelResult) 116 .ToDictionary( 117 modelResult => modelResult.Result.Name, 118 modelResult => modelResult.Value); 119 return x; 120 } 121 } 122 } 109 123 } 110 124 } -
branches/HeuristicLab.Modeling Database Backend/sources/HeuristicLab.Modeling.SQLiteBackend/3.2/ModelResult.cs
r2178 r2179 1 1 using System; 2 2 using System.Collections.Generic; 3 using System.Linq; 3 using System.Data.Linq; 4 using System.Data.Linq.Mapping; 4 5 using System.Text; 5 6 6 7 namespace HeuristicLab.Modeling.SQLiteBackend { 8 [Table(Name = "ModelResult")] 7 9 public class ModelResult { 10 public ModelResult() { 11 this.model = default(EntityRef<Model>); 12 this.result = default(EntityRef<Result>); 13 } 14 15 public ModelResult(Model model, Result result, double value) 16 : this() { 17 this.Model = model; 18 this.Result = result; 19 this.value = value; 20 } 21 22 private double value; 23 [Column(Storage = "value", CanBeNull = false)] 24 public double Value { 25 get { return this.value; } 26 set { this.value = value; } 27 } 28 29 private int modelId; 30 [Column(Storage = "modelId", CanBeNull = false)] 31 public int ModelId { 32 get { return this.modelId; } 33 private set { 34 if (modelId != value) { 35 if (model.HasLoadedOrAssignedValue) 36 throw new ForeignKeyReferenceAlreadyHasValueException(); 37 } 38 modelId = value; 39 } 40 } 41 42 private EntityRef<Model> model; 43 [Association(Storage = "model", ThisKey = "ModelId", OtherKey = "Id", IsForeignKey = true)] 44 public Model Model { 45 get { return this.model.Entity; } 46 set { 47 Model previousValue = model.Entity; 48 if (previousValue != value || (!model.HasLoadedOrAssignedValue)) { 49 if (previousValue != null) { 50 model.Entity = null; 51 } 52 model.Entity = value; 53 if (value != null) { 54 modelId = value.Id; 55 } 56 } 57 } 58 } 59 60 private int resultId; 61 [Column(Storage = "resultId", CanBeNull = false)] 62 public int ResultId { 63 get { return this.resultId; } 64 private set { 65 if (resultId != value) { 66 if (result.HasLoadedOrAssignedValue) 67 throw new ForeignKeyReferenceAlreadyHasValueException(); 68 } 69 modelId = value; 70 } 71 } 72 73 private EntityRef<Result> result; 74 [Association(Storage = "result", ThisKey = "ResultId", OtherKey = "Id", IsForeignKey = true)] 75 public Result Result { 76 get { return this.result.Entity; } 77 set { 78 Result previousValue = result.Entity; 79 if (previousValue != value || (!model.HasLoadedOrAssignedValue)) { 80 if (previousValue != null) { 81 result.Entity = null; 82 } 83 result.Entity = value; 84 if (value != null) { 85 resultId = value.Id; 86 } 87 } 88 } 89 } 90 8 91 } 9 92 } -
branches/HeuristicLab.Modeling Database Backend/sources/HeuristicLab.Modeling.SQLiteBackend/3.2/ModelingDataContext.cs
r2178 r2179 3 3 using System.Data.Linq; 4 4 using System.Data.Linq.Mapping; 5 using System.Data.Sql; 5 6 using System.Text; 6 7 … … 8 9 public class ModelingDataContext : DataContext{ 9 10 10 public static string connectionString = @"data source=D:\Reps\HL3-Source\branches\HeuristicLab.Modeling Database Backend\sources\HeuristicLab.Modeling.SQLiteBackend\3.2\HeuristicLab.Modeling.SQLiteBackend.database";11 public static string connectionString; 11 12 12 public ModelingDataContext() : this(connectionString) { 13 public ModelingDataContext() : this(connectionString) { 13 14 } 14 15 … … 22 23 } 23 24 24 public Table<InputVariable> InputVariables { 25 get { return GetTable<InputVariable>(); } 26 } 27 28 public Table<InputVariableResult> InputVariableResults { 29 get { return GetTable<InputVariableResult>(); } 30 } 31 public Table<Model> Models { 32 get { return GetTable<Model>(); } 33 } 34 35 public Table<ModelResult> ModelResults { 36 get { return GetTable<ModelResult>(); } 25 public Table<Variable> Variables { 26 get { return GetTable<Variable>(); } 37 27 } 38 28 … … 44 34 get { return GetTable<Result>(); } 45 35 } 36 37 public Table<Model> Models { 38 get { return GetTable<Model>(); } 39 } 40 41 42 public Table<InputVariableResult> InputVariableResults { 43 get { return GetTable<InputVariableResult>(); } 44 } 45 46 public Table<ModelResult> ModelResults { 47 get { return GetTable<ModelResult>(); } 48 } 49 50 public Table<InputVariable> InputVariables { 51 get { return GetTable<InputVariable>(); } 52 } 46 53 #endregion 47 54 } -
branches/HeuristicLab.Modeling Database Backend/sources/HeuristicLab.Modeling.SQLiteBackend/3.2/Problem.cs
r2178 r2179 13 13 } 14 14 15 public Problem(Dataset dataset) 16 : this() { 17 this.dataset = dataset; 18 } 19 15 20 private int id; 16 [Column(Storage = "id", DbType = "integer",IsPrimaryKey = true, IsDbGenerated = true)]21 [Column(Storage = "id", IsPrimaryKey = true, IsDbGenerated = true)] 17 22 public int Id { 18 23 get { return this.id; } … … 21 26 22 27 private Dataset dataset; 23 [Column(Storage = "dataset", DbType = " text", CanBeNull = false)]28 [Column(Storage = "dataset", DbType = "varbinary(8000)", CanBeNull = false)] 24 29 public Dataset Dataset { 25 30 get { return this.dataset; } 26 set { this.dataset = value; }27 } 31 private set { this.dataset = value; } 32 } 28 33 } 29 34 } -
branches/HeuristicLab.Modeling Database Backend/sources/HeuristicLab.Modeling.SQLiteBackend/3.2/Result.cs
r2178 r2179 1 1 using System; 2 2 using System.Collections.Generic; 3 using System.Linq; 3 4 using System.Data.Linq; 4 5 using System.Data.Linq.Mapping; … … 11 12 } 12 13 14 public Result(string name) 15 : this() { 16 this.name = name; 17 } 18 13 19 private int id; 14 [Column(Storage = "id", DbType = "integer", IsPrimaryKey = true, IsDbGenerated = true, UpdateCheck = UpdateCheck.Never)]20 [Column(Storage = "id", IsPrimaryKey = true, IsDbGenerated = true)] 15 21 public int Id { 16 22 get { return this.id; } … … 19 25 20 26 private string name; 21 [Column(Storage = "name", DbType = "VarChar(50) NOT NULL",CanBeNull = false)]27 [Column(Storage = "name", CanBeNull = false)] 22 28 public string Name { 23 29 get { return this.name; } … … 25 31 } 26 32 33 public Dictionary<Model, double> ModelResultValues { 34 get { 35 using (ModelingDataContext ctx = new ModelingDataContext()) { 36 var x = (from modelResult in ctx.ModelResults 37 where modelResult.Result == this 38 select modelResult).ToDictionary( 39 mr => mr.Model, 40 mr => mr.Value); 41 return x; 42 } 43 } 44 } 45 27 46 } 28 47 } -
branches/HeuristicLab.Modeling Database Backend/sources/HeuristicLab.Modeling.SQLiteBackend/3.2/Variable.cs
r2178 r2179 10 10 public class Variable { 11 11 public Variable() { 12 modelsPredictingThisVariable = new EntitySet<Model>(attach_Model, detach_Model); 12 } 13 14 public Variable(string name) 15 : this() { 16 this.name = name; 13 17 } 14 18 15 19 private int id; 16 [Column(Storage = "id", DbType = "integer", IsPrimaryKey = true, IsDbGenerated = true, UpdateCheck = UpdateCheck.Never)]20 [Column(Storage = "id", IsPrimaryKey = true, IsDbGenerated = true)] 17 21 public int Id { 18 22 get { return this.id; } … … 21 25 22 26 private string name; 23 [Column(Storage = "name", DbType = "VarChar(50) NOT NULL",CanBeNull = false)]27 [Column(Storage = "name", CanBeNull = false)] 24 28 public string Name { 25 29 get { return this.name; } … … 27 31 } 28 32 29 private EntitySet<Model> modelsPredictingThisVariable; 30 [Association(Storage = "modelsPredictingThisVariable", ThisKey = "Id", OtherKey = "TargetVariableId")] 31 public EntitySet<Model> ModelsPredictingThisVariable { 33 public IEnumerable<Model> ModelsPredictingThisVariable { 32 34 get { 33 if (modelsPredictingThisVariable.HasLoadedOrAssignedValues) 34 return modelsPredictingThisVariable; 35 return null; 35 using (ModelingDataContext ctx = new ModelingDataContext()) { 36 var x = from model in ctx.Models 37 where model.TargetVariable == this 38 select model; 39 return x.AsEnumerable(); 40 } 36 41 } 37 set {38 modelsPredictingThisVariable.Assign(value);39 }40 }41 42 private void attach_Model(Model model) {43 model.TargetVariable = this;44 }45 46 private void detach_Model(Model model) {47 model.TargetVariable = null;48 42 } 49 43
Note: See TracChangeset
for help on using the changeset viewer.