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