Package fi.evident.dalesbred

Examples of fi.evident.dalesbred.Database


    @Test
    public void testCreation() {
        Injector injector = Guice.createInjector(new DriverManagerDatabaseModule(), TestDatabaseProvider.inMemoryDatabasePropertiesModule());

        Database db = injector.getInstance(Database.class);

        Employee employee = db.findUnique(Employee.class, "values (42, 'Fred Foo')");
        assertThat(employee.id, is(42));
        assertThat(employee.name, is("Fred Foo"));
        assertThat(employee.db, is(db));
    }
View Full Code Here


    @Test
    public void testCreation() {
        Injector injector = Guice.createInjector(new DriverManagerDatabaseModule(), TestDatabaseProvider.inMemoryDatabasePropertiesModule());

        Database db = injector.getInstance(Database.class);

        assertThat(db.findUniqueInt("values (42)"), is(42));
    }
View Full Code Here

    @Test
    public void testCreation() {
        Injector injector = Guice.createInjector(new DataSourceDatabaseModule(), new MyDataSourceModule());

        Database db = injector.getInstance(Database.class);

        assertThat(db.findUniqueInt("values (42)"), is(42));
    }
View Full Code Here

        this.injector = requireNonNull(injector);
    }

    @Override
    public Database get() {
        Database db = new Database(dataSource);
        db.getInstantiatorRegistry().addInstantiationListener(new InstantiationListener() {
            @Override
            public void onInstantiation(@NotNull Object object) {
                injector.injectMembers(object);
            }
        });
View Full Code Here

    public Database dalesbredDatabase(DataSource dataSource, PlatformTransactionManager transactionManager) {
        Dialect dialect = dialect();
        if (dialect == null)
            dialect = Dialect.detect(dataSource);

        Database db = new Database(new SpringTransactionManager(dataSource, transactionManager), dialect);
        registerInstantiators(db.getInstantiatorRegistry());
        registerTypeConversions(db.getTypeConversionRegistry());
        setupDatabase(db);
        return db;
    }
View Full Code Here

public class TestDatabaseProviderTest {

    @Test
    public void defaultDialect() {
        Database db = TestDatabaseProvider.databaseForProperties("hsqldb-connection.properties");

        assertEquals("foo", db.findUnique(String.class, "values ('foo')"));
    }
View Full Code Here

        assertEquals("foo", db.findUnique(String.class, "values ('foo')"));
    }

    @Test
    public void customDialect() {
        Database db = TestDatabaseProvider.databaseForProperties("hsqldb-connection.properties", new UppercaseDialect());
        db.update("drop table if exists my_table");
        db.update("create table my_table (text varchar(64))");

        db.update("insert into my_table values (?)", "foo");

        assertEquals("FOO", db.findUnique(String.class, "select text from my_table"));
    }
View Full Code Here

    @Test
    public void rollbacksWithoutThirdPartyTransactions() throws SQLException {
        Connection connection = dataSource.getConnection();
        try {
            TransactionManager tm = new SingleConnectionTransactionManager(connection, false);
            final Database db = new Database(tm);

            db.update("drop table if exists test_table");
            db.update("create table test_table (text varchar(64))");
            db.update("insert into test_table (text) values ('foo')");

            db.withTransaction(new TransactionCallback<Object>() {
                @Nullable
                @Override
                public Object execute(@NotNull TransactionContext tx) {
                    db.update("update test_table set text='bar'");
                    tx.setRollbackOnly();
                    return null;
                }
            });

            assertThat(db.findUnique(String.class, "select text from test_table"), is("foo"));

        } finally {
            connection.close();
        }
    }
View Full Code Here

    @Test
    public void verifyHasTransaction() throws SQLException {
        Connection connection = dataSource.getConnection();
        try {
            Database db1 = new Database(new SingleConnectionTransactionManager(connection, true));
            assertTrue(db1.hasActiveTransaction());

            Database db2 = new Database(new SingleConnectionTransactionManager(connection, false));
            assertFalse(db2.hasActiveTransaction());

        } finally {
            connection.close();
        }
    }
View Full Code Here

     *
     * @throws org.junit.internal.AssumptionViolatedException if properties were not found
     */
    @NotNull
    public static Database databaseForProperties(@NotNull String propertiesPath) {
        return new Database(createDataSource(propertiesPath));
    }
View Full Code Here

TOP

Related Classes of fi.evident.dalesbred.Database

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.