Search in sources :

Example 1 with DatabaseSetEntry

use of com.ctrip.platform.dal.daogen.entity.DatabaseSetEntry in project dal by ctripcorp.

the class DalConfigHost method getDatabaseSetEntryMap.

public Map<String, DatabaseSetEntry> getDatabaseSetEntryMap() throws SQLException {
    Map<String, DatabaseSetEntry> map = null;
    if (databaseSetEntryMap != null && databaseSetEntryMap.size() > 0) {
        map = new HashMap<>();
        Set<String> set = new HashSet<>();
        for (Map.Entry<Integer, DatabaseSetEntry> entry : databaseSetEntryMap.entrySet()) {
            set.add(entry.getValue().getConnectionString());
        }
        List<DalGroupDB> dbs = BeanGetter.getDaoOfDalGroupDB().getGroupDbsByDbNames(set);
        if (dbs != null && dbs.size() > 0) {
            for (DalGroupDB db : dbs) {
                DatabaseSetEntry e = new DatabaseSetEntry();
                e.setConnectionString(db.getDbname());
                e.setProviderName(db.getDb_providerName());
                e.setDbAddress(db.getDb_address());
                e.setDbPort(db.getDb_port());
                e.setUserName(db.getDb_user());
                e.setPassword(db.getDb_password());
                e.setDbCatalog(db.getDb_catalog());
                map.put(e.getConnectionString(), e);
            }
        }
    }
    return map;
}
Also used : DalGroupDB(com.ctrip.platform.dal.daogen.entity.DalGroupDB) DatabaseSetEntry(com.ctrip.platform.dal.daogen.entity.DatabaseSetEntry)

Example 2 with DatabaseSetEntry

use of com.ctrip.platform.dal.daogen.entity.DatabaseSetEntry in project dal by ctripcorp.

the class GenTaskBySqlBuilderResource method buildPagingSQL.

@POST
@Path("buildPagingSQL")
public // dbset
Status buildPagingSQL(// dbset
@FormParam("db_name") String db_set_name, // C#风格或者Java风格
@FormParam("sql_style") String sql_style, @FormParam("sql_content") String sql_content) {
    Status status = Status.OK();
    try {
        DatabaseSetEntry databaseSetEntry = BeanGetter.getDaoOfDatabaseSet().getMasterDatabaseSetEntryByDatabaseSetName(db_set_name);
        CurrentLanguage lang = "java".equals(sql_style) ? CurrentLanguage.Java : CurrentLanguage.CSharp;
        String pagingSQL = SqlBuilder.pagingQuerySql(sql_content, DbUtils.getDatabaseCategory(databaseSetEntry.getConnectionString()), lang);
        status.setInfo(pagingSQL);
    } catch (Throwable e) {
        LoggerManager.getInstance().error(e);
        status = Status.ERROR();
        status.setInfo(e.getMessage());
        return status;
    }
    return status;
}
Also used : Status(com.ctrip.platform.dal.daogen.domain.Status) CurrentLanguage(com.ctrip.platform.dal.daogen.enums.CurrentLanguage) DatabaseSetEntry(com.ctrip.platform.dal.daogen.entity.DatabaseSetEntry)

Example 3 with DatabaseSetEntry

use of com.ctrip.platform.dal.daogen.entity.DatabaseSetEntry in project dal by ctripcorp.

the class DaoOfDatabaseSet method getAllDatabaseSetEntryByDbsetid.

public List<DatabaseSetEntry> getAllDatabaseSetEntryByDbsetid(Integer databaseSet_Id) throws SQLException {
    FreeSelectSqlBuilder<List<DatabaseSetEntry>> builder = new FreeSelectSqlBuilder<>(dbCategory);
    builder.setTemplate("SELECT id, name, databaseType, sharding, connectionString, databaseSet_Id, update_user_no, update_time FROM databasesetentry WHERE databaseSet_Id = ?");
    StatementParameters parameters = new StatementParameters();
    int i = 1;
    parameters.set(i++, "databaseSet_Id", Types.INTEGER, databaseSet_Id);
    builder.mapWith(databaseSetEntryRowMapper);
    DalHints hints = DalHints.createIfAbsent(null).allowPartial();
    List<DatabaseSetEntry> list = queryDao.query(builder, parameters, hints);
    processEntryList(list);
    return list;
}
Also used : FreeSelectSqlBuilder(com.ctrip.platform.dal.dao.sqlbuilder.FreeSelectSqlBuilder) DalHints(com.ctrip.platform.dal.dao.DalHints) StatementParameters(com.ctrip.platform.dal.dao.StatementParameters) List(java.util.List) DatabaseSetEntry(com.ctrip.platform.dal.daogen.entity.DatabaseSetEntry)

Example 4 with DatabaseSetEntry

use of com.ctrip.platform.dal.daogen.entity.DatabaseSetEntry in project dal by ctripcorp.

the class GenTaskByFreeSqlResource method buildPagingSQL.

@POST
@Path("buildPagingSQL")
public // dbset// name
Status buildPagingSQL(// dbset// name
@FormParam("db_name") String db_set_name, // C#风格或者Java风格
@FormParam("sql_style") String sql_style, @FormParam("sql_content") String sql_content) {
    try {
        Status status = Status.OK();
        DatabaseSetEntry databaseSetEntry = BeanGetter.getDaoOfDatabaseSet().getMasterDatabaseSetEntryByDatabaseSetName(db_set_name);
        CurrentLanguage lang = (sql_content.contains("@") || "csharp".equals(sql_style)) ? CurrentLanguage.CSharp : CurrentLanguage.Java;
        String pagingSQL = SqlBuilder.pagingQuerySql(sql_content, DbUtils.getDatabaseCategory(databaseSetEntry.getConnectionString()), lang);
        status.setInfo(pagingSQL);
        return status;
    } catch (Throwable e) {
        LoggerManager.getInstance().error(e);
        Status status = Status.ERROR();
        status.setInfo(e.getMessage());
        return status;
    }
}
Also used : Status(com.ctrip.platform.dal.daogen.domain.Status) CurrentLanguage(com.ctrip.platform.dal.daogen.enums.CurrentLanguage) DatabaseSetEntry(com.ctrip.platform.dal.daogen.entity.DatabaseSetEntry)

Example 5 with DatabaseSetEntry

use of com.ctrip.platform.dal.daogen.entity.DatabaseSetEntry 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)

Aggregations

DatabaseSetEntry (com.ctrip.platform.dal.daogen.entity.DatabaseSetEntry)9 DalHints (com.ctrip.platform.dal.dao.DalHints)3 StatementParameters (com.ctrip.platform.dal.dao.StatementParameters)2 FreeSelectSqlBuilder (com.ctrip.platform.dal.dao.sqlbuilder.FreeSelectSqlBuilder)2 Status (com.ctrip.platform.dal.daogen.domain.Status)2 CurrentLanguage (com.ctrip.platform.dal.daogen.enums.CurrentLanguage)2 Test (org.junit.Test)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 DaoOfDatabaseSet (com.ctrip.platform.dal.daogen.dao.DaoOfDatabaseSet)1 DalGroupDB (com.ctrip.platform.dal.daogen.entity.DalGroupDB)1 DatabaseSet (com.ctrip.platform.dal.daogen.entity.DatabaseSet)1 CSharpCodeGenContext (com.ctrip.platform.dal.daogen.generator.csharp.CSharpCodeGenContext)1 DalConfigHost (com.ctrip.platform.dal.daogen.host.DalConfigHost)1 List (java.util.List)1