use of org.exist.xquery.value.IntegerValue in project exist by eXist-db.
the class PrepareFunction method eval.
/**
* evaluate the call to the XQuery prepare() function, it is really the main entry point of this class.
*
* @param args arguments from the prepare() function call
* @param contextSequence the Context Sequence to operate on (not used here internally!)
* @return A xs:long representing the handle to the prepared statement
* @throws XPathException DOCUMENT ME!
* @see org.exist.xquery.BasicFunction#eval(org.exist.xquery.value.Sequence[], org.exist.xquery.value.Sequence)
*/
@Override
public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {
// was a connection and SQL statement specified?
if (args[0].isEmpty() || args[1].isEmpty()) {
return (Sequence.EMPTY_SEQUENCE);
}
// get the Connection
long connectionUID = ((IntegerValue) args[0].itemAt(0)).getLong();
Connection con = SQLModule.retrieveConnection(context, connectionUID);
if (con == null) {
return (Sequence.EMPTY_SEQUENCE);
}
// get the SQL statement
String sql = args[1].getStringValue();
PreparedStatement stmt = null;
try {
// execute the SQL statement
stmt = con.prepareStatement(sql);
// store the PreparedStatement and return the uid handle of the PreparedStatement
return (new IntegerValue(SQLModule.storePreparedStatement(context, new PreparedStatementWithSQL(sql, stmt)), Type.LONG));
} catch (SQLException sqle) {
LOG.error("sql:prepare() Caught SQLException \"{}\" for SQL: \"{}\"", sqle.getMessage(), sql, sqle);
throw (new XPathException(this, "sql:prepare() Caught SQLException \"" + sqle.getMessage() + "\" for SQL: \"" + sql + "\"", sqle));
}
}
use of org.exist.xquery.value.IntegerValue in project exist by eXist-db.
the class UMaskFunction method getUMask.
private IntegerValue getUMask(final DBBroker broker, final String username) {
final SecurityManager securityManager = broker.getBrokerPool().getSecurityManager();
final Account account = securityManager.getAccount(username);
return new IntegerValue(account.getUserMask());
}
use of org.exist.xquery.value.IntegerValue in project exist by eXist-db.
the class ExampleFunctions method eval.
@Override
public Sequence eval(final Sequence[] args, final Sequence contextSequence) throws XPathException {
switch(getName().getLocalPart()) {
case FS_HELLO_WORLD_NAME:
return sayHello(Optional.of(new StringValue("World")));
case FS_SAY_HELLO_NAME:
final Optional<StringValue> name = args[0].isEmpty() ? Optional.empty() : Optional.of((StringValue) args[0].itemAt(0));
return sayHello(name);
case FS_ADD_NAME:
final IntegerValue a = (IntegerValue) args[0].itemAt(0);
final IntegerValue b = (IntegerValue) args[1].itemAt(0);
return add(a, b);
default:
throw new XPathException(this, "No function: " + getName() + "#" + getSignature().getArgumentCount());
}
}
use of org.exist.xquery.value.IntegerValue in project exist by eXist-db.
the class FunLast method eval.
/* (non-Javadoc)
* @see org.exist.xquery.functions.Function#eval(org.exist.xquery.StaticContext, org.exist.dom.persistent.DocumentSet, org.exist.xquery.value.Sequence, org.exist.xquery.value.Item)
*/
public Sequence eval(Sequence contextSequence, Item contextItem) throws XPathException {
if (context.getProfiler().isEnabled()) {
context.getProfiler().start(this);
context.getProfiler().message(this, Profiler.DEPENDENCIES, "DEPENDENCIES", Dependency.getDependenciesName(this.getDependencies()));
if (contextSequence != null) {
context.getProfiler().message(this, Profiler.START_SEQUENCES, "CONTEXT SEQUENCE", contextSequence);
}
if (contextItem != null) {
context.getProfiler().message(this, Profiler.START_SEQUENCES, "CONTEXT ITEM", contextItem.toSequence());
}
}
Sequence inSequence = context.getContextSequence();
if (inSequence == null) {
inSequence = contextSequence;
}
Sequence result;
if (inSequence == null) {
throw new XPathException(this, ErrorCodes.XPDY0002, "undefined context item");
} else if (inSequence.isEmpty()) {
result = Sequence.EMPTY_SEQUENCE;
} else {
result = new IntegerValue(inSequence.getItemCount());
}
if (context.getProfiler().isEnabled()) {
context.getProfiler().end(this, "", result);
}
return result;
}
use of org.exist.xquery.value.IntegerValue in project exist by eXist-db.
the class FunStrLength method eval.
@Override
public Sequence eval(Sequence contextSequence, final Item contextItem) throws XPathException {
if (context.getProfiler().isEnabled()) {
context.getProfiler().start(this);
context.getProfiler().message(this, Profiler.DEPENDENCIES, "DEPENDENCIES", Dependency.getDependenciesName(this.getDependencies()));
if (contextSequence != null) {
context.getProfiler().message(this, Profiler.START_SEQUENCES, "CONTEXT SEQUENCE", contextSequence);
}
if (contextItem != null) {
context.getProfiler().message(this, Profiler.START_SEQUENCES, "CONTEXT ITEM", contextItem.toSequence());
}
}
if (contextItem != null) {
contextSequence = contextItem.toSequence();
}
if (getSignature().getArgumentCount() == 1) {
contextSequence = getArgument(0).eval(contextSequence);
}
if (contextSequence == null) {
throw new XPathException(this, ErrorCodes.XPDY0002, "Undefined context item");
}
final String strval = contextSequence.getStringValue();
final Sequence result = new IntegerValue(FunStringToCodepoints.getCodePointCount(strval));
if (context.getProfiler().isEnabled()) {
context.getProfiler().end(this, "", result);
}
return result;
}
Aggregations