Commits

tbrugz  committed aae75fc

servlet: added 'cache' of DumpSyntaxes

  • Participants
  • Parent commits 0f77e45

Comments (0)

Files changed (1)

File src/tbrugz/queryon/QueryOn.java

 import java.sql.SQLException;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 import java.util.Properties;
 
 import javax.naming.NamingException;
 		String outputTypeStr = DEFAULT_OUTPUT_SYNTAX;
 		DumpSyntax outputSyntax = null;
 		
-		public RequestSpec(HttpServletRequest req) throws ServletException {
+		public RequestSpec(HttpServletRequest req, Properties prop) throws ServletException {
 			String varUrl = req.getPathInfo();
 			int lastDotIndex = varUrl.lastIndexOf('.');
 			if(lastDotIndex>-1) {
 				params.add(URIpartz.get(i));
 			}
 			
-			outputSyntax = getDumpSyntax(outputTypeStr);
+			outputSyntax = getDumpSyntax(outputTypeStr, prop);
 			if(outputSyntax == null) {
 				throw new ServletException("Unknown output syntax: "+outputTypeStr);
 			}
 			throws ServletException, IOException {
 		log.info(">> pathInfo: "+req.getPathInfo());
 		
-		RequestSpec reqspec = new RequestSpec(req);
+		RequestSpec reqspec = new RequestSpec(req, prop);
 		
 		String[] objectParts = reqspec.object.split("\\.");
 		
 		int count = 0;
 		DumpSyntax ds = reqspec.outputSyntax;
 		
-		ds.procProperties(prop);
 		ds.initDump(table.getName(), 
 				table.getPKConstraint()!=null?table.getPKConstraint().uniqueColumns:null,
 				rs.getMetaData());
 		conn.close();
 	}
 	
-	static DumpSyntax getDumpSyntax(String format) {
+	static Map<String, DumpSyntax> syntaxes = new HashMap<String, DumpSyntax>();
+	
+	static DumpSyntax getDumpSyntax(String format, Properties prop) {
+		DumpSyntax dsx = syntaxes.get(format);
+		if(dsx!=null) { return dsx; }
+		
 		for(Class<? extends DumpSyntax> dsc: DumpSyntax.getSyntaxes()) {
 			DumpSyntax ds = (DumpSyntax) Utils.getClassInstance(dsc);
 			if(ds!=null && ds.getSyntaxId().equals(format)) {
+				ds.procProperties(prop);
+				syntaxes.put(format, ds);
 				return ds;
 			}
 		}