JDBCInterpreter extends Interpreter { public String getPropertyKey(String cmd) { boolean firstLineIndex = cmd.startsWith("("); if (firstLineIndex) { int configStartIndex = cmd.indexOf("("); int configLastIndex = cmd.indexOf(")"); if (configStartIndex != -1 && configLastIndex != -1) { return cmd.substring(configStartIndex + 1, configLastIndex); } else { return null; } } else { return DEFAULT_KEY; } } JDBCInterpreter(Properties property); HashMap<String, Properties> getPropertiesMap(); @Override void open(); Connection getConnection(String propertyKey); Statement getStatement(String propertyKey, String paragraphId); @Override void close(); @Override InterpreterResult interpret(String cmd, InterpreterContext contextInterpreter); @Override void cancel(InterpreterContext context); String getPropertyKey(String cmd); @Override FormType getFormType(); @Override int getProgress(InterpreterContext context); @Override Scheduler getScheduler(); @Override List<InterpreterCompletion> completion(String buf, int cursor); int getMaxResult();  }
@Test public void testForParsePropertyKey() throws IOException { JDBCInterpreter t = new JDBCInterpreter(new Properties()); assertEquals(t.getPropertyKey("(fake) select max(cant) from test_table where id >= 2452640"), "fake"); assertEquals(t.getPropertyKey("() select max(cant) from test_table where id >= 2452640"), ""); assertEquals(t.getPropertyKey(")fake( select max(cant) from test_table where id >= 2452640"), "default"); assertEquals(t.getPropertyKey("(prefix1)\n select max(cant) from test_table where id >= 2452640"), "prefix1"); assertEquals(t.getPropertyKey("(prefix2) select max(cant) from test_table where id >= 2452640"), "prefix2"); assertEquals(t.getPropertyKey("select max(cant) from test_table where id >= 2452640"), "default"); }