Revision 41638 trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.jdbc/src/main/java/org/gvsig/fmap/dal/store/jdbc/JDBCServerExplorer.java

View differences:

JDBCServerExplorer.java
31 31
import java.util.ArrayList;
32 32
import java.util.Iterator;
33 33
import java.util.List;
34
import org.apache.commons.lang3.StringUtils;
34 35

  
35 36
import org.slf4j.Logger;
36 37
import org.slf4j.LoggerFactory;
......
51 52
import org.gvsig.fmap.dal.feature.EditableFeatureType;
52 53
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
53 54
import org.gvsig.fmap.dal.feature.FeatureType;
54
import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters;
55 55
import org.gvsig.fmap.dal.resource.spi.ResourceProvider;
56 56
import org.gvsig.fmap.dal.serverexplorer.db.spi.AbstractDBServerExplorer;
57 57
import org.gvsig.fmap.dal.spi.DataManagerProviderServices;
......
438 438
		return edType;
439 439

  
440 440
	}
441
        
442
        protected List createGrantStatements(String tableName, String privilege, String theRoles) {
443
            List statements = new ArrayList();
444
            String[] roles = StringUtils.split(theRoles,",");
445
            for( int i=0; i<roles.length; i++) {
446
                String statement = "GRANT "+ privilege + "ON TABLE " + tableName + " TO " + roles[i];
447
                statements.add(statement);
448
            }
449
            return statements;
450
        } 
451
        
452
        protected List getPermissionsSQLs(JDBCNewStoreParameters ndsp) {
453
            List statements = null;
454
            String roles;
455
            
456
            roles = ndsp.getSelectRole();
457
            if( roles!=null ) {
458
                if( statements == null ) {
459
                    statements = new ArrayList();
460
                }
461
                statements.addAll(this.createGrantStatements(ndsp.tableID(), "SELECT", roles));
462
            }
463
            roles = ndsp.getInsertRole();
464
            if( roles!=null ) {
465
                if( statements == null ) {
466
                    statements = new ArrayList();
467
                }
468
                statements.addAll(this.createGrantStatements(ndsp.tableID(), "INSERT", roles));
469
            }
470
            roles = ndsp.getUpdateRole();
471
            if( roles!=null ) {
472
                if( statements == null ) {
473
                    statements = new ArrayList();
474
                }
475
                statements.addAll(this.createGrantStatements(ndsp.tableID(), "UPDATE", roles));
476
            }
477
            roles = ndsp.getDeleteRole();
478
            if( roles!=null ) {
479
                if( statements == null ) {
480
                    statements = new ArrayList();
481
                }
482
                statements.addAll(this.createGrantStatements(ndsp.tableID(), "DELETE", roles));
483
            }
484
            roles = ndsp.getTruncateRole();
485
            if( roles!=null ) {
486
                if( statements == null ) {
487
                    statements = new ArrayList();
488
                }
489
                statements.addAll(this.createGrantStatements(ndsp.tableID(), "TRUNCATE", roles));
490
            }
491
            roles = ndsp.getReferenceRole();
492
            if( roles!=null ) {
493
                if( statements == null ) {
494
                    statements = new ArrayList();
495
                }
496
                statements.addAll(this.createGrantStatements(ndsp.tableID(), "REFERENCE", roles));
497
            }
498
            roles = ndsp.getTriggerRole();
499
            if( roles!=null ) {
500
                if( statements == null ) {
501
                    statements = new ArrayList();
502
                }
503
                statements.addAll(this.createGrantStatements(ndsp.tableID(), "TRIGGER", roles));
504
            }
505
            roles = ndsp.getAllRole();
506
            if( roles!=null ) {
507
                if( statements == null ) {
508
                    statements = new ArrayList();
509
                }
510
                statements.addAll(this.createGrantStatements(ndsp.tableID(), "ALL", roles));
511
            }
512
            
513
            return statements;
514
        }
441 515

  
442

  
443 516
	public boolean add(String providerName, NewDataStoreParameters ndsp, boolean overwrite)
444 517
			throws DataException {
445 518

  
......
512 585
		sql.append(")");
513 586

  
514 587
		final String sqlCreate = sql.toString();
515
		final List sqlAdditional = helper
516
				.getAdditionalSqlToCreate(ndsp, fType);
588
		final List sqlAdditional = helper.getAdditionalSqlToCreate(ndsp, fType);
517 589

  
590
                List permissions = getPermissionsSQLs((JDBCNewStoreParameters) ndsp);
591
                if( permissions != null ) {
592
                    sqlAdditional.addAll(permissions);
593
                }
594
                
595
                if( ((JDBCNewStoreParameters) ndsp).getPostCreatingStatement()!=null ) {
596
                    sqlAdditional.add(((JDBCNewStoreParameters) ndsp).getPostCreatingStatement());
597
                }
598
                
518 599
		TransactionalAction action = new TransactionalAction() {
519 600

  
520 601
			public boolean continueTransactionAllowed() {
......
578 659
		x.add(JDBCStoreProvider.NAME);
579 660
		return x;
580 661
	}
662
        
663
        public void updateTableStatistics(String tableName) {
664
            
665
        }
581 666

  
582 667
}

Also available in: Unified diff