Package org.apache.geronimo.datastore.impl

Examples of org.apache.geronimo.datastore.impl.GFileTO


        Map props = new HashMap();
        props.put("name1", "value1");
        props.put("name2", "value2");
        byte[] content = "Dummy content".getBytes();
        ByteArrayInputStream in = new ByteArrayInputStream(content);
        GFileTO fileTO = new GFileTO(path, props, in);
        GFileDAO fileDAO = new LocalGFileDAO(root);

        // Create.
        fileDAO.create(fileTO);
       
        // Read.
        fileTO = fileDAO.read(path);
        assertEquals("Wrong path", path, fileTO.getPath());
        props = fileTO.getProperties();
        assertEquals("Wrong # of properties", 2, props.size());
        for (Iterator iter = props.entrySet().iterator(); iter.hasNext();) {
            Map.Entry property = (Map.Entry) iter.next();
            String name = (String) property.getKey();
            if ( name.equals("name1") ) {
                assertEquals("Wrong value", "value1", property.getValue());
            } else if ( name.equals("name2") ) {
                assertEquals("Wrong value", "value2", property.getValue());
            } else {
                assertTrue("Wrong property name {" + name + "}", false);
            }
        }
       
        // Update
        props.put("name3", "value3");
        fileDAO.update(fileTO);
        fileTO = fileDAO.read(path);
        props = fileTO.getProperties();
        assertEquals("Wrong # of properties", 3, props.size());
       
        // Delete
        fileDAO.delete(path);
        fileTO = fileDAO.read(path);
        assertFalse("Should not exist.", fileTO.exists());
    }
View Full Code Here


        throws DAOException {
        File target = new File(root, aPath);
        File metaDataFile = getMetaDataFile(target);
       
        if ( !metaDataFile.exists() ) {
            GFileTO fileTO = new GFileTO(aPath, new HashMap(), GFile.UNSET);
            fileTO.setExists(false);
            return fileTO;
        }
       
        Map properties = new HashMap();
        BufferedReader reader = null;
        try {
            reader = new BufferedReader(new FileReader(metaDataFile));
            String line;
            while ( null != (line = reader.readLine()) ) {
                int separator = line.indexOf('=');
                properties.put(line.substring(0, separator),
                    line.substring(separator + 1));
            }
        } catch (IOException e) {
            throw new DAOException(e);
        } finally {
            try {
                if ( null != reader ) { reader.close(); }
            } catch (IOException e) {}
        }
       
        GFileTO fileTO = new GFileTO(aPath, properties, GFile.UNSET);
        fileTO.setDirectory(target.isDirectory());
        fileTO.setExists(target.exists());
        fileTO.setFile(target.isFile());
        return fileTO;
    }
View Full Code Here

        throws DAOException {
        File target = new File(root, aPath);
        File metaDataFile = getMetaDataFile(target);
       
        if ( !metaDataFile.exists() ) {
            GFileTO fileTO = new GFileTO(aPath, new HashMap(), GFile.UNSET);
            fileTO.setExists(false);
            return fileTO;
        }
       
        Map properties = new HashMap();
        BufferedReader reader = null;
        try {
            reader = new BufferedReader(new FileReader(metaDataFile));
            String line;
            while ( null != (line = reader.readLine()) ) {
                int separator = line.indexOf('=');
                properties.put(line.substring(0, separator),
                    line.substring(separator + 1));
            }
        } catch (IOException e) {
            throw new DAOException(e);
        } finally {
            try {
                if ( null != reader ) { reader.close(); }
            } catch (IOException e) {}
        }
       
        GFileTO fileTO = new GFileTO(aPath, properties, GFile.UNSET);
        fileTO.setDirectory(target.isDirectory());
        fileTO.setExists(target.exists());
        fileTO.setFile(target.isFile());
        return fileTO;
    }
View Full Code Here

        Map props = new HashMap();
        props.put("name1", "value1");
        props.put("name2", "value2");
        byte[] content = "Dummy content".getBytes();
        ByteArrayInputStream in = new ByteArrayInputStream(content);
        GFileTO fileTO = new GFileTO(path, props, in);
        GFileDAO fileDAO = new LocalGFileDAO(root);

        // Create.
        fileDAO.create(fileTO);
       
        // Read.
        fileTO = fileDAO.read(path);
        assertEquals("Wrong path", path, fileTO.getPath());
        props = fileTO.getProperties();
        assertEquals("Wrong # of properties", 2, props.size());
        for (Iterator iter = props.entrySet().iterator(); iter.hasNext();) {
            Map.Entry property = (Map.Entry) iter.next();
            String name = (String) property.getKey();
            if ( name.equals("name1") ) {
                assertEquals("Wrong value", "value1", property.getValue());
            } else if ( name.equals("name2") ) {
                assertEquals("Wrong value", "value2", property.getValue());
            } else {
                assertTrue("Wrong property name {" + name + "}", false);
            }
        }
       
        // Update
        props.put("name3", "value3");
        fileDAO.update(fileTO);
        fileTO = fileDAO.read(path);
        props = fileTO.getProperties();
        assertEquals("Wrong # of properties", 3, props.size());
       
        // Delete
        fileDAO.delete(path);
        fileTO = fileDAO.read(path);
        assertFalse("Should not exist.", fileTO.exists());
    }
View Full Code Here

TOP

Related Classes of org.apache.geronimo.datastore.impl.GFileTO

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.