My description was a little lousy. So, I thought I'll try it out. It didn't
really work, but that's probably cause my patch is faulty.
I didn't combine both the lists. I just added extra info to them at the end
of determineUri. I'll check out what I did wrong tomorrow. If I can't figure
it out. I'll go for your method and combine determineUri() and load().
- Vishesh Handa
Index: resourcedata.cpp
===================================================================
--- resourcedata.cpp (revision 1129689)
+++ resourcedata.cpp (working copy)
@@ -60,7 +60,6 @@ Nepomuk::ResourceData::ResourceData( con
m_kickoffUri( uri ),
m_mainType( type ),
m_modificationMutex(QMutex::Recursive),
- m_proxyData(0),
m_cacheDirty(true),
m_pimoThing(0),
m_groundingOccurence(0),
@@ -102,16 +101,12 @@ bool Nepomuk::ResourceData::isFile()
QUrl Nepomuk::ResourceData::uri() const
{
- if( m_proxyData )
- return m_proxyData->uri();
return m_uri;
}
QUrl Nepomuk::ResourceData::type()
{
- if( m_proxyData )
- return m_proxyData->type();
load();
return m_mainType;
}
@@ -119,8 +114,6 @@ QUrl Nepomuk::ResourceData::type()
QList<QUrl> Nepomuk::ResourceData::allTypes()
{
- if( m_proxyData )
- return m_proxyData->allTypes();
load();
return m_types;
}
@@ -128,10 +121,7 @@ QList<QUrl> Nepomuk::ResourceData::allTy
void Nepomuk::ResourceData::setTypes( const QList<QUrl>& types )
{
- if( m_proxyData ) {
- m_proxyData->setTypes( types );
- }
- else if ( store() ) {
+ if ( store() ) {
QMutexLocker lock(&m_modificationMutex);
// reset types
@@ -154,19 +144,9 @@ void Nepomuk::ResourceData::setTypes( co
void Nepomuk::ResourceData::resetAll( bool isDelete )
{
- // reset proxy
- bool hadProxy = false;
- if( m_proxyData ) {
- hadProxy = true;
- if( !m_proxyData->deref() &&
- rm()->dataCacheFull() )
- delete m_proxyData;
- m_proxyData = 0;
- }
-
// remove us from all caches (store() will re-insert us later if necessary)
m_rm->mutex.lock();
- if( !m_uri.isEmpty() && !hadProxy ) // if we had a proxy we were not in m_initializedData ourselves
+ if( !m_uri.isEmpty() )
m_rm->m_initializedData.remove( m_uri );
if( !m_kickoffUri.isEmpty() )
m_rm->m_uriKickoffData.remove( m_kickoffUri );
@@ -197,9 +177,6 @@ void Nepomuk::ResourceData::resetAll( bo
QHash<QUrl, Nepomuk::Variant> Nepomuk::ResourceData::allProperties()
{
- if( m_proxyData )
- return m_proxyData->allProperties();
-
load();
return m_cache;
@@ -208,9 +185,6 @@ QHash<QUrl, Nepomuk::Variant> Nepomuk::R
bool Nepomuk::ResourceData::hasProperty( const QUrl& uri )
{
- if( m_proxyData )
- return m_proxyData->hasProperty( uri );
-
if( !load() )
return false;
@@ -224,9 +198,6 @@ bool Nepomuk::ResourceData::hasProperty(
bool Nepomuk::ResourceData::hasProperty( const QUrl& p, const Variant& v )
{
- if( m_proxyData )
- return m_proxyData->hasProperty( p, v );
-
if( !load() )
return false;
@@ -246,9 +217,6 @@ bool Nepomuk::ResourceData::hasProperty(
bool Nepomuk::ResourceData::hasType( const QUrl& uri )
{
- if( m_proxyData )
- return m_proxyData->hasType( uri );
-
load();
return constHasType( uri );
}
@@ -274,9 +242,6 @@ bool Nepomuk::ResourceData::constHasType
Nepomuk::Variant Nepomuk::ResourceData::property( const QUrl& uri )
{
- if( m_proxyData )
- return m_proxyData->property( uri );
-
if ( load() ) {
// we need to protect the reading, too. load my be triggered from another thread's
// connection to a Soprano statement signal
@@ -476,9 +441,6 @@ void Nepomuk::ResourceData::setProperty(
{
Q_ASSERT( uri.isValid() );
- if( m_proxyData )
- return m_proxyData->setProperty( uri, value );
-
// step 0: make sure this resource is in the store
if ( store() ) {
QMutexLocker lock(&m_modificationMutex);
@@ -531,9 +493,6 @@ void Nepomuk::ResourceData::removeProper
{
Q_ASSERT( uri.isValid() );
- if( m_proxyData )
- return m_proxyData->removeProperty( uri );
-
QMutexLocker lock(&m_modificationMutex);
if ( determineUri() ) {
@@ -557,30 +516,20 @@ void Nepomuk::ResourceData::remove( bool
// That way the proxy handling will take care of the rest.
m_rm->determineAllUris();
- if( m_proxyData ) {
- m_proxyData->remove( recursive );
- }
- else {
QMutexLocker lock(&m_modificationMutex);
-
if ( determineUri() ) {
MAINMODEL->removeAllStatements( Statement( m_uri, Node(), Node() ) );
if ( recursive ) {
MAINMODEL->removeAllStatements( Statement( Node(), Node(), m_uri ) );
}
}
- }
-
resetAll();
}
bool Nepomuk::ResourceData::exists()
{
- if( m_proxyData )
- return m_proxyData->exists();
-
if( determineUri() ) {
return MAINMODEL->containsAnyStatement( Statement( m_uri, Node(), Node() ) );
}
@@ -591,19 +540,12 @@ bool Nepomuk::ResourceData::exists()
bool Nepomuk::ResourceData::isValid() const
{
- if( m_proxyData )
- return m_proxyData->isValid();
-
return( !m_mainType.isEmpty() && ( !m_uri.isEmpty() || !m_kickoffUri.isEmpty() || !m_kickoffId.isEmpty() ) );
}
bool Nepomuk::ResourceData::determineUri()
{
- if( m_proxyData )
- return m_proxyData->determineUri();
-
- else {
//
// Preconditions:
// 1. m_kickoffId is not a local file path or URL (use m_kickoffUri for that)
@@ -687,7 +629,7 @@ bool Nepomuk::ResourceData::determineUri
}
else {
m_uri = uri;
- m_nieUrl = uri;
+ m_nieUrl = m_kickoffUri;
}
it.close();
}
@@ -743,14 +685,48 @@ bool Nepomuk::ResourceData::determineUri
m_rm->m_initializedData.insert( m_uri, this );
}
else {
- m_proxyData = it.value();
- m_proxyData->ref();
- }
+ Q_ASSERT( "We have a problem!" );
}
+
+ //Insert others identifiers in lists.
+ {
+ kDebug() << "Inserting others";
+ //Uri
+ QUrl uri = m_uri;
+ m_rm->m_idKickoffData.insert( uri.toString(), this );
+ m_rm->m_uriKickoffData.insert( uri, this );
+
+ //nie:url
+ QString query = QString("select ?url where { %1 %2 ?url . }")
+ .arg( Soprano::Node::resourceToN3(m_uri) )
+ .arg( Soprano::Node::resourceToN3( Nepomuk::Vocabulary::NIE::url() ) );
+ Soprano::QueryResultIterator it = model->executeQuery( query, Soprano::Query::QueryLanguageSparql );
+ if( it.next() ) {
+ QUrl url = it["url"].uri();
+
+ m_rm->m_idKickoffData.insert( url.toString(), this );
+ m_rm->m_uriKickoffData.insert( url, this );
}
+ it.close();
- return !m_uri.isEmpty();
+ //nao:identifier
+ query = QString("select ?id where { %1 %2 ?id . }")
+ .arg( Soprano::Node::resourceToN3(m_uri) )
+ .arg( Soprano::Node::resourceToN3( Soprano::Vocabulary::NAO::identifier() ) );
+ it = model->executeQuery( query, Soprano::Query::QueryLanguageSparql );
+ if( it.next() ) {
+ QString iden = it["id"].toString();
+ m_rm->m_idKickoffData.insert( iden, this );
+ }
+ it.close();
+ kDebug() << "Done inserting others";
}
+ }
+ }
+
+ bool res = !m_uri.isEmpty();
+ kDebug() << "Res : " << res;
+ return res;
}
@@ -795,17 +771,13 @@ Nepomuk::Thing Nepomuk::ResourceData::pi
bool Nepomuk::ResourceData::operator==( const ResourceData& other ) const
{
- const ResourceData* that = this;
- if( m_proxyData )
- that = m_proxyData;
-
- if( that == &other )
+ if( this == &other )
return true;
- return( that->m_uri == other.m_uri &&
- that->m_mainType == other.m_mainType &&
- that->m_kickoffUri == other.m_kickoffUri &&
- that->m_kickoffId == other.m_kickoffId );
+ return( this->m_uri == other.m_uri &&
+ this->m_mainType == other.m_mainType &&
+ this->m_kickoffUri == other.m_kickoffUri &&
+ this->m_kickoffId == other.m_kickoffId );
}
@@ -817,8 +789,6 @@ QDebug Nepomuk::ResourceData::operator<<
m_uri.url(),
m_mainType.toString())
.arg(m_ref);
- if(m_proxyData)
- dbg << QLatin1String(", proxy: " ) << *m_proxyData;
return dbg << QLatin1String("]");
}
Index: resourcedata.h
===================================================================
--- resourcedata.h (revision 1129689)
+++ resourcedata.h (working copy)
@@ -155,8 +155,6 @@ namespace Nepomuk {
ResourceManagerPrivate* rm() const { return m_rm; }
- ResourceData* proxy() const { return m_proxyData; }
-
private:
void loadType( const QUrl& type );
@@ -187,14 +185,6 @@ namespace Nepomuk {
QMutex m_determineUriMutex;
mutable QMutex m_modificationMutex;
- /**
- * Used to virtually merge two data objects representing the same
- * resource. This happens if the resource was once created using its
- * actual URI and once via its ID. To prevent early loading we allow
- * this scenario.
- */
- ResourceData* m_proxyData;
-
QHash<QUrl, Variant> m_cache;
bool m_cacheDirty;
Index: resource.cpp
===================================================================
--- resource.cpp (revision 1129689)
+++ resource.cpp (working copy)
@@ -119,13 +119,11 @@ Nepomuk::Resource::~Resource()
if ( m_data ) {
if ( !m_data->deref() ) {
//
- // We delete data objects in one of three cases:
+ // We delete data objects in one of two cases:
// 1. They are not valid and as such not in one of the ResourceManagerPrivate kickoff lists
- // 2. They have a proxy which is the actual thing to reuse later on
// 3. The cache is already full and we need to clean up
//
if ( !m_data->isValid() ||
- m_data->proxy() ||
m_data->rm()->dataCacheFull() ) {
delete m_data;
}
_______________________________________________
Nepomuk mailing list
[email protected]
https://mail.kde.org/mailman/listinfo/nepomuk