package me.chyxion.tigon.mybatis;

import org.w3c.dom.Document;
import org.w3c.dom.Element;

/**
 * @author Shaun Chyxion <br>
 * chyxion@163.com <br>
 * Feb 22, 2017 11:13:26
 */
public class PrimaryKeyXmlProcessor extends AbstractOnMissingCreateProcessor {

    /**
     * {@inheritDoc}
     */
    @Override
    protected String missingXPathExpression() {
        return "/mapper/sql[@id='primaryKey']";
    }

    /**
     * {@inheritDoc}
     */
    @Override
    protected Element elementToAppend(Class<BaseMapper<?, ?>> mapperClass, Document doc) {
        Element primaryKeyEl = doc.createElement("sql");
        primaryKeyEl.setAttribute("id", "primaryKey");
        primaryKeyEl.setTextContent(newModelObj(getModelClass(mapperClass)).primaryKeyName());
        return primaryKeyEl;
    }
}
