简体   繁体   English

如何使用Java中的SQL对来自对象的元模型的查询进行编码

[英]How to code query from SQL in Java for object oriented metamodel

I'm trying to learn how to create an object oriented model database using a tool called: Eyedb (on linux). 我正在尝试学习如何使用一个名为Eyedb(在Linux上)的工具来创建面向对象的模型数据库。 I've made some classes and records generators for this database but I don't know how to code queries for it using Java. 我为此数据库做了一些类和记录生成器,但是我不知道如何使用Java编写查询代码。

The structure of the database looks like this: 数据库的结构如下所示:

    class Lecturer {

        attribute string<32> name;
        attribute strin<32> surname;
        relationship set <Lecture*> lectures inverse Lecture::Lecturer;
};

class Item{
        attribute string<32> name;
        attribute string<512> description;
};

class Topic extends Item {
        relationship set<Lecture*> tlecture inverse Lecture::Topic;
};


class Lecture {
        relationship Lecturer *llecturer inverse Lecturer::lectures;
        relationship Topic *ltopic inverse Topic::tlecture;
        relationship set <Content*> lcontent inverse Content::Lecture;
        relationship set <Equipment*> lequipment inverse Content::Lecture;
        relationship Room_timeslot* lroom_timeslot inverse Room_timeslot::rlecture;                                                     
};

class Content extends Item {

        attribute int level;
        relationship set <Content*> subcontent inverse Content::supcontent; 
        relationship set <Content*> supcontent inverse  Content::subcontent;    
        relationship set <Teachingmaterial*> cteachingmaterial inverse Teachingmaterial::Content;
};

class Teachingmaterial extends Item {

        attribute string link;
        relationship set <Content*> tcontent inverse Content::Teachingmaterial;
};

class Equipment extends Item {
        attribute int quantity;
        attribute string symbol;
        relationship set<Lecture*> electure inverse Lecture::Equipment;
        relationship Room *eroom inverse Room::requipment;

};

class Room {
        relationship set <Equipment*> requipment inverse Equipment::Room
        attribute string name;
        attribute int number;
        attribute string symbol;
        attribute string building;
        attribute int floor;
        attribute string wing;
        relationship set <Room_timeslot*> rroom_timeslot inverse Room_timeslot::Room;
};

class Room_timeslot {
        relationship Room *room inverse room::rroom_timeslot;
        relationship Lecture* rlecture inverse Lecture::Room_timeslot;
        relationship set <Timeslot*> rtimeslot inverse Timeslot::lroom_timeslot;
};

class Timeslot {
        attribute string name;
        attribute int number;
        attribute time timemargin_start;
        attribute time timemargin_end;
        relationship set <Room_timeslot*> troom_timeslot inverse Room_timeslot::rtimeslot;
};

I want to make queries that look like this: 我想进行如下查询:

SELECT lr.name as lecturer, t.name as topic FROM topic t        
JOIN lecture l ON t.id_topic = l.id_topic
JOIN lecturer lr ON lr.id_lecturer = l.id_lecturer
ORDER BY lr.name

select t.name as topic from topic t 
join lecture l on t.id_topic = l.id_topic 
join lecturer lr on lr.id_lecturer = l.id_lecturer
where lr.name = "name1"

SELECT tm.name as teaching_material, e.name as equipment, lr.name as lecturer FROM teachingmaterial tm
JOIN teaching_content tc ON tc.id_teachingmaterial = tm.id_teachingmaterial
JOIN content c ON c.id_content = tc.id_content
JOIN content_lecture cl ON cl.id_content = c.id_content
JOIN lecture l ON l.id_lecture = cl.id_lecture
JOIN lecture_equipment le ON le.id_lecture = l.id_lecture
JOIN equipment e ON e.id_equipment = le.id_equipment
JOIN lecturer lr ON lr.id_lecturer = l.id_lecturer

Java uses JDBC to communicate with a relational database. Java使用JDBC与关系数据库进行通信。 If your database has a JDBC driver you're all set. 如果您的数据库具有JDBC驱动程序,那么您已经准备就绪。 If not, you're out of luck. 如果没有,那你就不走运了。 Both SQL Server and MySQL have JDBC drivers, so they should not be a problem. SQL Server和MySQL都具有JDBC驱动程序,因此它们应该不是问题。 You'll need those and the JDBC tutorial . 您将需要这些和JDBC教程

Looks like EyeDB is an object database that I've never heard of. 看来EyeDB是我从未听说过的对象数据库。 It claims to be usable by C++ and Java. 它声称可用于C ++和Java。

I'd expect at least one "hello world" connection example. 我希望至少有一个“ hello world”连接示例。 I'm suspicious of any software that doesn't even get the HTML on its web page right. 我对任何甚至无法正确显示其网页HTML的软件都感到怀疑。

There's Java documentation available. Java文档可用。 Looks awful. 看起来糟透了。 Is this a requirement? 这是一个要求吗? There are better databases, both relational (MySQL, SQLLite, or PostgreSQL), object (eg JODB ), or graph (NEO4J). 有更好的数据库,包括关系数据库(MySQL,SQLLite或PostgreSQL),对象数据库(例如JODB )或图形数据库(NEO4J)。 Must you use this one? 你一定要用这个吗?

The EyeDB documentation makes the steps clear. EyeDB文档使步骤更清晰。 They are spelled out for you in the sample problem : 示例问题中为您阐明了它们:

  1. Define the schema using the EyeDB Object Definition Language (ODL) 使用EyeDB对象定义语言(ODL)定义架构
  2. Generate the Java classes from the schema using the EyeDB eyedbodl tool, which comes with your download. 使用下载随附的EyeDB eyedbodl工具从架构生成Java类。
  3. Write a client program using the generated classes that interact with the database. 使用生成的与数据库交互的类编写客户端程序。

It's all there. 都在那里。 Give it a try. 试试看。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM