Skip to content

Commit

Permalink
Document @cds.java.this.name (#1187)
Browse files Browse the repository at this point in the history
Document the annotation `@cds.java.this.name` on the types. 

Requires cds-dk 8.2.0.
  • Loading branch information
vmikhailenko authored Sep 3, 2024
1 parent 3dc6939 commit 637b98d
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
36 changes: 35 additions & 1 deletion java/cds-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ book.put("ID", 97);
book.put("title", "Dracula");
```

You can now either define an accessor interface or use a [generated accessor interface](#generated-accessor-interfaces).
You can now either define an accessor interface or use a [generated accessor interface](#generated-accessor-interfaces).
If you define an interface yourself, it could look like the following example:

```java
Expand Down Expand Up @@ -525,6 +525,40 @@ interface Equity {
}
```

#### Renaming Types in Java

You might also want to rename the type of the entity. For this you can use annotation `@cds.java.this.name` to specify alternative name for the accessor interfaces and [static model](./cqn-services/persistence-services#staticmodel) interfaces. This annotation can be used only on definitions and is ignored everywhere else.

See the following example:

```cds
@cds.java.this.name: 'MyJavaClass'
entity Class {
key ID: String;
}
```

```java
@CdsName("javaNames.Class")
public interface MyJavaClass extends CdsData {
String ID = "ID";

@CdsName(ID)
String id();

@CdsName(ID)
MyJavaClass id(String id);

// rest of the interface
}
```

In contrast with the annotation `@cds.java.name`, the annotation `@cds.java.this.name` does not rename projections of the annotated entity. If you want to rename chain of entities, you must annotate each of them individually.

::: warning
This feature requires version 8.2.0 of the [CDS Command Line Interface](/tools/cds-cli).
:::

#### Entity Inheritance in Java

In CDS models it is allowed to extend a definition (for example, of an entity) with one or more named [aspects](../cds/cdl#aspects). The aspect allows to define elements or annotations that are common to all extending definitions in one place.
Expand Down
2 changes: 1 addition & 1 deletion java/cqn-services/persistence-services.md
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ See [Class JdbcTemplate](https://docs.spring.io/spring-framework/docs/current/ja
The static model and accessor interfaces can be generated using the [CDS Maven Plugin](../developing-applications/building#cds-maven-plugin).

::: warning _❗ Warning_
Currently, the generator doesn't support using reserved [Java keywords](https://docs.oracle.com/javase/specs/jls/se13/html/jls-3.html#jls-3.9) as identifiers in the CDS model. Conflicting element names can be renamed in Java using the [@cds.java.name](../cds-data#renaming-elements-in-java) annotation.
Currently, the generator doesn't support using reserved [Java keywords](https://docs.oracle.com/javase/specs/jls/se13/html/jls-3.html#jls-3.9) as identifiers in the CDS model. Conflicting element names can be renamed in Java using the [@cds.java.name](../cds-data#renaming-elements-in-java) annotation. For entities, you can use [@cds.java.this.name](../cds-data#renaming-types-in-java).
:::

#### Static Model in the Query Builder
Expand Down

0 comments on commit 637b98d

Please sign in to comment.