• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java DatasourcesFraction类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: main

import org.wildfly.swarm.datasources.DatasourcesFraction; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
	Container container = new Container();

	container.fraction(new DatasourcesFraction().jdbcDriver("com.mysql", (d) -> {
		d.driverClassName("com.mysql.jdbc.Driver");
		d.xaDatasourceClass("com.mysql.jdbc.jdbc2.optional.MysqlXADataSource");
		d.driverModuleName("com.mysql");
	}).dataSource("MySQLDS", (ds) -> {
		ds.driverName("com.mysql");
		ds.connectionUrl(System.getenv().getOrDefault("JDBC_URL", "jdbc:mysql://mysql:3306/guestbook?useSSL=false&autoReconnect=true"));
		ds.userName(System.getenv().getOrDefault("DATASOURCE_USERNAME", "myuser"));
		ds.password(System.getenv().getOrDefault("DATASOURCE_PASSWORD", "mypassword"));
		ds.backgroundValidation(true);
		ds.validConnectionCheckerClassName("org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLValidConnectionChecker");
		ds.validateOnMatch(true);
		ds.checkValidConnectionSql("SELECT 1");
	}));

	// Start the container and deploy the default war
	container.start().deploy();
}
 
开发者ID:redhat-developer-demos,项目名称:kubernetes-lab,代码行数:22,代码来源:Main.java


示例2: main

import org.wildfly.swarm.datasources.DatasourcesFraction; //导入依赖的package包/类
public static void main(String... args) throws Exception {
    swarm = new Swarm(args);

    swarm.fraction(
            new DatasourcesFraction()
                    .jdbcDriver("h2", (d) -> {
                        d.driverClassName("org.h2.Driver");
                        d.xaDatasourceClass("org.h2.jdbcx.JdbcDataSource");
                        d.driverModuleName("com.h2database.h2");
                    })
                    .dataSource("ExampleDS", (ds) -> {
                        ds.driverName("h2");
                        ds.connectionUrl("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE");
                        ds.userName("sa");
                        ds.password("sa");
                    })
    );

    swarm.start().deploy();
}
 
开发者ID:wildfly-swarm,项目名称:wildfly-swarm,代码行数:21,代码来源:Main.java


示例3: userSpecifiedFractionOverridesDependentFraction

import org.wildfly.swarm.datasources.DatasourcesFraction; //导入依赖的package包/类
public void userSpecifiedFractionOverridesDependentFraction() throws Exception {
    container.fraction(new DatasourcesFraction()
                    .jdbcDriver(new JDBCDriver("myDriver")
                            .driverDatasourceClassName("org.h2.Driver")
                            .driverXaDatasourceClassName("org.h2.jdbcx.JdbcDataSource")
                            .driverModuleName("com.h2database.h2"))
                    .dataSource(new DataSource("MyDS")
                            .driverName("myDriver")
                            .connectionUrl("jdbc:myDriver:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE")
                            .userName("sa")
                            .password("sa"))
    );

    container.start();

    verifyFractions(container.fractions(), dsFraction -> verifyValidDataSourceFraction(dsFraction, "MyDS", "myDriver"));
}
 
开发者ID:wildfly-swarm-archive,项目名称:ARCHIVE-wildfly-swarm,代码行数:18,代码来源:FractionHandlingTest.java


示例4: verifyValidDataSourceFraction

import org.wildfly.swarm.datasources.DatasourcesFraction; //导入依赖的package包/类
private void verifyValidDataSourceFraction(DatasourcesFraction dsFraction, String dsName, String driverName) {
    // Verify default DataSource Fraction
    assertThat(dsFraction).overridingErrorMessage("DataSourceFraction was null").isNotNull();
    assertThat(dsFraction.subresources().dataSources()).overridingErrorMessage("No DataSources specified").isNotEmpty();
    assertThat(dsFraction.subresources().dataSources().size()).overridingErrorMessage("More than one Datasource specified").isEqualTo(1);
    assertThat(dsFraction.subresources().jdbcDrivers()).overridingErrorMessage("No drivers specified").isNotEmpty();
    assertThat(dsFraction.subresources().jdbcDrivers().size()).overridingErrorMessage("More than one Driver specified").isEqualTo(1);

    // Verify DataSource
    DataSource ds = dsFraction.subresources().dataSources().get(0);
    assertThat(ds.getKey()).overridingErrorMessage("DataSource name is not " + dsName).isEqualTo(dsName);
    assertThat(ds.driverName()).overridingErrorMessage("DataSource driver is not " + driverName).isEqualTo(driverName);
    assertThat(ds.connectionUrl()).isEqualTo("jdbc:" + driverName + ":mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE");
    assertThat(ds.userName()).isEqualTo("sa");
    assertThat(ds.password()).isEqualTo("sa");

    // Verify Driver
    JDBCDriver driver = dsFraction.subresources().jdbcDrivers().get(0);
    assertThat(driver.getKey()).overridingErrorMessage("Driver name is not " + driverName).isEqualTo(driverName);
    assertThat(driver.driverDatasourceClassName()).overridingErrorMessage("Driver datasource class name is not 'org.h2.Driver'").isEqualTo("org.h2.Driver");
    assertThat(driver.driverXaDatasourceClassName()).overridingErrorMessage("Driver XA datasource class name is not 'org.h2.jdbcx.JdbcDataSource'").isEqualTo("org.h2.jdbcx.JdbcDataSource");
}
 
开发者ID:wildfly-swarm-archive,项目名称:ARCHIVE-wildfly-swarm,代码行数:23,代码来源:FractionHandlingTest.java


示例5: initialize

import org.wildfly.swarm.datasources.DatasourcesFraction; //导入依赖的package包/类
@Override
public void initialize(Container.InitContext initContext) {
    if (!inhibitDefaultDatasource) {
        final DatasourcesFraction datasources = new DatasourcesFraction()
                .jdbcDriver("h2", (d) -> {
                    d.driverClassName("org.h2.Driver");
                    d.xaDatasourceClass("org.h2.jdbcx.JdbcDataSource");
                    d.driverModuleName("com.h2database.h2");
                })
                .dataSource("ExampleDS", (ds) -> {
                    ds.driverName("h2");
                    ds.connectionUrl("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE");
                    ds.userName("sa");
                    ds.password("sa");
                });

        initContext.fraction(datasources);
        System.err.println("setting default Datasource to ExampleDS");
        defaultDatasource("jboss/datasources/ExampleDS");
    }
}
 
开发者ID:wildfly-swarm-archive,项目名称:ARCHIVE-wildfly-swarm,代码行数:22,代码来源:JPAFraction.java


示例6: newContainer

import org.wildfly.swarm.datasources.DatasourcesFraction; //导入依赖的package包/类
@Override
  public Container newContainer(String... args) throws Exception {
      Container container = new Container();
      container.fraction(new CamelCoreFraction());
      container.fraction(new DatasourcesFraction());
      container.fraction(new JPAFraction());
container.withXmlConfig(getClass().getResource("/standalone.xml"));
      return container;
  }
 
开发者ID:wildfly-swarm-archive,项目名称:wildfly-swarm-camel,代码行数:10,代码来源:JPATransactionManagerIntegrationTest.java


示例7: installDatasource

import org.wildfly.swarm.datasources.DatasourcesFraction; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public void installDatasource(DatasourcesFraction fraction, String dsName, DataSourceConsumer config) {
    fraction.dataSource(dsName, (ds) -> {
        ds.driverName(this.name);
        this.configureDefaultDS(ds);
        config.accept(ds);
    });
}
 
开发者ID:wildfly-swarm,项目名称:wildfly-swarm,代码行数:9,代码来源:DriverInfo.java


示例8: main

import org.wildfly.swarm.datasources.DatasourcesFraction; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
	Container container = new Container();

	container.fraction(new DatasourcesFraction().jdbcDriver("h2", (d) -> {
		d.driverDatasourceClassName("org.h2.Driver");
		d.xaDatasourceClass("org.h2.jdbcx.JdbcDataSource");
		d.driverModuleName("com.h2database.h2");
	}).dataSource("ExampleDS", (ds) -> {
		ds.driverName("h2");
		ds.connectionUrl("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE");
		ds.userName("sa");
		ds.password("sa");
	}));

	container.fraction(new JPAFraction().inhibitDefaultDatasource().defaultDatasource("jboss/datasources/ExampleDS"));

	container.start();

	WARArchive deployment = ShrinkWrap.create(WARArchive.class);
	deployment.addClasses(BlogEntryDao.class, BlogEntryQueryImpl.class, BlogEntry.class);
	deployment.addPackage(BlogEntryBean.class.getPackage());
	deployment.addAllDependencies();

	deployment.addAsWebResource(new ClassLoaderAsset("index.xhtml", Main.class.getClassLoader()), "index.xhtml");

	deployment.addAsWebInfResource(new ClassLoaderAsset("META-INF/persistence.xml", Main.class.getClassLoader()),
			"classes/META-INF/persistence.xml");
	deployment.addAsWebInfResource(new ClassLoaderAsset("META-INF/load.sql", Main.class.getClassLoader()), "classes/META-INF/load.sql");
	deployment.addAsWebInfResource(new ClassLoaderAsset("META-INF/beans.xml", Main.class.getClassLoader()), "classes/META-INF/beans.xml");

	container.deploy(deployment);
}
 
开发者ID:aracrown,项目名称:ara-blog-examples,代码行数:33,代码来源:Main.java


示例9: detect

import org.wildfly.swarm.datasources.DatasourcesFraction; //导入依赖的package包/类
public boolean detect(DatasourcesFraction fraction) {
    if (fraction.subresources().jdbcDriver(this.name) != null) {
        // already installed
        return true;
    }

    DatasourcesMessages.MESSAGES.attemptToAutoDetectJdbcDriver(this.name);

    File primaryJar = attemptDetection();

    if (primaryJar != null) {
        Set<File> optionalJars = findOptionalJars();

        optionalJars.add(primaryJar);

        fraction.jdbcDriver(this.name, (driver) -> {
            //noinspection deprecation
            ModuleIdentifier identifier = ModuleIdentifier.fromString(this.moduleIdentifier);
            driver.driverModuleName(identifier.getName());
            driver.moduleSlot(identifier.getSlot());
            this.configureDriver(driver);
        });

        DynamicModuleFinder.register(this.moduleIdentifier, (id, loader) -> {
            ModuleSpec.Builder builder = ModuleSpec.build(id);

            for (File eachJar : optionalJars) {

                try {
                    JarFile jar = new JarFile(eachJar);
                    builder.addResourceRoot(ResourceLoaderSpec.createResourceLoaderSpec(
                            ResourceLoaders.createIterableJarResourceLoader(jar.getName(), jar)
                    ));
                } catch (IOException e) {
                    DatasourcesMessages.MESSAGES.errorLoadingAutodetectedJdbcDriver(this.name, e);
                    return null;
                }
            }

            builder.addDependency(DependencySpec.createModuleDependencySpec("javax.api"));
            builder.addDependency(DependencySpec.createModuleDependencySpec("javax.transactions.api", false, true));
            builder.addDependency(DependencySpec.createLocalDependencySpec());
            addModuleDependencies(builder);

            return builder.create();
        });

        this.installed = true;
    }

    return this.installed;
}
 
开发者ID:wildfly-swarm,项目名称:wildfly-swarm,代码行数:53,代码来源:DriverInfo.java


示例10: postInitialize

import org.wildfly.swarm.datasources.DatasourcesFraction; //导入依赖的package包/类
@Override
public void postInitialize(Fraction.PostInitContext initContext) {

    if (System.getProperty("jboss.server.config.dir") == null) {
        try {
            //Path dir = Files.createTempDirectory("swarm-keycloak-config");
            File dir = TempFileManager.INSTANCE.newTempDirectory("swarm-keycloak-config", ".d");
            System.setProperty("jboss.server.config.dir", dir.getAbsolutePath());
            Files.copy(getClass().getClassLoader().getResourceAsStream("keycloak-server.json"),
                       dir.toPath().resolve("keycloak-server.json"),
                       StandardCopyOption.REPLACE_EXISTING);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    InfinispanFraction infinispan = (InfinispanFraction) initContext.fraction("infinispan");

    CacheContainer cache = infinispan.subresources().cacheContainer("keycloak");
    if (cache == null) {
        infinispan.cacheContainer("keycloak", (c) -> c.jndiName("infinispan/Keycloak")
                .localCache("realms")
                .localCache("users")
                .localCache("sessions")
                .localCache("offlineSessions")
                .localCache("loginFailures")
                .localCache("work")
                .localCache("realmVersions", (ca) -> ca.transactionComponent(new TransactionComponent()
                                                                                     .mode(TransactionComponent.Mode.BATCH)
                                                                                     .locking(TransactionComponent.Locking.PESSIMISTIC)))
        );
    }

    DatasourcesFraction datasources = (DatasourcesFraction) initContext.fraction("datasources");

    if (datasources.subresources().dataSource("KeycloakDS") == null) {
        if (datasources.subresources().jdbcDriver("h2") == null) {
            datasources.jdbcDriver("h2", (driver) -> {
                driver.driverModuleName("com.h2database.h2");
                driver.moduleSlot("main");
                driver.xaDatasourceClass("org.h2.jdbcx.JdbcDataSource");
            });
        }

        datasources.dataSource("KeycloakDS", (ds) -> {
            ds.jndiName("java:jboss/datasources/KeycloakDS");
            ds.useJavaContext(true);
            ds.connectionUrl("jdbc:h2:${wildfly.swarm.keycloak.server.db:./keycloak};AUTO_SERVER=TRUE");
            ds.driverName("h2");
            ds.userName("sa");
            ds.password("sa");
        });
    }
}
 
开发者ID:wildfly-swarm-archive,项目名称:wildfly-swarm-keycloak,代码行数:55,代码来源:KeycloakServerFraction.java


示例11: verifyEmptyDataSourceFraction

import org.wildfly.swarm.datasources.DatasourcesFraction; //导入依赖的package包/类
private void verifyEmptyDataSourceFraction(DatasourcesFraction dsFraction) {
    assertThat(dsFraction).overridingErrorMessage("DataSourceFraction was null").isNotNull();
    assertThat(dsFraction.subresources().dataSources()).overridingErrorMessage("DataSources were specified").isEmpty();
    assertThat(dsFraction.subresources().jdbcDrivers()).overridingErrorMessage("Drivers were specified").isEmpty();
}
 
开发者ID:wildfly-swarm-archive,项目名称:ARCHIVE-wildfly-swarm,代码行数:6,代码来源:FractionHandlingTest.java


示例12: DatasourcesConfiguration

import org.wildfly.swarm.datasources.DatasourcesFraction; //导入依赖的package包/类
public DatasourcesConfiguration() {
    super(DatasourcesFraction.class);
}
 
开发者ID:wildfly-swarm-archive,项目名称:ARCHIVE-wildfly-swarm,代码行数:4,代码来源:DatasourcesConfiguration.java


示例13: postInitialize

import org.wildfly.swarm.datasources.DatasourcesFraction; //导入依赖的package包/类
@Override
public void postInitialize(Container.PostInitContext initContext) {

    if (System.getProperty("jboss.server.config.dir") == null) {
        try {
            //Path dir = Files.createTempDirectory("swarm-keycloak-config");
            File dir = TempFileManager.INSTANCE.newTempDirectory( "swarm-keycloak-config", ".d" );
            System.setProperty("jboss.server.config.dir", dir.getAbsolutePath() );
            Files.copy(getClass().getClassLoader().getResourceAsStream("keycloak-server.json"),
                    dir.toPath().resolve("keycloak-server.json"),
                    StandardCopyOption.REPLACE_EXISTING);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    InfinispanFraction infinispan = (InfinispanFraction) initContext.fraction("infinispan");

    CacheContainer cache = infinispan.subresources().cacheContainer("keycloak");
    if (cache == null) {
        infinispan.cacheContainer("keycloak", (c) -> c.jndiName("infinispan/Keycloak")
                .localCache("realms")
                .localCache("users")
                .localCache("sessions")
                .localCache("offlineSessions")
                .localCache("loginFailures"));
    }

    DatasourcesFraction datasources = (DatasourcesFraction) initContext.fraction("datasources");

    if (datasources.subresources().dataSource("KeycloakDS") == null) {
        if (datasources.subresources().jdbcDriver("h2") == null) {
            datasources.jdbcDriver("h2", (driver) -> {
                driver.driverModuleName("com.h2database.h2");
                driver.moduleSlot("main");
                driver.xaDatasourceClass("org.h2.jdbcx.JdbcDataSource");
            });
        }

        datasources.dataSource("KeycloakDS", (ds) -> {
            ds.jndiName("java:jboss/datasources/KeycloakDS");
            ds.useJavaContext(true);
            ds.connectionUrl("jdbc:h2:${wildfly.swarm.keycloak.server.db:./keycloak};AUTO_SERVER=TRUE");
            ds.driverName("h2");
            ds.userName("sa");
            ds.password("sa");
        });
    }
}
 
开发者ID:wildfly-swarm-archive,项目名称:ARCHIVE-wildfly-swarm,代码行数:50,代码来源:KeycloakServerFraction.java


示例14: defaultJobRepository

import org.wildfly.swarm.datasources.DatasourcesFraction; //导入依赖的package包/类
/**
 * Adds a new JDBC job repository using the datasource name as the job repository name and sets it as the default job
 * repository.
 *
 * @param datasource the datasource to use to connect to the database
 * @return this fraction
 */
public BatchFraction defaultJobRepository(final DatasourcesFraction datasource) {
    return defaultJobRepository(datasource.getKey(), datasource);
}
 
开发者ID:wildfly-swarm,项目名称:wildfly-swarm,代码行数:11,代码来源:BatchFraction.java


示例15: jdbcJobRepository

import org.wildfly.swarm.datasources.DatasourcesFraction; //导入依赖的package包/类
/**
 * Creates a new JDBC job repository using the name of the datasource for the job repository name.
 *
 * @param datasource the datasource to use to connect to the database
 * @return this fraction
 */
public BatchFraction jdbcJobRepository(final DatasourcesFraction datasource) {
    return jdbcJobRepository(datasource.getKey(), datasource);
}
 
开发者ID:wildfly-swarm,项目名称:wildfly-swarm,代码行数:10,代码来源:BatchFraction.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java RecipeOutput类代码示例发布时间:2022-05-22
下一篇:
Java DefaultTileFactory类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap