Skip to content

Commit

Permalink
support Integer for Id
Browse files Browse the repository at this point in the history
  • Loading branch information
hohwille committed Jan 4, 2024
1 parent 6bc6c8a commit 24f746f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
17 changes: 11 additions & 6 deletions core/src/main/java/io/github/mmm/entity/id/GenericIdFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,20 @@ private GenericIdFactory() {
public <E> GenericId<E, Object, Comparable<?>> create(Class<E> entityType, Object id, Comparable<?> revision) {

GenericId result;
if (revision instanceof Integer i) {
revision = Long.valueOf(i.longValue());
}
if (id == null) {
assert (revision == null);
return null;
} else if (id instanceof Long) {
result = LongId.of((Long) id, entityType, revision);
} else if (id instanceof UUID) {
result = UuidId.of((UUID) id, entityType, revision);
} else if (id instanceof String) {
result = StringId.of((String) id, entityType, revision);
} else if (id instanceof Long l) {
result = LongId.of(l, entityType, revision);
} else if (id instanceof UUID uuid) {
result = UuidId.of(uuid, entityType, revision);
} else if (id instanceof String string) {
result = StringId.of(string, entityType, revision);
} else if (id instanceof Integer i) {
result = LongId.of(Long.valueOf(i.longValue()), entityType, revision);
} else {
throw new IllegalStateException("Unsupported ID type: " + id.getClass().getName());
}
Expand Down
7 changes: 5 additions & 2 deletions core/src/main/java/io/github/mmm/entity/id/Id.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,15 @@
*/
public interface Id<E> extends Supplier<Object> {

/** Name of the {@link #get() id} property. */
/** Marshalling property name of the {@link #get() id}. */
String PROPERTY_ID = "id";

/** Name of the {@link #getRevision() revision} property. */
/** Marshalling property name of the {@link #getRevision() revision}. */
String PROPERTY_REVISION = "rev";

/** Column name of the {@link #getRevision() revision}. */
String COLUMN_REVISION = "Rev";

/**
* The value used as {@link #getRevision() revision} if it unspecified. If you are using an {@link Id} as link to an
* {@link Entity} you will use this value to point to the recent revision of the {@link io.github.mmm.entity.Entity}.
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/io/github/mmm/entity/id/PkMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ private static class PkMapperRevision extends PkMapper {

private PkMapperRevision(GenericId idTemplate) {

super(idTemplate, "Rev", null);
super(idTemplate, Id.COLUMN_REVISION, null);
}

@Override
Expand Down

0 comments on commit 24f746f

Please sign in to comment.