Skip to content
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 @@ -231,18 +231,27 @@ private void dotToFile(String dotExeFileName, String dotFileName, String outFile
// d:\graphviz-1.12\bin\dot.exe -Tgif c:\temp\ManualDraw.dot > c:\temp\ManualDraw.gif
// so we follow that model here and read stdout until EOF
//

final String exeCmd =
escape(dotExeFileName) +
" -T" + getFormatForFile(outFileName) + " " +
escape(dotFileName) +
" -o " +
escape(outFileName);

Process p = Runtime.getRuntime().exec(exeCmd);
//p.getErrorStream().

final String[] cmdAsArray = new String[] {
escape( dotExeFileName ),
"-T",
getFormatForFile( outFileName ),
escape( dotFileName ),
"-o",
escape( outFileName )
};

StringBuilder sb = new StringBuilder();
for (String s : cmdAsArray) {
sb.append( s ).append( " " );
}

final String cmdAsString = sb.toString();

Process p = Runtime.getRuntime().exec(cmdAsArray);

try {
log.debug( "Executing: " + exeCmd );
log.debug( "Executing: " + cmdAsString );
// Get the input stream and read from it
InputStream in = p.getErrorStream();
int c;
Expand All @@ -253,10 +262,10 @@ private void dotToFile(String dotExeFileName, String dotFileName, String outFile
int i = p.waitFor( );
if(i!=0) {
//TODO: dump system.err
log.error("Error " + i + " while executing: " + exeCmd);
log.error("Error " + i + " while executing: " + cmdAsString);
}
} catch(Exception ie){
log.error( "Error while executing: " + exeCmd, ie );
log.error( "Error while executing: " + cmdAsString, ie );
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,17 @@ public Iterator<Map<String, Object>> getSuggestedPrimaryKeyStrategyName(String c
table = caseForSearch( table );

log.debug("geSuggestedPrimaryKeyStrategyName(" + catalog + "." + schema + "." + table + ")");

sql = "SELECT a.TABLE_CATALOG, a.TABLE_SCHEMA, a.TABLE_NAME as table_name, c.DATA_TYPE as data_type, b.CONSTRAINT_TYPE, OBJECTPROPERTY(OBJECT_ID(a.TABLE_NAME),'TableHasIdentity') as hasIdentity " +
"FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE a " +
"INNER JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS b on a.CONSTRAINT_NAME = b.CONSTRAINT_NAME " +
"INNER JOIN INFORMATION_SCHEMA.COLUMNS c on a.TABLE_CATALOG = c.TABLE_CATALOG AND a.TABLE_SCHEMA = c.TABLE_SCHEMA AND a.TABLE_NAME = c.TABLE_NAME AND a.COLUMN_NAME = c.COLUMN_NAME " +
"WHERE a.TABLE_NAME='"+table+"' AND a.TABLE_SCHEMA='"+schema+"' AND a.TABLE_CATALOG='"+catalog+"' AND b.CONSTRAINT_TYPE = 'Primary key'";
"WHERE a.TABLE_NAME=? AND a.TABLE_SCHEMA=? AND a.TABLE_CATALOG=? AND b.CONSTRAINT_TYPE = 'Primary key'";

PreparedStatement statement = getConnection().prepareStatement( sql );
statement.setString(1, table);
statement.setString( 2, schema );
statement.setString( 3, catalog );

final String sc = schema;
final String cat = catalog;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@
import javax.xml.xpath.XPathFactory;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.logging.Logger;

public abstract class AbstractXMLPrettyPrinterStrategy implements XMLPrettyPrinterStrategy {

protected Document newDocument(String xml, String encoding) throws SAXException, IOException, ParserConfigurationException {
final DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
final Document document = dbf
private static final Logger LOGGER = Logger.getLogger( AbstractXMLPrettyPrinterStrategy.class.getName() );
private static final DocumentBuilderFactory DOCUMENT_BUILDER_FACTORY = createDocumentBuilderFactory();

public Document newDocument(String xml, String encoding) throws SAXException, IOException, ParserConfigurationException {
final Document document = DOCUMENT_BUILDER_FACTORY
.newDocumentBuilder()
.parse(new InputSource(new ByteArrayInputStream(xml.getBytes(encoding))));
document.normalize();
Expand All @@ -39,4 +41,23 @@ protected void removeWhitespace(final Document document) throws XPathExpressionE
node.getParentNode().removeChild(node);
}
}

private static DocumentBuilderFactory createDocumentBuilderFactory() {
DocumentBuilderFactory result = null;
try {
result = DocumentBuilderFactory.newInstance(
"com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl",
null);
result.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
}
catch (ParserConfigurationException e) {
LOGGER.severe(
"A ParserConfigurationException happened while setting the " +
"'http://apache.org/xml/features/nonvalidating/load-external-dtd' feature" +
"to false." );
throw new RuntimeException(e);
}
return result;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,15 @@
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import java.io.StringWriter;
import java.util.logging.Logger;

public class TrAXPrettyPrinterStrategy extends AbstractXMLPrettyPrinterStrategy {

private static final Logger LOGGER = Logger.getLogger( TrAXPrettyPrinterStrategy.class.getName() );
private static final TransformerFactory TRANSFORMER_FACTORY = TransformerFactory.newInstance(
"com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl",
null);

private int indent = 4;
private boolean omitXmlDeclaration;

Expand All @@ -28,16 +35,18 @@ public String prettyPrint(String xml) throws Exception {
}

protected Transformer newTransformer(final Document document) throws TransformerConfigurationException {
final TransformerFactory transformerFactory = newTransformerFactory();

final Transformer transformer = transformerFactory.newTransformer();
final Transformer transformer = TRANSFORMER_FACTORY.newTransformer();
transformer.setOutputProperty(OutputKeys.METHOD, "xml");
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, isOmitXmlDeclaration() ? "yes" : "no");
try {
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", String.valueOf(getIndent()));
} catch (IllegalArgumentException ignored) {
}
catch (IllegalArgumentException e) {
LOGGER.severe( "An IllegalArgumentException happened while adding the 'indent' property." );
throw new RuntimeException(e);
}

final DocumentType doctype = document.getDoctype();
Expand All @@ -49,16 +58,6 @@ protected Transformer newTransformer(final Document document) throws Transformer
return transformer;
}

protected TransformerFactory newTransformerFactory() {
final TransformerFactory transformerFactory = TransformerFactory.newInstance();
try {
transformerFactory.setAttribute("indent-number", getIndent());
} catch (IllegalArgumentException ignored) {
}

return transformerFactory;
}

public int getIndent() {
return indent;
}
Expand All @@ -74,4 +73,5 @@ public boolean isOmitXmlDeclaration() {
public void setOmitXmlDeclaration(boolean omitXmlDeclaration) {
this.omitXmlDeclaration = omitXmlDeclaration;
}

}