You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by "Wernke zur Borg (Created) (JIRA)" <ji...@apache.org> on 2012/01/24 14:56:40 UTC

[jira] [Created] (CAY-1655) Logger injection to JdbcAdapter subclass does not work

Logger injection to JdbcAdapter subclass does not work
------------------------------------------------------

                 Key: CAY-1655
                 URL: https://issues.apache.org/jira/browse/CAY-1655
             Project: Cayenne
          Issue Type: Bug
          Components: Core Library
    Affects Versions: 3.1M3
         Environment: Windows 7, MS Access, JdbcOdbc driver
            Reporter: Wernke zur Borg


I created a custom subclass of JdbcAdapter for some special handling with MS Access. It is instantiated by a custom DbAdapterFactory subclass, which is configured as:

		Module m = new Module() {
			public void configure(Binder binder) {
				binder.bind(DbAdapterFactory.class).to(MyCustomDbAdapterFactory.class);
			}
		};

Now the application runs into a NullPointerException in org.apache.cayenne.access.jdbc.SelectAction.performAction() where it says:

adapter.getJdbcEventLogger()...  (line 171)

This means that the injection of the JdbcEventLogger "logger" in my superclass JdbcAdapter has not taken place. It might be important that also SelectAction has been subclassed with a custom SelectAction.

The problem does not occur when I comment the binder.bind(...) line out.

Workaround: Instantiate a CommonsJdbcEventLogger in the custom JdbcAdapter and assign it to the logger (it is protected). But this logger is not aware of the log4j log level. 



--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Closed] (CAY-1655) Logger injection to JdbcAdapter subclass does not work

Posted by "Andrus Adamchik (Closed) (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CAY-1655?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Andrus Adamchik closed CAY-1655.
--------------------------------

    Resolution: Not A Problem

That explains it. "return new MyCustomAdapter(); " is how adapter is created. There's nothing in this code that can perform injection. Looks at DefaultDbAdapterFactory. It does this to create an adapter with dependency injection:

 return objectFactory.newInstance(DbAdapter.class, adapterType);

You might need to do something similar to instantiate your adapter with all the dependencies coming from Cayenne.

I am closing this Jira, as there's no more indication that this is a bug and I hope the above will work.
                
> Logger injection to JdbcAdapter subclass does not work
> ------------------------------------------------------
>
>                 Key: CAY-1655
>                 URL: https://issues.apache.org/jira/browse/CAY-1655
>             Project: Cayenne
>          Issue Type: Bug
>          Components: Core Library
>    Affects Versions: 3.1M3
>         Environment: Windows 7, MS Access, JdbcOdbc driver
>            Reporter: Wernke zur Borg
>
> I created a custom subclass of JdbcAdapter for some special handling with MS Access. It is instantiated by a custom DbAdapterFactory subclass, which is configured as:
> 		Module m = new Module() {
> 			public void configure(Binder binder) {
> 				binder.bind(DbAdapterFactory.class).to(MyCustomDbAdapterFactory.class);
> 			}
> 		};
> Now the application runs into a NullPointerException in org.apache.cayenne.access.jdbc.SelectAction.performAction() where it says:
> adapter.getJdbcEventLogger()...  (line 171)
> This means that the injection of the JdbcEventLogger "logger" in my superclass JdbcAdapter has not taken place. It might be important that also SelectAction has been subclassed with a custom SelectAction.
> The problem does not occur when I comment the binder.bind(...) line out.
> Workaround: Instantiate a CommonsJdbcEventLogger in the custom JdbcAdapter and assign it to the logger (it is protected). But this logger is not aware of the log4j log level. 

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (CAY-1655) Logger injection to JdbcAdapter subclass does not work

Posted by "Andrus Adamchik (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CAY-1655?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13203766#comment-13203766 ] 

Andrus Adamchik commented on CAY-1655:
--------------------------------------

Hi! Our preliminary tests show that injection into superclass works just fine.. So a question. Custom adapter is created indirectly via MyCustomDbAdapterFactory. Is it possible to post the contents of MyCustomDbAdapterFactory to see how it is implemented? This is probably the key to the problem.


                
> Logger injection to JdbcAdapter subclass does not work
> ------------------------------------------------------
>
>                 Key: CAY-1655
>                 URL: https://issues.apache.org/jira/browse/CAY-1655
>             Project: Cayenne
>          Issue Type: Bug
>          Components: Core Library
>    Affects Versions: 3.1M3
>         Environment: Windows 7, MS Access, JdbcOdbc driver
>            Reporter: Wernke zur Borg
>
> I created a custom subclass of JdbcAdapter for some special handling with MS Access. It is instantiated by a custom DbAdapterFactory subclass, which is configured as:
> 		Module m = new Module() {
> 			public void configure(Binder binder) {
> 				binder.bind(DbAdapterFactory.class).to(MyCustomDbAdapterFactory.class);
> 			}
> 		};
> Now the application runs into a NullPointerException in org.apache.cayenne.access.jdbc.SelectAction.performAction() where it says:
> adapter.getJdbcEventLogger()...  (line 171)
> This means that the injection of the JdbcEventLogger "logger" in my superclass JdbcAdapter has not taken place. It might be important that also SelectAction has been subclassed with a custom SelectAction.
> The problem does not occur when I comment the binder.bind(...) line out.
> Workaround: Instantiate a CommonsJdbcEventLogger in the custom JdbcAdapter and assign it to the logger (it is protected). But this logger is not aware of the log4j log level. 

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (CAY-1655) Logger injection to JdbcAdapter subclass does not work

Posted by "Wernke zur Borg (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CAY-1655?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13204429#comment-13204429 ] 

Wernke zur Borg commented on CAY-1655:
--------------------------------------

Ok, now I realised that I do not need an own DbAdapterFactory at all because the default factory can instantiate my custom adapter. I only need to fill in the adapter class in the modeler at the data node.

So far so good. Now I do get the logger injected, but I am still missing the detailed queries in the log when I set the log level to DEBUG. However, this is a different topic, so I am fine with this issue being closed.

Thank you Andrus!
                
> Logger injection to JdbcAdapter subclass does not work
> ------------------------------------------------------
>
>                 Key: CAY-1655
>                 URL: https://issues.apache.org/jira/browse/CAY-1655
>             Project: Cayenne
>          Issue Type: Bug
>          Components: Core Library
>    Affects Versions: 3.1M3
>         Environment: Windows 7, MS Access, JdbcOdbc driver
>            Reporter: Wernke zur Borg
>
> I created a custom subclass of JdbcAdapter for some special handling with MS Access. It is instantiated by a custom DbAdapterFactory subclass, which is configured as:
> 		Module m = new Module() {
> 			public void configure(Binder binder) {
> 				binder.bind(DbAdapterFactory.class).to(MyCustomDbAdapterFactory.class);
> 			}
> 		};
> Now the application runs into a NullPointerException in org.apache.cayenne.access.jdbc.SelectAction.performAction() where it says:
> adapter.getJdbcEventLogger()...  (line 171)
> This means that the injection of the JdbcEventLogger "logger" in my superclass JdbcAdapter has not taken place. It might be important that also SelectAction has been subclassed with a custom SelectAction.
> The problem does not occur when I comment the binder.bind(...) line out.
> Workaround: Instantiate a CommonsJdbcEventLogger in the custom JdbcAdapter and assign it to the logger (it is protected). But this logger is not aware of the log4j log level. 

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (CAY-1655) Logger injection to JdbcAdapter subclass does not work

Posted by "Wernke zur Borg (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CAY-1655?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13204351#comment-13204351 ] 

Wernke zur Borg commented on CAY-1655:
--------------------------------------

Hi Andrus, thanks for testing this.

My factory is as simple as:

public class MyCustomDbAdapterFactory implements DbAdapterFactory {
	public DbAdapter createAdapter(DataNodeDescriptor nodeDescriptor,
			DataSource dataSource) throws Exception {
		return new MyCustomAdapter();
	}
}

My adapter looks like this:

public class MyCustomAdapter extends JdbcAdapter {
	public MyCustomAdapter() {
		this.logger = new CommonsJdbcEventLogger(); // only because logger injection does not work for me
	}
	
    @Override
    public SQLAction getAction(Query query, DataNode node) {
        return query.createSQLAction(new MyCustomActionBuilder(this, node.getEntityResolver()));
    }
}

MyActionBuilder just overrides objectSelectAction() because I need a specific syntax for the SELECT query.



                
> Logger injection to JdbcAdapter subclass does not work
> ------------------------------------------------------
>
>                 Key: CAY-1655
>                 URL: https://issues.apache.org/jira/browse/CAY-1655
>             Project: Cayenne
>          Issue Type: Bug
>          Components: Core Library
>    Affects Versions: 3.1M3
>         Environment: Windows 7, MS Access, JdbcOdbc driver
>            Reporter: Wernke zur Borg
>
> I created a custom subclass of JdbcAdapter for some special handling with MS Access. It is instantiated by a custom DbAdapterFactory subclass, which is configured as:
> 		Module m = new Module() {
> 			public void configure(Binder binder) {
> 				binder.bind(DbAdapterFactory.class).to(MyCustomDbAdapterFactory.class);
> 			}
> 		};
> Now the application runs into a NullPointerException in org.apache.cayenne.access.jdbc.SelectAction.performAction() where it says:
> adapter.getJdbcEventLogger()...  (line 171)
> This means that the injection of the JdbcEventLogger "logger" in my superclass JdbcAdapter has not taken place. It might be important that also SelectAction has been subclassed with a custom SelectAction.
> The problem does not occur when I comment the binder.bind(...) line out.
> Workaround: Instantiate a CommonsJdbcEventLogger in the custom JdbcAdapter and assign it to the logger (it is protected). But this logger is not aware of the log4j log level. 

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (CAY-1655) Logger injection to JdbcAdapter subclass does not work

Posted by "Wernke zur Borg (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CAY-1655?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13204434#comment-13204434 ] 

Wernke zur Borg commented on CAY-1655:
--------------------------------------

Problem solved. Need to set the logger explicitly in my custom SelectTranslator:

translator.setJdbcEventLogger(adapter.getJdbcEventLogger());


                
> Logger injection to JdbcAdapter subclass does not work
> ------------------------------------------------------
>
>                 Key: CAY-1655
>                 URL: https://issues.apache.org/jira/browse/CAY-1655
>             Project: Cayenne
>          Issue Type: Bug
>          Components: Core Library
>    Affects Versions: 3.1M3
>         Environment: Windows 7, MS Access, JdbcOdbc driver
>            Reporter: Wernke zur Borg
>
> I created a custom subclass of JdbcAdapter for some special handling with MS Access. It is instantiated by a custom DbAdapterFactory subclass, which is configured as:
> 		Module m = new Module() {
> 			public void configure(Binder binder) {
> 				binder.bind(DbAdapterFactory.class).to(MyCustomDbAdapterFactory.class);
> 			}
> 		};
> Now the application runs into a NullPointerException in org.apache.cayenne.access.jdbc.SelectAction.performAction() where it says:
> adapter.getJdbcEventLogger()...  (line 171)
> This means that the injection of the JdbcEventLogger "logger" in my superclass JdbcAdapter has not taken place. It might be important that also SelectAction has been subclassed with a custom SelectAction.
> The problem does not occur when I comment the binder.bind(...) line out.
> Workaround: Instantiate a CommonsJdbcEventLogger in the custom JdbcAdapter and assign it to the logger (it is protected). But this logger is not aware of the log4j log level. 

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira