Sunday 16 November 2014

Sitecore Databases

Sitecore is 100% Microsoft based, SQL Server, .NET Framework 3.5, and IIS is supported. Sitecore data is stored in multiple databases and itself is made up of three databases and a web application. Sitecore has three default databases and they are core, master and web.

Databases serve following purpose:

Core database :

The core database is used by Sitecore to manage membership, handle system settings and hold the entire configuration for all applications in the CMS. This database can be accessed through the CMS, and you are able to configure any of the settings, override standard functionality, build your own applications, and add buttons and functionality to the ribbon in the editors. The managed website that provides the Sitecore user interfaces accesses the core database and allows the user to view and edit content in the master database by default.

Master database :

The Master database is the authoring database - it contains all versions of any content or assets. CMS user interfaces access the master database by default. The master database is where all the content editor work is done. Whenever a new piece of content is created, edited or deleted it is stored here, including those in preview mode. The master database can have workflow enabled and customized, so sections of the site can be locked down to certain roles, or made to go through an approver or translator before they go live.


Web database :

The web database is the default publishing target database: by default, Sitecore publishes changes from the master database to the web database. It differs from the master database in that it doesn’t contain anything in preview mode and only stores the latest live version of each item. When a content editor publishes some content it is then copied from the master database to the web database.


Access and context:

Databases can be accessed through the Database class. 
To get a reference to a database, use the Factory class

Sitecore.Data.Database master =   Sitecore.Configuration.Factory.GetDatabase("master");

Whenever the user code is invoked by Sitecore, a so called context database is automatically assigned. You can access this database by using the Context class:

  Sitecore.Data.Database current = Sitecore.Context.Database;

A Sitecore database contains data elements called items. Programmatically, the data represented by Items is accessed through the class Item.

  To get an Item from the current context database, you can use

  string itemPath = "/sitecore/content/home"; 
  Sitecore.Data.Items.Item item = Sitecore.Context.Database.Items[itemPath];

The itemPath is the path of Item names leading to a specific Item.
Items can be retrieved using paths or IDs. Languages and versions can also be specified

  Sitecore.Data.ID itemID = Sitecore.Data.ID.Parse( 
    "{110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9}"); 

  Sitecore.Globalization.Language language =  
    Sitecore.Globalization.Language.Predefined.English;
  Sitecore.Data.Version version = Sitecore.Data.Version.Parse(1);  
  Sitecore.Data.Items.Item homeitemlanguage =  
    Sitecore.Context.Database.Items[itemID, language, version];

The data within an Item is organized in named fields. For instance, an Item to be displayed on a web site may contain a title and some text. To access the values of these fields, you can use an indexer on an Item

Sitecore.Data.Items.Item homeitem = Sitecore.Context.Database.Items["/sitecore/content/home"];
string title = item["title"];
string text = item["text"]; 

No comments:

Post a Comment