Package com.sleepycat.db

Examples of com.sleepycat.db.Db


      appl = appl.substring(1);

    File helpTextFile = File.createTempFile("helptext", ".ht");
    helpTextFile.deleteOnExit();
    String helpTextFileName = helpTextFile.getAbsolutePath();
    Db helpText = new Db(null, 0);
    helpText.open(null,helpTextFileName, null, Db.DB_BTREE, Db.DB_TRUNCATE, 0644);

    File dbBaseFile = File.createTempFile("database", "db");
    dbBaseFile.deleteOnExit();
    String dbBaseFileName = dbBaseFile.getAbsolutePath();
    Db dbBase = new Db(null, 0);
    dbBase.open(null,dbBaseFileName, null, Db.DB_BTREE, Db.DB_TRUNCATE, 0644);

    File keyWordFile = File.createTempFile("keybase", "key");
    keyWordFile.deleteOnExit();
    String keyWordFileName = keyWordFile.getAbsolutePath();
    Db keyWord = new Db(null, 0);
    keyWord.open(null,keyWordFileName, null, Db.DB_BTREE, Db.DB_TRUNCATE, 0644);
    HelpKeyword helpKeyword = new HelpKeyword();

    // now input the hid.lst and store it into a hashmap
    FileReader fileReader = new FileReader(hid);
    StringBuffer strBuf = new StringBuffer();
    int n = 0;
    char[] c = new char[1024];
    while ((n = fileReader.read(c, 0, 1024)) != -1)
      strBuf.append(c, 0, n);
    String str = strBuf.toString();
    StringTokenizer strTokenizer = new StringTokenizer(str);
    while (strTokenizer.hasMoreTokens()) {
      String key = strTokenizer.nextToken();
      String data = strTokenizer.nextToken();
      hidlistTranslation.put(
        key.toUpperCase().replace(':', '_'),
        data.trim());
    }

    // lastly, initialize the indexBuilder
    if (!helpFiles.isEmpty())
      initXMLIndexBuilder();

    // here we start our loop over the hzip files.
    Iterator iter = helpFiles.iterator();
    while (iter.hasNext()) {
      // process one file
      // streamTable contains the streams in the hzip file
      //Hashtable streamTable = new Hashtable();
      Hashtable streamTable1 = new Hashtable();

      String xhpFileName = (String) iter.next();
      if (!xhpFileName.endsWith(".xhp")) {
        // only work on .xhp - files
        System.err.println(
          "ERROR: input list entry '"
            + xhpFileName
            + "' has the wrong extension (only files with extension .xhp "
            + "are accepted)");
        continue;
      }

      HelpCompiler hc =
        new HelpCompiler(
          streamTable1,
          xhpFileName,
          sourceRoot + File.separator + lang + File.separator,
          embeddStylesheet,
          module,
          lang);
      try {
        boolean success = hc.compile();
        if (!success) {
          System.err.println(
            "\nERROR: compiling help particle '"
              + xhpFileName
              + "' for language '"
              + lang
              + "' failed!");
          System.exit(1);
        }
      } catch (UnsupportedEncodingException e) {
        System.err.println(
          "\nERROR: unsupported Encoding Exception'"
            + "': "
            + e.getMessage());
        System.exit(1);
      }

      // Read the document core data
      byte[] byStr = (byte[]) streamTable1.get("document/id");
      String documentBaseId = null;
      if (byStr != null) {
        documentBaseId = new String(byStr, "UTF8");
      } else {
        System.err.println("corrupt compileroutput");
        System.exit(1);
      }

      String documentPath =
        new String(
          ((byte[]) streamTable1.get("document/path")),
          "UTF8");

      if (documentPath.startsWith("/"))
        documentPath = documentPath.substring(1);
      String documentJarfile =
        new String(
          ((byte[]) streamTable1.get("document/module")),
          "UTF8")
          + ".jar";

      byte[] byteStream = (byte[]) streamTable1.get("document/title");

      String documentTitle = null;
      if (byteStream != null)
        documentTitle = new String(byteStream, "UTF8");
      else
        documentTitle = "<notitle>";

      byte[] fileB = documentPath.getBytes("UTF8");
      byte[] jarfileB = documentJarfile.getBytes("UTF8");
      byte[] titleB = documentTitle.getBytes("UTF8");
      // add once this as its own id.
      addBookmark(dbBase, documentPath, fileB, null, jarfileB, titleB);

      if (init) {
        FileInputStream indexXSLFile =
          new FileInputStream(indexStylesheet);
        int read = 0;
        byte[] bytes = new byte[2048];
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        while ((read = indexXSLFile.read(bytes, 0, 2048)) != -1)
          baos.write(bytes, 0, read);
        createFileFromBytes("index.xsl", baos.toByteArray());

        xmlIndexBuilder.init("index");
        init = false;
      }

      // first the database *.db
      // ByteArrayInputStream bais = null;
      // ObjectInputStream ois = null;

      Object baos = streamTable1.get(appl + "/hidlist");
      if (baos == null)
        baos = streamTable1.get("default/hidlist");
      if (baos != null) {
        HashSet hidlist = (HashSet) baos;

        // now iterate over all elements of the hidlist
        Iterator hidListIter = hidlist.iterator();
        while (hidListIter.hasNext()) {
          String hid = (String) hidListIter.next();

          byte[] anchorB = null;
          int index = hid.lastIndexOf('#');
          if (index != -1) {
            anchorB = hid.substring(1 + index).getBytes("UTF8");
            hid = hid.substring(0, index);
          }
          addBookmark(dbBase, hid, fileB, anchorB, jarfileB, titleB);
        }
      }

      // now the keywords
      baos = streamTable1.get(appl + "/keywords");
      if (baos == null)
        baos = streamTable1.get("default/keywords");
      if (baos != null) {
        Hashtable anchorToLL = (Hashtable) baos;
        Enumeration enumer = anchorToLL.keys();
        String fakedHid = URLEncoder.encode(documentPath);
        while (enumer.hasMoreElements()) {
          String anchor = (String) enumer.nextElement();
          addBookmark(
            dbBase,
            documentPath,
            fileB,
            anchor.getBytes("UTF8"),
            jarfileB,
            titleB);
          String totalId = fakedHid + "#" + anchor;
          // System.err.println(hzipFileName);
          LinkedList ll = (LinkedList) anchorToLL.get(anchor);
          Iterator llIter = ll.iterator();
          while (llIter.hasNext())
            helpKeyword.insert((String) llIter.next(), totalId);
        }
      }

      // and last the helptexts
      baos = streamTable1.get(appl + "/helptexts");
      if (baos == null)
        baos = streamTable1.get("default/helptexts");
      if (baos != null) {
        Hashtable helpTextHash = (Hashtable) baos;
        Enumeration helpTextIter = helpTextHash.keys();
        while (helpTextIter.hasMoreElements()) {
          String helpTextId = (String) helpTextIter.nextElement();
          String helpTextText = (String) helpTextHash.get(helpTextId);

          String tHid =
            (String) hidlistTranslation.get(
              helpTextId.toUpperCase().replace(':', '_'));
          if (tHid != null)
            helpTextId = tHid;
          helpTextId = URLEncoder.encode(helpTextId);
          Dbt keyDbt = new Dbt(helpTextId.getBytes("UTF8"));
          Dbt textDbt = new Dbt(helpTextText.getBytes("UTF8"));
          helpText.put(null, keyDbt, textDbt, 0);
        }
      }
      // now the indexing
      // and last the helptexts
      baos = (byte[]) streamTable1.get(appl + "/text");
      if (baos == null)
        baos = (byte[]) streamTable1.get("default/text");

      if (baos != null) {
        byte[] bytes = (byte[]) baos;

        HelpURLStreamHandlerFactory.setMode(bytes);
        xmlIndexBuilder.indexDocument(
          new URL(
            "vnd.sun.star.help://"
              + module.toLowerCase()
              + "/"
              + URLEncoder.encode(documentPath)),
          "");
      }
    } // while loop over hzip files ending

    helpText.close(0);
    dbBase.close(0);
    helpKeyword.dump(keyWord);
    keyWord.close(0);
    if (!helpFiles.isEmpty())
      closeXMLIndexBuilder();

    // now copy the databases into memory, so we will be able to add it to the outputfile
    String mod = module.toLowerCase();
View Full Code Here


    }

    private Db openDb(String file)
        throws Exception {

        Db db = new Db(env, 0);
        db.open(null, file, null, Db.DB_BTREE, openFlags, 0);
        return db;
    }
View Full Code Here

        catalog = new StoredClassCatalog(env, "catalog.db", null, openFlags);
        factory = new TupleSerialDbFactory(catalog);
        assertSame(catalog, factory.getCatalog());

        int type = isSorted ? Db.DB_BTREE : Db.DB_HASH;
        Db db;

        db = new Db(env, 0);
        db.open(null, "store1.db", null, type, openFlags, 0);
        store1 = factory.newDataStore(db, MarshalledObject.class, null);

        db = new Db(env, 0);
        db.open(null, "index1.db", null, type, openFlags, 0);
        index1 = factory.newDataIndex(store1, db, "1", false, true);

        db = new Db(env, 0);
        db.open(null, "store2.db", null, type, openFlags, 0);
        store2 = factory.newDataStore(db, MarshalledObject.class, null);

        db = new Db(env, 0);
        db.open(null, "index2.db", null, type, openFlags, 0);
        index2 = factory.newForeignKeyIndex(store2, db, "2", false, true,
                                            store1,
                                            ForeignKeyIndex.ON_DELETE_CASCADE);
    }
View Full Code Here

        ByteArrayBinding dataBinding = new ByteArrayBinding(dataFormat);

        int envFlags = Db.DB_INIT_MPOOL | Db.DB_CREATE;
        env = new DbEnv(0);
        env.open(dir.getAbsolutePath(), envFlags, 0);
        Db db = new Db(env, 0);
        db.open(null, "test.db", null, Db.DB_BTREE, Db.DB_CREATE, 0);
        store = new DataStore(db, dataFormat, dataFormat, null);
        view = new DataView(store, null, dataBinding, dataBinding, null, true);
    }
View Full Code Here

        store.close();
        store = null;

        // is not transactional because is not opened in a transaction
        //
        Db db = new Db(env, 0);
        db.open(null, null, null, Db.DB_BTREE, 0, 0);
        store = new DataStore(db, TestStore.BYTE_FORMAT,
                                  TestStore.BYTE_FORMAT, null);
        map = new StoredSortedMap(store,
                testStore.getKeyBinding(), testStore.getValueBinding(), true);
        assertTrue(!map.isTransactional());
        map.put(ONE, ONE);
        readCheck(map, ONE, ONE);
        store.close();

        // is transactional because is opened in a transaction
        //
        currentTxn.beginTxn();
        db = new Db(env, 0);
        db.open(currentTxn.getTxn(), null, null, Db.DB_BTREE, 0, 0);
        currentTxn.commitTxn();
        store = new DataStore(db, TestStore.BYTE_FORMAT,
                                  TestStore.BYTE_FORMAT, null);
        map = new StoredSortedMap(store,
                testStore.getKeyBinding(), testStore.getValueBinding(), true);
View Full Code Here

    }

    private Db openDb(String file, boolean dups)
        throws Exception {

        Db db = new Db(env, 0);
        if (dups)
            db.setFlags(Db.DB_DUPSORT);
        db.open(null, file, null, Db.DB_HASH,
                Db.DB_CREATE | Db.DB_AUTO_COMMIT, 0);
        return db;
    }
View Full Code Here

    }

    private Db openDb(String file)
        throws Exception {

        Db db = new Db(env, 0);
        db.open(null, file, null, Db.DB_HASH, openFlags, 0);
        return db;
    }
View Full Code Here

    DataStore open(DbEnv env, String fileName)
        throws IOException, DbException {

        int fixedLen = (isQueueOrRecno() ? 1 : 0);
        Db db = openDb(env, fileName, fixedLen);
        PrimaryKeyAssigner keyAssigner =
            isQueueOrRecno() null : getKeyAssigner();
        return new DataStore(db, keyFormat, BYTE_FORMAT, keyAssigner);
    }
View Full Code Here

    DataIndex openIndex(DataStore store, String fileName)
        throws IOException, DbException {

        int fixedLen = (isQueueOrRecno() ? 4 : 0);
        Db db = openDb(store.getEnv(), fileName, fixedLen);
        return new DataIndex(store, db, keyFormat,
                        (isRecNumFormat ? RECNO_EXTRACTOR : BYTE_EXTRACTOR));
    }
View Full Code Here

    }

    private Db openDb(DbEnv env, String fileName, int fixedLen)
        throws IOException, DbException {

        Db db = new Db(env, 0);
        db.setFlags(flags);
        if (fixedLen > 0) {
            db.setRecordLength(fixedLen);
            db.setRecordPad(0);
        }
        int openFlags = Db.DB_DIRTY_READ | Db.DB_CREATE;
        if (CurrentTransaction.getInstance(env) != null)
            openFlags |= Db.DB_AUTO_COMMIT;
        db.open(null, fileName, null, type, openFlags, 0);
        return db;
    }
View Full Code Here

TOP

Related Classes of com.sleepycat.db.Db

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.