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-4682] Oracle PL/SQL Procedure - Migration Report #251

Open
wants to merge 6 commits into
base: release/oracle_procedure_migration
Choose a base branch
from
Open
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 @@ -610,6 +610,20 @@ public void addTargetViewSchema(View view) {
}
}

public void addTargetPlcsqlProcedureSchema(PlcsqlProcedure proc) {
if (srcCatalog != null) {
throw new RuntimeException("Source database was specified.");
}
targetPlcsqlProcedures.add(proc);
}

public void addTargetPlcsqlFunctionSchema(PlcsqlFunction func) {
if (srcCatalog != null) {
throw new RuntimeException("Source database was specified.");
}
targetPlcsqlFunctions.add(func);
}

/**
* Clean up the settings, remove the configurations which are not in source schema.
*
Expand Down Expand Up @@ -3479,6 +3493,60 @@ public View getTargetViewSchema(String owner, String viewName) {
return null;
}

public List<PlcsqlProcedure> getTargetPlcsqlProcedureSchema() {
return new ArrayList<>(this.targetPlcsqlProcedures);
}

public PlcsqlProcedure getTargetPlcsqlProcedureSchema(String name) {
for (PlcsqlProcedure proc : this.targetPlcsqlProcedures) {
if (proc.getName().equalsIgnoreCase(name)) {
return proc;
}
}
return null;
}

public PlcsqlProcedure getTargetPlcsqlProcedureSchema(String owner, String name) {
if (owner == null) {
return getTargetPlcsqlProcedureSchema(name);
}

for (PlcsqlProcedure proc : this.targetPlcsqlProcedures) {
if (proc.getTargetName().equalsIgnoreCase(name)
&& proc.getTargetOwner().equalsIgnoreCase(owner)) {
return proc;
}
}
return null;
}

public List<PlcsqlFunction> getTargetPlcsqlFunctionSchema() {
return new ArrayList<>(this.targetPlcsqlFunctions);
}

public PlcsqlFunction getTargetPlcsqlFunctionSchema(String name) {
for (PlcsqlFunction func : this.targetPlcsqlFunctions) {
if (func.getName().equalsIgnoreCase(name)) {
return func;
}
}
return null;
}

public PlcsqlFunction getTargetPlcsqlFunctionSchema(String owner, String name) {
if (owner == null) {
return getTargetPlcsqlFunctionSchema(name);
}

for (PlcsqlFunction func : this.targetPlcsqlFunctions) {
if (func.getTargetName().equalsIgnoreCase(name)
&& func.getTargetOwner().equalsIgnoreCase(owner)) {
return func;
}
}
return null;
}

public boolean nullCheckEquals(String owner, Schema targetSchema) {
if (owner == null || targetSchema == null) {
return false;
Expand Down Expand Up @@ -4218,8 +4286,16 @@ public void setExp2FileOuput(String prefix, String odir, String charset) {
PathUtils.mergePath(odir, prefix),
schemaName + "_" + table.getName()));
}
addTargetAllPlcsqlProcedureFileName(
schemaName,
PathUtils.mergePath(
PathUtils.mergePath(odir, prefix), schemaName + "_procedure"));
addTargetAllPlcsqlFunctionFileName(
schemaName,
PathUtils.mergePath(
PathUtils.mergePath(odir, prefix), schemaName + "_function"));
setTargetCharSet(charset);
}
setTargetCharSet(charset);
}

public void setExportNoSupportObjects(boolean value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,28 @@ public String toString() {
sb.append("index[").append(dbObject.getName()).append("]");
} else if (dbObject instanceof Procedure) {
sb.append("procedure[").append(dbObject.getName()).append("]");
Procedure proc = (Procedure) dbObject;
if (proc.isAuthidChanged()) {
StringBuffer authidWarnig = new StringBuffer();
authidWarnig
.append(System.lineSeparator())
.append("[PROC_WARNING] procedure: ")
.append(proc.getName())
.append(" Change rights (CALLER RIGHTS -> OWNER RIGHTS)");
sb.append(authidWarnig);
}
} else if (dbObject instanceof Function) {
sb.append("function[").append(dbObject.getName()).append("]");
Function func = (Function) dbObject;
if (func.isAuthidChanged()) {
StringBuffer authidWarnig = new StringBuffer();
authidWarnig
.append(System.lineSeparator())
.append("[FUNC_WARNING] function: ")
.append(func.getName())
.append(" Change rights (CALLER RIGHTS -> OWNER RIGHTS)");
sb.append(authidWarnig);
}
} else if (dbObject instanceof Trigger) {
sb.append("trigger[").append(dbObject.getName()).append("]");
} else if (dbObject instanceof View) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
import com.cubrid.cubridmigration.core.common.PathUtils;
import com.cubrid.cubridmigration.core.common.log.LogUtil;
import com.cubrid.cubridmigration.core.dbobject.DBObject;
import com.cubrid.cubridmigration.core.dbobject.PlcsqlFunction;
import com.cubrid.cubridmigration.core.dbobject.PlcsqlProcedure;
import com.cubrid.cubridmigration.core.dbobject.View;
import com.cubrid.cubridmigration.core.engine.config.MigrationConfiguration;
import com.cubrid.cubridmigration.core.engine.event.CreateObjectEvent;
Expand Down Expand Up @@ -182,18 +184,12 @@ public void addEvent(MigrationEvent event) {
if (ev.isSuccess()) {
DBObjMigrationResult dbor = report.getDBObjResult(ev.getDbObject());
dbor.setSucceed(true);
dbor.setDdl(ev.getDbObject().getDDL());
if (ev.getDbObject().getObjType() == DBObject.OBJ_TYPE_VIEW) {
String viewAlterDDL = ((View) ev.getDbObject()).getAlterDDL();
if (!viewAlterDDL.equals(CUBRIDSQLHelper.SQL_NULL)) {
dbor.setDdl(dbor.getDdl() + "\n" + viewAlterDDL);
}
}
dbor.setDdl(setDBObjectResultDDL(ev));
} else {
DBObjMigrationResult dbor = report.getDBObjResult(ev.getDbObject());
dbor.setSucceed(false);
dbor.setDdl(setDBObjectResultDDL(ev));
dbor.setError(ev.getError().getMessage());
dbor.setDdl(ev.getDbObject().getDDL());
}
} else if (event instanceof StartExpTableEvent) {
StartExpTableEvent ev = (StartExpTableEvent) event;
Expand Down Expand Up @@ -239,6 +235,25 @@ public void addEvent(MigrationEvent event) {
}
}

private String setDBObjectResultDDL(CreateObjectEvent ev) {
String endLine = System.lineSeparator();
CUBRIDSQLHelper sqlHelper = CUBRIDSQLHelper.getInstance(null);

DBObject dbObject = ev.getDbObject();
String objectType = dbObject.getObjType();

switch (objectType) {
case DBObject.OBJ_TYPE_PLCSQL_PROCEDURE:
return buildProcedureDDL((PlcsqlProcedure) dbObject, sqlHelper, endLine);
case DBObject.OBJ_TYPE_PLCSQL_FUNCTION:
return buildFunctionDDL((PlcsqlFunction) dbObject, sqlHelper, endLine);
case DBObject.OBJ_TYPE_VIEW:
return buildViewDDL((View) dbObject, endLine);
default:
return dbObject.getDDL();
}
}

/** Write renamed objects to a file */
public void writeRenameObjectFile() {
List<ObjNameMigrationResult> renameObjectList = report.getObjNameResult();
Expand Down Expand Up @@ -382,4 +397,31 @@ public void loadMigrationHistory() {
throw new RuntimeException(e);
}
}

private String buildProcedureDDL(
PlcsqlProcedure procedure, CUBRIDSQLHelper sqlHelper, String endLine) {
return sqlHelper.getPlcsqlProcedureDDL(procedure, config.isAddUserSchema())
+ System.lineSeparator()
+ System.lineSeparator();
}

private String buildFunctionDDL(
PlcsqlFunction function, CUBRIDSQLHelper sqlHelper, String endLine) {
return sqlHelper.getPlcsqlFunctionDDL(function, config.isAddUserSchema())
+ System.lineSeparator()
+ System.lineSeparator();
}

private String buildViewDDL(View view, String endLine) {
String viewDDL = view.getDDL();
String viewAlterDDL = view.getAlterDDL();
if (!CUBRIDSQLHelper.SQL_NULL.equals(viewAlterDDL)) {
return joinDDLs(viewDDL, viewAlterDDL, endLine);
}
return viewDDL;
}

private String joinDDLs(String headerDDL, String bodyDDL, String endLine) {
return headerDDL + endLine + endLine + bodyDDL + endLine + endLine;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ public class MigrationReport implements Serializable {
DBObject.OBJ_TYPE_SEQUENCE,
DBObject.OBJ_TYPE_SYNONYM,
DBObject.OBJ_TYPE_TRIGGER,
DBObject.OBJ_TYPE_FUNCTION,
DBObject.OBJ_TYPE_PROCEDURE,
DBObject.OBJ_TYPE_PLCSQL_FUNCTION,
DBObject.OBJ_TYPE_PLCSQL_PROCEDURE,
DBObject.OBJ_TYPE_GRANT,
DBObject.OBJ_TYPE_RECORD
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,24 @@ private void writeFile(String schemaName) {
sb.append(lineSeparator);
}

// plcsql procedure header
String procedureHeaderFileRepository =
config.getTargetAllPlcsqlProcedureHeaderFileName(schemaName);
if (checkFileRepository(procedureHeaderFileRepository)) {
isCreateSchemaListFile = true;
sb.append(getFileName(procedureHeaderFileRepository));
sb.append(lineSeparator);
}

// plcsql function header
String functionHeaderFileRepository =
config.getTargetAllPlcsqlFunctionHeaderFileName(schemaName);
if (checkFileRepository(functionHeaderFileRepository)) {
isCreateSchemaListFile = true;
sb.append(getFileName(functionHeaderFileRepository));
sb.append(lineSeparator);
}

// pk
String pkFileRepository = config.getTargetPkFileName(schemaName);
if (checkFileRepository(pkFileRepository)) {
Expand Down Expand Up @@ -159,6 +177,22 @@ private void writeFile(String schemaName) {
sb.append(lineSeparator);
}

// plcsql procedure ddl
String procedureFileRepository = config.getTargetAllPlcsqlProcedureFileName(schemaName);
if (checkFileRepository(procedureFileRepository)) {
isCreateSchemaListFile = true;
sb.append(getFileName(procedureFileRepository));
sb.append(lineSeparator);
}

// plcsql function ddl
String functionFileRepository = config.getTargetAllPlcsqlFunctionFileName(schemaName);
if (checkFileRepository(functionFileRepository)) {
isCreateSchemaListFile = true;
sb.append(getFileName(functionFileRepository));
sb.append(lineSeparator);
}

if (isCreateSchemaListFile) {
os = new BufferedOutputStream(new FileOutputStream(schemaFileListFile, true));
os.write(sb.toString().getBytes());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
import com.cubrid.cubridmigration.core.dbobject.PK;
import com.cubrid.cubridmigration.core.dbobject.PartitionInfo;
import com.cubrid.cubridmigration.core.dbobject.PartitionTable;
import com.cubrid.cubridmigration.core.dbobject.PlcsqlFunction;
import com.cubrid.cubridmigration.core.dbobject.PlcsqlProcedure;
import com.cubrid.cubridmigration.core.dbobject.Schema;
import com.cubrid.cubridmigration.core.dbobject.Sequence;
import com.cubrid.cubridmigration.core.dbobject.Synonym;
Expand Down Expand Up @@ -450,6 +452,36 @@ private void parseTargetGrant(Attributes attributes) {
config.addTargetGrantSchema(grn);
}

/** @param attributes of node */
private void parseTargetPlcsqlProcedure(Attributes attributes) {
PlcsqlProcedure proc = new PlcsqlProcedure();
proc.setOwner(attributes.getValue(TemplateTags.ATTR_OWNER));
proc.setTargetOwner(attributes.getValue(TemplateTags.ATTR_TARGET_OWNER));
proc.setName(attributes.getValue(TemplateTags.ATTR_NAME));
proc.setTargetName(attributes.getValue(TemplateTags.ATTR_TARGET_NAME));
proc.setAuthid(attributes.getValue(TemplateTags.ATTR_AUTH_ID));
proc.setSourceDDL(attributes.getValue(TemplateTags.ATTR_SOURCE_DDL));
proc.setHeaderDDL(attributes.getValue(TemplateTags.ATTR_HEADER_DDL));
proc.setBodyDDL(attributes.getValue(TemplateTags.ATTR_BODY_DDL));
proc.setProcedureDDL(attributes.getValue(TemplateTags.ATTR_PROCEDURE_DDL));
config.addTargetPlcsqlProcedureSchema(proc);
}

/** @param attributes of node */
private void parseTargetPlcsqlFunction(Attributes attributes) {
PlcsqlFunction func = new PlcsqlFunction();
func.setOwner(attributes.getValue(TemplateTags.ATTR_OWNER));
func.setTargetOwner(attributes.getValue(TemplateTags.ATTR_TARGET_OWNER));
func.setName(attributes.getValue(TemplateTags.ATTR_NAME));
func.setTargetName(attributes.getValue(TemplateTags.ATTR_TARGET_NAME));
func.setAuthid(attributes.getValue(TemplateTags.ATTR_AUTH_ID));
func.setSourceDDL(attributes.getValue(TemplateTags.ATTR_SOURCE_DDL));
func.setHeaderDDL(attributes.getValue(TemplateTags.ATTR_HEADER_DDL));
func.setBodyDDL(attributes.getValue(TemplateTags.ATTR_BODY_DDL));
func.setFunctionDDL(attributes.getValue(TemplateTags.ATTR_FUNCTION_DDL));
config.addTargetPlcsqlFunctionSchema(func);
}

/** @param attributes of node */
private void parseTargetTable(Attributes attributes) {
targetTable = new Table();
Expand Down Expand Up @@ -737,8 +769,32 @@ private void startSourceElement(String qName, Attributes attributes) throws SAXE
config.addExpTriggerCfg(attributes.getValue(TemplateTags.ATTR_NAME));
} else if (TemplateTags.TAG_FUNCTION.equals(qName)) {
config.addExpFunctionCfg(attributes.getValue(TemplateTags.ATTR_NAME));
} else if (TemplateTags.TAG_PLCSQL_FUNCTION.equals(qName)) {
config.addExpPlcsqlFunctionCfg(
attributes.getValue(TemplateTags.ATTR_OWNER),
attributes.getValue(TemplateTags.ATTR_TARGET_OWNER),
attributes.getValue(TemplateTags.ATTR_NAME),
attributes.getValue(TemplateTags.ATTR_TARGET),
attributes.getValue(TemplateTags.ATTR_AUTH_ID),
getBoolean(attributes.getValue(TemplateTags.ATTR_AUTH_ID_CHANGED), false),
attributes.getValue(TemplateTags.ATTR_SOURCE_DDL),
attributes.getValue(TemplateTags.ATTR_HEADER_DDL),
attributes.getValue(TemplateTags.ATTR_BODY_DDL),
attributes.getValue(TemplateTags.ATTR_FUNCTION_DDL));
} else if (TemplateTags.TAG_PROCEDURE.equals(qName)) {
config.addExpProcedureCfg(attributes.getValue(TemplateTags.ATTR_NAME));
} else if (TemplateTags.TAG_PLCSQL_PROCEDURE.equals(qName)) {
config.addExpPlcsqlProcedureCfg(
attributes.getValue(TemplateTags.ATTR_OWNER),
attributes.getValue(TemplateTags.ATTR_TARGET_OWNER),
attributes.getValue(TemplateTags.ATTR_NAME),
attributes.getValue(TemplateTags.ATTR_TARGET),
attributes.getValue(TemplateTags.ATTR_AUTH_ID),
getBoolean(attributes.getValue(TemplateTags.ATTR_AUTH_ID_CHANGED), false),
attributes.getValue(TemplateTags.ATTR_SOURCE_DDL),
attributes.getValue(TemplateTags.ATTR_HEADER_DDL),
attributes.getValue(TemplateTags.ATTR_BODY_DDL),
attributes.getValue(TemplateTags.ATTR_PROCEDURE_DDL));
} else if (TemplateTags.TAG_SQL.equals(qName)) {
config.setSourceFileEncoding(attributes.getValue(TemplateTags.ATTR_CHARSET));
} else if (TemplateTags.TAG_SQL_FILE.equals(qName)) {
Expand Down Expand Up @@ -828,6 +884,10 @@ private void startTargetElement(String qName, Attributes attr) throws SAXExcepti
parseTargetSynonym(attr);
} else if (TemplateTags.TAG_GRANT.equals(qName)) {
parseTargetGrant(attr);
} else if (TemplateTags.TAG_PLCSQL_PROCEDURE.equals(qName)) {
parseTargetPlcsqlProcedure(attr);
} else if (TemplateTags.TAG_PLCSQL_FUNCTION.equals(qName)) {
parseTargetPlcsqlFunction(attr);
} else if (TemplateTags.TAG_VIEW.equals(qName)) {
parseTargetView(attr);
} else if (TemplateTags.TAG_VIEWCOLUMN.equals(qName)) {
Expand Down
Loading
Loading