TOraScript with create JAVA in direct mode

Discussion of open issues, suggestions and bugs regarding ODAC (Oracle Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
hannes_a
Posts: 77
Joined: Sun 22 Jan 2006 20:44
Location: munic

TOraScript with create JAVA in direct mode

Post by hannes_a » Mon 27 Oct 2008 10:06

I use ODAC 6.70 and get an error during script.execute command
ORA-29536: badly formed source: Encountered "" at line 1, column 29.
Was expecting one of:
"." ...
";" ...
because the TOraScript does not recognized my command as big script, it execute it line by line.....
there is no difference between direct mode and client mode, both raise this error
how to solve it ?

this is the script:

Code: Select all

CREATE OR REPLACE AND RESOLVE JAVA SOURCE NAMED "JavaZipCode" as import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import java.util.zip.ZipInputStream;
import java.util.Vector;
import java.io.OutputStream;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.DriverManager;
import java.sql.ResultSet;
import oracle.jdbc.OracleDriver;
import oracle.jdbc.OracleResultSet;
import oracle.sql.BLOB;
import oracle.sql.STRUCT;
import oracle.sql.ARRAY;
import oracle.sql.ArrayDescriptor;
import oracle.sql.StructDescriptor;

public class zip {
    static Connection con = null;
    static  BLOB zipLob = null;    
    static  InputStream lobIs    = null;
    static  ZipInputStream zipIs = null;
    static  ZipEntry zipFile = null;
    static boolean bFileIsOpen = false;

    static {
      try {
        con = DriverManager.getConnection("jdbc:default:connection");
      } catch (Exception e) {
        e.printStackTrace(System.out);
      }
    }

    public static void open(BLOB inLob) throws Exception {
      if (bFileIsOpen) {
        close();
        throw new Exception ("ZIP File already open - call close() first");
      }
      zipLob = inLob;
      lobIs = inLob.getBinaryStream();
      zipIs = new ZipInputStream(lobIs);
      bFileIsOpen = true;
    }
  
    public static int getCurrentHandle() throws Exception {
      return (bFileIsOpen?1:0);
    }

    public static int next() throws Exception {
      zipFile = zipIs.getNextEntry();
      return (zipFile == null?0:1);
    }

    private static String getFileName (String sEntryName) {
      int iLastSlashPos = sEntryName.lastIndexOf("/");
      if (iLastSlashPos != -1) {
        return sEntryName.substring(iLastSlashPos + 1);
      } else {
        return sEntryName;
      }
    }
 
    public static STRUCT getEntry() throws Exception {
      if (!bFileIsOpen) {
        throw new Exception ("ZIP File is not open - call open() first");
      }
      StructDescriptor sDescr = 
        StructDescriptor.createDescriptor("ZIP_ENTRY_T", con);
      BLOB blobEntryContent = 
        BLOB.createTemporary(con, true, BLOB.DURATION_SESSION);
      OutputStream lobOs = blobEntryContent.setBinaryStream(0L);
      int iChunkSize = blobEntryContent.getChunkSize();
      byte[] b = new byte[iChunkSize];

      int iBytesRead = 0;

      STRUCT oraZipEntry = null;
      Object[] oZipEntry = null;

      if (zipFile != null) {
       oZipEntry = new Object[6];
       oZipEntry[0] = zipFile.getName();
       oZipEntry[1] = getFileName(zipFile.getName());
       oZipEntry[2] = (zipFile.isDirectory()?"Y":"N");
       oZipEntry[3] = new java.math.BigDecimal(zipFile.getSize());
       oZipEntry[4] = new java.math.BigDecimal(zipFile.getCompressedSize());
       while ( (iBytesRead = zipIs.read(b, 0, iChunkSize)) != -1) {
        lobOs.write(b, 0, iBytesRead);
       }
       lobOs.flush();
       lobOs.close();
       oZipEntry[5] = blobEntryContent;
       oraZipEntry = new STRUCT(sDescr, con, oZipEntry);
      } else {
        throw new Exception ("End of zip file reached");
      }
      return oraZipEntry;
    }

    public static void close() throws Exception{
     lobIs.close();
     zipIs.close();
     lobIs = null;
     zipIs = null;
     bFileIsOpen = false;
    }
     

    public static ARRAY list (BLOB inLob) throws Exception {
      InputStream lobIs = inLob.getBinaryStream();
      ZipInputStream zipIs = new ZipInputStream(lobIs);
      ZipEntry zipFile = null;
      boolean bEndOfArchive = false;

      ArrayDescriptor aDescr = ArrayDescriptor.createDescriptor("ZIP_ENTRY_CT", con);
      StructDescriptor sDescr = StructDescriptor.createDescriptor("ZIP_ENTRY_T", con);

      Object[] oZipEntry = new Object[6];
      STRUCT oraZipEntry = null;
      Vector vZipEntries = new Vector();

      while (!bEndOfArchive) {
        zipFile = zipIs.getNextEntry();
        if (zipFile != null) {
         oZipEntry[0] = zipFile.getName();
         oZipEntry[1] = getFileName(zipFile.getName());
         oZipEntry[2] = (zipFile.isDirectory()?"Y":"N");
         oZipEntry[3] = new java.math.BigDecimal(zipFile.getSize());
         oZipEntry[4] = new java.math.BigDecimal(zipFile.getCompressedSize());
         oZipEntry[5] = null;
         oraZipEntry = new STRUCT(sDescr, con, oZipEntry);
         vZipEntries.add(oraZipEntry);
        } else {
         bEndOfArchive = true;
        }
      }            
      lobIs.close();
      return new ARRAY(aDescr, con, vZipEntries.toArray());
    }

    public static BLOB zip(String query) throws Exception {
        PreparedStatement pstmt = con.prepareStatement(query);
        BLOB result = zip(pstmt.executeQuery());
        pstmt.close();
        return result;
    }


    public static BLOB zip(ResultSet   rset) throws Exception {
        BLOB zipLob = BLOB.createTemporary(con, true, BLOB.DURATION_SESSION);
  
        OutputStream os = zipLob.setBinaryStream(1);
        ZipOutputStream zos = new ZipOutputStream(os);

        BLOB src = null;
        String filename = null;

        int chunksize = zipLob.getChunkSize();
        while (rset.next()) {
            filename = rset.getString( 1 );
            src = ((OracleResultSet)rset).getBLOB( 2);

            ZipEntry entry = new ZipEntry(filename);
            if (src != null) {
              entry.setSize(src.length());
            } else {
              entry.setSize(0);
            }
            zos.putNextEntry(entry);
            if (src != null) {
              long len = src.length();
              long offset = 1;
              byte[] buffer;
              while (offset < len) {
                 buffer = src.getBytes(offset, chunksize);
                 if (buffer == null) 
                   break;
 
                 zos.write(buffer, 0, buffer.length);  
                 offset += buffer.length;
              }
            }
            zos.closeEntry();
        }
        zos.close();
        rset.close();
        return zipLob;
    }
}
/

hannes_a
Posts: 77
Joined: Sun 22 Jan 2006 20:44
Location: munic

Re: TOraScript with create JAVA in direct mode

Post by hannes_a » Tue 28 Oct 2008 12:26

Devart support,

please give me an answer/hint/solution, I've to rollout a new version of our project this week

thank you !

Plash
Devart Team
Posts: 2844
Joined: Wed 10 May 2006 07:09

Post by Plash » Tue 28 Oct 2008 13:38

Currently the TOraScript component does not support CREATE JAVA statement. We'll add such support in the next ODAC build.

Post Reply