講解:CSI 410尘执、Database Systems鹃祖、JavaHaskell|R

CSI 410. Database Systems – Spring 2020Programming Assignment IThe total grade for this assignment is 100 points. The deadline for this assignment is 11:59PM, February 20, 2020. Submissions after this deadline will not be accepted. Students arerequired to enter the UAlbany Blackboard system and then upload a .zip file (in the form of [firstname] [last name].zip) that contains the Eclipse project directory and a short document describing:? any missing or incomplete elements of the code? any changes made to the original API? the amount of time spent for this assignment? suggestions or comments if anyIn this programming assignment, you need to implement a storage manager that maintains aseries of data objects in each data file. You first need to install and run Eclipse on your machineand import the “storage manager” project (see Appendix A). Please generate an API document(see Appendix B) and then take a look at that document as well as the source code to familiarizeyourself with this assignment. This assignment provides you with a set of incomplete classes (inparticular, see SlottedPage, FileManager, and BufferedFileManager which contain methodscurrently throwing an UnsupportedOperationException). You will need to write code for theseclasses. Your code will be graded by running a set of unit tests and then examining your code (seeSlottedPageTest and FileManagerTest which use JUnit1, as well as BufferedFileManagerTestwhich produces output messages). For details of running these tests, refer to Appendix A. Notethat passing unit tests does NOT necessarily guarantee that your implementation is correct andefficient. Please make sure that your code is correct and efficient so that it will not cause anyproblem in many other cases not covered by the unit tests. If you have questions, please contactthe TA(s) or the instructor. The remainder of this document describes the components that youneed to implement.Part 1. The Slotted Page Structure (50 points)The slotted page structure allows a storage manager to store variable-length records (dataobjects) within a fixed size page (an in-memory copy of a disk block). Each page is essentially abyte array that stores a header (at the beginning) and a number of data objects (at the end). Theheader of a page consists of (1) a 4-byte integer representing the number of entries in the page forstoring data objects, and (2) a series of 4-byte integers (one for each data object) each of whichrepresents where the corresponding data object is stored within the page (i.e., the location of thecorresponding data object within the page). Each page has, between its header and data objects,a free space where more data objects and header entries can be added. For further details of theslotted page structure, refer to Section 13.2.2 of the textbook. Upon a request to delete a dataobject from a page, the corresponding header entry (for storing the location of the data object)is simply set to -1 to indicate that there is no associated data object (the actual object is NOTnecessarily removed from the page).1http://junit.org1In this part, you need to implement the following methods (your code needs to pass all of the5 tests in SlottedPageTest):? add(Object o): adds the specified object o in the SlottedPage on which this method isinvoked. This method must first save the object o in the free space of the SlottedPage bycalling the save(Object o) method. This save(Object o) method returns an int valueindicating the location at which the object o is saved in the SlottedPage. That int valuemust be stored at the right header entry of the SlottedPage so that the saved object o canbe accessed in the future. For example, assume that object “123” is saved at location 2038 inthe byte array of an empty SlottedPage. Then, the first 4 bytes of the byte array (i.e., thebeginning of the header) must store an int value 1 to indicate that there is only one entry inthe header (in response to the addition of object “123”). The next 4 bytes of the byte array(i.e., the 0th entry in the header) must store 2038 (i.e., the location at which “123” is saved).When an additional object “456” is saved at location 2028 in the byte array, the first 4 bytesof the header must store 2 (to indicate that there are two entries in the header) and the 1stentry (i.e., the entry after the 0th entry) in the header must store 2028 (i.e., the location atwhich “456” is saved). To find the number of entries that the SlottedPage currently has, usethe entryCount() method. To set the number of entries in the header to an int value, usethe setEntryCount(int count) method. To save location l at the ith entry in the header,call saveLocation(i, l).? get(int index): returns the object at the specified index in the SlottedPage on which thismethod is invoked. For example, get(0) returns the object at index 0 (i.e., the object whoselocation is stored at the 0th entry in the header) and get(1) returns the object at index1. This method must first find the location of the object at the specified index by callingthe getLocation(int index) method. This getLocation(int index) method returns theint value stored at the header entry specified by index (i.e., the index-th header entry).If that location is -1, meaning that the object was removed from the SlottedPage, theget(int index) method needs to return null. Otherwise, get(int index) needs to obtainthe object by calling the toObject(byte[] b, int offset) method (with offset set tothe return value of getLocation(int index)) and then return that obtained object. If thegiven index cannot match any of the entries in the SlottedPage (e.g., get(-1)), the methodneeds to throw an IndexOutOfBoundsException.? remove(int index): removes the object at the specified index from the SlottedPage onwhich this method is invoked. This method must save -1 at the appropriate entry in theheader. This method must also return the object removed (i.e., the object previously storedat the specified index).? iterator(): returns an iterator over the objects (excluding those removed) stored in theSlottedPage on which this method is invoked. To find the number of entries in the currentSlottedPage, use entryCount(). To get the object at each index, call get(int index).Note that get(int index) returns null if there is currently no object at the specified indexdue to the deletion of the previous object. Feel free to add an auxiliary class or data structurefor this iterator() method.? compact(): reorganizes the SlottedPage on which the method is invoked (in ord代做CSI 410留學(xué)生作業(yè)溪椎、代寫(xiě)Database Systems作業(yè)、代做Java程序語(yǔ)言作業(yè) 幫做Haskell程序er to maximizethe free space of that SlottedPage). This method is used by the save(Object o)method when the object to save cannot fit into the current free space of the SlottedPage.This method needs to move objects at the end of the SlottedPage in a manner that eliminatesthe space previously wasted by the objects removed from the SlottedPage.2Please make sure that your code passes all of the tests in SlottedPageTest.Part 2. The Basic Storage Manager Implementation (40 points)In this part, you need to implement, in FileManager.java, a basic storage manager that maintainsa series of data objects in each data file without buffering (i.e., reading/writing SlottedPagesdirectly from/to data files). The methods to complete are as follows (your code needs to pass allof the 4 tests in FileManagerTest):? put(int fileID, Long location, Object o): puts object o at location location in thefile specified by fileID. Here, location has a long-type value, whose first half (4 bytescorresponding to an integer) represents the ID of the page (e.g., page 0, page 1, etc.) and thesecond half represents the index within the page. For example, put(10, 0x00000001L, o)stores object o in page 0 of the file specified by ID 10 (i.e., the first disk block in the file) atindex 1 within the page. On the other hand, put(10, 0x00010000L, o) stores object o inpage 1 of the file specified by ID 10 (i.e., the second disk block in the file) at index 0 withinthe page. Given a long-type argument location, use first(location) to get the ID of thepage and second(location) to get the index within the page. After finding an appropriatepage p, call put(int index, Object o) on p to put the object in that page and then callthe updated(p, fileID) method of FileManager to indicate that the page p is updated(then the updated(p, fileID) method of FileManager automatically writes the page tothe appropriate data file). If the location argument has an inappropriate value (e.g., its firsthalf refers to page -1), then put(int fileID, Long location, Object o) needs to throwan InvalidLocationException.? get(int fileID, Long location): returns the object at location location in the file specifiedby fileID.? remove(int fileID, Long location): removes the object at location location from thefile specified by fileID.? iterator(int fileID): returns an iterator over all objects stored in the the file specifiedby fileID. This method needs to use page(int fileID, int pageID) of FileManager anditerator() of SlottedPage. Make sure this method efficiently uses the memory (e.g., doesNOT put all of the objects in the memory first thereby incurring high space overhead andthen return an iterator over these objects).Please verify your code using the tests in FileManagerTest.3Part 3. Buffer Management (10 points)The FileManager class implemented in Part 2 directly accesses data files (i.e., no buffering),causing disk seeks frequently. In this part, you need to implement the BufferedFileManager classso that it extends the functionalities of FileManager in a manner that benefits from buffering(i.e., frequently used pages are kept in memory, thereby enabling fast read and write operations).Furthermore, you need to implement a page eviction policy for the cases where there are too manypages to keep in the main memory. The choice of eviction policy is up to you. It is not necessaryto do something sophisticated. Describe your policy in the document that you submit.When BufferedFileManager is implemented correctly, BufferedFileManagerTest will producesome output as follows (the exact number of reads and writes may vary depending on thebuffering strategy; however, there should in general be less reads and writes as the buffer sizeincreases):buffer size : 4 pages1000 additions % [ { name : table0 . dat , reads : 0 , writes : 3 8 } ]10 removals % [ { name : table0 . dat , reads : 1 0 , writes : 4 8 } ]iteration over 990 elements % [ { name : table0 . dat , reads : 5 2 , writes : 5 2 } ]shut down % [ { name : table0 . dat , reads : 5 2 , writes : 5 2 } ]buffer size : 16 pages1000 additions % [ { name : table0 . dat , reads : 0 , writes : 2 6 } ]10 removals % [ { name : table0 . dat , reads : 9 , writes : 3 5 } ]iteration over 990 elements % [ { name : table0 . dat , reads : 4 8 , writes : 5 1 } ]shut down % [ { name : table0 . dat , reads : 4 8 , writes : 5 1 } ]buffer size : 64 pages1000 additions % [ { name : table0 . dat , reads : 0 , writes : 0 } ]10 removals % [ { name : table0 . dat , reads : 0 , writes : 0 } ]iteration over 990 elements % [ { name : table0 . dat , reads : 0 , writes : 0 } ]shut down % [ { name : table0 . dat , reads : 0 , writes : 4 2 } ]Appendix A. Installing Eclipse and Importing a Java Project1. Visit:http://www.eclipse.org/downloads/2. From the web site, download the eclipse installer (those for Linux, Windows, and Mac OS Xare available) and then choose “Eclipse IDE for Java Developers” and install it.3. After finishing installation, start Eclipse.4. When Eclipse runs for the first time, it asks the user to choose the workspace location. Youmay use the default location.5. In the menu bar, choose “File” and then “Import”. Next, select “General” and “ExistingProjects into Workspace”. Then, click the “Browse” button and select the “storage manager.zip”file contained in this assignment package.6. Once the project is imported, you can choose one among SlottedPageTest.java, FileManagerTest.java,and BufferedFileManagerTest.java in the storage.test package and then run it by clickingthe icon highlighted in Figure 1.4Figure 1: EclipseAppendix B. Creating API documents using javadocOne nice feature of Java is its support for “documentation comments”, or “javadoc” comments,which you can use to automatically produce documentation for your code. Javadoc comments startwith “/**”. Inside a javadoc comment, there are some special symbols, like @param and @return.You can create HTML-based API documents from the source as follows:1. Click the “storage manager” project icon in the Navigator or Project Explorer window.2. Select “Generate Javadoc” from the “Project” menu.3. In the “Generate Javadoc” dialog box, press the “Finish” button.As it runs, it tells you that it’s generating various things. When it is finished, a few new foldersshould appear in your project: doc, doc.javadoc, and doc.resources. See what got generated (toopen the newly created HTML documentation files in a web browser window, just double-clickthem; you can start with “index.html”).5轉(zhuǎn)自:http://www.6daixie.com/contents/9/4920.html

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末恬口,一起剝皮案震驚了整個(gè)濱河市校读,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌祖能,老刑警劉巖歉秫,帶你破解...
    沈念sama閱讀 212,542評(píng)論 6 493
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異养铸,居然都是意外死亡雁芙,警方通過(guò)查閱死者的電腦和手機(jī)轧膘,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 90,596評(píng)論 3 385
  • 文/潘曉璐 我一進(jìn)店門(mén),熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)兔甘,“玉大人谎碍,你說(shuō)我怎么就攤上這事《幢海” “怎么了蟆淀?”我有些...
    開(kāi)封第一講書(shū)人閱讀 158,021評(píng)論 0 348
  • 文/不壞的土叔 我叫張陵,是天一觀的道長(zhǎng)闽晦。 經(jīng)常有香客問(wèn)我扳碍,道長(zhǎng),這世上最難降的妖魔是什么仙蛉? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 56,682評(píng)論 1 284
  • 正文 為了忘掉前任笋敞,我火速辦了婚禮,結(jié)果婚禮上荠瘪,老公的妹妹穿的比我還像新娘夯巷。我一直安慰自己,他們只是感情好哀墓,可當(dāng)我...
    茶點(diǎn)故事閱讀 65,792評(píng)論 6 386
  • 文/花漫 我一把揭開(kāi)白布趁餐。 她就那樣靜靜地躺著,像睡著了一般篮绰。 火紅的嫁衣襯著肌膚如雪后雷。 梳的紋絲不亂的頭發(fā)上,一...
    開(kāi)封第一講書(shū)人閱讀 49,985評(píng)論 1 291
  • 那天吠各,我揣著相機(jī)與錄音臀突,去河邊找鬼。 笑死贾漏,一個(gè)胖子當(dāng)著我的面吹牛候学,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播纵散,決...
    沈念sama閱讀 39,107評(píng)論 3 410
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼梳码,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來(lái)了伍掀?” 一聲冷哼從身側(cè)響起掰茶,我...
    開(kāi)封第一講書(shū)人閱讀 37,845評(píng)論 0 268
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎蜜笤,沒(méi)想到半個(gè)月后符匾,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 44,299評(píng)論 1 303
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡瘩例,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 36,612評(píng)論 2 327
  • 正文 我和宋清朗相戀三年啊胶,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了甸各。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 38,747評(píng)論 1 341
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡焰坪,死狀恐怖趣倾,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情某饰,我是刑警寧澤儒恋,帶...
    沈念sama閱讀 34,441評(píng)論 4 333
  • 正文 年R本政府宣布,位于F島的核電站黔漂,受9級(jí)特大地震影響诫尽,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜炬守,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 40,072評(píng)論 3 317
  • 文/蒙蒙 一牧嫉、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧减途,春花似錦酣藻、人聲如沸。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 30,828評(píng)論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)。三九已至税产,卻和暖如春怕轿,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背辟拷。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 32,069評(píng)論 1 267
  • 我被黑心中介騙來(lái)泰國(guó)打工撤卢, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人梧兼。 一個(gè)月前我還...
    沈念sama閱讀 46,545評(píng)論 2 362
  • 正文 我出身青樓,卻偏偏與公主長(zhǎng)得像智听,于是被迫代替她去往敵國(guó)和親羽杰。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 43,658評(píng)論 2 350

推薦閱讀更多精彩內(nèi)容

  • by Lene Nielsen The persona method has developed from bei...
    鮮核桃閱讀 1,054評(píng)論 0 0
  • Problem: Reverse a singly linked list. Solution: LeetCode...
    LonelyGod小黃老師閱讀 175評(píng)論 0 0
  • 聽(tīng)到李笑來(lái)老師講了很多道理到推,比如在做一件事的時(shí)候要想能夠讓自己堅(jiān)持下去考赛,而且不會(huì)感覺(jué)到痛苦的一個(gè)好的方法就是,在做...
    感想心得閱讀 457評(píng)論 0 0
  • 最近幾天莉测,應(yīng)該還在蘇州吧颜骤,心里有一陣莫名的熱烈之感,直到此刻捣卤,起碼還剩三十六度忍抽,預(yù)料肯定正確八孝,這個(gè)溫度不會(huì)再低下去...
    坡度_a770閱讀 385評(píng)論 0 3
  • 那么從此沒(méi)有我。
    百態(tài)姑娘閱讀 88評(píng)論 1 0