The conventions for the definition of beans are flexible
and the requirements are few.
You can use beans with pureQuery to specify the values
of the parameters in SQL statements and to return query results.
The JavaBeans™ specification
defines conventions for the definition of an object class, conventions
regarding the declaration of properties in the object and the naming
of the get() and set() methods for
manipulating those properties. An object class that conforms to the JavaBeans conventions is ideal
for working with the capabilities of pureQuery.
However, pureQuery
also works well with objects that do not follow the conventions exactly.
For example, if get() or set() methods
are not present for a certain property, pureQuery can read or set
the property directly.
pureQuery identifies properties in a
bean based on the public get() and set() methods,
and the public fields, in the bean.
- For every public get() method, pureQuery expects
a corresponding set() method. For example, if pureQuery
encounters the method getAbc(), it expects a corresponding setAbc() method.
pureQuery
considers the letters that follow get and set to
be the name of the property, though pureQuery assumes that the name
of the property begins with a lowercase letter. For example, if a
method is getAbc(), the name of the property is abc.
- pureQuery expects every property to have a corresponding public
field, and expects the case of name of a field to be identical to
the case of the name of the corresponding property.
pureQuery imposes only seven requirements on a definition
of a bean that is used to hold the results of a query:
- A bean must have a no-argument constructor available, either explicit
or implicit.
- The names of properties in a single bean must be unique to a case-insensitive
search. For example, you cannot create properties with the names "id"
and "ID" in the same bean.
- get() and set() methods must
come in pairs. You cannot have a get() method without
a corresponding set() method, and vice versa. The
number of parameters and their types must be identical for both methods.
- Beans cannot contain any get() or set() methods
that are unrelated to properties.
- Beans can have public fields. If you use protected or private
fields, the bean must have public get() methods (or
public is() methods for boolean properties) and public set() methods.
If a bean has a public field and the corresponding get(), is(),
or set() method is also public, pureQuery throws
an exception.
- If a get() method is named getNAME(),
the corresponding property must be nAME.
- Fields can be only those Java™ types
that JDBC supports.
For beans that are used to provide input parameters for
an SQL statement, the only restriction is that the properties that
are referred to by parameter markers in the SQL statement must be
unique to a case-insensitive search.