Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Converting a String object into an object's attribute

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All -

I need to have your views on the following problem.

I have an object say "TestObj".
It has the following attribute String "Attribute_A","Attribute_B".
For one of my current needs i have stored these Class.Attribute in DB.
e.g. TestObj.Attribute_A and TestObj.Attribute_B.
In my Server side code i am fetching these values from the DB.
Now i have to do some validation on these attributes which i retrieved from DB thinking as if they were the actual objects attribute.
e.g.
TestObj.Attribute_A > "500"
TestObj.Attribute_B == "testString".

These validations have to be done on Server side and can be changed dynamically and hence are stored in DB.

Please let me know if anyone of you have done or read about such a problem earlier.Also i am open to your suggestion.

Thanks.
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I've understood your question correctly, I think you need to use Reflection. Here's a tutorial
 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Neal is correct if you dont know the class attribute
 
Ranch Hand
Posts: 547
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the validaiton rules are stored in DB ? and they tell you what rule to apply to what field ?

so ni your db you have something like

ID|FIELDNAME|OPERATOR|LEFTHANDSIDE
01| age | > | 18
02| color | == | "red"

and then you need to apply these rules to different objects ?




ok, that is pretty ugly pseudo code. There are lots of things to think about....
Null Values, Number vs. Strings. Where to store error messages ?



Pascal
 
Abhi Mahimkar
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you all..

I will look into the reflection tuts...

Also i forgot to tell you all that our validation checks are basically all the complex logic possible & we have defined them in a TREE structure.The DB is similar to what Pascal has provided.So is there any other way to pull up the validation rules & execute them knowing that they are in a TREE structure.Meaning that

Any better way to handle the tree structure of preparing the validation ?
Thanks.
 
Ranch Hand
Posts: 884
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd take a different approach. If I could control the input in the first place, I'd have validations to ensure that the values that I'm going to store into the database is of the constraints I defined. Or I could put in constraints at the database level to ensure that if for some reasons my Java validations failed, at least the database would reject these inputs.
 
What? What, what, what? What what tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic