Ce contenu n'est pas disponible dans la langue sélectionnée.
31.6.5. DynamicQL
DynamicQL allows the runtime generation and execution of JBossQL queries. A DynamicQL query method is an abstract method that takes a JBossQL query and the query arguments as parameters. JBoss compiles the JBossQL and executes the generated SQL. The following generates a JBossQL query that selects all the gangsters that have a hangout in any state in the states set:
public abstract class GangsterBean
implements EntityBean
{
public Set ejbHomeSelectInStates(Set states)
throws FinderException
{
// generate JBossQL query
StringBuffer jbossQl = new StringBuffer();
jbossQl.append("SELECT OBJECT(g) ");
jbossQl.append("FROM gangster g ");
jbossQl.append("WHERE g.hangout.state IN (");
for (int i = 0; i < states.size(); i++) {
if (i > 0) {
jbossQl.append(", ");
}
jbossQl.append("?").append(i+1);
}
jbossQl.append(") ORDER BY g.name");
// pack arguments into an Object[]
Object[] args = states.toArray(new Object[states.size()]);
// call dynamic-ql query
return ejbSelectGeneric(jbossQl.toString(), args);
}
}
public abstract class GangsterBean
implements EntityBean
{
public Set ejbHomeSelectInStates(Set states)
throws FinderException
{
// generate JBossQL query
StringBuffer jbossQl = new StringBuffer();
jbossQl.append("SELECT OBJECT(g) ");
jbossQl.append("FROM gangster g ");
jbossQl.append("WHERE g.hangout.state IN (");
for (int i = 0; i < states.size(); i++) {
if (i > 0) {
jbossQl.append(", ");
}
jbossQl.append("?").append(i+1);
}
jbossQl.append(") ORDER BY g.name");
// pack arguments into an Object[]
Object[] args = states.toArray(new Object[states.size()]);
// call dynamic-ql query
return ejbSelectGeneric(jbossQl.toString(), args);
}
}
Copy to ClipboardCopied!Toggle word wrapToggle overflow
The DynamicQL select method may have any valid select method name, but the method must always take a string and an object array as parameters. DynamicQL is declared in the jbosscmp-jdbc.xml file with an empty dynamic-ql element. The following is the declaration for ejbSelectGeneric.
Nous aidons les utilisateurs de Red Hat à innover et à atteindre leurs objectifs grâce à nos produits et services avec un contenu auquel ils peuvent faire confiance. Découvrez nos récentes mises à jour.
Rendre l’open source plus inclusif
Red Hat s'engage à remplacer le langage problématique dans notre code, notre documentation et nos propriétés Web. Pour plus de détails, consultez le Blog Red Hat.
À propos de Red Hat
Nous proposons des solutions renforcées qui facilitent le travail des entreprises sur plusieurs plates-formes et environnements, du centre de données central à la périphérie du réseau.