Skip to content

Commit

Permalink
Merge pull request #265 from dkpro/bugfix/264-Compiler-error-in-Eclip…
Browse files Browse the repository at this point in the history
…se-only

#264 - Compiler error in Eclipse only
  • Loading branch information
reckart authored Oct 31, 2023
2 parents 3a56be3 + 1870e19 commit 2461903
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions dkpro-jwpl-api/src/main/java/org/dkpro/jwpl/api/Wikipedia.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.dkpro.jwpl.api.hibernate.WikiHibernateUtil;
import org.dkpro.jwpl.util.distance.LevenshteinStringDistance;
import org.hibernate.Session;
import org.hibernate.query.NativeQuery;
import org.hibernate.type.StandardBasicTypes;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -753,30 +754,38 @@ public Language getLanguage()
*/
public boolean existsPage(String title)
{

if (title == null || title.isEmpty()) {
return false;
}

Title t;
try {
t = new Title(title);
}
catch (WikiTitleParsingException e) {
return false;
}

String encodedTitle = t.getWikiStyleTitle();

Session session = this.__getHibernateSession();
session.beginTransaction();
String query = "select p.id from PageMapLine as p where p.name = :pName";
if (dbConfig.supportsCollation()) {
query += SQL_COLLATION;
}
Object returnValue = session.createNativeQuery(query)
.setParameter("pName", encodedTitle, StandardBasicTypes.STRING).uniqueResult();
session.getTransaction().commit();
try {
session.beginTransaction();
var query = "select p.id from PageMapLine as p where p.name = :pName";
if (dbConfig.supportsCollation()) {
query += SQL_COLLATION;
}

return returnValue != null;
// Eclipse somehow thinks that setParameter returns a MutationQuery instead of a
// NativeQuery...
var nativeQuery = (NativeQuery) session.createNativeQuery(query) //
.setParameter("pName", encodedTitle, StandardBasicTypes.STRING);
var returnValue = nativeQuery.uniqueResult();
return returnValue != null;
}
finally {
session.getTransaction().commit();
}
}

/**
Expand Down

0 comments on commit 2461903

Please sign in to comment.