Oracle Data Modeler CSV Transformation Script
Exports a subiew in a logical model to a CSV file.
var subView = “<subview_name>"; var file = “/tmp/"+subView+".csv”
// Get List of Subview Entities
entities = model.getSubViewByName(subView).getEntities();
// Store CSV output.
var output = "";
// Start traversing entity
processEntities(entities);
writeToFile(output, file);
/*
Process the selected entities
*/
function processEntities(entities)
{
for(var a=0; a < entities.length; a++)
{
processEntity(entities[a]);
}
}
/*
Process an entity
*/
function processEntity(entity)
{ // Get the entity's name.
name = entity.getName();
// Iterate through it's attributes
attributes = entity.getAttributes();
for(var b=0; b < attributes.length; b++)
{
processAttributes(entity, attributes[b]);
}
}
/*
Process an Attribute
*/
function processAttributes(entity, attribute)
{
// Name
var attrName = attribute.getName();
var entityName = entity.getName();
// Get Comments
var attrComments = attribute.getComment().replace(/(\r\n|\n|\r|,)/gm,"");
var entityComments = entity.getComment().replace(/(\r\n|\n|\r|,)/gm,"");
// Get Created Date
var entityDate = entity.getCreatedTime();
var attrDate = attribute.getCreatedTime();
// Get Internal Object ID
var entityID = entity.getObjectID();
var attrID = attribute.getObjectID();
// Get Last Changed By.
var entityModifiedBy = entity.getCreatedBy();
var attrModifiedBy = attribute.getCreatedBy();
// Get Extended Attribute Fields
var attrDataType = attribute.getDataType().toString().replace(/(,)/gm,".");
var attrFK = attribute.isFKAttribute()==true?"yes":"no";
var attPK = attribute.isPKElement()==true?"yes":"no";
output +=
subView + "," +
entityName + "," +
entityDate + "," +
entityID + "," +
entityComments + "," +
entityModifiedBy + "," +
attrName + "," +
attrDate + "," +
attrID + "," +
attrComments + "," +
attrDataType + "," +
attrFK + "," +
attPK + "," +
attrModifiedBy + "\n";
}
/*
Display a message
*/
function alert(message)
{
javax.swing.JOptionPane.showMessageDialog(null, message);
}
/*
Write String to File
*/
function writeToFile(output, file)
{
// Write to file.
try
{
var out = new java.io.PrintWriter(file);
out.println(output);
out.close();
}
catch(err)
{
alert(err);
}
alert(subView + " saved to file '" + file + "'");
}
Last modified on 2016-04-19