Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TOOLS-4536] Modify dump file directory, name #124

Merged
merged 6 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public class Grant extends
private String authType;
private boolean isGrantable;
private String createDDL;
private String sourceOwner;

public Grant() {
//do nothing
Expand Down Expand Up @@ -156,6 +157,14 @@ public String getDDL() {
public void setDDL(String createDDL) {
this.createDDL = createDDL;
}

public String getSourceOwner() {
return sourceOwner;
}

public void setSourceOwner(String sourceOwner) {
this.sourceOwner = sourceOwner;
}

@Override
public String getObjType() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public class Sequence extends
private String owner;
private String comment;
private String targetOwner;
private String sourceOwner;


public Sequence() {
Expand Down Expand Up @@ -178,6 +179,14 @@ public String getOwner() {
return owner;
}

public String getSourceOwner() {
return sourceOwner;
}

public void setSourceOwner(String sourceOwner) {
this.sourceOwner = sourceOwner;
}

public String getTargetOwner() {
return targetOwner;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public class Synonym extends
private String objectOwner;
private String comment;
private String createDDL;
private String sourceOwner;

public Synonym() {
//do nothing
Expand Down Expand Up @@ -139,6 +140,14 @@ public String getObjType() {
public void setDDL(String createDDL) {
this.createDDL = createDDL;
}

public String getSourceOwner() {
return sourceOwner;
}

public void setSourceOwner(String sourceOwner) {
this.sourceOwner = sourceOwner;
}

@Override
public String getDDL() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public abstract class TableOrView extends
*/
protected String owner;
protected String targetOwner;
protected String sourceOwner;

protected final List<Column> columns = new ArrayList<Column>();

Expand All @@ -66,6 +67,14 @@ public void setTargetOwner(String targetOwner) {
this.targetOwner = targetOwner;
}

public String getSourceOwner() {
return sourceOwner;
}

public void setSourceOwner(String sourceOwner) {
this.sourceOwner = sourceOwner;
}

public Schema getSchema() {
return schema;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,7 @@ private void buildSerialCfg(boolean isReset) {
tseq = (Sequence) seq.clone();
tseq.setName(sc.getTarget());
tseq.setOwner(sc.getTargetOwner());
tseq.setSourceOwner(sc.getOwner());
tseq.setDDL(cubridddlUtil.getSequenceDDL(tseq, this.addUserSchema));
tseq.setComment(seq.getComment());
}
Expand Down Expand Up @@ -773,6 +774,7 @@ private void buildGrantCfg(boolean isReset) {
tgrant.setClassOwner(sc.getClassOwner());
tgrant.setGrantable(sc.isGrantable());
tgrant.setName(tgrant.getName());
tgrant.setSourceOwner(sc.getOwner());
sc.setTarget(tgrant.getName());
tgrant.setDDL(cubridddlUtil.getGrantDDL(tgrant, this.addUserSchema));
}
Expand Down Expand Up @@ -830,6 +832,7 @@ private void buildSynonymCfg(boolean isReset) {
tsynonym.setOwner(sourceDBSchema.getTargetSchemaName());
tsynonym.setObjectOwner(getTargetOwner(schemas, synonym.getObjectOwner()));
tsynonym.setDDL(cubridddlUtil.getSynonymDDL(tsynonym, this.addUserSchema));
tsynonym.setSourceOwner(sourceDBSchema.getName());
}
tempSynonyms.add(tsynonym);
}
Expand All @@ -840,28 +843,35 @@ private void buildSynonymCfg(boolean isReset) {
targetSynonyms.addAll(tempSynonyms);
}

public void createDumpfile(boolean isSplit) {
Iterator<String> keys = scriptSchemaMapping.keySet().iterator();
while (keys.hasNext()) {
Schema schema = scriptSchemaMapping.get(keys.next());
String schemaName = schema.getTargetSchemaName();
if (isSplit) {
this.addTargetTableFileName(schemaName, getTableFullName(schemaName));
this.addTargetViewFileName(schemaName, getViewFullName(schemaName));
this.addTargetViewQuerySpecFileName(schemaName, getViewQuerySpecFullName(schemaName));
this.addTargetPkFileName(schemaName, getPkFullName(schemaName));
this.addTargetFkFileName(schemaName, getFkFullName(schemaName));
this.addTargetSerialFileName(schemaName, getSequenceFullName(schemaName));
this.addTargetSynonymFileName(schemaName, getSynonymFullName(schemaName));
this.addTargetGrantFileName(schemaName, getGrantFullName(schemaName));
this.addTargetSchemaFileListName(schemaName, getSchemaFileListFullName(schemaName));
} else {
this.addTargetSchemaFileName(schemaName, getSchemaFullName(schemaName));
public void createDumpfile(boolean isSplit, boolean isAddUserSchema) {
if (isAddUserSchema) {
Iterator<String> keys = scriptSchemaMapping.keySet().iterator();
while (keys.hasNext()) {
Schema schema = scriptSchemaMapping.get(keys.next());
addTargetObjectFileName(schema.getName(), isSplit);
}
this.addTargetDataFileName(schemaName, getDataFullName(schemaName));
this.addTargetIndexFileName(schemaName, getIndexFullName(schemaName));
this.addTargetUpdateStatisticFileName(schemaName, getUpdateStatisticFullName(schemaName));
} else {
addTargetObjectFileName(this.getSourceConParams().getConUser(), isSplit);
}
}

private void addTargetObjectFileName(String schemaName, boolean isSplit) {
if (isSplit) {
this.addTargetTableFileName(schemaName, getTableFullName(schemaName));
this.addTargetViewFileName(schemaName, getViewFullName(schemaName));
this.addTargetViewQuerySpecFileName(schemaName, getViewQuerySpecFullName(schemaName));
this.addTargetPkFileName(schemaName, getPkFullName(schemaName));
this.addTargetFkFileName(schemaName, getFkFullName(schemaName));
this.addTargetSerialFileName(schemaName, getSequenceFullName(schemaName));
this.addTargetSynonymFileName(schemaName, getSynonymFullName(schemaName));
this.addTargetGrantFileName(schemaName, getGrantFullName(schemaName));
this.addTargetSchemaFileListName(schemaName, getSchemaFileListFullName(schemaName));
} else {
this.addTargetSchemaFileName(schemaName, getSchemaFullName(schemaName));
}
this.addTargetDataFileName(schemaName, getDataFullName(schemaName));
this.addTargetIndexFileName(schemaName, getIndexFullName(schemaName));
this.addTargetUpdateStatisticFileName(schemaName, getUpdateStatisticFullName(schemaName));
}

private String getTargetOwner(List<Schema> schemas, String owner) {
Expand Down Expand Up @@ -1375,6 +1385,7 @@ private void buildViewCfg(boolean isReset) {
tVw.setName(sc.getTarget());
tVw.setOwner(sc.getTargetOwner());
tVw.setComment(vw.getComment());
tVw.setSourceOwner(sc.getOwner());
}
tempTarList.add(tVw);
}
Expand Down Expand Up @@ -1574,22 +1585,33 @@ public void changeTargetFilePath(String path) {
path2 = path + File.separator;
}

for (Schema schema : srcCatalog.getSchemas()) {
addTargetSchemaFileName(schema.getName(), path2 + targetSchemaFileName.get(schema.getName().substring(tempPath.length())));
addTargetTableFileName(schema.getName(), path2 + targetTableFileName.get(schema.getName().substring(tempPath.length())));
addTargetViewFileName(schema.getName(), path2 + targetViewFileName.get(schema.getName().substring(tempPath.length())));
addTargetViewQuerySpecFileName(schema.getName(), path2 + targetViewQuerySpecFileName.get(schema.getName().substring(tempPath.length())));
addTargetPkFileName(schema.getName(), path2 + targetPkFileName.get(schema.getName().substring(tempPath.length())));
addTargetFkFileName(schema.getName(), path2 + targetFkFileName.get(schema.getName().substring(tempPath.length())));
addTargetDataFileName(schema.getName(), path2 + targetDataFileName.get(schema.getName().substring(tempPath.length())));
addTargetIndexFileName(schema.getName(), path2 + targetIndexFileName.get(schema.getName().substring(tempPath.length())));
addTargetSerialFileName(schema.getName(), path2 + targetSerialFileName.get(schema.getName().substring(tempPath.length())));
addTargetUpdateStatisticFileName(schema.getName(), path2 + targetUpdateStatisticFileName.get(schema.getName().substring(tempPath.length())));
addTargetSchemaFileListName(schema.getName(), path2 + targetSchemaFileListName.get(schema.getName().substring(tempPath.length())));
addTargetSynonymFileName(schema.getName(), path2 + targetSynonymFileName.get(schema.getName().substring(tempPath.length())));
addTargetGrantFileName(schema.getName(), path2 + targetGrantFileName.get(schema.getName().substring(tempPath.length())));
if (isAddUserSchema()) {
for (Schema schema : srcCatalog.getSchemas()) {
mergeTargetFilePath(schema.getName(), tempPath, path2);
}
} else {
mergeTargetFilePath(getSourceConParams().getConUser(), tempPath, path2);
}
}

private void mergeTargetFilePath(String schemaName, String tempPath, String path2) {
if (this.splitSchema) {
addTargetTableFileName(schemaName, path2 + targetTableFileName.get(schemaName.substring(tempPath.length())));
addTargetViewFileName(schemaName, path2 + targetViewFileName.get(schemaName.substring(tempPath.length())));
addTargetViewQuerySpecFileName(schemaName, path2 + targetViewQuerySpecFileName.get(schemaName.substring(tempPath.length())));
addTargetPkFileName(schemaName, path2 + targetPkFileName.get(schemaName.substring(tempPath.length())));
addTargetFkFileName(schemaName, path2 + targetFkFileName.get(schemaName.substring(tempPath.length())));
addTargetSerialFileName(schemaName, path2 + targetSerialFileName.get(schemaName.substring(tempPath.length())));
addTargetSynonymFileName(schemaName, path2 + targetSynonymFileName.get(schemaName.substring(tempPath.length())));
addTargetGrantFileName(schemaName, path2 + targetGrantFileName.get(schemaName.substring(tempPath.length())));
addTargetSchemaFileListName(schemaName, path2 + targetSchemaFileListName.get(schemaName.substring(tempPath.length())));
} else {
addTargetSchemaFileName(schemaName, path2 + targetSchemaFileName.get(schemaName.substring(tempPath.length())));
}
addTargetDataFileName(schemaName, path2 + targetDataFileName.get(schemaName.substring(tempPath.length())));
addTargetIndexFileName(schemaName, path2 + targetIndexFileName.get(schemaName.substring(tempPath.length())));
addTargetUpdateStatisticFileName(schemaName, path2 + targetUpdateStatisticFileName.get(schemaName.substring(tempPath.length())));
}

/**
* Check the OOM risk of migration settings
Expand Down Expand Up @@ -2849,6 +2871,10 @@ public void setTargetSchemaList(List<Schema> targetSchemaList) {
this.targetSchemaList.addAll(targetSchemaList);
}

public void removeTargetSchemaList() {
this.targetSchemaList.clear();
}

/**
* Retrieves the target charset;UTF-8 will be returned by default.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,13 @@ protected void handleDataFile(String fileName, final SourceTableConfig stc, fina
synchronized (lockObj) {
MigrationDirAndFilesManager mdfm = mrManager.getDirAndFilesMgr();

if (!tableFiles.containsKey(stc.getTargetOwner() + stc.getName())) {
tableFiles.put(stc.getTargetOwner() + stc.getName(), new CurrentDataFileInfo(config.getTargetDataFileName(stc.getTargetOwner()),
mdfm.getMergeFilesDir(),config.getTargetFilePrefix(), stc.getTargetOwner(), stc.getName(), config.getDataFileExt()));
String schemaName = config.isAddUserSchema() ? stc.getOwner() : config.getSourceConParams().getConUser();
if (!tableFiles.containsKey(schemaName + stc.getName())) {
tableFiles.put(schemaName + stc.getName(), new CurrentDataFileInfo(config.getTargetDataFileName(schemaName),
mdfm.getMergeFilesDir(), config.getTargetFilePrefix(), schemaName, stc.getName(), config.getDataFileExt()));
}

CurrentDataFileInfo es = tableFiles.get(stc.getTargetOwner() + stc.getName());
CurrentDataFileInfo es = tableFiles.get(schemaName + stc.getName());

//If the target file is full.
if (mdfm.isDataFileFull(es.fileTableFullName)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,8 @@ public void createTable(final Table table) {
String ddl = CUBRIDSQLHelper.getInstance(null).getTableDDL(table, config.isAddUserSchema());
table.setDDL(ddl);
sql.append(ddl).append("\n");
executeDDL(sql.toString(), DBObject.OBJ_TYPE_TABLE, createResultHandler(table), table.getOwner());
executeDDL(sql.toString(), DBObject.OBJ_TYPE_TABLE, createResultHandler(table),
config.isAddUserSchema() ? table.getSourceOwner() : config.getSourceConParams().getConUser());
}

/**
Expand All @@ -655,7 +656,8 @@ public void createTable(final Table table) {
public void createView(View view) {
String viewDDL = CUBRIDSQLHelper.getInstance(null).getViewDDL(view, config.isAddUserSchema());
view.setDDL(viewDDL);
executeDDL(viewDDL + "\n", DBObject.OBJ_TYPE_VIEW, createResultHandler(view), view.getOwner());
executeDDL(viewDDL + "\n", DBObject.OBJ_TYPE_VIEW, createResultHandler(view),
config.isAddUserSchema() ? view.getSourceOwner() : config.getSourceConParams().getConUser());
}

/**
Expand All @@ -666,7 +668,8 @@ public void createView(View view) {
public void alterView(View view) {
String viewAlterDDL = CUBRIDSQLHelper.getInstance(null).getViewAlterDDL(view, config.isAddUserSchema());
view.setAlterDDL(viewAlterDDL);
executeDDL(viewAlterDDL + "\n", DBObject.OBJ_TYPE_VIEW_QUERY_SPEC, createResultHandler(view), view.getOwner());
executeDDL(viewAlterDDL + "\n", DBObject.OBJ_TYPE_VIEW_QUERY_SPEC, createResultHandler(view),
config.isAddUserSchema() ? view.getSourceOwner() : config.getSourceConParams().getConUser());
}

/**
Expand All @@ -678,7 +681,8 @@ public void createPK(PK pk) {
String ddl = CUBRIDSQLHelper.getInstance(null).getPKDDL(pk.getTable().getOwner(), pk.getTable().getName(),
pk.getName(), pk.getPkColumns(), config.isAddUserSchema());
pk.setDDL(ddl);
executeDDL(ddl + ";\n", DBObject.OBJ_TYPE_PK, createResultHandler(pk), pk.getTable().getOwner());
executeDDL(ddl + ";\n", DBObject.OBJ_TYPE_PK, createResultHandler(pk),
config.isAddUserSchema() ? pk.getTable().getSourceOwner() : config.getSourceConParams().getConUser());
}

/**
Expand All @@ -690,7 +694,8 @@ public void createFK(FK fk) {
String ddl = CUBRIDSQLHelper.getInstance(null).getFKDDL(fk.getTable().getOwner(), fk.getTable().getName(),
fk, config.isAddUserSchema());
fk.setDDL(ddl);
executeDDL(ddl + ";\n", DBObject.OBJ_TYPE_FK, createResultHandler(fk), fk.getTable().getOwner());
executeDDL(ddl + ";\n", DBObject.OBJ_TYPE_FK, createResultHandler(fk),
config.isAddUserSchema() ? fk.getTable().getSourceOwner() : config.getSourceConParams().getConUser());
}

/**
Expand All @@ -702,7 +707,8 @@ public void createIndex(Index index) {
String ddl = CUBRIDSQLHelper.getInstance(null).getIndexDDL(index.getTable().getOwner(), index.getTable().getName(),
index, "", config.isAddUserSchema());
index.setDDL(ddl);
executeDDL(ddl + ";\n", DBObject.OBJ_TYPE_INDEX, createResultHandler(index), index.getTable().getOwner());
executeDDL(ddl + ";\n", DBObject.OBJ_TYPE_INDEX, createResultHandler(index),
config.isAddUserSchema() ? index.getTable().getSourceOwner() : config.getSourceConParams().getConUser());
}

/**
Expand All @@ -713,7 +719,8 @@ public void createIndex(Index index) {
public void createSequence(Sequence sq) {
String ddl = CUBRIDSQLHelper.getInstance(null).getSequenceDDL(sq, config.isAddUserSchema());
sq.setDDL(ddl);
executeDDL(ddl + ";\n", DBObject.OBJ_TYPE_SEQUENCE, createResultHandler(sq), sq.getOwner());
executeDDL(ddl + ";\n", DBObject.OBJ_TYPE_SEQUENCE, createResultHandler(sq),
config.isAddUserSchema() ? sq.getSourceOwner() : config.getSourceConParams().getConUser());
}

/**
Expand All @@ -724,7 +731,8 @@ public void createSequence(Sequence sq) {
public void createSynonym(Synonym sn) {
String ddl = CUBRIDSQLHelper.getInstance(null).getSynonymDDL(sn, config.isAddUserSchema());
sn.setDDL(ddl);
executeDDL(ddl + ";\n", DBObject.OBJ_TYPE_SYNONYM, createResultHandler(sn), sn.getOwner());
executeDDL(ddl + ";\n", DBObject.OBJ_TYPE_SYNONYM, createResultHandler(sn),
config.isAddUserSchema() ? sn.getSourceOwner() : config.getSourceConParams().getConUser());
}

/**
Expand All @@ -735,7 +743,8 @@ public void createSynonym(Synonym sn) {
public void createGrant(Grant gr) {
String ddl = CUBRIDSQLHelper.getInstance(null).getGrantDDL(gr, config.isAddUserSchema());
gr.setDDL(ddl);
executeDDL(ddl + ";\n", DBObject.OBJ_TYPE_GRANT, createResultHandler(gr),gr.getOwner());
executeDDL(ddl + ";\n", DBObject.OBJ_TYPE_GRANT, createResultHandler(gr),
config.isAddUserSchema() ? gr.getSourceOwner() : config.getSourceConParams().getConUser());
}

public void createSchema(Schema schema) {
Expand Down
Loading