Some Smarty notes - PowerPoint PPT Presentation

1 / 18
About This Presentation
Title:

Some Smarty notes

Description:

Smarty also has a set of functions to help in creating html ... Blob. BLOB. long. BIGINT. Timestamp. TIMESTAMP. int. INTEGER. Time. TIME. short. SMALLINT. Date ... – PowerPoint PPT presentation

Number of Views:95
Avg rating:3.0/5.0
Slides: 19
Provided by: jyrk9
Category:
Tags: blob | notes | smarty

less

Transcript and Presenter's Notes

Title: Some Smarty notes


1
Some Smarty notes
  • Smarty has a set of functions for output
    modification (modifiers), e.g. for formatting of
    dates
  • Smarty also has a set of functions to help in
    creating html form elements, such as select
    lists, radio buttons e.g.
  • They have not been used in the example
    implementation,
  • I have used a function to make it more hard to
    get an e-mail address from the source. See
    footer.tpl
  • The Sassociation now includes a partial
    maintenance facility, which is not guaranteed to
    work (and fails with null values).
  • It is fairly straightforward. Notice, though,
    that if a session expires, the application stores
    the request and continues to manage it after a
    succesful login.

2
SQL-DATABASE JAVA
  • - The use of a connection pool.
  • - Java default JDBC datatype problems.
  • - Objects vs. tables in software development.
  • - Fujaba tool plugin for database design and
    database driven software development

3
Connection pooling
  • Creation of each connection
    DriverManager.getConnection() uses resources
    and takes time.
  • This is particularly true on the database server
    side, due to reservation of memory structures
    etc.
  • The programs typically execute only for a small
    while.
  • It looks like a bad idea to let each request
    action open and close its connections.
  • It would be better, if the programs could re-use
    connections from a pool (array) of database
    connections.
  • A separate process may manage the connections and
    open new ones, if the existing ones are not
    enough.

4
Services of a connection pool
  • When connection pool manager is started, it
    starts up a (configurable) number of database
    connections.
  • The programs executing can request connections
    and release them, when they are not needed.
  • If all connections are in use, then e.g. the
    following possibilities exist
  • - Wait for a free connection.- Fail as there
    were no free connections. - Create a new
    connection.

5
Connection pool implementation
  • JDBC 2.0 includes a connection pool, but there
    are also other implementations.
  • A typical implementation has a class, whose
    services are available using static methods.
  • This way, the manager can be found using method
    Class.forName()
  • This gives access to connections.
  • For details, see
  • http//www.webdevelopersjournal.com/columns/con
    nection_pool.html

6
SQL-tietotyypit ohjeellisia vastaavuuksia
7
Are they ok?
  • Some are classes, some are primitive data types.
  • All database implementations do not support all
    values
  • Boolean BIT is not generally supported.
  • Some store dates and times in the same value
    (timestamp)
  • Some store them separately
  • And sometimes this also makes more sense.
  • Java datatypes do not store (recognize) all
    properties of SQL data types (e.g. maximum length
    of a character string)
  • What follows from these reasons is that
    consistent and correct implementation of database
    applications using JDBC has additional
    difficulties.

8
Solution
  • An implementation of wrapper classes, which wrap
    the Java data types for JDBC in them.
  • The classes offer the services in a consistent
    form.
  • Common interface to access these services.
  • Problematic data types (e.g. boolean) can be
    implemented in a consistent way in Java.
  • If the DBMS changes and there are compatibility
    problems, the wrapper class may be changed.

9
Why not from Classes to Tables?
  • Object-oriented Java applications access SQL
    databases.
  • Many software design methodologies suggest that
    Classes are designed first, then some method for
    storing the objects in an SQL database.
  • Often the database already exists when software
    project starts.
  • If the database is designed just for storing the
    objects, it may be complicated to fulfill future
    query needs.
  • OO-style navigation with a SQL database is
    row-by-row (bad!)
  • Repeated queries instead of one query (resource
    waste)
  • Some systems anticipate and cache values, but
    this may not always work. (In fact it may just
    give the illusion that things are ok.)
  • DB resource is hard to replicate because of
    maintenance problems. It should be respected.

10
From Tables to Classes
  • Solution Generate classes from the database
    description (and not the other way round).
  • This is the idea of e.g. the Fujaba DB plugin.
  • This also supports writing software on top of an
    existing SQL database.
  • Typically the databases contain more persistent
    value to their users than the software that has
    been developed to run on the databases.
  • The base of Fujaba is developed at the University
    of Paderborn (http//www.fujaba.de)
  • The DB plugin has been developed at the
    University of Tampere
  • It has also been used in software development for
    several years.

11
DB Wrapper Class Basics
  • Wrap tables with classes (Assume table name Xyz)
  • DB Class (DbXyz) implements basic database
    functionality
  • Insert, modify, delete
  • A Bean (BeanXyz) class inherits DB class and
    implements Bean interface (set/get)
  • A top-level class for application-specific code
    inherits the Bean class
  • The application programmer should only touch the
    top-level class
  • This allows regeneration and replacement of the
    DB and Bean classes when the database structure
    changes.
  • Similarly wrap views with classes.
  • When querying it is possible to add WHERE clauses.

12
Advantages
  • Less dull and routine programming tasks.
  • Which often lead for errors
  • A unified model for accessing the data
  • Better support for database changes
  • In particular in the development stage
  • Changing the actual database in use is an
    additional complication.
  • This may be supported better by future Fujaba DB
    plugin versions.
  • Fast and easy database classes
  • No XML is needed
  • I guess just about everyone is seeing enough of
    it.

13
Database reverse engineering
  • A database may already exist.
  • In a badly managed project, somebody may go and
    say alter table something similar to change the
    database directly.
  • The Fujaba DB plugin can reverse engineer the
    database from .sql files
  • Also over JDBC, but at the time of the
    development the JDBC interface did not
    differentiate tables and views, so the reverse
    engineering shows tables as views.

14
JAVA APPLETS
15
JAVA APPLETS
  • If we want to execute a real program in the
    browser, we can use Java applets
  • Applets offer the functionalities of a real
    programming language.
  • Applets execute with limited rights to protect
    the client computer.
  • Java may be unabled in the browser.
  • Some specialties need to be taken into account in
    programming.
  • The applet is glued to the web page.
  • In the end, Applets are Java programs, so we just
    go through some special features.
  • http//java.sun.com/docs/books/tutorial/deployment
    /applet/index.html
  • Applets come in handy for some special features,
    like animation.

16
ltappletgt tag
  • ltAPPLETgt
  • Applet class
  • CODEclassname
  • CODEBASEcode directory
  • Applet size (area of applet in the web page)
  • WIDTHarea width
  • HEIGHTarea height
  • Parameters
  • ltPARAM NAMEname VALUEhellogt
  • lt/APPLETgt
  • Theres other things as well, if interested, see
    HTML documentation.
  • Also Internet Explorer and Netscape specific tags
    exist.

17
Converting a program to applet
  • Create a subclass of java.applet.Applet in which
    override
  • init() method to initialize your applet's
    resources like the main method initializes the
    application's resources.
  • Notice that init() might be called more than once
    and should be designed accordingly.
  • start() method for starting (and re-starting) the
    applet
  • stop() method for stopping the execution
    (re-start is possible)
  • destroy() as a destructor.
  • The top-level Panel could to be added to the
    applet in init()
  • In main() of a program it is usually added to a
    Frame
  • In applets, however, there exists a default
    Graphics object (see examples)
  • Make the applet class public.

18
A few more applet things
  • AWT and Swing are imported for UI.
  • Applets run on restricted rights, e.g.
  • No local disk access
  • Can only open a network connection to a host from
    where it is loaded.
  • But with aid of a program on that server, may
    contact others.
  • Can access only limited system properties.
  • Cannot start programs on the client computer.
  • For further details, see documentation.
  • Also the examples may give you some hints.
Write a Comment
User Comments (0)
About PowerShow.com