Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 /*
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  *
  * Copyright (c) 2013-2014 sagyf Yang. The Four Group.
  */
 package com.github.sog.plugin.tablebind;
 
public class AutoTableBindPlugin extends ActiveRecordPlugin {
    protected final Logger log = LoggerFactory.getLogger(getClass());
    private final INameStyle nameStyle;
    private boolean autoScan = true;
    public AutoTableBindPlugin(DataSource dataSource) {
        this(dataSource.);
    }
    public AutoTableBindPlugin(DataSource dataSourceINameStyle nameStyle) {
        super(dataSource);
        this. = nameStyle;
    }
    public AutoTableBindPlugin(IDataSourceProvider dataSourceProvider) {
        this(dataSourceProvider.);
    }
    public AutoTableBindPlugin(IDataSourceProvider dataSourceProviderINameStyle nameStyle) {
        super(dataSourceProvider);
        this. = nameStyle;
    }
    @SuppressWarnings({"unchecked""rawtypes"})
    @Override
    public boolean start() {
        List<ClassmodelClasses = ClassBox.getInstance().getClasses(.);
        if (modelClasses != null && !modelClasses.isEmpty()) {
            TableBind tb;
            for (Class modelClass : modelClasses) {
                tb = (TableBindmodelClass.getAnnotation(TableBind.class);
                String tableName;
                if (tb == null) {
                    if (!) {
                        continue;
                    }
                    tableName = .name(modelClass.getSimpleName());
                    this.addMapping(tableNamemodelClass);
                    .debug("addMapping(" + tableName + ", " + modelClass.getName() + .);
                } else {
                    tableName = tb.tableName();
                    if (StringKit.notBlank(tb.pkName())) {
                        this.addMapping(tableNametb.pkName(), modelClass);
                        .debug("addMapping(" + tableName + ", " + tb.pkName() + . + modelClass.getName() + .);
                    } else {
                        this.addMapping(tableNamemodelClass);
                        .debug("addMapping(" + tableName + ", " + modelClass.getName() + .);
                    }
                }
            }
        }
        return super.start();
    }
    @Override
    public boolean stop() {
        return super.stop();
    }
    public AutoTableBindPlugin autoScan(boolean autoScan) {
        this. = autoScan;
        return this;
    }
New to GrepCode? Check out our FAQ X