use of org.apache.jackrabbit.core.SessionImpl in project jackrabbit by apache.
the class QueryImpl method getColumns.
/**
* Returns the columns for this query.
*
* @return array of columns.
* @throws RepositoryException if an error occurs.
*/
protected ColumnImpl[] getColumns() throws RepositoryException {
SessionImpl session = sessionContext.getSessionImpl();
QueryObjectModelFactory qomFactory = session.getWorkspace().getQueryManager().getQOMFactory();
// get columns
Map<Name, ColumnImpl> columns = new LinkedHashMap<Name, ColumnImpl>();
for (Name name : root.getSelectProperties()) {
String pn = sessionContext.getJCRName(name);
ColumnImpl col = (ColumnImpl) qomFactory.column(sessionContext.getJCRName(DEFAULT_SELECTOR_NAME), pn, pn);
columns.put(name, col);
}
if (columns.size() == 0) {
// use node type constraint
LocationStepQueryNode[] steps = root.getLocationNode().getPathSteps();
final Name[] ntName = new Name[1];
steps[steps.length - 1].acceptOperands(new DefaultQueryNodeVisitor() {
public Object visit(AndQueryNode node, Object data) throws RepositoryException {
return node.acceptOperands(this, data);
}
public Object visit(NodeTypeQueryNode node, Object data) {
ntName[0] = node.getValue();
return data;
}
}, null);
if (ntName[0] == null) {
ntName[0] = NameConstants.NT_BASE;
}
NodeTypeImpl nt = session.getNodeTypeManager().getNodeType(ntName[0]);
PropertyDefinition[] propDefs = nt.getPropertyDefinitions();
for (PropertyDefinition pd : propDefs) {
QPropertyDefinition propDef = ((PropertyDefinitionImpl) pd).unwrap();
if (!propDef.definesResidual() && !propDef.isMultiple()) {
columns.put(propDef.getName(), columnForName(propDef.getName()));
}
}
}
// add jcr:path and jcr:score if not selected already
if (!columns.containsKey(NameConstants.JCR_PATH)) {
columns.put(NameConstants.JCR_PATH, columnForName(NameConstants.JCR_PATH));
}
if (!columns.containsKey(NameConstants.JCR_SCORE)) {
columns.put(NameConstants.JCR_SCORE, columnForName(NameConstants.JCR_SCORE));
}
return columns.values().toArray(new ColumnImpl[columns.size()]);
}
use of org.apache.jackrabbit.core.SessionImpl in project jackrabbit by apache.
the class ChildNodeConstraint method evaluate.
/**
* {@inheritDoc}
*/
public boolean evaluate(ScoreNode[] row, Name[] selectorNames, EvaluationContext context) throws IOException {
ScoreNode sn = row[getSelectorIndex(selectorNames)];
if (sn == null) {
return false;
}
SessionImpl session = context.getSession();
NodeImpl parent;
try {
parent = (NodeImpl) session.getNodeById(sn.getNodeId()).getParent();
} catch (RepositoryException e) {
return false;
}
return parent.getId().equals(getBaseNodeId(context));
}
use of org.apache.jackrabbit.core.SessionImpl in project jackrabbit by apache.
the class DescendantNodeConstraint method evaluate.
/**
* {@inheritDoc}
*/
public boolean evaluate(ScoreNode[] row, Name[] selectorNames, EvaluationContext context) throws IOException {
NodeId baseId = getBaseNodeId(context);
if (baseId == null) {
return false;
}
ScoreNode sn = row[getSelectorIndex(selectorNames)];
if (sn == null) {
return false;
}
NodeId id = sn.getNodeId();
SessionImpl session = context.getSession();
try {
NodeImpl parent = session.getNodeById(id);
for (; ; ) {
// throws exception if there is no parent
parent = (NodeImpl) parent.getParent();
if (parent.getId().equals(baseId)) {
return true;
}
}
} catch (RepositoryException e) {
return false;
}
}
use of org.apache.jackrabbit.core.SessionImpl in project jackrabbit by apache.
the class DefaultLoginModule method doInit.
//------------------------------------------------< AbstractLoginModule >---
/**
* Retrieves the user manager from the specified session. If this fails
* this login modules initialization must fail.
*
* @see AbstractLoginModule#doInit(CallbackHandler, Session, Map)
*/
@Override
protected void doInit(CallbackHandler callbackHandler, Session session, Map options) throws LoginException {
if (!(session instanceof SessionImpl)) {
throw new LoginException("Unable to initialize LoginModule: SessionImpl expected.");
}
try {
this.session = (SessionImpl) session;
userManager = this.session.getUserManager();
log.debug("- UserManager -> '" + userManager.getClass().getName() + "'");
} catch (RepositoryException e) {
throw new LoginException("Unable to initialize LoginModule: " + e.getMessage());
}
// configuration options related to token based authentication
if (options.containsKey(PARAM_DISABLE_TOKEN_AUTH)) {
disableTokenAuth = Boolean.parseBoolean(options.get(PARAM_DISABLE_TOKEN_AUTH).toString());
log.debug("- Token authentication disabled -> '" + disableTokenAuth + "'");
}
if (options.containsKey(PARAM_TOKEN_EXPIRATION)) {
try {
tokenExpiration = Long.parseLong(options.get(PARAM_TOKEN_EXPIRATION).toString());
log.debug("- Token expiration -> '" + tokenExpiration + "'");
} catch (NumberFormatException e) {
log.warn("Unabled to parse token expiration: {}", e.getMessage());
}
}
}
use of org.apache.jackrabbit.core.SessionImpl in project jackrabbit by apache.
the class GCConcurrentTest method testConcurrentDelete.
public void testConcurrentDelete() throws Exception {
Node root = testRootNode;
Session session = root.getSession();
final String testNodeName = "testConcurrentDelete";
node(root, testNodeName);
session.save();
DataStoreGarbageCollector gc = ((SessionImpl) session).createDataStoreGarbageCollector();
gc.setPersistenceManagerScan(false);
gc.setMarkEventListener(new MarkEventListener() {
public void beforeScanning(Node n) throws RepositoryException {
if (n.getName().equals(testNodeName)) {
n.remove();
n.getSession().save();
}
}
});
gc.mark();
gc.close();
}
Aggregations