/* rygel-lms-albums.c generated by valac 0.31.1.6-4f062, the Vala compiler
 * generated from rygel-lms-albums.vala, do not modify */

/*
 * Copyright (C) 2013 Intel Corporation.
 *
 * Author: Jussi Kukkonen <jussi.kukkonen@intel.com>
 *
 * This file is part of Rygel.
 *
 * Rygel is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * Rygel 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 Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

#include <glib.h>
#include <glib-object.h>
#include <rygel-server.h>
#include <sqlite3.h>
#include <stdlib.h>
#include <string.h>
#include <rygel-db.h>
#include <gee.h>
#include <glib/gi18n-lib.h>


#define RYGEL_LMS_TYPE_CATEGORY_CONTAINER (rygel_lms_category_container_get_type ())
#define RYGEL_LMS_CATEGORY_CONTAINER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RYGEL_LMS_TYPE_CATEGORY_CONTAINER, RygelLMSCategoryContainer))
#define RYGEL_LMS_CATEGORY_CONTAINER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), RYGEL_LMS_TYPE_CATEGORY_CONTAINER, RygelLMSCategoryContainerClass))
#define RYGEL_LMS_IS_CATEGORY_CONTAINER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), RYGEL_LMS_TYPE_CATEGORY_CONTAINER))
#define RYGEL_LMS_IS_CATEGORY_CONTAINER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), RYGEL_LMS_TYPE_CATEGORY_CONTAINER))
#define RYGEL_LMS_CATEGORY_CONTAINER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), RYGEL_LMS_TYPE_CATEGORY_CONTAINER, RygelLMSCategoryContainerClass))

typedef struct _RygelLMSCategoryContainer RygelLMSCategoryContainer;
typedef struct _RygelLMSCategoryContainerClass RygelLMSCategoryContainerClass;
typedef struct _RygelLMSCategoryContainerPrivate RygelLMSCategoryContainerPrivate;

#define RYGEL_LMS_TYPE_ALBUMS (rygel_lms_albums_get_type ())
#define RYGEL_LMS_ALBUMS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RYGEL_LMS_TYPE_ALBUMS, RygelLMSAlbums))
#define RYGEL_LMS_ALBUMS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), RYGEL_LMS_TYPE_ALBUMS, RygelLMSAlbumsClass))
#define RYGEL_LMS_IS_ALBUMS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), RYGEL_LMS_TYPE_ALBUMS))
#define RYGEL_LMS_IS_ALBUMS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), RYGEL_LMS_TYPE_ALBUMS))
#define RYGEL_LMS_ALBUMS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), RYGEL_LMS_TYPE_ALBUMS, RygelLMSAlbumsClass))

typedef struct _RygelLMSAlbums RygelLMSAlbums;
typedef struct _RygelLMSAlbumsClass RygelLMSAlbumsClass;
typedef struct _RygelLMSAlbumsPrivate RygelLMSAlbumsPrivate;
#define _g_free0(var) (var = (g_free (var), NULL))

#define RYGEL_LMS_TYPE_DATABASE (rygel_lms_database_get_type ())
#define RYGEL_LMS_DATABASE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RYGEL_LMS_TYPE_DATABASE, RygelLMSDatabase))
#define RYGEL_LMS_DATABASE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), RYGEL_LMS_TYPE_DATABASE, RygelLMSDatabaseClass))
#define RYGEL_LMS_IS_DATABASE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), RYGEL_LMS_TYPE_DATABASE))
#define RYGEL_LMS_IS_DATABASE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), RYGEL_LMS_TYPE_DATABASE))
#define RYGEL_LMS_DATABASE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), RYGEL_LMS_TYPE_DATABASE, RygelLMSDatabaseClass))

typedef struct _RygelLMSDatabase RygelLMSDatabase;
typedef struct _RygelLMSDatabaseClass RygelLMSDatabaseClass;
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _rygel_database_cursor_iterator_unref0(var) ((var == NULL) ? NULL : (var = (rygel_database_cursor_iterator_unref (var), NULL)))

#define RYGEL_LMS_TYPE_ALBUM (rygel_lms_album_get_type ())
#define RYGEL_LMS_ALBUM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RYGEL_LMS_TYPE_ALBUM, RygelLMSAlbum))
#define RYGEL_LMS_ALBUM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), RYGEL_LMS_TYPE_ALBUM, RygelLMSAlbumClass))
#define RYGEL_LMS_IS_ALBUM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), RYGEL_LMS_TYPE_ALBUM))
#define RYGEL_LMS_IS_ALBUM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), RYGEL_LMS_TYPE_ALBUM))
#define RYGEL_LMS_ALBUM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), RYGEL_LMS_TYPE_ALBUM, RygelLMSAlbumClass))

typedef struct _RygelLMSAlbum RygelLMSAlbum;
typedef struct _RygelLMSAlbumClass RygelLMSAlbumClass;

struct _RygelLMSCategoryContainer {
	RygelMediaContainer parent_instance;
	RygelLMSCategoryContainerPrivate * priv;
	RygelDatabaseCursor* cursor_all;
	RygelDatabaseCursor* cursor_find_object;
	RygelDatabaseCursor* cursor_added;
	RygelDatabaseCursor* cursor_removed;
	gchar* child_prefix;
	gchar* ref_prefix;
};

struct _RygelLMSCategoryContainerClass {
	RygelMediaContainerClass parent_class;
	RygelMediaObject* (*object_from_statement) (RygelLMSCategoryContainer* self, sqlite3_stmt* statement);
	gchar* (*get_sql_all_with_filter) (RygelLMSCategoryContainer* self, const gchar* filter);
	gchar* (*get_sql_count_with_filter) (RygelLMSCategoryContainer* self, const gchar* filter);
	guint (*get_child_count_with_filter) (RygelLMSCategoryContainer* self, const gchar* where_filter, GValueArray* args);
	RygelMediaObjects* (*get_children_with_filter) (RygelLMSCategoryContainer* self, const gchar* where_filter, GValueArray* args, const gchar* sort_criteria, guint offset, guint max_count);
};

struct _RygelLMSAlbums {
	RygelLMSCategoryContainer parent_instance;
	RygelLMSAlbumsPrivate * priv;
};

struct _RygelLMSAlbumsClass {
	RygelLMSCategoryContainerClass parent_class;
};


static gpointer rygel_lms_albums_parent_class = NULL;

GType rygel_lms_category_container_get_type (void) G_GNUC_CONST;
GType rygel_lms_albums_get_type (void) G_GNUC_CONST;
enum  {
	RYGEL_LMS_ALBUMS_DUMMY_PROPERTY
};
#define RYGEL_LMS_ALBUMS_SQL_ALL "SELECT audio_albums.id, audio_albums.name as title, " "audio_artists.name as artist " "FROM audio_albums " "LEFT JOIN audio_artists " "ON audio_albums.artist_id = audio_artists.id " "LIMIT ? OFFSET ?;"
#define RYGEL_LMS_ALBUMS_SQL_ALL_WITH_FILTER_TEMPLATE "SELECT audio_albums.id, audio_albums.name as title, " "audio_artists.name as artist " "FROM audio_albums " "LEFT JOIN audio_artists " "ON audio_albums.artist_id = audio_artists.id " "WHERE %s " "LIMIT ? OFFSET ?;"
#define RYGEL_LMS_ALBUMS_SQL_COUNT "SELECT COUNT(audio_albums.id) " "FROM audio_albums;"
#define RYGEL_LMS_ALBUMS_SQL_COUNT_WITH_FILTER_TEMPLATE "SELECT COUNT(audio_albums.id), audio_albums.name as title, " "audio_artists.name as artist " "FROM audio_albums " "LEFT JOIN audio_artists " "ON audio_albums.artist_id = audio_artists.id " "WHERE %s;"
#define RYGEL_LMS_ALBUMS_SQL_CHILD_COUNT_WITH_FILTER_TEMPLATE "SELECT COUNT(audios.id), audios.title as title, " "audio_artists.name as artist " "FROM audios, files, audio_albums " "LEFT JOIN audio_artists " "ON audios.artist_id = audio_artists.id " "WHERE dtime = 0 AND audios.id = files.id AND audios.album_id = audio_a" \
"lbums.id %s;"
#define RYGEL_LMS_ALBUMS_SQL_CHILD_ALL_WITH_FILTER_TEMPLATE "SELECT files.id, files.path, files.size, " "audios.title as title, audios.trackno, audios.length, audios.channels," \
" audios.sampling_rate, audios.bitrate, audios.dlna_profile, audios.dln" \
"a_mime, " "audio_artists.name as artist, " "audio_albums.name, audio_albums.id " "FROM audios, files, audio_albums " "LEFT JOIN audio_artists " "ON audios.artist_id = audio_artists.id " "WHERE dtime = 0 AND audios.id = files.id AND audios.album_id = audio_a" \
"lbums.id %s " "LIMIT ? OFFSET ?;"
#define RYGEL_LMS_ALBUMS_SQL_FIND_OBJECT "SELECT audio_albums.id, audio_albums.name " "FROM audio_albums " "WHERE audio_albums.id = ?;"
static gchar* rygel_lms_albums_real_get_sql_all_with_filter (RygelLMSCategoryContainer* base, const gchar* filter);
static gchar* rygel_lms_albums_real_get_sql_count_with_filter (RygelLMSCategoryContainer* base, const gchar* filter);
static guint rygel_lms_albums_real_get_child_count_with_filter (RygelLMSCategoryContainer* base, const gchar* where_filter, GValueArray* args);
guint rygel_lms_category_container_get_child_count_with_filter (RygelLMSCategoryContainer* self, const gchar* where_filter, GValueArray* args);
GType rygel_lms_database_get_type (void) G_GNUC_CONST;
RygelLMSDatabase* rygel_lms_category_container_get_lms_db (RygelLMSCategoryContainer* self);
static RygelMediaObjects* rygel_lms_albums_real_get_children_with_filter (RygelLMSCategoryContainer* base, const gchar* where_filter, GValueArray* args, const gchar* sort_criteria, guint offset, guint max_count);
RygelMediaObjects* rygel_lms_category_container_get_children_with_filter (RygelLMSCategoryContainer* self, const gchar* where_filter, GValueArray* args, const gchar* sort_criteria, guint offset, guint max_count);
GType rygel_lms_album_get_type (void) G_GNUC_CONST;
RygelLMSAlbum* rygel_lms_album_new (const gchar* db_id, RygelMediaContainer* parent, const gchar* title, RygelLMSDatabase* lms_db);
RygelLMSAlbum* rygel_lms_album_construct (GType object_type, const gchar* db_id, RygelMediaContainer* parent, const gchar* title, RygelLMSDatabase* lms_db);
RygelMediaObject* rygel_lms_category_container_object_from_statement (RygelLMSCategoryContainer* self, sqlite3_stmt* statement);
static RygelMediaObject* rygel_lms_albums_real_object_from_statement (RygelLMSCategoryContainer* base, sqlite3_stmt* statement);
RygelLMSAlbums* rygel_lms_albums_new (RygelMediaContainer* parent, RygelLMSDatabase* lms_db);
RygelLMSAlbums* rygel_lms_albums_construct (GType object_type, RygelMediaContainer* parent, RygelLMSDatabase* lms_db);
RygelLMSCategoryContainer* rygel_lms_category_container_construct (GType object_type, const gchar* db_id, RygelMediaContainer* parent, const gchar* title, RygelLMSDatabase* lms_db, const gchar* sql_all, const gchar* sql_find_object, const gchar* sql_count, const gchar* sql_added, const gchar* sql_removed);


static gchar* rygel_lms_albums_real_get_sql_all_with_filter (RygelLMSCategoryContainer* base, const gchar* filter) {
	RygelLMSAlbums * self;
	gchar* result = NULL;
	const gchar* _tmp0_ = NULL;
	gint _tmp1_ = 0;
	gint _tmp2_ = 0;
	const gchar* _tmp4_ = NULL;
	gchar* _tmp5_ = NULL;
	self = (RygelLMSAlbums*) base;
	g_return_val_if_fail (filter != NULL, NULL);
	_tmp0_ = filter;
	_tmp1_ = strlen (_tmp0_);
	_tmp2_ = _tmp1_;
	if (_tmp2_ == 0) {
		gchar* _tmp3_ = NULL;
		_tmp3_ = g_strdup (RYGEL_LMS_ALBUMS_SQL_ALL);
		result = _tmp3_;
		return result;
	}
	_tmp4_ = filter;
	_tmp5_ = g_strdup_printf (RYGEL_LMS_ALBUMS_SQL_ALL_WITH_FILTER_TEMPLATE, _tmp4_);
	result = _tmp5_;
	return result;
}


static gchar* rygel_lms_albums_real_get_sql_count_with_filter (RygelLMSCategoryContainer* base, const gchar* filter) {
	RygelLMSAlbums * self;
	gchar* result = NULL;
	const gchar* _tmp0_ = NULL;
	gint _tmp1_ = 0;
	gint _tmp2_ = 0;
	const gchar* _tmp4_ = NULL;
	gchar* _tmp5_ = NULL;
	self = (RygelLMSAlbums*) base;
	g_return_val_if_fail (filter != NULL, NULL);
	_tmp0_ = filter;
	_tmp1_ = strlen (_tmp0_);
	_tmp2_ = _tmp1_;
	if (_tmp2_ == 0) {
		gchar* _tmp3_ = NULL;
		_tmp3_ = g_strdup (RYGEL_LMS_ALBUMS_SQL_COUNT);
		result = _tmp3_;
		return result;
	}
	_tmp4_ = filter;
	_tmp5_ = g_strdup_printf (RYGEL_LMS_ALBUMS_SQL_COUNT_WITH_FILTER_TEMPLATE, _tmp4_);
	result = _tmp5_;
	return result;
}


static guint rygel_lms_albums_real_get_child_count_with_filter (RygelLMSCategoryContainer* base, const gchar* where_filter, GValueArray* args) {
	RygelLMSAlbums * self;
	guint result = 0U;
	guint count = 0U;
	const gchar* _tmp0_ = NULL;
	GValueArray* _tmp1_ = NULL;
	guint _tmp2_ = 0U;
	gchar* filter = NULL;
	gchar* _tmp3_ = NULL;
	const gchar* _tmp4_ = NULL;
	gint _tmp5_ = 0;
	gint _tmp6_ = 0;
	gchar* query = NULL;
	const gchar* _tmp9_ = NULL;
	gchar* _tmp10_ = NULL;
	GError * _inner_error_ = NULL;
	self = (RygelLMSAlbums*) base;
	g_return_val_if_fail (where_filter != NULL, 0U);
	g_return_val_if_fail (args != NULL, 0U);
	_tmp0_ = where_filter;
	_tmp1_ = args;
	_tmp2_ = RYGEL_LMS_CATEGORY_CONTAINER_CLASS (rygel_lms_albums_parent_class)->get_child_count_with_filter (G_TYPE_CHECK_INSTANCE_CAST (self, RYGEL_LMS_TYPE_CATEGORY_CONTAINER, RygelLMSCategoryContainer), _tmp0_, _tmp1_);
	count = _tmp2_;
	_tmp3_ = g_strdup ("");
	filter = _tmp3_;
	_tmp4_ = where_filter;
	_tmp5_ = strlen (_tmp4_);
	_tmp6_ = _tmp5_;
	if (_tmp6_ > 0) {
		const gchar* _tmp7_ = NULL;
		gchar* _tmp8_ = NULL;
		_tmp7_ = where_filter;
		_tmp8_ = g_strdup_printf ("AND %s", _tmp7_);
		_g_free0 (filter);
		filter = _tmp8_;
	}
	_tmp9_ = filter;
	_tmp10_ = g_strdup_printf (RYGEL_LMS_ALBUMS_SQL_CHILD_COUNT_WITH_FILTER_TEMPLATE, _tmp9_);
	query = _tmp10_;
	{
		gint _tmp11_ = 0;
		RygelLMSDatabase* _tmp12_ = NULL;
		RygelLMSDatabase* _tmp13_ = NULL;
		GValueArray* _tmp14_ = NULL;
		GValue* _tmp15_ = NULL;
		gint _tmp15__length1 = 0;
		gint _tmp16_ = 0;
		guint _tmp17_ = 0U;
		_tmp12_ = rygel_lms_category_container_get_lms_db ((RygelLMSCategoryContainer*) self);
		_tmp13_ = _tmp12_;
		_tmp14_ = args;
		_tmp15_ = _tmp14_->values;
		_tmp15__length1 = (gint) _tmp14_->n_values;
		_tmp16_ = rygel_database_database_query_value ((RygelDatabaseDatabase*) _tmp13_, query, _tmp15_, _tmp15__length1, &_inner_error_);
		_tmp11_ = _tmp16_;
		if (G_UNLIKELY (_inner_error_ != NULL)) {
			if (_inner_error_->domain == RYGEL_DATABASE_DATABASE_ERROR) {
				goto __catch8_rygel_database_database_error;
			}
			_g_free0 (query);
			_g_free0 (filter);
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
			g_clear_error (&_inner_error_);
			return 0U;
		}
		_tmp17_ = count;
		count = _tmp17_ + _tmp11_;
	}
	goto __finally8;
	__catch8_rygel_database_database_error:
	{
		GError* e = NULL;
		GError* _tmp18_ = NULL;
		const gchar* _tmp19_ = NULL;
		e = _inner_error_;
		_inner_error_ = NULL;
		_tmp18_ = e;
		_tmp19_ = _tmp18_->message;
		g_warning ("rygel-lms-albums.vala:113: Query failed: %s", _tmp19_);
		_g_error_free0 (e);
	}
	__finally8:
	if (G_UNLIKELY (_inner_error_ != NULL)) {
		_g_free0 (query);
		_g_free0 (filter);
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
		g_clear_error (&_inner_error_);
		return 0U;
	}
	result = count;
	_g_free0 (query);
	_g_free0 (filter);
	return result;
}


static RygelMediaObjects* rygel_lms_albums_real_get_children_with_filter (RygelLMSCategoryContainer* base, const gchar* where_filter, GValueArray* args, const gchar* sort_criteria, guint offset, guint max_count) {
	RygelLMSAlbums * self;
	RygelMediaObjects* result = NULL;
	RygelMediaObjects* children = NULL;
	const gchar* _tmp0_ = NULL;
	GValueArray* _tmp1_ = NULL;
	const gchar* _tmp2_ = NULL;
	guint _tmp3_ = 0U;
	guint _tmp4_ = 0U;
	RygelMediaObjects* _tmp5_ = NULL;
	gchar* filter = NULL;
	gchar* _tmp6_ = NULL;
	const gchar* _tmp7_ = NULL;
	gint _tmp8_ = 0;
	gint _tmp9_ = 0;
	gchar* query = NULL;
	const gchar* _tmp12_ = NULL;
	gchar* _tmp13_ = NULL;
	GError * _inner_error_ = NULL;
	self = (RygelLMSAlbums*) base;
	g_return_val_if_fail (where_filter != NULL, NULL);
	g_return_val_if_fail (args != NULL, NULL);
	g_return_val_if_fail (sort_criteria != NULL, NULL);
	_tmp0_ = where_filter;
	_tmp1_ = args;
	_tmp2_ = sort_criteria;
	_tmp3_ = offset;
	_tmp4_ = max_count;
	_tmp5_ = RYGEL_LMS_CATEGORY_CONTAINER_CLASS (rygel_lms_albums_parent_class)->get_children_with_filter (G_TYPE_CHECK_INSTANCE_CAST (self, RYGEL_LMS_TYPE_CATEGORY_CONTAINER, RygelLMSCategoryContainer), _tmp0_, _tmp1_, _tmp2_, _tmp3_, _tmp4_);
	children = _tmp5_;
	_tmp6_ = g_strdup ("");
	filter = _tmp6_;
	_tmp7_ = where_filter;
	_tmp8_ = strlen (_tmp7_);
	_tmp9_ = _tmp8_;
	if (_tmp9_ > 0) {
		const gchar* _tmp10_ = NULL;
		gchar* _tmp11_ = NULL;
		_tmp10_ = where_filter;
		_tmp11_ = g_strdup_printf ("AND %s", _tmp10_);
		_g_free0 (filter);
		filter = _tmp11_;
	}
	_tmp12_ = filter;
	_tmp13_ = g_strdup_printf (RYGEL_LMS_ALBUMS_SQL_CHILD_ALL_WITH_FILTER_TEMPLATE, _tmp12_);
	query = _tmp13_;
	{
		RygelDatabaseCursor* cursor = NULL;
		RygelLMSDatabase* _tmp14_ = NULL;
		RygelLMSDatabase* _tmp15_ = NULL;
		const gchar* _tmp16_ = NULL;
		GValueArray* _tmp17_ = NULL;
		GValue* _tmp18_ = NULL;
		gint _tmp18__length1 = 0;
		RygelDatabaseCursor* _tmp19_ = NULL;
		_tmp14_ = rygel_lms_category_container_get_lms_db ((RygelLMSCategoryContainer*) self);
		_tmp15_ = _tmp14_;
		_tmp16_ = query;
		_tmp17_ = args;
		_tmp18_ = _tmp17_->values;
		_tmp18__length1 = (gint) _tmp17_->n_values;
		_tmp19_ = rygel_database_database_exec_cursor ((RygelDatabaseDatabase*) _tmp15_, _tmp16_, _tmp18_, _tmp18__length1, &_inner_error_);
		cursor = _tmp19_;
		if (G_UNLIKELY (_inner_error_ != NULL)) {
			if (_inner_error_->domain == RYGEL_DATABASE_DATABASE_ERROR) {
				goto __catch9_rygel_database_database_error;
			}
			_g_free0 (query);
			_g_free0 (filter);
			_g_object_unref0 (children);
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
			g_clear_error (&_inner_error_);
			return NULL;
		}
		{
			RygelDatabaseCursorIterator* _stmt_it = NULL;
			RygelDatabaseCursor* _tmp20_ = NULL;
			RygelDatabaseCursorIterator* _tmp21_ = NULL;
			_tmp20_ = cursor;
			_tmp21_ = rygel_database_cursor_iterator (_tmp20_);
			_stmt_it = _tmp21_;
			while (TRUE) {
				gboolean _tmp22_ = FALSE;
				RygelDatabaseCursorIterator* _tmp23_ = NULL;
				gboolean _tmp24_ = FALSE;
				sqlite3_stmt* stmt = NULL;
				RygelDatabaseCursorIterator* _tmp25_ = NULL;
				sqlite3_stmt* _tmp26_ = NULL;
				gchar* album_id = NULL;
				sqlite3_stmt* _tmp27_ = NULL;
				const gchar* _tmp28_ = NULL;
				gchar* _tmp29_ = NULL;
				RygelLMSAlbum* album = NULL;
				const gchar* _tmp30_ = NULL;
				RygelLMSDatabase* _tmp31_ = NULL;
				RygelLMSDatabase* _tmp32_ = NULL;
				RygelLMSAlbum* _tmp33_ = NULL;
				RygelMediaObject* song = NULL;
				RygelLMSAlbum* _tmp34_ = NULL;
				sqlite3_stmt* _tmp35_ = NULL;
				RygelMediaObject* _tmp36_ = NULL;
				RygelMediaObject* _tmp37_ = NULL;
				RygelMediaObject* _tmp38_ = NULL;
				RygelMediaContainer* _tmp39_ = NULL;
				RygelMediaContainer* _tmp40_ = NULL;
				RygelMediaObjects* _tmp41_ = NULL;
				RygelMediaObject* _tmp42_ = NULL;
				_tmp23_ = _stmt_it;
				_tmp24_ = rygel_database_cursor_iterator_next (_tmp23_, &_inner_error_);
				_tmp22_ = _tmp24_;
				if (G_UNLIKELY (_inner_error_ != NULL)) {
					_rygel_database_cursor_iterator_unref0 (_stmt_it);
					_g_object_unref0 (cursor);
					if (_inner_error_->domain == RYGEL_DATABASE_DATABASE_ERROR) {
						goto __catch9_rygel_database_database_error;
					}
					_rygel_database_cursor_iterator_unref0 (_stmt_it);
					_g_object_unref0 (cursor);
					_g_free0 (query);
					_g_free0 (filter);
					_g_object_unref0 (children);
					g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
					g_clear_error (&_inner_error_);
					return NULL;
				}
				if (!_tmp22_) {
					break;
				}
				_tmp25_ = _stmt_it;
				_tmp26_ = rygel_database_cursor_iterator_get (_tmp25_, &_inner_error_);
				stmt = _tmp26_;
				if (G_UNLIKELY (_inner_error_ != NULL)) {
					_rygel_database_cursor_iterator_unref0 (_stmt_it);
					_g_object_unref0 (cursor);
					if (_inner_error_->domain == RYGEL_DATABASE_DATABASE_ERROR) {
						goto __catch9_rygel_database_database_error;
					}
					_rygel_database_cursor_iterator_unref0 (_stmt_it);
					_g_object_unref0 (cursor);
					_g_free0 (query);
					_g_free0 (filter);
					_g_object_unref0 (children);
					g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
					g_clear_error (&_inner_error_);
					return NULL;
				}
				_tmp27_ = stmt;
				_tmp28_ = sqlite3_column_text (_tmp27_, 13);
				_tmp29_ = g_strdup (_tmp28_);
				album_id = _tmp29_;
				_tmp30_ = album_id;
				_tmp31_ = rygel_lms_category_container_get_lms_db ((RygelLMSCategoryContainer*) self);
				_tmp32_ = _tmp31_;
				_tmp33_ = rygel_lms_album_new (_tmp30_, (RygelMediaContainer*) self, "", _tmp32_);
				album = _tmp33_;
				_tmp34_ = album;
				_tmp35_ = stmt;
				_tmp36_ = rygel_lms_category_container_object_from_statement ((RygelLMSCategoryContainer*) _tmp34_, _tmp35_);
				song = _tmp36_;
				_tmp37_ = song;
				_tmp38_ = song;
				_tmp39_ = rygel_media_object_get_parent (_tmp38_);
				_tmp40_ = _tmp39_;
				rygel_media_object_set_parent_ref (_tmp37_, _tmp40_);
				_tmp41_ = children;
				_tmp42_ = song;
				gee_abstract_collection_add ((GeeAbstractCollection*) _tmp41_, _tmp42_);
				_g_object_unref0 (song);
				_g_object_unref0 (album);
				_g_free0 (album_id);
			}
			_rygel_database_cursor_iterator_unref0 (_stmt_it);
		}
		_g_object_unref0 (cursor);
	}
	goto __finally9;
	__catch9_rygel_database_database_error:
	{
		GError* e = NULL;
		GError* _tmp43_ = NULL;
		const gchar* _tmp44_ = NULL;
		e = _inner_error_;
		_inner_error_ = NULL;
		_tmp43_ = e;
		_tmp44_ = _tmp43_->message;
		g_warning ("rygel-lms-albums.vala:147: Query failed: %s", _tmp44_);
		_g_error_free0 (e);
	}
	__finally9:
	if (G_UNLIKELY (_inner_error_ != NULL)) {
		_g_free0 (query);
		_g_free0 (filter);
		_g_object_unref0 (children);
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
		g_clear_error (&_inner_error_);
		return NULL;
	}
	result = children;
	_g_free0 (query);
	_g_free0 (filter);
	return result;
}


static RygelMediaObject* rygel_lms_albums_real_object_from_statement (RygelLMSCategoryContainer* base, sqlite3_stmt* statement) {
	RygelLMSAlbums * self;
	RygelMediaObject* result = NULL;
	gchar* id = NULL;
	sqlite3_stmt* _tmp0_ = NULL;
	gint _tmp1_ = 0;
	gchar* _tmp2_ = NULL;
	RygelLMSAlbum* album = NULL;
	sqlite3_stmt* _tmp3_ = NULL;
	const gchar* _tmp4_ = NULL;
	RygelLMSDatabase* _tmp5_ = NULL;
	RygelLMSDatabase* _tmp6_ = NULL;
	RygelLMSAlbum* _tmp7_ = NULL;
	self = (RygelLMSAlbums*) base;
	g_return_val_if_fail (statement != NULL, NULL);
	_tmp0_ = statement;
	_tmp1_ = sqlite3_column_int (_tmp0_, 0);
	_tmp2_ = g_strdup_printf ("%d", _tmp1_);
	id = _tmp2_;
	_tmp3_ = statement;
	_tmp4_ = sqlite3_column_text (_tmp3_, 1);
	_tmp5_ = rygel_lms_category_container_get_lms_db ((RygelLMSCategoryContainer*) self);
	_tmp6_ = _tmp5_;
	_tmp7_ = rygel_lms_album_new (id, (RygelMediaContainer*) self, _tmp4_, _tmp6_);
	album = _tmp7_;
	result = (RygelMediaObject*) album;
	_g_free0 (id);
	return result;
}


RygelLMSAlbums* rygel_lms_albums_construct (GType object_type, RygelMediaContainer* parent, RygelLMSDatabase* lms_db) {
	RygelLMSAlbums * self = NULL;
	RygelMediaContainer* _tmp0_ = NULL;
	const gchar* _tmp1_ = NULL;
	RygelLMSDatabase* _tmp2_ = NULL;
	g_return_val_if_fail (parent != NULL, NULL);
	g_return_val_if_fail (lms_db != NULL, NULL);
	_tmp0_ = parent;
	_tmp1_ = _ ("Albums");
	_tmp2_ = lms_db;
	self = (RygelLMSAlbums*) rygel_lms_category_container_construct (object_type, "albums", _tmp0_, _tmp1_, _tmp2_, RYGEL_LMS_ALBUMS_SQL_ALL, RYGEL_LMS_ALBUMS_SQL_FIND_OBJECT, RYGEL_LMS_ALBUMS_SQL_COUNT, NULL, NULL);
	return self;
}


RygelLMSAlbums* rygel_lms_albums_new (RygelMediaContainer* parent, RygelLMSDatabase* lms_db) {
	return rygel_lms_albums_construct (RYGEL_LMS_TYPE_ALBUMS, parent, lms_db);
}


static void rygel_lms_albums_class_init (RygelLMSAlbumsClass * klass) {
	rygel_lms_albums_parent_class = g_type_class_peek_parent (klass);
	((RygelLMSCategoryContainerClass *) klass)->get_sql_all_with_filter = rygel_lms_albums_real_get_sql_all_with_filter;
	((RygelLMSCategoryContainerClass *) klass)->get_sql_count_with_filter = rygel_lms_albums_real_get_sql_count_with_filter;
	((RygelLMSCategoryContainerClass *) klass)->get_child_count_with_filter = rygel_lms_albums_real_get_child_count_with_filter;
	((RygelLMSCategoryContainerClass *) klass)->get_children_with_filter = rygel_lms_albums_real_get_children_with_filter;
	((RygelLMSCategoryContainerClass *) klass)->object_from_statement = rygel_lms_albums_real_object_from_statement;
}


static void rygel_lms_albums_instance_init (RygelLMSAlbums * self) {
}


GType rygel_lms_albums_get_type (void) {
	static volatile gsize rygel_lms_albums_type_id__volatile = 0;
	if (g_once_init_enter (&rygel_lms_albums_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (RygelLMSAlbumsClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) rygel_lms_albums_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (RygelLMSAlbums), 0, (GInstanceInitFunc) rygel_lms_albums_instance_init, NULL };
		GType rygel_lms_albums_type_id;
		rygel_lms_albums_type_id = g_type_register_static (RYGEL_LMS_TYPE_CATEGORY_CONTAINER, "RygelLMSAlbums", &g_define_type_info, 0);
		g_once_init_leave (&rygel_lms_albums_type_id__volatile, rygel_lms_albums_type_id);
	}
	return rygel_lms_albums_type_id__volatile;
}



