Path not included in Queryresult (row.getValue) - jackrabbit

we still have Jackrabbit 2 (2.18.0) in use and I have a problem with loading the "jcr:path" in the Query-Result.
In this example we have a custom node "org:permission" with a custom property "org:permissionHolderIds".
The custom property is filled in values in the found rows.
String queryString = "SELECT [jcr:path], [org:permissionHolderIds] FROM [org:permission]";
QueryManager queryManager = session.getWorkspace().getQueryManager();
Query query = queryManager.createQuery(queryString, Query.JCR_SQL2);
QueryResult queryResult = query.execute();
RowIterator rows = queryResult.getRows();
Row r = rows.nextRow();
String holder= r.getValue("org:permissionHolderIds").getString();
// is filled properly
String path = r.getValue("jcr:path").getString();
// path is empty all the time :-(
Until now we iterated over the found nodes but this causes additional data base queries and is slow. So we tried to improve our performance and fetch all the necessary data in the query.
Thank you!

jcr:path is not a node property, so this is not supposed to do what you want. That said, why don't you use https://docs.adobe.com/docs/en/spec/javax.jcr/javadocs/jcr-2.0/javax/jcr/query/Row.html#getPath()?

Related

Why does this get method stop returning correctly?

I am trying to write an app engine application for my university. What I am trying to achieve right now, is to create a method which takes in a Course name, and returns a list of all the CourseYears (think of that as being like a link table e.g. if Maths is the course, and it has Year 1, year 2 and Year 3; MathsYear1, MathsYear2 and MathsYear3 would be the names of the CourseYears).
This is the code for the module (WARING: super dirty code below!):
#ApiMethod(name = "courseYears")
public ArrayList<CourseYear> courseYears(#Named("name") String name){
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
Query.Filter keyFilter = new Query.FilterPredicate("name", Query.FilterOperator.EQUAL, name);
Query query = new Query("Course").setFilter(keyFilter);
PreparedQuery preparedQuery = datastore.prepare(query);
List<Entity> resultList = preparedQuery.asList(FetchOptions.Builder.withLimit(1));
Course course = ofy().load().type(Course.class).id(resultList.get(0).getKey().getId()).now();
ArrayList<String> courseYearNames = course.getAllCourseYearNames();
System.out.println(course.getName());
ArrayList<CourseYear> courseYears = new ArrayList<CourseYear>();
for(String courseYearName: courseYearNames){
Query.Filter courseNameFilter = new Query.FilterPredicate("name", Query.FilterOperator.EQUAL, courseYearName);
Query query2 = new Query("CourseYear").setFilter(courseNameFilter);
List<Entity> resL = preparedQuery.asList(FetchOptions.Builder.withLimit(1));
System.out.println("test");
CourseYear courseYear = ofy().load().type(CourseYear.class).id(resL.get(0).getKey().getId()).now();
courseYears.add(courseYear);
}
return courseYears;
}
It basically takes a Course name in, applies a filter on all courses to get the corresponding Course object, and then calls getAllCourseYearNames() on the course to get an array list containing all its CourseYears' names. (I would have loved to do this using Keys, but parameterised Objectify keys don't seem to be supported in this version of App Engine).
I then try and get the CourseYears by looping through the arraylist of names and applying the filter for each name. I print "test" each time to see how many times it is looping. Like I said, a super dirty way of doing it.
When I try passing a few course names as a parameters, it loops the correct number of times only once or twice, and after that does not loop at all (doesn't print "test"). I could understand if it never looped, but not doing it correctly once or twice and then never again. It doesn't successfully return a list of CourseYears when it does work, but rather the relevant number of NULLs - I don't know if this is relevant. I believe it successfully retrieves the course every time, as I print the name of the course after loading and it never fails to do this.
If anyone has ANY suggestions for why this may be happening, I would be incredibly grateful to hear them!
Thanks
query2 is never used in your code. You reuse preparedQuery from your previous query, which runs on a different entity kind.

ndb query by KeyProperty

I'm struggling with a KeyProperty query, and can't see what's wrong.
My model is
class MyList(ndb.Model):
user = ndb.KeyProperty(indexed=True)
status = ndb.BooleanProperty(default=True)
items = ndb.StructuredProperty(MyRef, repeated=True, indexed=False)
I create an instance of MyList with the appropriate data and can run the following properly
cls = MyList
lists = cls.query().fetch()
Returns
[MyList(key=Key('MyList', 12), status=True, items=..., user=Key('User', 11))]
But it fails when I try to filter by user, i.e. finding lists where the user equals a particular entity; even when using the one I've just used for insert, or from the previous query result.
key = lists[0].user
lists = cls.query(cls.user=key).fetch()
Returns
[]
But works fine with status=True as the filter, and I can't see what's missing?
I should add it happens in a unit testing environment with the following v3_stub
self.policy = datastore_stub_util.PseudoRandomHRConsistencyPolicy(probability=0)
self.testbed.init_datastore_v3_stub(
require_indexes=True,
root_path="%s/../"%(os.path.dirname(__file__)),
consistency_policy=self.policy
)
user=Key('User', 11) is a key to a different class: User. Not MyList
Perhaps you meant:
user = ndb.KeyProperty(kind='User', indexed=True)
Your code looks fine, but I have noticed some data integrity issues when developing locally with NDB. I copied your model and code, and I also got the empty list at first, but then after a few more attempts, the data is there.
Try it a few times?
edit: possibly related?
google app engine ndb: put() and then query(), there is always one less item

How to store data from SmartGWT ListGrid?

I've been searching for hours but I couldn't find an answer to my question: I've set up a ListGrid similar to the one shown here (Link). Right now I am using a XML-File as data source (default rows) just like in the example. It is also possible to add and delete rows to/from the grid.
Therefore I would like to store every user's data from the grid in a data store (Google Datastore). So I need to read all the rows of the current user as Strings. What would be a good way to do that? I already tried the following, but without success:
ListGrid componentsGrid = new ListGrid();
componentsGrid.setWidth(500);
componentsGrid.setHeight(224);
componentsGrid.setCellHeight(22);
componentsGrid.setDataSource(ComponentsXmlDS.getInstance());
componentsGrid.setAutoFetchData(true);
componentsGrid.setCanEdit(true);
componentsGrid.setModalEditing(true);
componentsGrid.setEditEvent(ListGridEditEvent.CLICK);
componentsGrid.setListEndEditAction(RowEndEditAction.NEXT);
componentsGrid.setAutoSaveEdits(false);
layout.addMember(componentsGrid);
//First try
componentsGrid.fetchData();
logger.log(Level.INFO, "Components: "+ componentsGrid.getResultSet().get(0).getAttribute("componentType"));
//Second try
logger.log(Level.INFO, "Components: "+ componentsGrid.getAllFields());
// Third try
logger.log(Level.INFO, "Components: "+ componentsGrid.getRecords());
Anyone having a hint? Help is greatly appreciated.
If I understand well your requirement you want to read all the rows of the grid and store their data in a db.
I think you can use:
getRecordList() which *Return the underlying data of this DataBoundComponent as a RecordList.
You will be able to iterate inside this list, extract the attribute value you want for every record and store these data in your db.
Or use the getRecords() method as you said and iterate in the array of ListGridRecord obtained.
To iterate through your RecordList you have to transform it to an array, for example with a lot of dummy objects and methods:
RecordList data = MyGrid.getRecordList();
for(Record record : data.toArray()){
MyDataObject obj = new MyDataObject()
obj.setId(record.getAttribute("thId"));
obj.setOne(record.getAttribute("anAttribute"));
obj.setTwo(record.getAttribute("anotherAttribute"));
obj.StoreToDb();
}

Get all the Records from GXTGrid

//MyGrid
ListStore< PojoSurveyReportApproved> store = new ListStore< PojoSurveyReportApproved>(loader);
List<ColumnConfig> configs = getSurvey(list);
cm = new ColumnModel(configs);
cp = new ContentPanel();
final Grid< PojoSurveyReportApproved> grid = new Grid< PojoSurveyReportApproved>(store, cm);
grid.setTitle("ddddddd");
grid.setBorders(true);
grid.getAriaSupport().setDescribedBy(toolBar.getId() + "-display");
cp.removeAll();
cp.add(grid);
This is my Grid, which loads dynamically. whenever it changes, all the records from the grid should be retrieved, where i can easily export it to Excel.
Just i want is all the records in the grid eighter as an array or list, is there any listener to handle it or any way i can get all the records.
I have tried out in some ways by adding a listener to a store by it does not gives me result
Did you try-
store.getAll(); ?
This code takes all the records in the grid and returns as a collection. However, you may need to take another arrayList to use the store values depending on your needs.

MVC 4 return entries from database excluding specific items

I've been changing this call around for some time and can not quite get it to work. I am trying to return some records from a database and exclude items based on their ID numbers.
This is a database of quotes and when someone hides a quote it stores the quoteID in a cookie (required) and when returning to the site, The cookie.value is read.
I need to filter these IDs out of the return query and display the results in a view using WebGrid. I have the cookie part working. I retrieve the values (could be multiple) and split this into a list of strings. I then run a foreach loop ans parse the string to an integer and then try to remove quotes that I have retrieved from the database. Here is the code as I am using it...
// Filter on Cookie Value using tokenizer
string value = Request.Cookies.Get("hideCookie").Value;
List<string> values = value.Split(' ').ToList();
var quotes2 = db.Quotes.Include(q => q.QName);
foreach (var i in values)
{
int idv = int.Parse(i);
quotes2 = from q in quotes2 where q.QuoteID != idv select q;
}
return View(quotes2.ToList());
This throws an error "A specified Include path is not valid. The EntityType 'Exercise4.Models.Quote' does not declare a navigation property with the name 'QName'." (QName being an entry in the database record).
If I remove the ToList() in the return View(), quotes2 gets passed to the View but throws this error on the webGrid "A specified Include path is not valid. The EntityType 'Exercise4.Models.Quote' does not declare a navigation property with the name 'QName'."
I'm sure there is a much better way of doing this. Can you please point me in the correct direction so I can stop banging my head against my desk...

Resources