Mercurial Hosting > nabble
diff src/jdbcpgbackup/DbBackupObject.java @ 0:7ecd1a4ef557
add content
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Thu, 21 Mar 2019 19:15:52 -0600 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/jdbcpgbackup/DbBackupObject.java Thu Mar 21 19:15:52 2019 -0600 @@ -0,0 +1,49 @@ +/* Copyright (c) 2012 Tomislav Gountchev <tomi@gountchev.net> */ + +package jdbcpgbackup; + +abstract class DbBackupObject { + + protected final String name; + protected final Schema schema; + protected final String owner; + + protected DbBackupObject(String name, Schema schema, String owner) { + this.name = name; + this.schema = schema; + this.owner = owner; + } + + final String getName() { + return name; + } + + String getFullname() { + return schema.getName() + "." + name; + } + + final String getOwner() { + return owner; + } + + String getSql(DataFilter dataFilter) { + StringBuilder buf = new StringBuilder(); + if (!owner.equals(schema.getOwner())) { + buf.append("SET ROLE ").append(owner); + buf.append(" ;\n"); + } + appendCreateSql(buf, dataFilter); + if (!owner.equals(schema.getOwner())) { + buf.append("SET ROLE ").append(schema.getOwner()); + buf.append(" ;\n"); + } + return buf.toString(); + } + + protected abstract StringBuilder appendCreateSql(StringBuilder buf); + + protected StringBuilder appendCreateSql(StringBuilder buf, DataFilter dataFilter) { + return appendCreateSql(buf); + } + +}