Improved performance of lucene index build under SDB. NIHVIVO-1795

This commit is contained in:
bdc34 2011-01-26 20:14:46 +00:00
parent 3c3e160d68
commit 6d696a95c0

View file

@ -18,6 +18,8 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.joda.time.DateTime; import org.joda.time.DateTime;
import com.hp.hpl.jena.datatypes.RDFDatatype;
import com.hp.hpl.jena.datatypes.xsd.XSDDateTime;
import com.hp.hpl.jena.ontology.OntModel; import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.ontology.OntModelSpec; import com.hp.hpl.jena.ontology.OntModelSpec;
import com.hp.hpl.jena.ontology.OntResource; import com.hp.hpl.jena.ontology.OntResource;
@ -435,89 +437,68 @@ public class IndividualSDB extends IndividualImpl implements Individual {
public Date getSunrise() { public Date getSunrise() {
if( this.sunrise == null ){ if( this.sunrise == null ){
String[] graphVars = { "?g" }; String[] graphVars = { "?g" };
String getPropertyValue = String queryStr =
"SELECT ?value" + "SELECT ?value " +
"WHERE { GRAPH ?g { <" + individualURI + "> " + "WHERE { GRAPH ?g { <" + individualURI + "> " +
"<" + webappDaoFactory.getJenaBaseDao().SUNRISE + "> " + "<" + webappDaoFactory.getJenaBaseDao().SUNRISE + "> " +
"?value} \n" + "?value} \n" +
WebappDaoFactorySDB.getFilterBlock(graphVars, datasetMode) + //WebappDaoFactorySDB.getFilterBlock(graphVars, datasetMode) +
"}"; "}";
DatasetWrapper w = getDatasetWrapper(); DatasetWrapper w = getDatasetWrapper();
Dataset dataset = w.getDataset(); Dataset dataset = w.getDataset();
dataset.getLock().enterCriticalSection(Lock.READ); dataset.getLock().enterCriticalSection(Lock.READ);
try{ try{
sunrise =(Date) ResultSet rs = QueryExecutionFactory.create(QueryFactory.create(queryStr), dataset)
((Literal)QueryExecutionFactory.create(QueryFactory.create(getPropertyValue), dataset) .execSelect();
.execSelect()).getValue(); if( rs.hasNext()){
QuerySolution qs = rs.nextSolution();
if( qs.get("value") != null ){
Literal value = qs.get("value").asLiteral();
RDFDatatype datatype = value.getDatatype();
XSDDateTime xsdDt = (XSDDateTime)datatype.parse( value.getLexicalForm() );
sunrise = xsdDt.asCalendar().getTime();
}
}
}catch(Exception ex){ }catch(Exception ex){
log.error("could not get sunrise: " + ex.getMessage(),ex); log.error("could not get sunrise: " + ex.getMessage(),ex);
}finally{ }finally{
dataset.getLock().leaveCriticalSection(); dataset.getLock().leaveCriticalSection();
w.close(); w.close();
} }
} }
return sunrise; return sunrise;
// if (sunrise != null) {
// return sunrise;
// } else {
// constructProperty(ind, VitroVocabulary.SUNRISE);
// ind.getOntModel().enterCriticalSection(Lock.READ);
// try {
// sunrise = webappDaoFactory.getJenaBaseDao()
// .getPropertyDateTimeValue(
// ind,webappDaoFactory.getJenaBaseDao().SUNRISE);
// return sunrise;
// } finally {
// ind.getOntModel().leaveCriticalSection();
// }
// }
} }
public Date getSunset() { public Date getSunset() {
if( this.sunset == null ){ if( this.sunset == null ){
String[] graphVars = { "?g" }; String[] graphVars = { "?g" };
String getPropertyValue = String queryStr =
"SELECT ?value" + "SELECT ?value " +
"WHERE { GRAPH ?g { <" + individualURI + "> " + "WHERE { GRAPH ?g { <" + individualURI + "> " +
"<"+webappDaoFactory.getJenaBaseDao().SUNSET+"> " + "<"+webappDaoFactory.getJenaBaseDao().SUNSET+"> ?value} }";
"?value} \n" +
WebappDaoFactorySDB.getFilterBlock(graphVars, datasetMode) +
"}";
DatasetWrapper w = getDatasetWrapper(); DatasetWrapper w = getDatasetWrapper();
Dataset dataset = w.getDataset(); Dataset dataset = w.getDataset();
dataset.getLock().enterCriticalSection(Lock.READ); dataset.getLock().enterCriticalSection(Lock.READ);
try{ try{
sunset =(Date) ResultSet rs = QueryExecutionFactory.create(QueryFactory.create(queryStr), dataset)
((Literal)QueryExecutionFactory.create(QueryFactory.create(getPropertyValue), dataset) .execSelect();
.execSelect()).getValue(); if( rs.hasNext()){
QuerySolution qs = rs.nextSolution();
if( qs.get("value") != null ){
Literal value = qs.get("value").asLiteral();
RDFDatatype datatype = value.getDatatype();
XSDDateTime xsdDt = (XSDDateTime)datatype.parse( value.getLexicalForm() );
sunset = xsdDt.asCalendar().getTime();
}
}
}catch(Exception ex){ }catch(Exception ex){
log.error("could not get sunset: " + ex.getMessage(),ex); log.error("could not get sunset: " + ex.getMessage(),ex);
}finally{ }finally{
dataset.getLock().leaveCriticalSection(); dataset.getLock().leaveCriticalSection();
w.close(); w.close();
} }
} }
return sunset;
return sunset;
// if (sunset != null) {
// return sunset;
// } else {
// constructProperty(ind, VitroVocabulary.SUNSET);
// ind.getOntModel().enterCriticalSection(Lock.READ);
// try {
// sunset = webappDaoFactory.getJenaBaseDao()
// .getPropertyDateTimeValue(
// ind,webappDaoFactory.getJenaBaseDao().SUNSET);
// return sunset;
// } finally {
//
// ind.getOntModel().leaveCriticalSection();
// }
// }
} }
public Date getTimekey() { public Date getTimekey() {