package com.lxyer.config;

import com.jfinal.kit.PathKit;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.lxyer.model.*;

import java.io.File;

/**
 * Generated by JFinal, do not modify this file.
 * <pre>
 * Example:
 * public void configPlugin(Plugins me) {
 *     ActiveRecordPlugin arp = new ActiveRecordPlugin(...);
 *     DbMap.mapping(arp);
 *     me.add(arp);
 * }
 * </pre>
 */
public class DbMap {
	
	public static void mapping(ActiveRecordPlugin arp) {
		arp.addMapping("act_log", "logid", ActLog.class);
		arp.addMapping("comment", "commentId", Comment.class);
		arp.addMapping("content", "contentId", Content.class);
		arp.addMapping("content_item", "itemId", ContentItem.class);
		// Composite Primary Key order: tid,cate,attr
		arp.addMapping("dyna_attr", "tid,cate,attr", DynaAttr.class);
		arp.addMapping("user", "userId", User.class);
	}

    public static void addSqlTemplate(ActiveRecordPlugin arp) {
        String baseSqlTemplatePath = PathKit.getWebRootPath() + "/WEB-INF/classes/sql/";
        arp.setBaseSqlTemplatePath(baseSqlTemplatePath);

        File sqlFiles = new File(baseSqlTemplatePath);
        File[] files = sqlFiles.listFiles();
        for (File f : files){
            if (f.isFile() ||  f.getName().endsWith(".sql")){
                arp.addSqlTemplate(f.getName());
            }
        }
    }
}

