iam begineer in ejb's.I have one doubt in ejb 2.0,In session beans,i will create() with out args in EJBhome.But i didn't define any methods i.e., ejbcreate and ejbremove in the bean.So,Can i compile or run this code without those method in the bean?.
You can compile it but cannot run it. You must have a matching ejbCreate() method in your bean class.
If you are very new to EJB I recommend testing your code with OpenEJB (here's a getting started video). Not because I work on the project (which I do), but because we aggressively check code for mistakes and will print clear errors as to what you might have done wrong.
The output can come in 3 levels of verbosity. On the most verbose level, the output is more email response oriented and error messages include information like "put code like this -code-sample- in your bean." The code samples even try to use your method names and parameter names where possible.
As well it is compiler style. Meaning if you made the same mistake in 10 places, you will see all 10 in the first run and then have the opportunity to fix them all at once. Rather than the traditional style of fix 1 issue, compile, test, get same error elsewhere in code, repeat N times.
And of course you can still deploy into another EJB container. Sounds like you are stuck using a pretty old one if you have to use EJB 2.0.
Here's a list of some of the mistakes that are checked
Related
I found many languages provides some way to change code runtime. Many people ask queries regarding how to change code in this or that language runtime. Here I mean by change code is that rewrite code itself at runtime by using reflection or something else.
I have around 6 year of experience in Java application development. I never come again any problem where I have to change code at time.
Can anyone explain why we require to change code at runtime?
I have experienced three huge benefits of changing code at runtime:
Fixing bugs in a production environment without shutting down the application server. This allowed us to fix bugs on just some part of the application without interrupting the whole system.
Possibility of changing the business rule without having to deploy a new version of the application. A quicker deploy of features.
Writing unit test is easier. For example, you can mock dependencies, add some desired behaviour to some objects and etc. Spock Framework does well this.
Of course, we had this benefits because we have a very well defined development process on how to proceed on this situations.
At times you may need to call a method based on the input, that was received earlier in the program.
It could be used for dynamic calculation of value based on the key index, where every key is calculated in a different way or calculation requires fetching required data from different sources. Instead of using switch statement you can invoke a method dynamically using methodName+indexOfTheKey.
I'm currently learning TDD and have finished reading a book. Now that I'm about to start an ASP.NET MVC project, it seems its hard to do the "no code without failing test rule", at least in terms of starting.
Should I add the needed folders at the start like Controllers, and any other infrastructure-related files? Just add them? It seems its hard to start, does everything need to fail a test first? And how do I do it for the front-end? It seems its quite complicated when its not the business logic being tested. Could you guys point me to some resources for employing TDD for Views/Front-end?
In order to have a failing test, the test must be run. In order to be able to run the test, the unit test project must be able to compile. Therefore you should add the Controllers folder and at least a controller and an action. This is, IMHO, the bare minimum.
Write the first action with a single throw new NotImplementedException(); line of code.
Then write a test that exercises the method and asserts that the result is not null or of a given type (for example ViewResult type).
Now run the test and see it fails. The TDD supporters will cheer in the arena.
Next you can replace the single line of code (the not implemented exception) with a bit of actual code and repeat.
VS2015 shows how many references there are to a class.
However if the class is started by WebApplication.Run the references are not shown.
The highlighted code does get executed when the application is run.
Is there any way to get the reference count for the Configure method?
Here are two reasons ;)
The Startup Class is invoked by reflection (it does not implement an interface)
I doubt that code pieces outside of your local source code will influence the reference count. So even if somewhere deep in WebApplication.Run the Configure method is invoked (assuming directly over some magic interface), the reference code will not rise. Make sense, otherwise the counter for string would have overflow ;)
Because I rush in development (a lot of whip cracking here) and declare my objects at the top of the function and instantiate inside my try-catch block, I get a lot of the good old "object not set to an instance of an object" errors while doing TDD, and later if I do miss a branch that object was used in (doing VB now, would prefer C#) or just in every day coding, object not set to an instance of an object is a bit vague. Sure the stack trace sends me to the line the error occured at, but it would be nice if I could modify my logging to either name the object or its type because sometimes I have multiple objects on the same line. It's not the end of the world, but in the end it would save me a few minutes each day. Any ideas on how I can pass the info on which object wasn't set? Thanks
It is non trivial to "modify your logging" to output variable name or type - I am sure that if the framework could easily get this information from the executing IL, MS would have included it the null reference exception.
Prevention is always better than cure. Here are a couple of tips I would do
Fix your compiler warnings
C# would generate a compile error if it detects that there are code paths that could use an unassigned local variable. [For some odd reason] VB.Net will still compile but the compiler will generate a warning - take heed of these and go and fix the code and you should never run into the problem of unassigned variables again!
Adopt a different coding pattern for variable declaration
I appreciate that method variable scope in ye olde VB was that the variable was visible throughout the entire method regardless of where it was defined. As a result, it was a reasonable practice to put all your var declarations at the top of the method. VB.Net of course is different - you can only use variables after they are declared and so it is OK (and I would say preferable*) to put the declaration (and assignment) closer to where the variable is actually used. This should help you see "by eye" if your program logic means it is possible to use an unassigned variable.
Some people think this is a think that it is always good practice to put variable declarations in a block at the top of the method. I will not argue against them but I would say that that approach works best with small methods that do not use lots of variables.
I have a biztalk (2006 R2) map which uses an class to provide for some custom logic that we couldn't achieve neatly through the existing functoids.
When an exception is thrown from one of the methods of this class the exception detail is, unfortunately lost (at least as far as I can see), The transform shape simply throws an exception indicating 'Function 'ScriptNS-:DoFoo()' has failed'
I've since come to the conclusion that using the Scripting functoids in a map is a recipe for disaster, but thats another discussion. My question is is there a mechanism to allow the exception detail pass up the parent orchestration?
Try to use the 'System.Diagnostics.Trace' class and output stuff inside the method related to its progress. Start with outputting the input parameters as they might differ from what your method expect.
Simplified example:
System.Diagnostics.Trace.WriteLine("HelperClass XX - Method YY - This was passed from the map : " + inputParamOne);
Using a clear naming standard makes it easier to filter inside free tool DebugView, especially when on a machine running more than your stuff. I often leave this tracing in as it often proves invaluable later on. The overhead, if no listener is connected, could normally be ignored.
If you have the map deployed and running on a BizTalk development machine you could debug by performing the following steps:
Put a breakpoint in the method
Select 'Debug - Attach To Process'
Attach to the HostInstance process
(BTSNTSvc.exe if 32-bit) handling
your corresponding port or
orchestration running the map.