1. tbrugz
  2. sqldump

Commits

tbrugz  committed faa5aed

dumper: SchemaModelScriptDumper: more props refactoring

  • Participants
  • Parent commits 9d78b12
  • Branches default

Comments (0)

Files changed (3)

File sqldump.template.properties

View file
 # filepattern output props
 # patterns that may be used: [schemaname], [objecttype], [objectname]
 #
-sqldump.mainoutputfilepattern=${outputdir}/[schemaname]_[objecttype].sql
-sqldump.outputobjectwithreferencingtable=grant, index
+sqldump.schemadump.outputfilepattern=${outputdir}/[schemaname]_[objecttype].sql
+sqldump.schemadump.outputobjectwithreferencingtable=grant, index
 #sqldump.outputfilepattern.maptype.PROCEDURE=EXECUTABLE
 #sqldump.outputfilepattern.maptype.TRIGGER=EXECUTABLE
 #sqldump.outputfilepattern.maptype.FUNCTION=EXECUTABLE
 #sqldump.outputfilepattern.bytype.EXECUTABLE=${outputdir}/EXECUTABLEs.sql
 
-# to directly dump scripts to another database (use instead of 'sqldump.mainoutputfilepattern')
+# to directly dump scripts to another database (use instead of 'sqldump.schemadump.outputfilepattern')
 #sqldump.schemadump.output.connpropprefix=sqldump.conn-v2
 
 # other sqldump.outputfilepattern examples:
-#sqldump.outputfilepattern=output/[schemaname]/[objecttype]/[objectname].sql
-#sqldump.outputfilepattern=output/[objecttype]/[schemaname]_[objectname].sql
-#sqldump.outputobjectwithreferencingtable=grant, index, fk, trigger
+#sqldump.schemadump.outputfilepattern=output/[schemaname]/[objecttype]/[objectname].sql
+#sqldump.schemadump.outputfilepattern=output/[objecttype]/[schemaname]_[objectname].sql
+#sqldump.schemadump.outputobjectwithreferencingtable=grant, index, fk, trigger
 
-# other outputfilepattern by object types. "sqldump.outputobjectwithreferencingtable" takes precedence
+# other outputfilepattern by object types. 'sqldump.schemadump.outputobjectwithreferencingtable' takes precedence
 #sqldump.outputfilepattern.bytype.TABLE=output/TABLE.sql
 #sqldump.outputfilepattern.bytype.VIEW=output/VIEW.sql
 #sqldump.outputfilepattern.bytype.INDEX=output/INDEX.sql
 #sqldump.schemadump.dumpmaterializedviewastable=false
 #sqldump.schemadump.dumpdropstatements=false
 #sqldump.schemadump.usecreateorreplace=false
-#sqldump.doschemadump.fks.atend=true
+#sqldump.schemadump.fks.atend=true
 # defaults below
 #sqldump.schemadump.dumpscriptcomments=true
 #sqldump.schemadump.dumpremarks=true

File src/tbrugz/sqldump/SchemaModelScriptDumper.java

View file
 	@Deprecated
 	static final String FILENAME_PATTERN_OBJECTNAME_QUOTED = Pattern.quote(FILENAME_PATTERN_OBJECTNAME);
 
-	static final String PROP_OUTPUT_OBJECT_WITH_REFERENCING_TABLE = "sqldump.outputobjectwithreferencingtable";
+	@Deprecated static final String PROP_OUTPUT_OBJECT_WITH_REFERENCING_TABLE = "sqldump.outputobjectwithreferencingtable";
 
-	static final String PROP_MAIN_OUTPUT_FILE_PATTERN = "sqldump.mainoutputfilepattern";
-	@Deprecated static final String PROP_OUTPUTFILE = "sqldump.outputfile";
+	@Deprecated static final String PROP_MAIN_OUTPUT_FILE_PATTERN = "sqldump.mainoutputfilepattern";
 	static final String PROP_OUTPUT_CONN_PROP_PREFIX = PREFIX+".output.connpropprefix";
 
-	static final String PROP_DO_SCHEMADUMP_FKS_ATEND = "sqldump.doschemadump.fks.atend";
+	@Deprecated static final String PROP_DO_SCHEMADUMP_FKS_ATEND = "sqldump.doschemadump.fks.atend";
 
 	static final String PROP_SCHEMADUMP_SYNONYM_AS_TABLE = PREFIX+".dumpsynonymastable";
 	static final String PROP_SCHEMADUMP_VIEW_AS_TABLE = PREFIX+".dumpviewastable";
 	@Deprecated static final String PROP_DUMP_MATERIALIZEDVIEW_AS_TABLE = "sqldump.dumpmaterializedviewastable";
 
 	//also used by SQLDiff
-	static final String PROP_DUMP_WITH_SCHEMA_NAME = "sqldump.dumpwithschemaname"; //SQLDiff?
+	static final String PROP_DUMP_WITH_SCHEMA_NAME = "sqldump.dumpwithschemaname"; //XXX SQLDiff should use this?
 	public static final String PROP_SCHEMADUMP_USECREATEORREPLACE = PREFIX+".usecreateorreplace";
 	public static final String PROP_SCHEMADUMP_QUOTEALLSQLIDENTIFIERS = PREFIX+".quoteallsqlidentifiers";
 
 	static final String PROP_SCHEMADUMP_FKs = PREFIX+".fks";
 	//static final String PROP_SCHEMADUMP_WRITEAPPEND = PREFIX+".writeappend";
 	
+	static final String PROP_SCHEMADUMP_OUTPUT_FILE_PATTERN = PREFIX+".outputfilepattern";
+	static final String PROP_SCHEMADUMP_OUTPUT_OBJECT_WITH_REFERENCING_TABLE = PREFIX+".outputobjectwithreferencingtable";
+	static final String PROP_SCHEMADUMP_FKS_ATEND =  PREFIX+".fks.atend";
+	
+	static final String PREFIX_OUTPATTERN_BYTYPE = "sqldump.outputfilepattern.bytype";
+	
 	Map<DBObjectType, DBObjectType> mappingBetweenDBObjectTypes = new HashMap<DBObjectType, DBObjectType>();
 	
 	@Override
 		//init control vars
 		doSchemaDumpPKs = Utils.getPropBoolWithDeprecated(prop, PROP_SCHEMADUMP_PKS, JDBCSchemaGrabber.PROP_DO_SCHEMADUMP_PKS, doSchemaDumpPKs);
 		//XXX doSchemaDumpFKs = prop.getProperty(SQLDataDump.PROP_DO_SCHEMADUMP_FKS, "").equals("true");
-		boolean doSchemaDumpFKsAtEnd = Utils.getPropBool(prop, PROP_DO_SCHEMADUMP_FKS_ATEND, !dumpFKsInsideTable);
+		boolean doSchemaDumpFKsAtEnd = Utils.getPropBoolWithDeprecated(prop, PROP_SCHEMADUMP_FKS_ATEND, PROP_DO_SCHEMADUMP_FKS_ATEND, !dumpFKsInsideTable);
 		//XXX doSchemaDumpGrants = prop.getProperty(SQLDataDump.PROP_DO_SCHEMADUMP_GRANTS, "").equals("true");
 		dumpWithSchemaName = Utils.getPropBool(prop, PROP_DUMP_WITH_SCHEMA_NAME, dumpWithSchemaName);
 		dumpSynonymAsTable = Utils.getPropBoolWithDeprecated(prop, PROP_SCHEMADUMP_SYNONYM_AS_TABLE, PROP_DUMP_SYNONYM_AS_TABLE, dumpSynonymAsTable);
 		toDbId = prop.getProperty(Defs.PROP_TO_DB_ID);
 		dumpFKsInsideTable = !doSchemaDumpFKsAtEnd;
 		
-		mainOutputFilePattern = prop.getProperty(PROP_MAIN_OUTPUT_FILE_PATTERN);
-		if(mainOutputFilePattern==null) {
-			mainOutputFilePattern = prop.getProperty(PROP_OUTPUTFILE);
-			if(mainOutputFilePattern!=null) {
-				log.warn("using deprecated property '"+PROP_OUTPUTFILE+"' - use '"+PROP_MAIN_OUTPUT_FILE_PATTERN+"' instead");
-			}
-		}
+		mainOutputFilePattern = Utils.getPropWithDeprecated(prop, PROP_SCHEMADUMP_OUTPUT_FILE_PATTERN, PROP_MAIN_OUTPUT_FILE_PATTERN, mainOutputFilePattern);
 		if(mainOutputFilePattern==null) {
 			outputConnPropPrefix = prop.getProperty(PROP_OUTPUT_CONN_PROP_PREFIX);
 		}
 		
-		String outputobjectswithtable = prop.getProperty(PROP_OUTPUT_OBJECT_WITH_REFERENCING_TABLE);
+		String outputobjectswithtable = Utils.getPropWithDeprecated(prop, PROP_SCHEMADUMP_OUTPUT_OBJECT_WITH_REFERENCING_TABLE, PROP_OUTPUT_OBJECT_WITH_REFERENCING_TABLE, null);
 		if(outputobjectswithtable!=null) {
 			String[] outputsWith = outputobjectswithtable.split(",");
 			for(String out: outputsWith) {
 		DBObjectType mappedObjectType = mappingBetweenDBObjectTypes.get(objectType);
 		if(mappedObjectType!=null) { objectType = mappedObjectType; }
 		
-		String outFilePattern = prop.getProperty("sqldump.outputfilepattern.bytype."+objectType.name());
+		String outFilePattern = prop.getProperty(PREFIX_OUTPATTERN_BYTYPE+"."+objectType.name());
 		if(outFilePattern==null) {
 			outFilePattern = mainOutputFilePattern;
 		}
 		if(outFilePattern==null) {
-			throw new RuntimeException("output file patterns (e.g. 'sqldump.mainoutputfilepattern') not defined, aborting");
+			throw new RuntimeException("output file patterns (e.g. '"+PROP_SCHEMADUMP_OUTPUT_FILE_PATTERN+"') not defined, aborting");
 		}
 		
 		//if 'static' writer

File src/tbrugz/sqldump/util/Utils.java

View file
 		return DatatypeConverter.printBase64Binary(str.getBytes());
 	}
 	
+	public static String getPropWithDeprecated(Properties p, String key, String deprecatedKey, String defaultValue) {
+		String ret = defaultValue;
+		if(Utils.propertyExists(p, deprecatedKey)) {
+			log.warn("deprecated prop '"+deprecatedKey+"' present - use '"+key+"' instead");
+			ret = p.getProperty(deprecatedKey, defaultValue);
+		}
+		ret = p.getProperty(key, ret);
+		return ret;
+	}
+
 	public static boolean getPropBoolWithDeprecated(Properties p, String key, String deprecatedKey, boolean defaultValue) {
 		boolean ret = defaultValue;
 		if(Utils.propertyExists(p, deprecatedKey)) {