[ Pobierz całość w formacie PDF ]
.A cache can also reduce the number of costly network roundtripsbetween a client application and a database server.When the client application asks for an object, the translation layer should look to see whether thatobject already exists in the cache.The translation layer can use the primary key as the object identifier. If the object is in the cache, the translation layer can give the application a pointer to the existing objectwithout having to query the database.This is a huge optimization, but requires a bit of code.Unfortunately, describing the code required to implement an object cache is beyond the scope of thebook.Some technical white papers on this topic are available from programming tool vendors whospecialize in this kind of work.Use the Strengths of Both ModelsTake advantage of objects when you can, and take advantage of the RDMS server when you can-useboth.For example, if you need to get the total number of instances in the database, do not count them byinstantiating every object inside a loop in the client code.Instead, ask the database server to simplycount the records and return the figure to the client application that needs it.The performance will bemuch better with this approach.Another example is if you need to traverse a tree of nested objects, such as in a bill of materials.Itwould probably be inefficient to have the relational database server traverse the tree.Instead, youshould instantiate the appropriate objects and have the object code traverse the tree.SummaryRelational databases and object-oriented programming languages are powerful tools for managing dataand writing software.Unfortunately, melding these two technologies is not straightforward.This isbecause relational databases were not designed to store objects, and objects were not designed to bestored in relational databases.Melding an object-oriented application with a relational database requires you to write a translationlayer between the object code and the relational database.Writing this translation layer can be difficultand time-consuming.However, your application and your database can derive great benefits from thesynergies of these two technologies.Q&AQ Are any software tools available that make the task of writing the translation layereasier?A Yes.There are independent software vendors who produce tools for just this purpose.You can find them by perusing the advertisements in the various relational database orC++ technical journals.You can also search the Web for terms such as object database,RDBMS, ODBMS, persistence, mapping, translation layer, and so on.Q Aren't the vendors of relational databases extending their databases to support thestorage of objects? A Yes.Relational database vendors such as Informix, Oracle, and others have made effortsto extend their databases to support object storage.However, there is no clear indicationof significant market acceptance of any of their approaches so far.Let the buyer beware.Q Can't I just create a set of C++ base classes that talk to the translation layer andderive the classes in my application from these base classes to get easycommunication with a relational database?A If only it were that simple.One of the problems you will encounter is that a C++ baseclass will have trouble persisting an instance of a derived class, because the derived classmight contain data that the base class does not know about.The derived classesthemselves will probably need to participate in some way in their being persisted to thedatabase.Q What is Microsoft's approach to object storage?A Microsoft does not seem to be trying to extend its SQL Server database to make it storeobjects.Rather, Microsoft has provided OLE DB as an object-oriented API that cancommunicate with relational as well as object-oriented data stores.WorkshopThe Workshop quiz questions test your understanding of today's material.(The answers appear inAppendix F, "Answers.") The exercises encourage you to apply the information you learned today toreal-life situations.Quiz1.What prevents you from being able to store C++ objects in relational database fields?2.Why can't you use SQL for object-oriented programming tasks?3.What are the primary differences between C++ object databases and relational databases?4.When designing an application that will use object and relational technology, where do youstart?5.What are the benefits of a live object cache?Exercises1.Write a SELECT statement that retrieves the shoe type based on the shoe ID from the Shoestable shown in Figure 13.5.2.Write a SELECT statement that retrieves all the attributes of basketball shoes from the tablesshown in Figure 13.5.© Copyright, Sams Publishing.All rights reserved. Teach Yourself Database Programmingwith Visual C++ 6 in 21 daysDay 14Legacy Database APIsODBCThe ODBC Driver AdministratorThe ODBC Driver ManagerThe ODBC DriverProgrammatic Sequence for the ODBC APIStep 1: Connect to a Data SourceStep 2: Allocate a Statement HandleStep 3: Prepare and Execute the SQL StatementsStep 4: Get the ResultsStep 5: Committing the TransactionA Simple ExampleMFC Wrappers for ODBCCDatabaseCRecordSetDAOThe Jet Database EngineCdbDBEngine: The Root of It AllCdbDBWorkspaceCdbDBDatabaseCdbDBRecordsetsMFC Wrappers for DAOCDaoWorkspaceCDaoDatabase CDaoRecordSetA Simple ExampleSummaryQ&AWorkshopQuizExercisesAlthough considered legacy, the APIs that you will learn about today provide some valuable insightinto the structured nature of developing database applications.Merriam Webster defines legacy as"being from the past," but you can hardly limit the content of this chapter to dusty old relics that needonly cursory explanation.Although ODBC and DAO APIs might no longer be applicable inmainstream coding circles, the technology provides the foundation for most databases supportedtoday.Today you willLearn about the ODBC Architecture and API.Receive an introduction to the ODBC API calls.Learn about the DAO API.Receive an introduction to the DAO API calls.Explore the similarities and differences between ODBC and DAO.Understand the MFC wrapper classes for each API.NOTEThis book focuses primarily on the newer OLE DB (ADO) technologies, butremember that it is still in its infancy and OLE DB providers for manydatabases are still in development.With this in mind, it is easy to see theimportance of understanding these legacy interfaces.Who knows, youmight have to provide support for an application using these APIs.ODBCDatabases, and their programming APIs, come in a variety of flavors.Many different databases areavailable to the developer, and each has a specific set of programming APIs.SQL was an attempt tostandardize the database programming interface.However, each database implementation of SQLvaries slightly.NOTE ANSI SQL-92 is the latest and most supported version of SQL, but thespecification only provides a guideline.It is up to the database vendor tosupport all or part, as well as additional elements of the specification.ODBC was the first cohesive attempt to provide an application layer that would allow access to manydifferent databases.ODBC provided a consistent specification for database vendors to develop ODBCdrivers that applications could connect to.Applications can make function calls to the ODBC driver tosend data to and receive data from a database, or in some cases multiple databases.ODBC provides standardized access to databases.This enables the application developer to betterconcentrate on the application and its user interface and not have to worry about database specifics forevery possible database on the market [ Pobierz caÅ‚ość w formacie PDF ]

  • zanotowane.pl
  • doc.pisz.pl
  • pdf.pisz.pl
  • szamanka888.keep.pl