Announcement

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

    How to do a simple sql select?

    Hello,

    I am new to smartgwt and just evaluate the framework. I have big problems with datasource. I use jpa2 and want to try it with smartgwt. I created the .ds.xml file and do a

    DataSource userDS = DataSource.get("user_DataSource");

    But how can I do a simple

    UserObject = select * from user where userid = 1

    as an example. Your showcase shows how to bind to components but this I dont need here.

    It must be simple I guess (hope) but couldnt find a sample. Can I use NamedQuery from my entity object?

    Thx for any advice
    Hans

    #2
    Is there any hidden documentation

    Hi,

    I dont know, I couldnt find any usable documentation. The quickstart is short and only links to javadoc. Is there any description for the *.ds.xml file or and xsd for that?

    Do I need to buy a license to get usable documentation?

    Actually I use Vaadin but I thought the components are better and the way how to use it. However I found its incedible heavy to dig in. Are there maybe some documentation which is hidden? Or links to samples beside the distribution

    Thx,
    Hans

    Comment


      #3
      Hi Hans,

      .ds.xml concepts are also in the docs. See http://www.smartclient.com/smartgwte...e-summary.html

      For your query try a Clientside FETCH-DSRequest with an equals-Criteria. You'll need a .ds.xml file before.

      Best regards,
      Blama

      Comment


        #4
        To expand on what Blama's post, it goes like this:

        1) First you must have a defined DataSource Descriptor file. The DataSource file is the essence of Smart GWT persistence. It's a key differentiator of the framework. Consider not using JPA.

        - The naming convention is *.ds.xml, e.g., myData.ds.xml.

        - The location is .../war/ds/

        - You can create your own with the console called via SC.openDataSourceGenerator(). (Checkout com.smartgwt.client.util.SC, lots of good stuff in there for getting started).

        - A DataSource file roughly corresponds to a SQL table, but it can be extended far beyond that.

        For this example, let's assume we are using the "employees.ds.xml" DataSource in the supplied "builtinds" sample project.

        2) Your page has to load the DataSource.
        a) You can load it from the html page, as shown in the sample BuiltInDS.html file:
        Code:
            <!--load the datasources-->
            <script src="BuiltInDS/sc/DataSourceLoader?dataSource=supplyItem,animals,employees"></script>
        b) Or you can also load it from your Java code using the DataSource.load() method. I prefer this way, because it gives me conditional control, e.g., if (user authenticated) {DataSource.load(..., etc. But it's overkill for this explanation.

        3) From your Java code, declare the DataSource and use it:
        Code:
        DataSource ds_Employees = DataSource.getDataSource("employees"); //Note: Drop the .ds.xml
        	
        Criteria criteria = new Criteria();
        criteria.addCriteria("EmployeeId", 1);
        
        ds_Employees.fetchData(criteria, new DSCallback() {
         @Override
         public void execute(DSResponse dsResponse, Object data, DSRequest dsRequest) {
        
          // This is your Asynchronous response right here...
        
          Record[] theFetchReturnedTheseRecords = dsResponse.getData();
        
          String employeeName = theFetchReturnedTheseRecords[0].getAttribute("Name");
        
          SC.say("Name Retrieved was " + employeeName);
        
          }
        });
        Of course, in most cases (of mine anyway), you would be attaching the DataSource to a Visual Component (widget). This provides a HUGE amount of automatic behavior. E.g., you don't have to parse the returned records to populate a table, it's all automatic.
        Code:
        ListGrid listGrid = new ListGrid();
        listGrid.setDataSource(ds_Employee);
        		
        listGrid.fetchData(criteria);
        I hope this is helpful to you.
        Last edited by DevMo; 23 Jun 2014, 14:36. Reason: update project name in html load statement

        Comment


          #5
          Thx !

          Thx to Blama and especially DevMo! Unfortunately I had to skip my evaluation of SmartGWT. I hope I can start again and I will use your descriptions.

          Thanks,
          Hans

          Comment

          Working...
          X