Lotus Notes / Domino Sonstiges > Java und .NET mit Notes/Domino

Abfrage auf Oracle-DB dauert sehr labge

<< < (3/4) > >>

DAU-in:
So sieht es jetzt aus
wenn ich das Updatedoc recycle, bricht der Agent ab.
Die Abfragen dauern aktuell 12 bis 18 Sekunden.
Kann ich jetzt noch etwas machen, ohne den gesamten Agenten umzustricken?

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.*;
import java.lang.*;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Vector;
 
import lotus.domino.*;     


public class yyystellenPruefung extends AgentBase {
   Session session = null;
   long lastMillis = System.currentTimeMillis();
   
   Database dbCurrent = null; //aktuelle DB

//für Oracle-Verbindung
   View oracleConfigView = null;
   Document docOracleConfig = null; //Konfigurationseinstellungen für Oracle   
   String strOracleServer = null; //
   String strOracleView = null; //
   String strOracleUser = null; //
   String strOraclePwd = null; //
   Connection conn=null; //
   ResultSet rs=null; //
   //PreparedStatement stmt=null; //
   Statement stmt=null; //
   //Vector listNames = new Vector();  //(Vektorliste zum aufNehmen der werte)
   String [] listNames =  null;


// zu bearbeitende Dokumente

   View terminalView = null;  //zur 'Ermittlung der Dokumente
   long newDocs = 0;   
   Document terminalDoc = null; //aktuelles Terminaldoc
   Document nextDoc = null;
   
// Protokolldokument
   Document logDoc = null; //Protokoll
   GregorianCalendar cal=null; //
   Item logItem=null; //
   int logCount=0; //
   int logDocCount=1; //

   public void NotesMain() {

      try {
         System.out.println("Agent: Check für yyystellenaenderungen neu gestartet");
         session = getSession();
         AgentContext agentContext = session.getAgentContext();
         dbCurrent = agentContext.getCurrentDatabase();               // aktuelle Datenbank holen
                  
//Erstellung Protokolldokument
         cal = new GregorianCalendar();
               logDoc = dbCurrent.createDocument();
         logDoc.replaceItemValue("Form","Log");
         logDoc.replaceItemValue("Lauf","Lauf vom: " + cal.get(Calendar.DATE)+"."+(cal.get(Calendar.MONTH)+1)+"."+cal.get(Calendar.YEAR)+" " + cal.get(Calendar.HOUR_OF_DAY)+":"+cal.get(Calendar.MINUTE)+" Uhr");
         logDoc.replaceItemValue("Start",cal.get(Calendar.DATE)+"."+(cal.get(Calendar.MONTH)+1)+"."+cal.get(Calendar.YEAR)+" " + cal.get(Calendar.HOUR_OF_DAY)+":"+cal.get(Calendar.MINUTE)+" Uhr");
         
         logDoc.replaceItemValue("Log","");
         logItem = logDoc.getFirstItem("Log");      
         logEvent("neuer Agent: Check für yyystellenüberprüfung gestartet");   
         logDoc.save(true,false);   //einmal abspeichern, damit Abbruch ersichtlich wird
         
         //Einlesen der Oraclekonfigurationseinstellung
         oracleConfigView    = dbCurrent.getView("(luConfig)");
         docOracleConfig       = oracleConfigView.getDocumentByKey("OracleConfig");
         strOracleServer       = docOracleConfig.getItemValueString("OracleServer");
         strOracleView          = docOracleConfig.getItemValueString("OracleView");
         strOracleUser          = docOracleConfig.getItemValueString("OracleUser");
         strOraclePwd          = docOracleConfig.getItemValueString("OraclePwd");

//Erstellen der Verbindung
// achtung: wenn hier Fehlermeldung kommt wegen fehlendem Oracle-treiber --->
//im Agent müssen die Klassen als JArdatei eingehängt sein, wird unter 'Projekt bearbeiten' angezeigt, notfalls auf OracleHomeopage suchen
   logEvent("vor Driver " + System.currentTimeMillis());       
   DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver());
   logEvent("vor conn  " + System.currentTimeMillis());
   conn = DriverManager.getConnection("jdbc:oracle:thin:@"+strOracleServer, strOracleUser, strOraclePwd);  //Aufbau Verbindung

if (conn.isClosed())
            logEvent("Oracle Connection is not open yet.");
                  stmt = conn.createStatement();
         logEvent("Datenbankanbindung an ACAT erfolgreich hergestellt");
   
   
// Ermitteln der zu überprüfenden Dokumente

      terminalView = dbCurrent.getView("(luACATAbfrage)");
      terminalDoc = terminalView.getFirstDocument();

       while (terminalDoc != null) {
                 nextDoc = terminalView.getNextDocument(terminalDoc);
                
                checkyyyInfo(terminalDoc);
                       
                     logEvent("processing doc " + terminalDoc.getUniversalID() + " Zeitdif->" + getDifMillis() + " milliseconds");
            terminalDoc.recycle();
            terminalDoc = nextDoc;
         
         } //Ende While
         nextDoc.recycle();
            terminalDoc.recycle();

         logDoc.save(true,false);   
         logDoc.recycle();
      
         stmt.close();
          conn.close();
         
             terminalView.recycle();
      
         docOracleConfig.recycle();
         oracleConfigView.recycle();
         dbCurrent.recycle();
          session.recycle();
      } catch(Exception e) {
      
         e.printStackTrace();
      }      finally{
      

   
      
   //   GC.recycle(nextDoc);
      System.gc();
      }
   } //Schließen Main
   

public void checkyyyInfo(Document updateDoc)
   {
      
      try {
            logEvent("vor Abfrage " + System.currentTimeMillis());
            String common = updateDoc.getItemValueString("BKUName");
            rs = stmt.executeQuery ("SELECT * FROM " + strOracleView + " WHERE BKUName='"+common + "'");
                  logEvent(common + System.currentTimeMillis());
            if (rs.next())
            {
            String strxxxstelle = new String(rs.getString(3));
            String stryyystelle = new String(rs.getString(4));
         
            String strOldyyystelle = updateDoc.getItemValueString("yyystelle");
            String strOldxxxstelle = updateDoc.getItemValueString("xxxstelle");
            
            boolean result1 = strOldyyystelle.equals(stryyystelle );       
            boolean result2 = strOldxxxstelle.equals(strxxxstelle );   
            if ( result1 == false|| result2 == false)
                  {
                     fillyyyInfo (updateDoc, stryyystelle, strxxxstelle);
                  }

         }
              
             //  updateDoc.recycle();
                               rs.close();
     
         }
            
      catch(Exception e) {
         e.printStackTrace();
      }
   }// Schliessen checkyyystellenInfo    
   
      public void fillyyyInfo(Document updateDoc, String stryyystelle,String strxxxstelle)
   {
      try {
      
         String common = updateDoc.getItemValueString("zzzName");
   
               updateDoc.replaceItemValue("xxxstelle",stryyystelle);
               updateDoc.replaceItemValue("yyystelle",strxxxstelle);   
         logEvent(common + System.currentTimeMillis());

   
                  updateDoc.save(true,false);   
           
         }
            
      catch(Exception e) {
         e.printStackTrace();
      }
   }// Schliessen FillyyystellenInfo    
   
   
   public void logEvent(String eventToBeLogged)
   {
      try {
      
         logCount++;
         logItem.appendToTextList(eventToBeLogged);
         if (logCount > 200)
         {
            logDocCount++;
            logCount=0;
            logDoc.save(true,false);
            logDoc = dbCurrent.createDocument();
            logDoc.replaceItemValue("Form","Log");
            logDoc.replaceItemValue("Lauf","Lauf vom: " + cal.get(Calendar.DATE)+"."+(cal.get(Calendar.MONTH)+1)+"."+cal.get(Calendar.YEAR)+" " + cal.get(Calendar.HOUR_OF_DAY)+":"+cal.get(Calendar.MINUTE)+" Uhr " + logDocCount + ". Teil");
            logDoc.replaceItemValue("Log","");
            logItem = logDoc.getFirstItem("Log");
         }
      }
      catch (Exception e) {
         e.printStackTrace();
      }
   }//Ende logEvent
   
   public long getDifMillis()
   {
        long newMillis = System.currentTimeMillis();
        long dif = newMillis -  lastMillis;
        lastMillis = newMillis;
        return dif ;
   }// Ende getDifMillis()

}
 

flaite:

--- Zitat von: DAU-in link=topic=45155.msg290462#msg290462 date=1242227612
Kann ich jetzt noch etwas machen, ohne den gesamten Agenten umzustricken?
[/quote ---Ja. Warten, bis ich den "umgestrickt" hab.
Spätestens heute abend um 11.

--- Ende Zitat ---

flaite:
Mein Vorschlag (nicht getestet, da das Erstellen einer oracle db und deiner NotesDb zum funktionalen Testen jetzt too much wäre:
Code ist ein wenig besser aufgeteilt auf Methoden (geht natürlich noch besser, ist wichtig).


Und meine Idee mit den in. Über eine Map.
Du schreibst erst alle Infos aus den alten Notes Doks in eine Map.
Daraus läßt sich dann genau 1 Query erzeugen.
Nachteil ist, dass die zu verändernden Dokumente neu aus der Datenbank geholt werden müssen. Hab aber die Regel, Notes Dokumente tendentiell kurz zu halten. Dann übersieht man weniger recycle Probleme.

Hab eine Menge Variablen lokal gemacht.

Connection am besten im finally schliessen. resultset und statement müssen eigentlich geschlossen werden.

weiss btw. z.Zt. auch nicht wie man mit der select ... in syntax mit prepared Statements arbeitet, zorry.

Mach morgen krasse innovative Idee wie man mit dem ConfigOracleDoc umgeht.

logDoc geht auch besser.




--- Code: ---import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.Map;

import lotus.domino.AgentBase;
import lotus.domino.AgentContext;
import lotus.domino.Database;
import lotus.domino.Document;
import lotus.domino.Item;
import lotus.domino.NotesException;
import lotus.domino.Session;
import lotus.domino.View;

import java.util.Iterator;

public class yyystellenPruefung extends AgentBase {

private long lastMillis = System.currentTimeMillis();

private Database dbCurrent = null; // aktuelle DB

// für Oracle-Verbindung



private Document logDoc;
private Item logItem;

// zu bearbeitende Dokumente

private String strOracleView;
private long newDocs = 0;
private long logCount;
private long logDocCount;



private Connection connectToOracle(Document docOracleConfig) throws SQLException, NotesException {
logEvent("vor Driver " + System.currentTimeMillis());
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
logEvent("vor conn  " + System.currentTimeMillis());
String strOracleServer = docOracleConfig
.getItemValueString("OracleServer");
String strOracleUser = docOracleConfig.getItemValueString("OracleUser");
String strOraclePwd = docOracleConfig.getItemValueString("OraclePwd");


Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@"
+ strOracleServer, strOracleUser, strOraclePwd); // Aufbau

// Verbindung

if (conn.isClosed()) {
logEvent("Oracle Connection is not open yet.");
return null;
}

return conn;

}

public void NotesMain() {
Connection conn = null;
try {
System.out
.println("Agent: Check für yyystellenaenderungen neu gestartet");
Session session = getSession();
AgentContext agentContext = session.getAgentContext();
dbCurrent = agentContext.getCurrentDatabase(); // aktuelle Datenbank
// holen

// Erstellung Protokolldokument
Calendar cal = new GregorianCalendar();
logDoc = dbCurrent.createDocument();
logDoc.replaceItemValue("Form", "Log");
logDoc.replaceItemValue("Lauf", "Lauf vom: "
+ cal.get(Calendar.DATE) + "."
+ (cal.get(Calendar.MONTH) + 1) + "."
+ cal.get(Calendar.YEAR) + " "
+ cal.get(Calendar.HOUR_OF_DAY) + ":"
+ cal.get(Calendar.MINUTE) + " Uhr");
logDoc.replaceItemValue("Start", cal.get(Calendar.DATE) + "."
+ (cal.get(Calendar.MONTH) + 1) + "."
+ cal.get(Calendar.YEAR) + " "
+ cal.get(Calendar.HOUR_OF_DAY) + ":"
+ cal.get(Calendar.MINUTE) + " Uhr");

logDoc.replaceItemValue("Log", "");
logItem = logDoc.getFirstItem("Log");
logEvent("neuer Agent: Check für yyystellenüberprüfung gestartet");
logDoc.save(true, false); // einmal abspeichern, damit Abbruch
// ersichtlich wird

// Einlesen der Oraclekonfigurationseinstellung
View oracleConfigView = dbCurrent.getView("(luConfig)");
Document docOracleConfig  = oracleConfigView.getDocumentByKey("OracleConfig");

strOracleView = docOracleConfig.getItemValueString("OracleView");


// Erstellen der Verbindung
// achtung: wenn hier Fehlermeldung kommt wegen fehlendem
// Oracle-treiber --->
// im Agent müssen die Klassen als JArdatei eingehängt sein, wird
// unter 'Projekt bearbeiten' angezeigt, notfalls auf
// OracleHomeopage suchen
conn = connectToOracle(docOracleConfig);

if (conn != null) {
logEvent("Datenbankanbindung an ACAT erfolgreich hergestellt");

// Ermitteln der zu überprüfenden Dokumente

View terminalView = dbCurrent.getView("(luACATAbfrage)");
Document terminalDoc = terminalView.getFirstDocument();

// writes all old info in notes in vo objects in a map, using bkuname as key


Map mapTerminalDoc = new HashMap();
while (terminalDoc != null) {
Document nextDoc = terminalView
.getNextDocument(terminalDoc);
VOTerminalDoc termDoc = new VOTerminalDoc();
termDoc.setBkuName(terminalDoc
.getItemValueString("BKUName"));
termDoc.setNotesUniversalId(terminalDoc.getUniversalID());

termDoc.setXxxstelle(terminalDoc
.getItemValueString("xxxstelle"));
termDoc.setYyystelle(terminalDoc
.getItemValueString("yyystelle"));

mapTerminalDoc.put(termDoc.getBkuName(), termDoc);

terminalDoc.recycle();
terminalDoc = nextDoc;

} // Ende While

checkyyyInfo(mapTerminalDoc, conn);

logDoc.save(true, false);
logDoc.recycle();

// terminalView.recycle();

// docOracleConfig.recycle();
// oracleConfigView.recycle();

}

} catch (Exception e) {

e.printStackTrace();

} finally {
try {
if (conn != null) {
conn.close();
}

} catch (SQLException e) {

}

}
} // Schließen Main

public void checkyyyInfo(Map mapTerminalDoc, Connection conn) {

try {
logEvent("vor Abfrage " + System.currentTimeMillis());

String query = "Select BKUName, name_von_spalte_3, name_von_spalte_4 From "
+ strOracleView
+ " WHERE BKUName IN "
+ buildSelectInQueryCondition(mapTerminalDoc.keySet()
.iterator());
System.out.println("QUERY=" + query);
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(query);
logEvent(query + "-->" + System.currentTimeMillis());
if (rs.next()) {
String bkuName = rs.getString("BKUName");
VOTerminalDoc termDoc = (VOTerminalDoc) mapTerminalDoc
.get(bkuName);

String strxxxstelleFromDb = new String(rs
.getString("name_von_spalte_3"));
String stryyystelleFromDb = new String(rs
.getString("name_von_spalte_4"));

if (strxxxstelleFromDb != termDoc.getXxxstelle()
|| strxxxstelleFromDb != termDoc.getYyystelle()) {
Document updateDoc = dbCurrent.getDocumentByUNID(termDoc
.getNotesUniversalId());
System.out.println("updating doc ->" + termDoc);
fillyyyInfo(updateDoc, strxxxstelleFromDb,
stryyystelleFromDb);
}

}

// updateDoc.recycle();
rs.close();

}

catch (Exception e) {
e.printStackTrace();
}
}// Schliessen checkyyystellenInfo

private String buildSelectInQueryCondition(Iterator itKeys) {
StringBuffer buf = new StringBuffer();
buf.append("(");
while (itKeys.hasNext()) {
String key = itKeys.next().toString();
buf.append("'");
buf.append(key);
buf.append("'");
}
buf.append(")");

return buf.toString();

}

private void fillyyyInfo(Document updateDoc, String stryyystelle,
String strxxxstelle) {
try {

String common = updateDoc.getItemValueString("zzzName");

updateDoc.replaceItemValue("xxxstelle", stryyystelle);
updateDoc.replaceItemValue("yyystelle", strxxxstelle);
logEvent(common + System.currentTimeMillis());

updateDoc.save(true, false);
updateDoc.recycle();

}

catch (Exception e) {
e.printStackTrace();
}
}// Schliessen FillyyystellenInfo

private void logEvent(String eventToBeLogged) {
try {
Calendar cal = new GregorianCalendar();
logCount++;
logItem.appendToTextList(eventToBeLogged);
if (logCount > 200) {
logDocCount++;
logCount = 0;
logDoc.save(true, false);
logDoc = dbCurrent.createDocument();
logDoc.replaceItemValue("Form", "Log");
logDoc.replaceItemValue("Lauf", "Lauf vom: "
+ cal.get(Calendar.DATE) + "."
+ (cal.get(Calendar.MONTH) + 1) + "."
+ cal.get(Calendar.YEAR) + " "
+ cal.get(Calendar.HOUR_OF_DAY) + ":"
+ cal.get(Calendar.MINUTE) + " Uhr " + logDocCount
+ ". Teil");
logDoc.replaceItemValue("Log", "");
logItem = logDoc.getFirstItem("Log");
}
} catch (Exception e) {
e.printStackTrace();
}
}// Ende logEvent

public long getDifMillis() {
long newMillis = System.currentTimeMillis();
long dif = newMillis - lastMillis;
lastMillis = newMillis;
return dif;
}// Ende getDifMillis()

}

class VOTerminalDoc {
private String bkuName;
private String notesUniversalId;
private String xxxstelle;
private String yyystelle;

public String getBkuName() {
return bkuName;
}

public void setBkuName(String bkuName) {
this.bkuName = bkuName;
}

public String getNotesUniversalId() {
return notesUniversalId;
}

public void setNotesUniversalId(String notesUniversalId) {
this.notesUniversalId = notesUniversalId;
}

public String getXxxstelle() {
return xxxstelle;
}

public void setXxxstelle(String xxxstelle) {
this.xxxstelle = xxxstelle;
}

public String getYyystelle() {
return yyystelle;
}

public void setYyystelle(String yyystelle) {
this.yyystelle = yyystelle;
}

public String toString() {
return "[" + getClass().getName() + "\n\tbkuName=" + getBkuName()
+ "\n\tnotesUniversalId=" + getNotesUniversalId()
+ "\n\txxxstelle=" + getXxxstelle() + "\n\tyyystelle="
+ getYyystelle() + "\n]";
}

}

--- Ende Code ---

DAU-in:
Kompilieren lässt es sich, und die Verbindung wird hergestellt.

Dsnach hakts, aber da muss ich jetzt mal sehen

flaite:
Wo kommt denn der Fehler?
Du hast sicher einen Stacktrace oder ich hab eine Endlosschleife programmiert.

Gruß Axel 

Navigation

[0] Themen-Index

[#] Nächste Seite

[*] Vorherige Sete

Zur normalen Ansicht wechseln