private void writeGetConnection ( Definition def , Writer out , int indent ) throws IOException { String connInterface = def . getMcfDefs ( ) . get ( 0 ) . getConnInterfaceClass ( ) ; String cfInterface = def . getMcfDefs ( ) . get ( 0 ) . getCfInterfaceClass ( ) ; writeWithIndent ( out , indent , "/**\n" ) ; writeWithIndent ( out , indent , " * GetConnection\n" ) ; writeWithIndent ( out , indent , " * @return " + connInterface ) ; writeEol ( out ) ; writeWithIndent ( out , indent , " */\n" ) ; writeWithIndent ( out , indent , "private " + connInterface + " getConnection() throws Exception" ) ; writeLeftCurlyBracket ( out , indent ) ; writeWithIndent ( out , indent + 1 , "InitialContext context = new InitialContext();\n" ) ; writeIndent ( out , indent + 1 ) ; out . write ( cfInterface + " factory = (" + cfInterface + ")context.lookup(JNDI_NAME);\n" ) ; writeIndent ( out , indent + 1 ) ; out . write ( connInterface + " conn = factory.getConnection();\n" ) ; writeWithIndent ( out , indent + 1 , "if (conn == null)" ) ; writeLeftCurlyBracket ( out , indent + 1 ) ; writeIndent ( out , indent + 2 ) ; out . write ( "throw new RuntimeException(\"No connection\");" ) ; writeRightCurlyBracket ( out , indent + 1 ) ; writeWithIndent ( out , indent + 1 , "return conn;" ) ; writeRightCurlyBracket ( out , indent ) ; }
Output getConnection method