1 19 package org.openbravo.erpCommon.utility; 20 21 import org.openbravo.data.FieldProvider; 22 import org.apache.log4j.Logger; 23 24 public class ErrorTextParserORACLE extends ErrorTextParser { 25 static Logger log4j = Logger.getLogger(ErrorTextParserORACLE.class); 26 27 public OBError parse() throws Exception { 28 if (getMessage().equals("")) return null; 29 else if (getConnection()==null) return null; 30 OBError myError = null; 31 OBError myCodeError = null; 32 int errorCode = 0; 33 String errorCodeText = ""; 34 String myMessage = getMessage(); 35 if (log4j.isDebugEnabled()) log4j.debug("Message: " + myMessage); 36 int pos = myMessage.indexOf("ORA-"); 38 if (pos!=-1) { 39 try { 41 errorCode = Integer.valueOf(myMessage.substring(pos+4, myMessage.indexOf(":", pos+4))).intValue(); 42 errorCodeText = myMessage.substring(pos, myMessage.indexOf(":", pos)); 43 } catch (Exception ignored) { 44 errorCode = 0; 45 errorCodeText = ""; 46 } 47 if (log4j.isDebugEnabled()) log4j.debug("Error code: " + Integer.toString(errorCode)); 48 if (errorCode!=0) { 49 FieldProvider fldMessage = Utility.locateMessage(getConnection(), errorCodeText, getLanguage()); 50 if (fldMessage!=null) { 51 myCodeError = new OBError(); 52 myCodeError.setType((fldMessage.getField("msgtype").equals("E")?"Error":"Warning")); 53 myCodeError.setMessage(fldMessage.getField("msgtext")); 54 } else if (errorCode>= 20000 && errorCode<=30000) { 56 myError = new OBError(); 57 myError.setType("Error"); 58 String messageAux = Utility.parseTranslation(getConnection(), getVars(), getLanguage(), myMessage.replace(errorCodeText + ": ", "")); 59 if (log4j.isDebugEnabled()) log4j.debug("Message parsed: " + messageAux); 60 myError.setMessage(messageAux); 61 return myError; 62 } 63 } 64 pos = myMessage.indexOf("(", pos+4); 67 if (pos != -1) { 68 int finalPos = myMessage.indexOf(")", pos+1); 69 if (finalPos==-1) finalPos = myMessage.length(); 70 String objectName = myMessage.substring(pos + 1, finalPos); 71 if (log4j.isDebugEnabled()) log4j.debug("Object name: " + objectName); 72 pos = objectName.indexOf("."); 73 if (pos!=-1) objectName = objectName.substring(pos+1); 74 if (log4j.isDebugEnabled()) log4j.debug("Object real name: " + objectName); 75 ErrorTextParserORACLEData[] constraintData = ErrorTextParserORACLEData.select(getConnection(), objectName); 76 if (constraintData!=null && constraintData.length>0) { 78 FieldProvider fldMessage = Utility.locateMessage(getConnection(), constraintData[0].constraintName, getLanguage()); 80 if (fldMessage!=null) { 81 myError = new OBError(); 82 myError.setType((fldMessage.getField("msgtype").equals("E")?"Error":"Warning")); 83 myError.setMessage(fldMessage.getField("msgtext")); 84 return myError; 85 } 86 if (constraintData[0].constraintType.equalsIgnoreCase("C") && !constraintData[0].searchCondition.equals("")) { 88 fldMessage = Utility.locateMessage(getConnection(), constraintData[0].searchCondition, getLanguage()); 90 if (fldMessage!=null) { 91 myError = new OBError(); 92 myError.setType((fldMessage.getField("msgtype").equals("E")?"Error":"Warning")); 93 myError.setMessage(fldMessage.getField("msgtext")); 94 return myError; 95 } else if (!constraintData[0].searchCondition.trim().equals("")) { 96 String searchCond = constraintData[0].searchCondition.trim().toUpperCase(); 97 if (searchCond.endsWith(" IS NOT NULL")) { 98 String columnName = searchCond.substring(0, searchCond.lastIndexOf(" IS NOT NULL")).trim(); 99 columnName = Utility.messageBD(getConnection(), columnName, getLanguage()); 100 String tableName = Utility.messageBD(getConnection(), constraintData[0].tableName, getLanguage()); 101 myError = new OBError(); 102 myError.setType("Error"); 103 myError.setMessage(Utility.messageBD(getConnection(), "NotNullError", getLanguage()) + ": " + tableName + " - " + columnName); 104 return myError; 105 } else if (searchCond.endsWith(" IN ('Y','N')") || searchCond.endsWith(" IN ('Y', 'N')") || searchCond.endsWith(" IN ('N','Y')") || searchCond.endsWith(" IN ('N', 'Y')")) { 106 String columnName = searchCond.substring(0, searchCond.lastIndexOf(" IN (")).trim(); 107 columnName = Utility.messageBD(getConnection(), columnName, getLanguage()); 108 String tableName = Utility.messageBD(getConnection(), constraintData[0].tableName, getLanguage()); 109 myError = new OBError(); 110 myError.setType("Error"); 111 myError.setMessage(Utility.messageBD(getConnection(), "NotYNError", getLanguage()) + ": " + tableName + " - " + columnName); 112 return myError; 113 } 114 } 115 } 117 } 118 } 120 } 122 if (myCodeError!=null) return myCodeError; 124 else return myError; 125 } 126 } 127 | Popular Tags |