Java 类org.eclipse.jgit.lib.TreeFormatter 实例源码

项目:gmds    文件:Utils.java   
/**
     *
     * @param dbmdJson
     * @param repo
     * @param tree
     * @param conn
     * @param clmnTree
     * @return
     * @throws IOException
     * @throws SQLException
     */
    public static ObjectId metaTreeCommit(ObjectJson dbmdJson, Repository repo, TreeFormatter tree, 
            Connection conn, Boolean clmnTree) throws IOException, SQLException {

        DatabaseMetaData dbmd = conn.getMetaData();
//        ObjectJson dbmdJson = new ObjectJson();
        String mapString = metaDbInfo(dbmd);
        ObjectInserter objectInserter = repo.newObjectInserter();
        ObjectId blobId = objectInserter.insert(Constants.OBJ_BLOB, mapString.getBytes());
        objectInserter.flush();

        tree.append(Consts.DATABASE, FileMode.REGULAR_FILE, blobId);
        Utils.putTableMeta(repo, conn, dbmd, objectInserter, tree, clmnTree);

        ObjectId treeId = objectInserter.insert(tree);
        objectInserter.flush();

        System.out.println("Tree ID: " + treeId.getName());

        return treeId;
    }
项目:gmds    文件:Utils.java   
/**
     *
     * @param datarepo
     * @param tree
     * @param conn
     * @param clmnTree
     * @return
     * @throws SQLException
     * @throws IOException
     */
    public static ObjectId dataTreeCommit(Repository datarepo, TreeFormatter tree, Connection conn, Boolean clmnTree) throws SQLException, IOException {
        DatabaseMetaData dbmd = conn.getMetaData();
//        ObjectJson dbmdJson = new ObjectJson();
        String mapString = metaDbInfo(dbmd);

        // Build Db_Info object, general info about Database
        ObjectInserter objectInserter = datarepo.newObjectInserter();
        ObjectId blobId = objectInserter.insert(Constants.OBJ_BLOB, mapString.getBytes());
        objectInserter.flush();

        tree.append("DATABASE", FileMode.REGULAR_FILE, blobId);

        // Continue building Database Tree
        Utils.putTableMeta(datarepo, conn, dbmd, objectInserter, tree, clmnTree);

        ObjectId treeId = objectInserter.insert(tree);
        objectInserter.flush();

        System.out.println("Tree ID: " + treeId.getName());

        return treeId;
    }
项目:gmds    文件:Utils.java   
/**
 * 
 * @param columns
 * @param objectInserter
 * @param tblTree
 * @param walkTbl
 * @return
 * @throws SQLException
 * @throws IOException 
 */
public static ObjectId putColumnMetaAsObject(ResultSet columns, 
        ObjectInserter objectInserter, TreeFormatter tblTree, RevWalk walkTbl) throws SQLException, IOException {

    // Build object for column attributs
    ObjectId objectId = buildMetaObject(columns, Consts.COLUMN_META_ATTRIBUTES, objectInserter);

    tblTree.append(Consts.COLUMN_META, FileMode.REGULAR_FILE, (AnyObjectId) objectId);

    // Add empty tree for the column content
    TreeFormatter clmnDataTree = new TreeFormatter();
    ObjectId clmnDataTreeId = objectInserter.insert(clmnDataTree);
    objectInserter.flush();

    tblTree.append(Consts.COLUMN_DATA, walkTbl.parseTree(clmnDataTreeId));

    return objectId;
}
项目:gmds    文件:Utils.java   
/**
 *
 * @param columns
 * @param objectInserter
 * @param tblTree
 * @param walkTbl
 * @return
 * @throws SQLException
 * @throws IOException
 */
public static ObjectId putColumnMetaAsTree(ResultSet columns, 
        ObjectInserter objectInserter, TreeFormatter tblTree, RevWalk walkTbl) throws SQLException, IOException {

    // Add tree for the column Metadata
    TreeFormatter clmnMetaTree = new TreeFormatter();

    // Build tree for column attributs
    buildMetaTree(columns, Consts.COLUMN_META_ATTRIBUTES, objectInserter, clmnMetaTree);

    ObjectId clmnMetaTreeId = objectInserter.insert(clmnMetaTree);
    objectInserter.flush();

    tblTree.append(Consts.COLUMN_META, walkTbl.parseTree(clmnMetaTreeId));

    // Add empty tree for the column content
    TreeFormatter clmnDataTree = new TreeFormatter();
    ObjectId clmnDataTreeId = objectInserter.insert(clmnDataTree);
    objectInserter.flush();

    tblTree.append(Consts.COLUMN_DATA, walkTbl.parseTree(clmnDataTreeId));

    return clmnMetaTreeId;
}
项目:gmds    文件:Utils.java   
private static ObjectId buildMetaTree(ResultSet set, String[] attrs, ObjectInserter inserter, TreeFormatter tree) throws IOException, SQLException {

        for (String attr : attrs) {
            ObjectJson objectJson = new ObjectJson();
            objectJson.addDoc(attr, set.getString(attr));

            String attrJson = new Map2JsonString().convert(objectJson.getObjectAsMap());
            ObjectId objectId = inserter.insert(Constants.OBJ_BLOB, attrJson.getBytes());
            inserter.flush();

            System.out.println("MetaObject: " + attrJson);
//            commitJson.addDoc(Consts.OBJECT_ID, objectId);

            tree.append(attr, FileMode.REGULAR_FILE, objectId);
        }
        return tree.computeId(inserter);
    }
项目:gmds    文件:Utils.java   
/**
 *
 * @param repo
 * @param conn
 * @param dbmd
 * @param objectInserter
 * @param dbMetaTree
 * @param clmnTree
 * @return
 */
public static TreeFormatter putTableMeta(Repository repo, Connection conn,
        DatabaseMetaData dbmd, ObjectInserter objectInserter, TreeFormatter dbMetaTree, Boolean clmnTree) {

    String[] types = {"TABLE"};

    try {

        ResultSet tables = dbmd.getTables(null, null, null, types);
        RevWalk walkTbl = new RevWalk(repo);

        while (tables.next()) {
            System.out.println("***************************************");
            String tableName = tables.getString(Consts.TABLE_NAME);

            TreeFormatter tblMetaTree = new TreeFormatter();

            // Build tree for table attributs
            buildMetaTree(tables, Consts.TABLE_META_ATTRIBUTES, objectInserter, tblMetaTree);

            ResultSet columns = dbmd.getColumns(null, null, tableName, null);
            if (clmnTree) {
                addColumnsAsTrees(columns, objectInserter, tblMetaTree, walkTbl, dbMetaTree);
            } else {
                addColumnsAsObjects(columns, objectInserter, tblMetaTree, walkTbl, dbMetaTree);
            }

            TreeFormatter tblDataTree = new TreeFormatter();
            ObjectId tblDataTreeId = objectInserter.insert(tblDataTree);
            objectInserter.flush();

            dbMetaTree.append(Consts.TABLE_DATA, walkTbl.parseTree(tblDataTreeId));
        }
    } catch (SQLException | IOException ex) {
        System.out.println(ex.getMessage());
    }
    return dbMetaTree;
}
项目:gmds    文件:Utils.java   
/**
 * 
 * @param columns
 * @param objectInserter
 * @param tblMetaTree
 * @param walkTbl
 * @param dbMetaTree
 * @throws IOException
 * @throws SQLException 
 */
public static void addColumnsAsObjects(ResultSet columns, 
        ObjectInserter objectInserter, TreeFormatter tblMetaTree, RevWalk walkTbl, 
        TreeFormatter dbMetaTree) throws IOException, SQLException {

    while (columns.next()) {
        putColumnMetaAsObject(columns, objectInserter, tblMetaTree, walkTbl);
    }

    ObjectId tblMetaTreeId = objectInserter.insert(tblMetaTree);
    objectInserter.flush();

    dbMetaTree.append(Consts.TABLE_META, walkTbl.parseTree(tblMetaTreeId));
}
项目:gmds    文件:Utils.java   
/**
 * 
 * @param columns
 * @param objectInserter
 * @param tblMetaTree
 * @param walkTbl
 * @param dbMetaTree
 * @throws SQLException
 * @throws IOException 
 */
public static void addColumnsAsTrees(ResultSet columns, 
        ObjectInserter objectInserter, TreeFormatter tblMetaTree, RevWalk walkTbl, 
        TreeFormatter dbMetaTree) throws SQLException, IOException {

    while (columns.next()) {
        putColumnMetaAsTree(columns, objectInserter, tblMetaTree, walkTbl);
    }

    ObjectId tblMetaTreeId = objectInserter.insert(tblMetaTree);
    objectInserter.flush();

    dbMetaTree.append(Consts.TABLE_META, walkTbl.parseTree(tblMetaTreeId));
}
项目:ParallelGit    文件:GfsChangesCollectorTest.java   
@Nonnull
private GitFileEntry newDirectoryEntry(String... children) throws IOException {
  TreeFormatter tf = new TreeFormatter();
  for(String child : children) {
    GitFileEntry childEntry = someFileEntry();
    tf.append(child, childEntry.getMode(), childEntry.getId());
  }
  ObjectId treeId = TreeUtils.insertTree(tf, repo);
  return newTreeEntry(treeId);
}
项目:ParallelGit    文件:TreeUtilsInsertTreeTest.java   
@Test
public void insertTreeIntoRepository_shouldBeAbleToRetrieveChildrenIdsByTreeIdAndFilename() throws IOException {
  initRepository();

  TreeFormatter tf = new TreeFormatter();
  ObjectId nodeObject1 = someObjectId();
  tf.append("file1.txt", REGULAR_FILE, nodeObject1);
  ObjectId nodeObject2 = someObjectId();
  tf.append("file2.txt", REGULAR_FILE, nodeObject2);
  ObjectId tree = TreeUtils.insertTree(tf, repo);

  assertEquals(nodeObject1, TreeUtils.getObjectId("file1.txt", tree, repo));
  assertEquals(nodeObject2, TreeUtils.getObjectId("file2.txt", tree, repo));
}
项目:ParallelGit    文件:TreeUtilsInsertTreeTest.java   
@Test
public void insertTreeIntoRepository_shouldBeAbleToRetrieveChildrenFileModesByTreeIdAndFilename() throws IOException {
  initRepository();

  TreeFormatter tf = new TreeFormatter();
  tf.append("file.txt", REGULAR_FILE, someObjectId());
  tf.append("dir", TREE, someObjectId());
  ObjectId tree = TreeUtils.insertTree(tf, repo);

  assertEquals(REGULAR_FILE, TreeUtils.getFileMode("file.txt", tree, repo));
  assertEquals(TREE, TreeUtils.getFileMode("dir", tree, repo));
}
项目:ParallelGit    文件:GfsChangesCollectorTest.java   
@Nonnull
private GitFileEntry newDirectoryEntry(String... children) throws IOException {
  TreeFormatter tf = new TreeFormatter();
  for(String child : children) {
    GitFileEntry childEntry = someFileEntry();
    tf.append(child, childEntry.getMode(), childEntry.getId());
  }
  ObjectId treeId = TreeUtils.insertTree(tf, repo);
  return newTreeEntry(treeId);
}
项目:ParallelGit    文件:TreeUtilsInsertTreeTest.java   
@Test
public void insertTreeIntoRepository_shouldBeAbleToRetrieveChildrenIdsByTreeIdAndFilename() throws IOException {
  initRepository();

  TreeFormatter tf = new TreeFormatter();
  ObjectId nodeObject1 = someObjectId();
  tf.append("file1.txt", REGULAR_FILE, nodeObject1);
  ObjectId nodeObject2 = someObjectId();
  tf.append("file2.txt", REGULAR_FILE, nodeObject2);
  ObjectId tree = TreeUtils.insertTree(tf, repo);

  assertEquals(nodeObject1, TreeUtils.getObjectId("file1.txt", tree, repo));
  assertEquals(nodeObject2, TreeUtils.getObjectId("file2.txt", tree, repo));
}
项目:ParallelGit    文件:TreeUtilsInsertTreeTest.java   
@Test
public void insertTreeIntoRepository_shouldBeAbleToRetrieveChildrenFileModesByTreeIdAndFilename() throws IOException {
  initRepository();

  TreeFormatter tf = new TreeFormatter();
  tf.append("file.txt", REGULAR_FILE, someObjectId());
  tf.append("dir", TREE, someObjectId());
  ObjectId tree = TreeUtils.insertTree(tf, repo);

  assertEquals(REGULAR_FILE, TreeUtils.getFileMode("file.txt", tree, repo));
  assertEquals(TREE, TreeUtils.getFileMode("dir", tree, repo));
}
项目:git-as-svn    文件:GitTreeUpdate.java   
@NotNull ObjectId buildTree(@NotNull ObjectInserter inserter) throws IOException, SVNException {
  final TreeFormatter treeBuilder = new TreeFormatter();
  final List<GitTreeEntry> sortedEntries = new ArrayList<>(entries.values());
  Collections.sort(sortedEntries);
  for (GitTreeEntry entry : sortedEntries) {
    treeBuilder.append(entry.getFileName(), entry.getFileMode(), entry.getObjectId().getObject());
  }
  new ObjectChecker().checkTree(treeBuilder.toByteArray());
  return inserter.insert(treeBuilder);
}
项目:gmds    文件:DataMain.java   
public static void main(String[] args) throws IOException, GitAPIException {

        Connection conn = null;
        Repository datarepo = Commands.getRepo(Consts.DATA_REPO_PATH + ".git");                             // (1)

        ObjectId lastCommitId = datarepo.resolve(Constants.HEAD);                                           // (2)
        System.out.println("Last Commit: " + lastCommitId);

        try {
            conn = DriverManager.getConnection(URL);

            TreeFormatter tree = new TreeFormatter();                                                       // (3)

            if (conn != null) {
                ObjectJson dbmdJson = new ObjectJson();
                ObjectId treeId = Utils.dataTreeCommit(datarepo, tree, conn, true);                         // (4)
                ObjectId lastTreeId = Commands.getLastCommitTreeId(datarepo, lastCommitId);                 // (5)
                ObjectId commitId = Commands.processCommit(lastCommitId, treeId, datarepo, lastTreeId);     // (6)
                if (commitId != null) {
                    List<DiffEntry> list = Diffs.listDiffs(datarepo, lastTreeId, treeId);                   // (7)
                    if (list != null) {
                        // Simply display the diff between the two commits
                        list.forEach((diff) -> {
                            // TODO
                            // Perform indexing of added to commit objects                                  // (8)

                            // Print trace results
                            System.out.println(diff);
                        });

                        // Index the whole commit tree                                                      // (9)

                        System.out.print(dbmdJson.getObjectAsMap());
                    }
                }
            } else {
                System.out.println("Metadata not supported");
            }
        } catch (SQLException ex1) {
            System.err.println(ex1);
        } finally {
            if (conn != null) {
                try {
                    conn.close();
                } catch (SQLException ex) {
                    Logger.getLogger(DataMain.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
    }
项目:gmds    文件:MetaMain.java   
public static void main(String[] args) throws IOException, GitAPIException {

        Connection conn = null;
        Repository repo = Commands.getRepo(Consts.META_REPO_PATH + ".git");                             // (1)

        ObjectId lastCommitId = repo.resolve(Constants.HEAD);                                           // (2)
        System.out.println("Last Commit: " + lastCommitId);

        try {
            conn = DriverManager.getConnection(URL);

            TreeFormatter tree = new TreeFormatter();                                                   // (3)

            if (conn != null) {
                ObjectJson dbmdJson = new ObjectJson();
                ObjectId treeId = Utils.metaTreeCommit(dbmdJson, repo, tree, conn, false);              // (4)
                ObjectId lastTreeId = Commands.getLastCommitTreeId(repo, lastCommitId);                 // (5)
                ObjectId commitId = Commands.processCommit(lastCommitId, treeId, repo, lastTreeId);     // (6)

                if (commitId != null) {
                    List<DiffEntry> list = Diffs.listDiffs(repo, lastTreeId, treeId);                   // (7)
                    if (list != null) {
                        // Simply display the diff between the two commits
                        list.forEach((diff) -> {
                            // TODO
                            // Perform indexing of added to commit objects
                        });
                    }
                    // Index the whole commit tree                                                      // (9)
                    DbIndex dbIndex = new DbIndex(Consts.META_REPO_PATH + ".git", esUrl, esPort);
                    dbIndex.indexCommitTree(repo);
                }
            } else {
                System.out.println("Metadata not supported");
            }
        } catch (SQLException ex1) {
            System.err.println(ex1);
        } finally {
            try {
                if (conn != null) {
                    conn.close();
                }
            } catch (SQLException ex2) {
                System.out.println(ex2.getMessage());
            }
        }
    }
项目:gerrit    文件:CreateChange.java   
private static ObjectId emptyTreeId(ObjectInserter inserter) throws IOException {
  return inserter.insert(new TreeFormatter());
}