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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • java导出pdf模板_java模板导出PDF[通俗易懂]

    java导出pdf模板_java模板导出PDF[通俗易懂]本次完善综合特点:一对一,点对点的给对应的地方写值,比如模板里面放了个name标识,在程序里把“张三”赋给name,那么输出的pdf里面name的地方就变成了张三,准确方便快捷支持中文,可以使用自己下载的字体。支持图片:图片的大小范围可以在模板随意调,生成出来的图片不会超过范围。而且不需要根据坐标去算,程序里面自动计算的。支持多页模板,即使是好几页的模板,只要每个变量对应的范围确定好了,生成出来的…

    2022年5月10日
    42
  • navicat premium 15激活码最新[在线序列号]

    navicat premium 15激活码最新[在线序列号],https://javaforall.net/100143.html。详细ieda激活码不妨到全栈程序员必看教程网一起来了解一下吧!

    2022年3月20日
    304
  • vscode配置java环境变量_配置jre环境变量

    vscode配置java环境变量_配置jre环境变量用VsCode开发Java

    2022年10月4日
    2
  • eclipse环境的搭建以及JDK的安装步骤详细[通俗易懂]

    java学习之旅java开发环境:eclipse可以从这里下载链接:https://pan.baidu.com/s/1yPTV4UrAyWnc12NbAIj-MA密码:bnma安装步骤如下:从上链接获取压缩包下载到电脑之后,解压,此时的eclipse是打不开的,需要安装JDK和JRE,jdk的详细安装步骤在下面出现以下情况都是因为还没有安装JDK的原因:…

    2022年4月8日
    43
  • 安卓数据转移到iphone老是中断_关于iPhone手机之间数据转移的几种方式[通俗易懂]

    安卓数据转移到iphone老是中断_关于iPhone手机之间数据转移的几种方式[通俗易懂]最近肯定有很多小伙伴已经买了iPhone11的新机,或者有些打算换一台新iPhone。拿到新机之后转移数据可是一件麻烦的事。关于iPhone手机之间的数据转移有哪几种呢?今天码哥就来跟大家科普一。其实,除了通过iTunes或者iClouds之外,苹果后来又增加了两种方式:1.通过无线局域网把数据从旧iPhone传输到新iPhone手机。2.通过LightingtoLifhtin…

    2022年9月18日
    4
  • proxmox物理机迁移_迁移到物理服务器

    proxmox物理机迁移_迁移到物理服务器这两天由于源代码管理服务器的当机,准备将源服务器配置数据库迁移至新服务器。下面是TFS2010物理迁移的一些心得:1、尽可能将新服务器的计算机名称和源服务器相同。2、配置完成后,删除配置数据库,并附加同名的源数据库是无法成功使用。在访问tfs的web站点时出错。3、附加源配置数据后,需要通过命令重新配置才可以确保使用:TFSconfigregisterDB/sqlInstanc…

    2025年11月22日
    1

发表回复

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

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