Commits

tbrugz  committed d5cfdb6

model: added NamedDBObject, small changes, synonym & grants bugfixing

  • Participants
  • Parent commits ca5a36b

Comments (0)

Files changed (8)

File src/tbrugz/sqldump/SchemaModelScriptDumper.java

 	
 	boolean dumpDropStatements = false;
 	boolean dumpWithCreateOrReplace = false;
+	//boolean dumpWriteAppend = false;
 	
 	//Properties dbmsSpecificsProperties;
 	String fromDbId, toDbId;
 	static final String PROP_SCHEMADUMP_DUMPDROPSTATEMENTS = "sqldump.schemadump.dumpdropstatements";
 	static final String PROP_SCHEMADUMP_USECREATEORREPLACE = "sqldump.schemadump.usecreateorreplace";
 	static final String PROP_SCHEMADUMP_QUOTEALLSQLIDENTIFIERS = "sqldump.schemadump.quoteallsqlidentifiers";
+	//static final String PROP_SCHEMADUMP_WRITEAPPEND = "sqldump.schemadump.writeappend";
 	
 	Map<DBObjectType, DBObjectType> mappingBetweenDBObjectTypes = new HashMap<DBObjectType, DBObjectType>();
 	
 		dumpMaterializedViewAsTable = Utils.getPropBool(prop, PROP_DUMP_MATERIALIZEDVIEW_AS_TABLE, dumpMaterializedViewAsTable); //default should be 'true'?
 		dumpDropStatements = Utils.getPropBool(prop, PROP_SCHEMADUMP_DUMPDROPSTATEMENTS, dumpDropStatements);
 		dumpWithCreateOrReplace = Utils.getPropBool(prop, PROP_SCHEMADUMP_USECREATEORREPLACE, dumpWithCreateOrReplace);
+		//dumpWriteAppend = Utils.getPropBool(prop, PROP_SCHEMADUMP_WRITEAPPEND, dumpWriteAppend);
 		DBObject.dumpCreateOrReplace = dumpWithCreateOrReplace;
 		SQLIdentifierDecorator.dumpQuoteAll = Utils.getPropBool(prop, PROP_SCHEMADUMP_QUOTEALLSQLIDENTIFIERS, SQLIdentifierDecorator.dumpQuoteAll);
 
 				}
 			}
 
-			String tableName = (dumpWithSchemaName?table.getSchemaName()+".":"")+table.getName();
+			String tableName = DBObject.getFinalQualifiedName(table.getSchemaName(), table.getName(), dumpWithSchemaName);
 			
 			//Grants
 			if(dumpGrantsWithReferencingTable) {
 		if(!dumpGrantsWithReferencingTable) {
 			//tables
 			for(Table table: schemaModel.getTables()) {
-				String tableName = (dumpWithSchemaName?table.getSchemaName()+".":"")+table.getName();
+				String tableName = DBObject.getFinalQualifiedName(table.getSchemaName(), table.getName(), dumpWithSchemaName);
 				String grantOutput = compactGrantDump(table.getGrants(), tableName, toDbId);
 				if(grantOutput!=null && !"".equals(grantOutput)) {
 					categorizedOut(table.getSchemaName(), table.getName(), DBObjectType.GRANT, grantOutput);
 			//TODO: how to dump exec grants if 'dumpGrantsWithReferencingTable' is true?
 			//XXX: compactGrantDump for Executable's Grants doesn't make sense, since there is only one type of privilege for Executables (EXECUTE) (for now?)
 			for(ExecutableObject eo: schemaModel.getExecutables()) {
-				String eoName = (dumpWithSchemaName?eo.getSchemaName()+".":"")+eo.getName();
+				String eoName = DBObject.getFinalQualifiedName(eo.getSchemaName(), eo.getName(), dumpWithSchemaName);
 				//log.debug("exec to dump grants: "+eoName+" garr: "+eo.grants);
 				String grantOutput = compactGrantDump(eo.grants, eoName, toDbId);
 				if(grantOutput!=null && !"".equals(grantOutput)) {
 	}
 	
 	public static String fkScriptWithAlterTable(FK fk, boolean dumpDropStatements, boolean dumpWithSchemaName) {
-		String fkTableName = (dumpWithSchemaName?DBObject.getFinalIdentifier(fk.getFkTableSchemaName())+".":"")+DBObject.getFinalIdentifier(fk.getFkTable());
+		String fkTableName = DBObject.getFinalQualifiedName(fk.getFkTableSchemaName(), fk.getFkTable(), dumpWithSchemaName);
 		return
 			(dumpDropStatements?"--alter table "+fkTableName+" drop constraint "+fk.getName()+";\n":"")
 			+"alter table "+fkTableName
 		fos.close();
 	}
 
-	String simpleGrantDump(Collection<Grant> grants, String tableName, String toDbId) {
+	@Deprecated
+	String simpleGrantDump(Collection<Grant> grants, String finalTableName, String toDbId) {
 		StringBuffer sb = new StringBuffer();
 		
 		for(Grant grant: grants) {
 			sb.append("grant "+grant.privilege
-					+" on "+DBObject.getFinalIdentifier(tableName)
+					+" on "+finalTableName
 					+" to "+grant.grantee
 					+(grant.withGrantOption?" WITH GRANT OPTION":"")
 					+";\n\n");
 		return "";
 	}
 	
-	String compactGrantDump(Collection<Grant> grants, String tableName, String toDbId) {
+	String compactGrantDump(Collection<Grant> grants, String finalTableName, String toDbId) {
 		Map<String, Set<PrivilegeType>> mapWithGrant = new TreeMap<String, Set<PrivilegeType>>();
 		Map<String, Set<PrivilegeType>> mapWOGrant = new TreeMap<String, Set<PrivilegeType>>();
 		
 			Set<PrivilegeType> privs = mapWithGrant.get(grantee);
 			String privsStr = Utils.join(privs, ", ");
 			sb.append("grant "+privsStr
-					+" on "+DBObject.getFinalIdentifier(tableName)
+					+" on "+finalTableName
 					+" to "+grantee
 					+" WITH GRANT OPTION"+";\n\n");
 			/*for(PrivilegeType priv: privs) {
 			Set<PrivilegeType> privs = mapWOGrant.get(grantee);
 			String privsStr = Utils.join(privs, ", ");
 			sb.append("grant "+privsStr
-					+" on "+DBObject.getFinalIdentifier(tableName)
+					+" on "+finalTableName
 					+" to "+grantee
 					+";\n\n");
 			/*for(PrivilegeType priv: privs) {

File src/tbrugz/sqldump/dbmodel/DBIdentifiable.java

 import tbrugz.sqldump.dbmodel.Constraint.ConstraintType;
 
 //XXX implement Comparable<DBIdentifiable>? 
-public abstract class DBIdentifiable {
+public abstract class DBIdentifiable implements NamedDBObject {
 	String schemaName;
 	String name;
 

File src/tbrugz/sqldump/dbmodel/DBObject.java

 		return null;
 	}
 	
-	public static String getFinalIdentifier(String id) {
-		//return (dumpQuoteAll?dumpIdentifierQuoteString:"")+id+(dumpQuoteAll?dumpIdentifierQuoteString:"");
+	static String getFinalIdentifier(String id) {
 		return sqlIddecorator.get(id);
 	}
 	
+	/*private static String getFinalQualifiedName(NamedDBObject dbobject, boolean dumpSchemaName) {
+		return ((dumpSchemaName && dbobject.getSchemaName()!=null)?
+				sqlIddecorator.get(dbobject.getSchemaName())+".":"")+sqlIddecorator.get(dbobject.getName());
+	}*/
+
+	public static String getFinalQualifiedName(String schemaName, String name, boolean dumpSchemaName) {
+		return ((dumpSchemaName && schemaName!=null)?
+				sqlIddecorator.get(schemaName)+".":"")+sqlIddecorator.get(name);
+	}
 }

File src/tbrugz/sqldump/dbmodel/FK.java

 		whitespace = whitespace.replaceAll("[^ \n\t]", " ");
 		return "constraint "+DBObject.getFinalIdentifier(getName())
 			+" foreign key ("+Utils.join(fkColumns, ", ", SQLIdentifierDecorator.getInstance())+")"
-			+whitespace+"references "+(dumpWithSchemaName?DBObject.getFinalIdentifier(pkTableSchemaName)+".":"")
-			+DBObject.getFinalIdentifier(pkTable)+" ("+Utils.join(pkColumns, ", ", SQLIdentifierDecorator.getInstance())+")"
+			+whitespace+"references "
+			+DBObject.getFinalQualifiedName(pkTableSchemaName, pkTable, dumpWithSchemaName)
+			+" ("+Utils.join(pkColumns, ", ", SQLIdentifierDecorator.getInstance())+")"
 			+(updateRule!=null && updateRule!=UpdateRule.NO_ACTION?" on update "+updateRule:"")
 			+(deleteRule!=null && deleteRule!=UpdateRule.NO_ACTION?" on delete "+deleteRule:"")
 			;

File src/tbrugz/sqldump/dbmodel/Index.java

 	
 	@Override
 	public String getDefinition(boolean dumpSchemaName) {
-		String objectNamePrepend = (dumpSchemaName?DBObject.getFinalIdentifier(getSchemaName())+".":"");
 		return "create "+(unique?"unique ":"")+(type!=null?type+" ":"")+"index "+getFinalQualifiedName(dumpSchemaName)
-			+" on "+objectNamePrepend+DBObject.getFinalIdentifier(tableName)
+			+" on "+DBObject.getFinalQualifiedName(getSchemaName(), tableName, dumpSchemaName)
 			+" ("+Utils.join(columns, ", ", SQLIdentifierDecorator.getInstance())+")"
 			+((local!=null && local)?" local":"")
 			+(reverse!=null&&reverse?" reverse":"")+(comment!=null?" /* "+comment+" */":"");

File src/tbrugz/sqldump/dbmodel/NamedDBObject.java

+package tbrugz.sqldump.dbmodel;
+
+public interface NamedDBObject {
+	public String getName();
+	public String getSchemaName();
+}

File src/tbrugz/sqldump/dbmodel/Relation.java

 
 import java.util.List;
 
-public interface Relation {
+public interface Relation extends NamedDBObject {
 	
-	public String getName();
-
 	public void setName(String name);
 
-	public String getSchemaName();
-
 	public void setSchemaName(String schemaName);
 	
 	/*public List<Column> getColumns();

File src/tbrugz/sqldump/dbmodel/Synonym.java

 		//return "create "
 		return (dumpCreateOrReplace?"create or replace ":"create ") 
 			+(publik?"public ":"")+"synonym "+getFinalQualifiedName(dumpSchemaName)
-			+" for "+objectOwner+"."+referencedObject
+			+" for "+DBObject.getFinalQualifiedName(objectOwner, referencedObject, dumpSchemaName)
 			+(dbLink!=null?"@"+dbLink:"");
 	}