繼承關系
OrderEntryServiceImpl extends AbstractBase implements OrderEntryService
AbstractBase implements AdapterConfig :內部獲取Aapter,調用各種方法。
interface Adapter
SiebelAdapter implements Adapter
具體請看:
SiebelAdapter.java —適配器實現類
聯動 ExceptionWithCode, JDBFactory
public class SiebelAdapter<Z extends BaseModel> implements Adapter<Z>{public static final Logger logger = LoggerFactory.getLogger(SiebelAdapter.class);protected AdapterConfig<Z> config;public AdapterConfig<Z> getConfig(){return config;}public void setConfig( AdapterConfig<Z> config){this.config = config;}//1;獲取適配器配置public Z getConfigByModel(Z model){return fillProperties(getConfig(),model);}public Z fillProperties(AdapterConfig<Z> adapter, Z model){if(StringUtils.isBlank(model.getBusinessComponeseName())){ model.setBusinessComponeseName(adapter.getBCName())}//BC,BO,IC,IO,PBC一樣,我就不寫了.基本就是在各個實現類中 重寫AdapterConfig接口的方法.return model;}//2:getMappingfinal private Map<String ,String> getMapping(){Map<String ,String> mapping = new LinkedHashMap<>();if(mapping.isEmpty() ){Map<String ,String> map = getConfig().getRawMapping();if( map != null ){map.put("Id","rowId");map.put("Created","createTime");map.put("Created By","creatorId");mapping.putAll(map);}}return mapping;}//3,4 getExpress/getOrExpress 條件拼接。public final String getExpress (List<String> exprList){StringBuffer expr = new String Buffer();for(String e : exprList){if( expr.length() > 0 ) expr.append(" and ");expr.append(e);}return expr.toString();}public final String getOrExpress (List<String> exprList){StringBuffer expr = new String Buffer();for(String e : exprList){if( expr.length() > 0 ) expr.append(" or");expr.append(e);}return expr.toString();}//5通過查詢 取得數據的列表public List<Z> getList(Z model) throws Exception{return getList( model, getConfig().getListExpress(model) );}public List<Z> getListByBs(Z model) throws Exception{return getListByBs( model,getConfig().getListExpress(model) );}//--通過查詢 取得數據的列表public List<Z> getList(Z model,String expr) throws Exception{Z modelconfig = getConfigByModel(model);//得到具體有Bo,BC,IC,IO配置的模型if(StringUtils.isBlank(modelconfig.getBOName())){ throw new ExceptionWithCode("0010");} --BO未指定if(StringUtils.isBlank(modelconfig.getBCName())){ throw new ExceptionWithCode("0011");}--BC未指定/從這里可以看出來,在具體的實現類中必須 重寫BO,BC方法,指明其名字,否則將報錯。List<Z> retlist = new LinkedList<Z>();//獲取siebel--數據對象SiebelDataBean sdb = JDBFactory.getSiebelDataBean();
try{ getConfigInfo(sdb);//獲取siebel--BO對象SiebelBusObject busObject = sdb.getBusObject(modelconfig.getBusinessObjectNameI());//獲取siebel--BC對象,及其父BC對象
try{ SiebelBusComp busComp = busObject.getBusComp(modelconfig.getBusinessComponeseName());
try{ SiebelBusComp pc = busComp.parentBusComp();//激活BC字段activateField( getFieldOpt(busComp),model );if(expr != null && expr.length() > 0){//條件表達式,傳進來的busComp.clearToQuery();busComp.setSearchExpr(expr); }logger.info(String.format("ViewMode : [%s] ,BO : [%s], BC : [%s], SearchExpr : {%s}",model.getViewType(),modelconfig.getBOName(),modelconfig.getBCName(),expr) );//BC設置排序配置 if(StringUtils.isNotNullOrEmptyStr(getConfig().getSortSpec(model))){ busComp.setSortSpec( getConfig().getSortSpec(model) );}busComp.setViewModel( model.getViewType);//bc設置視圖busComp.executeQuery2(false,false);//執行查詢?//busComp.executeQuery(true);int count = 0;//啥意思?媽的,查列表 都這么復雜的嗎?if( busComp.firstRecord() ){Z m = convert(model.getFieldOpt(busComp));count++;m.setPageRowNo(count);retlist.add(m);while(busComp.nextRecord()){retlist.add(convert(model,getFieldOpt(busComp)));}}return retlist;}finally{busComp.release();}//首先釋放BC}finally{busObject.release();}//再次釋放BO}finally{JDBFactory.freeSiebelDataBean(sdb);}//最后釋放Siebel數據模型
}
//**6**.getListByBS 通過BS 獲取列表
public List<Z> getListByBs(Z model ,String expr) throws Exception{Z modelconfig = getConfigByModel(model);//得到具體有Bo,BC,IC,IO配置的模型if(StringUtils.isBlank(modelconfig.getBOName())){ throw new ExceptionWithCode("0010");}if(StringUtils.isBlank(modelconfig.getBCName())){ throw new ExceptionWithCode("0011");}//1:獲取siebel--數據對象SiebelDataBean sdb = JDBFactory.getSiebelDataBean();try{getConfigInfo(sdb);//2:創建輸入,出Siebel屬性集合SiebelPropertySet inpPS = sdb.newPropertySet(); SiebelPropertySet outPS = sdb.newPropertySet(); SiebelService oBS = sdb.getService("SHYY Upload Attachment Service Test");//3:給輸入Siebel集合設值inpPS .setProperty("BusObject",modelconfig.getBOName()); //給集合設值inpPS .setProperty("BusComp",modelconfig.getBCName()); inpPS .setProperty("ViewMode",String.format(%d"",model.getViewType())); if(expr != null && expr.legnth() > 0 ){ inpPS.setProperty("SearchExpr",expr); }if(StringUtils.isNotNullOrEmptyStr(getConfig().getSortSpec())){inpPS.setProperty("SortSpec",getConfig().getSortSpec());} //4:創建輸入Siebel參數集合SiebelPropertySet inpPS_PARAMS = sdb.newPropertySet();//5:得到實現類中的參數映射Map<String ,String > map = getMapping();for(String key : map){inpPS_PARAMS .setProperty(key,key); //把實現類中的key(BC字段),作為參數.}inpPS.addChild(inpPS_PARAMS ); //子BC?//控制臺打印日志:logger.info(String.format("ViewMode : [%s] ,BO : [%s], BC : [%s], SearchExpr : {%s}",model.getViewType(),modelconfig.getBOName(),modelconfig.getBCName(),expr) );//調用BS方法oBS.invokeMethod("Action",inpPS,outPS);List<Z> retlist = new LinkedList<>();for( int i = 0; i < outPS.getChildCount(); i++){SiebelPropertySet childPS = outPS.getChild(i);//得到每一個子屬性集合Z m = convert(model,childPS);String rowId = m.getRowId();boolean found = false;for(Z z : retlist){if(rowId.equals(z.getRowId())){found = true;break;}} if(!fount){retlist.add(m);}return retlist; }finally{JDBFactory.freeSiebelDateBean(sdb);}}
}
//**7**添加數據
public void add(Z model) throws Exception{addAndGetRowId(model);
}
public String addAndGetRowId(Z model) throws Exception{//1:得到具體有Bo,BC,IC,IO配置的模型Z modelconfig = getConfigByModel(model);if(StringUtils.isBlank(modelconfig.getBOName())){ throw new ExceptionWithCode("0010");}if(StringUtils.isBlank(modelconfig.getBCName())){ throw new ExceptionWithCode("0011");}//2:獲取siebel--數據對象SiebelDataBean sdb = JDBFactory.getSiebelDataBean();try{ getConfigInfo(sdb);//3:獲取siebel--BO對象SiebelBusObject busObj = sdb.getBusObject(modelconfig.getBusinessObjectName());try{Map<String, String > map = getConfig().getParentList(model);if(map != null ){for(String bcName : map.KeySet()){String rowId = map.get(bcName);if(StringUtils.isNotNullOrEmptyStr(rowId)){SiebelBusComp parentbusComp = busObject.getBusComp(bcname);parentbusComp.setViewMode(3);parentbusComp.setSearchExpr("[Id] = '"+rowId+"'");parentbusComp.executeQuery2(true,true);if( !parentbusComp.firstRecord()){throw new Exception("父BC中,查不到相關記錄")}}}}SiebelBusComp busComp = busObject.getBusComp(modelconfig.getBusinessComponeseName());try{if(model.isAdminModel()){busComp.invokeMethod("SetAdminMode",new String[] {"TRUE"});logger.info("SetAdminMode TRUE");}activateField(getFieldOpt(busComp),model);busComp.setViewMode(model.getViewMode());busComp.setSearchExpr("1<>1");busComp.executeQuery2(true,true);busComp.newRecord(true);setFieldValue(busComp,getFieldOpt(busComp),model);busComp.writeRecord();logger.info(String.format(
"ViewMode: [%s], BO :[%s] , BC : [%s] ,[Id] : %s ",model.getViewType(),modelconfig.getBOName(),modelconfig.getBCNaem(),
busComp.getFieldValue("Id")));String id = busComp.getFieldValue("Id");model.setRowId(id);return id;
}finally{if(model.isAdminMode()){busComp.invokeMethod("SetAdminMode",new String[] {"FALSE"});logger.info("SetAdminMode false");}busComp.release();}
}finally{busObject.release();
}
}finally{JDBFactory.freeSiebelDataBean();
}
//還有批量添加.
//**8** 批量添加
public List<String> batAddAndGetRowIds(List<Z> list) throws Exception{if( list == null || list.isEmpty() ) throws new Exception("沒有數據需要添加");if(StringUtils.isBlank(modelconfig.getBOName())){ throw new ExceptionWithCode("0010");}if(StringUtils.isBlank(modelconfig.getBCName())){ throw new ExceptionWithCode("0011");}//1:獲取siebel--數據對象SiebelDataBean sdb = JDBFactory.getSiebelDataBean();try{getConfigInfo(sdb);//3:獲取siebel--BO對象SiebelBusObject busObj = sdb.getBusObject(modelconfig.getBusinessObjectName());try{Map<String, String > map = getConfig().getParentList( list.get(0) );if(map != null ){for(String bcName : map.KeySet()){String rowId = map.get(bcName);if(StringUtils.isNotNullOrEmptyStr(rowId)){SiebelBusComp parentbusComp = busObject.getBusComp(bcname);parentbusComp.setViewMode(3);parentbusComp.setSearchExpr("[Id] = '"+rowId+"'");parentbusComp.executeQuery2(true,true);if( !parentbusComp.firstRecord()){throw new Exception("父BC中,查不到相關記錄")}}}}
SiebelBusComp busComp = busObject.getBusComp(modelconfig.getBusinessComponeseName());activateField(getFieldOpt(busComp),list.get(0));busComp.setViewMode(model.getViewMode());busComp.setSearchExpr("1<>1");busComp.executeQuery2(true,true);List<String> retlist = new LinkedList<>();for(Z model : retlist){busComp.newRecord(true);setFieldValue( busComp,getFieldOpt(busComp ),model );busComp.writeRecord();String id = busComp.getFieldValue("id");model.setRowId(id);retlist.add(id);}
logger.info(String.format(
"ViewMode: [%s], BO :[%s] , BC : [%s] ,[Id] : %s ",model.getViewType(),modelconfig.getBOName(),modelconfig.getBCNaem(),
busComp.getFieldValue("Id")));
return retlist;
}finally{busComp.release();}
}finally{busObject.release();}
}finally{JDBFactory.freeSiebelDataBean(sdb);}
}
//**9** 更新數據
public void update(Z model) throws Exception{if( StringUtils.isBlank( model.getRowId()) ){throw new Exception("未指定對應的RowId ,操作無法繼續");}//1:得到具體有Bo,BC,IC,IO配置的模型Z modelconfig = getConfigByModel(model);if(StringUtils.isBlank(modelconfig.getBOName())){ throw new ExceptionWithCode("0010");}if(StringUtils.isBlank(modelconfig.getBCName())){ throw new ExceptionWithCode("0011");}//2:獲取siebel--數據對象SiebelDataBean sdb = JDBFactory.getSiebelDataBean();try{ getConfigInfo(sdb);//3:獲取siebel--BO對象SiebelBusObject busObj = sdb.getBusObject(modelconfig.getBusinessObjectName());try{Map<String, String > map = getConfig().getParentList(model);if(map != null ){for(String bcName : map.KeySet()){String rowId = map.get(bcName);if(StringUtils.isNotNullOrEmptyStr(rowId)){SiebelBusComp parentbusComp = busObject.getBusComp(bcname);parentbusComp.setViewMode(3);parentbusComp.setSearchExpr("[Id] = '"+rowId+"'");parentbusComp.executeQuery2(true,true);if( !parentbusComp.firstRecord()){throw new Exception("父BC中,查不到相關記錄")}}}}SiebelBusComp busComp = busObject.getBusComp(modelconfig.getBusinessComponeseName());try{if(model.isAdminModel()){busComp.invokeMethod("SetAdminMode",new String[] {"TRUE"});logger.info("SetAdminMode TRUE");}activateField(getFieldOpt(busComp),model);busComp.setViewMode(model.getViewMode());busComp.cleatToQuery();logger.info(String.format(
"ViewMode: [%s], BO :[%s] , BC : [%s] ,[Id] : %s ",model.getViewType(),modelconfig.getBOName(),modelconfig.getBCNaem(),
busComp.getFieldValue("Id")));busComp.setSearchSpec( "Id",model.getRowId() );busComp.executeQuery2(true,true);if( busComp.firstRecord() ){setFieldValue(busComp,getFiledOpt(busComp), model);busComp.writeRecord();return;}throw new Exception("記錄沒有找到");}finally{if(model.isAdminModel()){busComp.invokeMethod("SetAdminMode",new String[] {"TRUE"});logger.info("SetAdminMode TRUE");}busComp.release();}finally{busObject.release();}}finally{JDBFactory.freeSiebelDataBean(sdb);}}
//增刪改查基本都是這樣,批量的情況下把model 換成list.get(0)
}//轉換參數 String[] ------ String :{"a","b","c"}---a,b,c
private static final String convert(String[] param ){
if(param ==null){ return "";}
StringBuffer sb = new StringBuffer();for(String p : param){if( sb.length()>0 ) sb.append(',');sb.append(p);}
return sb.toString();
}
//還有好多,太他媽多了,日樂購了。
final private void activateField(SiebelBusComp pickBusComp,MVGBaseModel model ) throws Exception{Map<String ,String > map = model.getMapping();for(String key : map.keySet()){if(StringUtils.isBlank(key)) continue;pickBusComp.activateField(key);}
}
//設置全局變量:就是新建一個map 放一個自定義變量進去,在放入參數
public Map<String,String> profileAttrs(List<String> attrList) throws Exception{SiebelDataBean sdb = JDBFactory.getSiebelDataBean();//這里有日志打印,校驗siebel連接的try{getConfigInfo(sdb);//這里有日志打印,---設置用戶信息到CurrentConfigModel的。Map<String,String> retmap = new LinkedHashMap<String,String>();for(String key : attrList){retMap.put(key,sdb.getProfileAttr(key));//Siebel那邊的方法}logger.info(String.format("profileAttrs:[%s]",retmap.toString()));return retmap; }finally{JDBFactory.freeSiebelDataBean();}
}
public void profileSetAttrs( Map<String,String> attrList )throws Exception{SiebelDataBean sdb = JDBFactory.getSiebelDataBean();//這里有日志打印,校驗siebel連接的try{getConfigInfo(sdb);//這里有日志打印,---設置用戶信息到CurrentConfigModel的。Map<String,String> retmap = new LinkedHashMap<String,String>();for(String key : attrList){sdb.setProfileAttr(key,attrList.get(key));logger.info(String.format("profileAttrs:[%s = %s]",key,attrList.get(key)));}}finally{JDBFactory.freeSiebelDataBean();}}
//忘記了一個很重要的方法,這個可以解釋為什么CurrentConfigModel 有值。就是登錄接口中的。
private static final void getConfigInfo(SiebelDataBean sdb){CurrentConfigModel = null ;try{config = SystemUtils.getCurrentConfigModel(); //這一步不要忘記了,同步副本信息。這樣可以拿到同一個。不然//副本中的還是空的。下面就可以 設值了。}catch(Exception e){e.printStackTrace();}if( config == null ) return ; //其實第一次登錄這個絕對是空的。if( sdb.positionId().equals(config.getPositionId()) ) return;//把siebel數據模型的數據 設置到CurrentConfigModel中。但是我不明白,為什么sdb中有值?、config.setPositionId(sdb.positionId());config.setPositinName(sdb.positionName());config.setLoginId(sdb.loginId());config.setLoginName(sdb.loginName()); try{config.setOrganizationLoc(sdb.getProfileAttr("Organization Loc")); }catch(SiebelException e){e.printStackTrace();}logger.info(String.format("用戶配置信息被設置!"));
}}//類尾
總結
以上是生活随笔為你收集整理的SiebelAdapter--具体干事的类,的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。