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);
}
}
}
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;
}
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;
}
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);
}
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);
}
Aggregations