/**
* INTERNAL: Return the create table statement.
*/
public Writer buildCreationWriter(AbstractSession session, Writer writer) throws ValidationException {
try {
DatabasePlatform platform = session.getPlatform();
writer.write(getCreationHeader() + getFullName());
if (getArguments().size() > getFirstArgumentIndex() || platform.requiresProcedureBrackets()) {
writer.write(" (");
}
writer.write("\n");
for (int i = getFirstArgumentIndex(); i < getArguments().size(); i++) {
writer.write("\t");
FieldDefinition argument = (FieldDefinition)getArguments().elementAt(i);
Integer argumentType = (Integer)getArgumentTypes().elementAt(i);
if (argumentType == IN) {
printArgument(argument, writer, session);
} else if (argumentType == OUT) {
printOutputArgument(argument, writer, session);
} else if (argumentType == INOUT) {
printInOutputArgument(argument, writer, session);
}
if (i < (getArguments().size() - 1)) {
writer.write(",\n");
}
}
if (getArguments().size() > getFirstArgumentIndex() || platform.requiresProcedureBrackets()) {
writer.write(")");
}
printReturn(writer, session);
writer.write(platform.getProcedureAsString());
writer.write("\n");
if (platform.shouldPrintStoredProcedureVariablesAfterBeginString()) {
writer.write(platform.getProcedureBeginString());
writer.write("\n");
}
if (!getVariables().isEmpty()) {
writer.write("DECLARE\n");
}
for (Enumeration variablesEnum = getVariables().elements();
variablesEnum.hasMoreElements();) {
FieldDefinition field = (FieldDefinition)variablesEnum.nextElement();
writer.write("\t");
writer.write(field.getName());
writer.write(" ");
writer.write(field.getTypeName());
writer.write(platform.getBatchDelimiterString());
writer.write("\n");
}
if (!platform.shouldPrintStoredProcedureVariablesAfterBeginString()) {
writer.write(platform.getProcedureBeginString());
writer.write("\n");
}
for (Enumeration statementsEnum = getStatements().elements();
statementsEnum.hasMoreElements();) {
writer.write((String)statementsEnum.nextElement());
writer.write(platform.getBatchDelimiterString());
writer.write("\n");
}
writer.write(platform.getProcedureEndString());
} catch (IOException ioException) {
throw ValidationException.fileError(ioException);
}
return writer;
}