Commits

tbrugz committed ca5a36b

model: changes & refactorings

Comments (0)

Files changed (12)

src/tbrugz/sqldump/dbmodel/DBIdentifiable.java

 	//XXX: getDefinition() should have 'sql dialect' param?
 	public abstract String getDefinition(boolean dumpSchemaName);
 
+	@SuppressWarnings("unchecked")
 	public static <T extends DBIdentifiable> T getDBIdentifiableByTypeSchemaAndName(Collection<? extends DBIdentifiable> dbids, DBObjectType type, String schemaName, String name) {
 		for(DBIdentifiable d: dbids) {
 			if(type.equals(getType4Diff(d)) 
 		return null;
 	}
 
+	@SuppressWarnings("unchecked")
 	public static <T extends DBIdentifiable> T getDBIdentifiableByTypeAndName(Collection<? extends DBIdentifiable> dbids, DBObjectType type, String name) {
 		for(DBIdentifiable d: dbids) {
 			if(type.equals(getType4Diff(d)) 
 		return null;
 	}
 	
+	@SuppressWarnings("unchecked")
 	public static <T extends DBIdentifiable> T getDBIdentifiableByTypeAndNameIgnoreCase(Collection<? extends DBIdentifiable> dbids, DBObjectType type, String name) {
 		for(DBIdentifiable d: dbids) {
 			if(type.equals(getType4Diff(d)) 

src/tbrugz/sqldump/dbmodel/DBObject.java

 		return getFinalQualifiedName(true);
 	}
 	
-	public String getFinalQualifiedName(boolean dumpschema) {
-		return ((dumpschema && schemaName!=null)?
+	public String getFinalQualifiedName(boolean dumpSchemaName) {
+		return ((dumpSchemaName && schemaName!=null)?
 				sqlIddecorator.get(schemaName)+".":"")+sqlIddecorator.get(name);
 	}
 	

src/tbrugz/sqldump/dbmodel/ExecutableObject.java

  * create package: http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_6006.htm
  */
 public class ExecutableObject extends DBObject {
-
+	private static final long serialVersionUID = 1L;
+	
 	//public String type;
 	DBObjectType type;
 	public String body;
 	
 	@Override
 	public String toString() {
-		return "[Executable:"+type+":"+schemaName+"."+name+
+		return "[Executable:"+type+":"+getSchemaName()+"."+getName()+
 				(packageName!=null?";pkg="+packageName:"")
 				+"]";
 	}

src/tbrugz/sqldump/dbmodel/ExecutableParameter.java

 import java.io.Serializable;
 
 public class ExecutableParameter implements Serializable {
+	private static final long serialVersionUID = 1L;
+
 	public enum INOUT {
 		IN,
 		OUT,

src/tbrugz/sqldump/dbmodel/Index.java

  * XXX: index type. e.g. bitmap (done for oracle)
  */
 public class Index extends DBObject {
+	private static final long serialVersionUID = 1L;
 	
 	public boolean unique;
 	public String type;
 	
 	@Override
 	public String getDefinition(boolean dumpSchemaName) {
-		String objectNamePrepend = (dumpSchemaName?DBObject.getFinalIdentifier(schemaName)+".":"");
-		return "create "+(unique?"unique ":"")+(type!=null?type+" ":"")+"index "+objectNamePrepend+DBObject.getFinalIdentifier(name)+" on "+objectNamePrepend+DBObject.getFinalIdentifier(tableName)
+		String objectNamePrepend = (dumpSchemaName?DBObject.getFinalIdentifier(getSchemaName())+".":"");
+		return "create "+(unique?"unique ":"")+(type!=null?type+" ":"")+"index "+getFinalQualifiedName(dumpSchemaName)
+			+" on "+objectNamePrepend+DBObject.getFinalIdentifier(tableName)
 			+" ("+Utils.join(columns, ", ", SQLIdentifierDecorator.getInstance())+")"
 			+((local!=null && local)?" local":"")
-			+(reverse!=null&&reverse?" reverse":"")+(comment!=null?" --"+comment:"");
+			+(reverse!=null&&reverse?" reverse":"")+(comment!=null?" /* "+comment+" */":"");
 	}
 	
 	@Override
 	public String toString() {
-		return "[Index:"+schemaName+"."+name+":t:"+tableName+",u?:"+unique+",c:"+columns+"]";
+		return "[Index:"+getSchemaName()+"."+getName()+":t:"+tableName+",u?:"+unique+",c:"+columns+"]";
 	}
 	
 	@Override

src/tbrugz/sqldump/dbmodel/MaterializedView.java

  * TODO: mviews: refresh on commit|demand ; tablespace
  */
 public class MaterializedView extends View {
-	//public boolean materialized = true;
-	
+	private static final long serialVersionUID = 1L;
+
 	@Override
 	public String getDefinition(boolean dumpSchemaName) {
 		return (dumpCreateOrReplace?"create or replace ":"create ") + "materialized view "
-				+ (dumpSchemaName && schemaName!=null?DBObject.getFinalIdentifier(schemaName)+".":"") + DBObject.getFinalIdentifier(name) + " as \n" + query;
+				+ getFinalQualifiedName(dumpSchemaName) + " as \n" + query;
 	}
 	
 	@Override
 	public String toString() {
-		return "MaterializedView["+name+"]";
+		return "MaterializedView["+getName()+"]";
 	}
 	
 	/*@Override

src/tbrugz/sqldump/dbmodel/Query.java

 import java.util.List;
 
 public class Query extends View {
+	private static final long serialVersionUID = 1L;
+
 	public String id;
 	public List<String> parameterValues;
 	public Integer parameterCount;

src/tbrugz/sqldump/dbmodel/Sequence.java

  * see: http://download.oracle.com/docs/cd/E14072_01/server.112/e10592/statements_6015.htm
  */
 public class Sequence extends DBObject {
-	
+	private static final long serialVersionUID = 1L;
+
 	public Long minValue;
 	public Long maxValue; //XXX: not used yet
 	public long incrementBy;
 		//XXX: option to use "create or replace" for sequence?
 		//return (dumpCreateOrReplace?"create or replace ":"create ") 
 		return "create " 
-			+"sequence "+(dumpSchemaName?DBObject.getFinalIdentifier(schemaName)+".":"")+DBObject.getFinalIdentifier(name)
+			+"sequence "+getFinalQualifiedName(dumpSchemaName)
 			+(minValue!=null?" minvalue "+minValue:"")
 			+(dumpStartWith?" start with "+lastNumber:"")
 			+" increment by "+incrementBy;
 	
 	@Override
 	public String toString() {
-		return "[Sequence:"+schemaName+"."+name+";min:"+minValue+",max:"+maxValue+"]";
+		return "[Sequence:"+getSchemaName()+"."+getName()+";min:"+minValue+",max:"+maxValue+"]";
 	}
 
 	//XXX: do not use lastNumber

src/tbrugz/sqldump/dbmodel/Synonym.java

 package tbrugz.sqldump.dbmodel;
 
 public class Synonym extends DBObject {
+	private static final long serialVersionUID = 1L;
+
 	boolean publik;
 	public String objectOwner;
 	public String referencedObject;
 		//XXX: option to use "create or replace" for synonym?
 		//return "create "
 		return (dumpCreateOrReplace?"create or replace ":"create ") 
-			+(publik?"public ":"")+"synonym "+(dumpSchemaName?DBObject.getFinalIdentifier(schemaName)+".":"")+DBObject.getFinalIdentifier(name)
+			+(publik?"public ":"")+"synonym "+getFinalQualifiedName(dumpSchemaName)
 			+" for "+objectOwner+"."+referencedObject
 			+(dbLink!=null?"@"+dbLink:"");
 	}
 	
 	@Override
 	public String toString() {
-		return "[Synonym:"+schemaName+"."+name+"->"+objectOwner+"."+referencedObject+"]";
+		return "[Synonym:"+getSchemaName()+"."+getName()+"->"+objectOwner+"."+referencedObject+"]";
 	}
 
 	@Override

src/tbrugz/sqldump/dbmodel/Table.java

 import tbrugz.sqldump.dbmodel.Constraint.ConstraintType;
 
 public class Table extends DBObject implements Relation {
+	private static final long serialVersionUID = 1L;
+
 	TableType type;
 	List<Column> columns = new ArrayList<Column>();
 	List<Grant> grants = new ArrayList<Grant>();
 	
 	public String getDefinition(boolean dumpWithSchemaName, boolean dumpPKs, boolean dumpFKsInsideTable, boolean dumpDropStatements, Properties colTypeConversionProp, Set<FK> foreignKeys) {
 		//List<String> pkCols = new ArrayList<String>();
-		String tableName = (dumpWithSchemaName?getFinalIdentifier(schemaName)+".":"")+getFinalIdentifier(name);
+		String tableName = getFinalQualifiedName(dumpWithSchemaName);
 
 		StringBuffer sb = new StringBuffer();
 		//Table

src/tbrugz/sqldump/dbmodel/Trigger.java

 package tbrugz.sqldump.dbmodel;
 
 public class Trigger extends DBObject {
+	private static final long serialVersionUID = 1L;
+
 	public String description;
 	public String body;
 	public String tableName;

src/tbrugz/sqldump/dbmodel/View.java

  * see: http://publib.boulder.ibm.com/infocenter/iseries/v5r3/index.jsp?topic=%2Fsqlp%2Frbafywcohdg.htm
  */
 public class View extends DBObject implements Relation {
-	
+	private static final long serialVersionUID = 1L;
+
 	public enum CheckOptionType {
 		LOCAL, CASCADED, NONE, 
 		TRUE; //true: set for databases that doesn't have local and cascaded options 
 		}
 		
 		return (dumpCreateOrReplace?"create or replace ":"create ") + "view "
-				+ (dumpSchemaName && schemaName!=null?DBObject.getFinalIdentifier(schemaName)+".":"") + DBObject.getFinalIdentifier(name)
+				+ getFinalQualifiedName(dumpSchemaName)
 				+ (sbConstraints.length()>0?" (\n\t"
 						+ ((columns!=null&&columns.size()>0)?Utils.join(getColumnNames(), ", ")+",\n\t":"")
 						+ sbConstraints.toString()+"\n)":"")
 	
 	@Override
 	public String toString() {
-		return "View["+name+"]";
+		return "View["+getName()+"]";
 	}
 	
 	@Override