Search in sources :

Example 6 with XMLEncoder

use of org.apache.cayenne.util.XMLEncoder in project cayenne by apache.

the class EOModelProcessorTest method assertLoaded.

protected void assertLoaded(String mapName, DataMap map) throws Exception {
    assertNotNull(map);
    assertEquals(mapName, map.getName());
    // check obj entities
    ObjEntity artistE = map.getObjEntity("Artist");
    assertNotNull(artistE);
    assertEquals("Artist", artistE.getName());
    // check Db entities
    DbEntity artistDE = map.getDbEntity("ARTIST");
    DbEntity artistDE1 = artistE.getDbEntity();
    assertSame(artistDE, artistDE1);
    // check attributes
    ObjAttribute a1 = artistE.getAttribute("artistName");
    assertNotNull(a1);
    DbAttribute da1 = a1.getDbAttribute();
    assertNotNull(da1);
    assertSame(da1, artistDE.getAttribute("ARTIST_NAME"));
    // check ObjRelationships
    ObjRelationship rel = artistE.getRelationship("artistExhibitArray");
    assertNotNull(rel);
    assertEquals(1, rel.getDbRelationships().size());
    // check DbRelationships
    DbRelationship drel = artistDE.getRelationship("artistExhibitArray");
    assertNotNull(drel);
    assertSame(drel, rel.getDbRelationships().get(0));
    // flattened relationships
    ObjRelationship frel = artistE.getRelationship("exhibitArray");
    assertNotNull(frel);
    assertEquals(2, frel.getDbRelationships().size());
    // storing data map may uncover some inconsistencies
    PrintWriter mockupWriter = new NullPrintWriter();
    map.encodeAsXML(new XMLEncoder(mockupWriter), new EmptyConfigurationNodeVisitor());
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) ObjRelationship(org.apache.cayenne.map.ObjRelationship) XMLEncoder(org.apache.cayenne.util.XMLEncoder) EmptyConfigurationNodeVisitor(org.apache.cayenne.configuration.EmptyConfigurationNodeVisitor) DbEntity(org.apache.cayenne.map.DbEntity) ObjAttribute(org.apache.cayenne.map.ObjAttribute) DbRelationship(org.apache.cayenne.map.DbRelationship) DbAttribute(org.apache.cayenne.map.DbAttribute) PrintWriter(java.io.PrintWriter)

Example 7 with XMLEncoder

use of org.apache.cayenne.util.XMLEncoder in project cayenne by apache.

the class Ordering method toString.

@Override
public String toString() {
    StringWriter buffer = new StringWriter();
    PrintWriter pw = new PrintWriter(buffer);
    XMLEncoder encoder = new XMLEncoder(pw);
    encodeAsXML(encoder, new EmptyConfigurationNodeVisitor());
    pw.close();
    buffer.flush();
    return buffer.toString();
}
Also used : XMLEncoder(org.apache.cayenne.util.XMLEncoder) EmptyConfigurationNodeVisitor(org.apache.cayenne.configuration.EmptyConfigurationNodeVisitor) StringWriter(java.io.StringWriter) PrintWriter(java.io.PrintWriter)

Example 8 with XMLEncoder

use of org.apache.cayenne.util.XMLEncoder in project cayenne by apache.

the class DataMapTest method testQuoteSqlIdentifiersEncodeAsXML.

@Test
public void testQuoteSqlIdentifiersEncodeAsXML() {
    DataMap map = new DataMap("aaa");
    map.setQuotingSQLIdentifiers(true);
    StringWriter w = new StringWriter();
    XMLEncoder encoder = new XMLEncoder(new PrintWriter(w));
    map.encodeAsXML(encoder, new EmptyConfigurationNodeVisitor());
    assertTrue(map.quotingSQLIdentifiers);
    XMLDataMapLoader loader = new XMLDataMapLoader();
    try {
        URL url = mock(URL.class);
        InputStream is = new ByteArrayInputStream(w.getBuffer().toString().getBytes("UTF-8"));
        when(url.openStream()).thenReturn(is);
        DataMap newMap = loader.load(new URLResource(url));
        assertTrue(newMap.quotingSQLIdentifiers);
    } catch (Exception e) {
        e.printStackTrace();
    }
    map.setQuotingSQLIdentifiers(false);
    StringWriter w2 = new StringWriter();
    XMLEncoder encoder2 = new XMLEncoder(new PrintWriter(w2));
    map.encodeAsXML(encoder2, new EmptyConfigurationNodeVisitor());
    assertFalse(map.quotingSQLIdentifiers);
    try {
        URL url = mock(URL.class);
        InputStream is = new ByteArrayInputStream(w.getBuffer().toString().getBytes("UTF-8"));
        when(url.openStream()).thenReturn(is);
        DataMap newMap = loader.load(new URLResource(url));
        assertFalse(newMap.quotingSQLIdentifiers);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : URLResource(org.apache.cayenne.resource.URLResource) XMLEncoder(org.apache.cayenne.util.XMLEncoder) EmptyConfigurationNodeVisitor(org.apache.cayenne.configuration.EmptyConfigurationNodeVisitor) StringWriter(java.io.StringWriter) ByteArrayInputStream(java.io.ByteArrayInputStream) XMLDataMapLoader(org.apache.cayenne.configuration.xml.XMLDataMapLoader) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) URL(java.net.URL) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 9 with XMLEncoder

use of org.apache.cayenne.util.XMLEncoder in project cayenne by apache.

the class ConfigurationSaver method visitDataMap.

@Override
public Void visitDataMap(DataMap node) {
    XMLEncoder encoder = new XMLEncoder(printWriter, "\t", version);
    printXMLHeader(encoder);
    delegate.setXMLEncoder(encoder);
    node.encodeAsXML(encoder, delegate);
    return null;
}
Also used : XMLEncoder(org.apache.cayenne.util.XMLEncoder)

Aggregations

XMLEncoder (org.apache.cayenne.util.XMLEncoder)9 PrintWriter (java.io.PrintWriter)6 EmptyConfigurationNodeVisitor (org.apache.cayenne.configuration.EmptyConfigurationNodeVisitor)6 StringWriter (java.io.StringWriter)5 Test (org.junit.Test)3 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 URL (java.net.URL)1 List (java.util.List)1 ConfigurationNodeVisitor (org.apache.cayenne.configuration.ConfigurationNodeVisitor)1 XMLDataMapLoader (org.apache.cayenne.configuration.xml.XMLDataMapLoader)1 DbAttribute (org.apache.cayenne.map.DbAttribute)1 DbEntity (org.apache.cayenne.map.DbEntity)1 DbRelationship (org.apache.cayenne.map.DbRelationship)1 EJBQLQueryDescriptor (org.apache.cayenne.map.EJBQLQueryDescriptor)1 ObjAttribute (org.apache.cayenne.map.ObjAttribute)1 ObjEntity (org.apache.cayenne.map.ObjEntity)1 ObjRelationship (org.apache.cayenne.map.ObjRelationship)1 URLResource (org.apache.cayenne.resource.URLResource)1 XMLSerializable (org.apache.cayenne.util.XMLSerializable)1