微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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,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",blobId);

        // Continue building Database Tree
        Utils.putTableMeta(datarepo,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,(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,IOException {

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

    // Build tree for column attributs
    buildMetaTree(columns,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,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,DatabaseMetaData dbmd,TreeFormatter dbMetaTree,Boolean clmnTree) {

    String[] types = {"TABLE"};

    try {

        ResultSet tables = dbmd.getTables(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,tblMetaTree);

            ResultSet columns = dbmd.getColumns(null,tableName,null);
            if (clmnTree) {
                addColumnsAsTrees(columns,tblMetaTree,walkTbl,dbMetaTree);
            } else {
                addColumnsAsObjects(columns,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,TreeFormatter tblMetaTree,RevWalk walkTbl,TreeFormatter dbMetaTree) throws IOException,sqlException {

    while (columns.next()) {
        putColumnMetaAsObject(columns,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,TreeFormatter dbMetaTree) throws sqlException,IOException {

    while (columns.next()) {
        putColumnMetaAsTree(columns,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",nodeObject2);
  ObjectId tree = TreeUtils.insertTree(tf,repo);

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

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

  assertEquals(REGULAR_FILE,TreeUtils.getFileMode("file.txt",repo));
  assertEquals(TREE,TreeUtils.getFileMode("dir",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,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,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,false);              // (4)
                ObjectId lastTreeId = Commands.getLastCommitTreeId(repo,lastTreeId);     // (6)

                if (commitId != null) {
                    List<DiffEntry> list = Diffs.listDiffs(repo,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());
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。