{"id":20060864,"url":"https://github.com/brandaof/entity-file-manager","last_synced_at":"2025-06-27T17:36:02.002Z","repository":{"id":184323264,"uuid":"130046754","full_name":"brandaof/entity-file-manager","owner":"brandaof","description":"Persists entities in structured files with transactional support.","archived":false,"fork":false,"pushed_at":"2018-10-05T17:19:09.000Z","size":338,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-02T10:14:48.595Z","etag":null,"topics":["disk","java","java-8","java8","persistence-framework"],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/brandaof.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-04-18T10:37:50.000Z","updated_at":"2025-01-14T13:08:44.000Z","dependencies_parsed_at":null,"dependency_job_id":"cbf231de-8ef1-4fb8-921f-b580a5ea0a74","html_url":"https://github.com/brandaof/entity-file-manager","commit_stats":null,"previous_names":["brandaof/entity-file-manager"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/brandaof/entity-file-manager","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brandaof%2Fentity-file-manager","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brandaof%2Fentity-file-manager/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brandaof%2Fentity-file-manager/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brandaof%2Fentity-file-manager/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/brandaof","download_url":"https://codeload.github.com/brandaof/entity-file-manager/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brandaof%2Fentity-file-manager/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262302537,"owners_count":23290280,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["disk","java","java-8","java8","persistence-framework"],"created_at":"2024-11-13T13:17:14.081Z","updated_at":"2025-06-27T17:36:01.982Z","avatar_url":"https://github.com/brandaof.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"﻿# Entity file manager\r\nEntity file manager é um recurso que permite persistir entidades em arquivos estruturados. Ele foi desenvolvido com a finalidade de dar suporte à persistência de dados no BRCache. Ele basicamente é composto pelas classes EntityFileManager, EntityFile, EntityFileAccess e EntityFileTransactionManager.\r\n\r\n## Como usar\r\n\r\n1.  Criar a implementação do EntityFileDataHandler;\r\n2.  Criar o header do arquivo;\r\n3.  Instanciar alguma implementação do EntityFileAccess;\r\n4.  Iniciar o EntityFileManager e registrar o EntityFileAccess.\r\n\r\n\r\nExemplo:\r\n\r\n### Entity\r\n\r\n```\r\npublic class Entity {\r\n\r\n\tprivate int id;\r\n\t\r\n\tprivate int status;\r\n\t\r\n\tprivate String message;\r\n\r\n\t...\r\n\t\r\n}\r\n```\r\n\r\n### EntityFileDataHandler\r\n\r\n```\r\npublic class EntityEntityFileAccessHandler \r\n\timplements EntityFileDataHandler\u003cEntity, byte[], EntityEntityFileAccessHeader\u003e{\r\n\r\n\tprivate static final int ROW_LENGTH = 151;\r\n\r\n\tprivate static final int DATA_LENGTH = 150;\r\n\t\r\n\tprivate static final int FIRST_POINTER = 0;\r\n\t\r\n\tprivate static final int HEADER_LENGTH = 0;\r\n\t\r\n\tprivate static final int EOF_LENGTH = 1;\r\n\t\r\n\tprivate static final int FIRST_RECORD = HEADER_LENGTH;\r\n\t\r\n\tprivate byte[] emptyEntity;\r\n\t\r\n\tprivate byte[] readBuffer;\r\n\t\r\n\tpublic EntityEntityFileAccessHandler(){\r\n\t\temptyEntity = new byte[DATA_LENGTH];\r\n\t\treadBuffer  = new byte[DATA_LENGTH];\r\n\t}\r\n\t\r\n\tpublic void writeMetaData(DataWritter stream,\r\n\t\t\tEntityEntityFileAccessHeader value) throws IOException {\r\n\t}\r\n\r\n\tpublic EntityEntityFileAccessHeader readMetaData(DataReader srteam)\r\n\t\t\tthrows IOException {\r\n\t\treturn new EntityEntityFileAccessHeader();\r\n\t}\r\n\r\n\tpublic void writeEOF(DataWritter stream) throws IOException {\r\n\t\tstream.writeByte((byte)-1);\r\n\t}\r\n\r\n\tpublic void write(DataWritter stream, Entity entity) throws IOException {\r\n\t\tstream.writeByte((byte)(entity == null? 0 : 1));\r\n\t\tif(entity == null){\r\n\t\t\tstream.write(emptyEntity);\r\n\t\t}\r\n\t\telse{\r\n\t\t\tstream.writeInt(entity.getId());\r\n\t\t\tstream.writeInt(entity.getStatus());\r\n\t\t\tstream.writeString(entity.getMessage(), 142);\r\n\t\t}\r\n\t}\r\n\r\n\tpublic void writeRaw(DataWritter stream, byte[] entity) throws IOException {\r\n\t\tstream.write(entity);\r\n\t}\r\n\r\n\tpublic Entity read(DataReader stream) throws IOException {\r\n\t\tboolean isnull = stream.readByte() == 0;\r\n\t\t\r\n\t\tif(isnull){\r\n\t\t\tstream.read(readBuffer);\r\n\t\t\treturn null;\r\n\t\t}\r\n\t\telse{\r\n\t\t\tEntity e = new Entity();\r\n\t\t\te.setId(stream.readInt());\r\n\t\t\te.setStatus(stream.readInt());\r\n\t\t\te.setMessage(stream.readString(142));\r\n\t\t\treturn e;\r\n\t\t}\r\n\t\t\r\n\t}\r\n\r\n\tpublic byte[] readRaw(DataReader stream) throws IOException {\r\n\t\tbyte[] buffer = new byte[ROW_LENGTH];\r\n\t\tstream.read(buffer);\r\n\t\treturn buffer;\r\n\t}\r\n\r\n\tpublic long getFirstPointer() {\r\n\t\treturn FIRST_POINTER;\r\n\t}\r\n\r\n\tpublic int getHeaderLength() {\r\n\t\treturn HEADER_LENGTH;\r\n\t}\r\n\r\n\tpublic int getRecordLength() {\r\n\t\treturn ROW_LENGTH;\r\n\t}\r\n\r\n\tpublic int getEOFLength() {\r\n\t\treturn EOF_LENGTH;\r\n\t}\r\n\r\n\tpublic int getFirstRecord() {\r\n\t\treturn FIRST_RECORD;\r\n\t}\r\n\r\n\tpublic Class\u003cEntity\u003e getType() {\r\n\t\treturn Entity.class;\r\n\t}\r\n\r\n\tpublic Class\u003cbyte[]\u003e getRawType() {\r\n\t\treturn byte[].class;\r\n\t}\r\n\r\n}\r\n```\r\n### Header\r\n\r\n```\r\npublic static class EntityEntityFileAccessHeader{\r\n}\r\n```\r\n\r\n### Instanciando o EntityFileAccess\r\n\r\n```\r\nFile entityFile = new File(\"entity\");\r\nEntityFileAccess\u003cEntity, byte[], EntityEntityFileAccessHeader\u003e entityEntityFileAccess =\r\n    new SimpleEntityFileAccess\u003cEntity, byte[], EntityEntityFileAccessHeader\u003e(\r\n        \"entity\", entityFile, new EntityEntityFileAccessHeader())\r\n\r\n``` \r\n\r\n### Iniciando o EntityFileManager\r\n\r\n```\r\nFile path   = new File(\"./data\");\r\nFile txPath = new File(path, \"tx\");\r\n\r\nEntityFileManagerConfigurer efm = new EntityFileManagerImp();\r\n\r\nLockProvider lp = new LockProviderImp();\r\n\r\nEntityFileTransactionManagerConfigurer tm = new EntityFileTransactionManagerImp();\r\n\r\ntm.setLockProvider(lp);\r\ntm.setTimeout(EntityFileTransactionManagerImp.DEFAULT_TIMEOUT);\r\ntm.setTransactionPath(txPath);\r\ntm.setEntityFileManagerConfigurer(efm);\r\n\r\nefm.setEntityFileTransactionManager(tm);\r\nefm.setLockProvider(lp);\r\nefm.setPath(path);\r\nefm.register(\"entity\", entityEntityFileAccess);\r\nefm.init();\r\n\r\n\r\nEntityFileTransaction tx = efm.beginTransaction();\r\ntry{\r\n    EntityFile\u003cLong\u003e ef = efm.getEntityFile(\"entity\", tx, Entity.class);\r\n    Entity e = new Entity();\r\n    ...\r\n    ef.insert(e);\r\n    tx.commit();\r\n}\r\ncatch(Throwable e){\r\n    tx.rollback();\r\n}\r\n```    \r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrandaof%2Fentity-file-manager","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrandaof%2Fentity-file-manager","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrandaof%2Fentity-file-manager/lists"}