当前位置: 首页>>代码示例>>Java>>正文


Java DBI类代码示例

本文整理汇总了Java中org.skife.jdbi.v2.DBI的典型用法代码示例。如果您正苦于以下问题:Java DBI类的具体用法?Java DBI怎么用?Java DBI使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


DBI类属于org.skife.jdbi.v2包,在下文中一共展示了DBI类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: Database

import org.skife.jdbi.v2.DBI; //导入依赖的package包/类
public Database() {
    try {
        Class.forName("org.mariadb.jdbc.Driver");
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }

    HikariConfig config = new HikariConfig();
    config.setJdbcUrl(App.getConfig().getString("database.url"));
    config.setUsername(App.getConfig().getString("database.user"));
    config.setPassword(App.getConfig().getString("database.pass"));
    config.addDataSourceProperty("cachePrepStmts", "true");
    config.addDataSourceProperty("prepStmtCacheSize", "250");
    config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
    config.addDataSourceProperty("allowMultiQueries", "true");
    config.setMaximumPoolSize(200); // this is plenty, the websocket uses 32

    dbi = new DBI(new HikariDataSource(config));
    

    getHandle().createPixelsTable();
    getHandle().createUsersTable();
    getHandle().createSessionsTable();
    getHandle().createAdminLogTable();
    getHandle().createReportsTable();
}
 
开发者ID:xSke,项目名称:Pxls,代码行数:27,代码来源:Database.java

示例2: connectToDatasource

import org.skife.jdbi.v2.DBI; //导入依赖的package包/类
private IDBI connectToDatasource(ShardInfo shardInfo) {
    PooledDataSourceFactory urlReplacedCopy =
            copyAndReplaceURL(dropwizardDSFactory, shardInfo);

    // we cannot re-register using the same name (dropwizard metrics do not merge on name collision)
    String dbShardName = humanFriendlyShardNamer.nameShard(shardInfo);
    DBI jdbi = dropwizardDbiFactory.build(
            dropwizardEnvironment,
            urlReplacedCopy,
            dbShardName);
    if (DBIInitializer != null) {
        DBIInitializer.initialize(jdbi);
    }
    logger.info("New shard connection created: " + dbShardName);

    return jdbi;
}
 
开发者ID:toasttab,项目名称:jdbishard,代码行数:18,代码来源:JDBIManager.java

示例3: AnetObjectEngine

import org.skife.jdbi.v2.DBI; //导入依赖的package包/类
public AnetObjectEngine(DBI jdbi) { 
	dbHandle = jdbi.open();
	
	personDao = new PersonDao(dbHandle);
	poamDao = new PoamDao(dbHandle);
	locationDao =  new LocationDao(dbHandle);
	orgDao = new OrganizationDao(dbHandle);
	positionDao = new PositionDao(dbHandle);
	asDao = new ApprovalStepDao(dbHandle);
	approvalActionDao = new ApprovalActionDao(dbHandle);
	reportDao = new ReportDao(dbHandle);
	commentDao = new CommentDao(dbHandle);
	adminDao = new AdminDao(dbHandle);
	savedSearchDao = new SavedSearchDao(dbHandle);
	
	instance = this;
	
	//TODO: maybe do this differently!
	if (DaoUtils.isMsSql(dbHandle)) { 
		searcher = new MssqlSearcher();
	} else { 
		searcher = new SqliteSearcher();
	}
}
 
开发者ID:deptofdefense,项目名称:anet,代码行数:25,代码来源:AnetObjectEngine.java

示例4: run

import org.skife.jdbi.v2.DBI; //导入依赖的package包/类
@Override
public void run(final BloopServerConfiguration configuration,
                final Environment environment) {
    final DBIFactory factory = new DBIFactory();
    final DBI jdbi = factory.build(environment, configuration.getDataSourceFactory(), "postgresql");
    final FlagDAO flagDAO = jdbi.onDemand(FlagDAO.class);
    final NearbyFlagDAO nearbyFlagDAO = jdbi.onDemand(NearbyFlagDAO.class);
    final PlayerDAO playerDAO = jdbi.onDemand(PlayerDAO.class);
    
    final Client client = new JerseyClientBuilder(environment).using(configuration.getJerseyClientConfiguration())
            .build(getName());
    final String firebaseKey = configuration.getFirebaseKey();
    
    environment.jersey().register(new FlagResource(flagDAO, nearbyFlagDAO, playerDAO, client, firebaseKey));
    environment.jersey().register(new PlayerResource(playerDAO, flagDAO));
}
 
开发者ID:BloopApp,项目名称:BloopServer,代码行数:17,代码来源:BloopServerApplication.java

示例5: setup

import org.skife.jdbi.v2.DBI; //导入依赖的package包/类
@Before
public void setup() throws Exception
{
    DBIFactory factory = new DBIFactory();
    Environment environment = new Environment("test", new ObjectMapper(), null, new MetricRegistry(), ClassLoader.getSystemClassLoader());
    DataSourceFactory dataSourceFactory = new DataSourceFactory();
    dataSourceFactory.setUrl("jdbc:hsqldb:mem:soa-jdbi;shutdown=true");
    dataSourceFactory.setDriverClass("org.hsqldb.jdbc.JDBCDriver");
    dataSourceFactory.setLogValidationErrors(true);
    dataSourceFactory.setUser("SA");
    dataSourceFactory.setValidationQuery("SELECT * FROM INFORMATION_SCHEMA.SYSTEM_TABLES");
    DBI jdbi = factory.build(environment, dataSourceFactory, "test");
    dynamicAttributes = new JdbiDynamicAttributes(jdbi, Collections.singletonList("test"));

    dynamicAttributes.getDao().createTable();
    dynamicAttributes.start();
}
 
开发者ID:soabase,项目名称:soabase,代码行数:18,代码来源:TestJdbiDynamicAttributes.java

示例6: configure

import org.skife.jdbi.v2.DBI; //导入依赖的package包/类
@Override
protected void configure() {
    bind(jsonMapper).to(ObjectMapper.class);
    //dao
    bind(jdbi.onDemand(AccessCredentialsDao.class)).to(AccessCredentialsDao.class);
    bind(jdbi.onDemand(UserDao.class)).to(UserDao.class);
    bind(jdbi.onDemand(TaskDao.class)).to(TaskDao.class);
    bind(jdbi.onDemand(MonitorDao.class)).to(MonitorDao.class);
    bind(jdbi.onDemand(MonitorTaskDao.class)).to(MonitorTaskDao.class);
    bind(jdbi.onDemand(MonitorNiPingResultDao.class)).to(MonitorNiPingResultDao.class);

    //config
    bind(sapConfiguration).to(SapConfiguration.class);
    bind(jobConfiguration).to(JobConfiguration.class);
    //jdbi
    bind(jdbi).to(DBI.class);
    //service
    bind(AuthService.class).in(Singleton.class).to(AuthService.class);
    bind(MonitorService.class).in(Singleton.class).to(MonitorService.class);
    bind(TaskService.class).in(Singleton.class).to(TaskService.class);
    bind(TaskConverter.class).in(Singleton.class).to(TaskConverter.class);
    bind(MonitorResultService.class).in(Singleton.class).to(MonitorResultService.class);
    //auth
    bind(SapOAuthenticator.class).in(Singleton.class).to(SapOAuthenticator.class);
    bind(SapBasicAuthenticator.class).in(Singleton.class).to(SapBasicAuthenticator.class);
}
 
开发者ID:CloudWise-OpenSource,项目名称:SAPNetworkMonitor,代码行数:27,代码来源:NiPingServiceBinder.java

示例7: realTimeDB

import org.skife.jdbi.v2.DBI; //导入依赖的package包/类
@Bean
@Autowired
@SuppressWarnings("PMD.EmptyCatchBlock")
public SqlJsonDB realTimeDB(DBI dbi) {

    ArrayList<Index> indexes = new ArrayList<>();
    for (Kind kind : Kind.values()) {
        UniqueProperty uniqueProperty = kind.getModelClass().getAnnotation(UniqueProperty.class);
        if (uniqueProperty != null) {
            indexes.add(new Index("/" + kind.getModelName() + "s", uniqueProperty.value()));
        }
    }

    SqlJsonDB jsondb = new SqlJsonDB(dbi, null, indexes);
    try {
        jsondb.createTables();
    } catch (@SuppressWarnings("PMD.AvoidCatchingGenericException") Exception ignore) {
        LOG.debug("Could not create tables", ignore);
    }
    return jsondb;
}
 
开发者ID:syndesisio,项目名称:syndesis,代码行数:22,代码来源:DataStoreConfiguration.java

示例8: SqlJsonDB

import org.skife.jdbi.v2.DBI; //导入依赖的package包/类
public SqlJsonDB(DBI dbi, EventBus bus, Collection<Index> indexes) {
    this.dbi = dbi;
    this.bus = bus;

    for (Index index : indexes) {
        this.indexes.add(index.getPath()+"/"+index.getField());
    }

    // Lets find out the type of DB we are working with.
    withTransaction(x -> {
        try {
            String dbName = x.getConnection().getMetaData().getDatabaseProductName();
            databaseKind = DatabaseKind.valueOf(dbName);

            // CockroachDB uses the PostgreSQL driver.. so need to look a little closer.
            if( databaseKind == DatabaseKind.PostgreSQL ) {
                String version = x.createQuery("SELECT VERSION()").mapTo(String.class).first();
                if( version.startsWith("CockroachDB") ) {
                    databaseKind = DatabaseKind.CockroachDB;
                }
            }
        } catch (@SuppressWarnings("PMD.AvoidCatchingGenericException") Exception e) {
            throw new IllegalStateException("Could not determine the database type", e);
        }
    });
}
 
开发者ID:syndesisio,项目名称:syndesis,代码行数:27,代码来源:SqlJsonDB.java

示例9: before

import org.skife.jdbi.v2.DBI; //导入依赖的package包/类
@Before
public void before() {
    JdbcDataSource ds = new JdbcDataSource();
    ds.setURL("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;MODE=PostgreSQL");
    DBI dbi = new DBI(ds);

    this.jsondb = new SqlJsonDB(dbi, null,
        Arrays.asList(new Index("/pair", "key"))
    );

    try {
        this.jsondb.dropTables();
    } catch (Exception e) {
    }
    this.jsondb.createTables();
}
 
开发者ID:syndesisio,项目名称:syndesis,代码行数:17,代码来源:JsonDBTest.java

示例10: build

import org.skife.jdbi.v2.DBI; //导入依赖的package包/类
@Override
public DBI build(Environment environment, PooledDataSourceFactory configuration, ManagedDataSource dataSource, String name) {
    final DBI dbi = super.build(environment, configuration, dataSource, name);

    dbi.registerArgumentFactory(new ValueArgumentFactory(configuration.getDriverClass()));
    dbi.registerArgumentFactory(new OptionArgumentFactory(configuration.getDriverClass()));
    dbi.registerContainerFactory(new OptionContainerFactory());

    // The order of container factories is important, least specific to most specific
    dbi.registerContainerFactory(new SeqContainerFactory());
    dbi.registerContainerFactory(new IndexedSeqContainerFactory());
    dbi.registerContainerFactory(new SetContainerFactory());
    dbi.registerContainerFactory(new TreeContainerFactory());
    dbi.registerContainerFactory(new ListContainerFactory());
    dbi.registerContainerFactory(new ArrayContainerFactory());
    dbi.registerContainerFactory(new QueueContainerFactory());
    dbi.registerContainerFactory(new StreamContainerFactory());
    dbi.registerContainerFactory(new VectorContainerFactory());

    return dbi;
}
 
开发者ID:dropwizard,项目名称:dropwizard-vavr,代码行数:22,代码来源:VavrDBIFactory.java

示例11: setupTests

import org.skife.jdbi.v2.DBI; //导入依赖的package包/类
@Before
public void setupTests() throws IOException {
    final DataSourceFactory dataSourceFactory = new DataSourceFactory();
    dataSourceFactory.setDriverClass("org.h2.Driver");
    dataSourceFactory.setUrl("jdbc:h2:mem:test-" + System.currentTimeMillis() + "?user=sa");
    dataSourceFactory.setInitialSize(1);
    final DBI dbi = new VavrDBIFactory().build(env, dataSourceFactory, "test");
    try (Handle h = dbi.open()) {
        h.execute("CREATE TABLE tasks (" +
                "id INT PRIMARY KEY, " +
                "assignee VARCHAR(255) NOT NULL, " +
                "start_date TIMESTAMP, " +
                "end_date TIMESTAMP, " +
                "comments VARCHAR(1024) " +
                ")");
    }
    dao = dbi.onDemand(TaskDao.class);

    dao.insert(100, Option.some("Name 1"), LocalDate.parse("2017-08-24"), Option.none(), Option.none());
    dao.insert(200, Option.some("Name 2"), LocalDate.parse("2017-08-25"), Option.none(), Option.some("To be done"));
}
 
开发者ID:dropwizard,项目名称:dropwizard-vavr,代码行数:22,代码来源:VavrDBIFactoryTest.java

示例12: addToJerseyConfig

import org.skife.jdbi.v2.DBI; //导入依赖的package包/类
@Override
public void addToJerseyConfig(JerseyConfig jerseyConfig) {
    jerseyConfig.addBinder(binder -> {
        if (name != null) {
            binder.bind(dbi).to(DBI.class).named(name);
            binder.bind(this).to(JdbiAddon.class).named(name);
        } else {
            binder.bind(dbi).to(DBI.class);
            binder.bind(this).to(JdbiAddon.class);
        }

        daos.forEach(clazz ->
                binder.bindFactory(new DaoFactory(dbi, clazz)).to(clazz)
        );

    });
}
 
开发者ID:code-obos,项目名称:servicebuilder,代码行数:18,代码来源:JdbiAddon.java

示例13: apply

import org.skife.jdbi.v2.DBI; //导入依赖的package包/类
@Override
public Statement apply(Statement base, Description description) {
    return rules.apply(new Statement() {
        @Override
        public void evaluate() throws Throwable {
            logger.info("Clearing database.");
            app.getApplication().run("db", "drop-all", "--confirm-delete-everything", configFilePath);
            app.getApplication().run("migrateToInitialDbState", configFilePath);
            doSecondaryDatabaseMigration();
            restoreDropwizardsLogging();

            DataSourceFactory dataSourceFactory = app.getConfiguration().getDataSourceFactory();
            databaseTestHelper = new DatabaseTestHelper(new DBI(dataSourceFactory.getUrl(), dataSourceFactory.getUser(), dataSourceFactory.getPassword()));

            base.evaluate();
        }
    }, description);
}
 
开发者ID:alphagov,项目名称:pay-adminusers,代码行数:19,代码来源:DropwizardAppWithPostgresRule.java

示例14: RegisterContext

import org.skife.jdbi.v2.DBI; //导入依赖的package包/类
public RegisterContext(RegisterName registerName, ConfigManager configManager, EnvironmentValidator environmentValidator,
                       RegisterLinkService registerLinkService, DBI dbi, Flyway flyway, String schema,
                       boolean enableRegisterDataDelete, boolean enableDownloadResource,
                       Optional<String> historyPageUrl, List<String> similarRegisters, List<String> indexNames,
                       RegisterAuthenticator authenticator) {
    this.registerName = registerName;
    this.configManager = configManager;
    this.environmentValidator = environmentValidator;
    this.registerLinkService = registerLinkService;
    this.dbi = dbi;
    this.flyway = flyway;
    this.schema = schema;
    this.historyPageUrl = historyPageUrl;
    this.similarRegisters = similarRegisters;
    this.indexFunctionConfigs = mapIndexes(indexNames);
    this.memoizationStore = new AtomicReference<>(new InMemoryPowOfTwoNoLeaves());
    this.enableRegisterDataDelete = enableRegisterDataDelete;
    this.enableDownloadResource = enableDownloadResource;
    this.authenticator = authenticator;
    this.itemValidator = new ItemValidator(registerName);
    this.hasConsistentState = true;
}
 
开发者ID:openregister,项目名称:openregister-java,代码行数:23,代码来源:RegisterContext.java

示例15: JdbcSessionStore

import org.skife.jdbi.v2.DBI; //导入依赖的package包/类
public JdbcSessionStore(DBI dbi, JdbcTableConfiguration jdbcConfig) {
    this.dbi = dbi;
    this.jdbcConfig = jdbcConfig;
    this.sqlGetSession = String.format("select %s, %s, %s, %s, %s, %s%s from %s where %s = :sessionId",
            jdbcConfig.getSessionIdCol(),
            jdbcConfig.getSessionLastAccessedCol(),
            jdbcConfig.getSessionMaxInactiveCol(),
            jdbcConfig.getSessionValidCol(),
            jdbcConfig.getSessionAppCol(),
            jdbcConfig.getSessionDataCol(),
            isStoredSizeConfigured()
                    ? String.format(", %s AS %s", jdbcConfig.getStoredSizeExpr(), STORED_SIZE_ALIAS)
                    : "",
            jdbcConfig.getSessionTable(),
            jdbcConfig.getSessionIdCol());
    this.sqlListSessions = String.format("select %s, %s, %s, %s, %s%s from %s",
            jdbcConfig.getSessionIdCol(),
            jdbcConfig.getSessionLastAccessedCol(),
            jdbcConfig.getSessionMaxInactiveCol(),
            jdbcConfig.getSessionValidCol(),
            jdbcConfig.getSessionAppCol(),
            isStoredSizeConfigured()
                    ? String.format(", %s AS %s", jdbcConfig.getStoredSizeExpr(), STORED_SIZE_ALIAS)
                    : "",
            jdbcConfig.getSessionTable());
}
 
开发者ID:commercehub-oss,项目名称:clouseau,代码行数:27,代码来源:JdbcSessionStore.java


注:本文中的org.skife.jdbi.v2.DBI类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。