Package org.apache.cayenne.dba

Examples of org.apache.cayenne.dba.JdbcAdapter


    public void testRunAsIndividualQueriesOptimisticLockingFailure() throws Exception {
        EntityResolver resolver = runtime.getDataDomain().getEntityResolver();

        // test with adapter that supports keys...
        JdbcAdapter adapter = buildAdapter(true);

        DbEntity dbEntity = resolver
                .lookupObjEntity(SimpleLockingTestEntity.class)
                .getDbEntity();
View Full Code Here


        assertEquals(0, mockConnection.getNumberCommits());
        assertEquals(0, mockConnection.getNumberRollbacks());
    }

    JdbcAdapter buildAdapter(boolean supportGeneratedKeys) {
        JdbcAdapter adapter = new JdbcAdapter();
        adapter.setSupportsGeneratedKeys(supportGeneratedKeys);
        injector.injectMembers(adapter);
        return adapter;
    }
View Full Code Here

    public void testHasGeneratedKeys1() throws Exception {
        EntityResolver resolver = runtime.getChannel().getEntityResolver();

        // test with adapter that supports keys
        JdbcAdapter adapter = buildAdapter(true);

        InsertBatchQuery batch1 = new InsertBatchQuery(resolver.lookupObjEntity(
                GeneratedColumnTestEntity.class).getDbEntity(), 5);
        assertTrue(new BatchAction(batch1, adapter, resolver).hasGeneratedKeys());
View Full Code Here

    public void testHasGeneratedKeys2() throws Exception {
        EntityResolver resolver = runtime.getChannel().getEntityResolver();

        // test with adapter that does not support keys...
        JdbcAdapter adapter = buildAdapter(false);

        InsertBatchQuery batch1 = new InsertBatchQuery(resolver.lookupObjEntity(
                GeneratedColumnTestEntity.class).getDbEntity(), 5);
        assertFalse(new BatchAction(batch1, adapter, resolver).hasGeneratedKeys());
View Full Code Here

                Artist.class).getDbEntity(), 5);
        assertFalse(new BatchAction(batch2, adapter, resolver).hasGeneratedKeys());
    }

    JdbcAdapter buildAdapter(boolean supportGeneratedKeys) {
        JdbcAdapter adapter = new JdbcAdapter();
        adapter.setSupportsGeneratedKeys(supportGeneratedKeys);
        return adapter;
    }
View Full Code Here

    @Inject
    protected DbAdapter adapter;

    private DeleteBatchQueryBuilder createBuilder() {
        return createBuilder(new JdbcAdapter());
    }
View Full Code Here

            DeleteBatchQuery deleteQuery = new DeleteBatchQuery(
                    entity,
                    idAttributes,
                    null,
                    1);
            JdbcAdapter adapter = (JdbcAdapter) this.adapter;
            DeleteBatchQueryBuilder builder = createBuilder(adapter);
            String generatedSql = builder.createSqlString(deleteQuery);

            String charStart = adapter.getIdentifiersStartQuote();
            String charEnd = adapter.getIdentifiersEndQuote();

            assertNotNull(generatedSql);
            assertEquals("UPDATE "
                    + charStart
                    + entity.getName()
View Full Code Here

    public void testUpdate() throws Exception {

        final DbEntity entity = context.getEntityResolver().lookupObjEntity(
                SoftTest.class).getDbEntity();

        JdbcAdapter adapter = (JdbcAdapter) this.adapter;
        BatchQueryBuilderFactory oldFactory = adapter.getBatchQueryBuilderFactory();
        try {
            adapter.setBatchQueryBuilderFactory(new SoftDeleteQueryBuilderFactory());

            final SoftTest test = context.newObject(SoftTest.class);
            test.setName("SoftDeleteBatchQueryBuilderTest");
            context.commitChanges();

            final SelectQuery query = new SelectQuery(SoftTest.class);

            new ThreadedTestHelper() {

                @Override
                protected void assertResult() throws Exception {
                    query
                            .setQualifier(ExpressionFactory.matchExp("name", test
                                    .getName()));
                    assertEquals(1, context.performQuery(query).size());

                    query.andQualifier(ExpressionFactory.matchDbExp("DELETED", true));
                    assertEquals(0, context.performQuery(query).size());
                }
            }.assertWithTimeout(200);

            context.deleteObjects(test);
            assertEquals(test.getPersistenceState(), PersistenceState.DELETED);
            context.commitChanges();

            new ThreadedTestHelper() {

                @Override
                protected void assertResult() throws Exception {
                    query
                            .setQualifier(ExpressionFactory.matchExp("name", test
                                    .getName()));
                    assertEquals(0, context.performQuery(query).size());

                    SQLTemplate template = new SQLTemplate(
                            entity,
                            "SELECT * FROM SOFT_TEST");
                    template.setFetchingDataRows(true);
                    assertEquals(1, context.performQuery(template).size());
                }
            }.assertWithTimeout(200);
        }
        finally {
            context.performQuery(new SQLTemplate(entity, "DELETE FROM SOFT_TEST"));
            adapter.setBatchQueryBuilderFactory(oldFactory);
        }
    }
View Full Code Here

    @Override
    public void execute() {

        // prepare defaults
        if (adapter == null) {
            adapter = new JdbcAdapter();
        }

        log("connection settings - [driver: "
                + driver
                + ", url: "
View Full Code Here

        super.setUp();
        deleteTestData();
    }

    public void testProperties() throws Exception {
        DbAdapter adapter = new JdbcAdapter();
        SQLTemplate template = new SQLTemplate(Object.class, "AAAAA");
        SQLTemplateAction action = new SQLTemplateAction(template, adapter, getDomain()
                .getEntityResolver());
        assertSame(adapter, action.getAdapter());
        assertSame(template, action.getQuery());
View Full Code Here

TOP

Related Classes of org.apache.cayenne.dba.JdbcAdapter

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.