Commits

tbrugz committed 92c7c54

model/sqldiff: added materialized_view object type, better type diff output

  • Participants
  • Parent commits fe5c279

Comments (0)

Files changed (3)

src/tbrugz/sqldump/dbmodel/DBIdentifiable.java

 	//used for 'DROP' statements
 	public static DBObjectType getType4Diff(DBIdentifiable ident) {
 		if(ident instanceof FK) { return DBObjectType.CONSTRAINT; }
+		if(ident instanceof MaterializedView) { return DBObjectType.MATERIALIZED_VIEW; }
 		if(ident instanceof ExecutableObject) { return ((ExecutableObject)ident).type; }
 		return DBIdentifiable.getType(ident);
 	}

src/tbrugz/sqldump/dbmodel/DBObjectType.java

 
 public enum DBObjectType {
 	TABLE, FK, VIEW, INDEX, EXECUTABLE, TRIGGER, SEQUENCE, SYNONYM, GRANT, //main types
+	MATERIALIZED_VIEW, //sub-types?
 	FUNCTION, JAVA_SOURCE, PACKAGE, PACKAGE_BODY, PROCEDURE, /*TRIGGER,*/ TYPE, TYPE_BODY, //executable types
 	
 	CONSTRAINT, COLUMN; //non '1st class' objects
-	//GRANT?
 	
-	//XXX: include PROCEDURE, FUNCTION, PACKAGE, PACKAGE_BODY, TYPE, MATERIALIZED VIEW, TYPE BODY, JAVA SOURCE, PROGRAM, SCHEDULE?
+	//XXX: include PROGRAM, SCHEDULE?
+	//XXX: oracle: java_class, java_resource, java_source: http://docs.oracle.com/cd/B28359_01/server.111/b28286/statements_5013.htm
 	//XXX: executables: FUNCTION, JAVA SOURCE, PACKAGE, PACKAGE BODY, PROCEDURE, TRIGGER, TYPE, TYPE BODY - "select distinct type from all_source"
+	
+	public String desc() {
+		switch (this) {
+		case JAVA_SOURCE:
+			return "java source";
+		case MATERIALIZED_VIEW:
+			return "materialized view";
+		case PACKAGE_BODY:
+			return "package body";
+		case TYPE_BODY:
+			return "type body";
+		}
+		
+		return this.name().toLowerCase();
+	}
 }

src_diff/tbrugz/sqldiff/model/DBIdentifiableDiff.java

 			//case ALTER:  return "ALTER "+ident.getDefinition(true);
 			//case RENAME:  return "RENAME "+ident.getDefinition(true);
 			case DROP: return (ownerTableName!=null?"alter table "+ownerTableName+" ":"")+"drop "
-					+ DBIdentifiable.getType4Diff(previousIdent)+" "+(previousIdent.getSchemaName()!=null?previousIdent.getSchemaName()+".":"")+previousIdent.getName()
+					+ DBIdentifiable.getType4Diff(previousIdent).desc()+" "+(previousIdent.getSchemaName()!=null?previousIdent.getSchemaName()+".":"")+previousIdent.getName()
 					+ (addComments?getComment(ident, "new: "):"");
 		}
 		throw new RuntimeException("changetype "+changeType+" not defined on DBIdentifiableDiff.getDiff()");
 	static String getComment(DBIdentifiable dbident, String comment) {
 		if(dbident==null) return "";
 		return "\n/* "+comment
-				+ DBIdentifiable.getType4Diff(dbident)+" "
+				+ DBIdentifiable.getType4Diff(dbident).desc()+" "
 				+ (dbident.getSchemaName()!=null?dbident.getSchemaName()+".":"")+dbident.getName()
 				+ " */";
 	}