Skip to content

Commit 00dff1b

Browse files
committedApr 29, 2020
Expanded docs
Signed-off-by: Gerolmed <[email protected]>
1 parent cf5cd41 commit 00dff1b

File tree

5 files changed

+97
-2
lines changed

5 files changed

+97
-2
lines changed
 

‎.idea/jarRepositories.xml

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@ Adapter to allow using and switching different backends in Java without a proble
44

55
**Features:**
66
- Easy setup and usage
7-
- Easy query building that translates into all supported datbases.
7+
- Easy query building that translates into all supported databases.
88
- Automatic java object <-> database entity conversion
99
- Support to define serializers for existing classes like java.util.Date
10+
11+
RealmDrive **supports abstract classes/interfaces** (sub classes must be registered).
12+
[More about sub classes here](./docs/sub-class.md)
1013

1114
Currently supported database systems:
1215
- MongoDB

‎docs/sub-class.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
Realm Drive allows defining sub and abstract classes.
2+
3+
> **Note** this only works, if the object was saved with RealmDrive.
4+
5+
#### Example:
6+
7+
> Removed getter/setter/noargs constructor/allargs constructor for simplicity
8+
9+
**Model classes**
10+
```java
11+
import net.endrealm.realmdrive.annotations.SaveAll;
12+
13+
@SaveAll
14+
public class MyObject {
15+
private DynamicInput input;
16+
}
17+
18+
/**
19+
* This could also be a normal/abstract class
20+
*/
21+
public interface DynamicInput {
22+
String getAddress();
23+
}
24+
25+
@SaveAll
26+
public class Input1 implements DynamicInput {
27+
private String street;
28+
private int houseNr;
29+
30+
public String getAddress() {
31+
return street + " " + houseNr;
32+
}
33+
}
34+
35+
@SaveAll
36+
public class Input2 implements DynamicInput {
37+
private double longitude;
38+
private double latitude;
39+
40+
public String getAddress() {
41+
return someLatLongToAddressCode(this);
42+
}
43+
}
44+
```
45+
46+
**Usage example**
47+
```java
48+
public class Main {
49+
public static void main(String[] args) {
50+
DriveService service = ...; // Get your service
51+
52+
// Register classes
53+
service.getConversionHandler()
54+
.registerClasses(MyObject.class, Input1.class, Input2.class);
55+
56+
// Create example objects
57+
MyObject obj1 = new MyObject(new Input1("adams-street", 14));
58+
MyObject obj2 = new MyObject(new Input2(12.2, 12.2));
59+
60+
service.getWriter().write(obj1);
61+
service.getWriter().write(obj2);
62+
63+
Query query = new Query().build(); // select all
64+
List<MyObject> all = service.getReader().readAll(query, GreatEntity.class);
65+
66+
assert all.get(0).equals(obj1);
67+
assert all.get(1).equals(obj2);
68+
}
69+
}
70+
```

‎docs/usage.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ Realm Drive can automatically find a constructor matching the type/super type of
5454

5555
Examples can be found [here](./inject-parent.md)
5656

57+
**Find out how powerful sub classes can be with RealmDrive [here](sub-class.md)
58+
5759
#### Marking fields
5860
Read more about it [here](./annotations.md)
5961
#### Register classes

‎pom.xml

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

55
<artifactId>realm-drive</artifactId>
66
<groupId>net.endrealm</groupId>
7-
<version>1.3.0-SNAPSHOT</version>
7+
<version>1.3.1-RELEASE</version>
88
<name>Realm Drive</name>
99
<description>
1010
A database adapter allowing to switch different databases without requiring users to change their code.

0 commit comments

Comments
 (0)
Please sign in to comment.