-
Notifications
You must be signed in to change notification settings - Fork 6
Quick Intro For Developers
Some people learn visually, some auditory, some kinesthetic. Developers are visual and kinesthetic: we let the code talk.
Here is the quick introduction into ClearJS for Hibernate and MyBatis developers.
Let's say you are a Hibernate developer and you have an entity called CompanyAssociate that is backed by some company_associate database table. You need to create a CRUD application accessing the data. To simplify the case - a read-only one.
Here is what you are going to do.
First, you will annotate CompanyAssociate with a @JSClass so that ClearJS can create a matching ExtJS model:
package clear.example.entity;
import com.farata.dto2extjs.annotations.*;
import java.io.Serializable;
import javax.persistence.*;
@Entity
@Table(name="company_associate")
@JSClass
public class CompanyAssociate implements Serializable {
. . .
}
The model will be created as soon as you save the annotated entity class.
Next, you will create a Java interface and use another annotation - @JSJPJQL - to declare what data do you need to fetch from company_associate. Below, method getCompanyAssociates is annotated to return complete record set:
package clear.example.service;
import java.util.List;
import clear.example.entity.CompanyAssociate;
import clear.cdb.annotations.*;
@JSService
public interface ICompanyService {
@JSJPQL(query="SELECT a FROM CompanyAssociate a WHERE companyId=:companyId")
List<CompanyAssociate> getCompanyAssociated(Integer companyId);
}
As soon as you save the interface, ClearJS will generate the implementation. It will also register the implementing class with DirectJNgine and expose it for remote call from the Ext JS code.
In you throw in one more Java annotation - @JSGenerateSample - ClearJS will generate a sample Ext JS application:
@JSGenerateSample(arguments="1")
@JSJPQLMethod(query="SELECT a FROM CompanyAssociate a WHERE companyId=:companyId")
List<CompanyAssociate> getCompanyAssociated(Integer companyId);
This how you will build a complete ExtJS/JEE/Hibernate read-only application practically avoiding Java code!
To see it in action, use the ClearJS setup wizard to create a sample Hibernate project. In fact, ClearJS will build a complete read-write application.
OK, you are not a Hibernate person. Your data access path is MyBatis or SQL and you already have a Data Transfer Object called CompanyAssociateDTO. You need to create a CRUD application accessing the data. To simplify the case - a read-only one.
First, you will annotate CompanyAssociateDTO with a @JSClass so that ClearJS can create a matching ExtJS model.
package clear.example.dto;
import com.farata.dto2extjs.annotations.*;
import java.io.Serializable;
@JSClass
public class CompanyAssociateDTO implements Serializable {
. . .
}
Next, you will use another annotation - @JSFill - to mark the method that you will be remotely calling from the Ext JS:
package clear.example.service;
import java.util.List;
import com.farata.test.dto.CompanyAssociateDTO;
import clear.cdb.annotations.*;
@JSService
public interface ICompanyService {
@JSFill
List<CompanyAssociateDTO> getCompanyAssociates(Integer companyId);
}
As soon as you save the interface, ClearJS will generate the implementation. It will also register the implementing class with DirectJNgine and expose it for remote call from the Ext JS code.
However, unlike the scenario with the @JSGenerateSample annotation, ClearJS does not know anything about the data you are accessing. That is why you will have to modify the Java class generated by ClearJS.
To facilitate this, ClearJS generates two classes: the base service class and it's subclass. Here is the subclass that will be generated from the above interface:
package com.farata.example.service;
import java.util.List;
import com.farata.example.service.generated._CompanyService;
public class CompanyService extends _CompanyService {
@Override
public List<CompanyDTO> getCompanyAssociates(Integer companyId) {
return null;
}
}
The subclass will not be regenerated unless you delete the file so that you can safely modify it's contents.
So, you next action is to specify how you acquire the data:
package com.farata.example.service;
import java.util.List;
import com.farata.example.service.generated._CompanyService;
public class CompanyService extends _CompanyService {
@Override
public List<CompanyDTO> getCompanyAssociates(Integer companyId) {
List<CompanyDTO> companyList;
// Populate companyList
. . .
return companyList;
}
}
Clearly, it's an extra step in comparison with the Hibernate based approach and it's manual coding but now you can use MyBatis, legacy SQL or whatever code you desire.
In you throw in one more Java annotation to ICompanyService interface - @JSGenerateSample - ClearJS will generate a sample Ext JS application:
@JSGenerateSample(arguments="1")
@JSFill
List<CompanyAssociateDTO> getCompanyAssociates(Integer companyId);
This how you will build a complete ExtJS/JEE read-only application.
To see it in action, use the ClearJS setup wizard to create a sample MyBatis or sample Java project. In fact, ClearJS will build a complete read-write application.