Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 63090200CC3 for ; Sat, 15 Jul 2017 12:15:49 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 61BA616AE09; Sat, 15 Jul 2017 10:15:49 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (unknown [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id BA5E516AE17 for ; Sat, 15 Jul 2017 12:15:47 +0200 (CEST) Received: (qmail 7708 invoked by uid 500); 15 Jul 2017 10:15:47 -0000 Mailing-List: contact commits-help@polygene.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@polygene.apache.org Delivered-To: mailing list commits@polygene.apache.org Received: (qmail 7380 invoked by uid 99); 15 Jul 2017 10:15:46 -0000 Received: from Unknown (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 15 Jul 2017 10:15:46 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 049D3F5529; Sat, 15 Jul 2017 10:15:44 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: niclas@apache.org To: commits@polygene.apache.org Date: Sat, 15 Jul 2017 10:15:45 -0000 Message-Id: <5d1e992070ec47a7bccadb89cf5d8a00@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [02/14] polygene-java git commit: Get rid of warnings, and some reformatting of a messy class. archived-at: Sat, 15 Jul 2017 10:15:49 -0000 Get rid of warnings, and some reformatting of a messy class. Project: http://git-wip-us.apache.org/repos/asf/polygene-java/repo Commit: http://git-wip-us.apache.org/repos/asf/polygene-java/commit/58b81749 Tree: http://git-wip-us.apache.org/repos/asf/polygene-java/tree/58b81749 Diff: http://git-wip-us.apache.org/repos/asf/polygene-java/diff/58b81749 Branch: refs/heads/develop Commit: 58b81749bfe27d204d85154f64fcc9806331701b Parents: 002fb1c Author: niclas Authored: Sun Jul 9 12:36:19 2017 +0800 Committer: niclas Committed: Sun Jul 9 12:36:19 2017 +0800 ---------------------------------------------------------------------- .../support/skeletons/AbstractSQLIndexing.java | 281 ++++++++++--------- 1 file changed, 141 insertions(+), 140 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/polygene-java/blob/58b81749/extensions/indexing-sql/src/main/java/org/apache/polygene/index/sql/support/skeletons/AbstractSQLIndexing.java ---------------------------------------------------------------------- diff --git a/extensions/indexing-sql/src/main/java/org/apache/polygene/index/sql/support/skeletons/AbstractSQLIndexing.java b/extensions/indexing-sql/src/main/java/org/apache/polygene/index/sql/support/skeletons/AbstractSQLIndexing.java index 47e0503..a250d66 100644 --- a/extensions/indexing-sql/src/main/java/org/apache/polygene/index/sql/support/skeletons/AbstractSQLIndexing.java +++ b/extensions/indexing-sql/src/main/java/org/apache/polygene/index/sql/support/skeletons/AbstractSQLIndexing.java @@ -87,13 +87,16 @@ public abstract class AbstractSQLIndexing implements SQLIndexing { - public static final Integer AMOUNT_OF_COLUMNS_IN_ENTITY_TABLE = 5; + protected static final Integer AMOUNT_OF_COLUMNS_IN_ENTITY_TABLE = 5; - public static final Integer AMOUNT_OF_COLUMNS_IN_ALL_QNAMES_TABLE = 2; + @SuppressWarnings( "WeakerAccess" ) + protected static final Integer AMOUNT_OF_COLUMNS_IN_ALL_QNAMES_TABLE = 2; - public static final Integer AMOUNT_OF_COLUMNS_IN_ASSO_TABLE = 2; + @SuppressWarnings( "WeakerAccess" ) + protected static final Integer AMOUNT_OF_COLUMNS_IN_ASSO_TABLE = 2; - public static final Integer AMOUNT_OF_COLUMNS_IN_MANY_ASSO_TABLE = 3; + @SuppressWarnings( "WeakerAccess" ) + protected static final Integer AMOUNT_OF_COLUMNS_IN_MANY_ASSO_TABLE = 3; @Structure private Application _app; @@ -299,10 +302,11 @@ public abstract class AbstractSQLIndexing } } + @SuppressWarnings( "WeakerAccess" ) protected InsertStatement createInsertStatement( String schemaName, String tableName, Integer amountOfColumns, SQLVendor vendor - ) + ) { ModificationFactory m = vendor.getModificationFactory(); LiteralFactory l = vendor.getLiteralFactory(); @@ -315,16 +319,14 @@ public abstract class AbstractSQLIndexing } return m.insert().setTableName( t.tableName( schemaName, tableName ) ) - .setColumnSource( columnBuilder.createExpression() ).createExpression(); + .setColumnSource( columnBuilder.createExpression() ).createExpression(); } protected abstract InsertStatement createInsertStatementWithAutoGeneratedIDForEntitiesTable( - String schemaName, String tableName, SQLVendor vendor - ); + String schemaName, String tableName, SQLVendor vendor ); - protected void addEntityInfoToInsertToEntityTablePS( EntityState state, PreparedStatement ps, - int startingIndex - ) + @SuppressWarnings( "SameParameterValue" ) + protected void addEntityInfoToInsertToEntityTablePS( EntityState state, PreparedStatement ps, int startingIndex ) throws SQLException { ps.setString( startingIndex, state.entityReference().identity().toString() ); @@ -333,9 +335,8 @@ public abstract class AbstractSQLIndexing ps.setString( startingIndex + 3, this._app.version() ); } - protected Long findEntityPK( EntityState state, - Lazy queryPKPS - ) + @SuppressWarnings( "WeakerAccess" ) + protected Long findEntityPK( EntityState state, Lazy queryPKPS ) throws SQLException { // TODO build cache: Polygene Identity -> PK @@ -363,11 +364,11 @@ public abstract class AbstractSQLIndexing protected abstract long getPKFromAutoGeneratedIDInsert( EntityState state, PreparedStatement autoGeneratedIDStatement, SQLVendor vendor, Connection connection - ) + ) throws SQLException; - protected UpdateStatement - createUpdateEntityTableStatement( String schemaName, SQLVendor vendor ) + @SuppressWarnings( "WeakerAccess" ) + protected UpdateStatement createUpdateEntityTableStatement( String schemaName, SQLVendor vendor ) { ModificationFactory m = vendor.getModificationFactory(); BooleanFactory b = vendor.getBooleanFactory(); @@ -397,9 +398,8 @@ public abstract class AbstractSQLIndexing return builder.createExpression(); } - protected QueryExpression createQueryEntityPkByIdentityStatement( String schemaName, - SQLVendor vendor - ) + @SuppressWarnings( "WeakerAccess" ) + protected QueryExpression createQueryEntityPkByIdentityStatement( String schemaName, SQLVendor vendor ) { BooleanFactory b = vendor.getBooleanFactory(); LiteralFactory l = vendor.getLiteralFactory(); @@ -421,25 +421,25 @@ public abstract class AbstractSQLIndexing return q.createQuery( query.createExpression() ); } - protected DeleteStatement createDeleteFromEntityTableStatement( String schemaName, - SQLVendor vendor - ) + @SuppressWarnings( "WeakerAccess" ) + protected DeleteStatement createDeleteFromEntityTableStatement( String schemaName, SQLVendor vendor ) { return this.createDeleteFromTableStatement( schemaName, DBNames.ENTITY_TABLE_NAME, DBNames.ENTITY_TABLE_IDENTITY_COLUMN_NAME, vendor ); } - protected DeleteStatement - createClearEntityDataStatement( String schemaName, SQLVendor vendor ) + @SuppressWarnings( "WeakerAccess" ) + protected DeleteStatement createClearEntityDataStatement( String schemaName, SQLVendor vendor ) { return this.createDeleteFromTableStatement( schemaName, DBNames.ALL_QNAMES_TABLE_NAME, DBNames.ENTITY_TABLE_PK_COLUMN_NAME, vendor ); } + @SuppressWarnings( "WeakerAccess" ) protected DeleteStatement createDeleteFromTableStatement( String schemaName, String tableName, String columnName, SQLVendor vendor - ) + ) { ModificationFactory m = vendor.getModificationFactory(); BooleanFactory b = vendor.getBooleanFactory(); @@ -452,12 +452,13 @@ public abstract class AbstractSQLIndexing // ";" // DeleteBySearchBuilder delete = m.deleteBySearch(); delete.setTargetTable( m.createTargetTable( t.tableName( schemaName, tableName ) ) ) - .getWhere() - .reset( b.eq( c.colName( columnName ), l.param() ) ); + .getWhere() + .reset( b.eq( c.colName( columnName ), l.param() ) ); return delete.createExpression(); } + @SuppressWarnings( "WeakerAccess" ) protected InsertStatement createPropertyInsert( QNameInfo qNameInfo, SQLVendor vendor ) { String tableName = qNameInfo.getTableName(); @@ -466,7 +467,7 @@ public abstract class AbstractSQLIndexing LiteralFactory l = vendor.getLiteralFactory(); ColumnSourceByValuesBuilder columnBuilder = m.columnSourceByValues() - .addValues( l.param(), l.param(), l.param() ); + .addValues( l.param(), l.param(), l.param() ); if( qNameInfo.getCollectionDepth() > 0 ) { columnBuilder.addValues( l.func( "text2ltree", l.param() ) ); @@ -474,12 +475,13 @@ public abstract class AbstractSQLIndexing columnBuilder.addValues( l.param() ); return m.insert().setTableName( t.tableName( this._state.schemaName().get(), tableName ) ) - .setColumnSource( columnBuilder.createExpression() ).createExpression(); + .setColumnSource( columnBuilder.createExpression() ).createExpression(); } + @SuppressWarnings( "WeakerAccess" ) protected InsertStatement createAssoInsert( QNameInfo qNameInfo, SQLVendor vendor, Integer amountOfParams - ) + ) { ModificationFactory m = vendor.getModificationFactory(); LiteralFactory l = vendor.getLiteralFactory(); @@ -512,6 +514,7 @@ public abstract class AbstractSQLIndexing .createExpression(); } + @SuppressWarnings( "WeakerAccess" ) protected InsertStatement createInsertEntityTypeStatement( String schemaName, SQLVendor vendor ) { return this.createInsertStatement( schemaName, ENTITY_TYPES_JOIN_TABLE_NAME, 2, vendor ); @@ -520,7 +523,7 @@ public abstract class AbstractSQLIndexing private void syncQNamesInsertPSs( Connection connection, Map qNameInsertPSs, Set qNames - ) + ) throws SQLException { Set copy = new HashSet<>( qNames ); @@ -530,8 +533,7 @@ public abstract class AbstractSQLIndexing QNameInfo info = this._state.qNameInfos().get().get( qName ); if( info == null ) { - throw new InternalError( - "Could not find database information about qualified name [" + qName + "]" ); + throw new SqlIndexingException( "Could not find database information about qualified name [" + qName + "]" ); } QNameType type = info.getQNameType(); @@ -549,8 +551,7 @@ public abstract class AbstractSQLIndexing } else { - throw new IllegalArgumentException( "Did not know what to do with QName of type " - + type + "." ); + throw new SqlIndexingException( "Did not know what to do with QName of type " + type + "." ); } } } @@ -575,7 +576,7 @@ public abstract class AbstractSQLIndexing private PreparedStatement createInsertManyAssociationPS( Connection connection, QNameInfo qNameInfo - ) + ) throws SQLException { SQLVendor vendor = this.descriptor.metaInfo( SQLVendor.class ); @@ -594,34 +595,34 @@ public abstract class AbstractSQLIndexing private Integer insertPropertyQNames( Connection connection, Map qNameInsertPSs, PreparedStatement insertAllQNamesPS, EntityState state, Long entityPK - ) + ) throws SQLException { Set qNames = this._state.entityUsedQNames().get().get( state.entityDescriptor() ); this.syncQNamesInsertPSs( connection, qNameInsertPSs, qNames ); - final Integer propertyPK[] = {0}; + final Integer propertyPK[] = { 0 }; state.entityDescriptor().state().properties() - .filter( pDesc -> SQLSkeletonUtil.isQueryable( pDesc.accessor() ) ) - .forEach( pDesc -> { - try - { - propertyPK[0] = this.insertProperty( - qNameInsertPSs, - insertAllQNamesPS, - propertyPK[0], - entityPK, - pDesc.qualifiedName(), - state.propertyValueOf( pDesc.qualifiedName() ), - null // - ); - } - catch( SQLException e ) - { - throw new EntityStoreException( "Underlying exception when inserting property " + pDesc, - SQLUtil.withAllSQLExceptions( e ) ); - } - } ); - return propertyPK[0]; + .filter( pDesc -> SQLSkeletonUtil.isQueryable( pDesc.accessor() ) ) + .forEach( pDesc -> { + try + { + propertyPK[ 0 ] = this.insertProperty( + qNameInsertPSs, + insertAllQNamesPS, + propertyPK[ 0 ], + entityPK, + pDesc.qualifiedName(), + state.propertyValueOf( pDesc.qualifiedName() ), + null // + ); + } + catch( SQLException e ) + { + throw new EntityStoreException( "Underlying exception when inserting property " + pDesc, + SQLUtil.withAllSQLExceptions( e ) ); + } + } ); + return propertyPK[ 0 ]; } private void insertAssoAndManyAssoQNames( Map qNameInsertPSs, @@ -629,71 +630,71 @@ public abstract class AbstractSQLIndexing EntityState state, final Integer localPK, Long entityPK - ) + ) throws SQLException { - final Integer[] qNamePK = {localPK}; + final Integer[] qNamePK = { localPK }; state.entityDescriptor().state().associations() - .filter( aDesc -> SQLSkeletonUtil.isQueryable( aDesc.accessor() ) ) - .forEach( aDesc -> { - try - { - QualifiedName qName = aDesc.qualifiedName(); - PreparedStatement ps = qNameInsertPSs.get( qName ); - EntityReference ref = state.associationValueOf( qName ); - if( ref != null ) - { - insertToAllQNamesPS.setInt( 1, qNamePK[0] ); - insertToAllQNamesPS.setLong( 2, entityPK ); - insertToAllQNamesPS.addBatch(); - - ps.setInt( 1, qNamePK[0] ); - ps.setLong( 2, entityPK ); - ps.setString( 3, ref.identity().toString() ); - ps.addBatch(); - - qNamePK[0] += 1; - } - } - catch( SQLException e ) - { - throw new EntityStoreException( "Underlying exception when inserting association " + aDesc, - SQLUtil.withAllSQLExceptions( e ) ); - } - } ); + .filter( aDesc -> SQLSkeletonUtil.isQueryable( aDesc.accessor() ) ) + .forEach( aDesc -> { + try + { + QualifiedName qName = aDesc.qualifiedName(); + PreparedStatement ps = qNameInsertPSs.get( qName ); + EntityReference ref = state.associationValueOf( qName ); + if( ref != null ) + { + insertToAllQNamesPS.setInt( 1, qNamePK[ 0 ] ); + insertToAllQNamesPS.setLong( 2, entityPK ); + insertToAllQNamesPS.addBatch(); + + ps.setInt( 1, qNamePK[ 0 ] ); + ps.setLong( 2, entityPK ); + ps.setString( 3, ref.identity().toString() ); + ps.addBatch(); + + qNamePK[ 0 ] += 1; + } + } + catch( SQLException e ) + { + throw new EntityStoreException( "Underlying exception when inserting association " + aDesc, + SQLUtil.withAllSQLExceptions( e ) ); + } + } ); state.entityDescriptor().state().manyAssociations() - .filter( mDesc -> SQLSkeletonUtil.isQueryable( mDesc.accessor() ) ) - .forEach( mDesc -> { - try - { - QualifiedName qName = mDesc.qualifiedName(); - PreparedStatement ps = qNameInsertPSs.get( qName ); - Integer index = 0; - for( EntityReference ref : state.manyAssociationValueOf( qName ) ) - { - if( ref != null ) - { - insertToAllQNamesPS.setInt( 1, qNamePK[0] ); - insertToAllQNamesPS.setLong( 2, entityPK ); - insertToAllQNamesPS.addBatch(); - - ps.setInt( 1, qNamePK[0] ); - ps.setLong( 2, entityPK ); - ps.setInt( 3, index ); - ps.setString( 4, ref.identity().toString() ); - ps.addBatch(); - qNamePK[0] += 1; - } - ++index; - } - } - catch( SQLException e ) - { - throw new EntityStoreException( "Underlying exception when inserting manyassociation " + mDesc, - SQLUtil.withAllSQLExceptions( e ) ); - } - } ); + .filter( mDesc -> SQLSkeletonUtil.isQueryable( mDesc.accessor() ) ) + .forEach( mDesc -> { + try + { + QualifiedName qName = mDesc.qualifiedName(); + PreparedStatement ps = qNameInsertPSs.get( qName ); + Integer index = 0; + for( EntityReference ref : state.manyAssociationValueOf( qName ) ) + { + if( ref != null ) + { + insertToAllQNamesPS.setInt( 1, qNamePK[ 0 ] ); + insertToAllQNamesPS.setLong( 2, entityPK ); + insertToAllQNamesPS.addBatch(); + + ps.setInt( 1, qNamePK[ 0 ] ); + ps.setLong( 2, entityPK ); + ps.setInt( 3, index ); + ps.setString( 4, ref.identity().toString() ); + ps.addBatch(); + qNamePK[ 0 ] += 1; + } + ++index; + } + } + catch( SQLException e ) + { + throw new EntityStoreException( "Underlying exception when inserting manyassociation " + mDesc, + SQLUtil.withAllSQLExceptions( e ) ); + } + } ); } private Integer insertProperty( @@ -704,7 +705,7 @@ public abstract class AbstractSQLIndexing QualifiedName qName, Object property, Integer parentQNameID - ) + ) throws SQLException { Integer result = propertyPK; @@ -744,7 +745,7 @@ public abstract class AbstractSQLIndexing QualifiedName qName, Collection property, Integer parentQNameID - ) + ) throws SQLException { QNameInfo info = this._state.qNameInfos().get().get( qName ); @@ -762,7 +763,7 @@ public abstract class AbstractSQLIndexing private Integer storeCollectionInfo( PreparedStatement insertAllQNamesPS, Integer propertyPK, Long entityPK, Integer parentQNameID, PreparedStatement ps, QNameInfo info - ) + ) throws SQLException { insertAllQNamesPS.setInt( 1, propertyPK ); @@ -798,7 +799,7 @@ public abstract class AbstractSQLIndexing Integer parentPK, Type finalType, Boolean isFinalTypePrimitive - ) + ) throws SQLException { Integer index = 0; @@ -836,7 +837,7 @@ public abstract class AbstractSQLIndexing Object item, Boolean isFinalTypePrimitive, Type finalType - ) + ) throws SQLException { insertAllQNamesPS.setInt( 1, propertyPK ); @@ -869,7 +870,7 @@ public abstract class AbstractSQLIndexing QualifiedName qName, Object property, Integer parentQNameID - ) + ) throws SQLException { QNameInfo info = this._state.qNameInfos().get().get( qName ); @@ -896,7 +897,7 @@ public abstract class AbstractSQLIndexing QualifiedName qName, Object property, Integer parentQNameID - ) + ) throws SQLException { @@ -920,7 +921,7 @@ public abstract class AbstractSQLIndexing Integer localPK, Long entityPK, Object property - ) + ) throws SQLException { ValueDescriptor vDesc = this._qi4SPI.valueDescriptorFor( property ); @@ -930,15 +931,15 @@ public abstract class AbstractSQLIndexing try { - propertyPK[0] = this.insertProperty( + propertyPK[ 0 ] = this.insertProperty( qNameInsertPSs, insertAllQNamesPS, - propertyPK[0], + propertyPK[ 0 ], entityPK, pDesc.qualifiedName(), state.propertyFor( pDesc.accessor() ).get(), localPK - ); + ); } catch( SQLException e ) { @@ -947,13 +948,13 @@ public abstract class AbstractSQLIndexing } } ); - return propertyPK[0]; + return propertyPK[ 0 ]; } private void storePrimitiveUsingPS( PreparedStatement ps, Integer nextFreeIndex, Object primitive, Type primitiveType - ) + ) throws SQLException { if( primitiveType instanceof ParameterizedType ) @@ -968,7 +969,7 @@ public abstract class AbstractSQLIndexing nextFreeIndex, this._state.enumPKs().get().get( QualifiedName.fromClass( (Class) primitiveType, primitive.toString() ).toString() ) - ); + ); } else { @@ -999,7 +1000,7 @@ public abstract class AbstractSQLIndexing EntityState state, Long entityPK, Map qNamePKs - ) + ) throws SQLException { @@ -1024,7 +1025,7 @@ public abstract class AbstractSQLIndexing EntityState state, Long entityPK, Map qNamePKs - ) + ) throws SQLException { Integer nextQnamePK = this.insertPropertyQNames( connection, @@ -1047,9 +1048,9 @@ public abstract class AbstractSQLIndexing Integer typePK = this._state.entityTypePKs().get().get( clazz.getName() ); if( typePK == null ) { - throw new InternalError( "Tried to get entity : " + clazz - + ", but only aware of the following entities: " - + this._state.entityTypePKs().get().keySet() ); + throw new SqlIndexingException( "Tried to get entity : " + clazz + + ", but only aware of the following entities: " + + this._state.entityTypePKs().get().keySet() ); } try { @@ -1059,7 +1060,7 @@ public abstract class AbstractSQLIndexing } catch( SQLException e ) { - throw new EntityStoreException( "Underlying Exception when inserting " + entityPK, + throw new SqlIndexingException( "Underlying Exception when inserting " + entityPK, SQLUtil.withAllSQLExceptions( e ) ); } } );