001/* 002 * Copyright (c) 2006-2011 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the Eclipse Public License v1.0 006 * which accompanies this distribution, and is available at 007 * http://www.eclipse.org/legal/epl-v10.html 008 * 009 * Contributors: 010 * Florent Guillaume 011 */ 012 013package org.nuxeo.ecm.core.storage.sql; 014 015/** 016 * Model of a property (simple or array) of a {@link Node}. 017 */ 018public class ModelProperty { 019 020 public final PropertyType propertyType; 021 022 public final String fragmentName; 023 024 public final String fragmentKey; 025 026 public final boolean readonly; 027 028 public final boolean fulltext; 029 030 protected final boolean isIntermediateSegment; 031 032 /** 033 * Creates a model for a scalar property, or the last segment of a complex property. 034 */ 035 public ModelProperty(PropertyType propertyType, String fragmentName, String fragmentKey, boolean readonly) { 036 this.propertyType = propertyType; 037 this.fragmentName = fragmentName; 038 this.fragmentKey = fragmentKey; 039 this.readonly = readonly; 040 isIntermediateSegment = false; 041 // TODO use some config to decide this 042 fulltext = (propertyType.equals(PropertyType.STRING) || propertyType.equals(PropertyType.BINARY) || propertyType.equals(PropertyType.ARRAY_STRING)) 043 && (fragmentKey == null || !fragmentKey.equals(Model.MAIN_KEY)) 044 && !fragmentName.equals(Model.HIER_TABLE_NAME) 045 && !fragmentName.equals(Model.VERSION_TABLE_NAME) 046 && !fragmentName.equals(Model.PROXY_TABLE_NAME) 047 && !fragmentName.equals(Model.FULLTEXT_TABLE_NAME) 048 && !fragmentName.equals(Model.LOCK_TABLE_NAME) 049 && !fragmentName.equals(Model.UID_SCHEMA_NAME) 050 && !fragmentName.equals(Model.MISC_TABLE_NAME); 051 } 052 053 /** 054 * Create a model for an intermediate segment of a complex property. 055 * 056 * @param name the canonical segment name 057 * @since 5.7.3 058 */ 059 public ModelProperty(String propertyName) { 060 this.fragmentName = propertyName; 061 propertyType = null; 062 fragmentKey = ""; 063 readonly = false; 064 fulltext = false; 065 isIntermediateSegment = true; 066 } 067 068 /** 069 * Gets the segment name for an intermediate segment. 070 * 071 * @return the segment name 072 * @since 5.7.3 073 */ 074 public String getIntermediateSegment() { 075 return fragmentName; 076 } 077 078 /** 079 * Checks if this is a pseudo-model for an intermediate segment of a complex property. 080 * 081 * @since 5.7.3 082 */ 083 public boolean isIntermediateSegment() { 084 return isIntermediateSegment; 085 } 086 087 @Override 088 public String toString() { 089 return getClass().getSimpleName() + '(' + fragmentName + ", " + fragmentKey + ", " + propertyType 090 + (readonly ? ", RO" : "") + (fulltext ? ", FT" : "") + ')'; 091 } 092 093}