FastQuery: a framework for fast data operations

FastQuery: a framework for fast data operations

FastQuery fast operation data layer framework

FastQuery is based on Java language. Its mission is to simplify the Java operation data layer. As a developer, you only need to design and write the DAO interface, which is dynamically generated and implemented by ASM internally, and executes quickly. Therefore, the code is concise and elegant, thus greatly improving development efficiency.

The main features of FastQuery are as follows:

  1. Elegant design, simple configuration, easy to use.
  2. ASM is used to dynamically generate bytecodes, so preprocessing before compilation is supported, which can minimize errors during runtime and significantly improve the robustness of the program.
  3. Supports secure query to prevent SQL injection.
  4. Support integration with mainstream connection pool frameworks, such as c3p0, dbcp, etc.
  5. Support @Query query, use @Condition to implement dynamic where condition query.
  6. The query result set supports JSON type
  7. Support AOP, injection interception only requires a few simple annotations, such as: @Before, @After

Operating environment requirements

JDK 1.8+

Configuration Files

jdbc-config.xml

Used to configure support for jdbc. Note: If a connection pool is used, this configuration file can be omitted.

  1. <? xml   version = "1.0"   encoding = "UTF-8" ?>  
  2. < jdbc-config >     
  3.          <!-- Configure *** data sources -->  
  4.          < named-config   name = "xk_db" >     
  5.          < property   name = "driverClass" > com.mysql.jdbc.Driver </ property >     
  6.          < property   name = "url" > jdbc:mysql://192.168.1.1:3306/xk? user = xk & password = abc123 </ property >  
  7.          </ named-config >  
  8.  
  9.          <!-- Configure the second data source -->  
  10.          < named-config   name = "shtest_db" >     
  11.          < property   name = "driverClass" > com.mysql.jdbc.Driver </ property >    <!-- jdbc driver -->  
  12.          < property   name = "databaseName" > dbname </ property >    <!-- Name of the database -->  
  13.          < property   name = "user" > username </ property >    <!-- Database User Name -->  
  14.          < property   name = "password" > userpasswd </ property >    <!-- Password of the database user -->    
  15.          < property   name = "portNumber" > 3306 </ property >     <!-- Port -->  
  16.          < property   name = "serverName" > 192.168.1.1 </ property >   <!-- Database host address -->  
  17.      </ named-config >  
  18. </ jdbc-config >  

c3p0-config.xml

Support c3p0 configuration, please refer to the c3p0 official website for detailed configuration: http://www.mchange.com/projects/c3p0/ .

  1. <? xml   version = "1.0"   encoding = "UTF-8" ?>  
  2. < c3p0-config >     
  3. <!--
  4.      < default-config >     
  5.          < property   name = "driverClass" > com.mysql.jdbc.Driver </ property >     
  6.          < property   name = "jdbcUrl" > jdbc:mysql://... </ property >  
  7.          < property   name = "user" > root </ property >     
  8.          < property   name = "password" > 123*** </ property >     
  9.          < property   name = "initialPoolSize" > 10 </ property >     
  10.          < property   name = "maxIdleTime" > 30 </ property >     
  11.          < property   name = "maxPoolSize" > 20 </ property >     
  12.          < property   name = "minPoolSize" > 5 </ property >     
  13.          < property   name = "maxStatements" > 200 </ property >     
  14.      </ default-config >    
  15. -- >      
  16.      < named-config   name = "xk-c3p0" >     
  17.          < property   name = "driverClass" > com.mysql.jdbc.Driver </ property >     
  18.          < property   name = "jdbcUrl" > jdbc:mysql://192.168.1.1:3306/xk </ property >     
  19.          < property   name = "user" > xk </ property >     
  20.          < property   name = "password" > abc123 </ property >     
  21.          < property   name = "acquireIncrement" > 50 </ property >     
  22.          < property   name = "initialPoolSize" > 100 </ property >     
  23.          < property   name = "minPoolSize" > 50 </ property >     
  24.          < property   name = "maxPoolSize" > 1000 </ property >  
  25.          < property   name = "maxStatements" > 0 </ property >     
  26.          < property   name = "maxStatementsPerConnection" > 5 </ property >        
  27.          </ named-config >    
  28. </c3p0-config>  

fastquery.json

Configure the scope of the data source

  1. // @author xixifeng ([email protected])
  2. // Configuration must follow standard json syntax.
  3. [
  4. // The optional values ​​currently supported by config are "jdbc", "c3p0"
  5. {
  6. "config": "c3p0", // indicates that c3p0 is responsible for providing the data source
  7. "dataSourceName": "xk-c3p0", // data source name
  8. "basePackages": [ // The scope of this data source
  9. "org.fastquery.example.StudentDBService"
  10. ]
  11. },
  12.  
  13. /*
  14. Configure another data source scope
  15. */
  16. {
  17. "config" : "jdbc", // indicates that the jdbc driver is responsible for providing the data source
  18. "dataSourceName": "shtest_db",
  19. "basePackages": [ // The scope of this data source
  20. "org.fastquery.example.DataAcquireDbService"
  21. ]
  22. }
  23. ]

A complete introductory example

  • Prepare an entity
  1. public class Student
  2. {
  3. private String no;
  4. private String name;
  5. private String sex;
  6. private Integer age;
  7. private String dept;
  8. // getter /setter omitted...
  9. }
  • DAO Interface
  1. public interface StudentDBService extends QueryRepository {
  2. @Query("select * from student")
  3. JSONArray findAll();
  4. @Query("select * from student")
  5. Student[] find();
  6. }
  • Use DAO interface.
  1. StudentDBService studentDBService = FQuery .getRepository(StudentDBService.class);
  2. JSONArray jsonArray = studentDBService .findAll();
  3. Student[] students = studentDBService .find();

<<:  Implementing image recognition in Web development based on Google Vision API and Ionic

>>:  Creating JavaScript modules with Babel and ES7

Recommend

The wolf in the tech world is coming and why it hasn’t come yet

The media always want to make a big news, and the...

The fabric as thin as a cicada's wing is actually a "silencer"!

Produced by: Science Popularization China Author:...

What are the reasons for the poor results of Baidu’s bidding promotion?

Customers often visit the official website to inq...

37 truths about marketing promotion

Marketing is a major writing topic for my officia...

Science cover: 20 years later, the Human Genome Project is finally complete

This Friday, the latest issue of Science magazine...

You are afraid of snakes, so what are snakes afraid of?

The zodiac lady opens the microphone: "You&#...

Bobo's weekly private domain case class

Bobo's weekly private domain case course reso...

How to plan a marketing campaign that reaches 1 million people

When I first learned about the event, I actually ...

How to create a hit title with over 100,000 views? Just master these 5 points!

Let’s take you to re-examine the meaning of title...

What is Wancibaping? How much does Wancibaping generally charge?

Wancibaping is a technology that uses Internet cl...

Stanford: 2018 Artificial Intelligence Index Report

The AI ​​Index, initiated by Stanford University,...