idx int64 0 41.2k | question stringlengths 73 5.81k | target stringlengths 5 918 |
|---|---|---|
35,600 | private FilterList getExtPropertyFilters ( EntityMetadata m , FilterList filterList ) { Filter filter = getFilter ( m . getTableName ( ) ) ; if ( filter != null ) { if ( filterList == null ) { filterList = new FilterList ( ) ; } filterList . addFilter ( filter ) ; } return filterList ; } | Gets the ext property filters . |
35,601 | public HBaseRow createHbaseRow ( EntityMetadata m , Object entity , Object rowId , List < RelationHolder > relations ) throws IOException { MetamodelImpl metaModel = ( MetamodelImpl ) kunderaMetadata . getApplicationMetadata ( ) . getMetamodel ( m . getPersistenceUnit ( ) ) ; EntityType entityType = metaModel . entity ( m . getEntityClazz ( ) ) ; Set < Attribute > attributes = entityType . getAttributes ( ) ; if ( metaModel . isEmbeddable ( m . getIdAttribute ( ) . getBindableJavaType ( ) ) ) { rowId = KunderaCoreUtils . prepareCompositeKey ( m , rowId ) ; } HBaseRow hbaseRow = new HBaseRow ( rowId , new ArrayList < HBaseCell > ( ) ) ; createCellsAndAddToRow ( entity , metaModel , attributes , hbaseRow , m , - 1 , "" ) ; if ( relations != null && ! relations . isEmpty ( ) ) { hbaseRow . addCells ( getRelationCell ( m , rowId , relations ) ) ; } String discrColumn = ( ( AbstractManagedType ) entityType ) . getDiscriminatorColumn ( ) ; String discrValue = ( ( AbstractManagedType ) entityType ) . getDiscriminatorValue ( ) ; if ( discrColumn != null && discrValue != null ) { hbaseRow . addCell ( new HBaseCell ( m . getTableName ( ) , discrColumn , discrValue ) ) ; } return hbaseRow ; } | Creates the hbase row . |
35,602 | private List < HBaseCell > getRelationCell ( EntityMetadata m , Object rowId , List < RelationHolder > relations ) throws IOException { List < HBaseCell > relationCells = new ArrayList < HBaseCell > ( ) ; for ( RelationHolder relation : relations ) { HBaseCell hBaseCell = new HBaseCell ( m . getTableName ( ) , relation . getRelationName ( ) , relation . getRelationValue ( ) ) ; relationCells . add ( hBaseCell ) ; } return relationCells ; } | Gets the relation cell . |
35,603 | private void writeHbaseRowInATable ( String tableName , HBaseRow hbaseRow ) throws IOException { Table hTable = gethTable ( tableName ) ; ( ( HBaseWriter ) hbaseWriter ) . writeRow ( hTable , hbaseRow ) ; hTable . close ( ) ; } | Write hbase row in a table . |
35,604 | private void createCellsAndAddToRow ( Object entity , MetamodelImpl metaModel , Set < Attribute > attributes , HBaseRow hbaseRow , EntityMetadata m , int count , String prefix ) { AbstractAttribute idCol = ( AbstractAttribute ) m . getIdAttribute ( ) ; for ( Attribute attribute : attributes ) { AbstractAttribute absAttrib = ( AbstractAttribute ) attribute ; Class clazz = absAttrib . getBindableJavaType ( ) ; if ( metaModel . isEmbeddable ( clazz ) ) { Set < Attribute > attribEmbeddables = metaModel . embeddable ( absAttrib . getBindableJavaType ( ) ) . getAttributes ( ) ; Object embeddedField = PropertyAccessorHelper . getObject ( entity , ( Field ) attribute . getJavaMember ( ) ) ; if ( attribute . isCollection ( ) && embeddedField != null ) { int newCount = count + 1 ; String newPrefix = prefix != "" ? prefix + absAttrib . getJPAColumnName ( ) + HBaseUtils . DELIM : absAttrib . getJPAColumnName ( ) + HBaseUtils . DELIM ; List listOfEmbeddables = ( List ) embeddedField ; addColumnForCollectionSize ( hbaseRow , listOfEmbeddables . size ( ) , newPrefix , m . getTableName ( ) ) ; for ( Object obj : listOfEmbeddables ) { createCellsAndAddToRow ( obj , metaModel , attribEmbeddables , hbaseRow , m , newCount ++ , newPrefix ) ; } } else if ( embeddedField != null ) { String newPrefix = prefix != "" ? prefix + absAttrib . getJPAColumnName ( ) + HBaseUtils . DOT : absAttrib . getJPAColumnName ( ) + HBaseUtils . DOT ; createCellsAndAddToRow ( embeddedField , metaModel , attribEmbeddables , hbaseRow , m , count , newPrefix ) ; } } else if ( ! attribute . isCollection ( ) && ! attribute . isAssociation ( ) ) { String columnFamily = absAttrib . getTableName ( ) != null ? absAttrib . getTableName ( ) : m . getTableName ( ) ; String columnName = absAttrib . getJPAColumnName ( ) ; columnName = count != - 1 ? prefix + columnName + HBaseUtils . DELIM + count : prefix + columnName ; Object value = PropertyAccessorHelper . getObject ( entity , ( Field ) attribute . getJavaMember ( ) ) ; HBaseCell hbaseCell = new HBaseCell ( columnFamily , columnName , value ) ; if ( ! idCol . getName ( ) . equals ( attribute . getName ( ) ) && value != null ) { hbaseRow . addCell ( hbaseCell ) ; } } } } | Creates the cells and add to row . |
35,605 | public Table gethTable ( final String tableName ) throws IOException { return connection . getTable ( TableName . valueOf ( tableName ) ) ; } | Gets the h table . |
35,606 | private Object populateEntityFromHBaseData ( Object entity , HBaseDataWrapper hbaseData , EntityMetadata m , Object rowKey ) { try { Map < String , Object > relations = new HashMap < String , Object > ( ) ; if ( entity . getClass ( ) . isAssignableFrom ( EnhanceEntity . class ) ) { relations = ( ( EnhanceEntity ) entity ) . getRelations ( ) ; entity = ( ( EnhanceEntity ) entity ) . getEntity ( ) ; } MetamodelImpl metaModel = ( MetamodelImpl ) kunderaMetadata . getApplicationMetadata ( ) . getMetamodel ( m . getPersistenceUnit ( ) ) ; EntityType entityType = metaModel . entity ( m . getEntityClazz ( ) ) ; Set < Attribute > attributes = ( ( AbstractManagedType ) entityType ) . getAttributes ( ) ; writeValuesToEntity ( entity , hbaseData , m , metaModel , attributes , m . getRelationNames ( ) , relations , - 1 , "" ) ; if ( ! relations . isEmpty ( ) ) { return new EnhanceEntity ( entity , rowKey , relations ) ; } return entity ; } catch ( PropertyAccessException e1 ) { throw new RuntimeException ( e1 ) ; } } | Populate entity from hBase data . |
35,607 | private void writeValuesToEntity ( Object entity , HBaseDataWrapper hbaseData , EntityMetadata m , MetamodelImpl metaModel , Set < Attribute > attributes , List < String > relationNames , Map < String , Object > relations , int count , String prefix ) { for ( Attribute attribute : attributes ) { Class javaType = ( ( AbstractAttribute ) attribute ) . getBindableJavaType ( ) ; if ( metaModel . isEmbeddable ( javaType ) ) { processEmbeddable ( entity , hbaseData , m , metaModel , count , prefix , attribute , javaType ) ; } else if ( ! attribute . isCollection ( ) ) { String columnName = ( ( AbstractAttribute ) attribute ) . getJPAColumnName ( ) ; columnName = count != - 1 ? prefix + columnName + HBaseUtils . DELIM + count : prefix + columnName ; String idColName = ( ( AbstractAttribute ) m . getIdAttribute ( ) ) . getJPAColumnName ( ) ; String colFamily = ( ( AbstractAttribute ) attribute ) . getTableName ( ) != null ? ( ( AbstractAttribute ) attribute ) . getTableName ( ) : m . getTableName ( ) ; byte [ ] columnValue = hbaseData . getColumnValue ( HBaseUtils . getColumnDataKey ( colFamily , columnName ) ) ; if ( relationNames != null && relationNames . contains ( columnName ) && columnValue != null && columnValue . length > 0 ) { EntityType entityType = metaModel . entity ( m . getEntityClazz ( ) ) ; relations . put ( columnName , getObjectFromByteArray ( entityType , columnValue , columnName , m ) ) ; } else if ( ! idColName . equals ( columnName ) && columnValue != null ) { PropertyAccessorHelper . set ( entity , ( Field ) attribute . getJavaMember ( ) , columnValue ) ; } } } } | Write values to entity . |
35,608 | private void processEmbeddable ( Object entity , HBaseDataWrapper hbaseData , EntityMetadata m , MetamodelImpl metaModel , int count , String prefix , Attribute attribute , Class javaType ) { Set < Attribute > attribEmbeddables = metaModel . embeddable ( javaType ) . getAttributes ( ) ; Object embeddedField = KunderaCoreUtils . createNewInstance ( javaType ) ; if ( ! attribute . isCollection ( ) ) { String newPrefix = prefix != "" ? prefix + ( ( AbstractAttribute ) attribute ) . getJPAColumnName ( ) + HBaseUtils . DOT : ( ( AbstractAttribute ) attribute ) . getJPAColumnName ( ) + HBaseUtils . DOT ; writeValuesToEntity ( embeddedField , hbaseData , m , metaModel , attribEmbeddables , null , null , count , newPrefix ) ; PropertyAccessorHelper . set ( entity , ( Field ) attribute . getJavaMember ( ) , embeddedField ) ; } else { int newCount = count + 1 ; String newPrefix = prefix != "" ? prefix + ( ( AbstractAttribute ) attribute ) . getJPAColumnName ( ) + HBaseUtils . DELIM : ( ( AbstractAttribute ) attribute ) . getJPAColumnName ( ) + HBaseUtils . DELIM ; List embeddedCollection = new ArrayList ( ) ; byte [ ] columnValue = hbaseData . getColumnValue ( HBaseUtils . getColumnDataKey ( m . getTableName ( ) , newPrefix + HBaseUtils . SIZE ) ) ; int size = 0 ; if ( columnValue != null ) { size = Bytes . toInt ( columnValue ) ; } while ( size != newCount ) { embeddedField = KunderaCoreUtils . createNewInstance ( javaType ) ; writeValuesToEntity ( embeddedField , hbaseData , m , metaModel , attribEmbeddables , null , null , newCount ++ , newPrefix ) ; embeddedCollection . add ( embeddedField ) ; } PropertyAccessorHelper . set ( entity , ( Field ) attribute . getJavaMember ( ) , embeddedCollection ) ; } } | Process embeddable . |
35,609 | public void setFilter ( Filter filter ) { if ( this . filter == null ) { this . filter = new FilterList ( ) ; } if ( filter != null ) { this . filter . addFilter ( filter ) ; } } | Sets the filter . |
35,610 | private List onRead ( EntityMetadata m , List < Map < String , Object > > columnsToOutput , Table hTable , List < HBaseDataWrapper > results ) throws IOException { Class clazz = m . getEntityClazz ( ) ; List outputResults = new ArrayList ( ) ; try { if ( results != null ) { return columnsToOutput != null && ! columnsToOutput . isEmpty ( ) ? returnSpecificFieldList ( m , columnsToOutput , results , outputResults ) : returnEntityObjectList ( m , results , outputResults ) ; } } catch ( Exception e ) { logger . error ( "Error while creating an instance of {}, Caused by: ." , clazz , e ) ; throw new PersistenceException ( e ) ; } finally { if ( hTable != null ) { closeHTable ( hTable ) ; } } return outputResults ; } | On read . |
35,611 | private List returnEntityObjectList ( EntityMetadata m , List < HBaseDataWrapper > results , List outputResults ) { Map < Object , Object > entityListMap = new HashMap < Object , Object > ( ) ; MetamodelImpl metaModel = ( MetamodelImpl ) kunderaMetadata . getApplicationMetadata ( ) . getMetamodel ( m . getPersistenceUnit ( ) ) ; EntityType entityType = metaModel . entity ( m . getEntityClazz ( ) ) ; List < AbstractManagedType > subManagedTypes = ( ( AbstractManagedType ) entityType ) . getSubManagedType ( ) ; Map < String , Class > discrValueToEntityClazz = new HashMap < String , Class > ( ) ; String discrColumn = null ; if ( subManagedTypes != null && ! subManagedTypes . isEmpty ( ) ) { for ( AbstractManagedType subEntity : subManagedTypes ) { discrColumn = ( ( AbstractManagedType ) subEntity ) . getDiscriminatorColumn ( ) ; discrValueToEntityClazz . put ( subEntity . getDiscriminatorValue ( ) , subEntity . getJavaType ( ) ) ; } } for ( HBaseDataWrapper data : results ) { Class clazz = null ; if ( discrValueToEntityClazz != null && ! discrValueToEntityClazz . isEmpty ( ) ) { String discrColumnKey = HBaseUtils . getColumnDataKey ( m . getTableName ( ) , discrColumn ) ; String discrValue = Bytes . toString ( data . getColumnValue ( discrColumnKey ) ) ; clazz = discrValueToEntityClazz . get ( discrValue ) ; m = KunderaMetadataManager . getEntityMetadata ( kunderaMetadata , clazz ) ; } else { clazz = m . getEntityClazz ( ) ; } Object entity = KunderaCoreUtils . createNewInstance ( clazz ) ; Object rowKeyValue = HBaseUtils . fromBytes ( m , metaModel , data . getRowKey ( ) ) ; if ( ! metaModel . isEmbeddable ( m . getIdAttribute ( ) . getBindableJavaType ( ) ) ) { PropertyAccessorHelper . setId ( entity , m , rowKeyValue ) ; } if ( entityListMap . get ( rowKeyValue ) != null ) { entity = entityListMap . get ( rowKeyValue ) ; } entity = populateEntityFromHBaseData ( entity , data , m , null ) ; if ( entity != null ) { entityListMap . put ( rowKeyValue , entity ) ; } } for ( Object obj : entityListMap . values ( ) ) { outputResults . add ( obj ) ; } return outputResults ; } | Return entity object list . |
35,612 | private List returnSpecificFieldList ( EntityMetadata m , List < Map < String , Object > > columnsToOutput , List < HBaseDataWrapper > results , List outputResults ) { for ( HBaseDataWrapper data : results ) { List result = new ArrayList ( ) ; Map < String , byte [ ] > columns = data . getColumns ( ) ; for ( Map < String , Object > map : columnsToOutput ) { Object obj ; String colDataKey = HBaseUtils . getColumnDataKey ( ( String ) map . get ( Constants . COL_FAMILY ) , ( String ) map . get ( Constants . DB_COL_NAME ) ) ; if ( ( boolean ) map . get ( Constants . IS_EMBEDDABLE ) ) { Class embedClazz = ( Class ) map . get ( Constants . FIELD_CLAZZ ) ; String prefix = ( String ) map . get ( Constants . DB_COL_NAME ) + HBaseUtils . DOT ; obj = populateEmbeddableObject ( data , KunderaCoreUtils . createNewInstance ( embedClazz ) , m , embedClazz , prefix ) ; } else if ( isIdCol ( m , ( String ) map . get ( Constants . DB_COL_NAME ) ) ) { obj = HBaseUtils . fromBytes ( data . getRowKey ( ) , ( Class ) map . get ( Constants . FIELD_CLAZZ ) ) ; } else { obj = HBaseUtils . fromBytes ( columns . get ( colDataKey ) , ( Class ) map . get ( Constants . FIELD_CLAZZ ) ) ; } result . add ( obj ) ; } if ( columnsToOutput . size ( ) == 1 ) outputResults . addAll ( result ) ; else outputResults . add ( result ) ; } return outputResults ; } | Return specific field list . |
35,613 | private boolean isIdCol ( EntityMetadata m , String colName ) { return ( ( AbstractAttribute ) m . getIdAttribute ( ) ) . getJPAColumnName ( ) . equals ( colName ) ; } | Checks if is id col . |
35,614 | private Object populateEmbeddableObject ( HBaseDataWrapper data , Object obj , EntityMetadata m , Class clazz , String prefix ) { MetamodelImpl metaModel = ( MetamodelImpl ) kunderaMetadata . getApplicationMetadata ( ) . getMetamodel ( m . getPersistenceUnit ( ) ) ; Set < Attribute > attributes = metaModel . embeddable ( clazz ) . getAttributes ( ) ; writeValuesToEntity ( obj , data , m , metaModel , attributes , null , null , - 1 , prefix ) ; return obj ; } | Populate embeddable object . |
35,615 | private Object getObjectFromByteArray ( EntityType entityType , byte [ ] value , String jpaColumnName , EntityMetadata m ) { if ( jpaColumnName != null ) { String fieldName = m . getFieldName ( jpaColumnName ) ; if ( fieldName != null ) { Attribute attribute = fieldName != null ? entityType . getAttribute ( fieldName ) : null ; EntityMetadata relationMetadata = KunderaMetadataManager . getEntityMetadata ( kunderaMetadata , attribute . getJavaType ( ) ) ; Object colValue = PropertyAccessorHelper . getObject ( relationMetadata . getIdAttribute ( ) . getJavaType ( ) , value ) ; return colValue ; } } logger . warn ( "No value found for column {}, returning null." , jpaColumnName ) ; return null ; } | Gets the object from byte array . |
35,616 | public HBaseDataHandler getHandle ( ) { HBaseDataHandler handler = new HBaseDataHandler ( this . kunderaMetadata , this . connection ) ; handler . filter = this . filter ; handler . filters = this . filters ; return handler ; } | Gets the handle . |
35,617 | private Transaction onBegin ( ) { Transaction tx ; if ( ( ( StatelessSessionImpl ) s ) . getTransactionCoordinator ( ) . isTransactionActive ( ) ) { tx = ( ( StatelessSessionImpl ) s ) . getTransaction ( ) ; } else { tx = s . beginTransaction ( ) ; } return tx ; } | On begin . |
35,618 | public void persistJoinTable ( JoinTableData joinTableData ) { String schemaName = KunderaMetadataManager . getEntityMetadata ( kunderaMetadata , joinTableData . getEntityClass ( ) ) . getSchema ( ) ; String joinTableName = joinTableData . getJoinTableName ( ) ; String joinColumnName = joinTableData . getJoinColumnName ( ) ; String invJoinColumnName = joinTableData . getInverseJoinColumnName ( ) ; Map < Object , Set < Object > > joinTableRecords = joinTableData . getJoinTableRecords ( ) ; for ( Object key : joinTableRecords . keySet ( ) ) { Set < Object > values = joinTableRecords . get ( key ) ; insertRecordInJoinTable ( schemaName , joinTableName , joinColumnName , invJoinColumnName , key , values ) ; } } | Inserts records into JoinTable . |
35,619 | private void insertRecordInJoinTable ( String schemaName , String joinTableName , String joinColumnName , String inverseJoinColumnName , Object parentId , Set < Object > childrenIds ) { s = getStatelessSession ( ) ; Transaction tx = onBegin ( ) ; for ( Object childId : childrenIds ) { StringBuffer query = new StringBuffer ( ) ; Object [ ] existingRowIds = findIdsByColumn ( schemaName , joinTableName , joinColumnName , inverseJoinColumnName , ( String ) childId , null ) ; boolean joinTableRecordsExists = false ; if ( existingRowIds != null && existingRowIds . length > 0 ) { for ( Object o : existingRowIds ) { if ( o . toString ( ) . equals ( parentId . toString ( ) ) ) { joinTableRecordsExists = true ; break ; } } } if ( ! joinTableRecordsExists ) { query . append ( "INSERT INTO " ) . append ( getFromClause ( schemaName , joinTableName ) ) . append ( "(" ) . append ( joinColumnName ) . append ( "," ) . append ( inverseJoinColumnName ) . append ( ")" ) . append ( " VALUES('" ) . append ( parentId ) . append ( "','" ) . append ( childId ) . append ( "')" ) ; s . createSQLQuery ( query . toString ( ) ) . executeUpdate ( ) ; } } onCommit ( tx ) ; } | Insert record in join table . |
35,620 | public int onNativeUpdate ( String query , Map < Parameter , Object > parameterMap ) { s = getStatelessSession ( ) ; Query q = s . createSQLQuery ( query ) ; setParameters ( parameterMap , q ) ; int i = q . executeUpdate ( ) ; return i ; } | On native update . |
35,621 | private Object [ ] getDataType ( EntityMetadata entityMetadata , Object ... arg1 ) throws PropertyAccessException { Field idField = ( Field ) entityMetadata . getIdAttribute ( ) . getJavaMember ( ) ; PropertyAccessor < ? > accessor = PropertyAccessorFactory . getPropertyAccessor ( idField ) ; Object [ ] pKeys = new Object [ arg1 . length ] ; int cnt = 0 ; for ( Object r : arg1 ) { pKeys [ cnt ++ ] = accessor . fromString ( idField . getClass ( ) , r . toString ( ) ) ; } return pKeys ; } | Gets the data type . |
35,622 | private String getFromClause ( String schemaName , String tableName ) { String clause = tableName ; if ( schemaName != null && ! schemaName . isEmpty ( ) ) { clause = schemaName + "." + tableName ; } return clause ; } | Gets the from clause . |
35,623 | private void updateForeignKeys ( EntityMetadata metadata , Object id , List < RelationHolder > relationHolders ) { for ( RelationHolder rh : relationHolders ) { String linkName = rh . getRelationName ( ) ; Object linkValue = rh . getRelationValue ( ) ; if ( linkName != null && linkValue != null ) { String clause = getFromClause ( metadata . getSchema ( ) , metadata . getTableName ( ) ) ; String updateSql = "Update " + clause + " SET " + linkName + "= '" + linkValue + "' WHERE " + ( ( AbstractAttribute ) metadata . getIdAttribute ( ) ) . getJPAColumnName ( ) + " = '" + id + "'" ; onNativeUpdate ( updateSql , null ) ; } } } | Updates foreign keys into master table . |
35,624 | private boolean removeKunderaProxies ( EntityMetadata metadata , Object entity , List < RelationHolder > relationHolders ) { boolean proxyRemoved = false ; for ( Relation relation : metadata . getRelations ( ) ) { if ( relation != null && relation . isUnary ( ) ) { Object relationObject = PropertyAccessorHelper . getObject ( entity , relation . getProperty ( ) ) ; if ( relationObject != null && ProxyHelper . isKunderaProxy ( relationObject ) ) { EntityMetadata relMetadata = KunderaMetadataManager . getEntityMetadata ( kunderaMetadata , relation . getTargetEntity ( ) ) ; Method idAccessorMethod = relMetadata . getReadIdentifierMethod ( ) ; Object foreignKey = null ; try { foreignKey = idAccessorMethod . invoke ( relationObject , new Object [ ] { } ) ; } catch ( IllegalArgumentException e ) { log . error ( "Error while Fetching relationship value of {}, Caused by {}." , metadata . getEntityClazz ( ) , e ) ; } catch ( IllegalAccessException e ) { log . error ( "Error while Fetching relationship value of {}, Caused by {}." , metadata . getEntityClazz ( ) , e ) ; } catch ( InvocationTargetException e ) { log . error ( "Error while Fetching relationship value of {}, Caused by {}." , metadata . getEntityClazz ( ) , e ) ; } if ( foreignKey != null ) { relationObject = null ; PropertyAccessorHelper . set ( entity , relation . getProperty ( ) , relationObject ) ; relationHolders . add ( new RelationHolder ( relation . getJoinColumnName ( kunderaMetadata ) , foreignKey ) ) ; proxyRemoved = true ; } } } } return proxyRemoved ; } | Removes the kundera proxies . |
35,625 | private void setParameters ( Map < Parameter , Object > parameterMap , Query q ) { if ( parameterMap != null && ! parameterMap . isEmpty ( ) ) { for ( Parameter parameter : parameterMap . keySet ( ) ) { Object paramObject = parameterMap . get ( parameter ) ; if ( parameter . getName ( ) != null ) { if ( paramObject instanceof Collection ) { q . setParameterList ( parameter . getName ( ) , ( Collection ) paramObject ) ; } else { q . setParameter ( parameter . getName ( ) , paramObject ) ; } } else if ( parameter . getPosition ( ) != null ) { if ( paramObject instanceof Collection ) { q . setParameterList ( Integer . toString ( parameter . getPosition ( ) ) , ( Collection ) paramObject ) ; } else { q . setParameter ( Integer . toString ( parameter . getPosition ( ) ) , paramObject ) ; } } } } } | Sets the parameters . |
35,626 | public void dropSchema ( ) { if ( operation != null && operation . equalsIgnoreCase ( "create-drop" ) ) { try { dropKeyspaceOrCFs ( ) ; } catch ( Exception ex ) { log . error ( "Error during dropping schema in cassandra, Caused by: ." , ex ) ; throw new SchemaGenerationException ( ex , "Cassandra" ) ; } } cassandra_client = null ; } | drop schema method drop the table from keyspace . |
35,627 | private void dropKeyspaceOrCFs ( ) throws InvalidRequestException , SchemaDisagreementException , TException , Exception { if ( createdKeyspaces . contains ( databaseName ) ) { cassandra_client . system_drop_keyspace ( databaseName ) ; } else { cassandra_client . set_keyspace ( databaseName ) ; for ( TableInfo tableInfo : tableInfos ) { dropColumnFamily ( tableInfo ) ; } } } | Drop keyspace or c fs . |
35,628 | private void dropColumnFamily ( TableInfo tableInfo ) throws Exception { if ( isCql3Enabled ( tableInfo ) ) { dropTableUsingCql ( tableInfo ) ; } else { cassandra_client . system_drop_column_family ( tableInfo . getTableName ( ) ) ; } } | Drops column family specified in table info . |
35,629 | private KsDef onCreateKeyspace ( ) throws Exception { try { createdKeyspaces . add ( databaseName ) ; createKeyspace ( ) ; } catch ( InvalidRequestException irex ) { createdKeyspaces . remove ( databaseName ) ; } cassandra_client . set_keyspace ( databaseName ) ; return cassandra_client . describe_keyspace ( databaseName ) ; } | On create keyspace . |
35,630 | private void createKeyspace ( ) throws Exception { if ( cql_version != null && cql_version . equals ( CassandraConstants . CQL_VERSION_3_0 ) ) { onCql3CreateKeyspace ( ) ; } else { Map < String , String > strategy_options = new HashMap < String , String > ( ) ; List < CfDef > cfDefs = new ArrayList < CfDef > ( ) ; KsDef ksDef = new KsDef ( databaseName , csmd . getPlacement_strategy ( databaseName ) , cfDefs ) ; setProperties ( ksDef , strategy_options ) ; ksDef . setStrategy_options ( strategy_options ) ; cassandra_client . system_add_keyspace ( ksDef ) ; } } | Creates keyspace . |
35,631 | private void onCql3CreateKeyspace ( ) throws InvalidRequestException , UnavailableException , TimedOutException , SchemaDisagreementException , TException , UnsupportedEncodingException { String createKeyspace = CQLTranslator . CREATE_KEYSPACE ; String placement_strategy = csmd . getPlacement_strategy ( databaseName ) ; String replication_conf = CQLTranslator . SIMPLE_REPLICATION ; createKeyspace = createKeyspace . replace ( "$KEYSPACE" , Constants . ESCAPE_QUOTE + databaseName + Constants . ESCAPE_QUOTE ) ; Schema schema = CassandraPropertyReader . csmd . getSchema ( databaseName ) ; if ( schema != null && schema . getName ( ) != null && schema . getName ( ) . equalsIgnoreCase ( databaseName ) && schema . getSchemaProperties ( ) != null ) { Properties schemaProperties = schema . getSchemaProperties ( ) ; if ( placement_strategy . equalsIgnoreCase ( SimpleStrategy . class . getSimpleName ( ) ) || placement_strategy . equalsIgnoreCase ( SimpleStrategy . class . getName ( ) ) ) { String replicationFactor = schemaProperties . getProperty ( CassandraConstants . REPLICATION_FACTOR , CassandraConstants . DEFAULT_REPLICATION_FACTOR ) ; replication_conf = replication_conf . replace ( "$REPLICATION_FACTOR" , replicationFactor ) ; createKeyspace = createKeyspace . replace ( "$CLASS" , placement_strategy ) ; } else if ( placement_strategy . equalsIgnoreCase ( NetworkTopologyStrategy . class . getSimpleName ( ) ) || placement_strategy . equalsIgnoreCase ( NetworkTopologyStrategy . class . getName ( ) ) ) { if ( schema . getDataCenters ( ) != null && ! schema . getDataCenters ( ) . isEmpty ( ) ) { StringBuilder builder = new StringBuilder ( ) ; for ( DataCenter dc : schema . getDataCenters ( ) ) { builder . append ( CQLTranslator . QUOTE_STR ) ; builder . append ( dc . getName ( ) ) ; builder . append ( CQLTranslator . QUOTE_STR ) ; builder . append ( ":" ) ; builder . append ( dc . getValue ( ) ) ; builder . append ( CQLTranslator . COMMA_STR ) ; } builder . delete ( builder . lastIndexOf ( CQLTranslator . COMMA_STR ) , builder . length ( ) ) ; replication_conf = builder . toString ( ) ; } } createKeyspace = createKeyspace . replace ( "$CLASS" , placement_strategy ) ; createKeyspace = createKeyspace . replace ( "$REPLICATION" , replication_conf ) ; boolean isDurableWrites = Boolean . parseBoolean ( schemaProperties . getProperty ( CassandraConstants . DURABLE_WRITES , "true" ) ) ; createKeyspace = createKeyspace . replace ( "$DURABLE_WRITES" , isDurableWrites + "" ) ; } else { createKeyspace = createKeyspace . replace ( "$CLASS" , placement_strategy ) ; replication_conf = replication_conf . replace ( "$REPLICATION_FACTOR" , ( CharSequence ) externalProperties . getOrDefault ( CassandraConstants . REPLICATION_FACTOR , CassandraConstants . DEFAULT_REPLICATION_FACTOR ) ) ; createKeyspace = createKeyspace . replace ( "$REPLICATION" , replication_conf ) ; createKeyspace = createKeyspace . replace ( "$DURABLE_WRITES" , "true" ) ; } cassandra_client . execute_cql3_query ( ByteBuffer . wrap ( createKeyspace . getBytes ( Constants . CHARSET_UTF8 ) ) , Compression . NONE , ConsistencyLevel . ONE ) ; KunderaCoreUtils . printQuery ( createKeyspace , showQuery ) ; } | On cql3 create keyspace . |
35,632 | private void createColumnFamilies ( List < TableInfo > tableInfos , KsDef ksDef ) throws Exception { for ( TableInfo tableInfo : tableInfos ) { if ( isCql3Enabled ( tableInfo ) ) { createOrUpdateUsingCQL3 ( tableInfo , ksDef ) ; createIndexUsingCql ( tableInfo ) ; } else { createOrUpdateColumnFamily ( tableInfo , ksDef ) ; } createInvertedIndexTable ( tableInfo , ksDef ) ; } } | Creates the column families . |
35,633 | private void createOrUpdateColumnFamily ( TableInfo tableInfo , KsDef ksDef ) throws Exception { MetaDataHandler handler = new MetaDataHandler ( ) ; if ( containsCompositeKey ( tableInfo ) ) { validateCompoundKey ( tableInfo ) ; createOrUpdateUsingCQL3 ( tableInfo , ksDef ) ; createIndexUsingCql ( tableInfo ) ; } else if ( containsCollectionColumns ( tableInfo ) || isCql3Enabled ( tableInfo ) ) { createOrUpdateUsingCQL3 ( tableInfo , ksDef ) ; createIndexUsingCql ( tableInfo ) ; } else { CfDef cf_def = handler . getTableMetadata ( tableInfo ) ; try { cassandra_client . system_add_column_family ( cf_def ) ; } catch ( InvalidRequestException irex ) { updateExistingColumnFamily ( tableInfo , ksDef , irex ) ; } } } | Creates the or update column family . |
35,634 | private boolean containsCompositeKey ( TableInfo tableInfo ) { return tableInfo . getTableIdType ( ) != null && tableInfo . getTableIdType ( ) . isAnnotationPresent ( Embeddable . class ) ; } | Contains composite key . |
35,635 | private void updateExistingColumnFamily ( TableInfo tableInfo , KsDef ksDef , InvalidRequestException irex ) throws Exception { StringBuilder builder = new StringBuilder ( "^Cannot add already existing (?:column family|table) .*$" ) ; if ( irex . getWhy ( ) != null && irex . getWhy ( ) . matches ( builder . toString ( ) ) ) { SchemaOperationType operationType = SchemaOperationType . getInstance ( operation ) ; switch ( operationType ) { case create : handleCreate ( tableInfo , ksDef ) ; break ; case createdrop : handleCreate ( tableInfo , ksDef ) ; break ; case update : if ( isCql3Enabled ( tableInfo ) ) { for ( ColumnInfo column : tableInfo . getColumnMetadatas ( ) ) { addColumnToTable ( tableInfo , column ) ; } createIndexUsingCql ( tableInfo ) ; } else { updateTable ( ksDef , tableInfo ) ; } break ; default : break ; } } else { log . error ( "Error occurred while creating table {}, Caused by: {}." , tableInfo . getTableName ( ) , irex ) ; throw new SchemaGenerationException ( "Error occurred while creating table " + tableInfo . getTableName ( ) , irex , "Cassandra" , databaseName ) ; } } | Update existing column family . |
35,636 | private void handleCreate ( TableInfo tableInfo , KsDef ksDef ) throws Exception { if ( containsCompositeKey ( tableInfo ) ) { validateCompoundKey ( tableInfo ) ; dropTableUsingCql ( tableInfo ) ; } else { onDrop ( tableInfo ) ; } createOrUpdateColumnFamily ( tableInfo , ksDef ) ; } | Handle create . |
35,637 | protected void update ( List < TableInfo > tableInfos ) { try { createOrUpdateKeyspace ( tableInfos ) ; } catch ( Exception ex ) { log . error ( "Error occurred while creating {}, Caused by: ." , databaseName , ex ) ; throw new SchemaGenerationException ( ex ) ; } } | update method update schema and table for the list of tableInfos . |
35,638 | private void getCompositeIdEmbeddables ( EmbeddableType embeddable , List compositeEmbeddables , MetamodelImpl metaModel ) { compositeEmbeddables . add ( embeddable . getJavaType ( ) . getSimpleName ( ) ) ; for ( Object column : embeddable . getAttributes ( ) ) { Attribute columnAttribute = ( Attribute ) column ; Field f = ( Field ) columnAttribute . getJavaMember ( ) ; if ( columnAttribute . getJavaType ( ) . isAnnotationPresent ( Embeddable . class ) ) { getCompositeIdEmbeddables ( metaModel . embeddable ( columnAttribute . getJavaType ( ) ) , compositeEmbeddables , metaModel ) ; } } } | Gets the composite id embeddables . |
35,639 | private void onEmbeddedColumns ( CQLTranslator translator , TableInfo tableInfo , StringBuilder queryBuilder , List compositeEmbeddables ) { List < EmbeddedColumnInfo > embeddedColumns = tableInfo . getEmbeddedColumnMetadatas ( ) ; for ( EmbeddedColumnInfo embColInfo : embeddedColumns ) { if ( ! compositeEmbeddables . contains ( embColInfo . getEmbeddable ( ) . getJavaType ( ) . getSimpleName ( ) ) ) { String cqlType = CQLTranslator . FROZEN + Constants . STR_LT + Constants . ESCAPE_QUOTE + embColInfo . getEmbeddable ( ) . getJavaType ( ) . getSimpleName ( ) + Constants . ESCAPE_QUOTE + Constants . STR_GT + translator . COMMA_STR ; translator . appendColumnName ( queryBuilder , embColInfo . getEmbeddedColumnName ( ) , cqlType ) ; } } } | On embedded columns . |
35,640 | private void postProcessEmbedded ( Map < String , String > embNametoUDTQuery , Map < String , List < String > > embNametoDependentList ) { for ( Map . Entry < String , List < String > > entry : embNametoDependentList . entrySet ( ) ) { checkRelationAndExecuteQuery ( entry . getKey ( ) , embNametoDependentList , embNametoUDTQuery ) ; } } | Post process embedded . |
35,641 | private void checkRelationAndExecuteQuery ( String embeddableKey , Map < String , List < String > > embeddableToDependentEmbeddables , Map < String , String > queries ) { List < String > dependentEmbeddables = embeddableToDependentEmbeddables . get ( embeddableKey ) ; if ( ! dependentEmbeddables . isEmpty ( ) ) { for ( String dependentEmbeddable : dependentEmbeddables ) { checkRelationAndExecuteQuery ( dependentEmbeddable , embeddableToDependentEmbeddables , queries ) ; } } KunderaCoreUtils . printQuery ( queries . get ( embeddableKey ) , showQuery ) ; try { cassandra_client . execute_cql3_query ( ByteBuffer . wrap ( queries . get ( embeddableKey ) . getBytes ( Constants . CHARSET_UTF8 ) ) , Compression . NONE , ConsistencyLevel . ONE ) ; } catch ( Exception e ) { throw new KunderaException ( "Error while creating type: " + queries . get ( embeddableKey ) , e ) ; } } | Check relation and execute query . |
35,642 | private void appendPrimaryKey ( CQLTranslator translator , EmbeddableType compoEmbeddableType , Field [ ] fields , StringBuilder queryBuilder ) { for ( Field f : fields ) { if ( ! ReflectUtils . isTransientOrStatic ( f ) ) { if ( f . getType ( ) . isAnnotationPresent ( Embeddable . class ) ) { MetamodelImpl metaModel = ( MetamodelImpl ) kunderaMetadata . getApplicationMetadata ( ) . getMetamodel ( puMetadata . getPersistenceUnitName ( ) ) ; queryBuilder . append ( translator . OPEN_BRACKET ) ; queryBuilder . append ( translator . SPACE_STRING ) ; appendPrimaryKey ( translator , ( EmbeddableType ) metaModel . embeddable ( f . getType ( ) ) , f . getType ( ) . getDeclaredFields ( ) , queryBuilder ) ; queryBuilder . deleteCharAt ( queryBuilder . length ( ) - 1 ) ; queryBuilder . append ( translator . CLOSE_BRACKET ) ; queryBuilder . append ( Constants . SPACE_COMMA ) ; } else { Attribute attribute = compoEmbeddableType . getAttribute ( f . getName ( ) ) ; translator . appendColumnName ( queryBuilder , ( ( AbstractAttribute ) attribute ) . getJPAColumnName ( ) ) ; queryBuilder . append ( Constants . SPACE_COMMA ) ; } } } } | Append primary key . |
35,643 | private void appendClusteringOrder ( CQLTranslator translator , List < ColumnInfo > compositeColumns , StringBuilder clusterKeyOrderingBuilder , StringBuilder primaryKeyBuilder ) { String [ ] primaryKeys = primaryKeyBuilder . toString ( ) . split ( "\\s*,\\s*" ) ; for ( String primaryKey : primaryKeys ) { primaryKey = primaryKey . trim ( ) . substring ( 1 , primaryKey . trim ( ) . length ( ) - 1 ) ; for ( ColumnInfo colInfo : compositeColumns ) { if ( primaryKey . equals ( colInfo . getColumnName ( ) ) ) { if ( colInfo . getOrderBy ( ) != null ) { translator . appendColumnName ( clusterKeyOrderingBuilder , colInfo . getColumnName ( ) ) ; clusterKeyOrderingBuilder . append ( translator . SPACE_STRING ) ; clusterKeyOrderingBuilder . append ( colInfo . getOrderBy ( ) ) ; clusterKeyOrderingBuilder . append ( translator . COMMA_STR ) ; } } } } if ( clusterKeyOrderingBuilder . length ( ) != 0 ) { clusterKeyOrderingBuilder . deleteCharAt ( clusterKeyOrderingBuilder . toString ( ) . lastIndexOf ( "," ) ) ; clusterKeyOrderingBuilder . append ( translator . CLOSE_BRACKET ) ; } } | Append clustering order . |
35,644 | private StringBuilder replaceColumnsAndStripLastChar ( String columnFamilyQuery , StringBuilder queryBuilder ) { if ( queryBuilder . length ( ) > 0 ) { queryBuilder . deleteCharAt ( queryBuilder . length ( ) - 1 ) ; columnFamilyQuery = StringUtils . replace ( columnFamilyQuery , CQLTranslator . COLUMNS , queryBuilder . toString ( ) ) ; queryBuilder = new StringBuilder ( columnFamilyQuery ) ; } return queryBuilder ; } | Strip last char . |
35,645 | private void createIndexUsingThrift ( TableInfo tableInfo , CfDef cfDef ) throws Exception { for ( IndexInfo indexInfo : tableInfo . getColumnsToBeIndexed ( ) ) { for ( ColumnDef columnDef : cfDef . getColumn_metadata ( ) ) { if ( new String ( columnDef . getName ( ) , Constants . ENCODING ) . equals ( indexInfo . getColumnName ( ) ) ) { columnDef . setIndex_type ( CassandraIndexHelper . getIndexType ( indexInfo . getIndexType ( ) ) ) ; } } } cassandra_client . system_update_column_family ( cfDef ) ; } | Creates the index using thrift . |
35,646 | private void createIndexUsingCql ( TableInfo tableInfo ) throws Exception { List < String > embeddedIndexes = new ArrayList < String > ( ) ; for ( EmbeddedColumnInfo embeddedColumnInfo : tableInfo . getEmbeddedColumnMetadatas ( ) ) { for ( ColumnInfo columnInfo : embeddedColumnInfo . getColumns ( ) ) { if ( columnInfo . isIndexable ( ) ) { embeddedIndexes . add ( columnInfo . getColumnName ( ) ) ; } } } StringBuilder indexQueryBuilder = new StringBuilder ( "create index if not exists on \"" ) ; indexQueryBuilder . append ( tableInfo . getTableName ( ) ) ; indexQueryBuilder . append ( "\"(\"$COLUMN_NAME\")" ) ; tableInfo . getColumnsToBeIndexed ( ) ; for ( IndexInfo indexInfo : tableInfo . getColumnsToBeIndexed ( ) ) { ColumnInfo columnInfo = new ColumnInfo ( ) ; columnInfo . setColumnName ( indexInfo . getColumnName ( ) ) ; if ( ! embeddedIndexes . contains ( indexInfo . getColumnName ( ) ) ) { String replacedWithindexName = StringUtils . replace ( indexQueryBuilder . toString ( ) , "$COLUMN_NAME" , indexInfo . getColumnName ( ) ) ; try { KunderaCoreUtils . printQuery ( replacedWithindexName , showQuery ) ; cassandra_client . execute_cql3_query ( ByteBuffer . wrap ( replacedWithindexName . getBytes ( ) ) , Compression . NONE , ConsistencyLevel . ONE ) ; } catch ( InvalidRequestException ire ) { if ( ire . getWhy ( ) != null && ! ire . getWhy ( ) . equals ( "Index already exists" ) && operation . equalsIgnoreCase ( SchemaOperationType . update . name ( ) ) ) { log . error ( "Error occurred while creating indexes on column{} of table {}, , Caused by: ." , indexInfo . getColumnName ( ) , tableInfo . getTableName ( ) , ire ) ; throw new SchemaGenerationException ( "Error occurred while creating indexes on column " + indexInfo . getColumnName ( ) + " of table " + tableInfo . getTableName ( ) , ire , "Cassandra" , databaseName ) ; } } } } } | Create secondary indexes on columns . |
35,647 | private void dropTableUsingCql ( TableInfo tableInfo ) throws Exception { CQLTranslator translator = new CQLTranslator ( ) ; StringBuilder dropQuery = new StringBuilder ( "drop table " ) ; translator . ensureCase ( dropQuery , tableInfo . getTableName ( ) , false ) ; KunderaCoreUtils . printQuery ( dropQuery . toString ( ) , showQuery ) ; cassandra_client . execute_cql3_query ( ByteBuffer . wrap ( dropQuery . toString ( ) . getBytes ( ) ) , Compression . NONE , ConsistencyLevel . ONE ) ; } | Drops table using cql3 . |
35,648 | private void addColumnToTable ( TableInfo tableInfo , ColumnInfo column ) throws Exception { CQLTranslator translator = new CQLTranslator ( ) ; StringBuilder addColumnQuery = new StringBuilder ( "ALTER TABLE " ) ; translator . ensureCase ( addColumnQuery , tableInfo . getTableName ( ) , false ) ; addColumnQuery . append ( " ADD " ) ; translator . ensureCase ( addColumnQuery , column . getColumnName ( ) , false ) ; addColumnQuery . append ( " " + translator . getCQLType ( CassandraValidationClassMapper . getValidationClass ( column . getType ( ) , isCql3Enabled ( tableInfo ) ) ) ) ; try { KunderaCoreUtils . printQuery ( addColumnQuery . toString ( ) , showQuery ) ; cassandra_client . execute_cql3_query ( ByteBuffer . wrap ( addColumnQuery . toString ( ) . getBytes ( ) ) , Compression . NONE , ConsistencyLevel . ONE ) ; } catch ( InvalidRequestException ireforAddColumn ) { StringBuilder ireforAddColumnbBuilder = new StringBuilder ( "Invalid column name " ) ; ireforAddColumnbBuilder . append ( column . getColumnName ( ) + " because it conflicts with an existing column" ) ; if ( ireforAddColumn . getWhy ( ) != null && ireforAddColumn . getWhy ( ) . equals ( ireforAddColumnbBuilder . toString ( ) ) ) { } else { log . error ( "Error occurred while altering column type of table {}, Caused by: ." , tableInfo . getTableName ( ) , ireforAddColumn ) ; throw new SchemaGenerationException ( "Error occurred while adding column into table " + tableInfo . getTableName ( ) , ireforAddColumn , "Cassandra" , databaseName ) ; } } } | Adds column to table if not exists previously i . e . alter table . |
35,649 | private void alterColumnType ( TableInfo tableInfo , CQLTranslator translator , ColumnInfo column ) throws Exception { StringBuilder alterColumnTypeQuery = new StringBuilder ( "ALTER TABLE " ) ; translator . ensureCase ( alterColumnTypeQuery , tableInfo . getTableName ( ) , false ) ; alterColumnTypeQuery . append ( " ALTER " ) ; translator . ensureCase ( alterColumnTypeQuery , column . getColumnName ( ) , false ) ; alterColumnTypeQuery . append ( " TYPE " + translator . getCQLType ( CassandraValidationClassMapper . getValidationClass ( column . getType ( ) , isCql3Enabled ( tableInfo ) ) ) ) ; cassandra_client . execute_cql3_query ( ByteBuffer . wrap ( alterColumnTypeQuery . toString ( ) . getBytes ( ) ) , Compression . NONE , ConsistencyLevel . ONE ) ; KunderaCoreUtils . printQuery ( alterColumnTypeQuery . toString ( ) , showQuery ) ; } | showSchema Alters column type of an existing column . |
35,650 | private void onCompositeColumns ( CQLTranslator translator , List < ColumnInfo > compositeColumns , StringBuilder queryBuilder , List < ColumnInfo > columns , boolean isCounterColumnFamily ) { MetamodelImpl metaModel = ( MetamodelImpl ) kunderaMetadata . getApplicationMetadata ( ) . getMetamodel ( puMetadata . getPersistenceUnitName ( ) ) ; for ( ColumnInfo colInfo : compositeColumns ) { if ( columns == null || ( columns != null && ! columns . contains ( colInfo ) ) ) { String cqlType = null ; if ( isCounterColumnFamily ) { cqlType = "counter" ; translator . appendColumnName ( queryBuilder , colInfo . getColumnName ( ) , cqlType ) ; queryBuilder . append ( Constants . SPACE_COMMA ) ; } else if ( colInfo . getType ( ) . isAnnotationPresent ( Embeddable . class ) ) { EmbeddableType embeddedObject = ( EmbeddableType ) metaModel . embeddable ( colInfo . getType ( ) ) ; for ( Field embeddedColumn : colInfo . getType ( ) . getDeclaredFields ( ) ) { if ( ! ReflectUtils . isTransientOrStatic ( embeddedColumn ) ) { validateAndAppendColumnName ( translator , queryBuilder , ( ( AbstractAttribute ) embeddedObject . getAttribute ( embeddedColumn . getName ( ) ) ) . getJPAColumnName ( ) , embeddedColumn . getType ( ) ) ; } } } else { validateAndAppendColumnName ( translator , queryBuilder , colInfo . getColumnName ( ) , colInfo . getType ( ) ) ; } } } } | On composite columns . |
35,651 | private void validateAndAppendColumnName ( CQLTranslator translator , StringBuilder queryBuilder , String b , Class < ? > clazz ) { String dataType = CassandraValidationClassMapper . getValidationClass ( clazz , true ) ; translator . appendColumnName ( queryBuilder , b , translator . getCQLType ( dataType ) ) ; queryBuilder . append ( Constants . SPACE_COMMA ) ; } | Validate and append column name . |
35,652 | private void onCollectionColumns ( CQLTranslator translator , List < CollectionColumnInfo > collectionColumnInfos , StringBuilder queryBuilder ) { for ( CollectionColumnInfo cci : collectionColumnInfos ) { String dataType = CassandraValidationClassMapper . getValidationClass ( cci . getType ( ) , true ) ; String collectionCqlType = translator . getCQLType ( dataType ) ; String collectionColumnName = new String ( cci . getCollectionColumnName ( ) ) ; StringBuilder genericTypesBuilder = null ; List < Class < ? > > genericClasses = cci . getGenericClasses ( ) ; if ( ! genericClasses . isEmpty ( ) ) { genericTypesBuilder = new StringBuilder ( ) ; if ( MapType . class . getSimpleName ( ) . equals ( dataType ) && genericClasses . size ( ) == 2 ) { genericTypesBuilder . append ( Constants . STR_LT ) ; String keyDataType = CassandraValidationClassMapper . getValidationClass ( genericClasses . get ( 0 ) , true ) ; genericTypesBuilder . append ( translator . getCQLType ( keyDataType ) ) ; genericTypesBuilder . append ( Constants . SPACE_COMMA ) ; String valueDataType = CassandraValidationClassMapper . getValidationClass ( genericClasses . get ( 1 ) , true ) ; genericTypesBuilder . append ( translator . getCQLType ( valueDataType ) ) ; genericTypesBuilder . append ( Constants . STR_GT ) ; } else if ( ( ListType . class . getSimpleName ( ) . equals ( dataType ) || SetType . class . getSimpleName ( ) . equals ( dataType ) ) && genericClasses . size ( ) == 1 ) { genericTypesBuilder . append ( Constants . STR_LT ) ; String valueDataType = CassandraValidationClassMapper . getValidationClass ( genericClasses . get ( 0 ) , true ) ; genericTypesBuilder . append ( translator . getCQLType ( valueDataType ) ) ; genericTypesBuilder . append ( Constants . STR_GT ) ; } else { throw new SchemaGenerationException ( "Incorrect collection field definition for " + cci . getCollectionColumnName ( ) + ". Generic Types must be defined correctly." ) ; } } if ( genericTypesBuilder != null ) { collectionCqlType += genericTypesBuilder . toString ( ) ; } translator . appendColumnName ( queryBuilder , collectionColumnName , collectionCqlType ) ; queryBuilder . append ( Constants . SPACE_COMMA ) ; } } | Generates schema for Collection columns . |
35,653 | private void createInvertedIndexTable ( TableInfo tableInfo , KsDef ksDef ) throws Exception { CfDef cfDef = getInvertedIndexCF ( tableInfo ) ; if ( cfDef != null ) { try { cassandra_client . system_add_column_family ( cfDef ) ; } catch ( InvalidRequestException irex ) { updateExistingColumnFamily ( tableInfo , ksDef , irex ) ; } } } | Creates the inverted index table . |
35,654 | private CfDef getInvertedIndexCF ( TableInfo tableInfo ) throws InvalidRequestException , SchemaDisagreementException , TException { boolean indexTableRequired = CassandraPropertyReader . csmd . isInvertedIndexingEnabled ( databaseName ) && ! tableInfo . getEmbeddedColumnMetadatas ( ) . isEmpty ( ) ; if ( indexTableRequired ) { CfDef cfDef = new CfDef ( ) ; cfDef . setKeyspace ( databaseName ) ; cfDef . setColumn_type ( "Super" ) ; cfDef . setName ( tableInfo . getTableName ( ) + Constants . INDEX_TABLE_SUFFIX ) ; cfDef . setKey_validation_class ( UTF8Type . class . getSimpleName ( ) ) ; return cfDef ; } return null ; } | Gets the inverted index cf . |
35,655 | private void dropInvertedIndexTable ( TableInfo tableInfo ) { boolean indexTableRequired = CassandraPropertyReader . csmd . isInvertedIndexingEnabled ( databaseName ) && ! tableInfo . getEmbeddedColumnMetadatas ( ) . isEmpty ( ) ; if ( indexTableRequired ) { try { cassandra_client . system_drop_column_family ( tableInfo . getTableName ( ) + Constants . INDEX_TABLE_SUFFIX ) ; } catch ( Exception ex ) { if ( log . isWarnEnabled ( ) ) { log . warn ( "Error while dropping inverted index table, Caused by: " , ex ) ; } } } } | Drop inverted index table . |
35,656 | private void onValidateTable ( KsDef ksDef , TableInfo tableInfo ) throws Exception { boolean tablefound = false ; for ( CfDef cfDef : ksDef . getCf_defs ( ) ) { if ( cfDef . getName ( ) . equals ( tableInfo . getTableName ( ) ) ) { if ( cfDef . getColumn_type ( ) . equals ( ColumnFamilyType . Standard . name ( ) ) ) { for ( ColumnInfo columnInfo : tableInfo . getColumnMetadatas ( ) ) { onValidateColumn ( tableInfo , cfDef , columnInfo ) ; } tablefound = true ; break ; } else if ( cfDef . getColumn_type ( ) . equals ( ColumnFamilyType . Super . name ( ) ) ) { tablefound = true ; } } } if ( ! tablefound ) { throw new SchemaGenerationException ( "Column family " + tableInfo . getTableName ( ) + " does not exist in keyspace " + databaseName + "" , "Cassandra" , databaseName , tableInfo . getTableName ( ) ) ; } } | On validate table . |
35,657 | private void onValidateColumn ( TableInfo tableInfo , CfDef cfDef , ColumnInfo columnInfo ) throws Exception { boolean columnfound = false ; boolean isCounterColumnType = isCounterColumnType ( tableInfo , null ) ; for ( ColumnDef columnDef : cfDef . getColumn_metadata ( ) ) { if ( isMetadataSame ( columnDef , columnInfo , isCql3Enabled ( tableInfo ) , isCounterColumnType ) ) { columnfound = true ; break ; } } if ( ! columnfound ) { throw new SchemaGenerationException ( "Column " + columnInfo . getColumnName ( ) + " does not exist in column family " + tableInfo . getTableName ( ) + "" , "Cassandra" , databaseName , tableInfo . getTableName ( ) ) ; } } | On validate column . |
35,658 | private boolean isMetadataSame ( ColumnDef columnDef , ColumnInfo columnInfo , boolean isCql3Enabled , boolean isCounterColumnType ) throws Exception { return isIndexPresent ( columnInfo , columnDef , isCql3Enabled , isCounterColumnType ) ; } | is metadata same method returns true if ColumnDef and columnInfo have same metadata . |
35,659 | private void updateTable ( KsDef ksDef , TableInfo tableInfo ) throws Exception { for ( CfDef cfDef : ksDef . getCf_defs ( ) ) { if ( cfDef . getName ( ) . equals ( tableInfo . getTableName ( ) ) && cfDef . getColumn_type ( ) . equals ( ColumnFamilyType . getInstanceOf ( tableInfo . getType ( ) ) . name ( ) ) ) { boolean toUpdate = false ; if ( cfDef . getColumn_type ( ) . equals ( STANDARDCOLUMNFAMILY ) ) { for ( ColumnInfo columnInfo : tableInfo . getColumnMetadatas ( ) ) { toUpdate = isCfDefUpdated ( columnInfo , cfDef , isCql3Enabled ( tableInfo ) , isCounterColumnType ( tableInfo , null ) , tableInfo ) ? true : toUpdate ; } } if ( toUpdate ) { cassandra_client . system_update_column_family ( cfDef ) ; } createIndexUsingThrift ( tableInfo , cfDef ) ; break ; } } } | Update table . |
35,660 | private boolean isCfDefUpdated ( ColumnInfo columnInfo , CfDef cfDef , boolean isCql3Enabled , boolean isCounterColumnType , TableInfo tableInfo ) throws Exception { boolean columnPresent = false ; boolean isUpdated = false ; for ( ColumnDef columnDef : cfDef . getColumn_metadata ( ) ) { if ( isColumnPresent ( columnInfo , columnDef , isCql3Enabled ) ) { if ( ! isValidationClassSame ( columnInfo , columnDef , isCql3Enabled , isCounterColumnType ) ) { columnDef . setValidation_class ( CassandraValidationClassMapper . getValidationClass ( columnInfo . getType ( ) , isCql3Enabled ) ) ; columnDef . setIndex_nameIsSet ( false ) ; columnDef . setIndex_typeIsSet ( false ) ; isUpdated = true ; } columnPresent = true ; break ; } } if ( ! columnPresent ) { cfDef . addToColumn_metadata ( getColumnMetadata ( columnInfo , tableInfo ) ) ; isUpdated = true ; } return isUpdated ; } | Checks if is cf def updated . |
35,661 | private ColumnDef getColumnMetadata ( ColumnInfo columnInfo , TableInfo tableInfo ) { ColumnDef columnDef = new ColumnDef ( ) ; columnDef . setName ( columnInfo . getColumnName ( ) . getBytes ( ) ) ; columnDef . setValidation_class ( CassandraValidationClassMapper . getValidationClass ( columnInfo . getType ( ) , isCql3Enabled ( tableInfo ) ) ) ; if ( columnInfo . isIndexable ( ) ) { IndexInfo indexInfo = tableInfo . getColumnToBeIndexed ( columnInfo . getColumnName ( ) ) ; columnDef . setIndex_type ( CassandraIndexHelper . getIndexType ( indexInfo . getIndexType ( ) ) ) ; } return columnDef ; } | getColumnMetadata use for getting column metadata for specific columnInfo . |
35,662 | private void setProperties ( KsDef ksDef , Map < String , String > strategy_options ) { Schema schema = CassandraPropertyReader . csmd . getSchema ( databaseName ) ; if ( schema != null && schema . getName ( ) != null && schema . getName ( ) . equalsIgnoreCase ( databaseName ) && schema . getSchemaProperties ( ) != null ) { setKeyspaceProperties ( ksDef , schema . getSchemaProperties ( ) , strategy_options , schema . getDataCenters ( ) ) ; } else { setDefaultReplicationFactor ( strategy_options ) ; } } | Sets the properties . |
35,663 | private void setKeyspaceProperties ( KsDef ksDef , Properties schemaProperties , Map < String , String > strategyOptions , List < DataCenter > dcs ) { String placementStrategy = schemaProperties . getProperty ( CassandraConstants . PLACEMENT_STRATEGY , SimpleStrategy . class . getSimpleName ( ) ) ; if ( placementStrategy . equalsIgnoreCase ( SimpleStrategy . class . getSimpleName ( ) ) || placementStrategy . equalsIgnoreCase ( SimpleStrategy . class . getName ( ) ) ) { String replicationFactor = schemaProperties . getProperty ( CassandraConstants . REPLICATION_FACTOR , CassandraConstants . DEFAULT_REPLICATION_FACTOR ) ; strategyOptions . put ( "replication_factor" , replicationFactor ) ; } else if ( placementStrategy . equalsIgnoreCase ( NetworkTopologyStrategy . class . getSimpleName ( ) ) || placementStrategy . equalsIgnoreCase ( NetworkTopologyStrategy . class . getName ( ) ) ) { if ( dcs != null && ! dcs . isEmpty ( ) ) { for ( DataCenter dc : dcs ) { strategyOptions . put ( dc . getName ( ) , dc . getValue ( ) ) ; } } } else { strategyOptions . put ( "replication_factor" , CassandraConstants . DEFAULT_REPLICATION_FACTOR ) ; } ksDef . setStrategy_class ( placementStrategy ) ; ksDef . setDurable_writes ( Boolean . parseBoolean ( schemaProperties . getProperty ( CassandraConstants . DURABLE_WRITES ) ) ) ; } | Sets the keyspace properties . |
35,664 | private Properties getColumnFamilyProperties ( TableInfo tableInfo ) { if ( tables != null ) { for ( Table table : tables ) { if ( table != null && table . getName ( ) != null && table . getName ( ) . equalsIgnoreCase ( tableInfo . getTableName ( ) ) ) { return table . getProperties ( ) ; } } } return null ; } | Gets the column family properties . |
35,665 | public boolean validateEntity ( Class clazz ) { EntityValidatorAgainstCounterColumn entityValidatorAgainstSchema = new EntityValidatorAgainstCounterColumn ( ) ; return entityValidatorAgainstSchema . validateEntity ( clazz ) ; } | validates entity for CounterColumnType . |
35,666 | private void setColumnFamilyProperties ( CfDef cfDef , Properties cfProperties , StringBuilder builder ) { if ( ( cfDef != null && cfProperties != null ) || ( builder != null && cfProperties != null ) ) { if ( builder != null ) { builder . append ( CQLTranslator . WITH_CLAUSE ) ; } onSetKeyValidation ( cfDef , cfProperties , builder ) ; onSetCompactionStrategy ( cfDef , cfProperties , builder ) ; onSetComparatorType ( cfDef , cfProperties , builder ) ; onSetSubComparator ( cfDef , cfProperties , builder ) ; onSetCompactionThreshold ( cfDef , cfProperties , builder ) ; onSetComment ( cfDef , cfProperties , builder ) ; onSetTableId ( cfDef , cfProperties , builder ) ; onSetGcGrace ( cfDef , cfProperties , builder ) ; onSetCaching ( cfDef , cfProperties , builder ) ; onSetBloomFilter ( cfDef , cfProperties , builder ) ; onSetRepairChance ( cfDef , cfProperties , builder ) ; onSetReadRepairChance ( cfDef , cfProperties , builder ) ; if ( builder != null && StringUtils . contains ( builder . toString ( ) , CQLTranslator . AND_CLAUSE ) ) { builder . delete ( builder . lastIndexOf ( CQLTranslator . AND_CLAUSE ) , builder . length ( ) ) ; } if ( builder != null && StringUtils . contains ( builder . toString ( ) , CQLTranslator . WITH_CLAUSE ) ) { builder . delete ( builder . lastIndexOf ( CQLTranslator . WITH_CLAUSE ) , builder . length ( ) ) ; } } } | Sets the column family properties . |
35,667 | private void onSetReadRepairChance ( CfDef cfDef , Properties cfProperties , StringBuilder builder ) { String dclocalReadRepairChance = cfProperties . getProperty ( CassandraConstants . DCLOCAL_READ_REPAIR_CHANCE ) ; if ( dclocalReadRepairChance != null ) { try { if ( builder != null ) { appendPropertyToBuilder ( builder , dclocalReadRepairChance , CassandraConstants . DCLOCAL_READ_REPAIR_CHANCE ) ; } else { cfDef . setDclocal_read_repair_chance ( Double . parseDouble ( dclocalReadRepairChance ) ) ; } } catch ( NumberFormatException nfe ) { log . error ( "READ_REPAIR_CHANCE should be double type, Caused by: {}." , nfe ) ; throw new SchemaGenerationException ( nfe ) ; } } } | On set read repair chance . |
35,668 | private void onSetRepairChance ( CfDef cfDef , Properties cfProperties , StringBuilder builder ) { String readRepairChance = cfProperties . getProperty ( CassandraConstants . READ_REPAIR_CHANCE ) ; if ( readRepairChance != null ) { try { if ( builder != null ) { appendPropertyToBuilder ( builder , readRepairChance , CassandraConstants . READ_REPAIR_CHANCE ) ; } else { cfDef . setRead_repair_chance ( Double . parseDouble ( readRepairChance ) ) ; } } catch ( NumberFormatException nfe ) { log . error ( "READ_REPAIR_CHANCE should be double type, Caused by: ." , nfe ) ; throw new SchemaGenerationException ( nfe ) ; } } } | On set repair chance . |
35,669 | private void onSetBloomFilter ( CfDef cfDef , Properties cfProperties , StringBuilder builder ) { String bloomFilterFpChance = cfProperties . getProperty ( CassandraConstants . BLOOM_FILTER_FP_CHANCE ) ; if ( bloomFilterFpChance != null ) { try { if ( builder != null ) { appendPropertyToBuilder ( builder , bloomFilterFpChance , CassandraConstants . BLOOM_FILTER_FP_CHANCE ) ; } else { cfDef . setBloom_filter_fp_chance ( Double . parseDouble ( bloomFilterFpChance ) ) ; } } catch ( NumberFormatException nfe ) { log . error ( "BLOOM_FILTER_FP_CHANCE should be double type, Caused by: ." , nfe ) ; throw new SchemaGenerationException ( nfe ) ; } } } | On set bloom filter . |
35,670 | private void onSetCaching ( CfDef cfDef , Properties cfProperties , StringBuilder builder ) { String caching = cfProperties . getProperty ( CassandraConstants . CACHING ) ; if ( caching != null ) { if ( builder != null ) { appendPropertyToBuilder ( builder , caching , CassandraConstants . CACHING ) ; } else { cfDef . setCaching ( caching ) ; } } } | On set caching . |
35,671 | private void onSetGcGrace ( CfDef cfDef , Properties cfProperties , StringBuilder builder ) { String gcGraceSeconds = cfProperties . getProperty ( CassandraConstants . GC_GRACE_SECONDS ) ; if ( gcGraceSeconds != null ) { try { if ( builder != null ) { appendPropertyToBuilder ( builder , gcGraceSeconds , CassandraConstants . GC_GRACE_SECONDS ) ; } else { cfDef . setGc_grace_seconds ( Integer . parseInt ( gcGraceSeconds ) ) ; } } catch ( NumberFormatException nfe ) { log . error ( "GC_GRACE_SECONDS should be numeric type, Caused by: ." , nfe ) ; throw new SchemaGenerationException ( nfe ) ; } } } | On set gc grace . |
35,672 | private void onSetTableId ( CfDef cfDef , Properties cfProperties , StringBuilder builder ) { String id = cfProperties . getProperty ( CassandraConstants . ID ) ; if ( id != null ) { try { if ( builder != null ) { } else { cfDef . setId ( Integer . parseInt ( id ) ) ; } } catch ( NumberFormatException nfe ) { log . error ( "Id should be numeric type, Caused by: " , nfe ) ; throw new SchemaGenerationException ( nfe ) ; } } } | On set table id . |
35,673 | private void onSetComment ( CfDef cfDef , Properties cfProperties , StringBuilder builder ) { String comment = cfProperties . getProperty ( CassandraConstants . COMMENT ) ; if ( comment != null ) { if ( builder != null ) { String comment_Str = CQLTranslator . getKeyword ( CassandraConstants . COMMENT ) ; builder . append ( comment_Str ) ; builder . append ( CQLTranslator . EQ_CLAUSE ) ; builder . append ( CQLTranslator . QUOTE_STR ) ; builder . append ( comment ) ; builder . append ( CQLTranslator . QUOTE_STR ) ; builder . append ( CQLTranslator . AND_CLAUSE ) ; } else { cfDef . setComment ( comment ) ; } } } | On set comment . |
35,674 | private void onSetReplicateOnWrite ( CfDef cfDef , Properties cfProperties , StringBuilder builder ) { String replicateOnWrite = cfProperties . getProperty ( CassandraConstants . REPLICATE_ON_WRITE ) ; if ( builder != null ) { String replicateOn_Write = CQLTranslator . getKeyword ( CassandraConstants . REPLICATE_ON_WRITE ) ; builder . append ( replicateOn_Write ) ; builder . append ( CQLTranslator . EQ_CLAUSE ) ; builder . append ( Boolean . parseBoolean ( replicateOnWrite ) ) ; builder . append ( CQLTranslator . AND_CLAUSE ) ; } else if ( cfDef != null ) { cfDef . setReplicate_on_write ( false ) ; } } | On set replicate on write . |
35,675 | private void onSetCompactionThreshold ( CfDef cfDef , Properties cfProperties , StringBuilder builder ) { String maxCompactionThreshold = cfProperties . getProperty ( CassandraConstants . MAX_COMPACTION_THRESHOLD ) ; if ( maxCompactionThreshold != null ) { try { if ( builder != null ) { } else { cfDef . setMax_compaction_threshold ( Integer . parseInt ( maxCompactionThreshold ) ) ; } } catch ( NumberFormatException nfe ) { log . error ( "Max_Compaction_Threshold should be numeric type, Caused by: ." , nfe ) ; throw new SchemaGenerationException ( nfe ) ; } } String minCompactionThreshold = cfProperties . getProperty ( CassandraConstants . MIN_COMPACTION_THRESHOLD ) ; if ( minCompactionThreshold != null ) { try { if ( builder != null ) { } else { cfDef . setMin_compaction_threshold ( Integer . parseInt ( minCompactionThreshold ) ) ; } } catch ( NumberFormatException nfe ) { log . error ( "Min_Compaction_Threshold should be numeric type, Caused by: . " , nfe ) ; throw new SchemaGenerationException ( nfe ) ; } } } | On set compaction threshold . |
35,676 | private void onSetSubComparator ( CfDef cfDef , Properties cfProperties , StringBuilder builder ) { String subComparatorType = cfProperties . getProperty ( CassandraConstants . SUBCOMPARATOR_TYPE ) ; if ( subComparatorType != null && ColumnFamilyType . valueOf ( cfDef . getColumn_type ( ) ) == ColumnFamilyType . Super ) { if ( builder != null ) { } else { cfDef . setSubcomparator_type ( subComparatorType ) ; } } } | On set sub comparator . |
35,677 | private void onSetComparatorType ( CfDef cfDef , Properties cfProperties , StringBuilder builder ) { String comparatorType = cfProperties . getProperty ( CassandraConstants . COMPARATOR_TYPE ) ; if ( comparatorType != null ) { if ( builder != null ) { } else { cfDef . setComparator_type ( comparatorType ) ; } } } | On set comparator type . |
35,678 | private void onSetCompactionStrategy ( CfDef cfDef , Properties cfProperties , StringBuilder builder ) { String compactionStrategy = cfProperties . getProperty ( CassandraConstants . COMPACTION_STRATEGY ) ; if ( compactionStrategy != null ) { if ( builder != null ) { String strategy_class = CQLTranslator . getKeyword ( CassandraConstants . COMPACTION_STRATEGY ) ; builder . append ( strategy_class ) ; builder . append ( CQLTranslator . EQ_CLAUSE ) ; builder . append ( CQLTranslator . QUOTE_STR ) ; builder . append ( compactionStrategy ) ; builder . append ( CQLTranslator . QUOTE_STR ) ; builder . append ( CQLTranslator . AND_CLAUSE ) ; } else { cfDef . setCompaction_strategy ( compactionStrategy ) ; } } } | On set compaction strategy . |
35,679 | private void onSetKeyValidation ( CfDef cfDef , Properties cfProperties , StringBuilder builder ) { String keyValidationClass = cfProperties . getProperty ( CassandraConstants . KEY_VALIDATION_CLASS ) ; if ( keyValidationClass != null ) { if ( builder != null ) { } else { cfDef . setKey_validation_class ( keyValidationClass ) ; } } } | On set key validation . |
35,680 | private boolean isCql3Enabled ( TableInfo tableInfo ) { Properties cfProperties = getColumnFamilyProperties ( tableInfo ) ; String defaultValidationClass = cfProperties != null ? cfProperties . getProperty ( CassandraConstants . DEFAULT_VALIDATION_CLASS ) : null ; boolean isCounterColumnType = isCounterColumnType ( tableInfo , defaultValidationClass ) ; return containsCompositeKey ( tableInfo ) || containsCollectionColumns ( tableInfo ) || ( ( cql_version != null && cql_version . equals ( CassandraConstants . CQL_VERSION_3_0 ) ) && ( containsEmbeddedColumns ( tableInfo ) || containsElementCollectionColumns ( tableInfo ) ) ) && ! isCounterColumnType || ( ( cql_version != null && cql_version . equals ( CassandraConstants . CQL_VERSION_3_0 ) ) && ! tableInfo . getType ( ) . equals ( Type . SUPER_COLUMN_FAMILY . name ( ) ) ) ; } | Checks if is cql3 enabled . |
35,681 | private void appendPropertyToBuilder ( StringBuilder builder , String replicateOnWrite , String keyword ) { String replicateOn_Write = CQLTranslator . getKeyword ( keyword ) ; builder . append ( replicateOn_Write ) ; builder . append ( CQLTranslator . EQ_CLAUSE ) ; builder . append ( replicateOnWrite ) ; builder . append ( CQLTranslator . AND_CLAUSE ) ; } | Append property to builder . |
35,682 | private void validateCompoundKey ( TableInfo tableInfo ) { if ( tableInfo . getType ( ) != null && tableInfo . getType ( ) . equals ( Type . SUPER_COLUMN_FAMILY . name ( ) ) ) { throw new SchemaGenerationException ( "Composite/Compound columns are not yet supported over Super column family by Cassandra" , "cassandra" , databaseName ) ; } } | Validate compound key . |
35,683 | private void onLog ( TableInfo tableInfo , CqlMetadata metadata , Map < ByteBuffer , String > value_types , CqlMetadata originalMetadata ) throws CharacterCodingException { System . out . format ( "Persisted Schema for " + tableInfo . getTableName ( ) ) ; System . out . format ( "\n" ) ; System . out . format ( "Column Name: \t\t Column name type" ) ; System . out . format ( "\n" ) ; printInfo ( originalMetadata ) ; System . out . format ( "\n" ) ; System . out . format ( "Mapped schema for " + tableInfo . getTableName ( ) ) ; System . out . format ( "\n" ) ; System . out . format ( "Column Name: \t\t Column name type" ) ; System . out . format ( "\n" ) ; printInfo ( metadata ) ; } | Print log in case schema doesn t match! . |
35,684 | private boolean isCounterColumnType ( TableInfo tableInfo , String defaultValidationClass ) { return ( csmd != null && csmd . isCounterColumn ( databaseName , tableInfo . getTableName ( ) ) ) || ( defaultValidationClass != null && ( defaultValidationClass . equalsIgnoreCase ( CounterColumnType . class . getSimpleName ( ) ) || defaultValidationClass . equalsIgnoreCase ( CounterColumnType . class . getName ( ) ) ) || ( tableInfo . getType ( ) . equals ( CounterColumnType . class . getSimpleName ( ) ) ) ) ; } | Checks if is counter column type . |
35,685 | private Object fetch ( Class clazz , Object key , Object connection , byte [ ] [ ] fields ) throws InstantiationException , IllegalAccessException { Object result = null ; EntityMetadata entityMetadata = KunderaMetadataManager . getEntityMetadata ( kunderaMetadata , clazz ) ; MetamodelImpl metaModel = ( MetamodelImpl ) kunderaMetadata . getApplicationMetadata ( ) . getMetamodel ( entityMetadata . getPersistenceUnit ( ) ) ; String rowKey = null ; if ( metaModel . isEmbeddable ( entityMetadata . getIdAttribute ( ) . getBindableJavaType ( ) ) ) { if ( key instanceof String && ( ( String ) key ) . indexOf ( COMPOSITE_KEY_SEPERATOR ) > 0 ) { rowKey = ( String ) key ; } else { rowKey = KunderaCoreUtils . prepareCompositeKey ( entityMetadata , key ) ; } } else { ObjectAccessor accessor = new ObjectAccessor ( ) ; rowKey = accessor . toString ( key ) ; } String hashKey = getHashKey ( entityMetadata . getTableName ( ) , rowKey ) ; KunderaCoreUtils . printQuery ( "Fetch data from " + entityMetadata . getTableName ( ) + " for PK " + rowKey , showQuery ) ; try { Map < byte [ ] , byte [ ] > columns = new HashMap < byte [ ] , byte [ ] > ( ) ; if ( fields != null ) { List < byte [ ] > fieldValues = null ; if ( resource != null && resource . isActive ( ) ) { Response response = ( ( Transaction ) connection ) . hmget ( getEncodedBytes ( hashKey ) , fields ) ; ( ( RedisTransaction ) resource ) . onExecute ( ( ( Transaction ) connection ) ) ; fieldValues = ( List < byte [ ] > ) response . get ( ) ; connection = getConnection ( ) ; } else { fieldValues = ( ( Jedis ) connection ) . hmget ( getEncodedBytes ( hashKey ) , fields ) ; } if ( fieldValues != null && ! fieldValues . isEmpty ( ) ) { for ( int i = 0 ; i < fields . length ; i ++ ) { if ( fieldValues . get ( i ) != null ) { columns . put ( fields [ i ] , fieldValues . get ( i ) ) ; } } } } else { columns = getColumns ( connection , hashKey , columns ) ; } result = unwrap ( entityMetadata , columns , key ) ; } catch ( JedisConnectionException jedex ) { return null ; } return result ; } | Retrieves entity instance of given class row key and specific fields . |
35,686 | private void deleteRelation ( Object connection , EntityMetadata entityMetadata , String rowKey ) { List < String > relations = entityMetadata . getRelationNames ( ) ; if ( relations != null ) { for ( String relation : relations ) { if ( resource != null && resource . isActive ( ) ) { ( ( Transaction ) connection ) . hdel ( getHashKey ( entityMetadata . getTableName ( ) , rowKey ) , relation ) ; } else { ( ( Pipeline ) connection ) . hdel ( getHashKey ( entityMetadata . getTableName ( ) , rowKey ) , relation ) ; } } } } | On delete relation . |
35,687 | private List fetchColumn ( String columnName , Object connection , List results , Set < String > resultKeys ) { for ( String hashKey : resultKeys ) { List columnValues = null ; if ( resource != null && resource . isActive ( ) ) { Response response = ( ( Transaction ) connection ) . hmget ( hashKey , columnName ) ; ( ( RedisTransaction ) resource ) . onExecute ( ( ( Transaction ) connection ) ) ; columnValues = ( List ) response . get ( ) ; } else { columnValues = ( ( Jedis ) connection ) . hmget ( hashKey , columnName ) ; } if ( columnValues != null && ! columnValues . isEmpty ( ) ) { results . addAll ( columnValues ) ; } } return results ; } | Fetch column . |
35,688 | private Object [ ] findIdsByColumn ( String tableName , String columnName , Object columnValue ) { Object connection = null ; try { connection = getConnection ( ) ; String valueAsStr = PropertyAccessorHelper . getString ( columnValue ) ; Set < String > results = null ; if ( resource != null && resource . isActive ( ) ) { Response response = ( ( Transaction ) connection ) . zrangeByScore ( getHashKey ( tableName , columnName ) , getDouble ( valueAsStr ) , getDouble ( valueAsStr ) ) ; ( ( RedisTransaction ) resource ) . onExecute ( ( ( Transaction ) connection ) ) ; results = ( Set < String > ) response . get ( ) ; } else { results = ( ( Jedis ) connection ) . zrangeByScore ( getHashKey ( tableName , columnName ) , getDouble ( valueAsStr ) , getDouble ( valueAsStr ) ) ; } if ( results != null ) { return results . toArray ( new Object [ 0 ] ) ; } } finally { onCleanup ( connection ) ; } return null ; } | Find ids by column . |
35,689 | private String getHashKey ( final String tableName , final String rowKey ) { StringBuilder builder = new StringBuilder ( tableName ) ; builder . append ( ":" ) ; builder . append ( rowKey ) ; return builder . toString ( ) ; } | Returns hash key . |
35,690 | byte [ ] getEncodedBytes ( final String name ) { try { if ( name != null ) { return name . getBytes ( Constants . CHARSET_UTF8 ) ; } } catch ( UnsupportedEncodingException e ) { logger . error ( "Error during persist, Caused by:" , e ) ; throw new PersistenceException ( e ) ; } return null ; } | Returns encoded bytes . |
35,691 | private void addIndex ( final Object connection , final AttributeWrapper wrapper , final String rowKey , final EntityMetadata metadata ) { Indexer indexer = indexManager . getIndexer ( ) ; if ( indexer != null && indexer . getClass ( ) . getSimpleName ( ) . equals ( "RedisIndexer" ) ) { wrapper . addIndex ( getHashKey ( metadata . getTableName ( ) , ( ( AbstractAttribute ) metadata . getIdAttribute ( ) ) . getJPAColumnName ( ) ) , getDouble ( rowKey ) ) ; wrapper . addIndex ( getHashKey ( metadata . getTableName ( ) , getHashKey ( ( ( AbstractAttribute ) metadata . getIdAttribute ( ) ) . getJPAColumnName ( ) , rowKey ) ) , getDouble ( rowKey ) ) ; indexer . index ( metadata . getEntityClazz ( ) , metadata , wrapper . getIndexes ( ) , rowKey , null ) ; } } | Add inverted index in sorted set . |
35,692 | private void unIndex ( final Object connection , final AttributeWrapper wrapper , final String member ) { Set < String > keys = wrapper . getIndexes ( ) . keySet ( ) ; for ( String key : keys ) { if ( resource != null && resource . isActive ( ) ) { ( ( Transaction ) connection ) . zrem ( key , member ) ; } else { ( ( Pipeline ) connection ) . zrem ( key , member ) ; } } } | Deletes inverted indexes from redis . |
35,693 | private void onCleanup ( Object connection ) { if ( this . connection != null ) { if ( settings != null ) { ( ( Jedis ) connection ) . configResetStat ( ) ; } factory . releaseConnection ( ( Jedis ) this . connection ) ; } this . connection = null ; } | On release connection . |
35,694 | private void addToWrapper ( EntityMetadata entityMetadata , AttributeWrapper wrapper , Object resultedObject , Attribute attrib ) { addToWrapper ( entityMetadata , wrapper , resultedObject , attrib , null ) ; } | Adds field to wrapper . |
35,695 | private Object reInitialize ( Object connection , Set < String > rowKeys ) { connection = getConnection ( ) ; return connection ; } | Re initialize . |
35,696 | private < E > List < E > findAllColumns ( Class < E > entityClass , byte [ ] [ ] columns , Object ... keys ) { Object connection = getConnection ( ) ; List results = new ArrayList ( ) ; try { for ( Object key : keys ) { Object result = fetch ( entityClass , key , connection , columns ) ; if ( result != null ) { results . add ( result ) ; } } } catch ( InstantiationException e ) { logger . error ( "Error during find by key:" , e ) ; throw new PersistenceException ( e ) ; } catch ( IllegalAccessException e ) { logger . error ( "Error during find by key:" , e ) ; throw new PersistenceException ( e ) ; } return results ; } | Find all columns . |
35,697 | private Object getConnection ( ) { if ( isBoundTransaction ( ) && this . connection != null ) { return this . connection ; } if ( resource != null && resource . isActive ( ) ) { if ( ( ( RedisTransaction ) resource ) . isResourceBound ( ) ) { return ( ( RedisTransaction ) resource ) . getResource ( ) ; } else { Jedis conn = getAndSetConnection ( ) ; return ( ( RedisTransaction ) resource ) . bindResource ( conn ) ; } } else { Jedis conn = getAndSetConnection ( ) ; return conn ; } } | Returns jedis connection . |
35,698 | private Jedis getAndSetConnection ( ) { Jedis conn = factory . getConnection ( ) ; this . connection = conn ; if ( settings != null ) { for ( String key : settings . keySet ( ) ) { conn . configSet ( key , settings . get ( key ) . toString ( ) ) ; } } return conn ; } | Gets the and set connection . |
35,699 | private void initializeIndexer ( ) { if ( this . indexManager . getIndexer ( ) != null && this . indexManager . getIndexer ( ) . getClass ( ) . getSimpleName ( ) . equals ( "RedisIndexer" ) ) { ( ( RedisIndexer ) this . indexManager . getIndexer ( ) ) . assignConnection ( getConnection ( ) ) ; } } | Initialize indexer . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.