comparable java_java rectangle

comparable java_java rectangle在JAVA中使用eXtremeDBautoid,主要有以下几个问题:定义插入数据已经获取记录,如何获得autoid知道autoid,如何获取记录定义autoid在类的定义前加入注释:@Persistent(autoid=true)注意,eXtremeDB中的autoid并不需要单独的定义出一列表示,只需要在类级别定义即可。插入数据正常的使用insert方法插入即可,无需关注autoid。如果需要…

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE稳定放心使用

在JAVA中使用eXtremeDB autoid,主要有以下几个问题:

定义

插入数据

已经获取记录,如何获得autoid

知道autoid,如何获取记录

定义autoid

在类的定义前加入注释:@Persistent(autoid=true)注意,eXtremeDB中的autoid并不需要单独的定义出一列表示,只需要在类级别定义即可。

插入数据

正常的使用insert方法插入即可,无需关注autoid。如果需要知道系统为记录生成的autoid值,可以通过insert方法的返回值。

通过记录获得autoid

可以先通过Cursor类的find方法,先把游标定位到指定记录,然后通过Cursor类的getAutoId()方法获取。

通过autoid获取记录

创建一个不指定索引名的Cursor,直接把autoid传递到find方法即可

Cursor cp = new Cursor(con, Person.class);

Person p3 = cp.find(prh2.personID);完整的样例程序如下

import com.mcobject.extremedb.Connection;

import com.mcobject.extremedb.Cursor;

import com.mcobject.extremedb.Database;

import com.mcobject.extremedb.Indexable;

import com.mcobject.extremedb.Persistent;

@Persistent(autoid=true) // class will be stored in eXtremeDB database, declare autoid indexes

class Person {

Person(String name) {

this.name = name;

}

@Indexable(unique=true, type=Database.IndexType.Hashtable)

String name;

}

@Persistent(autoid=true) // class will be stored in eXtremeDB database, declare autoid indexes

class House {

House(String address) {

this.address = address;

}

@Indexable(unique=true, type=Database.IndexType.Hashtable)

String address;

}

@Persistent(autoid=true)

class Person_R_House {

Person_R_House(long personID, long houseID) {

this.personID = personID;

this.houseID = houseID;

}

@Indexable(unique=false, type=Database.IndexType.Hashtable)

long personID;

@Indexable(unique=false, type=Database.IndexType.Hashtable)

long houseID;

}

public class TestAutoId {

static final int PAGE_SIZE = 128;

static final int DISK_PAGE_SIZE = 4096;

static final int DISK_CACHE_SIZE = 4*1024*1024;

static final int DATABASE_SIZE = 16*1024*1024;

static final int N_PERSON = 5;

static final int N_HOUSE = 5;

public static void main(String[] args) {

Database db = new Database();

Database.Parameters params = new Database.Parameters();

params.memPageSize = PAGE_SIZE;

params.classes = new Class[]{Person.class, House.class, Person_R_House.class};

db.open(“testAutoIDdb”, params, DATABASE_SIZE);

Connection con = new Connection(db);

//

// Insert data in the database

//

con.startTransaction(Database.TransactionType.ReadWrite);

for (int i = 1; i &lt= N_PERSON; i++) {

con.insert( new Person(“Person-” + i));

con.insert( new House(“House-” + i));

}

con.commitTransaction();

//

// associate existing Person and existing House

//

con.startTransaction(Database.TransactionType.ReadWrite);

Cursor cursorP = new Cursor(con, Person.class, “name”);

Cursor cursorH = new Cursor(con, House.class, “address”);

Person p1 = cursorP.find(“Person-1”);

House h1 = cursorH.find(“House-2”);

if( p1 != null && h1 != null) {

Person_R_House prh = new Person_R_House(cursorP.getAutoId(),cursorH.getAutoId());

con.insert(prh);

}

cursorP.close();

cursorH.close();

con.commitTransaction();

//

// associate new Person and new House

//

con.startTransaction(Database.TransactionType.ReadWrite);

Person p2 = new Person(“Person-new”);

House h2 = new House(“House-new”);

long pID = con.insert(p2);//because the class was annotated with (autoid=true),

//the insert method returns the generated AUTOID of the newly create object

long hID = con.insert(h2);

Person_R_House prh = new Person_R_House(pID,hID);

con.insert(prh);

con.commitTransaction();

//

// show the relationship between Person and House

//

con.startTransaction(Database.TransactionType.ReadOnly);

Cursor cursorPRH = new Cursor(con, Person_R_House.class);

for(Person_R_House prh2 : cursorPRH) {

Cursor cp = new Cursor(con, Person.class);

Cursor ch = new Cursor(con, House.class);

Person p3 = cp.find(prh2.personID);

House h3 = ch.find(prh2.houseID);

System.out.format(“%s has a house, address is:%s \n”, p3.name, h3.address);

cp.close();

ch.close();

}

cursorPRH.close();

con.commitTransaction();

con.disconnect();

db.close();

}

}

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

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/182219.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 使用javascript实现对于chineseocr的API调用「建议收藏」

    ChineseOCR在线API网页地址界面提供多种接口调用方式,比如在线调用、Javascriptapi调用、curlapi调用和pythonapi调用四种方式,本次使用javascriptapi调用的方式进行OCR识别在线Javascript工具在线工具网页链接在线Base64转化工具在线工具网页链接代码修改新增一个变量fill_with_base64_image接收图片的base64编码的字符串 将input内的<fill_with_base6.

    2022年4月6日
    33
  • ubuntu12.04 安装 opencv 2.4.8(非源代码编译)

    ubuntu12.04 安装 opencv 2.4.8(非源代码编译)

    2022年1月24日
    34
  • 什么是SOAP,有哪些应用

    什么是SOAP,有哪些应用SOAP是一种轻量级协议,用于在分散型、分布式环境中交换结构化信息。SOAP利用XML技术定义一种可扩展的消息处理框架,它提供了一种可通过多种底层协议进行交换的消息结构。这种框架的设计思想是要独立于任何一种特定的编程模型和其他特定实现的语义。SOAP规范还定义了HTTP消息是怎样传输SOAP消息的。MSMQ、SMTP、TCP/IP都可以做SOAP的传输协议。转载于:ht…

    2022年7月24日
    4
  • 字节转MB与Mb转字节[通俗易懂]

    字节转MB与Mb转字节[通俗易懂]/***字节转成MB*/privateBigDecimalfileSizeConversion(LongfileSize){DecimalFormatdf=newDecimalF

    2022年8月6日
    1
  • 嵌入式系统中启动Hostapd

    嵌入式系统中启动Hostapd项目过程中需要添加AP热点的需求,自然会想用到hostapd,具体的不做分析,自行百度,这里主要分析下启动脚本采用的WiFi模组是“博通”公司的AP6255芯片,“博通”公司的wifi芯片AP与STATION切换需要对网卡驱动进行卸载重装,所以配网方式不建议使用AP模式配网,这会造成多次WiFi模式的切换,耗时可能比较严重。不过给出以下方法,开发者可以自行配置,进入…

    2022年5月11日
    39
  • 字节数组转字符串(Java)

    字节数组转字符串(Java)字节数组转字符串(Java)我们在开发中经常会遇到将字节数组转换成字符串的情况,这里提供一个简单的方法即可实现。使用String构造方法转换:Stringres=newString(bytes,”UTF-8″)注意:第二个参数代表了字符的格式,因为字节流本身是无格式的,但转换成字符后,字符是有各种格式的,比如这里的字符格式是”UTF-8”,如果使用了错误的字符格式,转换后的字符串就会是乱码。…

    2022年10月26日
    0

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号