Add database field to enforce max age on index (per repo)

This commit is contained in:
Ciaran Gultnieks 2013-11-26 16:29:42 +00:00
parent 46bcfcf015
commit 7dc56e6009
2 changed files with 18 additions and 7 deletions

View File

@ -437,6 +437,7 @@ public class DB {
+ TABLE_REPO + " (id integer primary key, address text not null, " + TABLE_REPO + " (id integer primary key, address text not null, "
+ "name text, description text, inuse integer not null, " + "name text, description text, inuse integer not null, "
+ "priority integer not null, pubkey text, fingerprint text, " + "priority integer not null, pubkey text, fingerprint text, "
+ "maxage integer not null, "
+ "lastetag text);"; + "lastetag text);";
public static class Repo { public static class Repo {
@ -448,10 +449,11 @@ public class DB {
public int priority; public int priority;
public String pubkey; // null for an unsigned repo public String pubkey; // null for an unsigned repo
public String fingerprint; // always null for an unsigned repo public String fingerprint; // always null for an unsigned repo
public int maxage; // maximum age of index that will be accepted - 0 for any
public String lastetag; // last etag we updated from, null forces update public String lastetag; // last etag we updated from, null forces update
} }
private final int DBVersion = 29; private final int DBVersion = 30;
private static void createAppApk(SQLiteDatabase db) { private static void createAppApk(SQLiteDatabase db) {
db.execSQL(CREATE_TABLE_APP); db.execSQL(CREATE_TABLE_APP);
@ -519,6 +521,7 @@ public class DB {
String fingerprint = DB.calcFingerprint(pubkey); String fingerprint = DB.calcFingerprint(pubkey);
values.put("pubkey", pubkey); values.put("pubkey", pubkey);
values.put("fingerprint", fingerprint); values.put("fingerprint", fingerprint);
values.put("maxage", 0);
values.put("inuse", 1); values.put("inuse", 1);
values.put("priority", 10); values.put("priority", 10);
values.put("lastetag", (String) null); values.put("lastetag", (String) null);
@ -617,6 +620,10 @@ public class DB {
db.update(TABLE_REPO, values, "address = ?", new String[] { repo.address }); db.update(TABLE_REPO, values, "address = ?", new String[] { repo.address });
} }
} }
if (oldVersion < 30) {
db.execSQL("alter table " + TABLE_REPO + " add column maxage integer not null");
}
} }
} }
@ -1295,7 +1302,7 @@ public class DB {
try { try {
c = db.query(TABLE_REPO, new String[] { "address", "name", c = db.query(TABLE_REPO, new String[] { "address", "name",
"description", "inuse", "priority", "pubkey", "fingerprint", "description", "inuse", "priority", "pubkey", "fingerprint",
"lastetag" }, "maxage", "lastetag" },
"id = ?", new String[] { Integer.toString(id) }, null, null, null); "id = ?", new String[] { Integer.toString(id) }, null, null, null);
if (!c.moveToFirst()) if (!c.moveToFirst())
return null; return null;
@ -1308,7 +1315,8 @@ public class DB {
repo.priority = c.getInt(4); repo.priority = c.getInt(4);
repo.pubkey = c.getString(5); repo.pubkey = c.getString(5);
repo.fingerprint = c.getString(6); repo.fingerprint = c.getString(6);
repo.lastetag = c.getString(7); repo.maxage = c.getInt(7);
repo.lastetag = c.getString(8);
return repo; return repo;
} finally { } finally {
if (c != null) if (c != null)
@ -1323,7 +1331,7 @@ public class DB {
try { try {
c = db.query(TABLE_REPO, new String[] { "id", "address", "name", c = db.query(TABLE_REPO, new String[] { "id", "address", "name",
"description", "inuse", "priority", "pubkey", "fingerprint", "description", "inuse", "priority", "pubkey", "fingerprint",
"lastetag" }, "maxage", "lastetag" },
null, null, null, null, "priority"); null, null, null, null, "priority");
c.moveToFirst(); c.moveToFirst();
while (!c.isAfterLast()) { while (!c.isAfterLast()) {
@ -1336,7 +1344,8 @@ public class DB {
repo.priority = c.getInt(5); repo.priority = c.getInt(5);
repo.pubkey = c.getString(6); repo.pubkey = c.getString(6);
repo.fingerprint = c.getString(7); repo.fingerprint = c.getString(7);
repo.lastetag = c.getString(8); repo.maxage = c.getInt(8);
repo.lastetag = c.getString(9);
repos.add(repo); repos.add(repo);
c.moveToNext(); c.moveToNext();
} }
@ -1375,6 +1384,7 @@ public class DB {
} else { } else {
values.put("fingerprint", repo.fingerprint); values.put("fingerprint", repo.fingerprint);
} }
values.put("maxage", repo.maxage);
values.put("lastetag", (String) null); values.put("lastetag", (String) null);
db.update(TABLE_REPO, values, "address = ?", db.update(TABLE_REPO, values, "address = ?",
new String[] { repo.address }); new String[] { repo.address });
@ -1388,7 +1398,7 @@ public class DB {
} }
public void addRepo(String address, String name, String description, public void addRepo(String address, String name, String description,
int priority, String pubkey, String fingerprint, boolean inuse) int priority, String pubkey, String fingerprint, int maxage, boolean inuse)
throws SecurityException { throws SecurityException {
ContentValues values = new ContentValues(); ContentValues values = new ContentValues();
values.put("address", address); values.put("address", address);
@ -1408,6 +1418,7 @@ public class DB {
} }
} }
values.put("fingerprint", fingerprint); values.put("fingerprint", fingerprint);
values.put("maxage", maxage);
values.put("lastetag", (String) null); values.put("lastetag", (String) null);
db.insert(TABLE_REPO, null, values); db.insert(TABLE_REPO, null, values);
} }

View File

@ -202,7 +202,7 @@ public class ManageRepo extends ListActivity {
protected void addRepo(String repoUri, String fingerprint) { protected void addRepo(String repoUri, String fingerprint) {
try { try {
DB db = DB.getDB(); DB db = DB.getDB();
db.addRepo(repoUri, null, null, 10, null, fingerprint, true); db.addRepo(repoUri, null, null, 10, null, fingerprint, 0, true);
} finally { } finally {
DB.releaseDB(); DB.releaseDB();
} }