当前位置: 首页>>代码示例>>Java>>正文


Java AttributeUpdates类代码示例

本文整理汇总了Java中com.jcabi.dynamo.AttributeUpdates的典型用法代码示例。如果您正苦于以下问题:Java AttributeUpdates类的具体用法?Java AttributeUpdates怎么用?Java AttributeUpdates使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


AttributeUpdates类属于com.jcabi.dynamo包,在下文中一共展示了AttributeUpdates类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: pay

import com.jcabi.dynamo.AttributeUpdates; //导入依赖的package包/类
@Override
public void pay(final long cents, final String token, final String email)
    throws IOException {
    final String customer;
    try {
        customer = Customer.create(
            new StickyMap<String, Object>(
                new MapEntry<>("email", email),
                new MapEntry<>("source", token)
            ),
            new RequestOptions.RequestOptionsBuilder().setApiKey(
                Manifests.read("ThreeCopies-StripeSecret")
            ).build()
        ).getId();
    } catch (final APIException | APIConnectionException
        | AuthenticationException | CardException
        | InvalidRequestException ex) {
        throw new IOException(ex);
    }
    this.item().put(
        new AttributeUpdates()
            .with(
                "stripe_cents",
                new AttributeValueUpdate().withValue(
                    new AttributeValue().withN(Long.toString(cents))
                ).withAction(AttributeAction.PUT)
            )
            .with(
                "stripe_customer",
                new AttributeValueUpdate().withValue(
                    new AttributeValue().withS(customer)
                ).withAction(AttributeAction.PUT)
            )
    );
    this.rebill();
}
 
开发者ID:yegor256,项目名称:threecopies,代码行数:37,代码来源:DyScript.java

示例2: exec

import com.jcabi.dynamo.AttributeUpdates; //导入依赖的package包/类
@Override
public void exec(final Agent agent) throws IOException {
    final String text = this.item().get(DyDeck.ATTR_MEMO).getS();
    final XML xml = new StrictXML(
        Deck.UPGRADE.transform(
            DyDeck.CLEANUP.transform(new XMLDocument(text))
        ),
        Deck.SCHEMA
    );
    final Iterable<Directive> dirs = agent.exec(xml);
    if (!Iterables.isEmpty(dirs)) {
        final String update = new StrictXML(
            new XMLDocument(
                new Xembler(dirs).applyQuietly(xml.node())
            ),
            Deck.SCHEMA
        ).toString();
        if (!text.equals(update)) {
            this.item().put(
                new AttributeUpdates().with(
                    DyDeck.ATTR_MEMO,
                    update
                )
            );
        }
    }
}
 
开发者ID:yegor256,项目名称:thindeck,代码行数:28,代码来源:DyDeck.java

示例3: updatesTableAttributes

import com.jcabi.dynamo.AttributeUpdates; //导入依赖的package包/类
/**
 * H2Data can update table attributes.
 * @throws Exception In case test fails
 */
@Test
public void updatesTableAttributes() throws Exception {
    final String table = "tests";
    final String key = "tid";
    final int number = 43;
    final String attr = "descr";
    final String value = "Dummy\n\t\u20ac text";
    final String updated = "Updated";
    final MkData data = new H2Data().with(
        table, new String[] {key}, attr
    );
    data.put(table, new Attributes().with(key, number).with(attr, value));
    data.update(
        table,
        new Attributes().with(key, number),
        new AttributeUpdates().with(attr, "something else")
    );
    data.update(
        table,
        new Attributes().with(key, number),
        new AttributeUpdates().with(attr, updated)
    );
    final Iterable<Attributes> result = data.iterate(
        table, new Conditions().with(key, Conditions.equalTo(number))
    );
    MatcherAssert.assertThat(
        result.iterator().next(),
        Matchers.hasEntry(
            Matchers.equalTo(attr),
            Matchers.equalTo(new AttributeValue(updated))
        )
    );
    MatcherAssert.assertThat(
        result,
        Matchers.<Attributes>iterableWithSize(1)
    );
}
 
开发者ID:jcabi,项目名称:jcabi-dynamo,代码行数:42,代码来源:H2DataTest.java

示例4: required

import com.jcabi.dynamo.AttributeUpdates; //导入依赖的package包/类
/**
 * The date/time is expired?
 * @param item The item
 * @param period Either hour, day or week
 * @return Collection of items or empty
 * @throws IOException If fails
 */
private Collection<Item> required(final Item item, final String period)
    throws IOException {
    final Collection<Item> created = new LinkedList<>();
    if (!item.has(period)
        || DyScript.expired(item.get(period).getN(), period)) {
        final long start = System.currentTimeMillis();
        item.put(
            new AttributeUpdates()
                .with(
                    period,
                    new AttributeValueUpdate().withValue(
                        new AttributeValue().withN(Long.toString(start))
                    ).withAction(AttributeAction.PUT)
                )
        );
        created.add(
            this.region.table("logs").put(
                new Attributes()
                    .with("group", new AttributeValue().withS(this.group()))
                    .with(
                        "start",
                        new AttributeValue().withN(Long.toString(start))
                    )
                    .with("login", new AttributeValue().withS(this.login))
                    .with("period", new AttributeValue().withS(period))
                    .with("exit", new AttributeValue().withN("0"))
                    .with(
                        "finish",
                        new AttributeValue().withN(
                            Long.toString(Long.MAX_VALUE)
                        )
                    )
                    .with(
                        "ttl",
                        new AttributeValue().withN(
                            Long.toString(
                                // @checkstyle MagicNumber (2 lines)
                                System.currentTimeMillis() / 1000L
                                    + TimeUnit.DAYS.toSeconds(14L)
                            )
                        )
                    )
                    .with(
                        "ocket",
                        new AttributeValue().withS(
                            String.format(
                                "%s_%s-%s-%tF-%4$tH-%4$tM", this.login,
                                this.name, period, new Date()
                            )
                        )
                    )
            )
        );
    }
    return created;
}
 
开发者ID:yegor256,项目名称:threecopies,代码行数:64,代码来源:DyScript.java

示例5: start

import com.jcabi.dynamo.AttributeUpdates; //导入依赖的package包/类
/**
 * Start a Docker container.
 * @param script The script
 * @param log The log
 * @throws IOException If fails
 */
private void start(final Script script, final Item log)
    throws IOException {
    this.upload("start.sh");
    final XML xml = new XMLDocument(
        new Xembler(script.toXembly()).xmlQuietly()
    );
    final String login = xml.xpath("/script/login/text()").get(0);
    final String period = log.get("period").getS();
    final String container = log.get("ocket").getS();
    this.shell.exec(
        String.join(
            " && ",
            String.format("mkdir -p %s/%s", Routine.DIR, container),
            String.format("cat > %s/%s/script.sh", Routine.DIR, container)
        ),
        new InputOf(
            xml.xpath("/script/bash/text()").get(0).replace("\r\n", "\n")
        ).stream(),
        new DeadOutputStream(),
        new DeadOutputStream()
    );
    this.shell.exec(
        String.format(
            "%s/start.sh %s %s &",
            Routine.DIR, container, period
        ),
        new DeadInputStream(),
        new DeadOutputStream(),
        new DeadOutputStream()
    );
    log.put(
        new AttributeUpdates()
            .with(
                "container",
                new AttributeValueUpdate()
                    .withValue(new AttributeValue().withS(container))
                    .withAction(AttributeAction.PUT)
            )
    );
    Logger.info(this, "Started %s for %s", container, login);
}
 
开发者ID:yegor256,项目名称:threecopies,代码行数:48,代码来源:Routine.java

示例6: finish

import com.jcabi.dynamo.AttributeUpdates; //导入依赖的package包/类
/**
 * Finish already running Docker container.
 * @param script The script
 * @param log The log
 * @throws IOException If fails
 */
private void finish(final Script script, final Item log)
    throws IOException {
    this.upload("finish.sh");
    final String container = log.get("container").getS();
    final ByteArrayOutputStream stdout = new ByteArrayOutputStream();
    this.shell.exec(
        String.join(
            " && ",
            String.format("cd %s", Routine.DIR),
            String.format("./finish.sh %s", container)
        ),
        new DeadInputStream(),
        stdout,
        new DeadOutputStream()
    );
    final String[] parts = new String(
        stdout.toByteArray(), StandardCharsets.UTF_8
    ).split("\n", 2);
    if (parts.length > 1) {
        new Ocket.Text(
            this.bucket.ocket(log.get("ocket").getS())
        ).write(parts[1]);
        final int exit = Integer.parseInt(parts[0].trim());
        log.put(
            new AttributeUpdates()
                .with(
                    "finish",
                    new AttributeValueUpdate().withValue(
                        new AttributeValue().withN(
                            Long.toString(System.currentTimeMillis())
                        )
                    ).withAction(AttributeAction.PUT)
                )
                .with(
                    "exit",
                    new AttributeValueUpdate().withValue(
                        new AttributeValue().withN(Integer.toString(exit))
                    ).withAction(AttributeAction.PUT)
                )
        );
        script.track(
            (System.currentTimeMillis()
                - Long.parseLong(log.get("start").getN()))
                / TimeUnit.SECONDS.toMillis(1L)
        );
        Logger.info(
            this, "Finished %s with %s and %d log bytes",
            container, exit, parts[1].length()
        );
    }
}
 
开发者ID:yegor256,项目名称:threecopies,代码行数:58,代码来源:Routine.java

示例7: add

import com.jcabi.dynamo.AttributeUpdates; //导入依赖的package包/类
/**
 * Add one metric.
 * @param metric XML with metric
 * @throws IOException If fails
 */
private void add(final XML metric) throws IOException {
    final Item item;
    final Iterator<Item> items = this.table.frame()
        .through(
            new QueryValve()
                .withLimit(1)
                .withSelect(Select.ALL_ATTRIBUTES)
        )
        .where("metric", metric.xpath("@name").get(0))
        .where("version", new Version().value())
        .iterator();
    if (items.hasNext()) {
        item = items.next();
    } else {
        item = this.table.put(
            new Attributes()
                .with("metric", metric.xpath("@name").get(0))
                .with("version", new Version().value())
                .with("artifact", "?")
                .with("champions", 0L)
                // @checkstyle MagicNumber (2 lines)
                .with("mean", new DyNum(0.5d).longValue())
                .with("sigma", new DyNum(0.1d).longValue())
        );
    }
    final double mean = Double.parseDouble(
        metric.xpath("mean/text()").get(0)
    );
    final double sigma = Double.parseDouble(
        metric.xpath("sigma/text()").get(0)
    );
    final boolean reverse = Boolean.parseBoolean(
        metric.xpath("reverse/text()").get(0)
    );
    final double mbefore = new DyNum(item, "mean").doubleValue();
    final double sbefore = new DyNum(item, "sigma").doubleValue();
    // @checkstyle BooleanExpressionComplexityCheck (1 line)
    if (sigma < sbefore || mean < mbefore && reverse
        || mean > mbefore && !reverse) {
        item.put(
            new AttributeUpdates()
                .with("artifact", metric.xpath("/index/@artifact").get(0))
                .with(
                    "champions",
                    new AttributeValueUpdate()
                        .withValue(new AttributeValue().withN("1"))
                        .withAction(AttributeAction.ADD)
                )
                .with("mean", new DyNum(mean).update())
                .with("sigma", new DyNum(sigma).update())
        );
    }
}
 
开发者ID:yegor256,项目名称:jpeek,代码行数:59,代码来源:Sigmas.java

示例8: post

import com.jcabi.dynamo.AttributeUpdates; //导入依赖的package包/类
@Override
public void post(final String title, final String text)
    throws IOException {
    final Iterator<Item> items = this.items(title);
    if (items.hasNext()) {
        final Item item = items.next();
        item.put(
            new AttributeUpdates()
                .with(
                    "rank",
                    new AttributeValueUpdate()
                        .withValue(new AttributeValue().withN("1"))
                        .withAction(AttributeAction.ADD)
                )
                .with(
                    "text",
                    new AttributeValueUpdate()
                        .withAction(AttributeAction.PUT)
                        .withValue(
                            new AttributeValue().withS(
                                DyEvents.concat(
                                    item.get("text").getS(),
                                    text
                                )
                            )
                        )
                )
        );
        Logger.info(
            this, "Event updated for %s: \"%s\"",
            this.urn, title
        );
    } else {
        final int rank;
        if (title.startsWith("io.wring.agents.")) {
            rank = -Tv.THOUSAND;
        } else {
            rank = 1;
        }
        this.table().put(
            new Attributes()
                .with("urn", this.urn)
                .with("title", title)
                .with("text", text)
                .with("rank", rank)
                .with("time", System.currentTimeMillis())
        );
        Logger.info(
            this, "Event created for %s: \"%s\"",
            this.urn, title
        );
    }
}
 
开发者ID:yegor256,项目名称:wring,代码行数:54,代码来源:DyEvents.java

示例9: bibitem

import com.jcabi.dynamo.AttributeUpdates; //导入依赖的package包/类
@Override
public void bibitem(final String tex) throws IOException {
    this.item().put(new AttributeUpdates().with(DyBooks.ATTR_BIBITEM, tex));
}
 
开发者ID:yegor256,项目名称:bibrarian,代码行数:5,代码来源:DyBook.java

示例10: update

import com.jcabi.dynamo.AttributeUpdates; //导入依赖的package包/类
/**
 * Add new attribute into the given table.
 * @param table Table name
 * @param keys Keys
 * @param attrs Attributes to save
 * @throws IOException If fails
 */
void update(String table, Attributes keys,
    AttributeUpdates attrs) throws IOException;
 
开发者ID:jcabi,项目名称:jcabi-dynamo,代码行数:10,代码来源:MkData.java


注:本文中的com.jcabi.dynamo.AttributeUpdates类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。