tbrugz.sqldiff.util.DiffUtil Maven / Gradle / Ivy
package tbrugz.sqldiff.util;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Properties;
import tbrugz.sqldiff.datadiff.DiffSyntax;
import tbrugz.sqldump.dbmd.DBMSFeatures;
import tbrugz.sqldump.dbmodel.Column;
import tbrugz.sqldump.dbmodel.DBIdentifiable;
import tbrugz.sqldump.dbmodel.DBObject;
import tbrugz.sqldump.dbmodel.DBObjectType;
import tbrugz.sqldump.dbmodel.NamedDBObject;
import tbrugz.sqldump.util.Utils;
public class DiffUtil {
//XXX rename to getDumpableByXXX?
@SuppressWarnings("unchecked")
public static T getDBIdentifiableByTypeSchemaAndName(Collection extends DBIdentifiable> dbids, DBObjectType type, String schemaName, String name) {
for(DBIdentifiable d: dbids) {
if(type.equals(DBIdentifiable.getType(d))
&& (d.getSchemaName()!=null?d.getSchemaName().equalsIgnoreCase(schemaName):true)
&& d.getName().equalsIgnoreCase(name)
&& d.isDumpable())
return (T) d;
}
return null;
}
public static List singleElemList(T s) {
List ret = new ArrayList();
ret.add(s);
return ret;
}
public static List getSyntaxes(Properties prop, DBMSFeatures feat, String propKey) {
List dss = new ArrayList();
List syntaxes = Utils.getStringListFromProp(prop, propKey, ",");
if(syntaxes!=null) {
for(String s: syntaxes) {
DiffSyntax ds = getSyntax(prop, feat, s);
if(ds!=null) {
dss.add(ds);
}
}
}
return dss;
}
public static DiffSyntax getSyntax(Properties prop, DBMSFeatures feat, String className) {
DiffSyntax ds = (DiffSyntax) Utils.getClassInstance(className, "tbrugz.sqldiff.datadiff");
if(ds!=null) {
ds.procProperties(prop);
if(ds.needsDBMSFeatures()) { ds.setFeatures(feat); }
return ds;
}
return null;
}
public static String createAlterColumn(DBMSFeatures feat, NamedDBObject table, Column column, String xtraSql) {
return "alter table "+DBObject.getFinalName(table, true)+" "+feat.sqlAlterColumnClause()+" "+column.getName()
+(xtraSql!=null?xtraSql:"");
}
}