db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Flavio Palumbo" <f.palu...@silmasoftware.com>
Subject R: calling ASTParser repeatedly rises an exception
Date Tue, 30 Mar 2010 12:09:32 GMT
Hi all,
i made a little bit more investigation on original ASTParser code and i
discover something really strange :
- calling repeatedly the original ASTParser code works fine
- if i wrap the body of the parsing with try/catch block, original ASTParser
code, i get the exception menthioned
In my mind i think that the point is understanding in which cases this
exception is rised.
I provide below the classes code
Any hint would be appreciated
Flavio

----------------------------------------------------------------------------
--------------------------
public class MyRun {
    public static void main(String[] args) {
        String[] a = {"insert into flavio.anadiv (?,?,?,?,?,?,?,?,?,?,?,?)",
            "insert into eurofile.tdepro (dpcdst, dpcdme, dpcdpr) values(?,
?, ?)"};
        for (int i = 0; i < a.length; i++) {
            ASTParser astParser = new ASTParser();
            String[] aa = new String[1];
            aa[0] = a[i];
            try {
                astParser.execute(aa);
            } catch (Throwable t) {
                System.out.println("MyRun - errore - " + t);
            }
        }
        System.exit(0);
    }
}
----------------------------------------------------------------------------
--------------------------------
import java.io.*;
import java.sql.*;
import org.apache.derby.iapi.services.context.ContextManager;
import org.apache.derby.iapi.services.sanity.SanityManager;
import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;
import org.apache.derby.impl.jdbc.EmbedConnection;
import org.apache.derby.impl.sql.compile.QueryTreeNode;

public class ASTParser {
    public static final String DRIVER_NAME =
"org.apache.derby.jdbc.EmbeddedDriver";
    public static final String CONNECTION_URL =
"jdbc:derby:memory:dummy;create=true";
    public static final String DERBY_DEBUG_SETTING = "derby.debug.true";
    public static final String STOP_AFTER_PARSING = "StopAfterParsing";
    public static final String STOPPED_AFTER_PARSING = "42Z55";
    public static final String SHUTDOWN_URL = "jdbc:derby:;shutdown=true";
    public static final String LANG_CONNECTION =
"LanguageConnectionContext";
    private PrintStream _printStream = System.out;

    public static void main(String[] args)
            throws Exception {
        ASTParser astParser = new ASTParser();
        String[] a = {"insert into eurofile.tdepro (dpcdst, dpcdme, dpcdpr)
values(?, ?, ?)"};
        astParser.execute(a);
    }

    public void execute(String[] args)
            throws Exception {
        try {                  // <------- this is the try/catch block that
seems to break the program
            System.setProperty(DERBY_DEBUG_SETTING, STOP_AFTER_PARSING);
            Class.forName(DRIVER_NAME);

            String text = args[ 0];
            Connection conn = DriverManager.getConnection(CONNECTION_URL);
            PreparedStatement ps = null;

            println("Parsing:\n" + text);

            try {
                ps = conn.prepareStatement(text);
            } catch (SQLException se) {
                String sqlState = se.getSQLState();

                if (!STOPPED_AFTER_PARSING.equals(sqlState)) {
                    throw se;
                }
            }

            ContextManager contextManager = ((EmbedConnection)
conn).getContextManager();
            LanguageConnectionContext lcc = (LanguageConnectionContext)
contextManager.getContext(LANG_CONNECTION);
            QueryTreeNode queryTree = (QueryTreeNode)
lcc.getLastQueryTree();

            SanityManager.SET_DEBUG_STREAM(new PrintWriter(_printStream));
            queryTree.treePrint();
        } catch (Throwable t) {
            System.out.println("ASTParser - errore " + t);
        }
        boolean gotSQLExc = false;
        try {
            DriverManager.getConnection(SHUTDOWN_URL);
        } catch (SQLException se) {
            if (se.getSQLState().equals("XJ015")) {
                gotSQLExc = true;
            }
        }
        if (!gotSQLExc) {
            System.out.println("Database did not shut down normally");
        } else {
            System.out.println("Database shut down normally");
        }
    }

    public void println(String text) {
        _printStream.println(text);
    }
}





> -----Messaggio originale-----
> Da: Flavio Palumbo [mailto:f.palumbo@silmasoftware.com]
> Inviato: lunedì 29 marzo 2010 16.27
> A: derby-user@db.apache.org
> Oggetto: calling ASTParser repeatedly rises an exception
>
>
> Hi all,
> i'trying plug into an application some code derived from ASTParser.
>
> This code is inserted in a single class that does the parsing
> (say class A).
>
> The parsing can be called many time from a main class that
> everytime creates
> a new class A.
>
> The strange behavior i found is that, the first time i create the class A,
> the parsing is done with no problems, while from the second time i get a
> "java.sql.SQLException: org.apache.derby.jdbc.EmbeddedDriver is not
> registered with the JDBC driver manager" everytime.
>
> This happens when the class executes "Connection conn =
> DriverManager.getConnection(CONNECTION_URL);"
>
> I'm sure that everytime the class A is called i shut down the connection
> properly.
>
> Can somebody help me to figure out why this happens ?
>
> thanks a lot
> Flavio
>
>
> -----------------------------------------------------------
> Il presente messaggio non costituisce un impegno contrattuale tra
> SILMA S.r.l. ed il destinatario.
> Le opinioni ivi espresse sono quelle dell'autore.
> SILMA S.r.l. non assume alcuna responsabilita riguardo al
> contenuto del presente messaggio.
> Il messaggio è destinato esclusivamente al destinatario.
> Il contenuto e gli allegati sono da considerarsi di natura confidenziale
>
> Nel caso abbiate ricevuto il presente messaggio per errore siete
> pregati di comunicarlo
> alla casella segreteria@silmasoftware.com.
>


-----------------------------------------------------------
Il presente messaggio non costituisce un impegno contrattuale tra SILMA S.r.l. ed il destinatario.
Le opinioni ivi espresse sono quelle dell'autore.
SILMA S.r.l. non assume alcuna responsabilita riguardo al contenuto del presente messaggio.
Il messaggio è destinato esclusivamente al destinatario.
Il contenuto e gli allegati sono da considerarsi di natura confidenziale

Nel caso abbiate ricevuto il presente messaggio per errore siete pregati di comunicarlo
alla casella segreteria@silmasoftware.com.


Mime
View raw message