Permalink
Browse files

display properties in toString() methods

  • Loading branch information...
DirkMahler committed May 15, 2017
1 parent 7d8e59c commit 695f3c9317129fe3c16c4f2545c8327701c0d334
@@ -10,6 +10,7 @@
import com.buschmais.xo.api.ValidationMode;
import lombok.*;
import lombok.Builder.Default;
/**
* Represents a XO unit, i.e. a configuration for a
@@ -22,12 +23,6 @@
@ToString
public class XOUnit {
private static final XOUnit PROTOTYPE = new XOUnit();
public static XOUnitBuilder builder() {
return PROTOTYPE.toBuilder();
}
@Getter
@Builder
@NoArgsConstructor(access = PRIVATE)
@@ -41,18 +36,21 @@ public static XOUnitBuilder builder() {
* by an {@link com.buschmais.xo.api.XOException} at startup, otherwise
* a warning.
*/
@Default
private boolean strictValidation = false;
}
/**
* The name which is used to uniquely identify the XO unit.
*/
@Default
private String name = "default";
/*
* A human readable description (optional).
*/
@Default
private String description = "The default XO unit.";
/*
@@ -80,26 +78,31 @@ public static XOUnitBuilder builder() {
/**
* The {@link com.buschmais.xo.api.ValidationMode} to use.
*/
@Default
private ValidationMode validationMode = ValidationMode.AUTO;
/**
* The {@link com.buschmais.xo.api.ConcurrencyMode} to use.
*/
@Default
private ConcurrencyMode concurrencyMode = ConcurrencyMode.SINGLETHREADED;
/**
* The {@link TransactionAttribute} to use.
*/
@Default
private TransactionAttribute defaultTransactionAttribute = TransactionAttribute.NONE;
/**
* Additional properties to be passed to the provider.
*/
@Default
private Properties properties = new Properties();
/**
* The mapping configuration.
*/
@Default
private MappingConfiguration mappingConfiguration = MappingConfiguration.builder().build();
/**
@@ -0,0 +1,40 @@
package com.buschmais.xo.impl.proxy.common.object;
import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;
import com.buschmais.xo.spi.datastore.TypeMetadataSet;
import com.buschmais.xo.spi.metadata.method.MethodMetadata;
import com.buschmais.xo.spi.metadata.method.PrimitivePropertyMethodMetadata;
import com.buschmais.xo.spi.metadata.type.TypeMetadata;
public abstract class AbstractDatastoreTypeToStringMethod<T> extends AbstractToStringMethod<T> {
@Override
protected Map<String, Object> getProperties(T datastoreType) {
SortedMap<String, Object> properties = new TreeMap<>();
for (TypeMetadata type : getTypes(datastoreType)) {
addProperties(datastoreType, type, properties);
}
return properties;
}
private void addProperties(T datastoreType, TypeMetadata type, SortedMap<String, Object> properties) {
for (MethodMetadata<?, ?> methodMetadata : type.getProperties()) {
if (methodMetadata instanceof PrimitivePropertyMethodMetadata) {
PrimitivePropertyMethodMetadata propertyMethodMetadata = (PrimitivePropertyMethodMetadata) methodMetadata;
Object value = getProperty(datastoreType, propertyMethodMetadata);
properties.put(propertyMethodMetadata.getAnnotatedMethod().getName(), value);
}
}
for (TypeMetadata superType : type.getSuperTypes()) {
addProperties(datastoreType, superType, properties);
}
}
protected abstract TypeMetadataSet<?> getTypes(T datastoreType);
protected abstract Object getProperty(T datastoreType, PrimitivePropertyMethodMetadata propertyMethodMetadata);
}
@@ -1,5 +1,7 @@
package com.buschmais.xo.impl.proxy.common.object;
import java.util.Map;
import com.buschmais.xo.api.proxy.ProxyMethod;
public abstract class AbstractToStringMethod<T> implements ProxyMethod<T> {
@@ -13,11 +15,17 @@ public Object invoke(T datastoreType, Object instance, Object[] args) {
}
stringBuffer.append(type.getSimpleName());
}
stringBuffer.append(", id=");
stringBuffer.append(getId(datastoreType));
String id = getId(datastoreType);
if (id != null) {
stringBuffer.append(", id=");
stringBuffer.append(id);
}
stringBuffer.append(getProperties(datastoreType));
return stringBuffer.toString();
}
protected abstract Map<String,Object> getProperties(T datastoreType);
protected abstract String getId(T datastoreType);
}
@@ -1,18 +1,35 @@
package com.buschmais.xo.impl.proxy.entity.object;
import java.util.Set;
import com.buschmais.xo.impl.SessionContext;
import com.buschmais.xo.impl.proxy.common.object.AbstractToStringMethod;
import com.buschmais.xo.impl.proxy.common.object.AbstractDatastoreTypeToStringMethod;
import com.buschmais.xo.spi.datastore.DatastoreEntityMetadata;
import com.buschmais.xo.spi.datastore.TypeMetadataSet;
import com.buschmais.xo.spi.metadata.method.PrimitivePropertyMethodMetadata;
import com.buschmais.xo.spi.metadata.type.EntityTypeMetadata;
public class ToStringMethod<Entity> extends AbstractToStringMethod<Entity> {
public class ToStringMethod<Entity, EntityMetadata extends DatastoreEntityMetadata<EntityDiscriminator>, EntityDiscriminator>
extends AbstractDatastoreTypeToStringMethod<Entity> {
private final SessionContext<?, Entity, ?, ?, ?, ?, ?, ?, ?> sessionContext;
private final SessionContext<?, Entity, EntityMetadata, EntityDiscriminator, ?, ?, ?, ?, ?> sessionContext;
public ToStringMethod(SessionContext<?, Entity, ?, ?, ?, ?, ?, ?, ?> sessionContext) {
public ToStringMethod(SessionContext<?, Entity, EntityMetadata, EntityDiscriminator, ?, ?, ?, ?, ?> sessionContext) {
this.sessionContext = sessionContext;
}
@Override
protected String getId(Entity datastoreType) {
return sessionContext.getDatastoreSession().getDatastoreEntityManager().getEntityId(datastoreType).toString();
}
@Override
protected Object getProperty(Entity datastoreType, PrimitivePropertyMethodMetadata propertyMethodMetadata) {
return sessionContext.getDatastoreSession().getDatastoreEntityManager().getProperty(datastoreType, propertyMethodMetadata);
}
protected TypeMetadataSet<EntityTypeMetadata<EntityMetadata>> getTypes(Entity entity) {
Set<EntityDiscriminator> discriminators = sessionContext.getDatastoreSession().getDatastoreEntityManager().getEntityDiscriminators(entity);
return sessionContext.getMetadataProvider().getTypes(discriminators);
}
}
@@ -1,15 +1,20 @@
package com.buschmais.xo.impl.proxy.query.object;
import java.util.Map;
import com.buschmais.xo.impl.proxy.common.object.AbstractToStringMethod;
import com.buschmais.xo.impl.proxy.query.RowProxyMethod;
import java.util.Map;
public class ToStringMethod extends AbstractToStringMethod<Map<String, Object>> implements RowProxyMethod {
@Override
protected String getId(Map<String, Object> datastoreType) {
return datastoreType.toString();
return null;
}
@Override
protected Map<String, Object> getProperties(Map<String, Object> datastoreType) {
return datastoreType;
}
}
@@ -1,18 +1,39 @@
package com.buschmais.xo.impl.proxy.relation.object;
import com.buschmais.xo.impl.SessionContext;
import com.buschmais.xo.impl.proxy.common.object.AbstractToStringMethod;
import com.buschmais.xo.impl.proxy.common.object.AbstractDatastoreTypeToStringMethod;
import com.buschmais.xo.spi.datastore.*;
import com.buschmais.xo.spi.metadata.method.PrimitivePropertyMethodMetadata;
public class ToStringMethod<Relation> extends AbstractToStringMethod<Relation> {
public class ToStringMethod<Entity, EntityMetadata extends DatastoreEntityMetadata<EntityDiscriminator>, EntityDiscriminator, Relation, RelationMetadata extends DatastoreRelationMetadata<RelationDiscriminator>, RelationDiscriminator>
extends AbstractDatastoreTypeToStringMethod<Relation> {
private final SessionContext<?, ?, ?, ?, ?, Relation, ?, ?, ?> sessionContext;
private final SessionContext<?, Entity, EntityMetadata, EntityDiscriminator, ?, Relation, RelationMetadata, RelationDiscriminator, ?> sessionContext;
public ToStringMethod(SessionContext<?, ?, ?, ?, ?, Relation, ?, ?, ?> sessionContext) {
public ToStringMethod(
SessionContext<?, Entity, EntityMetadata, EntityDiscriminator, ?, Relation, RelationMetadata, RelationDiscriminator, ?> sessionContext) {
this.sessionContext = sessionContext;
}
@Override
protected String getId(Relation datastoreType) {
return sessionContext.getDatastoreSession().getDatastoreRelationManager().getRelationId(datastoreType).toString();
}
@Override
protected Object getProperty(Relation datastoreType, PrimitivePropertyMethodMetadata propertyMethodMetadata) {
return sessionContext.getDatastoreSession().getDatastoreRelationManager().getProperty(datastoreType, propertyMethodMetadata);
}
@Override
protected TypeMetadataSet<?> getTypes(Relation datastoreType) {
DatastoreRelationManager<Entity, ?, Relation, RelationMetadata, RelationDiscriminator, ?> datastoreRelationManager = sessionContext
.getDatastoreSession().getDatastoreRelationManager();
DatastoreEntityManager<?, Entity, EntityMetadata, EntityDiscriminator, ?> datastoreEntityManager = sessionContext.getDatastoreSession()
.getDatastoreEntityManager();
Entity from = datastoreRelationManager.getFrom(datastoreType);
Entity to = datastoreRelationManager.getTo(datastoreType);
return sessionContext.getMetadataProvider().getRelationTypes(datastoreEntityManager.getEntityDiscriminators(from),
datastoreRelationManager.getRelationDiscriminator(datastoreType), datastoreEntityManager.getEntityDiscriminators(to));
}
}

0 comments on commit 695f3c9

Please sign in to comment.