Skip to content

Commit a0561dd

Browse files
committed
Added transient as alternate for @ignore
1 parent c5a3acb commit a0561dd

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

README.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Include the Maven artifact:
2727
<dependency>
2828
<groupId>com.github.collinalpert</groupId>
2929
<artifactId>java2db</artifactId>
30-
<version>6.0.0</version>
30+
<version>6.0.1</version>
3131
</dependency>
3232
```
3333

@@ -103,8 +103,10 @@ public class Person extends BaseEntity {
103103
```
104104

105105
Every POJO *must* extend `BaseEntity` and have an empty or default constructor.\
106-
The class `BaseEntity` overrides the `equals` and `hashCode` methods using the `id`. Override them in your entity classes if you need different behavior.\
107-
If you want to have a field in your POJO that should be ignored by Java2DB, you can apply the `Ignore` attribute to the specific field.
106+
The class `BaseEntity` overrides the `equals` and `hashCode` methods using the `id`. Override them in your entity
107+
classes if you need different behavior.\
108+
If you want to have a field in your POJO that should be ignored by Java2DB, you can apply the `Ignore` attribute or
109+
the `transient` modifier to the specific field.
108110

109111
Then we can go ahead and create the service classes:
110112

@@ -144,7 +146,7 @@ the [Asynchronous operations](#asynchronous-operations) section.
144146
#### Read
145147

146148
The `BaseService` provides a `createQuery` method which allows you to manually build a query and then execute it with
147-
the `toList`, `toStream`, `toArray` or `toMap` methods. You should only need this approach seldomly.\
149+
the `toList`, `toStream`, `toArray` or `toMap` methods. You should only need this approach seldom.\
148150
Much rather, use the `getSingle` or `getMultiple` methods. `getMultiple` returns an `EntityQuery` object with a
149151
preconfigured WHERE condition and then allows you to chain some additional query options. As of the
150152
current `EntityQuery` version, WHERE, LIMIT, ORDER BY and GROUP BY are supported. Effectively, the
@@ -231,7 +233,11 @@ You can also check if a table has at least one row by calling `personService.any
231233
To check if a column's values are unique in a table, use the `hasDuplicates` method provided by the `BaseService`. It will return `true` if there is at least one duplicate value and false if all the values are unique.
232234

233235
### Programmability
234-
The `DBConnection` class offers the possibility to call a stored procedure and a function. Simply use the `callStoredProcedure` or `callFunction` method, respectively and pass in the class you would like the result mapped to. Using the `@Ignore` annotation will also work with these kinds of calls. Please make sure your class has an empty constructor.
236+
237+
The `DBConnection` class offers the possibility to call a stored procedure and a function. Simply use
238+
the `callStoredProcedure` or `callFunction` method, respectively and pass in the class you would like the result mapped
239+
to. Using the `@Ignore` annotation or the `transient` modifier will also work with these kinds of calls. Please make
240+
sure your class has an empty constructor.
235241

236242
### Asynchronous operations
237243

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.github.collinalpert</groupId>
88
<artifactId>java2db</artifactId>
9-
<version>6.0.0</version>
9+
<version>6.0.1</version>
1010
<packaging>jar</packaging>
1111

1212
<name>Java2DB</name>

src/main/java/com/github/collinalpert/java2db/modules/FieldModule.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import com.github.collinalpert.java2db.entities.BaseEntity;
66
import com.github.collinalpert.java2db.utilities.Utilities;
77

8-
import java.lang.reflect.Field;
8+
import java.lang.reflect.*;
99
import java.util.*;
1010
import java.util.stream.Collectors;
1111

@@ -57,7 +57,7 @@ private <E extends BaseEntity> List<Field> getEntityFields(Class<? super E> inst
5757
var fields = new LinkedList<Field>();
5858
do {
5959
Arrays.stream(instanceClass.getDeclaredFields())
60-
.filter(field -> field.getAnnotation(Ignore.class) == null && (includeForeignKeys || field.getAnnotation(ForeignKeyEntity.class) == null))
60+
.filter(field -> field.getAnnotation(Ignore.class) == null && !Modifier.isTransient(field.getModifiers()) && (includeForeignKeys || field.getAnnotation(ForeignKeyEntity.class) == null))
6161
.forEach(fields::add);
6262
instanceClass = instanceClass.getSuperclass();
6363
} while (instanceClass != delimiter);
@@ -118,7 +118,7 @@ private List<TableColumnReference> getColumnReferences(Class<? extends BaseEntit
118118
public List<Field> getAllFields(Class<?> clazz) {
119119
var list = new LinkedList<Field>();
120120
do {
121-
Arrays.stream(clazz.getDeclaredFields()).filter(x -> x.getAnnotation(Ignore.class) == null).forEach(list::add);
121+
Arrays.stream(clazz.getDeclaredFields()).filter(x -> x.getAnnotation(Ignore.class) == null && !Modifier.isTransient(x.getModifiers())).forEach(list::add);
122122
clazz = clazz.getSuperclass();
123123
} while (clazz != Object.class);
124124

0 commit comments

Comments
 (0)