You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/site/markdown/docs/codingStandards.md
+17-21Lines changed: 17 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,36 +6,32 @@ This library is coded in the pseudo-functional style that has become possible wi
6
6
these general principles for functional style coding in Java:
7
7
8
8
- Immutability is the core concept of functional programming
9
-
- Use private constructors for most classes
10
-
- Use a static "of" method as a builder method if there are one or two attributes. If there are two attributes,
11
-
they may not be of the same type. A Builder class is preferred with two attributes, but "of" may be used to make
12
-
the code more compact or readable in some cases.
13
-
- Generally use a static Builder class if more than one attribute is required to initialize a class
14
-
- Builders only have a zero argument constructor. All attributes set with "with" methods.
15
-
- When using a Builder, private class constructors take the Builder as the only argument
16
-
- Class constructors using a Builder should check for null if an attribute is required.
17
-
- Avoid direct use of null. Any Class attribute that could be null in normal use should be wrapped in a
18
-
java.util.Optional
19
-
- In Builders, Lists should be initialized and then populated with add or addAll. Classes
20
-
may directly reference the list in the builder.
21
-
- In Builders, Maps should be initialized and then populated with put or putAll. Classes
22
-
may directly reference the map in the builder.
23
-
- Builders may be mutable, other classes may not be mutable.
24
-
- Classes never expose a modifiable List. Lists are exposed with an unmodifiable List, or a Stream.
25
-
- Classes never expose a modifiable Map. A Map may be exposed with an unmodifiable Map.
9
+
- Use private constructors for most classes
10
+
- Use a static "of" method as a builder method if there are one or two attributes. If there are two attributes, they may not be of the same type. A Builder class is preferred with two attributes, but "of" may be used to make the code more compact or readable in some cases.
11
+
- Generally use a static Builder class if more than one attribute is required to initialize a class
12
+
- Builders only have a zero argument constructor. All attributes set with "with" methods.
13
+
- When using a Builder, private class constructors take the Builder as the only argument
14
+
- Class constructors using a Builder should check for null if an attribute is required.
15
+
- In Builders, Lists should be initialized and then populated with `add` or `addAll`. Classes may directly reference the list in the builder.
16
+
- In Builders, Maps should be initialized and then populated with `put` or `putAll`. Classes may directly reference the map in the builder.
17
+
- Builders may be mutable, other classes may not be mutable.
18
+
- No setters
19
+
- Classes never expose a modifiable List. Lists are exposed with an unmodifiable List, or a Stream.
20
+
- Classes never expose a modifiable Map. A Map may be exposed with an unmodifiable Map.
21
+
- Avoid direct use of null. Any Class attribute that could be null in normal use should be wrapped in a `java.util.Optional`
26
22
- Avoid for loops (imperative) - use map/filter/reduce/collect (declarative) instead
27
23
- Avoid Stream.forEach() - this method is only used for side effects, and we want no side-effects
28
-
-The only good function is a pure function
29
-
-Classes with no internal attributes are usually a collection of utility functions. Use static methods in an
30
-
interface instead.
24
+
-Avoid Optional.ifPresent() - this method is only used for side effects, and we want no side-effects
25
+
-The only good function is a pure function. Some functions in the library accept an AtomicInteger which is a necessary evil
26
+
- Classes with no internal attributes are usually a collection of utility functions. Use static methods in an interface instead.
31
27
- Remember the single responsibility principle - methods do one thing, classes have one responsibility
32
28
33
29
## Clean Code
34
30
35
31
We are committed to clean code. This means:
36
32
37
33
- Small methods - less than 5 lines is good, 1 line is ideal
38
-
- Small classes - less than 50 lines is good, less than 20 lines is ideal
34
+
- Small classes - less than 100 lines is good, less than 50 lines is ideal
39
35
- Use descriptive names
40
36
- Comments are a last resort - don't comment bad code, refactor it
41
37
- No nested control structures - ideal cyclomatic complexity of a function is 1
Copy file name to clipboardExpand all lines: src/site/markdown/docs/extending.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,8 +9,8 @@ The SELECT support is the most complex part of the library, and also the part of
9
9
10
10
| Interface | Purpose|
11
11
|-----------|--------|
12
-
| org.mybatis.dynamic.sql.BasicColumn | Use this interface if you want to add capabilities to a SELECT list or a GROUP BY expression. For example, creating a calculated column. |
13
-
| org.mybatis.dynamic.sql.BindableColumn | Use this interface if you want to add capabilities to a WHERE clause. For example, creating a custom condition. |
12
+
|`org.mybatis.dynamic.sql.BasicColumn`| Use this interface if you want to add capabilities to a SELECT list or a GROUP BY expression. For example, creating a calculated column. |
13
+
|`org.mybatis.dynamic.sql.BindableColumn`| Use this interface if you want to add capabilities to a WHERE clause. For example, creating a custom condition. |
Copy file name to clipboardExpand all lines: src/site/markdown/docs/howItWorks.md
+3-6Lines changed: 3 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -84,12 +84,9 @@ is designed to be the one single parameter for a MyBatis mapper method.
84
84
## What About SQL Injection?
85
85
86
86
It is true that mappers written this way are open to SQL injection. But this is also true of using any of the
87
-
various SQL provider classes in MyBatis (@SelectProvider, etc.) So you must be careful that these types of mappers
88
-
are not exposed to any general user input.
87
+
various SQL provider classes in MyBatis (`@SelectProvider`, etc.) So you must be careful that these types of mappers are not exposed to any general user input.
89
88
90
-
If you follow these practices, you will make the SQL injection possibility less obvious:
89
+
If you follow these practices, you will lower the risk of SQL injection:
91
90
92
91
1. Always use MyBatis annotated mappers
93
-
2. Use the SqlProviderAdapter utility class in conjunction with the MyBatis provider annotations (@InsertProvider, @SelectProvider, etc.)
94
-
95
-
This is, admittedly, only security through obscurity.
92
+
2. Use the `SqlProviderAdapter` utility class in conjunction with the MyBatis provider annotations (`@InsertProvider`, `@SelectProvider`, etc.)
0 commit comments