Search in sources :

Example 41 with IntegerValue

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));
    }
}
Also used : SQLException(java.sql.SQLException) XPathException(org.exist.xquery.XPathException) IntegerValue(org.exist.xquery.value.IntegerValue) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement)

Example 42 with IntegerValue

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());
}
Also used : Account(org.exist.security.Account) SecurityManager(org.exist.security.SecurityManager) IntegerValue(org.exist.xquery.value.IntegerValue)

Example 43 with IntegerValue

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());
    }
}
Also used : XPathException(org.exist.xquery.XPathException) IntegerValue(org.exist.xquery.value.IntegerValue) StringValue(org.exist.xquery.value.StringValue)

Example 44 with IntegerValue

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;
}
Also used : XPathException(org.exist.xquery.XPathException) IntegerValue(org.exist.xquery.value.IntegerValue) Sequence(org.exist.xquery.value.Sequence)

Example 45 with IntegerValue

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;
}
Also used : IntegerValue(org.exist.xquery.value.IntegerValue) Sequence(org.exist.xquery.value.Sequence)

Aggregations

IntegerValue (org.exist.xquery.value.IntegerValue)63 Sequence (org.exist.xquery.value.Sequence)33 XPathException (org.exist.xquery.XPathException)32 BrokerPool (org.exist.storage.BrokerPool)11 DBBroker (org.exist.storage.DBBroker)11 Test (org.junit.Test)11 Txn (org.exist.storage.txn.Txn)8 MessagingException (jakarta.mail.MessagingException)7 StringInputSource (org.exist.util.StringInputSource)7 NamingException (javax.naming.NamingException)6 DirContext (javax.naming.directory.DirContext)6 QName (org.exist.dom.QName)6 Source (org.exist.source.Source)6 StringSource (org.exist.source.StringSource)6 InputStream (java.io.InputStream)5 Map (java.util.Map)5 StringValue (org.exist.xquery.value.StringValue)5 ValueSequence (org.exist.xquery.value.ValueSequence)5 Folder (jakarta.mail.Folder)4 Image (java.awt.Image)4