Package org.apache.xindice.core.meta

Examples of org.apache.xindice.core.meta.MetaData


     * @return The requested MetaData
     */
    public MetaData getDocumentMeta(Collection collection, String id) throws DBException {
        Collection mcol = getMetaCollection(collection, true);
        if (null != mcol) {
            MetaData meta = (MetaData) mcol.getObject(id);

            if (meta == null) {
                meta = new MetaData();
            }

            if (meta.getType() == MetaData.UNKNOWN) {
                meta.setType(MetaData.DOCUMENT);
            }
            meta.setOwner(collection.getCanonicalName() + "/" + id);
            meta.setDirty(false);
            return meta;
        }
        return null;
    }
View Full Code Here


            // meta information is not enabled !
            throw new Exception(MISSING_META_CONFIGURATION);
        }

        // Read and store sent meta data
        MetaData meta = new MetaData();
        Document doc = DOMParser.toDocument((String) message.get(META));
        meta.streamFromXML(doc.getDocumentElement());
        col.setCollectionMeta(meta);

        // Retreive stored meta data and sent back
        meta = col.getCollectionMeta();
        doc = new DocumentImpl();
        doc.appendChild(meta.streamToXML(doc, true));
        result.put(RESULT, TextWriter.toString(doc));
        return result;
    }
View Full Code Here

     * returned will be null.
     *
     * @return MetaData this collection's metadata.
     */
    public MetaData getCollectionMeta() throws DBException {
        MetaData meta = null;
        if (!isMetaEnabled()) {
            if (log.isWarnEnabled()) {
                log.warn("Meta information requested but not enabled in config!");
            }
            return meta;
        }

        MetaSystemCollection metacol = getMetaSystemCollection();
        meta = metacol.getCollectionMeta(this);
        if (null == meta) {
            long now = System.currentTimeMillis();
            meta = new MetaData(MetaData.COLLECTION, getCanonicalName(), now, now);
            metacol.setCollectionMeta(this, meta);
        }

        return meta;
    }
View Full Code Here

                                  "Document '" + id + "' does not exist " +
                                  "in collection '" + getCanonicalName() + "'");
        }

        MetaSystemCollection metacol = getMetaSystemCollection();
        MetaData meta = metacol.getDocumentMeta(this, id);

        /*
        TimeRecord rec = null;
        if( null == meta || !meta.hasContext() )
           rec = getDatabase().getTime(path);

        long created = (null != rec) ? rec.getCreatedTime() : System.currentTimeMillis();
        long modified = (null != rec) ? rec.getModifiedTime() : System.currentTimeMillis();
        */

        // this is wrong.. but it should work for now...
        long now = System.currentTimeMillis();
        if (null == meta) {
            meta = new MetaData(MetaData.DOCUMENT, getCanonicalDocumentName(id), now, now);
            metacol.setDocumentMeta(this, id, meta);
        } else if (!meta.hasContext()) {
            meta.setContext(now, now);
        }

        return meta;
    }
View Full Code Here

                throw new DBException(FaultCodes.GEN_UNKNOWN,
                                      "Mismatch type of meta data for collection " + getCanonicalName());
            }

            MetaSystemCollection metacol = getMetaSystemCollection();
            MetaData current = metacol.getCollectionMeta(this);
            current.copyDataFrom(meta);
            metacol.setCollectionMeta(this, current);
        }
    }
View Full Code Here

            if (log.isInfoEnabled()) {
                log.info(debugHeader() + "Set document meta " + id);
            }
            MetaSystemCollection metacol = getMetaSystemCollection();
            MetaData current = metacol.getDocumentMeta(this, id);
            current.copyDataFrom(meta);
            metacol.setDocumentMeta(this, id, current);
        }
    }
View Full Code Here

     */
    protected void updateCollectionMeta() {
        // update the meta data if necessary
        if (isMetaEnabled()) {
            MetaSystemCollection metacol = getMetaSystemCollection();
            MetaData meta = null;
            try {
                meta = metacol.getCollectionMeta(this);
            } catch (DBException e) {
                // something strange has happened.. can't get the
                // meta data for this collection
                if (log.isWarnEnabled()) {
                    log.warn("Error fetching meta for collection '" + getCanonicalName() + "'", e);
                }
                return;
            }

            if (log.isTraceEnabled()) {
                log.trace(debugHeader() + "Updating modified time for collection");
            }
            long now = System.currentTimeMillis();
            if (null == meta) {
                meta = new MetaData(MetaData.COLLECTION, getCanonicalName(), now, now);
            } else if (!meta.hasContext()) {
                // Newly created meta. Update its created and modified time.
                meta.setContext(now, now);
            } else {
                // This collection already has a meta. So update its modified time.
                meta.setContext(0, now);
            }

            try {
                metacol.setCollectionMeta(this, meta);
            } catch (DBException e) {
View Full Code Here

            throw new DBException(FaultCodes.COL_DOCUMENT_NOT_FOUND,
                                  "Document " + id + " does not exist in " + getCanonicalName());
        }

        MetaSystemCollection metacol = getMetaSystemCollection();
        MetaData meta = metacol.getDocumentMeta(this, id);
        String path = getCanonicalDocumentName(id);

        /*
        TimeRecord rec = null;
        if( null == meta || !meta.hasContext() )
           rec = getDatabase().getTime(path);

        long created = (null != rec) ? rec.getCreatedTime() : System.currentTimeMillis();
        long modified = (null != rec) ? rec.getModifiedTime() : System.currentTimeMillis();
        */

        // this is wrong.. but it should work for now...
        if (log.isTraceEnabled()) {
            log.trace(debugHeader() + "Updating modified time for document '" + id + "'");
        }
        long now = System.currentTimeMillis();
        if (null == meta) {
            meta = new MetaData(MetaData.DOCUMENT, path, now, now);
        } else if (!meta.hasContext()) {
            meta.setContext(now, now);
        } else {
            meta.setContext(0, now);
        }
        metacol.setDocumentMeta(this, id, meta);
    }
View Full Code Here

            // meta information is not enabled !
            throw new Exception(MISSING_META_CONFIGURATION);
        }

        // Read and store sent meta data
        MetaData meta = new MetaData();
        Document doc = DOMParser.toDocument((String) message.get(META));
        meta.streamFromXML(doc.getDocumentElement());
        col.setDocumentMeta(docname, meta);

        // Retreive stored meta data and sent back
        meta = col.getDocumentMeta(docname);
        doc = new DocumentImpl();
        meta.streamToXML(doc, true);
        result.put(RESULT, TextWriter.toString(doc));
        return result;
    }
View Full Code Here

        // Get meta service
        Collection col = this.client.getCollection(TEST_COLLECTION_PATH);
        MetaService service = (MetaService) col.getService("MetaService", "1.0");

        // Get meta data
        MetaData data = service.getMetaData();
        assertNotNull("MetaData is not found for the collection!", data);
        assertTrue("Creation time is 0!", data.getCreatedTime() != 0);
        assertTrue("Modification time is 0!", data.getLastModifiedTime() != 0);
        long created0 = data.getCreatedTime();
        long modified0 = data.getLastModifiedTime();

        // Sleep and get it again
        Thread.sleep(150);
        data = service.getMetaData();
        long created1 = data.getCreatedTime();
        long modified1 = data.getLastModifiedTime();
        assertEquals("Creation time changed on 2nd get (diff: "+ (created1 - created0) +")!", created0, created1);
        assertEquals("Modification time changed on 2nd get (diff: "+ (modified1 - modified0) +")!", modified0, modified1);

        // Sleep, add new document, and get metadata again
        Thread.sleep(150);
        this.client.insertDocument(TEST_COLLECTION_PATH, DOCUMENT_ID2, DOCUMENT2);

        data = service.getMetaData();
        assertNotNull("MetaData is not found for the collection after update!", data);
        long created2 = data.getCreatedTime();
        long modified2 = data.getLastModifiedTime();
        assertEquals("Creation time changed on update (diff: "+ (created2 - created1) +")!", created1, created2);
        assertTrue("Modification time has not changed on update!", modified1 != modified2);
    }
View Full Code Here

TOP

Related Classes of org.apache.xindice.core.meta.MetaData

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.