Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
<source>${java.version}</source>
<target>${java.version}</target>
<encoding>${project.build.sourceEncoding}</encoding>
<proc>full</proc>
<maxmem>512M</maxmem>
</configuration>
</plugin>
Expand Down Expand Up @@ -168,7 +169,9 @@
<configuration>

<forkMode>once</forkMode>
<argLine>${argLine} -Xmx1024m -Dfile.encoding=UTF-8</argLine>
<!-- Temporary JE databases run inside the test JVM; the
host's free space must not gate isolated tests. -->
<argLine>${argLine} -Xmx1024m -Dfile.encoding=UTF-8 -Dje.freeDisk=0</argLine>
<additionalClasspathElements>
<additionalClasspathElement>${basedir}/target/test-classes</additionalClasspathElement>
</additionalClasspathElements>
Expand Down Expand Up @@ -633,4 +636,4 @@
</dependencyManagement>


<distributionManagement><repository><id>2624322-release-6F6h6R</id><name>Maven Release Repository</name><url>https://packages.aliyun.com/6927b116e6c3e0425dbdf60d/maven/2624322-release-6f6h6r</url><releases><enabled>true</enabled></releases><snapshots><enabled>false</enabled></snapshots></repository><snapshotRepository><id>2624322-snapshot-3EoOv3</id><name>Maven Snapshot Repository</name><url>https://packages.aliyun.com/6927b116e6c3e0425dbdf60d/maven/2624322-snapshot-3eoov3</url><releases><enabled>false</enabled></releases><snapshots><enabled>true</enabled></snapshots><uniqueVersion>true</uniqueVersion></snapshotRepository></distributionManagement></project>
<distributionManagement><repository><id>2624322-release-6F6h6R</id><name>Maven Release Repository</name><url>https://packages.aliyun.com/6927b116e6c3e0425dbdf60d/maven/2624322-release-6f6h6r</url><releases><enabled>true</enabled></releases><snapshots><enabled>false</enabled></snapshots></repository><snapshotRepository><id>2624322-snapshot-3EoOv3</id><name>Maven Snapshot Repository</name><url>https://packages.aliyun.com/6927b116e6c3e0425dbdf60d/maven/2624322-snapshot-3eoov3</url><releases><enabled>false</enabled></releases><snapshots><enabled>true</enabled></snapshots><uniqueVersion>true</uniqueVersion></snapshotRepository></distributionManagement></project>
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public Database catalogDatabase(Environment myDbEnvironment){

System.out.println(catalogDatabase.getDatabaseName());

this.catalogDatabase = catalogDatabase;
return catalogDatabase;

}
Expand Down Expand Up @@ -126,6 +127,7 @@ public Database berkeleyDatabase(Environment myDbEnvironment){

System.out.println(myDatabase.getDatabaseName());

this.myDatabase = myDatabase;
return myDatabase;

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,12 @@ public void otherMethod(){
List<String> list = myDbEnvironment.getDatabaseNames();//取得当前环境下数据库名称列表
System.out.println(list);

env.renameDatabase(null, databaseName, "newName");//给数据库改名
env.removeDatabase(null, databaseName);//删除当前环境数据库

long deleteNum = env.truncateDatabase(null, databaseName, true);//清空数据库中所有记录,并返回数量
// JE cannot truncate a database while its handle is open. Keep the
// template usable by reopening the same database after truncation.
com.sleepycat.je.DatabaseConfig config = myDatabase.getConfig();
myDatabase.close();
long deleteNum = env.truncateDatabase(null, databaseName, true);
myDatabase = env.openDatabase(null, databaseName, config);
System.out.println(deleteNum);


Expand Down
8 changes: 5 additions & 3 deletions src/main/java/com/sleepycat/berkeley/spring/boot/Cursor.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ public void getAllByCursor() throws UnsupportedEncodingException{
}

//向前遍历
while(myCursor.getPrev(databaseKey, databaseValue, LockMode.DEFAULT) == OperationStatus.SUCCESS){
myCursor.getFirst(databaseKey, databaseValue, LockMode.DEFAULT);
while(myCursor.getNext(databaseKey, databaseValue, LockMode.DEFAULT) == OperationStatus.SUCCESS){
String theKey = new String(databaseKey.getData(), "UTF-8");
String theData = new String(databaseValue.getData(), "UTF-8");
System.out.println("Key: " + theKey + "Data: " + theData);
Expand Down Expand Up @@ -92,7 +93,7 @@ public void searchMultipleByCursor(String key) throws UnsupportedEncodingExcepti
DatabaseEntry databaseValue = new DatabaseEntry();

OperationStatus res = myCursor.getSearchKey(databaseKey, databaseValue, LockMode.DEFAULT);
if(myCursor.count() > 1){
if(res == OperationStatus.SUCCESS){
while(res == OperationStatus.SUCCESS){
String foundKey = new String(databaseKey.getData(), "utf8");
String foundValue = new String(databaseValue.getData(), "utf8");
Expand Down Expand Up @@ -157,6 +158,7 @@ public void closeDatabase(){

public static void main(String[] args) throws UnsupportedEncodingException{
Cursor cursor = new Cursor();
if (args.length > 0) cursor.envDir = args[0];
cursor.configEnvironment();
cursor.createDatabase();
cursor.addDataByCursor("a", "www.baidu.com");
Expand All @@ -167,4 +169,4 @@ public static void main(String[] args) throws UnsupportedEncodingException{
cursor.closeDatabase();
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.sleepycat.berkeley.spring.boot;

import com.sleepycat.berkeley.spring.boot.hooks.BerkeleyShutdownHook;
import com.sleepycat.bind.serial.StoredClassCatalog;
import com.sleepycat.je.Database;
import com.sleepycat.je.Environment;
import com.sleepycat.je.EnvironmentConfig;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.core.io.DefaultResourceLoader;

import java.nio.file.Path;

import static org.junit.jupiter.api.Assertions.*;

class BerkeleyConfigurationTest {
@TempDir Path home;

@Test
void configuresEnvironmentAndOpensCatalogAndDatabase() {
BerkeleyProperties properties = new BerkeleyProperties();
properties.setAllowCreate(true);
properties.setTransactional(true);
properties.setCatalogDatabaseName("catalog");
properties.setDatabaseName("items");
BerkeleyAutoConfiguration configuration = new BerkeleyAutoConfiguration();
ReflectionTestUtils.setField(configuration, "properties", properties);
DefaultResourceLoader resourceLoader = new DefaultResourceLoader();
configuration.setResourceLoader(resourceLoader);
assertSame(resourceLoader, ReflectionTestUtils.getField(configuration, "resourceLoader"));
EnvironmentConfig settings = configuration.configEnvironment();
assertTrue(settings.getAllowCreate());
assertTrue(settings.getTransactional());
assertFalse(settings.getReadOnly());
assertNotNull(configuration.repConfigProxy());

Environment environment = new Environment(home.toFile(), settings);
Database catalogDatabase = configuration.catalogDatabase(environment);
StoredClassCatalog catalog = configuration.catalog();
Database database = configuration.berkeleyDatabase(environment);
assertEquals("catalog", catalogDatabase.getDatabaseName());
assertEquals("items", database.getDatabaseName());
new BerkeleyShutdownHook(database, catalog, environment).run();
}
}
Loading
Loading