package jdbj;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;

public final class JDBJ {

    /**
     * @param resource
     * @return a phase 2 builder
     */
    public static ReturnsQuery query(String resource) {
        final URL url = JDBJ.class.getClassLoader().getResource(resource);
        if (url == null) {
            throw new IllegalArgumentException("resource not found: " + resource);
        }
        return queryString(readQueryResource(url));
    }

    /**
     * @param queryString
     * @return a phase 2 builder
     */
    public static ReturnsQuery queryString(String queryString) {
        final NamedParameterStatement statement = NamedParameterStatement.make(queryString);
        return new ReturnsQuery(statement);
    }

    /**
     * @param queryString
     * @return a phase 2 builder
     */
    public static InsertQuery insertQueryString(String queryString) {
        final NamedParameterStatement statement = NamedParameterStatement.make(queryString);
        return new InsertQuery(statement);
    }

    JDBJ() {

    }

    private static String readQueryResource(URL url) {
        final String queryString1;
        try (BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream()))) {

            final StringBuilder queryString = new StringBuilder();
            String line;
            while ((line = br.readLine()) != null) {
                queryString.append(line).append('\n');
            }
            queryString1 = queryString.toString();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        return queryString1;
    }
}


@@ -1196,24 +1196,31 @@
 final String
+Builder
  queryString
@@ -1215,25 +1215,46 @@
  queryString
-1
+ = new StringBuilder()
 ;%0A        tr
@@ -1344,75 +1344,9 @@
  %7B%0A%0A
-            final StringBuilder queryString = new StringBuilder();
 %0A
+
     
@@ -1492,59 +1492,8 @@
   %7D%0A
-            queryString1 = queryString.toString();%0A
     
@@ -1605,9 +1605,19 @@
 ring
-1
+.toString()
 ;%0A  

simpler readQueryResource