CS636 – Database Application Development

Homework 2 Solution

Thanks to May Wong for part of this.

 

Q1       End tag 'office' does not match the start tag 'furniture': no end tag for <furniture name=”desk” price=”150.00”>

            Fix: add / as indicated in yellow, or use </furniture>.

     <office roomnumber="423">
          <professor lastname="smith" firstname="john" department="mgt" degree="Ph.D” average_evaluation="4.8"/>
          <furniture name="cabinet" price="200.00"/>
          <furniture name="desk" price="150.00"/>   / >
     </office>

 Q2.

  1. Nothing needed in paper.
  2. cp -r $cs636/pizza1 .
  3. Before build, after “ant clean” (should have been in the hw directions):

topcat$ du
19        ./database
3522    ./lib
4         ./src/cs636/pizza/config
18       ./src/cs636/pizza/dao
8         ./src/cs636/pizza/domain
22      ./src/cs636/pizza/presentation
12      ./src/cs636/pizza/service
65      ./src/cs636/pizza
66      ./src/cs636
67      ./src
3620    .

After build, see binaries under bin:

topcat$ du
19        ./database
3522    ./lib
4       ./src/cs636/pizza/config
18      ./src/cs636/pizza/dao
8       ./src/cs636/pizza/domain
22      ./src/cs636/pizza/presentation
12      ./src/cs636/pizza/service
65      ./src/cs636/pizza
66      ./src/cs636
67      ./src
20      ./bin/cs636/pizza/dao
4       ./bin/cs636/pizza/config
15      ./bin/cs636/pizza/service
9       ./bin/cs636/pizza/domain
25      ./bin/cs636/pizza/presentation
74      ./bin/cs636/pizza
75      ./bin/cs636
76      ./bin
3696    .

d.  Success!

e. Success!

f. Success!  (all that is needed for homework)

Details (not required in homework):
topcat$ ant start-hsqldb
Buildfile: build.xml

start-hsqldb:
     [java] [Server@1833955]: [Thread[main,5,main]]: checkRunning(false) entered
     [java] [Server@1833955]: [Thread[main,5,main]]: checkRunning(false) exited
     [java] [Server@1833955]: Startup sequence initiated from main() method
     [java] [Server@1833955]: Loaded properties from [/home/rum/Desktop/cs636/eoneil/cs636/pizza1/database/server.properties]
     [java] [Server@1833955]: Initiating startup sequence...
     [java] [Server@1833955]: Server socket opened successfully in 9 ms.
     [java] [Server@1833955]: Database [index=0, id=0, db=file:test, alias=] opened sucessfully in 230 ms.
     [java] [Server@1833955]: Startup sequence completed in 244 ms.
     [java] [Server@1833955]: 2009-09-17 12:27:29.943 HSQLDB server 1.8.0 is online
     [java] [Server@1833955]: To close normally, connect and execute SHUTDOWN SQL
     [java] [Server@1833955]: From command line, use [Ctrl]+[C] to abort abruptly

This process hangs, so you need to start another window to proceed

In another window:
topcat$ ant load-hsqldb
Buildfile: build.xml

load-hsqldb:
      [sql] Executing resource: /home/rum/Desktop/cs636/eoneil/cs636/pizza1/database/createdb.sql
      [sql] 6 of 6 SQL statements executed successfully

BUILD SUCCESSFUL
Total time: 0 seconds


topcat$ ant hsqlSysTest
Buildfile: build.xml

init:

build:
     [echo] pizza1: /home/rum/Desktop/cs636/eoneil/cs636/pizza1/build.xml

hsqlSysTest:
     [java] Connecting using driver org.hsqldb.jdbcDriver, connection string jdbc:hsqldb:hsql://localhost/
     [java]
     [java]
     [java] *************ai***************
     [java]
     [java] ----OK
     [java]
     [java]
     [java] *************so 5***************
     [java]
     [java] ----OK
     [java]

BUILD SUCCESSFUL
Total time: 0 seconds


Q3. a. PizzaOrderDAO.java has “package cs636.pizza.dao;”

src/cs636/pizza/dao from base directory pizza1 for sources

bin/cs636/pizza/dao from base directory pizza1 for .class files

b. StudentService.java has “package cs636.pizza.service;”, so it is in package cs636.pizza.service.

What methods of PizzaOrderDAO are called from here? (method names are sufficient here)
      findMenuSizes()
      findMenuToppings()
      insertOrder()
      findOrdersByRoom()
      updateOrderStatus()      

StudentService.java has “import cs636.pizza.dao.PizzaOrderDAO;” to allow it to access PizzaOrderDAO methods with short names

 c. After commenting out the above import statement, and using "ant build" (or "ant clean" followed by "ant build", we see:

C:\cs\cs636\pizza1>ant build
Buildfile: C:\cs\cs636\pizza1\build.xml

init:
    [mkdir] Created dir: C:\cs\cs636\pizza1\bin

build:
     [echo] pizza1: C:\cs\cs636\pizza1\build.xml
    [javac] Compiling 23 source files to C:\cs\cs636\pizza1\bin
    [javac] C:\cs\cs636\pizza1\src\cs636\pizza\service\StudentService.java:30: error: cannot find symbol
    [javac]     private PizzaOrderDAO pizzaOrderDAO;
    [javac]             ^
    [javac]   symbol:   class PizzaOrderDAO
    [javac]   location: class StudentService
    [javac] C:\cs\cs636\pizza1\src\cs636\pizza\service\StudentService.java:34: error: cannot find symbol
    [javac]     public StudentService(PizzaOrderDAO pizzaDAO, MenuDAO mDAO, AdminDAO admDAO) {
    [javac]                           ^
    [javac]   symbol:   class PizzaOrderDAO
    [javac]   location: class StudentService
    [javac] 2 errors

BUILD FAILED
C:\cs\cs636\pizza1\build.xml:45: Compile failed; see the compiler error output for details.

Total time: 1 second

Alternative answer: In eclipse, looking at StudentService.java without the import statement quoted above, we see a lot of red stars on lines of code. By putting the mouse on one of them, we can see the specific error. For example, the first one, on the pizzaOrderDAO field, says “PizzaOrderDAO can not be resolved to a type”. It is looking for class PizzaOrderDAO in the current package, cs636.pizza.service, and failing to find it.

d. What longer name could be used by StudentService to access the PizzaOrderDAO type without the import? Show the line of code that changes.

private PizzaOrderDAO pizzaOrderDAO;  becomes private cs636.pizza.dao.PizzaOrderDAO pizzaOrderDAO;

 Q4.                

a.     <delete dir="build"/> will delete the build directory, including all files and subdirectories of build.

“rmdir build” is used to remove the build directory if it is empty.  UNIX rmdir will not let us remove a non-empty directory.

“rm –r build” will remove files, directories, and recursively, any subdirectories under build directory, so this is the action that <delete> does, on UNIX.

All these commands will work when the present working directory is the parent directory of build directory, i.e., the base directory of the project.

      b.

<project>
            <target name="clean">
                        <delete dir="build"/>
            </target>
            <target name="compile">
                        <mkdir dir="build/classes"/>
                        <javac srcdir="src" destdir="build/classes"/>
            </target>

            <target name="jar">
                        <mkdir dir="build/jar"/>
                        <jar destfile="build/jar/HelloWorld.jar"basedir="build/classes">
                        <manifest>
                                    <attribute name="Main-Class"value="com.oata.HelloWorld"/>
                        </manifest>
                        </jar>
            </target>

            <target name="run">
                        <java jar="build/jar/HelloWorld.jar" fork="true"/>
            </target>
</project>

Now we need to store HelloWorld.java in basedir/src/com/oata/

   c.

For HSQL, we would put (somewhat similarly for mysql):

      <target name="select-pizza-orders-hsqldb">" description="Display pizza_orders in HSQLDB">
            <sql classpathref="project.classpath"driver="org.hsqldb.jdbcDriver"
                url="jdbc:hsqldb:hsql://localhost/"userid="sa" password="" >
                select * from pizza_orders;
            </sql>
      </target> 

Q5. 

HTML forms.  Read Murach on forms, pp. 114-123. Study this forms tutorial at http://www.w3schools.com and their tutorial on image

a)          X’s and O’s are displayed using Image tags. In HTML, images are defined with the <img> tag. To display an image on a page, we need to use the src attribute. src stands for "source". The value of the src attribute is the URL of the image that needs to be displayed.

            X is displayed using the HTML IMG tag:

                        <IMG SRC="x.gif" ALT="[X]" WIDTH=40 HEIGHT=42>

            O is displayed using:

                        <IMG SRC="o.gif" ALT="[O]" WIDTH=40 HEIGHT=42>
b)   The submission request (POST body) will have name=3 for box 3, etc.

c)  One for the page HTML and 3 for the tic-tac-toe box images (blank.gif, x.gif and o.gif) so 4 in all. Actually, there is another round-trip for the icon too. We looked at these accesses using Chrome: right-click, Inspect, choose Network tab, redisplay page and see request timeline.

d)   The browser handles the moment-to-moment cursor painting, based on HTML directives. The areas of special cursors are specified through hyperlinks and image tags, and also text input tags. A “hyperlink” is, most commonly, an underlined word or phrase, or sometimes even a graphic image or icon. When you move your cursor over a link, the cursor shape will usually change into a hand. The destination of the link will also turn up in the status bar - the bar at the bottom of the browser. In text boxes, the cursor turns into a vertical bar.

e)         The knowledge of X’s and O’s is kept in the following line in the browser, a hidden form field (not shown to user).

<INPUT NAME=BOARD TYPE=HIDDEN VALUE=-XO-O-XOX >         

Hidden fields (name, value) are sent back to the server when the form that contains them is submitted.

More discussion, FYI: The advantages of hidden form fields are their ubiquity and support for anonymity. Hidden fields are supported in all the popular browsers, they demand no special server requirements, and they can be used with clients that haven't registered or logged in. The major disadvantage with this technique, however, is that it works only for a sequence of dynamically generated forms. The technique breaks down immediately with static documents, emailed documents, bookmarked documents, and browser shutdowns.

Q2. HTML for simple form, no CSS:

<!DOCTYPE html>
<html>
      <head><title>User Registration</title></head>
      <body>
            <h2>Register for This Website</h2>
            <form method="post">
              Name:<input type="text" name="cname" size="30" /><br>
             Preferred E-mail:<input type="text" name="cemail" size="60" /><br><br>
            <input type="submit"/>
            </form>
      </body>
</html>

(or put the labels into <label> elements here, we get the same result:)

 Explanation (not required in hw paper): We see this does not align the input boxes.To do so, we need to turn the labels into block elements (first turn the labels into <label> elements) to allow us to specify a width. This can be done by float or display:inline-block in CSS.