Personal Summary of the Java Web considerations
1, prohibit in the loop, the operation of the database operations. The reason is that the operational database is time-consuming to open and shut down memory
For example: try to avoid the following actions in the programFor
(Object o:entitys) {
Save (o);
update (o);
Delete (o);
//
}
2, in the program appears HQL or SQL statement, as far as possible to filter the data more than the conditions first place
3, at the beginning of the design data, use frequent data as far as possible redundant fields. Avoid connecting tables when querying, consuming data query time.
For example: the relationship between people and departments; a person has multiple departments, a department has more than one person, and everyone has a default department
4. In the Java program Hql/sql, try not to call system functions in the where bar or select. The
following conditions:
<strong> StringBuilder sbud = new StringBuilder ("SELECT DISTINCT tps.project_id ID from t_project_ Stage TPs "); Sbud.append ("INNER join t_stage ts on ts.id = tps.stage_id where "); Sbud.append (" tps.last_modified is not null and tps.last_modified-1<to_date ('%2$s ', ' Yyyy-mm-dd ')");// Sbud.append ("and Tps.last_modified < to_date ('%3$s ', ' yyyy-mm-dd ') +1 and tps.overdue=0 GROUP by TPS.PROJECT_ID has MAX (ts.order_no) =%1$s) tt2 on Tt.id =tt2.id "); Sbud.append ("and to_date ('%3$s ', ' yyyy-mm-dd ') < <span style=" color: #ff0000; " >ADD_MONTHS</span> (tps.last_modified, 2) +1 and tps.overdue=0 and ts.order_no=%1$s) tt2 on Tt.id =tt2.id " ); Builder.append (String.Format (sbud.tostring (), witchstage,firstday,firstday));</strong>
Redundant fields are recommended if the amount of data is large.
5, if more than one place in the program using HQL query or local SQL query more than one table, you can use SQL stored procedures, SQL view, unified interface, to increase the reusability of code. Note: you can create an entity class for a view
The
above views: purely personal views, if there are errors, please the Great God guidance!
1
Java Web Project Optimization