Search in sources :

Example 1 with DalConfigHost

use of com.ctrip.platform.dal.daogen.host.DalConfigHost in project dal by ctripcorp.

the class AbstractJavaDataPreparer method addDatabaseSet.

protected void addDatabaseSet(CodeGenContext codeGenCtx, String databaseSetName) throws SQLException {
    DaoOfDatabaseSet daoOfDatabaseSet = BeanGetter.getDaoOfDatabaseSet();
    List<DatabaseSet> sets = daoOfDatabaseSet.getAllDatabaseSetByName(databaseSetName);
    if (null == sets || sets.isEmpty()) {
        return;
    }
    JavaCodeGenContext ctx = (JavaCodeGenContext) codeGenCtx;
    ContextHost contextHost = ctx.getContextHost();
    DalConfigHost dalConfigHost = ctx.getDalConfigHost();
    dalConfigHost.addDatabaseSet(sets);
    for (DatabaseSet databaseSet : sets) {
        List<DatabaseSetEntry> entries = daoOfDatabaseSet.getAllDatabaseSetEntryByDbsetid(databaseSet.getId());
        if (entries == null || entries.isEmpty()) {
            continue;
        }
        dalConfigHost.addDatabaseSetEntry(entries);
        Map<String, DatabaseSetEntry> map = dalConfigHost.getDatabaseSetEntryMap();
        for (DatabaseSetEntry entry : entries) {
            String key = entry.getConnectionString();
            if (map.containsKey(key)) {
                DatabaseSetEntry value = map.get(key);
                Resource resource = new Resource(value.getConnectionString(), value.getUserName(), value.getPassword(), value.getDbAddress(), value.getDbPort(), value.getDbCatalog(), value.getProviderName());
                contextHost.addResource(resource);
            }
        }
    }
}
Also used : DaoOfDatabaseSet(com.ctrip.platform.dal.daogen.dao.DaoOfDatabaseSet) DaoOfDatabaseSet(com.ctrip.platform.dal.daogen.dao.DaoOfDatabaseSet) DalConfigHost(com.ctrip.platform.dal.daogen.host.DalConfigHost) JavaCodeGenContext(com.ctrip.platform.dal.daogen.generator.java.JavaCodeGenContext)

Example 2 with DalConfigHost

use of com.ctrip.platform.dal.daogen.host.DalConfigHost in project dal by ctripcorp.

the class JavaCodeGenContextCreator method process.

@Override
public void process(CodeGenContext context) throws Exception {
    try {
        JavaCodeGenContext ctx = (JavaCodeGenContext) context;
        Project project = BeanGetter.getDaoOfProject().getProjectByID(ctx.getProjectId());
        DalConfigHost dalConfigHost = null;
        if (project.getDal_config_name() != null && !project.getDal_config_name().isEmpty()) {
            dalConfigHost = new DalConfigHost(project.getDal_config_name());
        } else if (project.getNamespace() != null && !project.getNamespace().isEmpty()) {
            dalConfigHost = new DalConfigHost(project.getNamespace());
        } else {
            dalConfigHost = new DalConfigHost("");
        }
        ctx.setDalConfigHost(dalConfigHost);
        ctx.setNamespace(project.getNamespace());
    } catch (Throwable e) {
        LoggerManager.getInstance().error(e);
        throw e;
    }
}
Also used : Project(com.ctrip.platform.dal.daogen.entity.Project) DalConfigHost(com.ctrip.platform.dal.daogen.host.DalConfigHost) JavaCodeGenContext(com.ctrip.platform.dal.daogen.generator.java.JavaCodeGenContext)

Example 3 with DalConfigHost

use of com.ctrip.platform.dal.daogen.host.DalConfigHost in project dal by ctripcorp.

the class AbstractCSharpDataPreparer method addDatabaseSet.

protected void addDatabaseSet(CodeGenContext codeGenCtx, String databaseSetName) throws SQLException {
    CSharpCodeGenContext ctx = (CSharpCodeGenContext) codeGenCtx;
    List<DatabaseSet> sets = daoOfDatabaseSet.getAllDatabaseSetByName(databaseSetName);
    if (null == sets || sets.isEmpty())
        return;
    DalConfigHost dalConfigHost = ctx.getDalConfigHost();
    dalConfigHost.addDatabaseSet(sets);
    for (DatabaseSet databaseSet : sets) {
        List<DatabaseSetEntry> entries = daoOfDatabaseSet.getAllDatabaseSetEntryByDbsetid(databaseSet.getId());
        if (null == entries || entries.isEmpty())
            continue;
        dalConfigHost.addDatabaseSetEntry(entries);
    }
}
Also used : DaoOfDatabaseSet(com.ctrip.platform.dal.daogen.dao.DaoOfDatabaseSet) DatabaseSet(com.ctrip.platform.dal.daogen.entity.DatabaseSet) CSharpCodeGenContext(com.ctrip.platform.dal.daogen.generator.csharp.CSharpCodeGenContext) DalConfigHost(com.ctrip.platform.dal.daogen.host.DalConfigHost) DatabaseSetEntry(com.ctrip.platform.dal.daogen.entity.DatabaseSetEntry)

Example 4 with DalConfigHost

use of com.ctrip.platform.dal.daogen.host.DalConfigHost in project dal by ctripcorp.

the class JavaDalGenerator method createContext.

@Override
public CodeGenContext createContext(int projectId, boolean regenerate, Progress progress, boolean newPojo, boolean ignoreApproveStatus) throws Exception {
    JavaCodeGenContext ctx = null;
    try {
        ctx = new JavaCodeGenContext(projectId, regenerate, progress);
        Project project = BeanGetter.getDaoOfProject().getProjectByID(projectId);
        DalConfigHost dalConfigHost = null;
        if (project.getDal_config_name() != null && !project.getDal_config_name().isEmpty()) {
            dalConfigHost = new DalConfigHost(project.getDal_config_name());
        } else if (project.getNamespace() != null && !project.getNamespace().isEmpty()) {
            dalConfigHost = new DalConfigHost(project.getNamespace());
        } else {
            dalConfigHost = new DalConfigHost("");
        }
        ctx.setDalConfigHost(dalConfigHost);
        ctx.setNamespace(project.getNamespace());
    } catch (Exception e) {
        LoggerManager.getInstance().error(e);
        throw e;
    }
    return ctx;
}
Also used : Project(com.ctrip.platform.dal.daogen.entity.Project) DalConfigHost(com.ctrip.platform.dal.daogen.host.DalConfigHost)

Example 5 with DalConfigHost

use of com.ctrip.platform.dal.daogen.host.DalConfigHost in project dal by ctripcorp.

the class CSharpCodeGenContextCreator method process.

@Override
public void process(CodeGenContext context) throws Exception {
    try {
        CSharpCodeGenContext ctx = (CSharpCodeGenContext) context;
        Project project = BeanGetter.getDaoOfProject().getProjectByID(ctx.getProjectId());
        DalConfigHost dalConfigHost = null;
        if (project.getDal_config_name() != null && !project.getDal_config_name().isEmpty()) {
            dalConfigHost = new DalConfigHost(project.getDal_config_name());
        } else if (project.getNamespace() != null && !project.getNamespace().isEmpty()) {
            dalConfigHost = new DalConfigHost(project.getNamespace());
        } else {
            dalConfigHost = new DalConfigHost("");
        }
        ctx.setDalConfigHost(dalConfigHost);
        ctx.setNamespace(project.getNamespace());
    } catch (Throwable e) {
        LoggerManager.getInstance().error(e);
        throw e;
    }
}
Also used : Project(com.ctrip.platform.dal.daogen.entity.Project) CSharpCodeGenContext(com.ctrip.platform.dal.daogen.generator.csharp.CSharpCodeGenContext) DalConfigHost(com.ctrip.platform.dal.daogen.host.DalConfigHost)

Aggregations

DalConfigHost (com.ctrip.platform.dal.daogen.host.DalConfigHost)6 Project (com.ctrip.platform.dal.daogen.entity.Project)4 DaoOfDatabaseSet (com.ctrip.platform.dal.daogen.dao.DaoOfDatabaseSet)2 CSharpCodeGenContext (com.ctrip.platform.dal.daogen.generator.csharp.CSharpCodeGenContext)2 JavaCodeGenContext (com.ctrip.platform.dal.daogen.generator.java.JavaCodeGenContext)2 DatabaseSet (com.ctrip.platform.dal.daogen.entity.DatabaseSet)1 DatabaseSetEntry (com.ctrip.platform.dal.daogen.entity.DatabaseSetEntry)1 HashMap (java.util.HashMap)1