package org.nutz.dao.impl.sql.pojo;

import org.nutz.dao.FieldMatcher;
import org.nutz.dao.entity.Entity;
import org.nutz.dao.entity.MappingField;
import org.nutz.dao.sql.Pojo;
import org.nutz.dao.sql.PItem;
import org.nutz.dao.sql.SqlType;

public abstract class AbstractPItem implements PItem {

    protected Pojo pojo;

    public Pojo getPojo() {
        return pojo;
    }

    public void setPojo(Pojo pojo) {
        this.pojo = pojo;
        this.setupPojo(pojo);
    }

    protected SqlType getSqlType() {
        return pojo.getSqlType();
    }

    protected FieldMatcher getFieldMatcher() {
        return pojo.getContext().getFieldMatcher();
    }

    protected void setupPojo(Pojo pojo) {}

    protected Entity<?> _en(Entity<?> en) {
        if (null == en && null != pojo)
            return pojo.getEntity();
        return en;
    }

    protected String _fmtcolnm(Entity<?> en, String name) {
        if (null == en && null != pojo)
            en = pojo.getEntity();

        if (null != en) {
            MappingField mf = en.getField(name);
            if (null != mf)
                return mf.getColumnName();
        }
        return name;
    }

}

@@ -165,19 +165,20 @@
 ao.sql.P
-ojo
+Item
 ;%0Aimport
@@ -188,36 +188,35 @@
 g.nutz.dao.sql.P
-Item
+ojo
 ;%0Aimport org.nut
@@ -1159,16 +1159,48 @@
 urn name
+.replaceAll(%22%5B%5E0-9a-zA-Z_%5D%22, %22%22)
 ;%0A    %7D%0A

Fix issue #527