Skip to content

Commit 8de721a

Browse files
committed
@NameInDb replaces attribute in @Property and @entity
1 parent be4a669 commit 8de721a

4 files changed

Lines changed: 29 additions & 44 deletions

File tree

objectbox-java-api/src/main/java/io/objectbox/annotation/Entity.java

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,8 @@
1313
@Target(ElementType.TYPE)
1414
public @interface Entity {
1515

16-
/**
17-
* Specifies the name on the DB side (e.g. table name) this entity maps to.
18-
* By default, the name is based on the entities class name.
19-
* <p>
20-
* Note: if you intent to rename an entity, consider using uid instead.
21-
*/
22-
String nameInDb() default "";
23-
16+
// Maybe better than "createInDb":
17+
// Class partialFor" to create a partial class referencing the class to the full entity
2418
// /**
2519
// * Advanced flag to disable table creation in the database (when set to false). This can be used to create partial
2620
// * entities, which may use only a sub set of properties. Be aware however that ObjectBox does not sync multiple
@@ -33,22 +27,12 @@
3327
// * Entities which belong to different schemas should <strong>not</strong> have relations.
3428
// */
3529
// String schema() default "default";
36-
//
30+
3731
// /**
38-
// * Whether update/delete/refresh methods should be generated.
39-
// * If entity has defined {@link Relation}, then it is active independently from this value
32+
// * Whether an all properties constructor should be generated.
4033
// */
41-
// boolean active() default false;
42-
//
43-
/**
44-
* Whether an all properties constructor should be generated. A no-args constructor is always required.
45-
*/
46-
boolean generateConstructors() default true;
34+
// boolean generateConstructors() default true;
4735

48-
/**
49-
* Whether getters and setters for properties should be generated if missing.
50-
*/
51-
boolean generateGettersSetters() default false;
5236
//
5337
// /**
5438
// * Define a protobuf class of this entity to create an additional, special DAO for.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package io.objectbox.annotation;
2+
3+
import java.lang.annotation.ElementType;
4+
import java.lang.annotation.Retention;
5+
import java.lang.annotation.RetentionPolicy;
6+
import java.lang.annotation.Target;
7+
8+
/**
9+
* Allows to specify a simple name mapping for entities and properties.
10+
* If names have diverged on the Java side (vs. the DB), you can specify the name used in the database here.
11+
* This allows simple renames in Java. For more advanced renames you should consider @{@link Uid} instead.
12+
*/
13+
@Retention(RetentionPolicy.CLASS)
14+
@Target({ElementType.FIELD, ElementType.TYPE})
15+
public @interface NameInDb {
16+
/**
17+
* Name used in the database.
18+
*/
19+
String value();
20+
21+
}

objectbox-java-api/src/main/java/io/objectbox/annotation/Property.java

Lines changed: 0 additions & 22 deletions
This file was deleted.

tests/objectbox-java-test/src/main/java/io/objectbox/relation/Order.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@
55
import io.objectbox.annotation.Entity;
66
import io.objectbox.annotation.Generated;
77
import io.objectbox.annotation.Id;
8+
import io.objectbox.annotation.NameInDb;
89
import io.objectbox.annotation.Relation;
910
import io.objectbox.annotation.apihint.Internal;
1011
import io.objectbox.exception.DbDetachedException;
1112

1213
/**
1314
* Entity mapped to table "ORDERS".
1415
*/
15-
@Entity(nameInDb = "ORDERS")
16+
@Entity
17+
@NameInDb("ORDERS")
1618
public class Order {
1719

1820
@Id(assignable = true)

0 commit comments

Comments
 (0)