Skip to content

Commit

Permalink
next ID refactoring, reaching perfection
Browse files Browse the repository at this point in the history
  • Loading branch information
hohwille committed Jul 12, 2024
1 parent 79e3c8c commit 333d15f
Show file tree
Hide file tree
Showing 49 changed files with 1,573 additions and 2,423 deletions.
222 changes: 111 additions & 111 deletions bean/src/main/java/io/github/mmm/entity/bean/AdvancedEntityBean.java
Original file line number Diff line number Diff line change
@@ -1,111 +1,111 @@
/* Copyright (c) The m-m-m Team, Licensed under the Apache License, Version 2.0
* http://www.apache.org/licenses/LICENSE-2.0 */
package io.github.mmm.entity.bean;

import io.github.mmm.bean.AdvancedBean;
import io.github.mmm.bean.Bean;
import io.github.mmm.bean.BeanClass;
import io.github.mmm.bean.StandardPropertyBuilders;
import io.github.mmm.bean.WritableBean;
import io.github.mmm.entity.bean.impl.EntityPropertyBuildersImpl;
import io.github.mmm.entity.id.Id;
import io.github.mmm.entity.id.LongVersionId;
import io.github.mmm.entity.property.builder.EntityPropertyBuilders;
import io.github.mmm.entity.property.id.IdProperty;
import io.github.mmm.entity.property.id.PkProperty;
import io.github.mmm.property.PropertyMetadata;

/**
* Implementation of {@link EntityBean} as simple {@link Bean}.
*
* @since 1.0.0
*/
public class AdvancedEntityBean extends AdvancedBean implements EntityBean {

/** The {@link IdProperty property} with the {@link Id primary key}. */
public final PkProperty Id;

/**
* The constructor.
*/
public AdvancedEntityBean() {

this(null, null, null);
}

/**
* The constructor.
*
* @param writable the {@link WritableBean} to wrap as {@link #isReadOnly() read-only} bean or {@code null} to create
* a mutable bean.
*/
public AdvancedEntityBean(WritableBean writable) {

this(writable, null, null);
}

/**
* The constructor.
*
* @param pkProperty the {@link #Id() ID property}.
*/
public AdvancedEntityBean(PkProperty pkProperty) {

this(null, null, pkProperty);
}

/**
* The constructor.
*
* @param type the {@link #getType() type}.
*/
public AdvancedEntityBean(BeanClass type) {

this(null, type, null);
}

/**
* The constructor.
*
* @param writable the {@link WritableBean} to wrap as {@link #isReadOnly() read-only} bean or {@code null} to create
* a mutable bean.
* @param type the {@link #getType() type}.
* @param pkProperty the {@link #Id() ID property}.
*/
private AdvancedEntityBean(WritableBean writable, BeanClass type, PkProperty pkProperty) {

super(writable, type);
if (pkProperty == null) {
if (writable == null) {
// default
Id<?> id = LongVersionId.getEmpty().withEntityType(getClass());
pkProperty = new PkProperty(id, PropertyMetadata.of(this));
} else {
pkProperty = ((AdvancedEntityBean) writable).Id;
}
} else {
assert pkProperty.getName().equals(PkProperty.NAME);
assert (writable == null);
}
this.Id = add(pkProperty);
}

@Override
public PkProperty Id() {

return this.Id;
}

@Override
protected EntityPropertyBuilders add() {

return (EntityPropertyBuilders) super.add();
}

@Override
protected StandardPropertyBuilders createPropertyBuilders() {

return new EntityPropertyBuildersImpl(this);
}

}
/* Copyright (c) The m-m-m Team, Licensed under the Apache License, Version 2.0
* http://www.apache.org/licenses/LICENSE-2.0 */
package io.github.mmm.entity.bean;

import io.github.mmm.bean.AdvancedBean;
import io.github.mmm.bean.Bean;
import io.github.mmm.bean.BeanClass;
import io.github.mmm.bean.StandardPropertyBuilders;
import io.github.mmm.bean.WritableBean;
import io.github.mmm.entity.bean.impl.EntityPropertyBuildersImpl;
import io.github.mmm.entity.id.Id;
import io.github.mmm.entity.id.RevisionedIdVersion;
import io.github.mmm.entity.property.builder.EntityPropertyBuilders;
import io.github.mmm.entity.property.id.IdProperty;
import io.github.mmm.entity.property.id.PkProperty;
import io.github.mmm.property.PropertyMetadata;

/**
* Implementation of {@link EntityBean} as simple {@link Bean}.
*
* @since 1.0.0
*/
public class AdvancedEntityBean extends AdvancedBean implements EntityBean {

/** The {@link IdProperty property} with the {@link Id primary key}. */
public final PkProperty Id;

/**
* The constructor.
*/
public AdvancedEntityBean() {

this(null, null, null);
}

/**
* The constructor.
*
* @param writable the {@link WritableBean} to wrap as {@link #isReadOnly() read-only} bean or {@code null} to create
* a mutable bean.
*/
public AdvancedEntityBean(WritableBean writable) {

this(writable, null, null);
}

/**
* The constructor.
*
* @param pkProperty the {@link #Id() ID property}.
*/
public AdvancedEntityBean(PkProperty pkProperty) {

this(null, null, pkProperty);
}

/**
* The constructor.
*
* @param type the {@link #getType() type}.
*/
public AdvancedEntityBean(BeanClass type) {

this(null, type, null);
}

/**
* The constructor.
*
* @param writable the {@link WritableBean} to wrap as {@link #isReadOnly() read-only} bean or {@code null} to create
* a mutable bean.
* @param type the {@link #getType() type}.
* @param pkProperty the {@link #Id() ID property}.
*/
private AdvancedEntityBean(WritableBean writable, BeanClass type, PkProperty pkProperty) {

super(writable, type);
if (pkProperty == null) {
if (writable == null) {
// default
Id<?> id = RevisionedIdVersion.DEFAULT.withEntityTypeGeneric(getClass());
pkProperty = new PkProperty(id, PropertyMetadata.of(this));
} else {
pkProperty = ((AdvancedEntityBean) writable).Id;
}
} else {
assert pkProperty.getName().equals(PkProperty.NAME);
assert (writable == null);
}
this.Id = add(pkProperty);
}

@Override
public PkProperty Id() {

return this.Id;
}

@Override
protected EntityPropertyBuilders add() {

return (EntityPropertyBuilders) super.add();
}

@Override
protected StandardPropertyBuilders createPropertyBuilders() {

return new EntityPropertyBuildersImpl(this);
}

}
4 changes: 2 additions & 2 deletions bean/src/main/java/io/github/mmm/entity/bean/EntityBean.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import io.github.mmm.bean.WritableBean;
import io.github.mmm.entity.Entity;
import io.github.mmm.entity.id.Id;
import io.github.mmm.entity.id.LongVersionId;
import io.github.mmm.entity.id.RevisionedIdVersion;
import io.github.mmm.entity.property.id.IdProperty;
import io.github.mmm.entity.property.id.PkProperty;

Expand Down Expand Up @@ -55,7 +55,7 @@ public interface EntityBean extends WritableBean, Entity {
*/
default PkProperty Id() {

return new PkProperty(LongVersionId.getEmpty().withEntityType(getType().getJavaClass()));
return new PkProperty(RevisionedIdVersion.DEFAULT.withEntityTypeGeneric(getType().getJavaClass()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import io.github.mmm.bean.StandardPropertyBuilders;
import io.github.mmm.entity.bean.impl.EntityPropertyBuildersImpl;
import io.github.mmm.entity.id.Id;
import io.github.mmm.entity.id.LongVersionId;
import io.github.mmm.entity.id.RevisionedIdVersion;
import io.github.mmm.entity.property.builder.EntityPropertyBuilders;
import io.github.mmm.entity.property.id.IdProperty;
import io.github.mmm.entity.property.id.PkProperty;
Expand Down Expand Up @@ -39,7 +39,8 @@ public SimpleEntityBean(PkProperty idProperty) {

super();
if (idProperty == null) {
idProperty = new PkProperty(LongVersionId.getEmpty().withEntityType(getClass()), PropertyMetadata.of(this));
idProperty = new PkProperty(RevisionedIdVersion.DEFAULT.withEntityTypeGeneric(getClass()),
PropertyMetadata.of(this));
}
this.Id = add(idProperty);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import io.github.mmm.entity.bean.EntityBean;
import io.github.mmm.entity.id.GenericId;
import io.github.mmm.entity.id.Id;
import io.github.mmm.entity.id.LongVersionId;
import io.github.mmm.entity.id.RevisionedIdVersion;
import io.github.mmm.entity.link.IdLink;
import io.github.mmm.entity.property.id.FkProperty;
import io.github.mmm.entity.property.id.FkPropertyBuilder;
Expand Down Expand Up @@ -95,7 +95,7 @@ default <E extends EntityBean> FkProperty<E> newFk(String name, Id<E> idTemplate
private <E> Id<E> safeId(Id<E> id) {

if (id == null) {
id = LongVersionId.getEmpty();
id = (Id) RevisionedIdVersion.DEFAULT;
}
AttributeReadOnly lock = getLock();
if (lock instanceof EntityBean) {
Expand Down
Loading

0 comments on commit 333d15f

Please sign in to comment.