Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2014-2015 the original author or authors.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
  * either express or implied. See the License for the specific language
  * governing permissions and limitations under the License.
  */
 package org.dbflute.dbway;
 
 import java.util.Map;
 
The definition of database.

Author(s):
jflute
 
 public enum DBDef {
 
     // ===================================================================================
     //                                                                                ENUM
     //                                                                                ====
     MySQL("mysql"nullnew WayOfMySQL()) // supported
     , PostgreSQL("postgresql""postgre"new WayOfPostgreSQL()) // supported
     , Oracle("oracle"nullnew WayOfOracle()) // supported
     , DB2("db2"nullnew WayOfDB2()) // supported
     , SQLServer("sqlserver""mssql"new WayOfSQLServer()) // supported
     , H2("h2"nullnew WayOfH2()) // supported
     , Derby("derby"nullnew WayOfDerby()) // supported
     , SQLite("sqlite"nullnew WayOfSQLite()) // sub supported
     , MSAccess("msaccess"nullnew WayOfMSAccess()) // sub supported
     , Firebird("firebird"nullnew WayOfFirebird()) // a-little-bit supported
     , Sybase("sybase"nullnew WayOfSybase()) // a-little-bit supported
     , Unknown("unknown"nullnew WayOfUnknown());
 
     // ===================================================================================
     //                                                                    Static Reference
     //                                                                    ================
     private static final Logger _log = LoggerFactory.getLogger(DBDef.class);
 
     // -----------------------------------------------------
     //                                            Code Value
     //                                            ----------
     private static final Map<StringDBDef_codeValueMap = new HashMap<StringDBDef>();
     static {
         for (DBDef value : values()) {
             .put(value.code().toLowerCase(), value);
         }
     }
     private static final Map<StringDBDef_codeAliasValueMap = new HashMap<StringDBDef>();
     static {
         for (DBDef value : values()) {
             if (value.codeAlias() != null) {
                 .put(value.codeAlias().toLowerCase(), value);
             }
         }
     }

    

Parameters:
code The code of the DB. (NullAllowed: If the code is null, it returns null)
Returns:
The instance that has the code. (NullAllowed)
 
     public static DBDef codeOf(String code) {
         if (code == null) {
             return null;
         }
         final String lowerCaseCode = code.toLowerCase();
         DBDef def = .get(lowerCaseCode);
         if (def == null) {
             def = .get(lowerCaseCode);
         }
         return def;
     }
 
     // ===================================================================================
     //                                                                           Attribute
     //                                                                           =========
     
The code of the DB. (NotNull)
 
     private final String _code;

    
The code alias of the DB. (NullAllowed)
 
     private final String _codeAlias;

    
The way of the DB. (NotNull)
 
     private DBWay _dbway;

    
Is this singleton world locked? e.g. you should unlock it to set your own DB-way.
 
     private boolean _locked = true// at first locked;
 
    // ===================================================================================
    //                                                                         Constructor
    //                                                                         ===========
    

Parameters:
code The code of the DB. (NotNull)
codeAlias The code alias of the DB. (NullAllowed)
codeAlias The DB-way of the DB. (NotNull)
    private DBDef(String codeString codeAliasDBWay dbway) {
         = code;
         = codeAlias;
         = dbway;
    }
    // ===================================================================================
    //                                                                      Basic Handling
    //                                                                      ==============
    

Returns:
The code of the DB. (NotNull)
    public String code() {
        return ;
    }

    

Returns:
The code alias of the DB. (NullAllowed)
    private String codeAlias() {
        return ;
    }

    

Returns:
The DB-way instance of the DB. (NotNull)
    public DBWay dbway() {
        return ;
    }
    // ===================================================================================
    //                                                                          Switch Way
    //                                                                          ==========
    
Switch from the old DB-way to the specified DB-way for the DB. (automatically locked after setting)
You should call this in application initialization if it needs.

Parameters:
dbway The new DB-way of the DB. (NotNull)
    public void switchDBWay(DBWay dbway) {
        if (dbway == null) {
            String msg = "The argument 'dbway' should not be null.";
            throw new IllegalArgumentException(msg);
        }
        assertUnlocked();
        final String oldName = .getClass().getSimpleName();
        if (.isInfoEnabled()) {
            .info("...Switching DB way from " + oldName + " to " + dbway);
        }
         = dbway;
        lock(); // auto-lock here, because of deep world
    }
    // ===================================================================================
    //                                                                     Definition Lock
    //                                                                     ===============
    
Lock this singleton world, e.g. not to set the DB-way.
    public void lock() {
        if () {
            return;
        }
        if (.isInfoEnabled()) {
            .info("...Locking the singleton world of the DB definition!");
        }
         = true;
    }

    
Unlock this singleton world, e.g. to set the DB-way.
    public void unlock() {
        if (!) {
            return;
        }
        if (.isInfoEnabled()) {
            .info("...Unlocking the singleton world of the DB definition!");
        }
         = false;
    }

    
Is this singleton world locked?

Returns:
The determination, true or false.
    public boolean isLocked() {
        return ;
    }

    
Assert this is not locked.
    protected void assertUnlocked() {
        if (!isLocked()) {
            return;
        }
        throw new IllegalStateException("The DB definition is locked.");
    }
New to GrepCode? Check out our FAQ X