DBCP Unsupported Method

조회수 55회
읽지 않은 첫 메시지로 건너뛰기

Gustavo Bilert

읽지 않음,
2016. 12. 13. 오후 3:34:2216. 12. 13.
받는사람 Ebean ORM
Hi Rob,

EBean calls a method that Apache DBCP does not implement:

DBCP BasicDataSource:

    /**
     * <strong>BasicDataSource does NOT support this method. </strong>
     *
     * @param user Database user on whose behalf the Connection
     *   is being made
     * @param pass The database user's password
     *
     * @throws UnsupportedOperationException
     * @throws SQLException if a database access error occurs
     * @return nothing - always throws UnsupportedOperationException
     */

   
@Override
   
public Connection getConnection(String user, String pass) throws SQLException {
       
// This method isn't supported by the PoolingDataSource returned by
       
// the createDataSource
       
throw new UnsupportedOperationException("Not supported by BasicDataSource");
   
}

EBean MigrationRunner:

  public void run(DataSource dataSource) {

   
String username = migrationConfig.getDbUsername();
   
String password =  migrationConfig.getDbPassword();
   
if (username == null) {
     
throw new IllegalStateException("No DB migration user specified (to run the db migration) ?");
   
}

   
try {
     
Connection connection = dataSource.getConnection(username, password); // <---------------------
      logger
.debug("using db user [{}] to run migrations ...", username);
      run
(connection);

   
} catch (SQLException e) {
     
throw new IllegalArgumentException("Error trying to connect to database using DB Migration user [" + username + "]", e);
   
}
 
}

I think DBCP expects you to call getConnection() without parameters, username and password are probably passed via setter methods.

Could you change it please? It is preventing us from running the migrations.

Obs.: I have not followed the changes related to the multi-tenancy.

Rob Bygrave

읽지 않음,
2016. 12. 13. 오후 3:47:5616. 12. 13.
받는사람 ebean@googlegroups
There was a change to DB Migration such that if you don't specify a username or password it doesn't throw IllegalStateException but instead uses dataSource.getConnection() ... (which is what you are after).

Do you want to check the DB Migration version.

Cheers, Rob.


--

---
You received this message because you are subscribed to the Google Groups "Ebean ORM" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ebean+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Gustavo Bilert

읽지 않음,
2016. 12. 21. 오후 3:45:4116. 12. 21.
받는사람 eb...@googlegroups.com
Hi,

It did not solve the problem.

I managed to work around it by creating an executable:

        MigrationConfig config = new MigrationConfig();
        config
.setMigrationPath("filesystem:dbmigration");
        config
.setDbSchema("testmigration");
        config
.setCreateSchemaIfNotExists(true);

       
MigrationRunner runner = new MigrationRunner(config);

       
BasicDataSource dataSource = new BasicDataSource();
        dataSource
.setUsername("postgres");
        dataSource
.setUsername("postgres");
        dataSource
.setUrl("jdbc:postgresql://localhost:5432/customer");
        dataSource
.setDriverClassName("org.postgresql.Driver");

        runner
.run(dataSource);

But then I have another problem:

2016-12-21 18:39:28 [main] INFO  o.a.d.runner.MigrationSchema - Migration Schema: testmigration
2016-12-21 18:39:28 [main] INFO  o.a.d.runner.MigrationSchema - Creating Schema: testmigration
2016-12-21 18:39:28 [main] INFO  o.a.d.runner.MigrationSchema - Setting Schema: testmigration
2016-12-21 18:39:28 [main] ERROR java.lang.RuntimeException - org.postgresql.util.PSQLException: ERROR: syntax error at or near "testmigration"
 
Position: 12
java
.lang.RuntimeException: org.postgresql.util.PSQLException: ERROR: syntax error at or near "testmigration"
 
Position: 12
    at org
.avaje.dbmigration.MigrationRunner.run(MigrationRunner.java:84)
    at org
.avaje.dbmigration.MigrationRunner.run(MigrationRunner.java:43)
    at com
.sollar.customer.RunMigrations.run(RunMigrations.java:27)
    at com
.sollar.customer.RunMigrations.main(RunMigrations.java:31)
    at sun
.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun
.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun
.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java
.lang.reflect.Method.invoke(Method.java:498)
    at com
.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
Caused by: org.postgresql.util.PSQLException: ERROR: syntax error at or near "testmigration"
 
Position: 12
    at org
.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2182)
    at org
.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1911)
    at org
.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:173)
    at org
.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:645)
    at org
.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:495)
    at org
.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:488)
    at org
.apache.commons.dbcp2.DelegatingPreparedStatement.execute(DelegatingPreparedStatement.java:198)
    at org
.apache.commons.dbcp2.DelegatingPreparedStatement.execute(DelegatingPreparedStatement.java:198)
    at org
.avaje.dbmigration.runner.MigrationSchema.setSchema(MigrationSchema.java:83)
    at org
.avaje.dbmigration.runner.MigrationSchema.createAndSetIfNeeded(MigrationSchema.java:45)
    at org
.avaje.dbmigration.MigrationRunner.run(MigrationRunner.java:76)
   
... 8 common frames omitted

It is because SET SCHEMA needs quotes like 'testmigration'

MigrationSchema line 81


Could you change it please?


Thanks, Gustavo
To unsubscribe from this group and stop receiving emails from it, send an email to ebean+un...@googlegroups.com.

Rob Bygrave

읽지 않음,
2016. 12. 21. 오후 4:01:0916. 12. 21.
받는사람 ebean@googlegroups

> MigrationSchema line 81

Yes, that should change to use connection.setSchema() really. 


> It did not solve the problem.

Can you clarify what you did.  I'm thinking you bumped the migration version?  What version are you using? 



Note that it is 22nd Dec so we running out of "runway" for changes until Jan 9th now (i.e. starting the Xmas summer break here).


Cheers, Rob.



To unsubscribe from this group and stop receiving emails from it, send an email to ebean+unsubscribe@googlegroups.com.

Rob Bygrave

읽지 않음,
2016. 12. 22. 오전 5:34:3616. 12. 22.
받는사람 ebean@googlegroups
For the set schema issue ... logged as https://github.com/ebean-orm/ebean-dbmigration/issues/8

Released as ebean-dbmigration version 10.1.2
전체답장
작성자에게 답글
전달
새 메시지 0개