My real question is about how to look up the expectations on the methods (the 'contract' for a method) in Spring. I keep hitting questions, where unless I find some blogger or a stack-overflow that addresses that specific issue, there seems to be no informative documentation. Am I looking the wrong places? Do I need to buy some book?
In the current specific case: I have working looking up a user/password by making my SQL table map to Spring's defaults, but when a user is absent it's hitting a null pointer exception. I see JdbcUserDetailsManager's "void setUserExistsSql( anSQLString)", and I want to know if that sql-string should return a boolean? a null? and what it should be 'named.' Googling is not turning up any usage examples, nor any documentation. The javadocs I'm finding are uncommented. I can guess-and-test, but it seems there should be a better way to look-it-up?
Ok, I've been working with spring since version 1, and many other open-source projects follow the same pattern. Documentation is hard and expensive to produce, and programmers donating their time for free often don't want to write it. Spring though is one of the better projects as far as documentation is concerned.
However, I've always found it necessary to link spring's source code into my project. If you're using maven you can download the sources along with the jars, and tools like IntelliJ (and probably eclipse) will allow you to drill down into the source and to trace its execution with their debuggers.
With these types of projects it is almost always necessary at some point to drill down and read the source, and that's a good thing because the source is always up to date and always exactly describes the behaviour you're trying to use. Documentation on the other hand is often badly written using an informal language (e.g. English) and it can never accurately describe anything, especially if it's being written or read by someone who isn't a native speaker, which is often the case.
So, to answer your question -- look to the source.
Related
The question is whether the functionality I describe below already exists, or whether I need to make an attempt at creating it myself. I am aware that I am probably looking at a lot of work if it does not exist yet, and I am also sure that others have already tried. I am nevertheless grateful for comments such as "project A tried this, but..." or "dude D already failed because...". If somebody has an overall more elegant solution, that would of course be welcome as well.
I want to change the way I develop (private) Java code by introducing a multiplexing layer. What I mean by that is that I want to be able to create library-like parameterizable AST-snippets, which I want to insert into my code via some sort of placeholders (such as annotations). I am aware of project https://projectlombok.org/ and have found that, while I find it useful for small applications, it does not generally suit my requirements, as it does not seem possible to insert own snippets without forking the entire project and making major modifications. Also lombok only ever modifies a single file at a time, while I am looking for a solution that will need to 'know' multiple files at a time.
I imagine a structure like this:
Source S: (Parameterizable) AST-snippets that can be included via some sort of reference in Source A.
Source A: Regular Java-Code, in which I can reference snippets from Source A. This code will not be compiled directly, as it is lacking the referenced snippets, and would thus throw a lot of compile time exceptions.
Source T: Target Source, which is an AST-equivalent copy of Source A, except that all references of AST-Snippets have been replaced by their respective Snippet from Source S. It needs to be mappable to the original Source A as well as the resolved snippets from Source S, where applicable, as most development will happen there.
I see several challenges with this concept, not the least of which are debuggability, source-mapping and compatibility with other frameworks/APIs. Also, it seems a challenge to work around the one-file-at-a-time limitation, memory wise.
The advantage over lombok would be flexibility, since lombok only provides a fixed set of snippets for specific purposes, whereas this would enable devs to write own snippets, or make modifications to getters, setters etc. Also, lombok 'quirks' into the compilation step, and does not output the 'fused' source, afaik.
I want to target at least javac and eclipse's ecj compilers.
I'm using RDF4J as I got caught by the advertised implementation of GEOSPARQL (which I didn't find in other RDF frameworks). I followed basic guides and tutorial, but unfortunately I haven't been able to perform basically any of the advertised queries.
I read and followed all the documentation at http://docs.rdf4j.org/programming/#_geosparql, and all the examples at http://graphdb.ontotext.com/documentation/standard/geosparql-support.html, and at https://portal.opengeospatial.org/files/?artifact_id=47664. The only spatial function that seemed to work in a SPARQL query is the geof:distance, all the others do not produce any results.
So I ultimately dug into the code in the package org.eclipse.rdf4j.query.algebra.evaluation.function.geosparql to kind of understand that there are some classes and interfaces that I should probably implements and extends, e.g. SpatialAlgebra, SpatialSupport, SpatialSupportInitializer. It looks like many of the function are not completely (or partially) implemented in the spatial logic. Apparently, there is a DefaultSpatialAlgebra which returns a lot of notSupported. Anyway, it's quite a mess (and undocumented) understanding what's the right procedure to have GEOSPARQL working properly. They only say that you can implement your own SpatialSupportInitializer, but how to use it afterwards is a mystery.
From the documentation, apparently there's also a way by using other SAILs, but again, nothing is clear about that.
Can anybody provide me with some guidance, or at least a snippet of code where it is shown how to actually pass to the engine a SpatialAlgebra or SpatialSupport or SpatialSupportInitializer, which is not the default one? Or is there any already existing SAIL which implements all these methods, and how can I use it? Thanks.
PS: I'm actually relying on the 2.4.0 M2 version of RDF4J, which doesn't seem to have the org.eclipse.rdf4j.query.algebra.evaluation.function.geosparql package inside (which I imported manually). I tried also with version 2.3.1, but I had the same issue.
Update Since RDF4J 2.4.0-M3, GeoSPARQL function support is a lot more comprehensive. The improved documentation gives a full list of all supported functions, as well as, hopefully, a better explanation on how to get started with GeoSPARQL. The short and sweet of it is that all you need to do is add this maven module:
<dependency>
<groupId>org.eclipse.rdf4j</groupId>
<artifactId>rdf4j-queryalgebra-geosparql</artifactId>
<version>2.4.0-M3</version>
</dependency>
and you're good to go to use GeoSPARQL on any kind of RDF4J repository.
There are several other GeoSPARQL functions supported by RDF4J out of the box: apart from distance, union, intersection, symDifference, difference, convexHull, boundary, envelope, and getSRID are also at a minimum supported. sfContains is currently not part of the default set, unfortunately. This is mostly due to a licensing issue RDF4J had with a previous version of the JTS library (required for polygon support). However, more recent JTS releases are done as part of the LocationTech project, and those license issues have cleared up, so we should hopefully be able to extend this in the near future (there's an issue tracking this at https://github.com/eclipse/rdf4j-storage/issues/89).
In the meantime you will indeed need to create your own `SpatialAlgebra` class, which you can add to RDF4J by means of a `SpatialSupportInitializer`. This is a bit of a workaround hack, but you should create a class with `org.eclipse.rdf4j.query.algebra.evaluation.function.geosparql.SpatialSupportInitializer` as its fully-qualified name, and make sure that it extends the `org.eclipse.rdf4j.query.algebra.evaluation.function.geosparql.SpatialSupport` abstract class, overriding its `getSpatialContext` and `getSpatialAlgebra` methods to provide your custom variants. Add to your classpath and restart, RDF4J will pick this up and use your `SpatialAlgebra` implementation instead of its own.
The bottom line is: this is all very beta. To be frank, if you think you could handle implementing additional GeoSPARQL functions using the workaround I mentioned above, then we would love to have your input (and if possible also your help) in actually adding this to RDF4J itself.
The manual for OpenJML (http://jmlspecs.sourceforge.net/OpenJMLUserGuide.pdf) intimates that static-checking of Java compilation units can be done programmatically.
Unfortunately, the manual entry for static-checking (Section 5.2.4) is empty, and no specific examples appear to be given for this.
Does anyone know of a simple example?
Unfortunately I cannot help you out for OpenJML, even in the new version of the manual, the section you refer to is empty.
However, you could try other tools such as the KeY program verifier with which you can statically prove your JML annotations correct, either using KeY as a front-end or also programmatically as a back-end. The code at the page referred to, which presents the programmatic usage of the symbolic execution API of KeY may be look quite intimidating at the first glance, but it contains a lot of boilerplate which you might actually not need because the available all options are explained.
For verification (aka "static checking"), you could look into the "key.core.example" package in the current source distribution which should get you started.
As for my knowledge, OpenJML and KeY are the currently only actively maintained tools for statically checking JML annotations. There were others, such as ESC/Java2 and KRAKATOA, but they seem to be outdated. KeY is actively maintained, but does not cover all of the Java language in contrast to OpenJML (maybe there will be LLVM or bytecode versions in the future, since there are corresponding plans, then the situation might improve).
As per the Hibernate Documentation, hibernate has a property called hibernate.bytecode.use_reflection_optimizer and the doc says:
Enables the use of bytecode manipulation instead of runtime
reflection. This is a System-level property and cannot be set in
hibernate.cfg.xml. Reflection can sometimes be useful when
troubleshooting. Hibernate always requires javassist even if you turn
off the optimizer.
e.g. true | false
What is byte code manipulation and runtime reflection and how hibernate uses it. Can someone please help m in understanding this. Also how reflection is useful for troubleshooting?
That's a bit too much for one question. Also the required level of detail to sufficiently answer the last part of your problem would probably be too advanced given the fact that the rest of your question is rather basic.
What is byte code manipulation and runtime reflection?
If you've never heard about byte code manipulation & reflection before I suggest you start exploring it yourself, utilizing the search engine of your choice. If you have any concrete question about either topic you are more than welcome to post it here at SOF.
how hibernate uses it
For the second part of your question I suggest looking at the Hibernate documentation and e.g. highlight the usage of "bytecode". This should give you a basic understanding of where it's being used. Again, get back to SOF with any concrete question.
Also how reflection is useful for troubleshooting
In a nutshell: Because you can use your IDE to debug and e.g. inspect variables - something you cannot do if the IDE sits on top of modified bytecode. At least not easily. But this should hopefully be much clearer after your own research.
Developers who have used eclipse cannot miss out the Cntrl+Shift+G combo - the easiest way to find all references to a particular member/method/class in your workspace.
Consider a scenario where you are a new guy maintaining a web application written in java. Now, you are about to change a method signature, and you do a Cntl+Shift+G to find all references to the said method (yes, hoping that you are not doing depedency injection / reflection etc). However, a new guy, would want not to screw up any functionality in the application. How would ensure that the functional dependencies are not affected?
I guess..the question is a bit unclear.. lemme rephrase... Say you are changing something functional (an if loop in a business rule or whateva) - this will definetly CHANGE something else in the context of the application.. and at this point you wish there was something (a plugin?) in eclipse, that would tell you - "hey noob..don't change this - it would affect this..." - Now, if you were to create something that does this for eclipse (plugin?) - where would you start? (tagging parts of scr code and introducing a depdency tree? etc?)
Perhaps I failed to understand your question, but I think I might have an answer. Take a look at nWire for Java (or PHP). It is a plugin for code exploration. Focusing on a piece of code, the developer can quickly determine where the method is invoked, where the class is used, etc. This makes it easier to understand what you are about to change.
I am the developer of this plugin. If it is not exactly what you are looking for, let me know, I'll be happy to better understand what you are looking for.
Besides: ALT+SHIFT+C is the way to change a method signature. ALT+SHIFT+G "only" finds references, which is helpful of course.
vickirk mentionend the most important aspect here: Without having tests and a good code coverage you aren't able to apply any changes without risking a failing system afterwards.
The book "Working Effectively with Legacy Code" from Robert C Martin explains it nicely: All code, which is not covered by tests, is legacy code. You could draw the conclusion, that before you apply any functional change you need to ensure a sufficient test coverage.
Tagging parts in the source code seems like a bad idea, since these tags need to be additionally maintained, which usually never really happens in projects. :)
What about JDepend?