/*
* Copyright (C) 2013-2016 Emeric Poupon
*
* This file is part of LMS.
*
* LMS 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.
*
* LMS 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 LMS. If not, see .
*/
#include "Cluster.hpp"
#include "Artist.hpp"
#include "Release.hpp"
#include "ScanSettings.hpp"
#include "Session.hpp"
#include "SqlQuery.hpp"
#include "Track.hpp"
namespace Database {
Cluster::Cluster()
{
}
Cluster::Cluster(Wt::Dbo::ptr type, std::string name)
: _name(std::string(name, 0, _maxNameLength)),
_clusterType(type)
{
}
Cluster::pointer
Cluster::create(Session& session, Wt::Dbo::ptr type, std::string name)
{
session.checkUniqueLocked();
Cluster::pointer res {session.getDboSession().add(std::make_unique(type, name))};
session.getDboSession().flush();
return res;
}
std::vector
Cluster::getAll(Session& session)
{
session.checkSharedLocked();
Wt::Dbo::collection res {session.getDboSession().find()};
return std::vector(res.begin(), res.end());
}
std::vector
Cluster::getAllOrphans(Session& session)
{
session.checkSharedLocked();
Wt::Dbo::collection res {session.getDboSession().query("SELECT DISTINCT c FROM cluster c WHERE NOT EXISTS(SELECT 1 FROM track t INNER JOIN track_cluster t_c ON t.id = t_c.track_id)")};
return std::vector(res.begin(), res.end());
}
Cluster::pointer
Cluster::getById(Session& session, IdType id)
{
session.checkSharedLocked();
return session.getDboSession().find().where("id = ?").bind(id);
}
void
Cluster::addTrack(Wt::Dbo::ptr