Only allows some specific code to use JDBC to access the database.
Example of test violation (let's imagine that
DatabaseManager() is one of the allowed classes):
public class Database
{
public void allowed()
{
// This should NOT trigger a pattern test violation as this is a
// class allowed to perform JDBC access.
DatabaseManager manager = new DatabaseManager();
}
public void forbidden() throws Exception
{
InitialContext context = new InitialContext();
DataSource dataSource = (DataSource) context.lookup("data source name");
// This should trigger a pattern test violation.
Connection connection = dataSource.getConnection();
// This should trigger a pattern test violation.
PreparedStatement statement = connection.prepareStatement("some SQL");
// This should trigger a pattern test violation.
statement.execute();
}
}