Where to put validation logic...

Hi,
We have a lot of validation logic in our database. Next to the normal foreign key, check, unique constraints, we use triggers for validation (which throw errors with custom error codes when needed).
On top of the database we are building a fairly large JClient based application using the BC4J framework. BC4J offers the possibility to use validation beans for validating the entity row. We are wondering if we should use this. If we implement the validation logic for each entity we are actually duplicating the validation logic that's already available in the database. And some database constraints are easily implemented using the standard validation beans (like not null and unique checks), but more complex validation rules can sometimes only be done in the database (so we need to use the database for validation using a method validation bean).
Like I said this means a lot of duplicating validation logic. Which first of all is an inefficient thing to do. Second validation logic can change over time, which means we need to change the logic on two places. It's easy to forget to change the logic on one place.
We found a way to somewhat use the database validation logic for validating entity rows. We just simple insert a row in the database and post the changes. If the new row contains an error an exception is thrown. This JBO exception contains a reference to the SQL exception. Which can be used to retrieve the database error code. Unfortunately we have not found a good way (yet) to find out where the error occured (in which trigger for example). Error codes don't have to be unique so it's important to know in which context they occured. Another problem with this method is we can't do an early validate on a limitted set of row data. E.g. we sometimes use wizards in our application for adding new rows. We really want to check the data after each step in the wizard (step by step). This is ofcourse impossible with the database logic. This means we again need to create the same validation logic again. I don't think it's even possible to use the row.validate() method for this (and ofcourse implement the validation logic in the entity too), because this method validates the complete row.
In short, where is the best way to put validation logic? And (how) can this be done without duplicating (to much) logic?
Regards,
Peter
P.S.
Does anyone know how to retrieve the context of an SQL exception?

Do you users have access to the data/tables outside
of using your application? (as in using sqlplus?)Not at the moment.
Ideally the database should just be going
constraint--data integrity type of checks. The
business rules would be in the business layer not
persitance layer..So in this case, they would be in
the bc4j entity objects.. Well most of them are simple integrity constraints, but sometimes we have to check things using triggers which are way more complicated and need extensive database access. It's more logical to do that in the database. If the trigger runs into a problem it raises an application error. We are hoping we can use this error somehow in our application.
That assumes that the only way a user can modify that
data is through your application only.Well it is, and if another application is written for it the BC4J entities etc. will probably be re-used, but like I said there are other reasons for not having all the business-rules in the BC4J layer.
by the way, are you migrating an existing application
that already has all the business rules in the
database?No, it's a brand new application, but we started out with defining a lot of business rules in the database because that seems a more logical place to put them (to us). I understand that some business-rules can better be implemented in the BC4J entities, but it's not that easy for every business rule we have.
Regards,
Peter

Similar Messages

  • Where to put Validation Code?

    Up until now, Im still having second-thoughts of where to put validation code when setting attributes of an entity.
    Right now I have created lots of custom validators --(implement JbovalidatorInterface) that calls stored procedures to validate the value entered. But sometimes, i just use a ViewObject and query it on the setterAttribute method of the Entity and just manually throw a JboException of the value is invalid based on some business rule.
    Question is, what are the best practices where to put validation codes? do we have to be strict that we always put all validations on Validators or are we free to just throw JboExceptions anywhere on the BC classes' code.
    regards,
    Anton

    1. The reason I have a custom validator and I don't normally use the built in declarative validators is that the error message generated when the validation fails is fixed, only one message. I decided to have create a custom validator is that I need to test a one attribute for many cases in each case should produce a distinct error message. So if I use the built in validators, I would have to create lots of built in validators for that single attribute only. (and i have lots of entities and lots of attributes that needs business rule validation). So, I decided to create a custom validator, that calls the stored procedure, the stored procedure takes care of all test cases, for that attribute only, and I can return a dynamic error message depending on the test case that failed. What do you think about the approach?
    It's a little extra work to create a reusable validator class that will only be used once, but whether you do it that way or encapsulate the call in a helper class that your one-off method validator code delegates too, it seems similar to me. So it's more of a stylistic choice for you which you like better. Now, if your reusable validator were enable to encapsulate
    2. When I said anywhere; I meant inside the setterAttribute methods on the Entity and on the ViewRowImpl, orThe ViewImpl class or inside a method on an ApplicationModule?
    Rather than writing code in the setAttribute, I recommend using attribute-level method validators. This makes it more clear where all your validation code lives.
    I don't recommend performing validation in the view object level since entity objects are the component in the system that are tasked with handling validation. It would be easy to circumvent view level validation checks unless you make a lot of assumptions about exactly how your application is working.
    3. One other issue is that Validator methods are for validation purposes only. So its not a good idea to put in attribute setters to other attributes inside there. So you put the attribute setter logic outside of the validator usually inside the setAttribute() just after validator returns. But there are cases that is very straightfoward to put validation logic inside the setAttribute; meaning, inside the setAttribute() method, I test for a condition, if it fails, just throw a JboException, if its true, continue with the otherAttributes setter logic.
    Whether attribute setting of other attributes is performed in a setter method or in an attribute-level method validator, either way you will need conditional logic to avoid going into a validation "loop" (which eventually will throw an exception if after 10 attempts the object is still not valid at posting time.

  • Where to put the logic!

    Hello everybody!
    I have a big doubt and so does my CIO.
    I'd like to develop Web Services using the facade pattern (Entity + Session). I prefer to put the business logic into the stateless EJB and just go to the database to insert, update or delete records.
    But the boss says it would be better just to develop a pl SQL (Oracle) that has all the business logic into it and just make the call from the Stateless.
    Is there a general approach? What do you recommend?
    Thank you very much!

    Hi,
    in my experience it is better to put the logic in the bean itself.Because if we want to change the database later, it would be very easier.

  • Where do we put Validations in Internet Sales Application

    Where do we put validation on user input data in ISA.
    like in Actions,BO,BE.Please tell where exactly we do it.
    I need to compare Sold to Party with Ship to Party and Bill to Party.Any idea how i can do it.

    There was some problem from crm side....It working now

  • Need to put a logic in FDM where by accounts and ICP is compared and accord

    Hello ,
    Need to put a logic in FDM where by accounts and ICP is compared and accordingly ICP field is modified. Need to create an array of accounts
    Scenario:
    ICP needs to be derived based on account code. If account code is part of a predetermined list then further logic needs to be executed.
    For ex. If Acc is part of the account list ("7880","7881","7882","7883","7340","7341",
    "7342","7343","7345","7347","7346","8460","8603","8484","8610","8611","8612","8614")
    then if ICP <> 00000 then ICP = strfield
    else if Acc not part of list then ICP = "00000".
    We are facing issues in defining and referencing an array in FDM which would store the list of accounts code which can then be compared along with ICP. The other logic is as follows
    If strField <> "00000" And Val = Acc_Arr(i) Then
    T3 = strfield
    End If
    If strField = "00000" And Val = Acc_Arr(i) Then
    T3 = "ICPENT"
    End If
    If strField <> "00000" And Val <> Acc_Arr(i) Then
    T3 = "00000"
    End If
    If strField = "00000" And Val <> Acc_Arr(i) Then
    T3 = "00000"
    End If
    Regards,

    Hi,
    Two options:
    1. You can evaluate ICP based on either source account or target account. Use varValues(13) for source account and varValues(14) for target account in the conditional mapping statement for ICP.
    2. A faster performing option is to concatenate the Account and ICP into a single code, which you then import in the ICP dimentsion. You can then use simple mapping rules to do your ICP mappings and avoid conditional statements altogether.
    Regards,
    Vlado

  • Oaf: putting validation in VO based on sql query

    Hi All,
    I need few inputs for the customization of OAF page.
    Business Need: Restriction of special character in supplier oaf pages for supplier name.
    There are 3 oaf pages involved in supplier creation/update for R 12.1.3
    1)     oracle\apps\pos\supplier\webui\OrganizationPG (underlying VO is sql query based).
    2)     oracle\apps\pos\supplier\webui\QuickUpdatePG (underlying VO is sql query based).
    3)     oracle\apps\pos\supplier\webui\SuppCrtPG (underlying VO is based on EO - HzPuiOrgProfileQuickEOEx) .
    For pages referring EO, we have extended the underlying EO and override the validateEntity() method to throw the OAAttrValException. After substitution, validation is working.
    For VO based on query, the standard AM’s are instantiating the VO and using Rowimpl class they are setting the attributes.
    Question: How to enforce validation logic in VO or AM in such cases where oracle standard code is instantiating the VO dynamically?
    One possible solution is to use the PPR event on input text message bean and catch it in custom controller’s processFormRequest method and before super. processFormRequest(), we can put the validation.
    Is there any other way to achieve it?

    VO extension will not work as the
    Standard Controller code : oracle.apps.pos.supplier.webui.QuickUpdateCO is calling the AM's method on the click of save button and AM is dynamically invoking the methods in VO.
    Standard Controller code:
    OAApplicationModule oaapplicationmodule = oapagecontext.getApplicationModule(oawebbean);
    if(oapagecontext.getParameter("btnSave") != null)
    oaapplicationmodule.invokeMethod("updateVendor");
    oaapplicationmodule.invokeMethod("updateVendorSites");
    oaapplicationmodule.getTransaction().commit();
    Corressponding standard standard AM code...
    CallableStatement callablestatement;
    Exception exception;
    oadbtransaction = getOADBTransaction();
    connection = oadbtransaction.getJdbcConnection();
    Object obj = null;
    oaviewobjectimpl = (OAViewObjectImpl)findViewObject("SupplierVO");
    callablestatement = null;
    try
    callablestatement = oadbtransaction.createCallableStatement(" BEGIN savepoint upd_vndr_ab ; END;", 0);
    callablestatement.executeQuery();
    catch(SQLException sqlexception1)
    throw OAException.wrapperException(sqlexception1);
    finally
    if(callablestatement == null) goto L0; else goto L0
    if(callablestatement != null)
    try
    callablestatement.close();
    catch(SQLException sqlexception) { }
    break MISSING_BLOCK_LABEL_97;
    try
    callablestatement.close();
    catch(SQLException sqlexception2) { }
    throw exception;
    VendorsVORowImpl vendorsvorowimpl;
    label0:
    oaviewobjectimpl.reset();
    vendorsvorowimpl = (VendorsVORowImpl)oaviewobjectimpl.first();
    String s = vendorsvorowimpl.getPosModified();
    String s1 = vendorsvorowimpl.getHzModified();
    Number number = vendorsvorowimpl.getVendorId();
    int i = number.intValue();.....
    Extending the VO will not server the good as the handle will not be given to extended class....
    Edited by: user13791631 on Jun 20, 2012 9:29 PM

  • Putting validation in VO based on sql query

    Hi All,
    I need few inputs for the customization of OAF page.
    Business Need: Restriction of special character in supplier oaf pages for supplier name.
    There are 3 oaf pages involved in supplier creation/update for R 12.1.3
    1)     oracle\apps\pos\supplier\webui\OrganizationPG (underlying VO is sql query based).
    2)     oracle\apps\pos\supplier\webui\QuickUpdatePG (underlying VO is sql query based).
    3)     oracle\apps\pos\supplier\webui\SuppCrtPG (underlying VO is based on EO - HzPuiOrgProfileQuickEOEx) .
    For pages referring EO, we have extended the underlying EO and override the validateEntity() method to throw the OAAttrValException. After substitution, validation is working.
    For VO based on query, the standard AM’s are instantiating the VO and using Rowimpl class they are setting the attributes.
    Question: How to enforce validation logic in VO or AM in such cases where oracle standard code is instantiating the VO dynamically?
    One possible solution is to use the PPR event on input text message bean and catch it in custom controller’s processFormRequest method and before super. processFormRequest(), we can put the validation.
    Is there any other way to achieve it?

    {forum:id=210} is the OAF forum

  • Where to put the commit in the FORALL BULK COLLECT LOOP

    Hi,
    Have the following LOOP code using FORALL and bulk collect, but didnt know where to put the
    'commit' :
    open f_viewed;
    LOOP
    fetch f_viewed bulk collect into f_viewed_rec LIMIT 2000;
    forall i in 1..f_viewed_rec.count
    insert into jwoodman.jw_job_history_112300
    values f_viewed_rec(i);
    --commit; [Can I put this 'commit' here? - Jenny]
    EXIT when f_viewed%NOTFOUND;
    END LOOP;
    commit;
    Thanks,
    - Jenny

    mc**** wrote:
    Bulk collect normally used with large data sets. If you have less dataset such as 1000-2000 records then you canot get such a performance improvent using bulk collect.(Please see oracle documents for this)
    When you update records Oracle acquire exclusive lock for that. So if you use commit inside the loop then it will process number of records defined by limit parameter at ones and then commit those changes.
    That will release all locks acquired by Oracle and also teh memory used to keep those uncommited transactions.
    If you use commit outside the loop,
    Just assume that you insert 100,000 records, all those records will store in oracle memory and it will affect all other users performance as well.
    Further more if you update 100,000 records then it will hold exclusive lock for all 100,000 records addtion to the usage of the oracle memory.
    I am using this for telco application which we process over 30 million complex records (one row has 234 columns).
    When we work with large data sets we do not depends with the oracle basic rollback function. because when you keep records without commit itb uses oracle memory and badly slowdown all other processes.Hi mc****,
    What a load of dangerous and inaccurate rubbish to be telling a new Oracle developer. Commit processing should be driven by the logical unit of a transaction. This should hold true whether that transaction involves a few rows or millions. If, and only if, the transaction is so large that it affects the size constraints of the database resources, in particular, rollback or redo space, then you can consider breaking that transaction up to smaller transactions.
    Why is frequent committing undesirable I hear you ask?
    First of all it is hugely wasteful of rollback or redo space. This is because while the database is capable of locking at a row level, redo is written at a block level, which means that if you update, delete or insert a million rows and commit after each individual statement, then that is a million blocks that need to go into redo. As many of these rows will be in the same block, if you instead do these as one transaction, then the same block in redo can be transacted upon, making the operation more efficient. True, locks will be held for longer, but if this is new data being done in batches then users will rarely be inconvenienced. If locking is a problem then I would suggest that you should be looking at how you are doing your processing.
    Secondly, committing brings into play one of the major serialization points in the database, log sync. When a transaction is committed, the log buffer needs to be written to disc. This occurs serially for multiple commits. Each commit has to wait until the commit before has completed. This becomes even more of a bottleneck if you are using Data Guard in SYNC mode, as the commit cycle does not complete until the remote log is notified as written.
    This then brings us two rules of thumb that will always lead a developer in the right direction.
    1. Commit as infrequently as possible, usually at the logical unit of a transaction
    2. When building transactions, first of all seek to do it using straight SQL (CTAS, insert select, update where etc). If this can't be easily achieved, then use PL/SQL bulk operations.
    Regards
    Andre

  • How to put validation between attributes at View Object level in BC4J

    Hi,
    Is it possible in BC4J to put validation between attributes at View Object level?
    I know that I can do it at Entity Object level in validateEntity method, but I have several View Objects connected with one Entity Object and don't want to have the same validation logic for all View Objects.
    Thanks for any help!

    It returns errorWhat error does it return?
    John

  • Where to put EJB design patterns?

    Im considering where to put the EJB design pattern classes and files.
    i.e. Facade, Data Access Objects, Transfer Objects, Delegate...
    I was thinking since the EJB business logics and implementation should be hidden from the user, then it is more logical to place these classes at the webapp.war inside of the ejb.jar.
    What are your thoughts guys?

    Photoshop patterns and normally stored in sets the set files have an extension of .pat.  You may also add individual patterns using menu Edit>Define Pattern.  In some Photoshop Pattern dialog you will see a little gear icon to open a Fly-Out menu in that menu there is a entry for Photoshop Preset Manager.  The are also other ways to get into the Preset manager.   In the preset manager you can manage many types of presets. Using its pull-down menu select patterns.  You can Load an save patterns sets.  To save a set tou heed to hilifht the paterns yoy want to include in the set.  You can also delete and rename patterns.

  • Where to put java code - Best Practice

    Hello. I am working with the Jdeveloper 11.2.2. I am trying to figure out the best practice for where to put code. After reviewing http://docs.oracle.com/cd/E26098_01/web.1112/e16182.pdf it seemed like the application module was the preferred spot (although many of the examples in the pdf are in main methods). After coding a while though, I noticed that there were quite a few libraries imported, and wondered whether this would impact performance.
    I reviewed postings on the forum, especially Re: Access service method (client interface) programmatically . This link mentions accessing code from a backing bean -- and the gist of the recommendations seems to be to use the data control to drag it to the JSF, or use the bindings to access code.
    My interest lies in where to put java code in the first place; In the View Object, Entity Object, and Am object, backing bean.....other?
    I can outline several best guesses about where to put code and the pros and cons:
    1. In the application module
    Pros: Centralized location for code makes development and support more simple as there are not multiple access points. Much like a data control centralizes services, the application module can act as a conduit for different pieces of code you have in objects in your model.
    Cons: Everything in one place means the application module becomes bloated. I am not sure how memory works in java -- if the app module has tons of different libraries are they all called when even a simple query re-execute method is called? Memory hog?
    2. Write code in the objects it affects. If you are writing code that accesses a view object, write it in a view object. Then make it visible to the client.
    pros: The code is accessed via fewer conduits (for example, I would expect that if you call the application module from a JSF backing bean, then the application module calls the view object, you have three different pieces of code --
    conts: The code gets spread out, harder to locate etc.
    I would greatly appreciate your thoughts on the matter.
    Regards,
    Stuart
    Edited by: Stuart Fleming on May 20, 2012 5:25 AM
    Edited by: Stuart Fleming on May 20, 2012 5:27 AM

    First point here is when you say "where to put the java code" and you're referring to ADF BC, the point is you put "business logic java code" in the ADF Business Components. It's fine of course to have Java code in the ViewController layer that deals with the UI layer. Just don't put business logic in the UI layer, and don't put UI logic in the model layer. In your 2 examples you seem to be considering the ADF BC layer only, so I'll assume you mean business logic java code only.
    Meanwhile I'm not keen on the term best practice as people follow best practices without thinking, typically best practices come with conditions and people forget to apply them. Luckily you're not doing that here as you've thought through the pros and cons of each (nice work).
    Anyway, back on topic and off my soap box, as for where to put your code, my thoughts:
    1) If you only have 1 or 2 methods put it in the AppModuleImpl
    2) If you have hundreds of methods, or there's a chance #1 above will morph into #2, split the code up between the AppModuleImpl, ViewImpl and ViewRowImpls. Why? Because your AM will become overloaded with hundreds of methods making it unreadable. Instead put the code where it should logically go. Methods that work on a specific VO row go into the associated ViewRowImpl, methods that work across rows in a VO go into the ViewImpl, and methods that work across VOs in the associated AppModuleImpl.
    To be honest which you ever option you choose, one thing I do recommend as a best practice is be consistent and document the standard so your other programmers know.
    Btw there isn't an issue about loading lots of libraries/imports into a class, it has no runtime cost. However if your methods require lots of class variables, then yes this will have a memory cost.
    On a side note if you're interested in more ideas around how to build ADF apps correctly think about joining the "ADF EMG", a free online forum which discusses ADF architecture, best practices (cough), deployment architectures and more.
    Regards,
    CM.

  • Where is the SAP logic to process the BDCDATA?

    Hi, expert.
    Where is the SAP logic to process the BDCDATA that we passed on CALL TRANSACTION 'VA01' using bdcdata mode.....?
    On the other words, can I see the SAP logic to understand how SAP process 'CALL TRANSACTION' statement?
    Thanks.

    Martin,
    thanks for the reply.
    I understand 'CALL TRANSACTION' works, SAP propagates the value to VA01 screen based on the records we built on the BDCDATA internal table.  
    For example, we are going to create order with 5 line items.  However, the 1st line itme is okey, but 2nd line itme we hit a material error, so BDC stopped.  We have requirement that want to remove 2nd line item and want BDC continue to process for 3rd, 4th, 5th line items.   User can run CALL TRANSACTION with mode 'E'.  So BDC will stop when hit error.  at this point user can delete item use SAP 'delete' icon.   But the problem is BDC still have leftover records for 2nd item.   I hope there is way to locate BDCrecords and in the userexit to remove the leftover BDC records for 2nd item.  Then BDC can continue to process 3rd item....   That is why I try to find how SAP logic behind 'CALL TRANSACTION' and hoping to locate where is the SAP logic that process BDCDATA record one by one....  hence I can think about how to cleanup/delete leftover BDC records for 2nd line item.
    I put breakpoint at 'CALL TRANSACTION' statement and then click 'single step'.  But next step, it immediately stop in the VA01 main program 'SAPMV45A' module transaktion_init.  I was hopping the next step will stop in the SAP program that I can see it handles/loops BDCDATA...  But not.

  • SFM system administrator responsibility -Validation logic

    Issue- We have invoke the Install base some data fix in validate logic of SFM Message CSISOSHP. And the standard program which is not getting fired 'Service Contracts Order Capture Integration',
    The standard SFM logic is getting suppressed where the custom process logic added. It works fine when we execute the program ‘Service Contracts Order Capture Integration’ manually.
    Kindly suggest how to get fire both validation logic functionality and the standard process together.
    Thanks,
    Padma

    Hi,
    In R12 the  concurrent program name is  "Invoice Validation Program" and this concurrent program is available in R12.1.3. Short name of the concurrent program is "APPRVL". Please check whether this concurrent program is assigned to the request group or not. If not, please add and check.

  • Where to put the sql

    Hi,
    When I develop a Java software which gets data from the user (for example a Web page) and use them for performing and put the result into the database, according to you is it almost always smarter calling an Oracle stored procedure or a package making the task or can it be usefull to put the logics-sql inside the Java code? For me it's always better to develop a strored procedure to be called, but I'd like to listen to your experience.
    Thanks!

    If the Java code is to run against a variety of different database products, then it is limited to the lowest common denominator between these products - the basic SQL language.
    And unfortunately, such code will use the various database products non-optimally. SQL language implementations differ. Analytical SQL functions available in one product will be different or even non-existent in another.
    But in this case, the Java code has little choice - and need to use bare bones SQL.
    Usually this is only a problem for ISVs that are developing commercial client products. For most others, we have a single database product as the strategic product for the selected IT architecture.
    So in this case it makes sense to use and leverage all the features of that database products. Enabling the Java code to optimally use the database. Enable the database to perform and scale.
    In the case of Oracle, that typically means not having Java developers code SQL at all. Not because they are SQL/Oracle idiots (which can be argued). But because of providing a formal and abstract data interface allows far greater flexibility, maintainability and usability.
    It enables you to to deal with SQL and SQL related performance inside this interface, without having to touch and recompile a single byte of Java client code.
    It enables you to deal with database structure changes via this interface, without having to touch and recompile a single byte of Java client code.
    So it makes a LOT of sense to create and use such an interface - not just for Java clients, but all clients. Allowing all clients to share the same interface and be subject to the same validation and business rules in a coherent and consistent fashion.
    In Oracle, this interface will be written using PL/SQL packages - and will typically return ref cursors to the clients.

  • Where i Put my swing application jar file in jboss

    Hi experts...
    I develope swing application and convert it into jar file....I know jnlp deployment using tomcat..In tomcat i
    put my appcation.jar in webapps/root folder...This is not similar in jboss..I dont know where i put my applcation.jar in jboss.If any body know the idea please let me know..

    Hi
    You have to put your jar file in
    server/default/deploy
    Regards
    M Fazal Ur Rehman

Maybe you are looking for

  • Passing Values to BADI in LUW

    We have a process in SRM where incoming IDOCS are coming in from an external source. In our Z function module the BBP_DOC_CHANGE_BADI is called and we need to pass a value to DOC_CHANGE_BADI to make sure we process only code for this process. Options

  • Amateur question reagarding quality of video formats

    Since iMovie '08 came out, I switched to FCE, to get into the program, before support for iMovie 06 HD disappears completely, Now with the discussion of the future of FW on Apple's non pro machine, I do have the following question, which is not immen

  • Combined PDFs have bigger jpegs then word doc

    I am having an issue with adobe 11. If I open a word doc and print to my pdf printer the pdf created looks identical to the word 13 doc. If I open adobe and choose to combine files all the graphics in the combined pdf are a little bit bigger then the

  • SCN Content Submission: Is there any further information on the submission status?

    Hi colleagues, I understand and have read a couple of times that I can contribute content via the content submission (SAML Response from SAP ID Service). and I see the status "Submitted" for my document. The question is, is there a way to get more in

  • How do I bar specific incoming numbers from calling my iPhone?

    Hi. Recently, I have been getting persistent scam calls from various people trying to sell me "T-mobile upgrades" (for my O2 based UK iPhone 3G S!) and other scam nonsense. Not sure if it relates to the new mobile/cellphone number directory that laun