Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Change the shema and the tableName in DataSource

    I work with smartGwt 3.0 power version

    I want to change the shema and the tableName in my Datasource (.ds.xml)

    I try this way but it's not working:

    Code:
    <DataSource serverType="sql" dataSourceVersion="1" 
    	dbName="Test KUL" ID="DIM_TREEDATASOURCE" schema="{$schema}" tableName="{$tableName}" >
    	
        <fields>
            <field name="PARENT_ID" type="text" length="140" primaryKey="true"/>
            <field name="CHILD_ID" type="text" length="140"/>
            <field name="CHILD_DESC" type="text" length="140"/>
    <!--         <field name="PARENT_MEMBER_ID" type="float"/> -->
    <!--         <field name="CHILD_MEMBER_ID" type="float"/> -->
        </fields>
        <generatedBy>SC_SNAPSHOT-2012-02-05_v8.2p/PowerEdition Deployment 2012-02-05</generatedBy>
    </DataSource>
    And in my Java code :

    Code:
    DataSource ds = new TreeDs("BO","V_UM_CONN_BU","DIM_TREEDATASOURCE");
    
    ....
    
    
    	private  class TreeDs extends DataSource {  
      
    	    public TreeDs(String schema,String table,String id) {  
    
    	    	this.setAttribute("schema", schema, true);
    	    	this.setAttribute("tableName", table, true);
    	    	this.setID(id);   	
    	    	GWT.log(getAttribute("schema"));
    	    	GWT.log(getAttribute("tableName"));
    	    	
    	        setTitleField("CHILD_DESC");  
    	       
    	        DataSourceTextField desc = new DataSourceTextField("CHILD_DESC", "Description", 128);
    	        //desc.setAttribute("tableName", table);
    	        DataSourceTextField pId = new DataSourceTextField("PARENT_ID", "Description", 128);
    	        //pId.setAttribute("tableName", table);
    	        pId.setPrimaryKey(true);
    	        DataSourceTextField cId = new DataSourceTextField("CHILD_ID", "Description", 128);
    	        //cId.setAttribute("tableName", table);
    	        
    	        
    	        //DataSourceTextField desc = new DataSourceTextField("CHILD_DESC", "Description", 128);
    	  
    	        
    	        setFields(desc,pId,cId);  
    	  
    	         
    	        
    	    }  
    
    	}
    schema and tableName are set I see in GWT log but how to get it in the XML datasource file ?

    I have also see that : DynamicDSGenerator, DataSource.fromXML(), DataSource.addDynamicDSGenerator(). I have read the javadoc, and quick guide and other forum post but I don't know how to use it.
    Is everywhere a sample or a other documentation?

    Thanks,

    #2
    I have do that :

    <operationBinding
    operationType="fetch">
    <selectClause>*</selectClause>
    <tableClause>$criteria.TABLE</tableClause>
    </operationBinding>

    But the query is :
    SELECT * FROM 'BO.V_UM_CONN_OU_HIERARCHY' WHERE ('1'='1')

    The good query is normaly: without quotes ' table '
    SELECT * FROM BO.V_UM_CONN_OU_HIERARCHY WHERE ('1'='1')

    Can I delete the quotes ' ' ?

    Please

    Thanks.

    Comment


      #3
      Your attempt to use Velocity expressions for tableName and schema won't work, you do need to use addDynamicDSGenerator(). Use forums search (or Google site search) - a few people have posted example code.

      Comment


        #4
        Can you give me link.

        I have search (on javadoc and google) and I have also see 4 posts in the forum but I don't find any sample.



        Thanks

        Comment


          #5
          I don't see how to pass the name of the table to fetch with addDynamicDSGenerator()

          Comment


            #6
            Hi, I have test dynamic datasource like in this post :
            http://forums.smartclient.com/showthread.php?t=15937&page=2

            But I have yet this javascript error from ISC_DATABINDING.js:
            unexpected end of XML source

            Code:
            [ERROR] [Test] - 01:28:43.568:XRP2:WARN:Log:SyntaxError: unexpected end of XML source
                unnamed({Obj}, "<BR>BaseServlet Global Exception<BR>\r\..."[ 4187], {Obj}) @ Test/sc/modules/ISC_DataBinding.js:297
                [c]Class.fireCallback(_1=>function (_9, _10, _11),  _2=>"rpcResponse,data,rpcRequest",  _3=>[object Array],  _4=>{Obj},  _5=>undef) @ Test/sc/modules/ISC_Core.js:324
                [c]Class.fireCallback(_1=>function (_9, _10, _11),  _2=>"rpcResponse,data,rpcRequest",  _3=>[object Array]) @ Test/sc/modules/ISC_Core.js:422
                anonymous(callback=>function (_9, _10, _11),  request=>{Obj},  response=>{Obj},  data=>"<BR>BaseServlet Global Exception<BR>\r\..."[ 4187]) @ Test/sc/modules/ISC_DataBinding.js:1326
                unnamed(function (_9, _10, _11), {Obj}, {Obj}, "<BR>BaseServlet Global Exception<BR>\r\..."[ 4187]) @ :186
                [c]RPCManager.fireReplyCallbacks(_1=>{Obj},  _2=>{Obj}) @ Test/sc/modules/ISC_DataBinding.js:1331
                [c]RPCManager.performOperationReply(_1=>{Obj},  _2=>{Obj}) @ Test/sc/modules/ISC_DataBinding.js:1325
                RPCManager._performTransactionReply(0) @ Test/sc/modules/ISC_DataBinding.js:1319
                [c]RPCManager.performTransactionReply(_1=>0,  _2=>"<BR>BaseServlet Global Exception<BR>\r\..."[ 4187],  _3=>undef) @ Test/sc/modules/ISC_DataBinding.js:1279
                anonymous(0, [object XMLHttpRequest]) @ Test/sc/modules/ISC_Core.js:61
                [c]Class.fireCallback(_1=>"isc.RPCManager.performTransactionReply(..."[ 67],  _2=>"transactionNum,results,wd",  _3=>[object Array]) @ Test/sc/modules/ISC_Core.js:324
                [c]Comm.performXmlTransactionReply(_1=>0,  _2=>[object XMLHttpRequest]) @ Test/sc/modules/ISC_Core.js:1295
                anonymous([object XMLHttpRequest]) @ Test/sc/modules/ISC_Core.js:61
                [c]Class.fireCallback(_1=>"isc.Comm.performXmlTransactionReply(0, ..."[ 56],  _2=>"xmlHttpRequest",  _3=>[object Array],  _4=>[object Proxy],  _5=>true) @ Test/sc/modules/ISC_Core.js:324
                Comm._fireXMLCallback([object XMLHttpRequest], "isc.Comm.performXmlTransactionReply(0, ..."[ 56]) @ Test/sc/modules/ISC_Core.js:1269
                unnamed([object Event]) @ Test/sc/modules/ISC_Core.js:1281
                unnamed() @
            This is my code :

            Code:
            public class CustomGenerator implements DynamicDSGenerator {
            
            	@Override
            	public DataSource getDataSource(String arg0, DSRequest arg1) {
            		DataSource ds = null;
            		
            		try {
            			ds = DataSource.fromXML(loadDataSourceDocument(arg0));
            		} catch (Exception e) {
            			e.printStackTrace();
            		}
            		
            		return ds;
            		
            	}
            	
            	//Get the datasource from xml and set the datasource's dbName
            		private Document loadDataSourceDocument( String dsName){
            			DocumentBuilderFactory fac = DocumentBuilderFactory.newInstance();
            			org.w3c.dom.Document doc = null;
            			try{
            				DocumentBuilder builder = fac.newDocumentBuilder();
            				doc = builder.parse("ds/" + dsName + ".ds.xml");
            				//doc.getDocumentElement().setAttribute("ID", dsName);
            				//doc.getDocumentElement().setAttribute("dbName", dbName);
            				
            				return doc;
            			}catch(Exception e){
            				e.printStackTrace();
            				return doc;
            			}
            		}
            
            }
            
            
            
            
            -------- 
            
            public class DSloader extends BaseServlet{
            
            	/**
            	 * 
            	 */
            	private static final long serialVersionUID = 1L;
            	private String table;
            	
            	public DSloader(String table){
            		this.table=table;
            	}
            
            	@Override
                public void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException {
                	DataSource.addDynamicDSGenerator(new CustomGenerator(), table);
                    
                }
            	@Override
                public void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException {
                	DataSource.addDynamicDSGenerator(new CustomGenerator(), table);
                }
            	
                public void processRequest(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response,String table) throws javax.servlet.ServletException, IOException {
                	DataSource.addDynamicDSGenerator(new CustomGenerator(), table);
                }
            
            
            	
            	
            	
            	
            }
            
            -----------------------------
            
            final ListGrid list2 = new ListGrid();
            		 
            		list2.setAutoFetchData(true);
            		DataSource.load("pc",new Function() {
            			
            			@Override
            			public void execute() {
            				System.out.println("### DS load complete");
            				list2.setDataSource(DataSource.get("pc"));
            				//getDS();
            				
            			}
            		}, true);
            		
            		//list2.setDataSource(DataSource.get("pc"));
            		
            		vLayout.addMember(list2);
            I have place a ZIP file in attached file.
            In this zip you will find the eclipse project (no lib cause smartPower lib)
            I have place ISC_DATABINDING.js in the root of the zip file if you want to see.

            Thanks,

            josé

            Comment


              #7
              wooops I have forgot the zip

              https://docs.google.com/open?id=0B09JQx_xvr-UOTE4OTkyZGYtNWU3NC00NzZjLThlZTItMThkMjE0MmZjYjE5

              Comment


                #8
                With another pc I have no Xml problem

                I think that is a problem with my servlet:

                Code:
                <servlet>
                        <servlet-name>Mydsloader</servlet-name>
                        <servlet-class>com.smartgwt.sample.server.dyna.DSloader</servlet-class>
                    </servlet>
                
                <servlet-mapping>
                        <servlet-name>Mydsloader</servlet-name>
                        <url-pattern>/Test/sc/DSloader/*</url-pattern>
                    </servlet-mapping>
                
                
                -------
                
                public class DSloader extends BaseServlet{
                
                	/**
                	 * 
                	 */
                	private static final long serialVersionUID = 1L;
                	private String table;
                	
                	public DSloader(String table){
                		this.table=table;
                	}
                
                	@Override
                    public void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException {
                    	DataSource.addDynamicDSGenerator(new CustomGenerator(), table);
                        
                    }
                	@Override
                    public void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException {
                    	DataSource.addDynamicDSGenerator(new CustomGenerator(), table);
                    }
                	
                	
                    public void processRequest(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response,String table) throws javax.servlet.ServletException, IOException {
                    	DataSource.addDynamicDSGenerator(new CustomGenerator(), table);
                    }
                
                
                	
                	
                	
                	
                }
                Code:
                [ERROR] [Test] - 09:25:21.918:XRP2:WARN:Log:Error:
                	'Syntax error'
                	in http://127.0.0.1:8888/Test.html?gwt.codesvr=127.0.0.1:9997
                	at line 298
                    callback(_9=>Obj, _10=>"<BR>BaseServlet Global Exception<BR>\r\n<P..."[4025], _11=>Obj)
                    [c]Class.fireCallback(_1=>callback(), _2=>"rpcResponse,data,rpcRequest", _3=>Array[3], _4=>[RPCManager ID:builtinApplication], _5=>undef) on [Class RPCManager]
                    Class.fireCallback(_1=>callback(), _2=>"rpcResponse,data,rpcRequest", _3=>Array[3], _4=>undef)
                    [c]RPCManager.__fireReplyCallback(_1=>callback(), _2=>Obj, _3=>Obj, _4=>"<BR>BaseServlet Global Exception<BR>\r\n<P..."[4025])
                    [c]RPCManager.fireReplyCallbacks(_1=>Obj, _2=>Obj)
                    [c]RPCManager.performOperationReply(_1=>Obj, _2=>Obj)
                    [c]RPCManager.$39d(_1=>0)
                    [c]RPCManager.performTransactionReply(_1=>0, _2=>"<BR>BaseServlet Global Exception<BR>\r\n<P..."[4025], _3=>undef)
                    callback(transactionNum=>0, results=>Obj, wd=>undef)
                        "isc.RPCManager.performTransactionReply(transactionNum,results,wd)"
                    ** recursed on [c]Class.fireCallback
                How to do the servlet ?

                Comment

                Working...
                X