me.icymint.libra.sage.spring.SageContext Maven / Gradle / Ivy
package me.icymint.libra.sage.spring;
import java.sql.SQLException;
import java.util.Map;
import me.icymint.libra.sage.model.SqlFactory;
import me.icymint.libra.sage.model.operator.SQLExistsException;
/**
* 该对象用于初始化Sage包的所有SQL工厂。
*
* <bean id="abc" class="me.icymint.sage.spring.SageContext"
* init-method="init">
* <property name="needToBeInitiallized" value="true"/>
* <property name="factory">
* <map>
* <entry key="abc">
* <ref bean="xx" />
* </entry>
* </map>
* </property>
* </bean>
*
* @author Daniel
* @datetime 2013-1-23下午2:01:59
*
*/
public class SageContext {
private boolean needToBeInitiallized;
public SageContext() {
this(false);
}
public SageContext(boolean needToBeInitiallized) {
this.needToBeInitiallized = needToBeInitiallized;
// System.out.println("1");
}
public void init() throws SQLException {
if (this.needToBeInitiallized) {
for (String key : SqlFactory.fetchAllRegistedNames()) {
SqlFactory sf = SqlFactory.fetchByRegistedName(key);
sf.getDatabase().rebuild();
}
this.setNeedToBeInitiallized(false);
}
// System.out.println("4");
}
public boolean isNeedToBeInitiallized() {
return needToBeInitiallized;
}
public void setFactory(Map map)
throws SQLExistsException {
for (String key : map.keySet()) {
SqlFactory.registerFactory(map.get(key), key);
}
// System.out.println("3");
}
public void setNeedToBeInitiallized(boolean needToBeInitiallized) {
this.needToBeInitiallized = needToBeInitiallized;
// System.out.println("2");
}
}