00001 /* 00002 * XRequestCommandInsert.java 00003 * 00004 * Created on June 8, 2005, 12:22 PM 00005 * Created by Detro - 566/2145 00006 */ 00007 00008 package org.jaebi.server.service; 00009 00010 import org.jaebi.server.service.exception.BackEndHandlerGenericException; 00011 import org.jaebi.server.service.exception.BackEndHandlerSQLCreationException; 00012 import org.jaebi.server.service.exception.CommandExecException; 00013 import org.jaebi.server.service.exception.XRequestCommandInitException; 00014 import org.jaebi.server.service.xml.exception.JAXBXResponseFactoryBuildingException; 00015 import org.jaebi.server.service.xml.xrequest.Xrequest; 00016 00023 public class XRequestCommandInsert extends XRequestCommand { 00024 00026 public XRequestCommandInsert(Xrequest xrequestObj, BackEndHandlerImpl backEndHandler) 00027 throws XRequestCommandInitException { 00028 00029 super(xrequestObj, backEndHandler); 00030 00031 /* Controlla se la Factory ha costruito 00032 * l'XRequestCommand con l'Xrequest corretto */ 00033 if ( !xrequestObj.getType().equalsIgnoreCase("insert") ) { 00034 throw new XRequestCommandInitException( 00035 exceptionPrefix + "Xrequest Type does not match"); 00036 } 00037 } 00038 00044 public Object execute() 00045 throws CommandExecException { 00046 00047 try { 00048 backEndHandler.insert( getAffectedTable() , getColumnsValue() ); 00049 } catch ( BackEndHandlerGenericException e) { 00050 // Errore nel BackEnd 00051 try { 00052 return xresponseFactory.buildXresponse(false, 00053 "BackEnd Error - " + e.getMessage() ); 00054 } catch ( JAXBXResponseFactoryBuildingException otherE ) { 00055 throw new CommandExecException( exceptionPrefix + otherE ); 00056 } 00057 } catch ( BackEndHandlerSQLCreationException sqle) { 00058 // Errore nel BackEndHandler durante la creazione dell'SQL 00059 try { 00060 return xresponseFactory.buildXresponse(false, 00061 "Error in Submitted Data - " + sqle.getMessage() ); 00062 } catch ( JAXBXResponseFactoryBuildingException otherE ) { 00063 throw new CommandExecException( exceptionPrefix + otherE ); 00064 } 00065 } 00066 00067 // Inserimento riuscito 00068 try { 00069 return xresponseFactory.buildXresponse(true, "INSERT #1 ROW" ); 00070 } catch ( JAXBXResponseFactoryBuildingException otherE ) { 00071 throw new CommandExecException( exceptionPrefix + otherE ); 00072 } 00073 } 00074 }