Search in sources :

Example 6 with DatabaseSetEntry

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

the class DaoOfDatabaseSet method deleteDatabaseSetEntryById.

/**
 * 根据主键id删除entry
 *
 * @param id
 * @return
 */
public int deleteDatabaseSetEntryById(Integer id) throws SQLException {
    DatabaseSetEntry entry = new DatabaseSetEntry();
    entry.setId(id);
    DalHints hints = DalHints.createIfAbsent(null);
    return client2.delete(hints, entry);
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) DatabaseSetEntry(com.ctrip.platform.dal.daogen.entity.DatabaseSetEntry)

Example 7 with DatabaseSetEntry

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

the class DaoOfDatabaseSet method getMasterDatabaseSetEntryByDatabaseSetName.

public DatabaseSetEntry getMasterDatabaseSetEntryByDatabaseSetName(String dbName) throws SQLException {
    FreeSelectSqlBuilder<DatabaseSetEntry> builder = new FreeSelectSqlBuilder<>(dbCategory);
    builder.setTemplate("SELECT en.id, en.name, en.databaseType, en.sharding, en.connectionString, en.databaseSet_Id, en.update_user_no, en.update_time " + "FROM databasesetentry as en join databaseset as se on en.databaseSet_Id = se.id " + "WHERE se.name = ? and en.databaseType = 'Master' limit 1");
    StatementParameters parameters = new StatementParameters();
    int i = 1;
    parameters.set(i++, "name", Types.VARCHAR, dbName);
    builder.mapWith(databaseSetEntryRowMapper).requireFirst().nullable();
    DalHints hints = DalHints.createIfAbsent(null).allowPartial();
    DatabaseSetEntry entry = queryDao.query(builder, parameters, hints);
    processDatabaseSetEntry(entry);
    return entry;
}
Also used : FreeSelectSqlBuilder(com.ctrip.platform.dal.dao.sqlbuilder.FreeSelectSqlBuilder) DalHints(com.ctrip.platform.dal.dao.DalHints) StatementParameters(com.ctrip.platform.dal.dao.StatementParameters) DatabaseSetEntry(com.ctrip.platform.dal.daogen.entity.DatabaseSetEntry)

Example 8 with DatabaseSetEntry

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

the class AllInOneNameUtilsTest method getAllInOneNameByNameOnlyTest.

@Test
public void getAllInOneNameByNameOnlyTest() throws SQLException {
    String dbname = "abtest_dalcluster";
    assertEquals(dbname, AllInOneNameUtils.getAllInOneNameByNameOnly(dbname));
    PowerMockito.mockStatic(BeanGetter.class);
    PowerMockito.when(BeanGetter.getDaoOfDatabaseSet()).thenReturn(daoOfDatabaseSet);
    DatabaseSetEntry databaseSetEntry = new DatabaseSetEntry();
    databaseSetEntry.setConnectionString("connection");
    Mockito.when(daoOfDatabaseSet.getMasterDatabaseSetEntryByDatabaseSetName("titankey")).thenReturn(databaseSetEntry);
    assertEquals("connection", AllInOneNameUtils.getAllInOneNameByNameOnly("titankey"));
}
Also used : DatabaseSetEntry(com.ctrip.platform.dal.daogen.entity.DatabaseSetEntry) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 9 with DatabaseSetEntry

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

the class AllInOneNameUtilsTest method getAllInOneNameTest.

@Test
public void getAllInOneNameTest() throws SQLException {
    String dbname = "abtest_dalcluster";
    assertEquals(dbname, AllInOneNameUtils.getAllInOneName(dbname, "dalcluster"));
    PowerMockito.mockStatic(BeanGetter.class);
    PowerMockito.when(BeanGetter.getDaoOfDatabaseSet()).thenReturn(daoOfDatabaseSet);
    DatabaseSetEntry databaseSetEntry = new DatabaseSetEntry();
    databaseSetEntry.setConnectionString("connection");
    Mockito.when(daoOfDatabaseSet.getMasterDatabaseSetEntryByDatabaseSetName(dbname)).thenReturn(databaseSetEntry);
    assertEquals("connection", AllInOneNameUtils.getAllInOneName(dbname, "titankey"));
}
Also used : DatabaseSetEntry(com.ctrip.platform.dal.daogen.entity.DatabaseSetEntry) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

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