@Test public void testGrants() throws Exception { Database db = new Database("foo", "2"); Role role = new Role("admin"); role.setAnyAuthenticated(true); Role role1 = new Role("uber"); Permission permission = new Permission(); permission.setAllowAlter(true); permission.setAllowSelect(true); permission.setResourceName("schema.tableName"); permission.setResourceType(ResourceType.TABLE); Permission permission2 = new Permission(); permission2.setAllowDelete(true); permission2.setResourceName("schema.tableName"); permission2.setResourceType(ResourceType.TABLE); Permission permission3 = new Permission(); permission3.setAllowAllPrivileges(true); permission3.setAllowTemporyTables(true); Permission permission4 = new Permission(); permission4.setAllowTemporyTables(true); Permission permission5 = new Permission(); permission5.setAllowDelete(true); permission5.setResourceName("schema.tableName.col"); permission5.setResourceType(ResourceType.COLUMN); Permission permission6 = new Permission(); permission6.setAllowSelect(true); permission6.setResourceName("schema.tableName.col"); permission6.setResourceType(ResourceType.TABLE); Permission permission7 = new Permission(); permission7.setAllowSelect(true); permission7.setResourceName("schema.tableName.col2"); permission7.setResourceType(ResourceType.COLUMN); permission7.setCondition("x=y", null); permission7.setMaskOrder(2); permission7.setMask("'xxx'"); db.addRole(role); db.addRole(role1); db.addGrant(new Grant(role.getName(), permission)); db.addGrant(new Grant(role.getName(), permission4)); db.addGrant(new Grant(role.getName(), permission2)); db.addGrant(new Grant(role.getName(), permission5)); db.addGrant(new Grant(role.getName(), permission6)); db.addGrant(new Grant(role.getName(), permission7)); db.addGrant(new Grant("uber", permission3)); String expected = "\n" + "\n" + "CREATE DATABASE foo VERSION '2';\n" + "USE DATABASE foo VERSION '2';\n" + "\n" + "--############ Roles ############\n" + "CREATE ROLE admin WITH ANY AUTHENTICATED;\n" + "\n" + "CREATE ROLE uber;\n" + "\n" + "\n" + "--############ Grants ############\n" + "GRANT SELECT,DELETE,ALTER ON TABLE \"schema.tableName\" TO admin;\n" + "GRANT TEMPORARY TABLE TO admin;\n" + "GRANT DELETE ON COLUMN \"schema.tableName.col\" TO admin;\n" + "GRANT SELECT ON TABLE \"schema.tableName.col\" TO admin;\n" + "GRANT SELECT ON COLUMN \"schema.tableName.col2\" MASK ORDER 2 '''xxx''' CONDITION x=y TO admin;\n" + "\n" + "GRANT ALL PRIVILEGES TO uber;\n" + "GRANT TEMPORARY TABLE TO uber;\n" + "\n" + "\n" + "\n" + "\n"; String metadataDDL = DDLStringVisitor.getDDLString(db); assertEquals(expected, metadataDDL); }
public static String getDDLString(Schema schema, EnumSet<SchemaObjectType> types, String regexPattern) { DDLStringVisitor visitor = new DDLStringVisitor(types, regexPattern); visitor.visit(schema); return visitor.toString(); }
DDLStringVisitor { public static String getDDLString(Schema schema, EnumSet<SchemaObjectType> types, String regexPattern) { DDLStringVisitor visitor = new DDLStringVisitor(types, regexPattern); visitor.visit(schema); return visitor.toString(); } }
DDLStringVisitor { public static String getDDLString(Schema schema, EnumSet<SchemaObjectType> types, String regexPattern) { DDLStringVisitor visitor = new DDLStringVisitor(types, regexPattern); visitor.visit(schema); return visitor.toString(); } DDLStringVisitor(EnumSet<SchemaObjectType> types, String regexPattern); }
DDLStringVisitor { public static String getDDLString(Schema schema, EnumSet<SchemaObjectType> types, String regexPattern) { DDLStringVisitor visitor = new DDLStringVisitor(types, regexPattern); visitor.visit(schema); return visitor.toString(); } DDLStringVisitor(EnumSet<SchemaObjectType> types, String regexPattern); static String getDDLString(Schema schema, EnumSet<SchemaObjectType> types, String regexPattern); static String getDDLString(Database database); void visit(Database database); String addTableBody(Table table); @Override String toString(); static String getDomainDDLString(Database database); }
DDLStringVisitor { public static String getDDLString(Schema schema, EnumSet<SchemaObjectType> types, String regexPattern) { DDLStringVisitor visitor = new DDLStringVisitor(types, regexPattern); visitor.visit(schema); return visitor.toString(); } DDLStringVisitor(EnumSet<SchemaObjectType> types, String regexPattern); static String getDDLString(Schema schema, EnumSet<SchemaObjectType> types, String regexPattern); static String getDDLString(Database database); void visit(Database database); String addTableBody(Table table); @Override String toString(); static String getDomainDDLString(Database database); static final String GENERATED; }