#region License Information
/* HeuristicLab
* Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
*
* This file is part of HeuristicLab.
*
* HeuristicLab is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* HeuristicLab is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with HeuristicLab. If not, see .
*/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using HeuristicLab.Hive.Contracts.BusinessObjects;
using HeuristicLab.Hive.Server.DataAccess;
namespace HeuristicLab.Hive.Server.LINQDataAccess {
public class HiveExperimentDao : BaseDao, IHiveExperimentDao {
#region IGenericDao Members
HiveExperimentDto IGenericDao.FindById(Guid id) {
return (from he in Context.HiveExperiments
where he.HiveExperimentId.Equals(id)
select EntityToDto(he, null)).SingleOrDefault();
}
IEnumerable IGenericDao.FindAll() {
return (from he in Context.HiveExperiments
select EntityToDto(he, null)).ToList();
}
public HiveExperimentDto Insert(HiveExperimentDto bObj) {
HiveExperiment he = DtoToEntity(bObj, null);
Context.HiveExperiments.InsertOnSubmit(he);
CommitChanges();
bObj.Id = he.HiveExperimentId;
return bObj;
}
public void Delete(Guid id) {
HiveExperiment he = Context.HiveExperiments.SingleOrDefault(h => h.HiveExperimentId.Equals(id));
Context.HiveExperiments.DeleteOnSubmit(he);
Context.SubmitChanges();
}
public void Update(HiveExperimentDto bObj) {
HiveExperiment he = Context.HiveExperiments.SingleOrDefault(h => h.HiveExperimentId.Equals(bObj.Id));
DtoToEntity(bObj, he);
CommitChanges();
}
public IEnumerable FindAllByUserId(Guid userId) {
return (from he in Context.HiveExperiments
where he.UserId.Equals(userId)
select EntityToDto(he, null)).ToList();
}
#endregion
public override HiveExperiment DtoToEntity(HiveExperimentDto source, HiveExperiment target) {
if (source == null)
return null;
if (target == null)
target = new HiveExperiment();
target.HiveExperimentId = source.Id;
target.Name = source.Name;
target.Description = source.Description;
target.ResourceIds = source.ResourceIds;
target.UserId = source.UserId;
target.RootJobId = source.RootJobId;
//if (source.RootJobId.HasValue) {
// var jobDao = new JobDao();
// target.RootJob = jobDao.DtoToEntity(jobDao.FindById(source.RootJobId.Value), null);
//} else {
// target.RootJob = null;
//}
return target;
}
public override HiveExperimentDto EntityToDto(HiveExperiment source, HiveExperimentDto target) {
if (source == null)
return null;
if (target == null)
target = new HiveExperimentDto();
target.Id = source.HiveExperimentId;
target.Name = source.Name;
target.Description = source.Description;
target.ResourceIds = source.ResourceIds;
target.UserId = source.UserId;
target.RootJobId = source.RootJobId;
return target;
}
}
}