package cn.web.init;

import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import cn.orm.util.metadata.DBMetaData;
import cn.util.core.LogKit;

@Component
@Order(2)
@Configuration
public class MetaDataRunner implements ApplicationRunner 
{
	@Value("${sam.dbName}")
	private String dbName;
	
	@Override
	public void run(ApplicationArguments args) throws Exception
	{
		long start = System.currentTimeMillis();
		initTableMeta();
		LogKit.info(String.format("获取表元数据总耗时：%s 毫秒",System.currentTimeMillis() - start));
	}
	
	@Autowired
	private DataSource ds;
	
	private void initTableMeta() 
	{
		try {
			DBMetaData.initTables(ds,dbName);
		} catch (Exception e) {
			LogKit.info("获取表元数据： "+ e.getMessage()); 
		}
	}
}
