Search in sources :

Example 6 with Datasource

use of org.apache.ofbiz.entity.config.model.Datasource in project ofbiz-framework by apache.

the class ModelFieldTypeReader method getModelFieldTypeReader.

public static ModelFieldTypeReader getModelFieldTypeReader(String helperName) {
    Datasource datasourceInfo = EntityConfig.getDatasource(helperName);
    if (datasourceInfo == null) {
        throw new IllegalArgumentException("Could not find a datasource/helper with the name " + helperName);
    }
    String tempModelName = datasourceInfo.getFieldTypeName();
    ModelFieldTypeReader reader = readers.get(tempModelName);
    while (reader == null) {
        FieldType fieldTypeInfo = null;
        try {
            fieldTypeInfo = EntityConfig.getInstance().getFieldType(tempModelName);
        } catch (GenericEntityConfException e) {
            Debug.logWarning(e, "Exception thrown while getting field type config: ", module);
        }
        if (fieldTypeInfo == null) {
            throw new IllegalArgumentException("Could not find a field-type definition with name \"" + tempModelName + "\"");
        }
        ResourceHandler fieldTypeResourceHandler = new MainResourceHandler(EntityConfig.ENTITY_ENGINE_XML_FILENAME, fieldTypeInfo.getLoader(), fieldTypeInfo.getLocation());
        UtilTimer utilTimer = new UtilTimer();
        utilTimer.timerString("[ModelFieldTypeReader.getModelFieldTypeReader] Reading field types from " + fieldTypeResourceHandler.getLocation());
        Document document = null;
        try {
            document = fieldTypeResourceHandler.getDocument();
        } catch (GenericConfigException e) {
            Debug.logError(e, module);
            throw new IllegalStateException("Error loading field type file " + fieldTypeResourceHandler.getLocation());
        }
        Map<String, ModelFieldType> fieldTypeMap = createFieldTypeCache(document.getDocumentElement(), fieldTypeResourceHandler.getLocation());
        reader = readers.putIfAbsentAndGet(tempModelName, new ModelFieldTypeReader(fieldTypeMap));
        utilTimer.timerString("[ModelFieldTypeReader.getModelFieldTypeReader] Read " + fieldTypeMap.size() + " field types");
    }
    return reader;
}
Also used : Datasource(org.apache.ofbiz.entity.config.model.Datasource) GenericEntityConfException(org.apache.ofbiz.entity.GenericEntityConfException) UtilTimer(org.apache.ofbiz.base.util.UtilTimer) ResourceHandler(org.apache.ofbiz.base.config.ResourceHandler) MainResourceHandler(org.apache.ofbiz.base.config.MainResourceHandler) Document(org.w3c.dom.Document) FieldType(org.apache.ofbiz.entity.config.model.FieldType) GenericConfigException(org.apache.ofbiz.base.config.GenericConfigException) MainResourceHandler(org.apache.ofbiz.base.config.MainResourceHandler)

Example 7 with Datasource

use of org.apache.ofbiz.entity.config.model.Datasource in project ofbiz-framework by apache.

the class EntityDataLoader method getUrlByComponentList.

public static List<URL> getUrlByComponentList(String helperName, List<String> components) {
    Datasource datasourceInfo = EntityConfig.getDatasource(helperName);
    List<String> readerNames = new LinkedList<String>();
    for (ReadData readerInfo : datasourceInfo.getReadDataList()) {
        String readerName = readerInfo.getReaderName();
        // ignore the "tenant" reader if the multitenant property is "N"
        if ("tenant".equals(readerName) && "N".equals(UtilProperties.getPropertyValue("general", "multitenant"))) {
            continue;
        }
        readerNames.add(readerName);
    }
    return getUrlByComponentList(helperName, components, readerNames);
}
Also used : Datasource(org.apache.ofbiz.entity.config.model.Datasource) ReadData(org.apache.ofbiz.entity.config.model.ReadData) LinkedList(java.util.LinkedList)

Example 8 with Datasource

use of org.apache.ofbiz.entity.config.model.Datasource in project ofbiz-framework by apache.

the class EntityDataLoader method getPathsString.

public static String getPathsString(String helperName) {
    StringBuilder pathBuffer = new StringBuilder();
    if (UtilValidate.isNotEmpty(helperName)) {
        Datasource datasourceInfo = EntityConfig.getDatasource(helperName);
        for (SqlLoadPath sqlLoadPath : datasourceInfo.getSqlLoadPathList()) {
            String prependEnv = sqlLoadPath.getPrependEnv();
            pathBuffer.append(pathBuffer.length() == 0 ? "" : ";");
            if (UtilValidate.isNotEmpty(prependEnv)) {
                pathBuffer.append(System.getProperty(prependEnv));
                pathBuffer.append("/");
            }
            pathBuffer.append(sqlLoadPath.getPath());
        }
    }
    return pathBuffer.toString();
}
Also used : Datasource(org.apache.ofbiz.entity.config.model.Datasource) SqlLoadPath(org.apache.ofbiz.entity.config.model.SqlLoadPath)

Example 9 with Datasource

use of org.apache.ofbiz.entity.config.model.Datasource in project ofbiz-framework by apache.

the class GeronimoTransactionFactory method getConnection.

public Connection getConnection(GenericHelperInfo helperInfo) throws SQLException, GenericEntityException {
    Datasource datasourceInfo = EntityConfig.getDatasource(helperInfo.getHelperBaseName());
    if (datasourceInfo != null && datasourceInfo.getInlineJdbc() != null) {
        return ConnectionFactoryLoader.getInstance().getConnection(helperInfo, datasourceInfo.getInlineJdbc());
    }
    Debug.logError("Geronimo is the configured transaction manager but no inline-jdbc element was specified in the " + helperInfo.getHelperBaseName() + " datasource. Please check your configuration", module);
    return null;
}
Also used : Datasource(org.apache.ofbiz.entity.config.model.Datasource)

Example 10 with Datasource

use of org.apache.ofbiz.entity.config.model.Datasource in project ofbiz-framework by apache.

the class SQLProcessor method setBinaryStream.

/**
 * Set the next binding variable of the currently active prepared statement
 * to write the serialized data of 'field' to a BLOB.
 *
 * @param field
 *
 * @throws SQLException
 */
public void setBinaryStream(Object field) throws SQLException {
    if (field != null) {
        try {
            ByteArrayOutputStream os = new ByteArrayOutputStream();
            ObjectOutputStream oos = new ObjectOutputStream(os);
            oos.writeObject(field);
            oos.close();
            byte[] buf = os.toByteArray();
            os.close();
            ByteArrayInputStream is = new ByteArrayInputStream(buf);
            _ps.setBinaryStream(_ind, is, buf.length);
            is.close();
        } catch (IOException ex) {
            throw new SQLException(ex.getMessage());
        }
    } else {
        Datasource datasourceInfo = EntityConfig.getDatasource(this.helperInfo.getHelperBaseName());
        if (datasourceInfo.getUseBinaryTypeForBlob()) {
            _ps.setNull(_ind, Types.BINARY);
        } else {
            _ps.setNull(_ind, Types.BLOB);
        }
    }
    _ind++;
}
Also used : Datasource(org.apache.ofbiz.entity.config.model.Datasource) ByteArrayInputStream(java.io.ByteArrayInputStream) SQLException(java.sql.SQLException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) ObjectOutputStream(java.io.ObjectOutputStream)

Aggregations

Datasource (org.apache.ofbiz.entity.config.model.Datasource)11 Connection (java.sql.Connection)2 GenericEntityException (org.apache.ofbiz.entity.GenericEntityException)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 ObjectOutputStream (java.io.ObjectOutputStream)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 SQLException (java.sql.SQLException)1 LinkedList (java.util.LinkedList)1 XAConnection (javax.sql.XAConnection)1 GenericConfigException (org.apache.ofbiz.base.config.GenericConfigException)1 MainResourceHandler (org.apache.ofbiz.base.config.MainResourceHandler)1 ResourceHandler (org.apache.ofbiz.base.config.ResourceHandler)1 UtilTimer (org.apache.ofbiz.base.util.UtilTimer)1 GenericEntityConfException (org.apache.ofbiz.entity.GenericEntityConfException)1 EntityCondition (org.apache.ofbiz.entity.condition.EntityCondition)1 FieldType (org.apache.ofbiz.entity.config.model.FieldType)1 JndiJdbc (org.apache.ofbiz.entity.config.model.JndiJdbc)1 ReadData (org.apache.ofbiz.entity.config.model.ReadData)1