@ SuppressWarnings ( { "rawtypes" } ) @ Override public < T extends Element > void createKeyIndex ( final String key , final Class < T > elementClass , final Parameter ... indexParameters ) { makeActive ( ) ; if ( elementClass == null ) throw ExceptionFactory . classForElementCannotBeNull ( ) ; executeOutsideTx ( new OCallable < OClass , OrientBaseGraph > ( ) { @ Override public OClass call ( final OrientBaseGraph g ) { String indexType = OClass . INDEX_TYPE . NOTUNIQUE . name ( ) ; OType keyType = OType . STRING ; String className = null ; String collate = null ; ODocument metadata = null ; final String ancestorClassName = getClassName ( elementClass ) ; // READ PARAMETERS for ( Parameter < ? , ? > p : indexParameters ) { if ( p . getKey ( ) . equals ( "type" ) ) indexType = p . getValue ( ) . toString ( ) . toUpperCase ( Locale . ENGLISH ) ; else if ( p . getKey ( ) . equals ( "keytype" ) ) keyType = OType . valueOf ( p . getValue ( ) . toString ( ) . toUpperCase ( Locale . ENGLISH ) ) ; else if ( p . getKey ( ) . equals ( "class" ) ) className = p . getValue ( ) . toString ( ) ; else if ( p . getKey ( ) . equals ( "collate" ) ) collate = p . getValue ( ) . toString ( ) ; else if ( p . getKey ( ) . toString ( ) . startsWith ( "metadata." ) ) { if ( metadata == null ) metadata = new ODocument ( ) ; metadata . field ( p . getKey ( ) . toString ( ) . substring ( "metadata." . length ( ) ) , p . getValue ( ) ) ; } } if ( className == null ) className = ancestorClassName ; final ODatabaseDocument db = getRawGraph ( ) ; final OSchema schema = db . getMetadata ( ) . getSchema ( ) ; final OClass cls = schema . getOrCreateClass ( className , schema . getClass ( ancestorClassName ) ) ; final OProperty property = cls . getProperty ( key ) ; if ( property != null ) keyType = property . getType ( ) ; OPropertyIndexDefinition indexDefinition = new OPropertyIndexDefinition ( className , key , keyType ) ; if ( collate != null ) indexDefinition . setCollate ( collate ) ; db . getMetadata ( ) . getIndexManager ( ) . createIndex ( className + "." + key , indexType , indexDefinition , cls . getPolymorphicClusterIds ( ) , null , metadata ) ; return null ; } } , "create key index on '" , elementClass . getSimpleName ( ) , "." , key , "'" ) ; }
Creates an automatic indexing structure for indexing provided key for element class .