JAVA CODING EXAMPLES - 4690 Operating System Base
/* * Class to test access to a 4690 Keyed File from a Java Application * It is written to use an existing file on a shared basis to make sure * the file can be accessed while GSA or SA is also using the file */ /* * Philip Robinson June 1999 * Version 1.0 */ import [Link].OS4690.* ; import [Link].* ; class Keyed_File_Access { public static void main(String[] args) { String fileName ; int inchr ; byte[] myRecord = new byte[3000] ; String myKey ; // This try is for ALL the code in the class to catch any errors that may occur try { // Ask for a filename [Link]("Type a Filename and then press the Enter key") ; // Read user input fileName = "" ; while (true) { inchr = [Link]() ; if (inchr == 13 || inchr == 10) break ; fileName = fileName + (char)inchr ; } // Show filename user entered [Link]("\nUsing Filename: " + fileName) ; // Open filename as an existing 4690 Keyed File for shared read access KeyedFile myFile = new KeyedFile(new File(fileName), "r", KeyedFile.SHARED_READ_ACCESS) ; // Display KeyLength and RecordSize [Link]("\nRecordSize is: " + [Link]()) ; [Link]("KeyLength is: " + [Link]()) ;
JAVA CODING EXAMPLES - 4690 Operating System Base
// Ask user for keys until user enters 0 (zero) while (true) { // Ask user for a key [Link]("\nType a Key and press Enter") ; [Link]("Type 0 (zero) to stop") ; // Read user input and put it into myKey myKey = "" ; while (true) { inchr = [Link]() ; if (inchr == 13 || inchr == 10) break ; myKey = myKey + (char)inchr ; } // If key is zero then stop if ([Link]("0")) break ; // Now pack myKey into the record buffer (a byte array) packUPD(myRecord, 0, myKey) ; // Now read the record from the file and display the item description [Link](myRecord, KeyedFile.NO_LOCK) ; [Link]("Item Description: " + new String(myRecord, 24, 15)) ; } // End of asking for keys loop } // End of Try // All possible catches for the try block that covers the whole class catch (FlexosException e) { String err = [Link]() ; [Link](err + " Return Code: " + [Link]()) ; } catch (InvalidParameterException e) { String err = [Link]() ; [Link](err) ; } catch (IOException e) { String err = [Link]() ; [Link](err) ; } } // End of Main /**
JAVA CODING EXAMPLES - 4690 Operating System Base
* Insert an unsigned packed decimal into a byte array. * * @param Array the byte array to which the <code>String</code> will be inserted. * @param Offset the position in the byte array from where insertion will begin. * @param Value the string to be inserted (this must be only digits). */ public static void packUPD( byte[] Array, int Offset, String Value ) { // If the string is an odd length then pack with an F if ( [Link]() % 2 == 1 ) Value = (char) 0xFF + Value ; // Now pack each pair of bytes into the array for ( int i = 0, j = Offset ; i < [Link]() ; i += 2, j++ ) Array[j] = (byte) ( ( ( [Link](i) & 0x0F ) << 4 ) + ( [Link](i+1) & 0x0F ) ) ; } } // End of Class _________________________________________________________________________________________ import [Link].*; import [Link].*; import [Link]; /** * Quick demonstration of GSA signon with JIOP * * REQUIRED: GSA * JavaPOS installed configured * Redirection configured for JIOP * * Philip Robinson June 1999 */ public class Signon implements Runnable, IOPReadyListener, PromptChangeListener, QueueStatusChangeListener { /** * Main */ public static void main(String[] args) { [Link]("JIOP demo starting"); // SystemMonitor will enable trace system for uncaught exceptions SystemMonitor sm = new SystemMonitor(); Thread mainThread = new Thread(sm, new Demo()); [Link](); } public void run() { // Construct the JIOP and listen for Ready IOPReadyListener[] iopRListener = new IOPReadyListener[1]; iopRListener[0] = this; iop = new JIOProcessor(iopRListener);
JAVA CODING EXAMPLES - 4690 Operating System Base
// Inform DM we are ready [Link](); } /** * Indicates the JIOP is ready * */ public void iopReady(IOPReadyEvent iopr) { [Link]("JIOP ready"); [Link](this); [Link]().addQueueStatusListener(this); } /** * Provides information about the loading process * */ public void iopStatus(IOPInitStatus iops) { [Link]([Link]()); } /** * Dump prompt changes to standard out * */ public void promptChanged(PromptChangeEvent pce) { [Link]([Link]()); } /** * Input queue status event indicates when Input Queue * will accept input */ public void queueStatusChange(QueueStatusChangeEvent q) { if( [Link]().isLocked() ) { return; } try { // Post a 1 UserId and the Signon key when the JIOP // is in the signon state StateTableProcessor stp = [Link](); if( [Link]() == 1 ) { [Link]().postString("1"); [Link]().postCommand(76); [Link]("Signon sent to JIOP"); } } catch (Exception e)
JAVA CODING EXAMPLES - 4690 Operating System Base
{ [Link](e); } } JIOProcessor iop; } _______________________________________________________________________________________ // Title: [Link] // Description: Read and Update of SQL tables using JDBC and Pipe's techniques // to communicate between GSA and JAVA. This program runs in a // terminal environnement // // Two parts: // // Customer loyalty processing: // Read calcultate points and update customer information of an // Oracle database. // // Picking order processing: // Many items of this transaction has to be prepared for // the customer. This part is used to warn the picking // manager that a batch has to be prepared for the customer. // import [Link].*; import [Link].*; import [Link].*; import [Link].OS4690.*; public class fnacGSA { private static int linesize = 131; private static String ucode0 = "\u0000"; private static String ucode1 = "\u0001"; private static String ucode2 = "\u0002"; private static String ucode91 = "\u0041"; private static String ucode81 = "\u0031"; private static String ucode82 = "\u0032"; private static String ucode92 = "\u0042"; private static String ucode93 = "\u0043"; private static String ucode94 = "\u0044"; // Trim a character in a string private static String fnacTrim(String stringToTrim, char charTotrim) { String tempo = new String(); for (int i = 0 ; i < [Link]() ; ++i) { if ([Link](i) != charTotrim) { tempo = tempo + [Link](i); } } /* End for*/ return tempo; } // Main object public fnacGSA() { try { // Pipe creation streamInput = new POSPipeInputStream("PI:GSA2JAVA",6500);
JAVA CODING EXAMPLES - 4690 Operating System Base
[Link]("waiting on PI:GSA2JAVA ..."); // Infinite loop on the reading pipe while (1 == 1) { // Waiting for the GSA message [Link](streamIn); result = new String(streamIn); // Print the result [Link]("message received ..."); [Link]([Link]()); // Process the GSA request traiter(); // Open the pipe from JAVA to GSA. this pipe has already been // created by the GSA program. streamOutput = new POSPipeOutputStream("PI:JAVA2GSA"); [Link]("PI:JAVA2GSA opened"); // Send back the result to GSA streamOut = [Link](); [Link](streamOut); } // end while } // end try OS4690 catch (InvalidParameterException e) { [Link]("InvalidParameterException"); } catch (FlexosException e) { [Link]([Link]()); [Link]("Length"+[Link]()); [Link]("FlexosException"); } // end try OS4690 [Link](result); } // Process the GSA's request void traiter() { // Customer information request if ([Link](ucode91)) { // Read the customer information in the Oracle database Consultation(); } // Customer update request else if ([Link](ucode93)) { // Update the customer information in the Oracle database majSolde(); } // Change the picking status in the Oracle database else if ([Link](ucode81)) { // Update the picking information in the Oracle database picking(); } } // Read the customer information using JDBC void Consultation() { codeRetour = ucode0; SQLStatement = "select * from adherents where compte="+[Link](2,22); try { [Link] ( new [Link] ()); Connection conn = [Link] (
JAVA CODING EXAMPLES - 4690 Operating System Base
"jdbc:oracle:thin:@[Link]:1526:STORE","SCOTT","TIGER"); Statement stmt = [Link] (); ResultSet rset = [Link] (SQLStatement); [Link](); // Get the results // Date of the last customer buy dateDernierAchat = [Link]("DERNIER_ACHAT_CUMULE").toString(); // Time of the last customer buy timeDernierAchat = [Link]("DERNIER_ACHAT_CUMULE").toString(); // Date of the last customer buy dateDerniereAcquisitionPoints = [Link]("DERNIERE_ACQUISITION_POINTS").toString(); // Time of the last customer buy timeDerniereAcquisitionPoints = [Link]("DERNIERE_ACQUISITION_POINTS").toString(); // Calculate bonus points for this customer calculPoints(); // Format the results ancienCumulPointsString = "00000000"+[Link]("CUMUL_POINTS"); //[Link]("ancienCumulPoints: "+ancienCumulPointsString); ancienCumulAchatsString = "00000000"+[Link]("CUMUL_ACHATS"); //[Link]("ancienCumulAchats: "+ancienCumulAchatsString); nombrePointsAttribuerString = "000"+ nombrePointsAttribuer; //[Link]("nombrePointsAttribuer: "+nombrePointsAttribuerString); nomAdherent = [Link]("NOM") + new String(" "); padder(); dateDernierAchat = fnacTrim(dateDernierAchat,'-'); timeDernierAchat = fnacTrim(timeDernierAchat,':'); dateDerniereAcquisitionPoints= fnacTrim(dateDerniereAcquisitionPoints,'-'); timeDerniereAcquisitionPoints= fnacTrim(timeDerniereAcquisitionPoints,':'); // Format the result result = ucode92 +codeRetour +[Link](2,30) +dateDernierAchat +timeDernierAchat +dateDerniereAcquisitionPoints +timeDerniereAcquisitionPoints +ancienCumulPointsString +ancienCumulAchatsString +nombrePointsAttribuerString +[Link](78,94) +nomAdherent; } // end try Consultation catch (SQLException e) { if ([Link]() == 0 ) { codeRetour = ucode1; } else { codeRetour = ucode2; } // if any error occured, update the return code result = ucode92+codeRetour+[Link](2,linesize); [Link]("SQLException"); } // end try Consultation } // end consultation // Update the new customer information
JAVA CODING EXAMPLES - 4690 Operating System Base
void majSolde() { codeRetour = ucode0; // Set the transaction date dateDernierAchat = [Link](30,34)+'-'+[Link](34,36)+'-'+[Link](36,38); dateDerniereAcquisitionPoints = dateDernierAchat; // Build the SQL statement SQLStatement = "update adherents set " +"DERNIER_ACHAT_CUMULE = to_date('" + dateDernierAchat + "','YYYY-MM-DD')" +", DERNIERE_ACQUISITION_POINTS = to_date('" + dateDerniereAcquisitionPoints + "','YYYY-MM-DD')" +", CUMUL_POINTS = "+[Link](77,85) +", CUMUL_ACHATS = "+[Link](85,93) +" where compte="+[Link](2,22); try { [Link] ( new [Link] ()); Connection conn = [Link] ( "jdbc:oracle:thin:@[Link]:1526:STORE","SCOTT","TIGER"); Statement stmt = [Link] (); // Update customer information [Link](SQLStatement); // Format the result result = ucode94+codeRetour+[Link](2,linesize); } // end try SQL catch (SQLException e) { if ([Link]() == 0 ) { codeRetour = ucode1; } else { codeRetour = ucode2; } // An error occured, advise GSA result = ucode94+codeRetour+[Link](2,linesize); [Link]("SQLException"); } // end try SQL } // end majSolde // Update the picking status in the Oracle database void picking() { codeRetour = ucode0; dateFinReservation = new Date([Link]()); SQLStatement = "update WIN_STORE_TRC set " +"STATUS = 'P'" +", DATE_TIME = SYSDATE" +" where STORE ="+[Link](2,6) +" and INVOICE_NUMBER ="+[Link](6,18); [Link]("update WIN_STORE_TRC set " [Link]("STATUS = 'P'" ); [Link](", DATE_TIME = SYSDATE"); [Link](" where STORE ="+[Link](2,6) ); [Link](" and INVOICE_NUMBER ="+[Link](6,18)); try {
);
JAVA CODING EXAMPLES - 4690 Operating System Base
[Link] ( new [Link] ()); Connection conn = [Link] ( "jdbc:oracle:thin:@[Link]:1526:FIBPROTO","RMSDEV80","RMSDEV80"); Statement stmt = [Link] (); //Update table WIN_STORE_TRC [Link](SQLStatement); // Format he result message that will be senbd to GSA result = ucode82 + codeRetour + [Link](2,19); [Link](); [Link](); } // end try picking SQL catch (SQLException e) { codeRetour = ucode1; // an eror occured result = ucode82 + codeRetour+[Link](2,19); [Link]("SQLException"+[Link]()); } // end try picking SQL with catches } // Formatting routine void padder() { ancienCumulPointsString = [Link]([Link]()-8); [Link]("ancienCumulPoints: "+ancienCumulPointsString); ancienCumulAchatsString = [Link]([Link]()-8); [Link]("ancienCumulAchatsString: "+ ancienCumulAchatsString); nombrePointsAttribuerString = [Link]([Link]()-3); [Link]("nombrePointsAttribuerString: "+ nombrePointsAttribuerString); nomAdherent = [Link](0,38); [Link]("nomAdherent: "+ nomAdherent ); [Link]("nomAdherent length: " + [Link]() ); } // Calculate bonus point. First transaction of the day, give 3 points 0 if // not. void calculPoints() { dateDernierAchatDate = [Link](dateDernierAchat); dateDerniereAcquisitionPointsDate = [Link](dateDerniereAcquisitionPoints); if ([Link](dateDerniereAcquisitionPointsDate)) { nombrePointsAttribuer = 3; } else { nombrePointsAttribuer = 0; } } // Init variables POSPipeOutputStream streamOutput; byte[] streamOut = new byte[linesize]; byte[] streamIn = new byte[linesize]; POSPipeInputStream streamInput; String result = "0123456789"; String codeRetour = ucode0; SimpleDateFormat formatDate = new SimpleDateFormat ("yyyyMMdd"); SimpleDateFormat formatHeure = new SimpleDateFormat ("HHmmss");
JAVA CODING EXAMPLES - 4690 Operating System Base
int nombrePointsAttribuer = 0; String ancienCumulPointsString = "00000000"; String ancienCumulAchatsString = "00000000"; String nomAdherent = "012345678901234567890123456789012345678"; String nombrePointsAttribuerString = "000"; String dateDernierAchat = "19990101"; String timeDernierAchat = "123456"; String dateDerniereAcquisitionPoints = "19990101"; String timeDerniereAcquisitionPoints = "123456"; Date dateDerniereAcquisitionPointsDate = new Date([Link]()); Date dateDernierAchatDate = new Date([Link]()); String SQLStatement = "select * from dual"; Date dateFinReservation; // Mainline public static void main(String[] args) { new fnacGSA(); } } // end fnacGSA()