Search in sources :

Example 1 with DBServiceProvider

use of net.heartsome.cat.database.DBServiceProvider in project translationstudio8 by heartsome.

the class DatabaseService method getSysDbOperateByMetaData.

/**
	 * 通过数据库元数据库获取数据库连接,主要取数据库类型
	 * @param metaData
	 * @return ;
	 */
public static SystemDBOperator getSysDbOperateByMetaData(MetaData metaData) {
    @SuppressWarnings({ "rawtypes", "unchecked" }) ServiceTracker tracker = new ServiceTracker(Activator.context, DBServiceProvider.class.getName(), null);
    tracker.open();
    try {
        Object[] services = tracker.getServices();
        for (Object i : services) {
            DBServiceProvider serviceProvider = (DBServiceProvider) i;
            SystemDBOperator temp = serviceProvider.getOperateDBInstance();
            if (temp == null) {
                continue;
            }
            MetaData tempMetaData = temp.getMetaData();
            if (tempMetaData.getDbType().equals(metaData.getDbType())) {
                tempMetaData.setDatabaseName(metaData.getDatabaseName());
                tempMetaData.setDataPath(metaData.getDataPath());
                tempMetaData.setInstance(metaData.getInstance());
                tempMetaData.setPassword(metaData.getPassword());
                tempMetaData.setPort(metaData.getPort());
                tempMetaData.setServerName(metaData.getServerName());
                tempMetaData.setTB(metaData.isTB());
                tempMetaData.setTM(metaData.isTM());
                tempMetaData.setUserName(metaData.getUserName());
                return temp;
            }
        }
    } finally {
        tracker.close();
    }
    return null;
}
Also used : DBServiceProvider(net.heartsome.cat.database.DBServiceProvider) SystemDBOperator(net.heartsome.cat.database.SystemDBOperator) ServiceTracker(org.osgi.util.tracker.ServiceTracker) MetaData(net.heartsome.cat.common.bean.MetaData)

Example 2 with DBServiceProvider

use of net.heartsome.cat.database.DBServiceProvider in project translationstudio8 by heartsome.

the class DatabaseService method getDBOperator.

/**
	 * 获取数据处理对象{@link DBOperator},该数据处理对象用于访问指定的数据库中的数据<br>
	 * 在访问数据库时,根据不同数据库类型获取相应的处理对象.这些数据库被封装在{@link MetaData}中
	 * @param metaData
	 *            当前数据库的元数据,封装了连接数据库的一系列参数
	 * @return 返回null时,表示未获取到数据处理对象;
	 */
public static DBOperator getDBOperator(MetaData metaData) {
    DBOperator dbOperator = null;
    @SuppressWarnings({ "rawtypes", "unchecked" }) ServiceTracker tracker = new ServiceTracker(Activator.context, DBServiceProvider.class.getName(), null);
    tracker.open();
    try {
        Object[] services = tracker.getServices();
        for (Object i : services) {
            DBServiceProvider serviceProvider = (DBServiceProvider) i;
            DBOperator temp = serviceProvider.getTmDatabaseInstance();
            if (temp == null) {
                continue;
            }
            if (temp.getDbConfig().getDefaultType().equals(metaData.getDbType())) {
                dbOperator = temp;
                dbOperator.setMetaData(metaData);
            }
        }
    } finally {
        tracker.close();
    }
    return dbOperator;
}
Also used : DBServiceProvider(net.heartsome.cat.database.DBServiceProvider) ServiceTracker(org.osgi.util.tracker.ServiceTracker) SystemDBOperator(net.heartsome.cat.database.SystemDBOperator) DBOperator(net.heartsome.cat.database.DBOperator)

Example 3 with DBServiceProvider

use of net.heartsome.cat.database.DBServiceProvider in project translationstudio8 by heartsome.

the class DatabaseService method getSystemDbOperaterList.

/**
	 * 根据当前系统支持的数据库类型,获取所有的库处理对象,<br>
	 * 该库处理对象是对服务器中的数据库进行管理,包括创建,删除等一系列操作.参见{@link SystemDBOperator} *
	 * @return 返回当前系统所支持的库处理对象集;
	 */
@SuppressWarnings({ "rawtypes", "unchecked" })
public static List<SystemDBOperator> getSystemDbOperaterList() {
    List<SystemDBOperator> list = new ArrayList<SystemDBOperator>();
    ServiceTracker operateDbTracker = new ServiceTracker(Activator.context, DBServiceProvider.class.getName(), null);
    operateDbTracker.open();
    try {
        Object[] services = operateDbTracker.getServices();
        for (Object i : services) {
            DBServiceProvider temp = (DBServiceProvider) i;
            list.add(temp.getOperateDBInstance());
        }
    } finally {
        operateDbTracker.close();
    }
    if (list.size() == 0) {
        return list;
    }
    int size = list.size();
    SystemDBOperator[] temp = new SystemDBOperator[size];
    for (SystemDBOperator op : list) {
        if (op.getDBConfig().getDefaultType().equals(Constants.DBTYPE_INTERNALDB)) {
            temp[size - 1] = op;
        }
        if (op.getDBConfig().getDefaultType().equals(Constants.DBTYPE_MYSQL)) {
            temp[size - 5] = op;
        }
        if (op.getDBConfig().getDefaultType().equals(Constants.DBTYPE_MSSQL2005)) {
            temp[size - 4] = op;
        }
        if (op.getDBConfig().getDefaultType().equals(Constants.DBTYPE_POSTGRESQL)) {
            temp[size - 2] = op;
        }
        if (op.getDBConfig().getDefaultType().equals(Constants.DBTYPE_Oracle)) {
            temp[size - 3] = op;
        }
        if (op.getDBConfig().getDefaultType().equals(Constants.DBTYPE_SQLITE)) {
            temp[0] = op;
        }
    }
    return Arrays.asList(temp);
}
Also used : SystemDBOperator(net.heartsome.cat.database.SystemDBOperator) DBServiceProvider(net.heartsome.cat.database.DBServiceProvider) ServiceTracker(org.osgi.util.tracker.ServiceTracker) ArrayList(java.util.ArrayList)

Aggregations

DBServiceProvider (net.heartsome.cat.database.DBServiceProvider)3 SystemDBOperator (net.heartsome.cat.database.SystemDBOperator)3 ServiceTracker (org.osgi.util.tracker.ServiceTracker)3 ArrayList (java.util.ArrayList)1 MetaData (net.heartsome.cat.common.bean.MetaData)1 DBOperator (net.heartsome.cat.database.DBOperator)1