[gnome-games/wip/exalm/cache2: 7/8] database: Switch DatabaseDeveloper to DatabaseMetadata
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games/wip/exalm/cache2: 7/8] database: Switch DatabaseDeveloper to DatabaseMetadata
- Date: Wed, 12 Sep 2018 11:54:22 +0000 (UTC)
commit 0118c2c6b1147349d80c95c2d9d01df1c2e42ab8
Author: Alexander Mikhaylenko <exalm7659 gmail com>
Date: Mon Sep 3 22:37:23 2018 +0500
database: Switch DatabaseDeveloper to DatabaseMetadata
Use DatabaseMetadata to fetch developer, and use DatabaseDeveloper as an
adapter object.
src/database/database-developer.vala | 71 +++---------------------------------
src/database/database-game.vala | 4 +-
src/database/database.vala | 4 --
3 files changed, 8 insertions(+), 71 deletions(-)
---
diff --git a/src/database/database-developer.vala b/src/database/database-developer.vala
index ef17dd87..67feca42 100644
--- a/src/database/database-developer.vala
+++ b/src/database/database-developer.vala
@@ -1,75 +1,14 @@
// This file is part of GNOME Games. License: GPL-3.0+.
private class Games.DatabaseDeveloper : Object, Developer {
- private const string LOAD_DEVELOPER_QUERY = """
- SELECT developer FROM game_metadata WHERE uid=$UID;
- """;
+ private DatabaseMetadata metadata;
- private const string SAVE_DEVELOPER_QUERY = """
- UPDATE game_metadata SET developer=$DEVELOPER WHERE uid=$UID;
- """;
-
- private Developer developer;
- private Uid uid;
- private Sqlite.Statement load_statement;
- private Sqlite.Statement save_statement;
- private string loaded;
-
- public DatabaseDeveloper (Sqlite.Database database, Developer developer, Uid uid) {
- this.developer = developer;
- this.uid = uid;
-
- developer.changed.connect (() => changed ());
-
- try {
- load_statement = Database.prepare (database, LOAD_DEVELOPER_QUERY);
- save_statement = Database.prepare (database, SAVE_DEVELOPER_QUERY);
- }
- catch (Error e) {
- warning (e.message);
- }
+ public DatabaseDeveloper (DatabaseMetadata metadata) {
+ this.metadata = metadata;
+ metadata.developer_changed.connect (() => changed ());
}
public string get_developer () {
- try {
- if (loaded == null)
- load_developer ();
- if (loaded != "")
- return loaded;
- else
- save_developer ();
- }
- catch (Error e) {
- warning (e.message);
- }
-
- return developer.get_developer ();
- }
-
- private void load_developer () throws Error {
- if (load_statement == null)
- return;
-
- Database.bind_text (load_statement, "$UID", uid.get_uid ());
-
- if (load_statement.step () == Sqlite.ROW)
- loaded = load_statement.column_text (0) ?? "";
- else
- warning ("Execution failed.");
- }
-
- private void save_developer () throws Error {
- if (save_statement == null)
- return;
-
- loaded = developer.get_developer ();
- if (loaded == "")
- return;
-
- Database.bind_text (save_statement, "$UID", uid.get_uid ());
- Database.bind_text (save_statement, "$DEVELOPER", loaded);
-
- if (save_statement.step () != Sqlite.DONE)
- warning ("Execution failed.");
+ return metadata.get_developer ();
}
}
diff --git a/src/database/database-game.vala b/src/database/database-game.vala
index 7b82d7ec..20c7ce51 100644
--- a/src/database/database-game.vala
+++ b/src/database/database-game.vala
@@ -8,6 +8,7 @@ private class Games.DatabaseGame : Object, Game {
private Database database;
private Game game;
private Uid uid;
+ private Developer developer;
public DatabaseGame (Database database, Game game) {
this.database = database;
@@ -16,6 +17,7 @@ private class Games.DatabaseGame : Object, Game {
var metadata = database.get_metadata (game);
uid = new DatabaseUid (metadata);
+ developer = new DatabaseDeveloper (metadata);
}
public Uid get_uid () {
@@ -47,7 +49,7 @@ private class Games.DatabaseGame : Object, Game {
}
public Developer get_developer () {
- return database.get_developer (game.get_developer (), get_uid ());
+ return developer;
}
public Publisher get_publisher () {
diff --git a/src/database/database.vala b/src/database/database.vala
index e5ddc5ec..352b0caa 100644
--- a/src/database/database.vala
+++ b/src/database/database.vala
@@ -63,10 +63,6 @@ private class Games.Database : Object {
return new DatabaseUriSource (database);
}
- public DatabaseDeveloper get_developer (Developer developer, Uid uid) {
- return new DatabaseDeveloper (database, developer, uid);
- }
-
public DatabaseMetadata get_metadata (Game game) {
return new DatabaseMetadata (database, game);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]