Search in sources :

Example 1 with Datasource

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

the class GenericDelegator method initializeOneGenericHelper.

private void initializeOneGenericHelper(String groupName) {
    GenericHelperInfo helperInfo = this.getGroupHelperInfo(groupName);
    if (helperInfo == null) {
        if (Debug.infoOn()) {
            Debug.logInfo("Delegator \"" + delegatorFullName + "\" NOT initializing helper for entity group \"" + groupName + "\" because the group is not associated to this delegator.", module);
        }
        return;
    }
    String helperBaseName = helperInfo.getHelperBaseName();
    if (Debug.infoOn()) {
        Debug.logInfo("Delegator \"" + delegatorFullName + "\" initializing helper \"" + helperBaseName + "\" for entity group \"" + groupName + "\".", module);
    }
    if (UtilValidate.isNotEmpty(helperInfo.getHelperFullName())) {
        // pre-load field type defs, the return value is ignored
        ModelFieldTypeReader.getModelFieldTypeReader(helperBaseName);
        // get the helper and if configured, do the datasource check
        GenericHelper helper = GenericHelperFactory.getHelper(helperInfo);
        try {
            Datasource datasource = EntityConfig.getDatasource(helperBaseName);
            if (datasource.getCheckOnStart()) {
                if (Debug.infoOn()) {
                    Debug.logInfo("Doing database check as requested in entityengine.xml with addMissing=" + datasource.getAddMissingOnStart(), module);
                }
                helper.checkDataSource(this.getModelEntityMapByGroup(groupName), null, datasource.getAddMissingOnStart());
            }
        } catch (GenericEntityException e) {
            Debug.logWarning(e, e.getMessage(), module);
        }
    }
}
Also used : Datasource(org.apache.ofbiz.entity.config.model.Datasource) GenericHelperInfo(org.apache.ofbiz.entity.datasource.GenericHelperInfo) GenericHelper(org.apache.ofbiz.entity.datasource.GenericHelper)

Example 2 with Datasource

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

the class DumbTransactionFactory method getConnection.

public Connection getConnection(GenericHelperInfo helperInfo) throws SQLException, GenericEntityException {
    Datasource datasourceInfo = EntityConfig.getDatasource(helperInfo.getHelperBaseName());
    if (datasourceInfo.getInlineJdbc() != null) {
        Connection otherCon = ConnectionFactoryLoader.getInstance().getConnection(helperInfo, datasourceInfo.getInlineJdbc());
        return TransactionUtil.getCursorConnection(helperInfo, otherCon);
    }
    Debug.logError("Dumb/Empty 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) Connection(java.sql.Connection)

Example 3 with Datasource

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

the class JNDITransactionFactory method getConnection.

public Connection getConnection(GenericHelperInfo helperInfo) throws SQLException, GenericEntityException {
    Datasource datasourceInfo = EntityConfig.getDatasource(helperInfo.getHelperBaseName());
    if (datasourceInfo.getJndiJdbc() != null) {
        JndiJdbc jndiJdbcElement = datasourceInfo.getJndiJdbc();
        String jndiName = jndiJdbcElement.getJndiName();
        String jndiServerName = jndiJdbcElement.getJndiServerName();
        Connection con = getJndiConnection(jndiName, jndiServerName);
        if (con != null) {
            return TransactionUtil.getCursorConnection(helperInfo, con);
        }
    } else {
    }
    if (datasourceInfo.getInlineJdbc() != null) {
        Connection otherCon = ConnectionFactoryLoader.getInstance().getConnection(helperInfo, datasourceInfo.getInlineJdbc());
        return TransactionUtil.getCursorConnection(helperInfo, otherCon);
    }
    // no real need to print an error here
    return null;
}
Also used : Datasource(org.apache.ofbiz.entity.config.model.Datasource) JndiJdbc(org.apache.ofbiz.entity.config.model.JndiJdbc) Connection(java.sql.Connection) XAConnection(javax.sql.XAConnection)

Example 4 with Datasource

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

the class EntityTestSuite method testForeignKeyCreate.

/*
     * Tests foreign key integrity by trying to remove an entity which has foreign-key dependencies.  Should cause an exception.
     */
public void testForeignKeyCreate() {
    try {
        String helperName = delegator.getEntityHelper("Testing").getHelperName();
        Datasource datasourceInfo = EntityConfig.getDatasource(helperName);
        if (!datasourceInfo.getUseForeignKeys()) {
            Debug.logInfo("Datasource " + datasourceInfo.getName() + " use-foreign-keys set to false, skipping testForeignKeyCreate", module);
            return;
        }
    } catch (GenericEntityException e) {
        Debug.logError(e, module);
    }
    GenericEntityException caught = null;
    try {
        delegator.create("Testing", "testingId", delegator.getNextSeqId("Testing"), "testingTypeId", "NO-SUCH-KEY");
    } catch (GenericEntityException e) {
        caught = e;
    }
    assertNotNull("Foreign key referential integrity is not observed for create (INSERT)", caught);
    Debug.logInfo(caught.toString(), module);
}
Also used : Datasource(org.apache.ofbiz.entity.config.model.Datasource) GenericEntityException(org.apache.ofbiz.entity.GenericEntityException)

Example 5 with Datasource

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

the class EntityTestSuite method testForeignKeyRemove.

/*
     * Tests foreign key integrity by trying to remove an entity which has foreign-key dependencies.  Should cause an exception.
     */
public void testForeignKeyRemove() throws Exception {
    try {
        String helperName = delegator.getEntityHelper("TestingNode").getHelperName();
        Datasource datasourceInfo = EntityConfig.getDatasource(helperName);
        if (!datasourceInfo.getUseForeignKeys()) {
            Debug.logInfo("Datasource " + datasourceInfo.getName() + " use-foreign-keys set to false, skipping testForeignKeyRemove", module);
            return;
        }
    } catch (GenericEntityException e) {
        Debug.logError(e, module);
    }
    delegator.removeByCondition("TestingNode", EntityCondition.makeCondition("description", EntityOperator.LIKE, "foreign-key-remove #%"));
    delegator.create("TestingNode", "testingNodeId", "TEST-FK-REMOVE-0", "description", "foreign-key-remove #0");
    delegator.create("TestingNode", "testingNodeId", "TEST-FK-REMOVE-1", "primaryParentNodeId", "TEST-FK-REMOVE-0", "description", "foreign-key-remove #1");
    delegator.create("TestingNode", "testingNodeId", "TEST-FK-REMOVE-2", "primaryParentNodeId", "TEST-FK-REMOVE-1", "description", "foreign-key-remove #2");
    delegator.create("TestingNode", "testingNodeId", "TEST-FK-REMOVE-3", "primaryParentNodeId", "TEST-FK-REMOVE-2", "description", "foreign-key-remove #3");
    GenericEntityException caught = null;
    try {
        EntityCondition isLevel1 = EntityCondition.makeCondition("description", EntityOperator.EQUALS, "foreign-key-remove #1");
        delegator.removeByCondition("TestingNode", isLevel1);
    } catch (GenericEntityException e) {
        caught = e;
    }
    assertNotNull("Foreign key referential integrity is not observed for remove (DELETE)", caught);
    Debug.logInfo(caught.toString(), module);
}
Also used : Datasource(org.apache.ofbiz.entity.config.model.Datasource) GenericEntityException(org.apache.ofbiz.entity.GenericEntityException) EntityCondition(org.apache.ofbiz.entity.condition.EntityCondition)

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