text:
define(function() {
    var Am = window.Am;
    var TEST_TIMEOUT = 50;

    describe("Am", function() {
        describe("View", function() {
            describe("Element", function() {
                afterEach(function() {
                    $("#test").html("");
                });

                it("should be defined", function(done) {
                    expect(Am.View).to.exist;

                    done();
                });

                describe("instance.getElement()", function() {
                    it("should return the appropriate HTMLElement", function(done) {
                        $("#test").append("
");
                        var element = Am.View.Element.create("#test1");

                        expect(element.getElement()).to.equal($("#test1")[0]);

                        done();
                    });

                    it("should return the first HTMLElement if there are multiple HTMLElements", function(done) {
                        $("#test").append("
");
                        $("#test").append("
");
                        var element = Am.View.Element.create("#test1");

                        expect(element.getElement()).to.equal($("#test1")[0]);

                        done();
                    });
                });

                describe("instance.getElements()", function() {
                    it("should return an array of all the HTMLElements", function(done) {
                        $("#test").append("
");
                        $("#test").append("
");
                        var element = Am.View.Element.create("#test1, #test2");
                        var htmlElements = element.getElements();

                        expect(htmlElements[0]).to.equal($("#test1")[0]);
                        expect(htmlElements[1]).to.equal($("#test2")[0]);

                        done();
                    });

                    it("should return sole HTMLElements in an array", function(done) {
                        $("#test").append("
");
                        var element = Am.View.Element.create("#test1");
                        var htmlElements = element.getElements();

                        expect(htmlElements[0]).to.equal($("#test1")[0]);

                        done();
                    });
                });

                describe("instance.addDataBinding()", function() {
                    it("should automatically call refresh() for non-reverse bindings", function(done) {
                        $("#test").append("<input id=\"test1\" type=\"text\">");
                        $("#test").append("<input id=\"test2\" type=\"text\">");
                        $("#test").append("<input id=\"test3\" type=\"text\">");
                        var Person = Am.Model.create("Person", ["name"]);
                        var person = new Person("Alan");
                        var element1 = Am.View.Element.create("#test1");
                        var element2 = Am.View.Element.create("#test2");
                        var element3 = Am.View.Element.create("#test3");

                        element1.addDataBinding(person, "name", { direction: Am.View.Element.ONE_WAY_BINDING });
                        element2.addDataBinding(person, "name", { direction: Am.View.Element.REVERSE_BINDING });
                        element3.addDataBinding(person, "name", { direction: Am.View.Element.TWO_WAY_BINDING });

                        expect($("#test1").val()).to.equal("Alan");
                        expect($("#test2").val()).to.equal("");
                        expect($("#test3").val()).to.equal("Alan");

                        done();
                    });

                    it("should bind the Element's HTMLElement(s)'s innerHTML to the instance by default for " +
                        "non-input HTML elements", function(done) {
                        $("#test").append("
");
                        $("#test").append("
");
                        $("#test").append("
");
                        var Person = Am.Model.create("Person", ["name"]);
                        var person = new Person("Alan");
                        var element1 = Am.View.Element.create("#test1");
                        var element2 = Am.View.Element.create("#test2, #test3");

                        element1.addDataBinding(person, "name");
                        element2.addDataBinding(person, "name");

                        expect($("#test1").html()).to.equal("Alan");
                        expect($("#test2").html()).to.equal("Alan");
                        expect($("#test3").html()).to.equal("Alan");

                        done();
                    });

                    it("should bind the Element's HTMLElement(s)'s value to the instance by default for input HTML " +
                        "elements", function(done) {
                        $("#test").append("<input id=\"test1\" type=\"text\">");
                        $("#test").append("<input id=\"test2\" type=\"text\">");
                        $("#test").append("<input id=\"test3\" type=\"text\">");
                        var Person = Am.Model.create("Person", ["name"]);
                        var person = new Person("Alan");
                        var element1 = Am.View.Element.create("#test1");
                        var element2 = Am.View.Element.create("#test2, #test3");

                        element1.addDataBinding(person, "name");
                        element2.addDataBinding(person, "name");

                        expect($("#test1").val()).to.equal("Alan");
                        expect($("#test2").val()).to.equal("Alan");
                        expect($("#test3").val()).to.equal("Alan");

                        done();
                    });

                    it("should bind the instance to the Element's HTMLElement(s)' characterData by default for " +
                        "non-input HTML  elements", function(done) {
                        $("#test").append("
");
                        $("#test").append("
");
                        $("#test").append("
");
                        var Person = Am.Model.create("Person", ["name"]);
                        var person = new Person("Alan");
                        var element1 = Am.View.Element.create("#test1");
                        var element2 = Am.View.Element.create("#test2, #test3");

                        element1.addDataBinding(person, "name");
                        element2.addDataBinding(person, "name");
                        $("#test1").html("John");

                        window.setTimeout(function() {
                            expect(person.get("name")).to.equal("John");

                            done();
                        }, TEST_TIMEOUT);
                    });

                    it("should bind the instance to the Element's HTMLElement(s)' value by default for input " +
                        "HTML  elements", function(done) {
                        $("#test").append("<input id=\"test1\" type=\"text\">");
                        $("#test").append("<input id=\"test2\" type=\"text\">");
                        $("#test").append("<input id=\"test3\" type=\"text\">");
                        var Person = Am.Model.create("Person", ["name"]);
                        var person = new Person("Alan");
                        var element1 = Am.View.Element.create("#test1");
                        var element2 = Am.View.Element.create("#test2, #test3");

                        element1.addDataBinding(person, "name");
                        element2.addDataBinding(person, "name");
                        $("#test1").val("John");

                        //Manually trigger change event
                        var event = document.createEvent("HTMLEvents");
                        event.initEvent("change", true, true);
                        $("#test1")[0].dispatchEvent(event);

                        window.setTimeout(function() {
                            expect(person.get("name")).to.equal("John");

                            //element2.refresh();

                            //expect($("#test2").html()).to.equal("John");
                            //expect($("#test3").html()).to.equal("John");

                            done();
                        }, TEST_TIMEOUT);
                    });

                    it("should respect the backward transform option on characterData if it is specified",
                        function(done) {
                        $("#test").append("
");
                        var Person = Am.Model.create("Person", ["name"]);
                        var person = new Person("Alan");
                        var element = Am.View.Element.create("#test1");

                        element.addDataBinding(person, "name", {
                            backwardTransform: function(value) { return value.toLowerCase(); }
                        });
                        $("#test1").html("John");

                        window.setTimeout(function() {
                            expect(person.get("name")).to.equal("john");
                            done();
                        }, TEST_TIMEOUT);
                    });

                    it("should respect the backward transform option on attributes if it is specified",
                        function(done) {
                        var assertionCount = 2;
                        var completedCount = 0;
                        var notify = function() {
                            if (++completedCount === assertionCount) {
                                done();
                            }
                        };

                        $("#test").append("
");
                        var Color = Am.Model.create("Color", ["name"]);
                        var color = new Color("Red");
                        var element1 = Am.View.Element.create("#test1");

                        element1.addDataBinding(color, "name", {
                            elementProperties: ["data-color"],
                            backwardTransform: function(value) { return value.toString().toLowerCase(); }
                        });
                        $("#test1")[0].dataset.color = "Blue";

                        window.setTimeout(function() {
                            //Evil workaround PhantomJS not supporting mutation observers or DOMAttrModified
                            if (!window.PHANTOMJS) {
                                expect(color.get("name")).to.equal("blue");
                            }

                            notify();
                        }, TEST_TIMEOUT);

                        $("#test").append("<input id=\"test2\" type=\"text\">");
                        var Input = Am.Model.create("Input", ["type"]);
                        var input = new Input("TEXT");
                        var element2 = Am.View.Element.create("#test2");

                        element2.addDataBinding(input, "type", {
                            elementProperties: ["type"],
                            backwardTransform: function(value) { return value.toString().toUpperCase(); }
                        });

                        $("#test2")[0].type = "email";

                        window.setTimeout(function() {
                            //Evil workaround PhantomJS not supporting mutation observers or DOMAttrModified
                            if (!window.PHANTOMJS) {
                                expect(input.get("type")).to.equal("EMAIL");
                            }

                            notify();
                        }, TEST_TIMEOUT);
                    });

                    it("should respect the backward transform option on input values if it is specified",
                        function(done) {
                        $("#test").append("<input id=\"test1\" type=\"text\">");
                        var Person = Am.Model.create("Person", ["name"]);
                        var person = new Person("Alan");
                        var element = Am.View.Element.create("#test1");

                        element.addDataBinding(person, "name", {
                            backwardTransform: function(value) { return value.toLowerCase(); }
                        });
                        $("#test1").val("John");

                        //Manually trigger change event
                        var event = document.createEvent("HTMLEvents");
                        event.initEvent("change", true, true);
                        $("#test1")[0].dispatchEvent(event);

                        window.setTimeout(function() {
                            expect(person.get("name")).to.equal("john");
                            done();
                        }, TEST_TIMEOUT);
                    });

                    it("should respect the direction option if it is specified, or default to two-way binding",
                        function(done) {
                        $("#test").append("<input id=\"test1\" type=\"text\">");
                        $("#test").append("<input id=\"test2\" type=\"text\">");
                        $("#test").append("<input id=\"test3\" type=\"text\">");
                        $("#test").append("<input id=\"test4\" type=\"text\">");
                        var Person = Am.Model.create("Person", ["name"]);
                        var person = new Person("Alan");
                        var element1 = Am.View.Element.create("#test1");
                        var element2 = Am.View.Element.create("#test2");
                        var element3 = Am.View.Element.create("#test3");
                        var element4 = Am.View.Element.create("#test4");

                        element1.addDataBinding(person, "name", { direction: Am.View.Element.ONE_WAY_BINDING });
                        element2.addDataBinding(person, "name", { direction: Am.View.Element.REVERSE_BINDING });
                        element3.addDataBinding(person, "name", { direction: Am.View.Element.TWO_WAY_BINDING });
                        element4.addDataBinding(person, "name");

                        expect($("#test1").val()).to.equal("Alan");
                        expect($("#test2").val()).to.equal("");
                        expect($("#test3").val()).to.equal("Alan");
                        expect($("#test4").val()).to.equal("Alan");

                        person.set("name", "John");
                        element1.refresh(person);
                        element2.refresh(person);
                        element3.refresh(person);
                        element4.refresh(person);

                        expect($("#test1").val()).to.equal("John");
                        expect($("#test2").val()).to.equal("");
                        expect($("#test3").val()).to.equal("John");
                        expect($("#test4").val()).to.equal("John");

                        done();
                    });
                });

                describe("instance.refresh()", function() {
                    it("should refresh the Element's HTMLElement(s)'s specified attribute (string)",
                        function(done) {
                        $("#test").append("
");
                        var Person = Am.Model.create("Person", ["name"]);
                        var person = new Person("Alan");
                        var element = Am.View.Element.create("#test1");

                        element.addDataBinding(person, "name", { elementProperties: "innerHTML" });

                        expect($("#test1").html()).to.equal("Alan");

                        done();
                    });

                    it("should refresh the Element's HTMLElement(s)'s specified attribute(s) (array)",
                        function(done) {
                        $("#test").append("
");
                        var Person = Am.Model.create("Person", ["name"]);
                        var person = new Person("Alan");
                        var element = Am.View.Element.create("#test1");

                        element.addDataBinding(person, "name", { elementProperties: ["innerHTML", "data-name"] });

                        expect($("#test1").html()).to.equal("Alan");
                        expect($("#test1").data("name")).to.equal("Alan");

                        done();
                    });

                    it("should refresh the Element's HTMLElement(s)'s specified data attribute(s)",
                        function(done) {
                        $("#test").append("
");
                        var Person = Am.Model.create("Person", ["name"]);
                        var person = new Person("Alan");
                        var element = Am.View.Element.create("#test1");

                        element.addDataBinding(person, "name", { elementProperties: ["dataset.test", "data-name"] });

                        expect($("#test1").data("test")).to.equal("Alan");
                        expect($("#test1").data("name")).to.equal("Alan");

                        done();
                    });

                    it("should refresh the Element's HTMLElement(s)'s specified style attribute(s)",
                        function(done) {
                        $("#test").append("
");
                        var Shirt = Am.Model.create("Shirt", ["color"]);
                        var shirt = new Shirt("#f00");
                        var element = Am.View.Element.create("#test1");

                        element.addDataBinding(shirt, "color", { elementProperties: ["style.color"] });

                        expect(
                            $("#test1").css("color") === "#f00" ||
                            $("#test1").css("color") === "#ff0000" ||
                            $("#test1").css("color") === "rgb(255, 0, 0)"
                        ).to.be.true;

                        done();
                    });

                    it("should respect forward transforms",
                        function(done) {
                        $("#test").append("
");
                        $("#test").append("
");
                        var Person = Am.Model.create("Person", ["firstName", "lastName"]);
                        var person = new Person("Alan", "Doe");
                        var element1 = Am.View.Element.create("#test1");
                        var element2 = Am.View.Element.create("#test2");

                        element1.addDataBinding(person, "firstName", { forwardTransform: function(value) {
                            return value.toLowerCase();
                        }});

                        element2.addDataBinding(person, "firstName", { forwardTransform: function(value, instance) {
                            return value.toLowerCase() + " " + instance.get("lastName").toLowerCase();
                        }});

                        expect($("#test1").html()).to.equal("alan");
                        expect($("#test2").html()).to.equal("alan doe");

                        done();
                    });
                });

                describe("instance.removeDataBinding()", function() {
                    it("should remove the Element's HTMLElement(s)'s innerHTML bindings to the instance by default " +
                        "for non-input HTML elements", function(done) {
                        $("#test").append("
");
                        $("#test").append("
");
                        $("#test").append("
");
                        var Person = Am.Model.create("Person", ["name"]);
                        var person = new Person("Alan");
                        var element1 = Am.View.Element.create("#test1");
                        var element2 = Am.View.Element.create("#test2, #test3");

                        element1.addDataBinding(person, "name");
                        element2.addDataBinding(person, "name");

                        element1.removeDataBinding(person, "name");
                        element2.removeDataBinding(person, "name");

                        person.set("name", "John");
                        element1.refresh(person);
                        element2.refresh(person);

                        expect($("#test1").html()).to.equal("Alan");
                        expect($("#test2").html()).to.equal("Alan");
                        expect($("#test3").html()).to.equal("Alan");

                        done();
                    });

                    it("should remove the Element's HTMLElement(s)'s value bindings to the instance by default " +
                        "for input HTML elements", function(done) {
                        $("#test").append("<input id=\"test1\" type=\"text\">");
                        $("#test").append("<input id=\"test2\" type=\"text\">");
                        $("#test").append("<input id=\"test3\" type=\"text\">");
                        var Person = Am.Model.create("Person", ["name"]);
                        var person = new Person("Alan");
                        var element1 = Am.View.Element.create("#test1");
                        var element2 = Am.View.Element.create("#test2, #test3");

                        element1.addDataBinding(person, "name");
                        element2.addDataBinding(person, "name");

                        element1.removeDataBinding(person, "name");
                        element2.removeDataBinding(person, "name");

                        person.set("name", "John");
                        element1.refresh(person);
                        element2.refresh(person);

                        expect($("#test1").val()).to.equal("Alan");
                        expect($("#test2").val()).to.equal("Alan");
                        expect($("#test3").val()).to.equal("Alan");

                        done();
                    });

                    it("should remove all of the Element's HTMLElement(s)'s matching data bindings", function(done) {
                        $("#test").append("<input id=\"test1\" type=\"text\">");
                        $("#test").append("<input id=\"test2\" type=\"text\">");
                        $("#test").append("<input id=\"test3\" type=\"text\">");
                        $("#test").append("<input id=\"test4\" type=\"text\">");
                        $("#test").append("<input id=\"test5\" type=\"text\">");
                        $("#test").append("<input id=\"test6\" type=\"text\">");
                        $("#test").append("<input id=\"test7\" type=\"text\">");
                        $("#test").append("<input id=\"test8\" type=\"text\">");
                        var Person = Am.Model.create("Person", ["name"]);
                        var person = new Person("Alan");
                        var forwardTransform = function(value) { return value; };
                        var backwardTransform = function(value) { return value; };

                        var element1 = Am.View.Element.create("#test1");
                        element1.addDataBinding(person, "name", { elementProperties: "data-name" });
                        element1.removeDataBinding(person, "name", { elementProperties: "data-name" });
                        person.set("name", "John");
                        element1.refresh(person);

                        expect($("#test1").data("name")).to.equal("Alan");

                        var element2 = Am.View.Element.create("#test2");
                        person.set("name", "Alan");
                        element2.addDataBinding(person, "name", { elementProperties: "value" });
                        element2.removeDataBinding(person, "name", { elementProperties: "data-name" });
                        person.set("name", "John");
                        element2.refresh(person);

                        expect($("#test2").val()).to.equal("John");

                        var element3 = Am.View.Element.create("#test3");
                        person.set("name", "Alan");
                        element3.addDataBinding(person, "name", { direction: Am.View.Element.ONE_WAY_BINDING });
                        element3.removeDataBinding(person, "name", { direction: Am.View.Element.ONE_WAY_BINDING });
                        person.set("name", "John");
                        element3.refresh(person);

                        expect($("#test3").val()).to.equal("Alan");

                        var element4 = Am.View.Element.create("#test4");
                        person.set("name", "Alan");
                        element4.addDataBinding(person, "name");
                        element4.removeDataBinding(person, "name", { direction: Am.View.Element.ONE_WAY_BINDING });
                        person.set("name", "John");
                        element4.refresh(person);

                        expect($("#test4").val()).to.equal("John");

                        var element5 = Am.View.Element.create("#test5");
                        person.set("name", "Alan");
                        element5.addDataBinding(person, "name", { forwardTransform: forwardTransform });
                        element5.removeDataBinding(person, "name", { forwardTransform: forwardTransform });
                        person.set("name", "John");
                        element5.refresh(person);

                        expect($("#test5").val()).to.equal("Alan");

                        var element6 = Am.View.Element.create("#test6");
                        person.set("name", "Alan");
                        element6.addDataBinding(person, "name");
                        element6.removeDataBinding(person, "name", { forwardTransform: forwardTransform });
                        person.set("name", "John");
                        element6.refresh(person);

                        expect($("#test6").val()).to.equal("John");

                        var element7 = Am.View.Element.create("#test7");
                        person.set("name", "Alan");
                        element7.addDataBinding(person, "name", { backwardTransform: backwardTransform });
                        element7.removeDataBinding(person, "name", { backwardTransform: backwardTransform });
                        person.set("name", "John");
                        element7.refresh(person);

                        expect($("#test7").val()).to.equal("Alan");

                        var element8 = Am.View.Element.create("#test8");
                        person.set("name", "Alan");
                        element8.addDataBinding(person, "name");
                        element8.removeDataBinding(person, "name", { backwardTransform: backwardTransform });
                        person.set("name", "John");
                        element8.refresh(person);

                        expect($("#test8").val()).to.equal("John");

                        done();
                    });
                });

                describe("instance.hasDataBindings()", function() {
                    it("should return whether the Element has any data bindings", function(done) {
                        $("#test").append("
");
                        $("#test").append("
");
                        var Person = Am.Model.create("Person", ["name"]);
                        var person1 = new Person("Alan");
                        var element1 = Am.View.Element.create("#test1");
                        var element2 = Am.View.Element.create("#test2");

                        element1.addDataBinding(person1, "name");

                        expect(element1.hasDataBindings()).to.be.true;
                        expect(element2.hasDataBindings()).to.be.false;

                        done();
                    });
                });

                describe("instance.isDataBound()", function() {
                    it("should return whether the Element is data bound to the specified instance", function(done) {
                        $("#test").append("
");
                        $("#test").append("
");
                        var Person = Am.Model.create("Person", ["name"]);
                        var person1 = new Person("Alan");
                        var person2 = new Person("John");
                        var element1 = Am.View.Element.create("#test1");
                        var element2 = Am.View.Element.create("#test2");

                        element1.addDataBinding(person1, "name");

                        expect(element1.isDataBoundTo(person1)).to.be.true;
                        expect(element2.isDataBoundTo(person1)).to.be.false;
                        expect(element1.isDataBoundTo(person2)).to.be.false;
                        expect(element2.isDataBoundTo(person2)).to.be.false;

                        done();
                    });
                });
            });
        });
    });
});


text:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Opening a Transactional Environment and
            Database

        </title>
    <link rel="stylesheet" href="gettingStarted.css" type="text/css" />
    <meta name="generator" content="DocBook XSL Stylesheets V1.62.4" />
    <link rel="home" href="index.html" title="Getting Started with Berkeley DB Transaction Processing" />
    <link rel="up" href="enabletxn.html" title="Chapter 2. Enabling Transactions" />
    <link rel="previous" href="enabletxn.html" title="Chapter 2. Enabling Transactions" />
    <link rel="next" href="usingtxns.html" title="Chapter 3. Transaction Basics" />

          Opening a Transactional Environment and
            Database

          Prev
          Chapter 2. Enabling Transactions
           Next

Opening a Transactional Environment and
            Database

            To enable transactions for your environment, you must initialize the
            transactional subsystem. Note that doing this also initializes the
            logging subsystem. In addition, you must initialize the memory pool
            (in-memory cache). Frequently, but not always, you will also
            initialize the locking subsystem.

                For example:

        Notice in the following example that you create your environment
        handle using the <tt class="function">db_env_create()</tt> function before you open
        the environment:

#include <stdio.h>
#include <stdlib.h>

#include "db.h"

int
main(void)
{
    int ret, ret_c;
    u_int32_t env_flags;
    DB_ENV *envp;
    const char *db_home_dir = "/tmp/myEnvironment";

    envp = NULL;

    /* Open the environment */
    ret = db_env_create(&envp, 0);
    if (ret != 0) {
        fprintf(stderr, "Error creating environment handle: %s\n",
            db_strerror(ret));
        return (EXIT_FAILURE);
    }

    env_flags = DB_CREATE |    /* Create the environment if it does
                                * not already exist. */
                DB_INIT_TXN  | /* Initialize transactions */
                DB_INIT_LOCK | /* Initialize locking. */
                DB_INIT_LOG  | /* Initialize logging */
                DB_INIT_MPOOL; /* Initialize the in-memory cache. */

    ret = envp->open(envp, db_home_dir, env_flags, 0);
    if (ret != 0) {
        fprintf(stderr, "Error opening environment: %s\n",
            db_strerror(ret));
        goto err;
    }

err:
    /* Close the environment */
    if (envp != NULL) {
        ret_c = envp->close(envp, 0);
        if (ret_c != 0) {
            fprintf(stderr, "environment close failed: %s\n",
                db_strerror(ret_c));
            ret = ret_c;
        }
    }

    return (ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
}

        You then create and open your database(s) as you would for a non-transactional system.

            The only difference is that you must pass the environment handle to
            the

                    <tt class="function">db_create()</tt> function,

             and you must open the database within a transaction.
             Typically auto commit is used for this purpose. To do so, pass
            <tt class="literal">DB_AUTO_COMMIT</tt> to the database open command.
            Also, make sure you close all your databases before you close
            your environment.
            For example:

#include <stdio.h>
#include <stdlib.h>

#include "db.h"

int
main(void)
{
    int ret, ret_c;
    u_int32_t <tt>db_flags,</tt> env_flags;
    <tt>DB *dbp;</tt>
    DB_ENV *envp;
    const char *db_home_dir = "/tmp/myEnvironment";
    <tt>const char *file_name = "mydb.db";

    dbp = NULL;</tt>
    envp = NULL;

    /* Open the environment */
    ret = db_env_create(&envp, 0);
    if (ret != 0) {
        fprintf(stderr, "Error creating environment handle: %s\n",
            db_strerror(ret));
        return (EXIT_FAILURE);
    }

    env_flags = DB_CREATE |    /* Create the environment if it does
                                * not already exist. */
                DB_INIT_TXN  | /* Initialize transactions */
                DB_INIT_LOCK | /* Initialize locking. */
                DB_INIT_LOG  | /* Initialize logging */
                DB_INIT_MPOOL; /* Initialize the in-memory cache. */

    ret = envp->open(envp, db_home_dir, env_flags, 0);
    if (ret != 0) {
        fprintf(stderr, "Error opening environment: %s\n",
            db_strerror(ret));
        goto err;
    }

    <tt>/* Initialize the DB handle */
    ret = db_create(&dbp, envp, 0);
    if (ret != 0) {
        envp->err(envp, ret, "Database creation failed");
        goto err;
    }

    db_flags = DB_CREATE | DB_AUTO_COMMIT;
    ret = dbp->open(dbp,        /* Pointer to the database */
                    NULL,       /* Txn pointer */
                    file_name,  /* File name */
                    NULL,       /* Logical db name */
                    DB_BTREE,   /* Database type (using btree) */
                    db_flags,   /* Open flags */
                    0);         /* File mode. Using defaults */
    if (ret != 0) {
        envp->err(envp, ret, "Database '%s' open failed",
            file_name);
        goto err;
    }</tt>

err:
    <tt>/* Close the database */
    if (dbp != NULL) {
        ret_c = dbp->close(dbp, 0);
        if (ret_c != 0) {
            envp->err(envp, ret_c, "Database close failed.");
            ret = ret_c
        }
    }</tt>

    /* Close the environment */
    if (envp != NULL) {
        ret_c = envp->close(envp, 0);
        if (ret_c != 0) {
            fprintf(stderr, "environment close failed: %s\n",
                db_strerror(ret_c));
            ret = ret_c;
        }
    }

    return (ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
}

Note

                Never close a database  that has active transactions. Make sure
            all transactions are resolved (either committed or aborted)
            before closing the database.

          Prev

            Up

           Next

          Chapter 2. Enabling Transactions

            Home

           Chapter 3. Transaction Basics

redpajama_set_name: RedPajamaGithub


text:
layout: page
title: 分类
---

{% for category in site.categories %}
### {{ category | first }}
{% for post in category[1] %}
- {{ post.title }}
{% endfor %}
{% endfor %}


text:
package userstore

import (
	"database/sql"
	"time"

	"github.com/google/uuid"
)

type Org struct {
	// Organization ID - Unique ID for table
	OrgID uuid.UUID
	// Organization Unique External ID to be given to outside callers.
	OrgExtlID string
	// Organization Name - a short name for the organization
	OrgName string
	// Organization Description - several sentences to describe the organization
	OrgDescription string
	// Foreign Key to org_kind table.
	OrgKindID uuid.UUID
	// The application which created this record.
	CreateAppID uuid.UUID
	// The user which created this record.
	CreateUserID uuid.NullUUID
	// The timestamp when this record was created.
	CreateTimestamp time.Time
	// The application which performed the most recent update to this record.
	UpdateAppID uuid.UUID
	// The user which performed the most recent update to this record.
	UpdateUserID uuid.NullUUID
	// The timestamp when the record was updated most recently.
	UpdateTimestamp time.Time
}

type OrgUser struct {
	// The user ID is the unique ID for user (pk for table)
	UserID uuid.UUID
	// The unique user external ID to be given to outside callers.
	UserExtlID string
	// The username is a unique, human readable username.
	Username string
	// The organization ID for the organization that the user belongs to.
	OrgID uuid.UUID
	// The person profile ID - ID for the profile of the person to which this user belongs.
	PersonProfileID uuid.UUID
	// The application which created this record.
	CreateAppID uuid.UUID
	// The user which created this record.
	CreateUserID uuid.NullUUID
	// The timestamp when this record was created.
	CreateTimestamp time.Time
	// The application which performed the most recent update to this record.
	UpdateAppID uuid.UUID
	// The user which performed the most recent update to this record.
	UpdateUserID uuid.NullUUID
	// The timestamp when the record was updated most recently.
	UpdateTimestamp time.Time
}

type Person struct {
	PersonID        uuid.UUID
	OrgID           uuid.UUID
	CreateAppID     uuid.UUID
	CreateUserID    uuid.NullUUID
	CreateTimestamp time.Time
	UpdateAppID     uuid.UUID
	UpdateUserID    uuid.NullUUID
	UpdateTimestamp time.Time
}

type PersonProfile struct {
	PersonProfileID uuid.UUID
	PersonID        uuid.UUID
	NamePrefix      sql.NullString
	FirstName       string
	MiddleName      sql.NullString
	LastName        string
	NameSuffix      sql.NullString
	Nickname        sql.NullString
	CompanyName     sql.NullString
	CompanyDept     sql.NullString
	JobTitle        sql.NullString
	BirthDate       sql.NullTime
	BirthYear       sql.NullInt64
	BirthMonth      sql.NullInt64
	BirthDay        sql.NullInt64
	LanguageID      uuid.NullUUID
	CreateAppID     uuid.UUID
	CreateUserID    uuid.NullUUID
	CreateTimestamp time.Time
	UpdateAppID     uuid.UUID
	UpdateUserID    uuid.NullUUID
	UpdateTimestamp time.Time
}


text:
package org.wso2.developerstudio.eclipse.greg.base.util;

public class BaseConstants {

	public static final String READ = "Read";
	public static final String WRITE = "Write";
	public static final String DELETE = "Delete";
	public static final String AUTHORIZE = "Authorize";

	public static final String ADMIN = "admin";
}


text:
'use strict';

angular.module('SatanApp.sventove', [])

.controller('SventoveController', [function() {

}]);


text:
body {
	background: #eee;
}
.navbar {
	border-radius: 0;
}
.nav-tabs {
	margin-bottom: 15px;
}

.list-group {
    margin-bottom: 0px;
}

.panel-body.alerts {
    padding: 0;
}

.panel-body.alerts .list-group-item {
    border-right: 0px;
    border-left: 0px;
}

.list-group-item {
	width: 100%;
}

.panel-body.alerts .list-group-item .col-md-8,
.list-group.main .list-group-item .col-md-8 {
    padding-left: 0px;
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
}

.panel-body.alerts .list-group-item:first-child {
    border-top: 0px;
}

.panel-body.alerts .list-group-item:last-child {
    border-bottom: 0px;
}

.red {
    color: red;
}

.green {
    color: green;
}

.yellow {
    color: orange;
}

body {
	padding-top: 70px;
	background-color: #e5e5e5;
}
.list-group {
	border-radius: 0;
	/*border: 1px solid #d8d8d8;*/
	/*border-bottom-width: 2px;*/
	border-top-width: 0px;

	background-image: -webkit-linear-gradient(#e5e5e5 49px,#eaeaea 49px);
	background-image: linear-gradient(#e5e5e5 49px,#eaeaea 49px);
	-webkit-background-size: 100% 98px;
	background-size: 100% 98px;
	-webkit-box-shadow: 0 0 2px rgba(0,0,0,.12),0 2px 4px rgba(0,0,0,.24);
	box-shadow: 0 0 2px rgba(0,0,0,.12),0 2px 4px rgba(0,0,0,.24);
	margin-bottom: 20px;
}

.list-group-item.read {
    border-left: 4px solid #5bc0de;
    padding-left: 24px !important;
}

.list-group-item {
	border-radius: 0 !important;
	border-bottom: 1px solid #ececec;
	border: none;
	margin-bottom: 1px;
	opacity: 1;
	color: #262626 !important;
	padding: 9px 18px;
}

.list-group.main .list-group-item {
	padding: 15px 28px;
	vertical-align: middle;
}

input[type=radio].css-checkbox {
	position:absolute;
	z-index:-1000;
	left:-1000px;
	overflow: hidden;
	clip: rect(0 0 0 0);
	height:1px;
	width:1px;
	margin:-1px;
	padding:0;
	border:0;
}

input[type=radio].css-checkbox + label.css-label {
	padding-left:30px;
	height:25px;
	display:inline-block;
	line-height:25px;
	background-repeat:no-repeat;
	background-position: 0 0;
	font-size: 16px;
	vertical-align:middle;
	cursor:pointer;
    margin-top: 4px;
}

input[type=radio].css-checkbox:checked + label.css-label {
	background-position: 0 -25px;
}

label.css-label {
	background-image:url(../img/checkbox_sprite.png);
	-webkit-touch-callout: none;
	-webkit-user-select: none;
	-khtml-user-select: none;
	-moz-user-select: none;
	-ms-user-select: none;
	user-select: none;
}

.page-header {
    margin: 0;
    padding: 0;
    background: #222;
}

.page-title {
    padding: 18px 30px;
    margin: 0;
    color: #ffffff;
}

.page-body {
    background: #fff;
    margin: 0;
    padding: 10px;
}
.page-actions {
    padding: 23px 28px 23px 20px;
}
.import-map {
    border-spacing: 10px 0;
    border-collapse: separate;
}
.import-map th {
    min-width: 250px;
}

.import-map th.map-activecol {
    background: #52bad5;
}
.import-map th.map-deleted {
    background: #ee836e;
}
.import-map td.map-activecol {
    background-color: #b1e0ec;
}

.import-map td.map-deleted {
    background-color: #fbe3e4;
}

.import-map .map-activecol {
    border-color: #52bad5;
    border-top: 1px dotted #52bad5;
    color: #484848;
}

.import-map .map-deleted {
    border-color: #ee836e;
    border-top: 1px dotted #ee836e;
    color: #484848;
}

.import-map tbody tr:last-child .map-activecol {
    border-bottom-color: #52bad5;
}

.import-map tbody tr:last-child .map-deleted {
    border-bottom-color: #ee836e;
}

.import-map tbody tr:last-child td {
    border-bottom: 2px solid #e0e0e0;
}
.import-map td, .import-map th {
    border-left: 2px solid #e0e0e0;
    border-right: 2px solid #e0e0e0;
    font-size: 13px;
}

.table-responsive {
    width: 100%;
}

.alert-setting {
    overflow: hidden;
    // white-space: nowrap;
    text-overflow: ellipsis;
}

.alert-setting:hover {
    background: #ffffff;
}

.complete {
  display: none;
  text-align: center;
}

.api-keys {
    table-layout: fixed;
    min-width: 800px;
}
.table-responsive > .api-keys > tbody > tr > td {
    white-space: normal;
}

.table.api-keys > thead > tr > th, .api-keys > tbody > tr > td {
    padding: 18px 15px;
}
@media (min-width: 992px) {
	.list-group.nav {
		width: 213px;
	}
}

@media (min-width: 1200px) {
	.list-group.nav {
		width: 263px;
	}
}

.navbar {
    border-bottom: 5px solid #5bc0de;
}

/*Dropzone*/
/*
 * The MIT License
 * Copyright (c) 2012 Matias Meno <m@tias.me>
 */
@-webkit-keyframes passing-through {
  0% {
    opacity: 0;
    -webkit-transform: translateY(40px);
    -moz-transform: translateY(40px);
    -ms-transform: translateY(40px);
    -o-transform: translateY(40px);
    transform: translateY(40px); }
  30%, 70% {
    opacity: 1;
    -webkit-transform: translateY(0px);
    -moz-transform: translateY(0px);
    -ms-transform: translateY(0px);
    -o-transform: translateY(0px);
    transform: translateY(0px); }
  100% {
    opacity: 0;
    -webkit-transform: translateY(-40px);
    -moz-transform: translateY(-40px);
    -ms-transform: translateY(-40px);
    -o-transform: translateY(-40px);
    transform: translateY(-40px); } }
@-moz-keyframes passing-through {
  0% {
    opacity: 0;
    -webkit-transform: translateY(40px);
    -moz-transform: translateY(40px);
    -ms-transform: translateY(40px);
    -o-transform: translateY(40px);
    transform: translateY(40px); }
  30%, 70% {
    opacity: 1;
    -webkit-transform: translateY(0px);
    -moz-transform: translateY(0px);
    -ms-transform: translateY(0px);
    -o-transform: translateY(0px);
    transform: translateY(0px); }
  100% {
    opacity: 0;
    -webkit-transform: translateY(-40px);
    -moz-transform: translateY(-40px);
    -ms-transform: translateY(-40px);
    -o-transform: translateY(-40px);
    transform: translateY(-40px); } }
@keyframes passing-through {
  0% {
    opacity: 0;
    -webkit-transform: translateY(40px);
    -moz-transform: translateY(40px);
    -ms-transform: translateY(40px);
    -o-transform: translateY(40px);
    transform: translateY(40px); }
  30%, 70% {
    opacity: 1;
    -webkit-transform: translateY(0px);
    -moz-transform: translateY(0px);
    -ms-transform: translateY(0px);
    -o-transform: translateY(0px);
    transform: translateY(0px); }
  100% {
    opacity: 0;
    -webkit-transform: translateY(-40px);
    -moz-transform: translateY(-40px);
    -ms-transform: translateY(-40px);
    -o-transform: translateY(-40px);
    transform: translateY(-40px); } }
@-webkit-keyframes slide-in {
  0% {
    opacity: 0;
    -webkit-transform: translateY(40px);
    -moz-transform: translateY(40px);
    -ms-transform: translateY(40px);
    -o-transform: translateY(40px);
    transform: translateY(40px); }
  30% {
    opacity: 1;
    -webkit-transform: translateY(0px);
    -moz-transform: translateY(0px);
    -ms-transform: translateY(0px);
    -o-transform: translateY(0px);
    transform: translateY(0px); } }
@-moz-keyframes slide-in {
  0% {
    opacity: 0;
    -webkit-transform: translateY(40px);
    -moz-transform: translateY(40px);
    -ms-transform: translateY(40px);
    -o-transform: translateY(40px);
    transform: translateY(40px); }
  30% {
    opacity: 1;
    -webkit-transform: translateY(0px);
    -moz-transform: translateY(0px);
    -ms-transform: translateY(0px);
    -o-transform: translateY(0px);
    transform: translateY(0px); } }
@keyframes slide-in {
  0% {
    opacity: 0;
    -webkit-transform: translateY(40px);
    -moz-transform: translateY(40px);
    -ms-transform: translateY(40px);
    -o-transform: translateY(40px);
    transform: translateY(40px); }
  30% {
    opacity: 1;
    -webkit-transform: translateY(0px);
    -moz-transform: translateY(0px);
    -ms-transform: translateY(0px);
    -o-transform: translateY(0px);
    transform: translateY(0px); } }
@-webkit-keyframes pulse {
  0% {
    -webkit-transform: scale(1);
    -moz-transform: scale(1);
    -ms-transform: scale(1);
    -o-transform: scale(1);
    transform: scale(1); }
  10% {
    -webkit-transform: scale(1.1);
    -moz-transform: scale(1.1);
    -ms-transform: scale(1.1);
    -o-transform: scale(1.1);
    transform: scale(1.1); }
  20% {
    -webkit-transform: scale(1);
    -moz-transform: scale(1);
    -ms-transform: scale(1);
    -o-transform: scale(1);
    transform: scale(1); } }
@-moz-keyframes pulse {
  0% {
    -webkit-transform: scale(1);
    -moz-transform: scale(1);
    -ms-transform: scale(1);
    -o-transform: scale(1);
    transform: scale(1); }
  10% {
    -webkit-transform: scale(1.1);
    -moz-transform: scale(1.1);
    -ms-transform: scale(1.1);
    -o-transform: scale(1.1);
    transform: scale(1.1); }
  20% {
    -webkit-transform: scale(1);
    -moz-transform: scale(1);
    -ms-transform: scale(1);
    -o-transform: scale(1);
    transform: scale(1); } }
@keyframes pulse {
  0% {
    -webkit-transform: scale(1);
    -moz-transform: scale(1);
    -ms-transform: scale(1);
    -o-transform: scale(1);
    transform: scale(1); }
  10% {
    -webkit-transform: scale(1.1);
    -moz-transform: scale(1.1);
    -ms-transform: scale(1.1);
    -o-transform: scale(1.1);
    transform: scale(1.1); }
  20% {
    -webkit-transform: scale(1);
    -moz-transform: scale(1);
    -ms-transform: scale(1);
    -o-transform: scale(1);
    transform: scale(1); } }
.dropzone, .dropzone * {
  box-sizing: border-box; }

.dropzone {
  min-height: 150px;
  border: 2px dashed #5bc0de;
  background: white;
  padding: 20px 20px; }
  .dropzone.dz-clickable {
    cursor: pointer; }
    .dropzone.dz-clickable * {
      cursor: default; }
    .dropzone.dz-clickable .dz-message, .dropzone.dz-clickable .dz-message * {
      cursor: pointer; }
  .dropzone.dz-started .dz-message {
    display: none; }
  .dropzone.dz-drag-hover {
    border-style: solid; }
    .dropzone.dz-drag-hover .dz-message {
      opacity: 0.5; }
  .dropzone .dz-message {
    text-align: center;
    margin: 2em 0; }
  .dropzone .dz-preview {
    position: relative;
    display: inline-block;
    vertical-align: top;
    margin: 16px;
    min-height: 100px; }
    .dropzone .dz-preview:hover {
      z-index: 1000; }
      .dropzone .dz-preview:hover .dz-details {
        opacity: 1; }
    .dropzone .dz-preview.dz-file-preview .dz-image {
      border-radius: 20px;
      background: #999;
      background: linear-gradient(to bottom, #eee, #ddd); }
    .dropzone .dz-preview.dz-file-preview .dz-details {
      opacity: 1; }
    .dropzone .dz-preview.dz-image-preview {
      background: white; }
      .dropzone .dz-preview.dz-image-preview .dz-details {
        -webkit-transition: opacity 0.2s linear;
        -moz-transition: opacity 0.2s linear;
        -ms-transition: opacity 0.2s linear;
        -o-transition: opacity 0.2s linear;
        transition: opacity 0.2s linear; }
    .dropzone .dz-preview .dz-remove {
      font-size: 14px;
      text-align: center;
      display: block;
      cursor: pointer;
      border: none; }
      .dropzone .dz-preview .dz-remove:hover {
        text-decoration: underline; }
    .dropzone .dz-preview:hover .dz-details {
      opacity: 1; }
    .dropzone .dz-preview .dz-details {
      z-index: 20;
      position: absolute;
      top: 0;
      left: 0;
      opacity: 0;
      font-size: 13px;
      min-width: 100%;
      max-width: 100%;
      padding: 2em 1em;
      text-align: center;
      color: rgba(0, 0, 0, 0.9);
      line-height: 150%; }
      .dropzone .dz-preview .dz-details .dz-size {
        margin-bottom: 1em;
        font-size: 16px; }
      .dropzone .dz-preview .dz-details .dz-filename {
        white-space: nowrap; }
        .dropzone .dz-preview .dz-details .dz-filename:hover span {
          border: 1px solid rgba(200, 200, 200, 0.8);
          background-color: rgba(255, 255, 255, 0.8); }
        .dropzone .dz-preview .dz-details .dz-filename:not(:hover) {
          overflow: hidden;
          text-overflow: ellipsis; }
          .dropzone .dz-preview .dz-details .dz-filename:not(:hover) span {
            border: 1px solid transparent; }
      .dropzone .dz-preview .dz-details .dz-filename span, .dropzone .dz-preview .dz-details .dz-size span {
        background-color: rgba(255, 255, 255, 0.4);
        padding: 0 0.4em;
        border-radius: 3px; }
    .dropzone .dz-preview:hover .dz-image img {
      -webkit-transform: scale(1.05, 1.05);
      -moz-transform: scale(1.05, 1.05);
      -ms-transform: scale(1.05, 1.05);
      -o-transform: scale(1.05, 1.05);
      transform: scale(1.05, 1.05);
      -webkit-filter: blur(8px);
      filter: blur(8px); }
    .dropzone .dz-preview .dz-image {
      border-radius: 20px;
      overflow: hidden;
      width: 120px;
      height: 120px;
      position: relative;
      display: block;
      z-index: 10; }
      .dropzone .dz-preview .dz-image img {
        display: block; }
    .dropzone .dz-preview.dz-success .dz-success-mark {
      -webkit-animation: passing-through 3s cubic-bezier(0.77, 0, 0.175, 1);
      -moz-animation: passing-through 3s cubic-bezier(0.77, 0, 0.175, 1);
      -ms-animation: passing-through 3s cubic-bezier(0.77, 0, 0.175, 1);
      -o-animation: passing-through 3s cubic-bezier(0.77, 0, 0.175, 1);
      animation: passing-through 3s cubic-bezier(0.77, 0, 0.175, 1); }
    .dropzone .dz-preview.dz-error .dz-error-mark {
      opacity: 1;
      -webkit-animation: slide-in 3s cubic-bezier(0.77, 0, 0.175, 1);
      -moz-animation: slide-in 3s cubic-bezier(0.77, 0, 0.175, 1);
      -ms-animation: slide-in 3s cubic-bezier(0.77, 0, 0.175, 1);
      -o-animation: slide-in 3s cubic-bezier(0.77, 0, 0.175, 1);
      animation: slide-in 3s cubic-bezier(0.77, 0, 0.175, 1); }
    .dropzone .dz-preview .dz-success-mark, .dropzone .dz-preview .dz-error-mark {
      pointer-events: none;
      opacity: 0;
      z-index: 500;
      position: absolute;
      display: block;
      top: 50%;
      left: 50%;
      margin-left: -27px;
      margin-top: -27px; }
      .dropzone .dz-preview .dz-success-mark svg, .dropzone .dz-preview .dz-error-mark svg {
        display: block;
        width: 54px;
        height: 54px; }
    .dropzone .dz-preview.dz-processing .dz-progress {
      opacity: 1;
      -webkit-transition: all 0.2s linear;
      -moz-transition: all 0.2s linear;
      -ms-transition: all 0.2s linear;
      -o-transition: all 0.2s linear;
      transition: all 0.2s linear; }
    .dropzone .dz-preview.dz-complete .dz-progress {
      opacity: 0;
      -webkit-transition: opacity 0.4s ease-in;
      -moz-transition: opacity 0.4s ease-in;
      -ms-transition: opacity 0.4s ease-in;
      -o-transition: opacity 0.4s ease-in;
      transition: opacity 0.4s ease-in; }
    .dropzone .dz-preview:not(.dz-processing) .dz-progress {
      -webkit-animation: pulse 6s ease infinite;
      -moz-animation: pulse 6s ease infinite;
      -ms-animation: pulse 6s ease infinite;
      -o-animation: pulse 6s ease infinite;
      animation: pulse 6s ease infinite; }
    .dropzone .dz-preview .dz-progress {
      opacity: 1;
      z-index: 1000;
      pointer-events: none;
      position: absolute;
      height: 16px;
      left: 50%;
      top: 50%;
      margin-top: -8px;
      width: 80px;
      margin-left: -40px;
      background: rgba(255, 255, 255, 0.9);
      -webkit-transform: scale(1);
      border-radius: 8px;
      overflow: hidden; }
      .dropzone .dz-preview .dz-progress .dz-upload {
        background: #333;
        background: linear-gradient(to bottom, #666, #444);
        position: absolute;
        top: 0;
        left: 0;
        bottom: 0;
        width: 0;
        -webkit-transition: width 300ms ease-in-out;
        -moz-transition: width 300ms ease-in-out;
        -ms-transition: width 300ms ease-in-out;
        -o-transition: width 300ms ease-in-out;
        transition: width 300ms ease-in-out; }
    .dropzone .dz-preview.dz-error .dz-error-message {
      display: block; }
    .dropzone .dz-preview.dz-error:hover .dz-error-message {
      opacity: 1;
      pointer-events: auto; }
    .dropzone .dz-preview .dz-error-message {
      pointer-events: none;
      z-index: 1000;
      position: absolute;
      display: block;
      display: none;
      opacity: 0;
      -webkit-transition: opacity 0.3s ease;
      -moz-transition: opacity 0.3s ease;
      -ms-transition: opacity 0.3s ease;
      -o-transition: opacity 0.3s ease;
      transition: opacity 0.3s ease;
      border-radius: 8px;
      font-size: 13px;
      top: 130px;
      left: -10px;
      width: 140px;
      background: #be2626;
      background: linear-gradient(to bottom, #be2626, #a92222);
      padding: 0.5em 1.2em;
      color: white; }
      .dropzone .dz-preview .dz-error-message:after {
        content: '';
        position: absolute;
        top: -6px;
        left: 64px;
        width: 0;
        height: 0;
        border-left: 6px solid transparent;
        border-right: 6px solid transparent;
        border-bottom: 6px solid #be2626; }


text:
import java.util.concurrent.TimeUnit;

/**
 * Created by alexxst.st on 30.03.2017.
 * Class for timered
 */
public class Stopwatch {
    private long startTime;
    private long endTime;
    private long accum;

    public void start() {
        startTime = System.nanoTime();
    }

    public void stop() {
        endTime = System.nanoTime();
        accum += endTime - startTime;
    }

    public long getElapsed() {
        return TimeUnit.MILLISECONDS.convert(accum, TimeUnit.NANOSECONDS);
    }

    public void reset() {
        startTime = endTime = accum = 0;
    }
}


text:
public class SinglyLinkedList {

    Node head;

    private boolean isEqual(Node node, int content) {
        return node.container == content;
    }

    private Node findNode(int number) {
        Node currentNode = head;

        while (!isEqual(currentNode, number) && currentNode.next != null) {
            currentNode = currentNode.next;
        }

        if (isEqual(currentNode, number)) {
            return currentNode;
        } else {
            return null;
        }
    }

    public void append(int number) {
        Node toInsert = new Node(number);
        toInsert.next = head;
        head = toInsert;

        /*
         * schlecht: Node currentNode = head;
         *
         * while (currentNode.next != null) { currentNode = currentNode.next; }
         * currentNode.next = n;
         */
    }

    public void remove(int number) {
        Node previous = head;
        Node currentNode = head;

        while (!isEqual(currentNode, number) && currentNode.next != null) {
            previous = currentNode;
            currentNode = currentNode.next;
        }

        if (currentNode.next != null) {
            previous.next = currentNode.next;
        }
    }

    public int find(int number) {
        Node node = findNode(number);

        if (node == null) {
            return 0;
        } else {
            return node.container;
        }
    }

    public void printList() {
        Node currentNode = head;
        System.out.print("head -> ");
        while (currentNode != null) {
            System.out.print(currentNode.container + " -> ");
            currentNode = currentNode.next;
        }
        System.out.println("null");
    }
}