Search in sources :

Example 1 with EJBQLQueryDescriptor

use of org.apache.cayenne.map.EJBQLQueryDescriptor in project cayenne by apache.

the class EJBQLQueryIT method testEncodeAsXML.

@Test
public void testEncodeAsXML() {
    String ejbql = "select a FROM Artist a";
    String name = "Test";
    StringWriter w = new StringWriter();
    XMLEncoder e = new XMLEncoder(new PrintWriter(w));
    String separator = System.getProperty("line.separator");
    String s = "<query name=\"" + name + "\" type=\"EJBQLQuery\">" + separator + "<ejbql><![CDATA[" + ejbql + "]]></ejbql>" + separator + "</query>" + separator;
    EJBQLQueryDescriptor descriptor = new EJBQLQueryDescriptor();
    descriptor.setEjbql(ejbql);
    descriptor.setName(name);
    descriptor.encodeAsXML(e, new EmptyConfigurationNodeVisitor());
    assertEquals(w.getBuffer().toString(), s);
}
Also used : EJBQLQueryDescriptor(org.apache.cayenne.map.EJBQLQueryDescriptor) XMLEncoder(org.apache.cayenne.util.XMLEncoder) EmptyConfigurationNodeVisitor(org.apache.cayenne.configuration.EmptyConfigurationNodeVisitor) StringWriter(java.io.StringWriter) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 2 with EJBQLQueryDescriptor

use of org.apache.cayenne.map.EJBQLQueryDescriptor in project cayenne by apache.

the class EjbqlQueryScriptsTab method setEJBQL.

void setEJBQL(String text) {
    EJBQLQueryDescriptor query = getQuery();
    if (query == null) {
        return;
    }
    if (text != null && text.trim().isEmpty()) {
        text = null;
    }
    // will call "verify" even if no changes have occured....
    if (!Util.nullSafeEquals(text, query.getEjbql())) {
        query.setEjbql(text);
        mediator.fireQueryEvent(new QueryEvent(this, query));
    }
}
Also used : EJBQLQueryDescriptor(org.apache.cayenne.map.EJBQLQueryDescriptor) QueryEvent(org.apache.cayenne.configuration.event.QueryEvent)

Aggregations

EJBQLQueryDescriptor (org.apache.cayenne.map.EJBQLQueryDescriptor)2 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 EmptyConfigurationNodeVisitor (org.apache.cayenne.configuration.EmptyConfigurationNodeVisitor)1 QueryEvent (org.apache.cayenne.configuration.event.QueryEvent)1 XMLEncoder (org.apache.cayenne.util.XMLEncoder)1 Test (org.junit.Test)1