⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xwikihibernatestore.java

📁 xwiki 源码
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
        try {            // Start monitoring timer            if (monitor!=null)             monitor.startTimer("hibernate");            doc.setStore(this);            Archive archive = basedoc.getRCSArchive();            doc.setRCSArchive(archive);            if (archive == null) {                doc.updateArchive(doc.toXML(context));                archive = basedoc.getRCSArchive();            }            Version v = archive.getRevisionVersion(version);            if (!version.equals(v.toString())) {                doc.setVersion(version);                return doc;            }            Object[] text = (Object[]) archive.getRevision(version);            if (text[0].toString().startsWith("<")) {                StringBuffer content = new StringBuffer();                for (int i=0;i<text.length;i++) {                    String line = text[i].toString();                    content.append(line);                    content.append("\n");                }                doc.fromXML(content.toString());            } else {                StringBuffer content = new StringBuffer();                boolean bMetaDataDone = false;                for (int i=0;i<text.length;i++) {                    String line = text[i].toString();                    if (bMetaDataDone||(XWikiRCSFileStore.parseMetaData(doc,line)==false)) {                        content.append(line);                        content.append("\n");                    }                    doc.setContent(content.toString());                }            }            // Make sure the document has the same name            // as the new document (in case there was a name change            doc.setName(basedoc.getName());            doc.setWeb(basedoc.getWeb());        } catch (Exception e) {            Object[] args = { doc.getFullName(), version.toString() };            throw new XWikiException( XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_HIBERNATE_READING_VERSION,                    "Exception while reading document {0} version {1}", e, args);        } finally {            // End monitoring timer            if (monitor!=null)                monitor.endTimer("hibernate");        }        return doc;    }    public void deleteXWikiDoc(XWikiDocument doc, XWikiContext context) throws XWikiException {        boolean bTransaction = true;        MonitorPlugin monitor  = getMonitorPlugin(context);        try {            // Start monitoring timer            if (monitor!=null)             monitor.startTimer("hibernate");            checkHibernate(context);            bTransaction = beginTransaction(context);            Session session = getSession(context);            if (doc.getStore()==null) {                Object[] args = { doc.getFullName() };                throw new XWikiException( XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_HIBERNATE_CANNOT_DELETE_UNLOADED_DOC,                        "Impossible to delete document {0} if it is not loaded", null, args);            }            // Let's delete any attachment this document might have            List attachlist = doc.getAttachmentList();            for (int i=0;i<attachlist.size();i++) {                XWikiAttachment attachment = (XWikiAttachment) attachlist.get(i);                deleteXWikiAttachment(attachment, false, context, false);            }            BaseClass bclass = doc.getxWikiClass();            if ((bclass==null)&&(bclass.getName()!=null)) {                deleteXWikiClass(bclass, context, false);            }            // Find the list of classes for which we have an object            // Remove properties planned for removal            if (doc.getObjectsToRemove().size()>0) {                for (int i=0;i<doc.getObjectsToRemove().size();i++) {                    deleteXWikiObject((BaseObject)doc.getObjectsToRemove().get(i), context, false);                }                doc.setObjectsToRemove(new ArrayList());            }            Iterator it = doc.getxWikiObjects().values().iterator();            while (it.hasNext()) {                Vector objects = (Vector) it.next();                for (int i=0;i<objects.size();i++) {                    BaseObject obj = (BaseObject)objects.get(i);                    if (obj!=null)                        deleteXWikiObject(obj, context, false);                }            }            session.delete(doc);            if (bTransaction)                endTransaction(context, true);        } catch (Exception e) {            Object[] args = { doc.getFullName() };            throw new XWikiException( XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_HIBERNATE_DELETING_DOC,                    "Exception while deleting document {0}", e, args);        } finally {            try {                if (bTransaction)                    endTransaction(context, false);            } catch (Exception e) {}            // End monitoring timer            if (monitor!=null)                monitor.endTimer("hibernate");        }    }    public Version[] getXWikiDocVersions(XWikiDocument doc) throws XWikiException {        return getXWikiDocVersions(doc, null);    }    public Version[] getXWikiDocVersions(XWikiDocument doc, XWikiContext context) throws XWikiException {        try {            if (doc.getStore()==null) {                doc = loadXWikiDoc(doc, context);            }            if (doc.getRCSArchive()==null)                return new Version[0];            Node[] nodes = doc.getRCSArchive().changeLog();            Version[] versions = new Version[nodes.length];            for (int i=0;i<nodes.length;i++) {                versions[i] = nodes[i].getVersion();            }            return versions;        } catch (Exception e) {            Object[] args = { doc.getFullName() };            throw new XWikiException( XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_HIBERNATE_READING_REVISIONS,                    "Exception while reading document {0} revisions", e, args);        }    }    public void saveXWikiObject(BaseObject object, XWikiContext context, boolean bTransaction) throws XWikiException {        saveXWikiCollection(object, context, bTransaction);    }    public void saveXWikiCollection(BaseCollection object, XWikiContext context, boolean bTransaction) throws XWikiException {        try {            if (object==null)                return;            // We need a slightly different behavior here            boolean stats = (object instanceof XWikiStats);            if (bTransaction) {                checkHibernate(context);                bTransaction = beginTransaction(context);            }            Session session = getSession(context);            // Verify if the property already exists            Query query;            if (stats)                query = session.createQuery("select obj.id from " +                            object.getClass().getName() + " as obj where obj.id = :id");            else                query = session.createQuery("select obj.id from BaseObject as obj where obj.id = :id");            query.setInteger("id", object.getId());            if (query.uniqueResult()==null)                session.save(object);            else                session.update(object);            if (!object.getClassName().equals("internal")) {                // Remove all existing properties                if (object.getFieldsToRemove().size()>0) {                    for (int i=0;i<object.getFieldsToRemove().size();i++) {                        session.delete(object.getFieldsToRemove().get(i));                    }                    object.setFieldsToRemove(new ArrayList());                }                Iterator it = object.getPropertyList().iterator();                while (it.hasNext()) {                    String key = (String) it.next();                    BaseProperty prop = (BaseProperty) object.getField(key);                    if (!prop.getName().equals(key)) {                        Object[] args = { key, object.getName() };                        throw new XWikiException(XWikiException.MODULE_XWIKI_CLASSES, XWikiException.ERROR_XWIKI_CLASSES_FIELD_INVALID,                                "Field {0} in object {1} has an invalid name", null, args);                    }                    saveXWikiProperty(prop, context, false);                }            }            if (bTransaction) {                endTransaction(context, true);            }        } catch (XWikiException xe) {            throw xe;        } catch (Exception e) {            Object[] args = { object.getName() };            throw new XWikiException( XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_HIBERNATE_SAVING_OBJECT,                    "Exception while saving object {0}", e, args);        } finally {            try {                if (bTransaction)                    endTransaction(context, true);            } catch (Exception e) {}        }    }    public void loadXWikiObject(BaseObject object, XWikiContext context, boolean bTransaction) throws XWikiException {        loadXWikiCollection(object, context, bTransaction, false);    }    public void loadXWikiCollection(BaseCollection object, XWikiContext context, boolean bTransaction) throws XWikiException {        loadXWikiCollection(object, context, bTransaction, false);    }    public void loadXWikiCollection(BaseCollection object, XWikiContext context, boolean bTransaction, boolean alreadyLoaded) throws XWikiException {        try {            if (bTransaction) {                checkHibernate(context);                bTransaction = beginTransaction(context);            }            Session session = getSession(context);            if (!alreadyLoaded) {             try {                session.load(object, new Integer(object.getId()));             }             catch (ObjectNotFoundException e) {                // There is no object data saved                object = null;                return;             }            }            String className = object.getClassName();            if (!className.equals("internal")) {                HashMap map = new HashMap();                Query query = session.createQuery("select prop.name, prop.classType from BaseProperty as prop where prop.id.id = :id");                query.setInteger("id", object.getId());                Iterator it = query.list().iterator();                while (it.hasNext()) {                    Object obj = it.next();                    Object[] result = (Object[]) obj;                    String name = (String)result[0];                    String classType = (String)result[1];                    BaseProperty property = (BaseProperty) Class.forName(classType).newInstance();                    property.setObject(object);                    property.setName(name);                    loadXWikiProperty(property, context, false);                    object.addField(name, property);                }            }            if (bTransaction) {                endTransaction(context, false);            }        } catch (Exception e) {            Object[] args = { object.getName() };            throw new XWikiException( XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_HIBERNATE_LOADING_OBJECT,                    "Exception while loading object {0}", e, args);        } finally {            try {                if (bTransaction)                    endTransaction(context, false);            } catch (Exception e) {}        }    }    public void deleteXWikiCollection(BaseCollection object, XWikiContext context, boolean bTransaction) throws XWikiException {        deleteXWikiCollection(object, context, bTransaction, false);    }    public void deleteXWikiCollection(BaseCollection object, XWikiContext context, boolean bTransaction, boolean evict) throws XWikiException {        try {            if (bTransaction) {                checkHibernate(context);                bTransaction = beginTransaction(context);            }            Session session = getSession(context);            if (!object.getClassName().equals("internal")) {                for (Iterator it = object.getFieldList().iterator(); it.hasNext();) {                    BaseProperty property = (BaseProperty)it.next();                    session.delete(property);                    if (evict)                        session.evict(property);                }            }            session.delete(object);            if (evict)                session.evict(object);            if (bTransaction) {                endTransaction(context, true);            }        } catch (Exception e) {            Object[] args = { object.getName() };            throw new XWikiException( XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_HIBERNATE_DELETING_OBJECT,                    "Exception while deleting object {0}", e, args);        } finally {            try {                if (bTransaction)                    endTransaction(context, false);            } catch (Exception e) {}        }    }    public void deleteXWikiObject(BaseObject baseObject, XWikiContext context, boolean bTransaction, boolean bEvict) throws XWikiException {        deleteXWikiCollection(baseObject, context, bTransaction, bEvict);    }    public void deleteXWikiObject(BaseObject baseObject, XWikiContext context, boolean b) throws XWikiException {        deleteXWikiCollection(baseObject, context, b);    }    public void deleteXWikiClass(BaseClass baseClass, XWikiContext context, boolean b) throws XWikiException {        deleteXWikiCollection(baseClass, context, b);    }    public void loadXWikiProperty(PropertyInterface property, XWikiContext context, boolean bTransaction) throws XWikiException    {        try {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -