All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.javers.core.metamodel.clazz.EntityDefinitionBuilder Maven / Gradle / Ivy

There is a newer version: 7.6.2
Show newest version
package org.javers.core.metamodel.clazz;

import org.javers.common.collections.Arrays;
import org.javers.common.validation.Validate;

import java.util.ArrayList;
import java.util.List;

import static java.util.Collections.*;

/**
 * Fluent builder for {@link EntityDefinition},
 * allows to set all optional attributes:
 * Id-properties, ignoredProperties and typeAlias, for example:
 * 
 * EntityDefinitionBuilder.entityDefinition(Person.class)
 *    .withIdPropertyName("firstName")
 *    .withIdPropertyName("lastName")
 *    .withIgnoredProperties(ignoredProperties)
 *    .withTypeName("typeName")
 *    .build();
 *
* * @since 1.4 * @author bartosz.walacik */ public class EntityDefinitionBuilder extends ClientsClassDefinitionBuilder{ private List idPropertyNames = new ArrayList<>(); private boolean shallowReference; EntityDefinitionBuilder(Class entity) { super(entity); } public static EntityDefinitionBuilder entityDefinition(Class entity) { return new EntityDefinitionBuilder(entity); } public EntityDefinitionBuilder withIdPropertyName(String idPropertyName) { Validate.argumentIsNotNull(idPropertyName); if (!idPropertyNames.contains(idPropertyName)) { idPropertyNames.add(idPropertyName); } return this; } public EntityDefinitionBuilder withIdPropertyNames(String... idPropertyNames) { Validate.argumentIsNotNull(idPropertyNames); return withIdPropertyNames((List) Arrays.asList(idPropertyNames)); } public EntityDefinitionBuilder withIdPropertyNames(List idPropertyNames) { Validate.argumentIsNotNull(idPropertyNames); idPropertyNames.forEach(this::withIdPropertyName); return this; } public EntityDefinitionBuilder withShallowReference(){ this.shallowReference = true; return this; } @Override public EntityDefinition build() { return new EntityDefinition(this); } List getIdPropertyNames() { return idPropertyNames; } boolean isShallowReference() { return shallowReference; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy