Rule Definition
This rules permits to verify that only a specific set of classes are making access to the database and not all the application. Usually DAO classes are used to make access to the database.
Remediation
Review the architecture of the application to move all classes that reference the database in a specific layer usually called data layer.
Violation Code Sample
import java.sql.Connection; import java.sql.SQLException; import java.sql.Statement; import java.util.function.Predicate; public class ClassUsingDB_KO { private Connection connection; boolean avoidSubqueries() { Predicate<String> sql = x -> { try { Statement statement = connection.createStatement(); statement.executeQuery( "select a.AU_FNAME from AUTHORS a where a.AU_ID in (select t.AU_ID from TITLEAUTHOR t)"); } catch (SQLException e) { e.printStackTrace(); } return true; }; return sql.test("xx"); } }
Reference
http://best-practice-software-engineering.ifs.tuwien.ac.at/patterns/dao.html https://www.oracle.com/java/technologies/dataaccessobject.html
Related Technologies
JEE
Technical Criterion
Architecture - Multi-Layers and Data Access
About CAST Appmarq
CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.