├── .github
├── FUNDING.yml
└── workflows
│ └── ci.yml
├── .gitignore
├── .travis.yml
├── LICENSE.txt
├── README.md
├── build.gradle
├── buildSrc
├── build.gradle
└── src
│ └── main
│ └── java
│ ├── GenMarkers.kt
│ ├── GenRecords.kt
│ └── MDBCodeGen.kt
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── logger.properties
└── src
├── assembly
├── bin-component.xml
└── bin.xml
├── main
└── java
│ └── org
│ └── mapdb
│ ├── CC.java
│ ├── DBException.java
│ ├── cli
│ ├── Export.java
│ └── Import.java
│ ├── db
│ └── DB.java
│ ├── flat
│ └── LongBufStack.java
│ ├── io
│ ├── DataIO.java
│ ├── DataInput2.java
│ ├── DataInput2ByteArray.java
│ ├── DataInput2ByteBuffer.java
│ ├── DataInputToStream.java
│ ├── DataOutput2.java
│ └── DataOutput2ByteArray.java
│ ├── list
│ ├── KernelList.java
│ └── MonolithList.java
│ ├── record
│ └── Atomic.java
│ ├── ser
│ ├── ArrayDeltaSerializer.java
│ ├── ArrayListSerializer.java
│ ├── ArraySerializer.java
│ ├── ArrayTupleSerializer.java
│ ├── BigDecimalSerializer.java
│ ├── BigIntegerSerializer.java
│ ├── BooleanSerializer.java
│ ├── ByteArrayDelta2Serializer.java
│ ├── ByteArrayDeltaSerializer.java
│ ├── ByteArrayNoSizeSerializer.java
│ ├── ByteArraySerializer.java
│ ├── ByteSerializer.java
│ ├── CharArraySerializer.java
│ ├── CharSerializer.java
│ ├── ClassSerializer.java
│ ├── DateSerializer.java
│ ├── DefaultGroupSerializer.java
│ ├── DoubleArraySerializer.java
│ ├── DoubleSerializer.java
│ ├── EightByteSerializer.java
│ ├── FloatArraySerializer.java
│ ├── FloatSerializer.java
│ ├── FourByteSerializer.java
│ ├── GroupSerializer.java
│ ├── IntArraySerializer.java
│ ├── IntegerDeltaSerializer.java
│ ├── IntegerPackedSerializer.java
│ ├── IntegerSerializer.java
│ ├── JavaSerializer.java
│ ├── LongArraySerializer.java
│ ├── LongDeltaSerializer.java
│ ├── LongPackedSerializer.java
│ ├── LongSerializer.java
│ ├── RecidArraySerializer.java
│ ├── RecidSerializer.java
│ ├── Serializer.java
│ ├── SerializerIllegalAccess.java
│ ├── SerializerUtils.java
│ ├── Serializers.java
│ ├── ShortArraySerializer.java
│ ├── ShortSerializer.java
│ ├── StringAsciiSerializer.java
│ ├── StringDelta2Serializer.java
│ ├── StringDeltaSerializer.java
│ ├── StringInternSerializer.java
│ ├── StringNoSizeSerializer.java
│ ├── StringOrigHashSerializer.java
│ ├── StringSerializer.java
│ └── UUIDSerializer.java
│ ├── store
│ ├── ConcMapStore.java
│ ├── FileHeapBufStore.java
│ ├── HeapBufStore.java
│ ├── ReadonlyStore.java
│ ├── Recids.java
│ ├── Store.java
│ ├── StoreTx.java
│ ├── legacy
│ │ ├── DataInput2Exposed.java
│ │ ├── Fun.java
│ │ ├── LongConcurrentHashMap.java
│ │ ├── LongHashMap.java
│ │ ├── LongMap.java
│ │ ├── Store2.java
│ │ ├── StoreDirect.java
│ │ └── Volume.java
│ └── li
│ │ ├── LiStore.java
│ │ └── LiUtil.java
│ └── util
│ ├── Exporter.java
│ ├── IO.java
│ ├── JavaUtils.java
│ └── MonoRef.java
└── test
└── java
├── aaGenTest.kt
├── harmony
├── AbstractListTest.java
├── ArrayListTest.java
├── LinkedListTest.java
├── Support_CollectionTest.java
├── Support_ListTest.java
└── Support_UnmodifiableCollectionTest.java
└── org
└── mapdb
├── DBCollectionTest.kt
├── TT.kt
├── Verifiable.java
├── flat
└── LongBufStackTest.kt
├── guavaTests
├── ConcurrentMapInterfaceTest.java
├── GwtCompatible.java
├── Helpers.java
├── MapInterfaceTest.java
└── SortedMapInterfaceTest.java
├── io
└── DataIOTest.java
├── jsr166Tests
├── BlockingQueueTest.java
├── Collection8Test.java
├── CollectionImplementation.java
├── CollectionTest.java
├── JSR166TestCase.java
├── LinkedBlockingDeque8Test.java
├── LinkedBlockingDequeTest.java
├── LinkedBlockingQueue8Test.java
├── LinkedBlockingQueueTest.java
└── TreeMapTest.java
├── kotlin
├── Issue888_JavaI.java
├── Issue888_KotlinI.kt
└── Issue888_serializer_override.java
├── list
├── KernelListHarmonyTest.java
└── MonolithListHarmonyTest.java
├── record
├── BooleanRecordTest.java
├── IntRecordTest.java
├── LongRecordTest.java
├── StringRecordTest.java
└── VarRecordTest.java
├── ser
├── BTreeKeySerializerTest.java
├── SerializerArrayTest.java
├── SerializerTest.kt
├── SerializersJavaAccessTest.java
└── SerializersTest.kt
└── store
├── StoreReopenTest.kt
└── StoreTest.kt
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | github: jankotek
2 |
--------------------------------------------------------------------------------
/.github/workflows/ci.yml:
--------------------------------------------------------------------------------
1 | ---
2 | name: Java CI
3 |
4 | on: [push]
5 |
6 | jobs:
7 | test:
8 | runs-on: ${{ matrix.os }}
9 | strategy:
10 | matrix:
11 | os: [ubuntu-18.04, macOS-latest, windows-2016]
12 | java: [8, 11]
13 | fail-fast: false
14 | max-parallel: 4
15 | name: Test JDK ${{ matrix.java }}, ${{ matrix.os }}
16 |
17 | steps:
18 | - uses: actions/checkout@v2
19 | - name: Set up JDK
20 | uses: actions/setup-java@v1
21 | with:
22 | java-version: ${{ matrix.java }}
23 | - name: Grant execute permission for gradlew
24 | run: chmod +x gradlew
25 | - name: Test with Gradle
26 | run: ./gradlew test
27 | ...
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .classpath
2 | .project
3 | .settings
4 | .idea
5 | target
6 | build
7 | bin
8 | out
9 | helper
10 | *.iml
11 | *.ipr
12 | *.iws
13 | .directory
14 | *.log
15 | .gradle
16 | *.log
17 |
18 |
19 | srcGen/*
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: java
2 |
3 | jdk:
4 | - openjdk8
5 | - openjdk11
6 | # - oraclejdk10
7 |
8 | sudo: false
9 |
10 | before_cache:
11 | - rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
12 | - rm -fr $HOME/.gradle/caches/*/plugin-resolution/
13 |
14 | #before_install:
15 | # - sudo apt-get purge gradle
16 | # - sudo add-apt-repository ppa:cwchien/gradle -y
17 | # - sudo apt-get update -q
18 | # - sudo apt-get install gradle -y
19 |
20 | cache:
21 | directories:
22 | - $HOME/.gradle/caches/
23 | - $HOME/.gradle/wrapper/
24 | - $HOME/.m2/repository/
25 |
26 | install: /bin/true
27 |
28 | script: ./gradlew test
29 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | MapDB: database engine
4 | =======================
5 | [](https://travis-ci.org/jankotek/mapdb)
6 | [](https://search.maven.org/#search%7Cga%7C1%7Cg%3A%22org.mapdb%22%20AND%20a%3Amapdb)
7 | [](https://gitter.im/jankotek/mapdb?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
8 |
9 |
10 | MapDB combines embedded database engine and Java collections.
11 | It is free under Apache 2 license. MapDB is flexible and can be used in many roles:
12 |
13 | * Drop-in replacement for Maps, Lists, Queues and other collections.
14 | * Off-heap collections not affected by Garbage Collector
15 | * Multilevel cache with expiration and disk overflow.
16 | * RDBMs replacement with transactions, MVCC, incremental backups etc…
17 | * Local data processing and filtering. MapDB has utilities to process huge quantities of data in reasonable time.
18 |
19 | Hello world
20 | -------------------
21 |
22 | Maven snippet, VERSION is [](https://search.maven.org/#search%7Cga%7C1%7Cg%3A%22org.mapdb%22%20AND%20a%3Amapdb)
23 |
24 | ```xml
25 |
26 | org.mapdb
27 | mapdb
28 | VERSION
29 |
30 | ```
31 |
32 | Hello world:
33 |
34 | ```java
35 | //import org.mapdb.*
36 | DB db = DBMaker.memoryDB().make();
37 | ConcurrentMap map = db.hashMap("map").make();
38 | map.put("something", "here");
39 | ```
40 |
41 | You can continue with [quick start](https://jankotek.gitbooks.io/mapdb/content/quick-start/) or refer to the [documentation](https://jankotek.gitbooks.io/mapdb/).
42 |
43 | Support
44 | ------------
45 |
46 | More [details](http://www.mapdb.org/support/).
47 |
48 | Development
49 | --------------------
50 |
51 | MapDB is written in Kotlin, you will need IntelliJ Idea.
52 |
53 | You can use Gradle to build MapDB.
54 |
55 | MapDB is extensively unit-tested.
56 | By default, only tiny fraction of all tests are executed, so build finishes under 10 minutes.
57 | Full test suite has over million test cases and runs for several hours/days.
58 | To run full test suite, set `-Dmdbtest=1` VM option.
59 |
60 | Longer unit tests might require more memory. Use this to increase heap memory assigned to unit tests: `-DtestArgLine="-Xmx3G"`
61 |
62 | By default unit tests are executed in 3 threads. Thread count is controlled by `-DtestThreadCount=3` property
63 |
64 | On machine with limited memory you can change fork mode so unit test consume less RAM, but run longer: `-DtestReuseForks=false`
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 |
3 | ext.kotlin_version = '1.4.10'
4 | ext.junit_version = '5.7.0'
5 | ext.ec_version = '10.4.0'
6 | ext.guava_version = '28.2-jre'
7 |
8 | repositories {
9 | mavenCentral()
10 | }
11 |
12 | dependencies {
13 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
14 | }
15 | }
16 | apply plugin: "kotlin"
17 |
18 | compileKotlin {
19 | kotlinOptions {
20 | jvmTarget = '1.8'
21 | }
22 | }
23 |
24 |
25 | sourceSets {
26 | //combine Kotlin and Java source into same dirs
27 | main.kotlin.srcDirs += 'src/main/java'
28 | main.java.srcDirs += 'src/main/java'
29 | test.kotlin.srcDirs += 'src/test/java'
30 | test.java.srcDirs += 'src/test/java'
31 |
32 | //include generated code into build
33 | main.kotlin.srcDirs += 'srcGen/main/java'
34 | main.java.srcDirs += 'srcGen/main/java'
35 | test.kotlin.srcDirs += 'srcGen/test/java'
36 | test.java.srcDirs += 'srcGen/test/java'
37 |
38 | }
39 |
40 | repositories {
41 | mavenCentral()
42 | }
43 |
44 |
45 | test{
46 | maxParallelForks = 5
47 | maxHeapSize = '2G'
48 | }
49 |
50 | dependencies {
51 | compile "org.eclipse.collections:eclipse-collections-api:$ec_version"
52 | compile "org.eclipse.collections:eclipse-collections:$ec_version"
53 |
54 | compile "com.google.guava:guava:$guava_version"
55 |
56 | compile group: 'org.jetbrains', name: 'annotations', version: '20.1.0'
57 |
58 | compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
59 | compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
60 |
61 | compile 'org.lz4:lz4-java:1.7.1'
62 |
63 | testCompile("io.kotlintest:kotlintest-runner-junit5:3.4.2")
64 | testCompile("org.junit.vintage:junit-vintage-engine:$junit_version")
65 | testCompile("org.junit.jupiter:junit-jupiter-api:$junit_version")
66 | testCompile("org.junit.jupiter:junit-jupiter-engine:$junit_version")
67 | }
68 |
--------------------------------------------------------------------------------
/buildSrc/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | ext.kotlin_version = '1.2.50'
3 |
4 | repositories {
5 | mavenCentral()
6 | }
7 |
8 | dependencies {
9 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
10 | }
11 | }
12 |
13 | apply plugin: "kotlin"
14 |
15 | compileKotlin {
16 | kotlinOptions {
17 | // freeCompilerArgs = ['-Xenable-jvm-default']
18 | jvmTarget = '1.8'
19 | }
20 | }
21 |
22 |
23 | sourceSets {
24 | main.kotlin.srcDirs += 'src/main/java'
25 | main.java.srcDirs += 'src/main/java'
26 | test.kotlin.srcDirs += 'src/test/java'
27 | test.java.srcDirs += 'src/test/java'
28 |
29 |
30 | }
31 |
32 | repositories {
33 | mavenCentral()
34 | }
35 |
36 |
37 | dependencies {
38 | compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
39 | }
40 |
41 |
42 | task codegenClean(type: Delete) {
43 | delete "../srcGen"
44 | }
45 |
46 | task codegen(type:JavaExec) {
47 |
48 | dependsOn(codegenClean)
49 | main = "MDBCodeGen"
50 | classpath = sourceSets.main.runtimeClasspath
51 | }
52 |
53 |
54 | build.dependsOn(codegen)
--------------------------------------------------------------------------------
/buildSrc/src/main/java/GenMarkers.kt:
--------------------------------------------------------------------------------
1 | import java.io.File
2 |
3 | object GenMarkers{
4 |
5 | val markers:Map = linkedMapOf(
6 | Pair("//-WLOCK", """lock.writeLock().lock(); try{"""),
7 | Pair("//-WUNLOCK", """}finally{lock.writeLock().unlock();}"""),
8 | Pair("//-newRWLOCK", """java.util.concurrent.locks.ReadWriteLock lock = new java.util.concurrent.locks.ReentrantReadWriteLock();""")
9 | )
10 |
11 | fun recurJavaFiles(dir:File, f: (File) -> Unit){
12 | val allFiles = dir.listFiles();
13 | allFiles.filter { it.extension.equals("java") }.forEach(f)
14 | allFiles.filter{it.isDirectory}.forEach{recurJavaFiles(it,f)}
15 | }
16 |
17 |
18 | // process //*-WLOCk markers
19 | fun wlock(srcDir: File, genDir:File) {
20 | recurJavaFiles(srcDir) { f:File->
21 | var content = f.readText()
22 |
23 | if(markers.keys.none{content.contains(it)}) {
24 | return@recurJavaFiles
25 | }
26 | for ((marker, repl) in markers) {
27 | content = content.replace(marker, repl)
28 | }
29 |
30 | val oldClassName = f.nameWithoutExtension
31 | content = content.replace("class "+oldClassName, "class ${oldClassName}RWLock")
32 | content = content.replace(" "+oldClassName+"(", " ${oldClassName}RWLock(")
33 |
34 | val newFile = File(genDir.path + "/"+ f.relativeTo(srcDir).parent +"/"+ oldClassName + "RWLock.java")
35 |
36 | newFile.parentFile.mkdirs()
37 | newFile.writeText(content)
38 |
39 | }
40 | }
41 |
42 | }
--------------------------------------------------------------------------------
/buildSrc/src/main/java/MDBCodeGen.kt:
--------------------------------------------------------------------------------
1 | import org.gradle.internal.impldep.org.apache.commons.io.FileUtils
2 | import java.io.File
3 |
4 | class MDBCodeGen{
5 | companion object {
6 | @JvmStatic
7 | fun main(args: Array) {
8 |
9 | val srcGenDir = File("../srcGen/main/java")
10 | val srcDir = File("../src/main/java")
11 |
12 | val testGenDir = File("../srcGen/test/java")
13 |
14 |
15 | FileUtils.write(File(srcGenDir, "AACodeGen.java"), """
16 | public class AACodeGen{
17 | }
18 | """)
19 |
20 | val srcDirRecords = File(srcGenDir, "org/mapdb/record/")
21 | srcDirRecords.mkdirs()
22 | GenRecords.makeRecordMakers(srcDirRecords)
23 |
24 | GenMarkers.wlock(srcDir, srcGenDir);
25 |
26 | }
27 | }
28 |
29 |
30 | }
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jankotek/mapdb/8721c0e824d8d546ecc76639c05ccbc618279511/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-bin.zip
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @rem
2 | @rem Copyright 2015 the original author or authors.
3 | @rem
4 | @rem Licensed under the Apache License, Version 2.0 (the "License");
5 | @rem you may not use this file except in compliance with the License.
6 | @rem You may obtain a copy of the License at
7 | @rem
8 | @rem http://www.apache.org/licenses/LICENSE-2.0
9 | @rem
10 | @rem Unless required by applicable law or agreed to in writing, software
11 | @rem distributed under the License is distributed on an "AS IS" BASIS,
12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | @rem See the License for the specific language governing permissions and
14 | @rem limitations under the License.
15 | @rem
16 |
17 | @if "%DEBUG%" == "" @echo off
18 | @rem ##########################################################################
19 | @rem
20 | @rem Gradle startup script for Windows
21 | @rem
22 | @rem ##########################################################################
23 |
24 | @rem Set local scope for the variables with windows NT shell
25 | if "%OS%"=="Windows_NT" setlocal
26 |
27 | set DIRNAME=%~dp0
28 | if "%DIRNAME%" == "" set DIRNAME=.
29 | set APP_BASE_NAME=%~n0
30 | set APP_HOME=%DIRNAME%
31 |
32 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
33 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
34 |
35 | @rem Find java.exe
36 | if defined JAVA_HOME goto findJavaFromJavaHome
37 |
38 | set JAVA_EXE=java.exe
39 | %JAVA_EXE% -version >NUL 2>&1
40 | if "%ERRORLEVEL%" == "0" goto init
41 |
42 | echo.
43 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
44 | echo.
45 | echo Please set the JAVA_HOME variable in your environment to match the
46 | echo location of your Java installation.
47 |
48 | goto fail
49 |
50 | :findJavaFromJavaHome
51 | set JAVA_HOME=%JAVA_HOME:"=%
52 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
53 |
54 | if exist "%JAVA_EXE%" goto init
55 |
56 | echo.
57 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
58 | echo.
59 | echo Please set the JAVA_HOME variable in your environment to match the
60 | echo location of your Java installation.
61 |
62 | goto fail
63 |
64 | :init
65 | @rem Get command-line arguments, handling Windows variants
66 |
67 | if not "%OS%" == "Windows_NT" goto win9xME_args
68 |
69 | :win9xME_args
70 | @rem Slurp the command line arguments.
71 | set CMD_LINE_ARGS=
72 | set _SKIP=2
73 |
74 | :win9xME_args_slurp
75 | if "x%~1" == "x" goto execute
76 |
77 | set CMD_LINE_ARGS=%*
78 |
79 | :execute
80 | @rem Setup the command line
81 |
82 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
83 |
84 | @rem Execute Gradle
85 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
86 |
87 | :end
88 | @rem End local scope for the variables with windows NT shell
89 | if "%ERRORLEVEL%"=="0" goto mainEnd
90 |
91 | :fail
92 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
93 | rem the _cmd.exe /c_ return code!
94 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
95 | exit /b 1
96 |
97 | :mainEnd
98 | if "%OS%"=="Windows_NT" endlocal
99 |
100 | :omega
101 |
--------------------------------------------------------------------------------
/logger.properties:
--------------------------------------------------------------------------------
1 | #
2 | # An example of logger config file used for debugging.
3 | #
4 | # MapDB is compiled without logging messages by default.
5 | # Make sure you enable them in CC.java
6 | #
7 | # You must enable this file by passing system property before JVM starts
8 | #
9 | # >java -Djava.util.logging.config.file=logger.properties
10 | #
11 |
12 | handlers=java.util.logging.FileHandler, java.util.logging.ConsoleHandler
13 |
14 | # Default global logging level.
15 | # Loggers and Handlers may override this level
16 | .level=FINEST
17 |
18 | # Loggers
19 | # ------------------------------------------
20 | # Loggers are usually attached to packages.
21 | # Here, the level for each package is specified.
22 | # The global level is used by default, so levels
23 | # specified here simply act as an override.
24 | org.mapdb.level=ALL
25 |
26 | #some other filtering options
27 | myapp.business.level=CONFIG
28 | myapp.data.level=SEVERE
29 |
30 | # Handlers
31 | java.util.logging.ConsoleHandler.level=ALL
32 | java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter
33 |
34 | # --- FileHandler ---
35 | java.util.logging.FileHandler.level=ALL
36 |
37 | # Naming style for the output file:
38 | # (The output file is placed in the directory
39 | # defined by the "user.home" System property.)
40 | java.util.logging.FileHandler.pattern=%h/java%u.log
41 |
42 | # Limiting size of output file in bytes:
43 | java.util.logging.FileHandler.limit=500000
44 |
45 | # Number of output files to cycle through, by appending an
46 | # integer to the base file name:
47 | java.util.logging.FileHandler.count=1
48 |
49 | # Style of output (Simple or XML):
50 | java.util.logging.FileHandler.formatter=java.util.logging.SimpleFormatter
--------------------------------------------------------------------------------
/src/assembly/bin-component.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | lib
5 | false
6 | runtime
7 |
8 |
9 |
10 |
20 |
21 |
--------------------------------------------------------------------------------
/src/assembly/bin.xml:
--------------------------------------------------------------------------------
1 |
5 | bin
6 |
7 | zip
8 |
9 |
10 | src/assembly/bin-component.xml
11 |
12 |
22 |
23 |
--------------------------------------------------------------------------------
/src/main/java/org/mapdb/CC.java:
--------------------------------------------------------------------------------
1 | package org.mapdb;
2 |
3 | //TODO name conflict with 3.0, remove this class
4 | public interface CC {
5 | boolean PARANOID = false;
6 | boolean ASSERT = true;
7 | //TODO move to preprocessor
8 | boolean LOG_STORE = false;
9 | }
10 |
--------------------------------------------------------------------------------
/src/main/java/org/mapdb/DBException.java:
--------------------------------------------------------------------------------
1 | package org.mapdb;
2 |
3 |
4 | public class DBException extends RuntimeException {
5 |
6 | public DBException(Exception cause){
7 | super(cause);
8 | }
9 |
10 | public DBException(String msg){
11 | super(msg);
12 | }
13 |
14 | public DBException(String msg, Exception cause){
15 | super(msg,cause);
16 | }
17 |
18 | public static class RecordNotFound extends DBException{
19 | public RecordNotFound(){
20 | super("record not found");
21 | }
22 | }
23 |
24 |
25 |
26 | public static class StoreReentry extends DBException {
27 | public StoreReentry() {
28 | super("repeated call to Store method");
29 | }
30 | }
31 |
32 | public static class FileLocked extends DBException {
33 | public FileLocked() {
34 | super("file locked");
35 | }
36 | }
37 |
38 | public static class PreallocRecordAccess extends DBException{
39 | public PreallocRecordAccess(){
40 | super("preallocated record accessed");
41 | }
42 | }
43 |
44 | public static class StoreClosed extends DBException{
45 | public StoreClosed(){
46 | super("store closed");
47 | }
48 | }
49 |
50 |
51 | public static class DataCorruption extends DBException{
52 | public DataCorruption(){
53 | super("data corruption");
54 | }
55 |
56 | public DataCorruption(String msg) {
57 | super(msg);
58 | }
59 | }
60 |
61 | public static class SerializationError extends DBException{
62 | public SerializationError(Exception e){
63 | super(e);
64 | }
65 | }
66 |
67 | public static class WrongConfig extends DBException {
68 |
69 | public WrongConfig(String msg) {
70 | super(msg);
71 | }
72 | }
73 |
74 | public static class WrongSerializer extends WrongConfig{
75 | public WrongSerializer(){
76 | super("wrong serializer used");
77 | }
78 | }
79 |
80 |
81 | public static class PointerChecksumBroken extends DataCorruption{
82 |
83 | }
84 |
85 | public static class TODO extends DBException{
86 |
87 | public TODO() {
88 | super("not implemented yet");
89 | }
90 |
91 | public TODO(String msg) {
92 | super(msg);
93 | }
94 | }
95 |
96 | public static class RecordNotPreallocated extends DBException {
97 |
98 | public RecordNotPreallocated() {
99 | super("Record was not preallocated");
100 | }
101 | }
102 | }
--------------------------------------------------------------------------------
/src/main/java/org/mapdb/cli/Export.java:
--------------------------------------------------------------------------------
1 | package org.mapdb.cli;
2 |
3 | import org.jetbrains.annotations.NotNull;
4 |
5 | public class Export {
6 |
7 | public static void main(@NotNull String[] arrayOf) {
8 |
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/org/mapdb/cli/Import.java:
--------------------------------------------------------------------------------
1 | package org.mapdb.cli;
2 |
3 | import org.jetbrains.annotations.NotNull;
4 |
5 | public class Import {
6 |
7 | public static void main(@NotNull String[] args) {
8 |
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/org/mapdb/db/DB.java:
--------------------------------------------------------------------------------
1 | package org.mapdb.db;
2 |
3 | import org.jetbrains.annotations.NotNull;
4 | import org.mapdb.store.HeapBufStore;
5 | import org.mapdb.store.Store;
6 |
7 | import java.io.File;
8 |
9 | public class DB {
10 | private final Store store;
11 |
12 | public DB(Store store) {
13 | this.store = store;
14 | }
15 |
16 | public Store getStore(){
17 | return store;
18 | }
19 |
20 | public void close() {
21 |
22 | }
23 |
24 | public static class Maker {
25 |
26 | private final Store store;
27 |
28 | private Maker(Store store) {
29 | this.store = store;
30 | }
31 |
32 | @NotNull
33 | public static Maker appendFile(@NotNull File f) {
34 | return null;
35 | }
36 |
37 | @NotNull
38 | public DB make() {
39 | return new DB(store);
40 | }
41 |
42 | @NotNull
43 | public static Maker heapSer() {
44 | return new Maker(new HeapBufStore());
45 | }
46 |
47 | @NotNull
48 | public static Maker memoryDB() {
49 | return new Maker(new HeapBufStore());
50 | }
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/src/main/java/org/mapdb/flat/LongBufStack.java:
--------------------------------------------------------------------------------
1 | package org.mapdb.flat;
2 |
3 | import java.nio.ByteBuffer;
4 |
5 | public class LongBufStack{
6 |
7 | private int pos = 0;
8 |
9 |
10 | //TODO LongBuffer?
11 | private final ByteBuffer buf;
12 |
13 | public LongBufStack(ByteBuffer buf) {
14 | this.buf = buf;
15 | }
16 |
17 | public LongBufStack(){
18 | this(ByteBuffer.allocate(8*1024*1024));
19 | }
20 |
21 | public long pop(){
22 | if(pos==0)
23 | return 0L;
24 | return buf.getLong(8*(--pos));
25 | }
26 |
27 | public void push(long value){
28 | if(value == 0L)
29 | throw new IllegalArgumentException();
30 |
31 | buf.putLong(8*(pos++), value);
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/src/main/java/org/mapdb/io/DataInput2.java:
--------------------------------------------------------------------------------
1 | package org.mapdb.io;
2 |
3 | import java.io.DataInput;
4 | import java.io.IOException;
5 |
6 | public interface DataInput2{
7 |
8 | /**
9 | * How many bytes are available for read (`total size - current position`).
10 | * Returns `Integer.MIN_VALUE` if this information is not available
11 | */
12 | int available() ;
13 |
14 |
15 | /** returns true if more bytes are available for read
16 | *
17 | * TODO throws exception if output has no EOF info?
18 | */
19 | boolean availableMore()throws IOException;
20 |
21 |
22 | int readPackedInt() ;
23 |
24 | long readPackedLong() ;
25 |
26 | default long readPackedRecid(){
27 | //TODO bit parity for recids
28 | return readPackedLong();
29 | }
30 |
31 | default long readRecid(){
32 | //TODO bit parity for recids
33 | return readLong();
34 | }
35 |
36 | long readLong();
37 |
38 | default float readFloat() {
39 | return java.lang.Float.intBitsToFloat(readInt());
40 | }
41 |
42 | int readInt();
43 |
44 | default double readDouble() {
45 | return java.lang.Double.longBitsToDouble(readLong());
46 | }
47 |
48 | default String readLine() {
49 | return readUTF();
50 | }
51 |
52 | default String readUTF() {
53 | //TODO is it better then DataOutputStream.readUTF?
54 | int len = readPackedInt();
55 | char[] b = new char[len];
56 | for (int i=0;i0;
102 | }
103 |
104 | @Override
105 | public int readPackedInt() {
106 | return readInt();
107 | }
108 |
109 | @Override
110 | public long readPackedLong() {
111 | return readLong();
112 | }
113 |
114 |
115 | @Override
116 | public void unpackLongSkip(int count) {
117 | byte[] b = buf;
118 | int pos2 = this.pos;
119 | while(count>0){
120 | // count -= (b[pos2++]&0x80)>>7;
121 | //TODO go back to packed longs, remove code bellow
122 | readLong();
123 | count--;
124 | pos2+=8;
125 | }
126 | this.pos = pos2;
127 | }
128 |
129 | }
130 |
131 |
--------------------------------------------------------------------------------
/src/main/java/org/mapdb/io/DataInput2ByteBuffer.java:
--------------------------------------------------------------------------------
1 | package org.mapdb.io;
2 |
3 | import java.nio.ByteBuffer;
4 |
5 | /** DataInput on top of {@link ByteBuffer} */
6 | public final class DataInput2ByteBuffer implements DataInput2 {
7 |
8 | protected final ByteBuffer buf;
9 |
10 | public DataInput2ByteBuffer(ByteBuffer buf) {
11 | this.buf = buf;
12 | }
13 |
14 | public void readFully(byte[] b, int off, int len) {
15 | buf.get(b, off,len);
16 | }
17 |
18 | @Override
19 | public int skipBytes(final int n) {
20 | buf.position(buf.position()+n);
21 | return n;
22 | }
23 |
24 | @Override
25 | public boolean readBoolean() {
26 | return buf.get() == 1;
27 | }
28 |
29 | @Override
30 | public byte readByte() {
31 | return buf.get();
32 | }
33 |
34 | @Override
35 | public int readUnsignedByte() {
36 | return buf.get() & 0xff;
37 | }
38 |
39 | @Override
40 | public short readShort() {
41 | return buf.getShort();
42 | }
43 |
44 | @Override
45 | public char readChar() {
46 | return buf.getChar();
47 | }
48 |
49 | @Override
50 | public int readInt() {
51 | return buf.getInt();
52 | }
53 |
54 | @Override
55 | public long readLong() {
56 | return buf.getLong();
57 | }
58 |
59 |
60 | @Override
61 | public int available() {
62 | return buf.remaining();
63 | }
64 |
65 | @Override
66 | public boolean availableMore() {
67 | return available()>0;
68 | }
69 |
70 | @Override
71 | public int readPackedInt() {
72 | return readInt();
73 | }
74 |
75 | @Override
76 | public long readPackedLong() {
77 | return readLong();
78 | }
79 |
80 |
81 | @Override
82 | public void unpackLongSkip(int count) {
83 | while(count>0){
84 | //TODO go back to packed longs, remove code bellow
85 | readLong();
86 | count--;
87 | }
88 | }
89 |
90 | }
91 |
92 |
--------------------------------------------------------------------------------
/src/main/java/org/mapdb/io/DataInputToStream.java:
--------------------------------------------------------------------------------
1 | package org.mapdb.io;
2 |
3 | import java.io.Closeable;
4 | import java.io.DataInput;
5 | import java.io.IOException;
6 | import java.io.InputStream;
7 |
8 | /**
9 | * Wraps {@code DataInput} into {@code InputStream}
10 | */
11 | public final class DataInputToStream extends InputStream {
12 |
13 | protected final DataInput2 in;
14 |
15 | public DataInputToStream(DataInput2 in) {
16 | this.in = in;
17 | }
18 |
19 | @Override
20 | public int read(byte[] b, int off, int len) throws IOException {
21 | in.readFully(b,off,len);
22 | return len;
23 | }
24 |
25 | @Override
26 | public long skip(long n) throws IOException {
27 | n = Math.min(n, Integer.MAX_VALUE);
28 | //$DELAY$
29 | return in.skipBytes((int) n);
30 | }
31 |
32 | @Override
33 | public void close() throws IOException {
34 | if(in instanceof Closeable)
35 | ((Closeable) in).close();
36 | }
37 |
38 | @Override
39 | public int read() throws IOException {
40 | return in.readUnsignedByte();
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/main/java/org/mapdb/io/DataOutput2.java:
--------------------------------------------------------------------------------
1 | package org.mapdb.io;
2 |
3 | import java.io.DataOutput;
4 | import java.io.IOException;
5 |
6 |
7 | public interface DataOutput2{
8 |
9 | /**
10 | * Give a hint to DataOutput about total size of serialized data.
11 | * This may prevent `byte[]` resize. And huge records might be placed into temporary file
12 | */
13 | void sizeHint(int size);
14 |
15 | /** write int in packed form */
16 | void writePackedInt(int value);
17 |
18 | /** write long in packed form */
19 | void writePackedLong(long value);
20 |
21 | /** write recid, recids have extra parity bit to detect data corruption */
22 | void writeRecid(long recid);
23 |
24 | /** write recid in packed form, recids have extra parity bit to detect data corruption */
25 | void writePackedRecid(long recid);
26 |
27 | /** copy content of this DataOutput2 into `ByteArray` */
28 | byte[] copyBytes();
29 |
30 |
31 | void writeBoolean(boolean v);
32 |
33 | void writeByte(int v);
34 |
35 | void writeShort(int v);
36 |
37 | void writeChar(int v);
38 |
39 | void writeInt(int v);
40 |
41 | void writeLong(long v);
42 |
43 | void writeFloat(float v);
44 |
45 | void writeDouble(double v);
46 |
47 | void writeBytes(String s);
48 |
49 | void writeChars(String s);
50 |
51 | void writeUTF(String s);
52 |
53 | @Deprecated //TODO temp method for compatibility
54 | default void packInt(int i){
55 | writePackedInt(i);
56 | }
57 |
58 | void write(int bytee); //TODO remove this method? compatibility with java.io.DataOutput
59 |
60 | void write(byte[] buf);
61 | void write(byte b[], int off, int len);
62 | }
63 |
--------------------------------------------------------------------------------
/src/main/java/org/mapdb/list/KernelList.java:
--------------------------------------------------------------------------------
1 | package org.mapdb.list;
2 |
3 | import org.mapdb.ser.Serializer;
4 | import org.mapdb.ser.Serializers;
5 | import org.mapdb.store.Store;
6 |
7 | import java.util.*;
8 |
9 | public class KernelList
10 | extends AbstractList
11 | implements List, RandomAccess {
12 |
13 | private static final Serializer KERNEL_SER = Serializers.LONG_ARRAY;
14 |
15 | private final Store kernelStore;
16 | private final Store entryStore;
17 | private final long recid;
18 | private final Serializer ser;
19 |
20 | public KernelList(Store kernelStore, Store entryStore, long recid, Serializer ser) {
21 | this.kernelStore = kernelStore;
22 | this.entryStore = entryStore;
23 | this.recid = recid;
24 | this.ser = ser;
25 | }
26 |
27 |
28 | public static class Maker {
29 | private final Store store;
30 |
31 | private Store entryStore = null;
32 | private final Serializer ser;
33 | private final long recid;
34 |
35 | public Maker(Store store, long recid, Serializer ser) {
36 | this.store = store;
37 | this.entryStore = store;
38 | this.recid = recid;
39 | this.ser = ser;
40 | }
41 |
42 | public static KernelList.Maker newList(Store store, Serializer ser) {
43 | long recid = store.put(new long[]{}, KERNEL_SER);
44 | return new KernelList.Maker(store, recid, ser);
45 | }
46 |
47 | public Maker entryStore(Store store){
48 | this.entryStore = store;
49 | return this;
50 | }
51 |
52 | public KernelList make(){
53 | return new KernelList(store, entryStore, recid, ser);
54 | }
55 | }
56 |
57 |
58 | @Override
59 | public E get(int index) {
60 | long entryRecid = getKernel()[index];
61 | return entryStore.get(entryRecid, ser);
62 | }
63 |
64 | @Override
65 | public int size() {
66 | return getKernel().length;
67 | }
68 |
69 | @Override
70 | public boolean add(E e) {
71 | long[] kernel = getKernel();
72 | kernel = Arrays.copyOf(kernel, kernel.length+1);
73 | long newRecid = entryStore.put(e, ser);
74 | kernel[kernel.length-1] = newRecid;
75 | storeKernel(kernel);
76 | return true;
77 | }
78 |
79 | @Override
80 | public void add(int index, E e) {
81 | long[] kernel = getKernel();
82 | if(index<0 || index>kernel.length)
83 | throw new IndexOutOfBoundsException();
84 |
85 | long[] kernel2 = Arrays.copyOf(kernel, kernel.length+1);
86 | System.arraycopy(kernel, index, kernel2, index+1, kernel.length-index);
87 |
88 | long newRecid = entryStore.put(e, ser);
89 | kernel2[index] = newRecid;
90 | storeKernel(kernel2);
91 | }
92 |
93 | @Override
94 | public boolean addAll(Collection extends E> c) {
95 | long[] kernel = getKernel();
96 | int pos = kernel.length;
97 | kernel = Arrays.copyOf(kernel, kernel.length+c.size());
98 | for(E e:c){
99 | long newRecid = entryStore.put(e, ser);
100 | kernel[pos++] = newRecid;
101 | }
102 | if(pos!=kernel.length)
103 | throw new ConcurrentModificationException();
104 | storeKernel(kernel);
105 | return true;
106 | }
107 |
108 | @Override
109 | public boolean addAll(int index, Collection extends E> c) {
110 | long[] kernel = getKernel();
111 | if(index<0 || index>kernel.length)
112 | throw new IndexOutOfBoundsException();
113 | int csize = c.size();
114 | long[] kernel2 = Arrays.copyOf(kernel, kernel.length+csize);
115 | System.arraycopy(kernel, index, kernel2, index+csize, kernel.length-index);
116 | kernel=null; //release memory for GC
117 | int pos = index;
118 | for(E e:c){
119 | long newRecid = entryStore.put(e, ser);
120 | kernel2[pos++] = newRecid;
121 | }
122 | if(pos!=csize+index)
123 | throw new ConcurrentModificationException();
124 | storeKernel(kernel2);
125 | return true;
126 | }
127 |
128 | @Override
129 | public E remove(int index) {
130 | long[] kernel = getKernel();
131 | long eRecid = kernel[index];
132 | E ret = entryStore.getAndDelete(eRecid, ser);
133 | long[] kernel2 = Arrays.copyOf(kernel, kernel.length-1);
134 | System.arraycopy(kernel, index+1, kernel2, index, kernel2.length-index);
135 | storeKernel(kernel2);
136 | return ret;
137 | }
138 |
139 | @Override
140 | public E set(int index, E element) {
141 | long[] kernel = getKernel();
142 | return entryStore.getAndUpdate(kernel[index], ser, element);
143 | }
144 |
145 | protected void storeKernel(long[] kernel) {
146 | for(long recid:kernel) {
147 | if (recid <= 0)
148 | throw new ConcurrentModificationException();
149 | }
150 | kernelStore.update(recid, KERNEL_SER, kernel);
151 | }
152 |
153 | protected long[] getKernel(){
154 | return kernelStore.get(recid, KERNEL_SER);
155 | }
156 |
157 | }
158 |
--------------------------------------------------------------------------------
/src/main/java/org/mapdb/list/MonolithList.java:
--------------------------------------------------------------------------------
1 | package org.mapdb.list;
2 |
3 | import org.mapdb.ser.ArrayListSerializer;
4 | import org.mapdb.ser.Serializer;
5 | import org.mapdb.store.Store;
6 |
7 | import java.util.*;
8 |
9 | public class MonolithList
10 | extends AbstractList
11 | implements List, RandomAccess {
12 |
13 | public static class Maker {
14 | private final Store store;
15 | private final Serializer ser;
16 | private final long recid;
17 |
18 | public Maker(Store store, long recid, Serializer ser) {
19 | this.store = store;
20 | this.recid = recid;
21 | this.ser = ser;
22 | }
23 |
24 | public static Maker newList(Store store, Serializer ser) {
25 | long recid = store.put(new ArrayList(), new ArrayListSerializer(ser));
26 | return new Maker(store, recid, ser);
27 | }
28 |
29 | public MonolithList make(){
30 | return new MonolithList(store, recid, ser);
31 | }
32 | }
33 |
34 |
35 | private final Store store;
36 | private final long recid;
37 | private final Serializer ser;
38 | private final Serializer> listSer;
39 |
40 | public MonolithList(Store store, long recid, Serializer ser) {
41 | this.store = store;
42 | this.recid = recid;
43 | this.ser = ser;
44 | this.listSer = new ArrayListSerializer(ser);
45 | }
46 |
47 |
48 | @Override
49 | public E get(int index) {
50 | ArrayList list = store.get(recid, listSer);
51 | return list.get(index);
52 | }
53 |
54 | @Override
55 | public int size() {
56 | ArrayList list = store.get(recid, listSer);
57 | return list.size();
58 | }
59 |
60 | @Override
61 | public boolean add(E e) {
62 | ArrayList list = getClone();
63 | list.add(e);
64 | store(list);
65 | return true;
66 | }
67 |
68 | @Override
69 | public E set(int index, E element) {
70 | ArrayList list = getClone();
71 | E e=list.set(index,element);
72 | store(list);
73 | return e;
74 | }
75 |
76 | @Override
77 | public void add(int index, E element) {
78 | ArrayList list = getClone();
79 | list.add(index,element);
80 | store(list);
81 | }
82 |
83 | @Override
84 | public boolean addAll(int index, Collection extends E> c) {
85 | ArrayList list = getClone();
86 | list.addAll(index, c);
87 | store(list);
88 | return true;
89 | }
90 |
91 | @Override
92 | public boolean addAll(Collection extends E> c) {
93 | ArrayList list = getClone();
94 | list.addAll(c);
95 | store(list);
96 | return true;
97 | }
98 |
99 | @Override
100 | public E remove(int index) {
101 | ArrayList list = getClone();
102 | E e=list.remove(index);
103 | store(list);
104 | return e;
105 | }
106 |
107 | protected ArrayList getClone() {
108 | return (ArrayList) store.get(recid, listSer).clone();
109 | }
110 |
111 | protected void store(ArrayList list) {
112 | store.update(recid, listSer, list);
113 | }
114 |
115 | }
116 |
--------------------------------------------------------------------------------
/src/main/java/org/mapdb/ser/ArrayDeltaSerializer.java:
--------------------------------------------------------------------------------
1 | package org.mapdb.ser;
2 |
3 | import org.mapdb.io.DataInput2;
4 | import org.mapdb.io.DataOutput2;
5 |
6 | import java.io.IOException;
7 |
8 | /**
9 | * Created by jan on 2/28/16.
10 | */
11 | public class ArrayDeltaSerializer extends ArraySerializer {
12 |
13 | private static final long serialVersionUID = -930920902390439234L;
14 |
15 |
16 | public ArrayDeltaSerializer(Serializer serializer) {
17 | super(serializer);
18 | }
19 |
20 | @Override
21 | public void valueArraySerialize(DataOutput2 out, Object[] vals2) {
22 | Object[] vals = (Object[]) vals2;
23 | if (vals.length == 0)
24 | return;
25 | //write first array
26 | Object[] prevKey = (Object[]) vals[0];
27 | out.packInt(prevKey.length);
28 | for (Object key : prevKey) {
29 | serializer.serialize(out, (T) key);
30 | }
31 |
32 | //write remaining arrays
33 | for (int i = 1; i < vals.length; i++) {
34 | Object[] key = (Object[]) vals[i];
35 | //calculate number of entries equal with prevKey
36 | int len = Math.min(key.length, prevKey.length);
37 | int pos = 0;
38 | while (pos < len && (key[pos] == prevKey[pos] || serializer.equals((T) key[pos], (T) prevKey[pos]))) {
39 | pos++;
40 | }
41 | out.packInt(pos);
42 | //write remaining bytes
43 | out.packInt(key.length - pos);
44 | for (; pos < key.length; pos++) {
45 | serializer.serialize(out, (T) key[pos]);
46 | }
47 | prevKey = key;
48 | }
49 |
50 | }
51 |
52 | @Override
53 | public Object[] valueArrayDeserialize(DataInput2 in, final int size) {
54 | Object[] ret = new Object[size];
55 | if (size == 0)
56 | return ret;
57 | int ss = in.unpackInt();
58 | Object[] prevKey = new Object[ss];
59 | for (int i = 0; i < ss; i++) {
60 | prevKey[i] = serializer.deserialize(in, -1);
61 | }
62 | ret[0] = prevKey;
63 | for (int i = 1; i < size; i++) {
64 | //number of items shared with prev
65 | int shared = in.unpackInt();
66 | //number of items unique to this array
67 | int unq = in.unpackInt();
68 | Object[] key = new Object[shared + unq];
69 | //copy items from prev array
70 | System.arraycopy(prevKey, 0, key, 0, shared);
71 | //and read rest
72 | for (; shared < key.length; shared++) {
73 | key[shared] = serializer.deserialize(in, -1);
74 | }
75 | ret[i] = key;
76 | prevKey = key;
77 | }
78 | return ret;
79 | }
80 |
81 | }
82 |
--------------------------------------------------------------------------------
/src/main/java/org/mapdb/ser/ArrayListSerializer.java:
--------------------------------------------------------------------------------
1 | package org.mapdb.ser;
2 |
3 | import org.jetbrains.annotations.NotNull;
4 | import org.jetbrains.annotations.Nullable;
5 | import org.mapdb.io.DataInput2;
6 | import org.mapdb.io.DataOutput2;
7 |
8 | import java.util.ArrayList;
9 |
10 | public class ArrayListSerializer implements Serializer> {
11 |
12 | protected final Serializer ser;
13 |
14 | public ArrayListSerializer(Serializer ser) {
15 | this.ser = ser;
16 | }
17 |
18 | @Override
19 | public void serialize(@NotNull DataOutput2 out, @NotNull ArrayList list) {
20 | out.writePackedInt(list.size());
21 | for(E e:list){
22 | ser.serialize(out,e);
23 | }
24 | }
25 |
26 | @Override
27 | public ArrayList deserialize(@NotNull DataInput2 input) {
28 | final int size = input.readPackedInt();
29 | ArrayList list = new ArrayList<>(size);
30 | for(int i=0;i extends DefaultGroupSerializer {
22 |
23 | private static final long serialVersionUID = -982394293898234253L;
24 | protected final Serializer serializer;
25 | protected final Class componentType;
26 |
27 |
28 | /**
29 | * Wraps given serializer and produces Object[] serializer.
30 | * To produce array with different component type, specify extra class.
31 | */
32 | public ArraySerializer(Serializer serializer) {
33 | this(serializer, null);
34 | }
35 |
36 |
37 | /**
38 | * Wraps given serializer and produces array serializer.
39 | *
40 | * @param serializer
41 | * @param componentType type of array which will be created on deserialization
42 | */
43 | public ArraySerializer(Serializer serializer, Class componentType) {
44 | if (serializer == null)
45 | throw new NullPointerException("null serializer");
46 | this.serializer = serializer;
47 | this.componentType = componentType!=null
48 | ? componentType
49 | : (Class)Object.class;
50 | }
51 |
52 | // /** used for deserialization */
53 | // @SuppressWarnings("unchecked")
54 | // protected Array(SerializerBase serializerBase, DataInput2 is, SerializerBase.FastArrayList