polygene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From paulmer...@apache.org
Subject [26/50] [abbrv] polygene-java git commit: Get rid of warnings, and some reformatting of a messy class.
Date Mon, 17 Jul 2017 12:46:18 GMT
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/af87b22b
Tree: http://git-wip-us.apache.org/repos/asf/polygene-java/tree/af87b22b
Diff: http://git-wip-us.apache.org/repos/asf/polygene-java/diff/af87b22b

Branch: refs/heads/master
Commit: af87b22b7ed1aadc3d0c9774a4197af719e02ac0
Parents: 53fe704
Author: niclas <niclas@hedhman.org>
Authored: Sun Jul 9 12:36:19 2017 +0800
Committer: Paul Merlin <paulmerlin@apache.org>
Committed: Thu Jul 13 17:13:07 2017 +0200

----------------------------------------------------------------------
 .../support/skeletons/AbstractSQLIndexing.java  | 281 ++++++++++---------
 1 file changed, 141 insertions(+), 140 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/polygene-java/blob/af87b22b/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<PreparedStatement, SQLException> queryPKPS
-    )
+    @SuppressWarnings( "WeakerAccess" )
+    protected Long findEntityPK( EntityState state, Lazy<PreparedStatement, SQLException>
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<QualifiedName, PreparedStatement> qNameInsertPSs,
                                       Set<QualifiedName> qNames
-    )
+                                    )
         throws SQLException
     {
         Set<QualifiedName> 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<QualifiedName, PreparedStatement> qNameInsertPSs,
                                           PreparedStatement insertAllQNamesPS, EntityState
state, Long entityPK
-    )
+                                        )
         throws SQLException
     {
         Set<QualifiedName> 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<QualifiedName, PreparedStatement>
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<Long, Integer> qNamePKs
-    )
+                                              )
         throws SQLException
     {
 
@@ -1024,7 +1025,7 @@ public abstract class AbstractSQLIndexing
                                    EntityState state,
                                    Long entityPK,
                                    Map<Long, Integer> 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 ) );
             }
         } );


Mime
View raw message