Ignoring views from db schema?


EJB design: Ignoring views from db schema?

  1. Ignoring views from db schema? (1 messages)

    Hi all,

    I am having a situation where I am reading a file called db.sql containing tables,unique,sequence,index,etc.

    Basically my application can read and write all this.

    Whenever db.sql is having views or stored procedures my aprser is giving error.

    I made changes in parser to read views,

    but of no use since application is not having any information about redng writing views,procdures further.

    Now the only solution i am having to ignore them writing(appending) " -- " in front of views or procedures. so that my parser(while reading) and complete application while writing(generating database from db.sql schema) can simply ignore it.

    Please give me some ideas to make this happen.

    Its like:

    "its reading from stream of characters from the file, and then sending to the parser."

    In between i need a mechanism from which i can do my ignorence portion please give me hints,solutions whatever is possible in this stage.

    My work is pending for a long time..


    Vijendra Singh
  2. try {
                // open the file for reading
                FileReader inputstream = new FileReader (sqlFileName);
                BufferedReader rdr = new BufferedReader( inputstream );

                // the StringBuilder which stores the processed lines
                StringBuffer dataLines = new StringBuffer();

                // read the file line by line
                String dataLine;
    /*We have four possible states to check for:
    (1) haven't started a view/proc yet,
    (2) found the start of a view/proc,
    (3) still in a view/proc but haven't found the end,
    (4) found the end of the view/proc.
    boolean startofToken=false;

                while( ( dataLine = rdr.readLine() ) != null ) {
    // split the input data into words upto first 3 words only
                   String[] tokens = (dataLine.trim()).split( " ", 3 );

                   if (!startofToken) {
                      //line contains view or proc.
    // if the line starts with 'create' and a 'view' follows it,
                    // then add a "--" to the beginning of the line
                   if(tokens[ 0 ].equalsIgnoreCase( "create" ) &&
                        tokens[ 1 ].equalsIgnoreCase( "view" ) ||
                        tokens[ 0 ].equalsIgnoreCase( "create" ) &&
                        tokens[ 1 ].equalsIgnoreCase( "procedure" )) {
                         startofToken = true;
                     else {//#1
    dataLines.append( dataLine ).append( '\n' );
    if (startofToken) { //#4
    if (dataLine.endsWith(";")) {
    dataLines.append( "-- " );
    dataLines.append( dataLine ).append( '\n' );
    startofToken = false;
    else {//#3
    dataLines.append( "-- " );
    dataLines.append( dataLine ).append( '\n' );

                // open the file for writing new data to it
                FileWriter outputstream=new FileWriter( sqlFileName );
                BufferedWriter writer = new BufferedWriter(outputstream);

                writer.write( dataLines.toString(), 0, dataLines.length() );

            _stream = new FileReader (sqlFileName);

            } catch( IOException e ) {