idx
int64
0
165k
question
stringlengths
73
5.81k
target
stringlengths
5
918
15,500
protected void updateMixin ( NodeData node ) { NodeData prevData = ( NodeData ) cache . put ( new CacheId ( getOwnerId ( ) , node . getIdentifier ( ) ) , node , true ) ; if ( ! ( prevData instanceof NullNodeData ) ) { if ( prevData != null ) { if ( prevData . getACL ( ) == null || ! prevData . getACL ( ) . equals ( node . getACL ( ) ) ) { updateChildsACL ( node . getIdentifier ( ) , node . getACL ( ) ) ; } } else if ( LOG . isDebugEnabled ( ) ) { LOG . debug ( "Previous NodeData not found for mixin update " + node . getQPath ( ) . getAsString ( ) ) ; } } }
Update Node s mixin and ACL .
15,501
protected Set < String > updateTreePath ( QPath prevRootPath , QPath newRootPath , Set < String > idsToSkip ) { return caller . updateTreePath ( prevRootPath , newRootPath , idsToSkip ) ; }
Check all items in cache if it is a descendant of the previous root path and if so update the path according the new root path .
15,502
protected void renameItem ( final ItemState state , final ItemState lastDelete ) { ItemData data = state . getData ( ) ; ItemData prevData = getFromBufferedCacheById . run ( data . getIdentifier ( ) ) ; if ( data . isNode ( ) ) { if ( state . isPersisted ( ) ) { removeItem ( lastDelete . getData ( ) ) ; putItem ( state . getData ( ) ) ; } else { cache . put ( new CacheId ( getOwnerId ( ) , data . getIdentifier ( ) ) , data , false ) ; } } else { PropertyData prop = ( PropertyData ) data ; if ( prevData != null && ! ( prevData instanceof NullItemData ) ) { PropertyData newProp = new PersistedPropertyData ( prop . getIdentifier ( ) , prop . getQPath ( ) , prop . getParentIdentifier ( ) , prop . getPersistedVersion ( ) , prop . getType ( ) , prop . isMultiValued ( ) , ( ( PropertyData ) prevData ) . getValues ( ) , new SimplePersistedSize ( ( ( PersistedPropertyData ) prevData ) . getPersistedSize ( ) ) ) ; cache . put ( new CacheId ( getOwnerId ( ) , newProp . getIdentifier ( ) ) , newProp , false ) ; } else { cache . remove ( new CacheId ( getOwnerId ( ) , data . getIdentifier ( ) ) ) ; } } }
Apply rename operation on cache . Parent node will be re - added into the cache since parent or name might changing . For other children only item data will be replaced .
15,503
private void onCacheEntryUpdated ( ItemData data ) { if ( data == null || data instanceof NullItemData ) { return ; } for ( WorkspaceStorageCacheListener listener : listeners ) { try { listener . onCacheEntryUpdated ( data ) ; } catch ( RuntimeException e ) { LOG . warn ( "The method onCacheEntryUpdated fails for the listener " + listener . getClass ( ) , e ) ; } } }
Called when a cache entry corresponding to the given node has item updated
15,504
private static DNChar denormalize ( String string ) { if ( string . startsWith ( "&lt;" ) ) return new DNChar ( '<' , 4 ) ; else if ( string . startsWith ( "&gt;" ) ) return new DNChar ( '>' , 4 ) ; else if ( string . startsWith ( "&amp;" ) ) return new DNChar ( '&' , 5 ) ; else if ( string . startsWith ( "&quot;" ) ) return new DNChar ( '"' , 6 ) ; else if ( string . startsWith ( "&apos;" ) ) return new DNChar ( '\'' , 6 ) ; else if ( string . startsWith ( "_x000D_" ) ) return new DNChar ( '\r' , 7 ) ; else if ( string . startsWith ( "_x000A_" ) ) return new DNChar ( '\n' , 7 ) ; else if ( string . startsWith ( "_x0009_" ) ) return new DNChar ( '\t' , 7 ) ; else if ( string . startsWith ( "_x0020_" ) ) return new DNChar ( ' ' , 7 ) ; else if ( string . startsWith ( "_x005f_" ) ) return new DNChar ( '_' , 7 ) ; else throw new IllegalArgumentException ( ILLEGAL_DNCHAR ) ; }
Denormalizes and print the given character .
15,505
public File getFile ( String hash ) { return new File ( channel . rootDir , channel . makeFilePath ( hash , 0 ) ) ; }
Construct file name of given hash .
15,506
public MultiColumnQueryHits execute ( Query query , Sort sort , long resultFetchHint , InternalQName selectorName ) throws IOException { return new QueryHitsAdapter ( evaluate ( query , sort , resultFetchHint ) , selectorName ) ; }
Executes the query and returns the hits that match the query .
15,507
private boolean authenticate ( Session session , String userName , String password , PasswordEncrypter pe ) throws Exception { boolean authenticated ; Node userNode ; try { userNode = utils . getUserNode ( session , userName ) ; } catch ( PathNotFoundException e ) { return false ; } boolean enabled = userNode . canAddMixin ( JCROrganizationServiceImpl . JOS_DISABLED ) ; if ( ! enabled ) { throw new DisabledUserException ( userName ) ; } if ( pe == null ) { authenticated = utils . readString ( userNode , UserProperties . JOS_PASSWORD ) . equals ( password ) ; } else { String encryptedPassword = new String ( pe . encrypt ( utils . readString ( userNode , UserProperties . JOS_PASSWORD ) . getBytes ( ) ) ) ; authenticated = encryptedPassword . equals ( password ) ; } if ( authenticated ) { Calendar lastLoginTime = Calendar . getInstance ( ) ; userNode . setProperty ( UserProperties . JOS_LAST_LOGIN_TIME , lastLoginTime ) ; session . save ( ) ; } return authenticated ; }
Checks if credentials matches .
15,508
private void createUser ( Session session , UserImpl user , boolean broadcast ) throws Exception { Node userStorageNode = utils . getUsersStorageNode ( session ) ; Node userNode = userStorageNode . addNode ( user . getUserName ( ) ) ; if ( user . getCreatedDate ( ) == null ) { Calendar calendar = Calendar . getInstance ( ) ; user . setCreatedDate ( calendar . getTime ( ) ) ; } user . setInternalId ( userNode . getUUID ( ) ) ; if ( broadcast ) { preSave ( user , true ) ; } writeUser ( user , userNode ) ; session . save ( ) ; putInCache ( user ) ; if ( broadcast ) { postSave ( user , true ) ; } }
Persists new user .
15,509
private User removeUser ( Session session , String userName , boolean broadcast ) throws Exception { Node userNode = utils . getUserNode ( session , userName ) ; User user = readUser ( userNode ) ; if ( broadcast ) { preDelete ( user ) ; } removeMemberships ( userNode , broadcast ) ; userNode . remove ( ) ; session . save ( ) ; removeFromCache ( userName ) ; removeAllRelatedFromCache ( userName ) ; if ( broadcast ) { postDelete ( user ) ; } return user ; }
Remove user and related membership entities .
15,510
private void removeMemberships ( Node userNode , boolean broadcast ) throws RepositoryException { PropertyIterator refUserProps = userNode . getReferences ( ) ; while ( refUserProps . hasNext ( ) ) { Node refUserNode = refUserProps . nextProperty ( ) . getParent ( ) ; refUserNode . remove ( ) ; } }
Removes membership entities related to current user .
15,511
private void saveUser ( Session session , UserImpl user , boolean broadcast ) throws Exception { Node userNode = getUserNode ( session , user ) ; if ( broadcast ) { preSave ( user , false ) ; } String oldName = userNode . getName ( ) ; String newName = user . getUserName ( ) ; if ( ! oldName . equals ( newName ) ) { String oldPath = userNode . getPath ( ) ; String newPath = utils . getUserNodePath ( newName ) ; session . move ( oldPath , newPath ) ; removeFromCache ( oldName ) ; moveMembershipsInCache ( oldName , newName ) ; } writeUser ( user , userNode ) ; session . save ( ) ; putInCache ( user ) ; if ( broadcast ) { postSave ( user , false ) ; } }
Persists user .
15,512
private Node getUserNode ( Session session , UserImpl user ) throws RepositoryException { if ( user . getInternalId ( ) != null ) { return session . getNodeByUUID ( user . getInternalId ( ) ) ; } else { return utils . getUserNode ( session , user . getUserName ( ) ) ; } }
Returns user node by internal identifier or by name .
15,513
public UserImpl readUser ( Node userNode ) throws Exception { UserImpl user = new UserImpl ( userNode . getName ( ) ) ; Date creationDate = utils . readDate ( userNode , UserProperties . JOS_CREATED_DATE ) ; Date lastLoginTime = utils . readDate ( userNode , UserProperties . JOS_LAST_LOGIN_TIME ) ; String email = utils . readString ( userNode , UserProperties . JOS_EMAIL ) ; String password = utils . readString ( userNode , UserProperties . JOS_PASSWORD ) ; String firstName = utils . readString ( userNode , UserProperties . JOS_FIRST_NAME ) ; String lastName = utils . readString ( userNode , UserProperties . JOS_LAST_NAME ) ; String displayName = utils . readString ( userNode , UserProperties . JOS_DISPLAY_NAME ) ; boolean enabled = userNode . canAddMixin ( JCROrganizationServiceImpl . JOS_DISABLED ) ; user . setInternalId ( userNode . getUUID ( ) ) ; user . setCreatedDate ( creationDate ) ; user . setLastLoginTime ( lastLoginTime ) ; user . setEmail ( email ) ; user . setPassword ( password ) ; user . setFirstName ( firstName ) ; user . setLastName ( lastName ) ; user . setDisplayName ( displayName ) ; user . setEnabled ( enabled ) ; return user ; }
Read user properties from the node in the storage .
15,514
private void writeUser ( User user , Node node ) throws Exception { node . setProperty ( UserProperties . JOS_EMAIL , user . getEmail ( ) ) ; node . setProperty ( UserProperties . JOS_FIRST_NAME , user . getFirstName ( ) ) ; node . setProperty ( UserProperties . JOS_LAST_NAME , user . getLastName ( ) ) ; node . setProperty ( UserProperties . JOS_PASSWORD , user . getPassword ( ) ) ; node . setProperty ( UserProperties . JOS_DISPLAY_NAME , user . getDisplayName ( ) ) ; node . setProperty ( UserProperties . JOS_USER_NAME , node . getName ( ) ) ; Calendar calendar = Calendar . getInstance ( ) ; calendar . setTime ( user . getCreatedDate ( ) ) ; node . setProperty ( UserProperties . JOS_CREATED_DATE , calendar ) ; }
Write user properties from the node to the storage .
15,515
void migrateUser ( Node oldUserNode ) throws Exception { String userName = oldUserNode . getName ( ) ; if ( findUserByName ( userName , UserStatus . ANY ) != null ) { removeUser ( userName , false ) ; } UserImpl user = readUser ( oldUserNode ) ; createUser ( user , false ) ; }
Method for user migration .
15,516
private void preSave ( User user , boolean isNew ) throws Exception { for ( UserEventListener listener : listeners ) { listener . preSave ( user , isNew ) ; } }
Notifying listeners before user creation .
15,517
private void postSave ( User user , boolean isNew ) throws Exception { for ( UserEventListener listener : listeners ) { listener . postSave ( user , isNew ) ; } }
Notifying listeners after user creation .
15,518
private void preDelete ( User user ) throws Exception { for ( UserEventListener listener : listeners ) { listener . preDelete ( user ) ; } }
Notifying listeners before user deletion .
15,519
private void postDelete ( User user ) throws Exception { for ( UserEventListener listener : listeners ) { listener . postDelete ( user ) ; } }
Notifying listeners after user deletion .
15,520
private void removeAllRelatedFromCache ( String userName ) { cache . remove ( userName , CacheType . USER_PROFILE ) ; cache . remove ( CacheHandler . USER_PREFIX + userName , CacheType . MEMBERSHIP ) ; }
Remove user and related entities from cache .
15,521
private User getFromCache ( String userName ) { return ( User ) cache . get ( userName , CacheType . USER ) ; }
Get user from cache .
15,522
private void moveMembershipsInCache ( String oldName , String newName ) { cache . move ( CacheHandler . USER_PREFIX + oldName , CacheHandler . USER_PREFIX + newName , CacheType . MEMBERSHIP ) ; }
Move memberships entities from old key to new one .
15,523
private void putInCache ( User user ) { cache . put ( user . getUserName ( ) , user , CacheType . USER ) ; }
Put user in cache .
15,524
public PersistedValueData read ( ObjectReader in , int type ) throws UnknownClassIdException , IOException { File tempDirectory = new File ( SerializationConstants . TEMP_DIR ) ; PrivilegedFileHelper . mkdirs ( tempDirectory ) ; int key ; if ( ( key = in . readInt ( ) ) != SerializationConstants . PERSISTED_VALUE_DATA ) { throw new UnknownClassIdException ( "There is unexpected class [" + key + "]" ) ; } int orderNumber = in . readInt ( ) ; boolean isByteArray = in . readBoolean ( ) ; if ( isByteArray ) { byte [ ] data = new byte [ in . readInt ( ) ] ; in . readFully ( data ) ; return ValueDataUtil . createValueData ( type , orderNumber , data ) ; } else { String id = in . readString ( ) ; long length = in . readLong ( ) ; SerializationSpoolFile sf = holder . get ( id ) ; if ( sf == null ) { if ( length == SerializationConstants . NULL_FILE ) { return new StreamPersistedValueData ( orderNumber , ( SerializationSpoolFile ) null , spoolConfig ) ; } sf = new SerializationSpoolFile ( tempDirectory , id , holder ) ; writeToFile ( in , sf , length ) ; holder . put ( id , sf ) ; return new StreamPersistedValueData ( orderNumber , sf , spoolConfig ) ; } else { sf . acquire ( this ) ; try { PersistedValueData vd = new StreamPersistedValueData ( orderNumber , sf , spoolConfig ) ; if ( in . skip ( length ) != length ) { throw new IOException ( "Content isn't skipped correctly." ) ; } return vd ; } finally { sf . release ( this ) ; } } } }
Read and set PersistedValueData object data .
15,525
private void readFully ( ByteBuffer dst ) throws IOException { int r = channel . read ( dst ) ; if ( r < 0 ) throw new EOFException ( ) ; if ( r < dst . capacity ( ) && r > 0 ) throw new StreamCorruptedException ( "Unexpected EOF in middle of data block." ) ; }
Reads a sequence of bytes from file into the given buffer .
15,526
public void register ( SearchManager searchManager , SearchManager parentSearchManager , QueryHandler handler , QueryHandler parentHandler ) throws RepositoryConfigurationException { indexers . put ( searchManager . getWsId ( ) , new Indexer ( searchManager , parentSearchManager , handler , parentHandler ) ) ; if ( LOG . isDebugEnabled ( ) ) { LOG . debug ( "Register " + searchManager . getWsId ( ) + " " + this + " in " + indexers ) ; } }
This method will register a new Indexer according to the given parameters .
15,527
public static String getNodeType ( String nodeTypeHeader , String defaultNodeType , Set < String > allowedNodeTypes ) throws NoSuchNodeTypeException { if ( nodeTypeHeader == null ) { return defaultNodeType ; } if ( allowedNodeTypes . contains ( nodeTypeHeader ) ) { return nodeTypeHeader ; } throw new NoSuchNodeTypeException ( "Unsupported node type: " + nodeTypeHeader ) ; }
Returns parsed nodeType obtained from node - type header . This method is unified for files and folders .
15,528
public static String getContentNodeType ( String contentNodeTypeHeader ) { if ( contentNodeTypeHeader != null ) return contentNodeTypeHeader ; else return WebDavConst . NodeTypes . NT_RESOURCE ; }
Returns the NodeType of content node according to the Content - NodeType header .
15,529
public static ArrayList < String > getMixinTypes ( String mixinTypes ) { return mixinTypes == null ? new ArrayList < String > ( ) : new ArrayList < String > ( Arrays . asList ( mixinTypes . split ( "," ) ) ) ; }
Returns the list of node mixins .
15,530
public TransactionChangesLog read ( ObjectReader in ) throws UnknownClassIdException , IOException { int key ; if ( ( key = in . readInt ( ) ) != SerializationConstants . TRANSACTION_CHANGES_LOG ) { throw new UnknownClassIdException ( "There is unexpected class [" + key + "]" ) ; } TransactionChangesLog log = new TransactionChangesLog ( ) ; if ( in . readByte ( ) == SerializationConstants . NOT_NULL_DATA ) { log . setSystemId ( in . readString ( ) ) ; } while ( in . readByte ( ) == SerializationConstants . NOT_NULL_DATA ) { PlainChangesLogReader rdr = new PlainChangesLogReader ( holder , spoolConfig ) ; PlainChangesLog pl = rdr . read ( in ) ; log . addLog ( pl ) ; } return log ; }
Read and set TransactionChangesLog data .
15,531
public void setRelativePath ( QPath relPath ) { if ( relPath != null && relPath . isAbsolute ( ) ) { throw new IllegalArgumentException ( "relPath must be relative" ) ; } this . relPath = relPath ; }
Sets the relative path to the property in this relation .
15,532
public long getRepositoryDataSizeDirectly ( ) throws QuotaManagerException { long size = 0 ; for ( WorkspaceQuotaManager wQuotaManager : wsQuotaManagers . values ( ) ) { size += wQuotaManager . getWorkspaceDataSizeDirectly ( ) ; } return size ; }
Returns repository data size by summing size of all workspaces .
15,533
private EditableValueData createEditableCopy ( ValueData oldValue ) throws RepositoryException , IllegalStateException , IOException { if ( oldValue . isByteArray ( ) ) { byte [ ] oldBytes = oldValue . getAsByteArray ( ) ; byte [ ] newBytes = new byte [ oldBytes . length ] ; System . arraycopy ( oldBytes , 0 , newBytes , 0 , newBytes . length ) ; try { return new EditableValueData ( newBytes , oldValue . getOrderNumber ( ) ) ; } catch ( IOException e ) { throw new RepositoryException ( e ) ; } } else { try { return new EditableValueData ( oldValue . getAsStream ( ) , oldValue . getOrderNumber ( ) , spoolConfig ) ; } catch ( FileNotFoundException e ) { throw new RepositoryException ( "Create editable copy error. " + e , e ) ; } catch ( IOException e ) { throw new RepositoryException ( "Create editable copy error. " + e , e ) ; } } }
Create editable ValueData copy .
15,534
private static String getRepoWS ( String [ ] args , int curArg ) { if ( curArg == args . length ) { System . out . println ( INCORRECT_PARAM + "There is no path to workspace parameter." ) ; return null ; } String repWS = args [ curArg ] ; repWS = repWS . replaceAll ( "\\\\" , "/" ) ; if ( ! repWS . matches ( "[/][^/]+" ) && ! repWS . matches ( "[/][^/]+[/][^/]+" ) ) { System . out . println ( INCORRECT_PARAM + "There is incorrect path to workspace parameter: " + repWS ) ; return null ; } else { return repWS ; } }
Get parameter from argument list check it and return as valid path to repository and workspace .
15,535
protected int getStartValue ( Connection con ) { Statement stmt = null ; ResultSet trs = null ; try { String query ; String tableItem = DBInitializerHelper . getItemTableName ( containerConfig ) ; if ( JDBCUtils . tableExists ( tableItem , con ) ) { query = "select max(N_ORDER_NUM) from " + tableItem ; } else { return - 1 ; } stmt = con . createStatement ( ) ; trs = stmt . executeQuery ( query ) ; if ( trs . next ( ) && trs . getInt ( 1 ) >= 0 ) { return trs . getInt ( 1 ) ; } else { return - 1 ; } } catch ( SQLException e ) { if ( LOG . isDebugEnabled ( ) ) { LOG . debug ( "SQLException occurred while calculate the sequence start value" , e ) ; } return - 1 ; } finally { JDBCUtils . freeResources ( trs , stmt , null ) ; } }
Init Start value for sequence .
15,536
public Query like ( int docNum ) throws IOException { if ( fieldNames == null ) { setFieldNames ( ) ; } return createQuery ( retrieveTerms ( docNum ) ) ; }
Return a query that will return docs like the passed lucene document ID .
15,537
public Query like ( File f ) throws IOException { if ( fieldNames == null ) { setFieldNames ( ) ; } return like ( new FileReader ( f ) ) ; }
Return a query that will return docs like the passed file .
15,538
public Query like ( URL u ) throws IOException { return like ( new InputStreamReader ( u . openConnection ( ) . getInputStream ( ) ) ) ; }
Return a query that will return docs like the passed URL .
15,539
public Query like ( java . io . InputStream is ) throws IOException { return like ( new InputStreamReader ( is ) ) ; }
Return a query that will return docs like the passed stream .
15,540
public String describeParams ( ) { StringBuilder sb = new StringBuilder ( ) ; sb . append ( "\t" + "maxQueryTerms : " + maxQueryTerms + "\n" ) ; sb . append ( "\t" + "minWordLen : " + minWordLen + "\n" ) ; sb . append ( "\t" + "maxWordLen : " + maxWordLen + "\n" ) ; sb . append ( "\t" + "fieldNames : " ) ; String delim = "" ; for ( int i = 0 ; i < fieldNames . length ; i ++ ) { String fieldName = fieldNames [ i ] ; sb . append ( delim ) . append ( fieldName ) ; delim = ", " ; } sb . append ( "\n" ) ; sb . append ( "\t" + "boost : " + boost + "\n" ) ; sb . append ( "\t" + "minTermFreq : " + minTermFreq + "\n" ) ; sb . append ( "\t" + "minDocFreq : " + minDocFreq + "\n" ) ; return sb . toString ( ) ; }
Describe the parameters that control how the more like this query is formed .
15,541
public PriorityQueue < Object [ ] > retrieveTerms ( int docNum ) throws IOException { Map < String , Int > termFreqMap = new HashMap < String , Int > ( ) ; for ( int i = 0 ; i < fieldNames . length ; i ++ ) { String fieldName = fieldNames [ i ] ; TermFreqVector vector = ir . getTermFreqVector ( docNum , fieldName ) ; if ( vector == null ) { Document d = ir . document ( docNum ) ; String [ ] text = d . getValues ( fieldName ) ; if ( text != null ) { for ( int j = 0 ; j < text . length ; j ++ ) { addTermFrequencies ( new StringReader ( text [ j ] ) , termFreqMap , fieldName ) ; } } } else { addTermFrequencies ( termFreqMap , vector ) ; } } return createQueue ( termFreqMap ) ; }
Find words for a more - like - this query former .
15,542
private void addTermFrequencies ( Map < String , Int > termFreqMap , TermFreqVector vector ) { String [ ] terms = vector . getTerms ( ) ; int [ ] freqs = vector . getTermFrequencies ( ) ; for ( int j = 0 ; j < terms . length ; j ++ ) { String term = terms [ j ] ; if ( isNoiseWord ( term ) ) { continue ; } Int cnt = termFreqMap . get ( term ) ; if ( cnt == null ) { cnt = new Int ( ) ; termFreqMap . put ( term , cnt ) ; cnt . x = freqs [ j ] ; } else { cnt . x += freqs [ j ] ; } } }
Adds terms and frequencies found in vector into the Map termFreqMap
15,543
private void addTermFrequencies ( Reader r , Map < String , Int > termFreqMap , String fieldName ) throws IOException { TokenStream ts = analyzer . tokenStream ( fieldName , r ) ; int tokenCount = 0 ; while ( ts . incrementToken ( ) ) { CharTermAttribute term = ts . getAttribute ( CharTermAttribute . class ) ; String word = new String ( term . buffer ( ) , 0 , term . length ( ) ) ; tokenCount ++ ; if ( tokenCount > maxNumTokensParsed ) { break ; } if ( isNoiseWord ( word ) ) { continue ; } Int cnt = termFreqMap . get ( word ) ; if ( cnt == null ) { termFreqMap . put ( word , new Int ( ) ) ; } else { cnt . x ++ ; } } ts . end ( ) ; ts . close ( ) ; }
Adds term frequencies found by tokenizing text from reader into the Map words
15,544
private boolean isNoiseWord ( String term ) { int len = term . length ( ) ; if ( minWordLen > 0 && len < minWordLen ) { return true ; } if ( maxWordLen > 0 && len > maxWordLen ) { return true ; } if ( stopWords != null && stopWords . contains ( term ) ) { return true ; } return false ; }
determines if the passed term is likely to be of interest in more like comparisons
15,545
protected String handleAddException ( IOException e , ItemData item ) throws RepositoryException , InvalidItemStateException { StringBuilder message = new StringBuilder ( "[" ) ; message . append ( containerName ) . append ( "] ADD " ) . append ( item . isNode ( ) ? "NODE. " : "PROPERTY. " ) ; String errMessage = e . getMessage ( ) ; String itemInfo = item . getQPath ( ) . getAsString ( ) + ", ID: " + item . getIdentifier ( ) + ", ParentID: " + item . getParentIdentifier ( ) + ( errMessage != null ? ". Cause >>>> " + errMessage : "" ) ; RepositoryException ownException = null ; try { NodeData parent = ( NodeData ) conn . getItemData ( item . getParentIdentifier ( ) ) ; if ( parent != null ) { try { ItemData me = conn . getItemData ( item . getIdentifier ( ) ) ; if ( me != null ) { message . append ( "Item already exists in storage: " ) . append ( itemInfo ) ; ownException = new ItemExistsException ( message . toString ( ) , e ) ; throw ownException ; } me = conn . getItemData ( parent , new QPathEntry ( item . getQPath ( ) . getName ( ) , item . getQPath ( ) . getIndex ( ) ) , ItemType . getItemType ( item ) ) ; if ( me != null ) { message . append ( "Item already exists in storage: " ) . append ( itemInfo ) ; ownException = new ItemExistsException ( message . toString ( ) , e ) ; throw ownException ; } } catch ( Exception ep ) { if ( ownException != null ) throw ownException ; } message . append ( "Error of item add. " ) . append ( itemInfo ) ; ownException = new RepositoryException ( message . toString ( ) , e ) ; throw ownException ; } } catch ( Exception ep ) { if ( ownException != null ) throw ownException ; } message . append ( "Error of item add. " ) . append ( itemInfo ) ; throw new JCRInvalidItemStateException ( message . toString ( ) , item . getIdentifier ( ) , ItemState . ADDED , e ) ; }
Handle Add IOException .
15,546
public String handleDeleteException ( SQLException e , ItemData item ) throws RepositoryException , InvalidItemStateException { StringBuilder message = new StringBuilder ( "[" ) ; message . append ( containerName ) . append ( "] DELETE " ) . append ( item . isNode ( ) ? "NODE. " : "PROPERTY. " ) ; String errMessage = e . getMessage ( ) ; String itemInfo = item . getQPath ( ) . getAsString ( ) + " " + item . getIdentifier ( ) + ( errMessage != null ? ". Cause >>>> " + errMessage : "" ) ; if ( errMessage != null ) { String umsg = errMessage . toLowerCase ( ) . toUpperCase ( ) ; if ( umsg . indexOf ( conn . JCR_FK_ITEM_PARENT ) >= 0 ) { message . append ( "Can not delete parent till childs exists. Item " ) . append ( itemInfo ) ; throw new JCRInvalidItemStateException ( message . toString ( ) , item . getIdentifier ( ) , ItemState . DELETED , e ) ; } else if ( umsg . indexOf ( conn . JCR_FK_VALUE_PROPERTY ) >= 0 ) { message . append ( "[FATAL] Can not delete property item till it contains values. Condition: property ID. " ) . append ( itemInfo ) ; throw new RepositoryException ( message . toString ( ) , e ) ; } } message . append ( "Error of item delete " ) . append ( itemInfo ) ; throw new RepositoryException ( message . toString ( ) , e ) ; }
Handle delete Exceptions .
15,547
public String handleUpdateException ( SQLException e , ItemData item ) throws RepositoryException , InvalidItemStateException { StringBuilder message = new StringBuilder ( "[" ) ; message . append ( containerName ) . append ( "] EDIT " ) . append ( item . isNode ( ) ? "NODE. " : "PROPERTY. " ) ; String errMessage = e . getMessage ( ) ; String itemInfo = item . getQPath ( ) . getAsString ( ) + " " + item . getIdentifier ( ) + ( errMessage != null ? ". Cause >>>> " + errMessage : "" ) ; if ( errMessage != null ) if ( errMessage . toLowerCase ( ) . toUpperCase ( ) . indexOf ( conn . JCR_FK_VALUE_PROPERTY ) >= 0 ) { message . append ( "Property is not exists but the value is being created. Condition: property ID. " ) . append ( itemInfo ) ; throw new RepositoryException ( message . toString ( ) , e ) ; } else if ( errMessage . toLowerCase ( ) . toUpperCase ( ) . indexOf ( conn . JCR_PK_ITEM ) >= 0 ) { message . append ( "Item already exists. Condition: ID. " ) . append ( itemInfo ) ; throw new JCRInvalidItemStateException ( message . toString ( ) , item . getIdentifier ( ) , ItemState . UPDATED , e ) ; } RepositoryException ownException = null ; try { ItemData me = conn . getItemData ( item . getIdentifier ( ) ) ; if ( me != null ) { message . append ( "Item already exists. But update errors. " ) . append ( itemInfo ) ; ownException = new RepositoryException ( message . toString ( ) , e ) ; throw ownException ; } } catch ( Exception ep ) { if ( ownException != null ) throw ownException ; } message . append ( "Error of item update. " ) . append ( itemInfo ) ; throw new JCRInvalidItemStateException ( message . toString ( ) , item . getIdentifier ( ) , ItemState . UPDATED , e ) ; }
Handle update Exceptions .
15,548
public PropertyDataReader forProperty ( InternalQName name , int type ) { if ( nodePropertyReader == null ) { nodePropertyReader = new PropertyDataReader ( parent , dataManager ) ; } return nodePropertyReader . forProperty ( name , type ) ; }
Read node properties
15,549
public List < ChangesContainer > getSortedList ( ) { List < ChangesContainer > changesContainers = new ArrayList < ChangesContainer > ( changes ) ; Collections . sort ( changesContainers ) ; return changesContainers ; }
Builds single list of modifications from internal structures and sorts it .
15,550
private void createMembership ( Session session , MembershipImpl membership , boolean broadcast ) throws InvalidNameException , Exception { Node userNode ; try { userNode = utils . getUserNode ( session , membership . getUserName ( ) ) ; } catch ( PathNotFoundException e ) { throw new InvalidNameException ( "The user " + membership . getUserName ( ) + " does not exist" ) ; } Node groupNode ; try { groupNode = utils . getGroupNode ( session , membership . getGroupId ( ) ) ; } catch ( PathNotFoundException e ) { throw new InvalidNameException ( "The group " + membership . getGroupId ( ) + " does not exist" ) ; } Node typeNode ; String membershipType = membership . getMembershipType ( ) . equals ( MembershipTypeHandler . ANY_MEMBERSHIP_TYPE ) ? JCROrganizationServiceImpl . JOS_MEMBERSHIP_TYPE_ANY : membership . getMembershipType ( ) ; try { typeNode = utils . getMembershipTypeNode ( session , membershipType ) ; } catch ( PathNotFoundException e ) { throw new InvalidNameException ( "The membership type " + membership . getMembershipType ( ) + " does not exist" ) ; } Node membershipStorageNode = groupNode . getNode ( JCROrganizationServiceImpl . JOS_MEMBERSHIP ) ; Node refUserNode ; try { refUserNode = membershipStorageNode . addNode ( membership . getUserName ( ) ) ; refUserNode . setProperty ( MembershipProperties . JOS_USER , userNode ) ; } catch ( ItemExistsException e ) { refUserNode = membershipStorageNode . getNode ( membership . getUserName ( ) ) ; } Node refTypeNode ; try { refTypeNode = refUserNode . addNode ( membershipType ) ; refTypeNode . setProperty ( MembershipProperties . JOS_MEMBERSHIP_TYPE , typeNode ) ; } catch ( ItemExistsException e ) { return ; } String id = utils . composeMembershipId ( groupNode , refUserNode , refTypeNode ) ; membership . setId ( id ) ; if ( broadcast ) { preSave ( membership , true ) ; } session . save ( ) ; putInCache ( membership ) ; if ( broadcast ) { postSave ( membership , true ) ; } }
Persist new membership .
15,551
private MembershipByUserGroupTypeWrapper findMembership ( Session session , String id ) throws Exception { IdComponents ids ; try { ids = utils . splitId ( id ) ; } catch ( IndexOutOfBoundsException e ) { throw new ItemNotFoundException ( "Can not find membership by id=" + id , e ) ; } Node groupNode = session . getNodeByUUID ( ids . groupNodeId ) ; Node refUserNode = groupNode . getNode ( JCROrganizationServiceImpl . JOS_MEMBERSHIP ) . getNode ( ids . userName ) ; Node refTypeNode = refUserNode . getNode ( ids . type . equals ( MembershipTypeHandler . ANY_MEMBERSHIP_TYPE ) ? JCROrganizationServiceImpl . JOS_MEMBERSHIP_TYPE_ANY : ids . type ) ; String groupId = utils . getGroupIds ( groupNode ) . groupId ; MembershipImpl membership = new MembershipImpl ( ) ; membership . setId ( id ) ; membership . setGroupId ( groupId ) ; membership . setMembershipType ( ids . type ) ; membership . setUserName ( ids . userName ) ; putInCache ( membership ) ; return new MembershipByUserGroupTypeWrapper ( membership , refUserNode , refTypeNode ) ; }
Use this method to search for an membership record with the given id .
15,552
private Membership findMembershipByUserGroupAndType ( Session session , String userName , String groupId , String type ) throws Exception { MembershipImpl membership = getFromCache ( userName , groupId , type ) ; if ( membership != null ) { return membership ; } try { Node groupNode = utils . getGroupNode ( session , groupId ) ; Node refUserNode = groupNode . getNode ( JCROrganizationServiceImpl . JOS_MEMBERSHIP ) . getNode ( userName ) ; Node refTypeNode = refUserNode . getNode ( type . equals ( MembershipTypeHandler . ANY_MEMBERSHIP_TYPE ) ? JCROrganizationServiceImpl . JOS_MEMBERSHIP_TYPE_ANY : type ) ; String id = utils . composeMembershipId ( groupNode , refUserNode , refTypeNode ) ; membership = new MembershipImpl ( ) ; membership . setGroupId ( groupId ) ; membership . setUserName ( userName ) ; membership . setMembershipType ( type ) ; membership . setId ( id ) ; putInCache ( membership ) ; return membership ; } catch ( PathNotFoundException e ) { return null ; } }
Use this method to search for a specific membership type of an user in a group .
15,553
private Collection < Membership > findMembershipsByGroup ( Session session , Group group ) throws Exception { Node groupNode ; NodeIterator refUsers ; try { groupNode = utils . getGroupNode ( session , group ) ; refUsers = groupNode . getNode ( JCROrganizationServiceImpl . JOS_MEMBERSHIP ) . getNodes ( ) ; } catch ( PathNotFoundException e ) { return new ArrayList < Membership > ( ) ; } List < Membership > memberships = new ArrayList < Membership > ( ) ; while ( refUsers . hasNext ( ) ) { Node refUserNode = refUsers . nextNode ( ) ; memberships . addAll ( findMembershipsByUserAndGroup ( session , refUserNode , groupNode ) ) ; } return memberships ; }
Use this method to find all the membership in a group .
15,554
private MembershipsByUserWrapper findMembershipsByUser ( Session session , String userName ) throws Exception { Node userNode ; try { userNode = utils . getUserNode ( session , userName ) ; } catch ( PathNotFoundException e ) { return new MembershipsByUserWrapper ( new ArrayList < Membership > ( ) , new ArrayList < Node > ( ) ) ; } List < Membership > memberships = new ArrayList < Membership > ( ) ; List < Node > refUserNodes = new ArrayList < Node > ( ) ; PropertyIterator refUserProps = userNode . getReferences ( ) ; while ( refUserProps . hasNext ( ) ) { Node refUserNode = refUserProps . nextProperty ( ) . getParent ( ) ; Node groupNode = refUserNode . getParent ( ) . getParent ( ) ; memberships . addAll ( findMembershipsByUserAndGroup ( session , refUserNode , groupNode ) ) ; refUserNodes . add ( refUserNode ) ; } return new MembershipsByUserWrapper ( memberships , refUserNodes ) ; }
Use this method to find all the memberships of an user in any group .
15,555
void migrateMemberships ( Node oldUserNode ) throws Exception { Session session = oldUserNode . getSession ( ) ; NodeIterator iterator = ( ( ExtendedNode ) oldUserNode ) . getNodesLazily ( ) ; while ( iterator . hasNext ( ) ) { Node oldMembershipNode = iterator . nextNode ( ) ; if ( oldMembershipNode . isNodeType ( MigrationTool . JOS_USER_MEMBERSHIP ) ) { String oldGroupUUID = utils . readString ( oldMembershipNode , MigrationTool . JOS_GROUP ) ; String oldMembershipTypeUUID = utils . readString ( oldMembershipNode , MembershipProperties . JOS_MEMBERSHIP_TYPE ) ; String userName = oldUserNode . getName ( ) ; String groupId = utils . readString ( session . getNodeByUUID ( oldGroupUUID ) , MigrationTool . JOS_GROUP_ID ) ; String membershipTypeName = session . getNodeByUUID ( oldMembershipTypeUUID ) . getName ( ) ; User user = service . getUserHandler ( ) . findUserByName ( userName ) ; Group group = service . getGroupHandler ( ) . findGroupById ( groupId ) ; MembershipType mt = service . getMembershipTypeHandler ( ) . findMembershipType ( membershipTypeName ) ; Membership existingMembership = findMembershipByUserGroupAndType ( userName , groupId , membershipTypeName ) ; if ( existingMembership != null ) { removeMembership ( existingMembership . getId ( ) , false ) ; } linkMembership ( user , group , mt , false ) ; } } }
Migrates user memberships from old storage into new .
15,556
private Membership removeMembership ( Session session , String id , boolean broadcast ) throws Exception { MembershipByUserGroupTypeWrapper mWrapper ; try { mWrapper = findMembership ( session , id ) ; } catch ( ItemNotFoundException e ) { return null ; } catch ( PathNotFoundException e ) { return null ; } if ( broadcast ) { preDelete ( mWrapper . membership ) ; } removeMembership ( mWrapper . refUserNode , mWrapper . refTypeNode ) ; session . save ( ) ; removeFromCache ( mWrapper . membership ) ; if ( broadcast ) { postDelete ( mWrapper . membership ) ; } return mWrapper . membership ; }
Remove memberships entity by identifier .
15,557
void removeMembership ( Node refUserNode , Node refTypeNode ) throws Exception { refTypeNode . remove ( ) ; if ( ! refUserNode . hasNodes ( ) ) { refUserNode . remove ( ) ; } }
Remove membership record .
15,558
private Collection < Membership > removeMembershipByUser ( Session session , String userName , boolean broadcast ) throws Exception { MembershipsByUserWrapper mWrapper = findMembershipsByUser ( session , userName ) ; if ( broadcast ) { for ( Membership m : mWrapper . memberships ) { preDelete ( m ) ; } } for ( Node refUserNode : mWrapper . refUserNodes ) { refUserNode . remove ( ) ; } session . save ( ) ; removeFromCache ( CacheHandler . USER_PREFIX + userName ) ; if ( broadcast ) { for ( Membership m : mWrapper . memberships ) { postDelete ( m ) ; } } return mWrapper . memberships ; }
Remove memberships entities related to current user .
15,559
private MembershipImpl getFromCache ( String userName , String groupId , String type ) { return ( MembershipImpl ) cache . get ( cache . getMembershipKey ( userName , groupId , type ) , CacheType . MEMBERSHIP ) ; }
Gets membership entity from cache .
15,560
private void removeFromCache ( Membership membership ) { cache . remove ( cache . getMembershipKey ( membership ) , CacheType . MEMBERSHIP ) ; }
Removes membership entities from cache .
15,561
private void putInCache ( MembershipImpl membership ) { cache . put ( cache . getMembershipKey ( membership ) , membership , CacheType . MEMBERSHIP ) ; }
Adds membership entity into cache .
15,562
private void preSave ( Membership membership , boolean isNew ) throws Exception { for ( MembershipEventListener listener : listeners ) { listener . preSave ( membership , isNew ) ; } }
Notifying listeners before membership creation .
15,563
private void postSave ( Membership membership , boolean isNew ) throws Exception { for ( MembershipEventListener listener : listeners ) { listener . postSave ( membership , isNew ) ; } }
Notifying listeners after membership creation .
15,564
private void preDelete ( Membership membership ) throws Exception { for ( MembershipEventListener listener : listeners ) { listener . preDelete ( membership ) ; } }
Notifying listeners before membership deletion .
15,565
private void postDelete ( Membership membership ) throws Exception { for ( MembershipEventListener listener : listeners ) { listener . postDelete ( membership ) ; } }
Notifying listeners after membership deletion .
15,566
protected Node createNode ( final Node parentNode , final String nodeName , final String nodeType , final List < String > mixinTypes , final Map < String , String [ ] > permissions , final boolean isLeaf , final boolean callSave ) throws RepositoryException { boolean useParameters = ! useParametersOnLeafOnly ( ) || ( useParametersOnLeafOnly ( ) && isLeaf ) ; Node node ; if ( nodeType == null || nodeType . isEmpty ( ) || ! useParameters ) { node = parentNode . addNode ( nodeName , DEFAULT_NODE_TYPE ) ; } else { node = parentNode . addNode ( nodeName , nodeType ) ; } if ( node . getIndex ( ) > 1 ) { parentNode . refresh ( false ) ; return parentNode . getNode ( nodeName ) ; } if ( useParameters ) { if ( permissions != null && ! permissions . isEmpty ( ) ) { if ( node . canAddMixin ( "exo:privilegeable" ) ) { node . addMixin ( "exo:privilegeable" ) ; } ( ( ExtendedNode ) node ) . setPermissions ( permissions ) ; } if ( mixinTypes != null ) { for ( int i = 0 , length = mixinTypes . size ( ) ; i < length ; i ++ ) { String mixin = mixinTypes . get ( i ) ; if ( node . canAddMixin ( mixin ) ) { node . addMixin ( mixin ) ; } } } } if ( callSave ) { try { parentNode . save ( ) ; } catch ( ItemExistsException e ) { if ( LOG . isTraceEnabled ( ) ) { LOG . trace ( "An exception occurred: " + e . getMessage ( ) ) ; } parentNode . refresh ( false ) ; while ( ! parentNode . hasNode ( nodeName ) ) ; return parentNode . getNode ( nodeName ) ; } } return node ; }
Creates the node of the given node type with the given node name directly under the given parent node using the given mixin types and permissions
15,567
public NodeTypeIterator getMixinNodeTypes ( ) throws RepositoryException { List < NodeTypeData > allNodeTypes = typesManager . getAllNodeTypes ( ) ; Collections . sort ( allNodeTypes , new NodeTypeDataComparator ( ) ) ; EntityCollection ec = new EntityCollection ( ) ; for ( NodeTypeData nodeTypeData : allNodeTypes ) { if ( nodeTypeData . isMixin ( ) ) { ec . add ( new NodeTypeImpl ( nodeTypeData , typesManager , this , locationFactory , valueFactory , dataManager ) ) ; } } return ec ; }
Returns an iterator over all available mixin node types .
15,568
public NodeTypeIterator getPrimaryNodeTypes ( ) throws RepositoryException { EntityCollection ec = new EntityCollection ( ) ; NodeTypeIterator allTypes = getAllNodeTypes ( ) ; while ( allTypes . hasNext ( ) ) { NodeType type = allTypes . nextNodeType ( ) ; if ( ! type . isMixin ( ) ) { ec . add ( type ) ; } } return ec ; }
Returns an iterator over all available primary node types .
15,569
public final Map < String , Set < HierarchicalProperty > > getPropStats ( ) throws RepositoryException { String statname = WebDavConst . getStatusDescription ( HTTPStatus . OK ) ; if ( propNames == null ) { propStats . put ( statname , resource . getProperties ( namesOnly ) ) ; } else { if ( propNames . contains ( PropertyConstants . DAV_ALLPROP_INCLUDE ) ) { propStats . put ( statname , resource . getProperties ( namesOnly ) ) ; propNames . remove ( PropertyConstants . DAV_ALLPROP_INCLUDE ) ; } for ( QName propName : propNames ) { HierarchicalProperty prop = new HierarchicalProperty ( propName ) ; try { if ( propName . equals ( PropertyConstants . IS_READ_ONLY ) && session != null ) { if ( isReadOnly ( ) ) { prop . setValue ( "1" ) ; } else { prop . setValue ( "0" ) ; } statname = WebDavConst . getStatusDescription ( HTTPStatus . OK ) ; } else { prop = resource . getProperty ( propName ) ; statname = WebDavConst . getStatusDescription ( HTTPStatus . OK ) ; } } catch ( AccessDeniedException exc ) { statname = WebDavConst . getStatusDescription ( HTTPStatus . FORBIDDEN ) ; LOG . error ( exc . getMessage ( ) , exc ) ; } catch ( ItemNotFoundException exc ) { statname = WebDavConst . getStatusDescription ( HTTPStatus . NOT_FOUND ) ; } catch ( PathNotFoundException e ) { statname = WebDavConst . getStatusDescription ( HTTPStatus . NOT_FOUND ) ; } catch ( RepositoryException e ) { statname = WebDavConst . getStatusDescription ( HTTPStatus . INTERNAL_ERROR ) ; } if ( ! propStats . containsKey ( statname ) ) { propStats . put ( statname , new HashSet < HierarchicalProperty > ( ) ) ; } Set < HierarchicalProperty > propSet = propStats . get ( statname ) ; propSet . add ( prop ) ; } } return propStats ; }
Returns properties statuses .
15,570
public ItemData getItemData ( String identifier , boolean checkChangesLogOnly ) throws RepositoryException { if ( txStarted ( ) ) { ItemState state = transactionLog . getItemState ( identifier ) ; if ( state != null ) { return state . isDeleted ( ) ? null : state . getData ( ) ; } } return ( checkChangesLogOnly ) ? null : storageDataManager . getItemData ( identifier ) ; }
Return item data by identifier in this transient storage then in storage container .
15,571
void removeLog ( PlainChangesLog log ) { if ( LOG . isDebugEnabled ( ) ) { LOG . debug ( "tx removeLog() " + this + ( transactionLog != null ? "\n" + transactionLog . dump ( ) : "[NULL]" ) ) ; } if ( txStarted ( ) ) { transactionLog . removeLog ( log ) ; if ( transactionLog . getSize ( ) == 0 ) { transactionLog = null ; } } }
Re move a given changes log
15,572
public void save ( ItemStateChangesLog changes ) throws RepositoryException { PlainChangesLog statesLog = ( PlainChangesLog ) changes ; if ( LOG . isDebugEnabled ( ) ) { LOG . debug ( "save() " + this + " txStarted: " + txStarted ( ) + "\n====== Changes ======\n" + ( statesLog != null ? "\n" + statesLog . dump ( ) : "[NULL]" ) + "=====================" ) ; } if ( session . canEnrollChangeToGlobalTx ( statesLog ) ) { transactionLog . addLog ( statesLog ) ; } else { storageDataManager . save ( new TransactionChangesLog ( statesLog ) ) ; } }
Updates the manager with new changes . If transaction is started it will fill manager s changes log else just move changes to workspace storage manager . It saves the changes AS IS - i . e . id DOES NOT care about cloning of this objects etc . Here PlainChangesLog expected .
15,573
protected List < AccessControlEntry > readACLPermisions ( String cid , Map < String , SortedSet < TempPropertyData > > properties ) throws SQLException , IllegalACLException , IOException { List < AccessControlEntry > naPermissions = new ArrayList < AccessControlEntry > ( ) ; Set < TempPropertyData > permValues = properties . get ( Constants . EXO_PERMISSIONS . getAsString ( ) ) ; if ( permValues != null ) { for ( TempPropertyData value : permValues ) { AccessControlEntry ace ; try { ace = AccessControlEntry . parse ( ValueDataUtil . getString ( value . getValueData ( ) ) ) ; } catch ( RepositoryException e ) { throw new IOException ( e . getMessage ( ) , e ) ; } naPermissions . add ( ace ) ; } return naPermissions ; } else { throw new IllegalACLException ( "Property exo:permissions is not found for node with id: " + getIdentifier ( cid ) ) ; } }
Read ACL Permissions from properties set .
15,574
protected String readACLOwner ( String cid , Map < String , SortedSet < TempPropertyData > > properties ) throws IllegalACLException , IOException { SortedSet < TempPropertyData > ownerValues = properties . get ( Constants . EXO_OWNER . getAsString ( ) ) ; if ( ownerValues != null ) { try { return ValueDataUtil . getString ( ownerValues . first ( ) . getValueData ( ) ) ; } catch ( RepositoryException e ) { throw new IOException ( e . getMessage ( ) , e ) ; } } else { throw new IllegalACLException ( "Property exo:owner is not found for node with id: " + getIdentifier ( cid ) ) ; } }
Read ACL owner .
15,575
protected PersistedNodeData loadNodeFromTemporaryNodeData ( TempNodeData tempData , QPath parentPath , AccessControlList parentACL ) throws RepositoryException , SQLException , IOException { return loadNodeRecord ( parentPath , tempData . cname , tempData . cid , tempData . cpid , tempData . cindex , tempData . cversion , tempData . cnordernumb , tempData . properties , parentACL ) ; }
Create NodeData from TempNodeData content .
15,576
protected int getLastOrderNumber ( ) throws RepositoryException { checkIfOpened ( ) ; try { ResultSet count = findLastOrderNumber ( 1 , true ) ; try { if ( count . next ( ) ) { return count . getInt ( 1 ) - 1 ; } else { return - 1 ; } } finally { try { count . close ( ) ; } catch ( SQLException e ) { LOG . error ( "Can't close the ResultSet: " + e . getMessage ( ) ) ; } } } catch ( SQLException e ) { throw new RepositoryException ( e ) ; } }
Gets the last order number from the sequence
15,577
protected void updateSequence ( ) throws RepositoryException { checkIfOpened ( ) ; try { ResultSet count = updateNextOrderNumber ( localMaxOrderNumber ) ; try { if ( ! count . next ( ) ) { throw new RepositoryException ( "Could not update the sequence: " + "the returned value cannot be found" ) ; } } finally { try { count . close ( ) ; } catch ( SQLException e ) { LOG . error ( "Can't close the ResultSet: " + e . getMessage ( ) ) ; } } } catch ( SQLException e ) { throw new RepositoryException ( e ) ; } }
Updates the value of the sequence in order to avoid any gap
15,578
protected String escape ( String pattern ) { char [ ] chars = pattern . toCharArray ( ) ; StringBuilder sb = new StringBuilder ( chars . length + 1 ) ; for ( int i = 0 ; i < chars . length ; i ++ ) { switch ( chars [ i ] ) { case '\'' : sb . append ( getSingleQuoteEscapeSymbol ( ) ) ; default : sb . append ( chars [ i ] ) ; } } return sb . toString ( ) ; }
Escape all the single quote found
15,579
protected void appendPattern ( StringBuilder sb , QPathEntry entry , boolean indexConstraint ) { String pattern = entry . getAsString ( false ) ; sb . append ( "(I.NAME" ) ; if ( pattern . contains ( "*" ) ) { sb . append ( " LIKE '" ) ; sb . append ( escapeSpecialChars ( pattern ) ) ; sb . append ( "' ESCAPE '" ) ; sb . append ( getLikeExpressionEscape ( ) ) ; sb . append ( "'" ) ; } else { sb . append ( "='" ) ; sb . append ( escape ( pattern ) ) ; sb . append ( "'" ) ; } if ( indexConstraint && entry . getIndex ( ) != - 1 ) { sb . append ( " and I.I_INDEX=" ) ; sb . append ( entry . getIndex ( ) ) ; } sb . append ( ")" ) ; }
Append pattern expression . Appends String I . NAME LIKE escaped pattern ESCAPE escapeString or I . NAME = pattern to String builder sb .
15,580
public void remove ( ) throws RepositoryException { NodeData vhnode = ( NodeData ) dataManager . getItemData ( vhID ) ; if ( vhnode == null ) { ItemState vhState = null ; List < ItemState > allStates = transientChangesLog . getAllStates ( ) ; for ( int i = allStates . size ( ) - 1 ; i >= 0 ; i -- ) { ItemState state = allStates . get ( i ) ; if ( state . getData ( ) . getIdentifier ( ) . equals ( vhID ) ) vhState = state ; } if ( vhState != null && vhState . isDeleted ( ) ) { return ; } throw new RepositoryException ( "Version history is not found. UUID: " + vhID + ". Context item (ancestor to save) " + ancestorToSave . getAsString ( ) ) ; } for ( String wsName : repository . getWorkspaceNames ( ) ) { SessionImpl wsSession = repository . getSystemSession ( wsName ) ; try { for ( PropertyData sref : wsSession . getTransientNodesManager ( ) . getReferencesData ( vhID , false ) ) { if ( sref . getQPath ( ) . isDescendantOf ( Constants . JCR_VERSION_STORAGE_PATH ) ) { if ( ! sref . getQPath ( ) . isDescendantOf ( vhnode . getQPath ( ) ) && ( containingHistory != null ? ! sref . getQPath ( ) . isDescendantOf ( containingHistory ) : true ) ) return ; } else if ( ! currentWorkspaceName . equals ( wsName ) ) { return ; } } } finally { wsSession . logout ( ) ; } } List < NodeData > childs = dataManager . getChildNodesData ( vhnode ) ; for ( NodeData nodeData : childs ) { if ( ntManager . isNodeType ( Constants . NT_VERSIONEDCHILD , vhnode . getPrimaryTypeName ( ) , vhnode . getMixinTypeNames ( ) ) ) { PropertyData property = ( PropertyData ) dataManager . getItemData ( nodeData , new QPathEntry ( Constants . JCR_CHILDVERSIONHISTORY , 1 ) , ItemType . PROPERTY ) ; if ( property == null ) throw new RepositoryException ( "Property " + Constants . JCR_CHILDVERSIONHISTORY . getAsString ( ) + " for node " + nodeData . getQPath ( ) . getAsString ( ) + " not found" ) ; String childVhID = ValueDataUtil . getString ( property . getValues ( ) . get ( 0 ) ) ; VersionHistoryRemover historyRemover = new VersionHistoryRemover ( childVhID , dataManager , ntManager , repository , currentWorkspaceName , containingHistory , ancestorToSave , transientChangesLog , accessManager , userState ) ; historyRemover . remove ( ) ; } } ItemDataRemoveVisitor visitor = new ItemDataRemoveVisitor ( dataManager , ancestorToSave ) ; vhnode . accept ( visitor ) ; transientChangesLog . addAll ( visitor . getRemovedStates ( ) ) ; }
Remove history .
15,581
private LocalWorkspaceDataManagerStub getWorkspaceDataManager ( ) { if ( workspaceDataManager == null ) { synchronized ( this ) { if ( workspaceDataManager == null ) { LocalWorkspaceDataManagerStub workspaceDataManager = ( LocalWorkspaceDataManagerStub ) container . getComponentInstanceOfType ( LocalWorkspaceDataManagerStub . class ) ; if ( workspaceDataManager == null ) { throw new IllegalStateException ( "The workspace data manager cannot be found" ) ; } this . workspaceDataManager = workspaceDataManager ; } } } return workspaceDataManager ; }
Lazily gets the LocalWorkspaceDataManagerStub from the eXo container . This is required to prevent cyclic dependency
15,582
public boolean isGlobalTxActive ( ) { TransactionContext ctx ; try { return ( ctx = contexts . get ( ) ) != null && ctx . getXidContext ( ) != null && tm . getStatus ( ) != Status . STATUS_NO_TRANSACTION ; } catch ( SystemException e ) { log . warn ( "Could not check if a global Tx has been started" , e ) ; } return false ; }
Indicates whether a global tx is active or not
15,583
public void putSharedObject ( String key , Object value ) { TransactionContext ctx = contexts . get ( ) ; if ( ctx == null ) { throw new IllegalStateException ( "There is no active transaction context" ) ; } XidContext xidCtx = ctx . getXidContext ( ) ; if ( xidCtx == null ) { throw new IllegalStateException ( "There is no active xid context" ) ; } xidCtx . putSharedObject ( key , value ) ; }
Registers an object to be shared within the XidContext
15,584
public < T > T getSharedObject ( String key ) { TransactionContext ctx = contexts . get ( ) ; if ( ctx == null ) { throw new IllegalStateException ( "There is no active transaction context" ) ; } XidContext xidCtx = ctx . getXidContext ( ) ; if ( xidCtx == null ) { throw new IllegalStateException ( "There is no active xid context" ) ; } return xidCtx . getSharedObject ( key ) ; }
Gives the shared object corresponding to the given key
15,585
public boolean canEnrollChangeToGlobalTx ( final SessionImpl session , final PlainChangesLog changes ) { try { int status ; if ( tm != null && ( status = tm . getStatus ( ) ) != Status . STATUS_NO_TRANSACTION ) { if ( status != Status . STATUS_ACTIVE && status != Status . STATUS_PREPARING ) { throw new IllegalStateException ( "The session cannot be enrolled in the current global transaction due " + "to an invalidate state, the current status is " + status + " and only ACTIVE and PREPARING are allowed" ) ; } SecurityHelper . doPrivilegedExceptionAction ( new PrivilegedExceptionAction < Void > ( ) { public Void run ( ) throws Exception { add ( session , changes ) ; return null ; } } ) ; return true ; } } catch ( PrivilegedActionException e ) { log . warn ( "Could not check if a global Tx has been started or register the session into the resource manager" , e ) ; } catch ( SystemException e ) { log . warn ( "Could not check if a global Tx has been started or register the session into the resource manager" , e ) ; } return false ; }
Checks if a global Tx has been started if so the session and its change will be dynamically enrolled
15,586
public void addListener ( TransactionableResourceManagerListener listener ) { TransactionContext ctx = contexts . get ( ) ; if ( ctx == null ) { throw new IllegalStateException ( "There is no active transaction context" ) ; } XidContext xidCtx = ctx . getXidContext ( ) ; if ( xidCtx == null ) { throw new IllegalStateException ( "There is no active xid context" ) ; } xidCtx . addListener ( listener ) ; }
Add a new listener to register to the current tx
15,587
private void add ( SessionImpl session , PlainChangesLog changes ) throws SystemException , IllegalStateException , RollbackException { Transaction tx = tm . getTransaction ( ) ; if ( tx == null ) { return ; } TransactionContext ctx = getOrCreateTransactionContext ( ) ; ctx . registerTransaction ( tx ) ; ctx . add ( session , changes ) ; }
Add session to the transaction group .
15,588
private void abort ( List < TransactionableResourceManagerListener > listeners ) throws XAException { boolean exception = false ; for ( int i = 0 , length = listeners . size ( ) ; i < length ; i ++ ) { TransactionableResourceManagerListener listener = listeners . get ( i ) ; try { listener . onAbort ( ) ; } catch ( Exception e ) { log . error ( "Could not execute the method onAbort" , e ) ; exception = true ; } } if ( exception ) { throw new XAException ( XAException . XAER_RMERR ) ; } }
Call the method onAbort on all the given listeners
15,589
private void setRollbackOnly ( ) { try { tm . getTransaction ( ) . setRollbackOnly ( ) ; } catch ( IllegalStateException e ) { log . warn ( "Could not set the status of the tx to 'rollback-only'" , e ) ; } catch ( SystemException e ) { log . warn ( "Could not set the status of the tx to 'rollback-only'" , e ) ; } }
Change the status of the tx to rollback - only
15,590
private void checkSameNameSibling ( NodeData node , WorkspaceStorageConnection con , final Set < QPath > addedNodes ) throws RepositoryException { if ( node . getQPath ( ) . getIndex ( ) > 1 ) { final QPathEntry [ ] path = node . getQPath ( ) . getEntries ( ) ; final QPathEntry [ ] siblingPath = new QPathEntry [ path . length ] ; final int li = path . length - 1 ; System . arraycopy ( path , 0 , siblingPath , 0 , li ) ; siblingPath [ li ] = new QPathEntry ( path [ li ] , path [ li ] . getIndex ( ) - 1 ) ; if ( addedNodes . contains ( new QPath ( siblingPath ) ) ) { return ; } else { if ( dataContainer . isCheckSNSNewConnection ( ) ) { final WorkspaceStorageConnection acon = dataContainer . openConnection ( ) ; try { checkPersistedSNS ( node , acon ) ; } finally { acon . close ( ) ; } } else { checkPersistedSNS ( node , con ) ; } } } }
Check if given node path contains index higher 1 and if yes if same - name sibling exists in persistence or in current changes log .
15,591
private void checkPersistedSNS ( NodeData node , WorkspaceStorageConnection acon ) throws RepositoryException { NodeData parent = ( NodeData ) acon . getItemData ( node . getParentIdentifier ( ) ) ; QPathEntry myName = node . getQPath ( ) . getEntries ( ) [ node . getQPath ( ) . getEntries ( ) . length - 1 ] ; ItemData sibling = acon . getItemData ( parent , new QPathEntry ( myName . getNamespace ( ) , myName . getName ( ) , myName . getIndex ( ) - 1 ) , ItemType . NODE ) ; if ( sibling == null || ! sibling . isNode ( ) ) { throw new InvalidItemStateException ( "Node can't be saved " + node . getQPath ( ) . getAsString ( ) + ". No same-name sibling exists with index " + ( myName . getIndex ( ) - 1 ) + "." ) ; } }
Check if same - name sibling exists in persistence .
15,592
protected void doDelete ( final ItemData item , final WorkspaceStorageConnection con , ChangedSizeHandler sizeHandler ) throws RepositoryException , InvalidItemStateException { if ( item . isNode ( ) ) { con . delete ( ( NodeData ) item ) ; } else { con . delete ( ( PropertyData ) item , sizeHandler ) ; } }
Performs actual item data deleting .
15,593
protected void doUpdate ( final ItemData item , final WorkspaceStorageConnection con , ChangedSizeHandler sizeHandler ) throws RepositoryException , InvalidItemStateException { if ( item . isNode ( ) ) { con . update ( ( NodeData ) item ) ; } else { con . update ( ( PropertyData ) item , sizeHandler ) ; } }
Performs actual item data updating .
15,594
protected void doAdd ( final ItemData item , final WorkspaceStorageConnection con , final Set < QPath > addedNodes , ChangedSizeHandler sizeHandler ) throws RepositoryException , InvalidItemStateException { if ( item . isNode ( ) ) { final NodeData node = ( NodeData ) item ; checkSameNameSibling ( node , con , addedNodes ) ; addedNodes . add ( node . getQPath ( ) ) ; con . add ( node ) ; } else { con . add ( ( PropertyData ) item , sizeHandler ) ; } }
Performs actual item data adding .
15,595
protected void doRename ( final ItemData item , final WorkspaceStorageConnection con , final Set < QPath > addedNodes ) throws RepositoryException , InvalidItemStateException { final NodeData node = ( NodeData ) item ; checkSameNameSibling ( node , con , addedNodes ) ; addedNodes . add ( node . getQPath ( ) ) ; con . rename ( node ) ; }
Perform node rename .
15,596
protected void notifySaveItems ( final ItemStateChangesLog changesLog , boolean isListenerTXAware ) { for ( MandatoryItemsPersistenceListener mlistener : mandatoryListeners ) { if ( mlistener . isTXAware ( ) == isListenerTXAware ) { mlistener . onSaveItems ( changesLog ) ; } } for ( ExtendedMandatoryItemsPersistenceListener mlistener : extendedMandatoryListeners ) { if ( mlistener . isTXAware ( ) == isListenerTXAware ) { mlistener . onSaveItems ( changesLog ) ; } } for ( ItemsPersistenceListener listener : listeners ) { if ( listener . isTXAware ( ) == isListenerTXAware ) { listener . onSaveItems ( changesLog ) ; } } }
Notify listeners about current changes log persistent state . Listeners notified according to is listener transaction aware .
15,597
public Set < InternalQName > getSubtypes ( final InternalQName nodeTypeName ) { Set < InternalQName > resultSet = new HashSet < InternalQName > ( ) ; for ( InternalQName ntName : nodeTypes . keySet ( ) ) { if ( getSupertypes ( ntName ) . contains ( nodeTypeName ) ) { resultSet . add ( ntName ) ; } } return resultSet ; }
Returns all subtypes of this node type in the node type inheritance hierarchy .
15,598
public AccessControlList read ( ObjectReader in ) throws UnknownClassIdException , IOException { int key ; if ( ( key = in . readInt ( ) ) != SerializationConstants . ACCESS_CONTROL_LIST ) { throw new UnknownClassIdException ( "There is unexpected class [" + key + "]" ) ; } String owner ; if ( in . readByte ( ) == SerializationConstants . NOT_NULL_DATA ) { owner = in . readString ( ) ; } else { owner = null ; } List < AccessControlEntry > accessList = new ArrayList < AccessControlEntry > ( ) ; int listSize = in . readInt ( ) ; for ( int i = 0 ; i < listSize ; i ++ ) { String ident = in . readString ( ) ; String perm = in . readString ( ) ; accessList . add ( new AccessControlEntry ( ident , perm ) ) ; } return new AccessControlList ( owner , accessList ) ; }
Read and set AccessControlList data .
15,599
public long getWorkspaceChangedSize ( ) { long wsDelta = 0 ; Iterator < ChangesItem > changes = iterator ( ) ; while ( changes . hasNext ( ) ) { wsDelta += changes . next ( ) . getWorkspaceChangedSize ( ) ; } return wsDelta ; }
Returns workspace changed size accumulated during some period .