Commit ff126ac1 authored by O'Reilly Media, Inc.'s avatar O'Reilly Media, Inc.
Browse files

Initial commit

parents
Loading
Loading
Loading
Loading

9780596003814

0 → 120000
+1 −0
Changes for 9780596003814: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
9780596003814
 No newline at end of file

README.md

0 → 100644
+15 −0
Changes for README.md: 15 added lines, 0 removed lines.
Original line number Diff line number Diff line
## Example files for the title:  
  
# Oracle PL/SQL Programming 3rd Edition, by Steven Feuerstein
  
[![Oracle PL/SQL Programming 3rd Edition, by Steven Feuerstein](http://akamaicovers.oreilly.com/images/9780596003814/cat.gif)](https://www.safaribooksonline.com/library/view/title/0596003811//)
  
The following applies to example files from material published by O’Reilly Media, Inc. Content from other publishers may include different rules of usage. Please refer to any additional usage rights explained in the actual example files or refer to the publisher’s website.
  
O'Reilly books are here to help you get your job done. In general, you may use the code in O'Reilly books in your programs and documentation. You do not need to contact us for permission unless you're reproducing a significant portion of the code. For example, writing a program that uses several chunks of code from our books does not require permission. Answering a question by citing our books and quoting example code does not require permission. On the other hand, selling or distributing a CD-ROM of examples from O'Reilly books does require permission. Incorporating a significant amount of example code from our books into your product's documentation does require permission.
  
We appreciate, but do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN.
  
If you think your use of code examples falls outside fair use or the permission given here, feel free to contact us at <permissions@oreilly.com>.
  
Please note that the examples are not production code and have not been carefully testing. They are provided "as-is" and come with no warranty of any kind.
+89 −0
Changes for individual_files/DeleteFile.java: 89 added lines, 0 removed lines.
Original line number Diff line number Diff line
CREATE or REPLACE JAVA SOURCE NAMED "DeleteFile" AS

import java.io.*;
import java.sql.*;
import oracle.jdbc.driver.*;
import oracle.sql.*;
import java.util.Date;
import java.text.*;
import java.text.DateFormat.*;

/*
 ** Delete files in specified directories that were last modified before 
 ** a specified date
 */
public class DeleteFile {
    
    public static int delete(oracle.sql.ARRAY tbl) throws SQLException {
        try {
            
            
            // Retrieve the contents of the table/varray as a result set
            ResultSet rs = tbl.getResultSet();
            
            // Iterate through the rows returned by the result set
            // NOTE: The JDBC 2.0 standard specifies that the ResultSet
            //       contains rows consisting of two columns.
            //
            //       Column 1 stores the element index for the row.
            //       Column 2 stores the actual element value.
            //
            for (int ndx = 0; ndx < tbl.length(); ndx++) {
                rs.next();
                
                // Retrieve the array index
                int aryndx = (int)rs.getInt(1);
                
                // Retrieve the array element (an object returned as type STRUCT)
                STRUCT obj = (STRUCT)rs.getObject(2);
                
                // Retrieve the attributes for the object
                // as an array of Java Objects
                Object[] attrs = obj.getAttributes();
                
                // Retrieve the individual attributes
                // casting the object to the correct type
                String    fileDir  = (String)attrs[0];
                Timestamp saveDate = (java.sql.Timestamp)attrs[1];

                // Check that the directory exists
                if (new File (fileDir).isDirectory()) {
                    // Retrive a list of the files in the specified directory
                    String[] filesList = new File (fileDir).list();
                    // Loop through the files checking which ones are older then the date specified
                    for (int i = 0; i < filesList.length; i++) {
                        String fullPathName = fileDir + "\\"+filesList[i];
                        if (lastModified(fullPathName) < saveDate.getTime()) {
                            delete(fullPathName);
                        }
                    }
                } 
            }
            // Close the result set
            rs.close();
            return 0;

        } catch (Exception e) {
            e.printStackTrace();
            return -1;
        }
  }
  
   public static long lastModified (String fileName) {
      return new File (fileName).lastModified();
      }

   public static int delete (String fileName) {
      return bln2int (new File (fileName).delete());
      }
   public static int bln2int (boolean valIn) {
     if (valIn) return 1; else return 0;
   }
}

/*======================================================================
| Supplement to the third edition of Oracle PL/SQL Programming by Steven
| Feuerstein with Bill Pribyl, Copyright (c) 1997-2002 O'Reilly &
| Associates, Inc. To submit corrections or find more code samples visit
| http://www.oreilly.com/catalog/oraclep3/
*/
+17 −0
Changes for individual_files/JDelete.java: 17 added lines, 0 removed lines.
Original line number Diff line number Diff line
import java.io.File;

public class JDelete {
 
   public static int delete (String fileName) {
      File myFile = new File (fileName);
      boolean retval = myFile.delete();
      if (retval) return 1; else return 0;
      }
}

/*======================================================================
| Supplement to the third edition of Oracle PL/SQL Programming by Steven
| Feuerstein with Bill Pribyl, Copyright (c) 1997-2002 O'Reilly &
| Associates, Inc. To submit corrections or find more code samples visit
| http://www.oreilly.com/catalog/oraclep3/
*/
+143 −0
Changes for individual_files/JFile.java: 143 added lines, 0 removed lines.
Original line number Diff line number Diff line
import java.io.File;

public class JFile {
/***************** Modification History **************************
|| Date     By     Description
|| 2/26/99  SEF    Created
|| 8/2000   SEF    Incorporate into PL/Vision
******************************************************************/

   public static String separator (String fileName) {
      File myFile = new File (fileName);
      return myFile.separator;
      }

   /* Also from Paul Sharples
   public static String separator () {
      return System.getProperty("file.separator");
   }
   */
   
   public static int canRead (String fileName) {
      File myFile = new File (fileName);
      boolean retval = myFile.canRead();
      if (retval) return 1; else return 0;
      }

   public static int canWrite (String fileName) {
      File myFile = new File (fileName);
      boolean retval = myFile.canWrite();
      if (retval) return 1; else return 0;
      }

   public static int exists (String fileName) {
      File myFile = new File (fileName);
      boolean retval = myFile.exists();
      if (retval) return 1; else return 0;
      }

   public static int isDirectory (String fileName) {
      File myFile = new File (fileName);
      boolean retval = myFile.isDirectory();
      if (retval) return 1; else return 0;
      }

   public static int isFile (String fileName) {
      File myFile = new File (fileName);
      boolean retval = myFile.isFile();
      if (retval) return 1; else return 0;
      }

   public static long length (String fileName) {
      File myFile = new File (fileName);
      return myFile.length();
      }

   public static String parentDir (String fileName) {
      File myFile = new File (fileName);
      return myFile.getParent();
      }

   public static String pathName (String fileName) {
      File myFile = new File (fileName);
      return myFile.getPath();
      }

   public static long lastModified (String fileName) {
      File myFile = new File (fileName);
      return myFile.lastModified();
      }

   public static int delete (String fileName) {
      File myFile = new File (fileName);
      boolean retval = myFile.delete();
      if (retval) return 1; else return 0;
      }

   public static int mkdir (String fileName) {
      File myFile = new File (fileName);
      boolean retval = myFile.mkdir();
      if (retval) return 1; else return 0;
      }

   public static int rename (
         String oldFile, String newFile) {
      File myFile = new File (oldFile);
      File myFile2 = new File (newFile);
      boolean retval = myFile.renameTo(myFile2);
      if (retval) return 1; else return 0;
      }
      
   /*
   public static oracle.sql.ARRAY dirContents (String dir) 
      throws SQLException, ClassNotFoundException {
      
      File myDir = new File (dir);
      String[] filesList = myDir.list();
      
      Class.forName("oracle.jdbc.driver.OracleDriver");
      Connection con = new OracleDriver().defaultConnection();
      
      ArrayDescriptor arrayDesc = 
         ArrayDescriptor.createDescriptor ("directory_t", con);
      oracle.sql.ARRAY filesArray = new oracle.sql.ARRAY (arrayDesc, con, filesList);
      
      return filesArray;
      }
   */

   public static String dirContents (String dir, String delim) {
      File myDir = new File (dir);
      String[] filesList = myDir.list();
      String contents = new String();
      for (int i = 0; i < filesList.length; i++) 
         contents = contents + delim + filesList[i]; // Utrecht 4/2002
      return contents;
   }
      
   public static void main (String[] args) {
      String contents = dirContents (args[0], args[1]);
      System.out.println (contents);
      /*
      try {
         oracle.sql.ARRAY filesArray = dirContents (args[0]);
         String[] files = (String[]) filesArray.getArray ();
         for (int i = 0; i <= files.length; i++) 
            System.out.println (files[i]);
         }
      catch ( SQLException e ) {
         System.out.println (e.getMessage());}
      catch ( ClassNotFoundException e ) {
         System.out.println ("ClassNotFoundException");}
      */
   } 
           
}


/*======================================================================
| Supplement to the third edition of Oracle PL/SQL Programming by Steven
| Feuerstein with Bill Pribyl, Copyright (c) 1997-2002 O'Reilly &
| Associates, Inc. To submit corrections or find more code samples visit
| http://www.oreilly.com/catalog/oraclep3/
*/
Loading