Igor's Blog

This is a bit of code from my latest personal project that's using PHPCR / Jackalope for it's storage backend. With Jackalope you can keep using nt:unstructured as your node type, but it makes a lot of sense to create custom node types when you are certain of what your data will look like. With a custom node type you are guaranteed that the structure of the node you're trying to store will be as defined and you don't have to worry about writing additional validation code yourself since the storage backend will take care of it for you.

This is where CND files come in. A good way of thinking of a CND file node definition is as if it is a table in a traditional relational database.

There is a node type notation defined that provides the grammar for a CND file. This format is very compact and easy to understand.

Here's an example node definition that has two properties and specifies that the parent node will have an unstructured child node. Notice that I define my own custom namespace here.
 location.cnd
<tb = 'http://travelblog.ws/ns'>
[tb:Location]
- tb:name (string) primary mandatory
- tb:arrivalDate (date) mandatory
+ tb:posts (nt:unstructured) mandatory autocreated


To register this definition, the NodeTypeManager is used. This object is fetched from the workspace and a workspace comes from a session...
 PHP
$workspace = $session->getWorkspace();
$nodeTypeManager = $workspace->getNodeTypeManager();
$nodeTypeManager->registerNodeTypesCnd(file_get_contents('location.cnd'), true);


The above code assumes that a session has already been created. The CND file is read into a string and passed to the NodeTypeManager. That's all there is to it. Of course you would probably want to have multiple CND files.

The loading of registration of CND files is a one time operation, once it's in your repository you can keep reusing the defined node types.



-i

comments powered by Disqus
Other posts you may like...
Programming, DIY, Games, Hacks, and Tech

Recent Blog Posts

Swapping HDD logic boards between different brand disks - is it possible?

A guide for plotting your hard drive for Burstcoin mining on a Mac using mjminer

Replacing a broken hard drive in a Samsung Story Station

Fix Java applications slow start and net connection times on macOS sierra

Pierre Cardin Leather Computer Bag (PC2278)

How to stop SSH remote host disconnecting your session

Using PayPal PHP SDK on Google App Engine

Use the Touch Bar to lock your Mac with a single button press

Multi module builds with Maven 3.5 and the parent-child pom version management

Google App Engine local dev server DataStore becoming corrupted after a bad GQL statement is run

Recent Galleries

Monument Valley 2 is released and does not disappoint

Space Food - Chocolate Ice Cream with Chocolate Chips

Legeod Star Wars AT-DP kit

DIY spare parts computer build with a RAIDMAX Anura case

Fake 'Lepin' brand Lego packaging

Hardwood garden bench with clear resin void filler

Fixing a 3D printer extruder that stopped heating up

Easily increase disk space in a Lenovo Ideapad 100S 14" laptop with an M.2 SSD

Making a multi-piece 3D printed solder spool holder stand

DIY indoor apartment grow light wiring

My Other Web Sites

Igor and Elise's Travels
Riverside Expressway Cam
300 George St Blogumentary

My Online Tools

UUID to OID Converter
Guru JSON-RPC Tester
Extrudifier Object Designer
Travel ┬ÁBlog

Blogs and Friends

Matt Moores Blog
Georgi's FlatPress Guide
Perplexing Permutations
The Security Sleuth
Ilia Rogatchevski
Travelling Fairy

Blog Activity

Blog Activity
Your call, follow me if you want to read more great posts like this one!
     
Don't show this again