
package org.lilyproject.repository.api;

import java.util.HashMap;
import java.util.Map;

/**
 * Thrown when trying to create or update a field type or record type with a QName which is already used by another field type or record type.
 */
public class ConcurrentUpdateTypeException extends TypeException {
    private String type;

    public ConcurrentUpdateTypeException(String message, Map<String, String> state) {
        this.type = state.get("type");
    }

    @Override
    public Map<String, String> getState() {
        Map<String, String> state = new HashMap<String, String>();
        state.put("type", type);
        return state;
    }

    public ConcurrentUpdateTypeException(String typeName) {
        this.type = typeName;
    }

    @Override
    public String getMessage() {
        StringBuilder message = new StringBuilder();
        message.append("Concurrent create or update occurred for field or record type '").append(type).append("'");
        return message.toString();
    }
}
