use of org.datanucleus.store.StoreManager in project datanucleus-core by datanucleus.
the class FederatedPersistenceHandler method fetchObject.
/* (non-Javadoc)
* @see org.datanucleus.store.StorePersistenceHandler#fetchObject(org.datanucleus.store.ObjectProvider, int[])
*/
public void fetchObject(ObjectProvider op, int[] fieldNumbers) {
StoreManager classStoreMgr = storeMgr.getStoreManagerForClass(op.getClassMetaData());
classStoreMgr.getPersistenceHandler().fetchObject(op, fieldNumbers);
}
use of org.datanucleus.store.StoreManager in project datanucleus-api-jdo by datanucleus.
the class JDOPersistenceManagerFactory method supportedOptions.
/**
* The application can determine from the results of this method which optional features, and which query languages are supported by the JDO implementation.
* See section 11.6 of the JDO specification.
* @return A Collection of String representing the supported options.
*/
public Collection<String> supportedOptions() {
// Generate the list of supported options, taking the general options we support and removing
// any that the particular StoreManager doesn't support
Set<String> options = new HashSet<>(Arrays.asList(OPTION_ARRAY));
StoreManager storeMgr = nucleusContext.getStoreManager();
if (storeMgr != null) {
Collection<String> storeMgrOptions = storeMgr.getSupportedOptions();
if (!storeMgrOptions.contains(StoreManager.OPTION_NONDURABLE_ID)) {
options.remove("javax.jdo.option.NonDurableIdentity");
}
if (!storeMgrOptions.contains(StoreManager.OPTION_DATASTORE_ID)) {
options.remove("javax.jdo.option.DatastoreIdentity");
}
if (!storeMgrOptions.contains(StoreManager.OPTION_APPLICATION_ID)) {
options.remove("javax.jdo.option.ApplicationIdentity");
}
if (!storeMgr.supportsQueryLanguage(Query.LANGUAGE_JDOQL)) {
options.remove("javax.jdo.query.JDOQL");
}
if (!storeMgr.supportsQueryLanguage(Query.LANGUAGE_SQL)) {
options.remove("javax.jdo.query.SQL");
}
if (storeMgrOptions.contains(StoreManager.OPTION_TXN_ISOLATION_READ_COMMITTED)) {
options.add("javax.jdo.option.TransactionIsolationLevel.read-committed");
}
if (storeMgrOptions.contains(StoreManager.OPTION_TXN_ISOLATION_READ_UNCOMMITTED)) {
options.add("javax.jdo.option.TransactionIsolationLevel.read-uncommitted");
}
if (storeMgrOptions.contains(StoreManager.OPTION_TXN_ISOLATION_REPEATABLE_READ)) {
options.add("javax.jdo.option.TransactionIsolationLevel.repeatable-read");
}
if (storeMgrOptions.contains(StoreManager.OPTION_TXN_ISOLATION_SERIALIZABLE)) {
options.add("javax.jdo.option.TransactionIsolationLevel.serializable");
}
if (storeMgrOptions.contains("TransactionIsolationLevel.snapshot")) {
options.add("javax.jdo.option.TransactionIsolationLevel.snapshot");
}
if (storeMgrOptions.contains(StoreManager.OPTION_QUERY_CANCEL)) {
options.add("javax.jdo.option.QueryCancel");
}
if (storeMgrOptions.contains(StoreManager.OPTION_DATASTORE_TIMEOUT)) {
options.add("javax.jdo.option.DatastoreTimeout");
}
if (storeMgrOptions.contains(StoreManager.OPTION_QUERY_JDOQL_BITWISE_OPS)) {
options.add("javax.jdo.query.JDOQL.BitwiseOperations");
}
}
return Collections.unmodifiableSet(options);
}
use of org.datanucleus.store.StoreManager in project tests by datanucleus.
the class DynamicEnhanceSchemaToolTest method schemaCreate.
public void schemaCreate(DynamicEnhanceSchemaToolClassLoader runtimeCL) throws Exception {
Map props = getPropertiesForDatastore(runtimeCL);
JDOPersistenceManagerFactory pmf = (JDOPersistenceManagerFactory) JDOHelper.getPersistenceManagerFactory(props);
try {
JDOMetadata filemd = pmf.newMetadata();
createMetadata(filemd);
pmf.registerMetadata(filemd);
Set<String> classNames = new HashSet<>();
classNames.add("test.Client");
PersistenceNucleusContext nucCtx = pmf.getNucleusContext();
StoreManager storeMgr = nucCtx.getStoreManager();
if (!(storeMgr instanceof SchemaAwareStoreManager)) {
// Can't create schema with this datastore
return;
}
try {
SchemaTool schematool = new SchemaTool();
schematool.setDdlFile("target/schema.ddl");
schematool.setCompleteDdl(true);
SchemaAwareStoreManager schemaStoreMgr = (SchemaAwareStoreManager) nucCtx.getStoreManager();
schematool.createSchemaForClasses(schemaStoreMgr, classNames);
} catch (Exception e) {
e.printStackTrace();
}
} finally {
pmf.close();
}
}
use of org.datanucleus.store.StoreManager in project datanucleus-core by datanucleus.
the class PersistenceNucleusContextImpl method initialiseSchema.
/**
* Method to handle generation (create, drop, drop+create) of a schema at initialisation.
* Will generate the schema for all classes that have had their metadata loaded at this point, which
* typically means the persistence-unit.
* @param generateModeStr Generate "mode"
* @param generateScripts Whether to generate
*/
protected void initialiseSchema(String generateModeStr, boolean generateScripts) {
Mode mode = null;
if (generateModeStr.equalsIgnoreCase("create")) {
mode = Mode.CREATE;
} else if (generateModeStr.equalsIgnoreCase("drop")) {
mode = Mode.DELETE;
} else if (generateModeStr.equalsIgnoreCase("drop-and-create")) {
mode = Mode.DELETE_CREATE;
}
if (NucleusLogger.DATASTORE_SCHEMA.isDebugEnabled()) {
if (mode == Mode.CREATE) {
NucleusLogger.DATASTORE_SCHEMA.debug(Localiser.msg("014000"));
} else if (mode == Mode.DELETE) {
NucleusLogger.DATASTORE_SCHEMA.debug(Localiser.msg("014001"));
} else if (mode == Mode.DELETE_CREATE) {
NucleusLogger.DATASTORE_SCHEMA.debug(Localiser.msg("014045"));
}
}
// Extract the classes that have metadata loaded (e.g persistence-unit)
Set<String> schemaClassNames = null;
MetaDataManager metaDataMgr = getMetaDataManager();
FileMetaData[] filemds = metaDataMgr.getFileMetaData();
schemaClassNames = new TreeSet<String>();
if (filemds == null) {
throw new NucleusUserException("No classes to process in generateSchema");
}
for (int i = 0; i < filemds.length; i++) {
for (int j = 0; j < filemds[i].getNoOfPackages(); j++) {
for (int k = 0; k < filemds[i].getPackage(j).getNoOfClasses(); k++) {
String className = filemds[i].getPackage(j).getClass(k).getFullClassName();
if (!schemaClassNames.contains(className)) {
schemaClassNames.add(className);
}
}
}
}
StoreManager storeMgr = getStoreManager();
if (storeMgr instanceof SchemaAwareStoreManager) {
SchemaAwareStoreManager schemaStoreMgr = (SchemaAwareStoreManager) storeMgr;
SchemaTool schemaTool = new SchemaTool();
if (mode == Mode.CREATE) {
if (generateScripts) {
// Generate the required script
schemaTool.setDdlFile(config.getStringProperty(PropertyNames.PROPERTY_SCHEMA_GENERATE_SCRIPTS_CREATE_TARGET));
schemaTool.createSchemaForClasses(schemaStoreMgr, schemaClassNames);
} else {
// Process the required metadata/script
String createOrder = config.getStringProperty(PropertyNames.PROPERTY_SCHEMA_GENERATE_CREATE_ORDER);
String createScript = config.getStringProperty(PropertyNames.PROPERTY_SCHEMA_GENERATE_SCRIPTS_CREATE_SOURCE);
if (StringUtils.isWhitespace(createScript)) {
createScript = null;
}
if (StringUtils.isWhitespace(createOrder)) {
createOrder = (createScript != null) ? "script" : "metadata";
} else {
if (createOrder.equals("script") || createOrder.equals("metadata-then-script") || createOrder.equals("script-the-metadata")) {
if (createScript == null) {
NucleusLogger.DATASTORE_SCHEMA.warn("create order set to " + createOrder + " but no script defined, so using metadata instead");
createOrder = "metadata";
}
}
}
if (createOrder.equals("script")) {
processDatastoreScript(createScript);
} else if (createOrder.equals("script-then-metadata")) {
processDatastoreScript(createScript);
schemaTool.createSchemaForClasses(schemaStoreMgr, schemaClassNames);
} else if (createOrder.equals("metadata-then-script")) {
schemaTool.createSchemaForClasses(schemaStoreMgr, schemaClassNames);
processDatastoreScript(createScript);
} else {
schemaTool.createSchemaForClasses(schemaStoreMgr, schemaClassNames);
}
}
} else if (mode == Mode.DELETE) {
if (generateScripts) {
// Generate the required script
schemaTool.setDdlFile(config.getStringProperty(PropertyNames.PROPERTY_SCHEMA_GENERATE_SCRIPTS_DROP_TARGET));
schemaTool.deleteSchemaForClasses(schemaStoreMgr, schemaClassNames);
} else {
// Process the required metadata/script
String dropOrder = config.getStringProperty(PropertyNames.PROPERTY_SCHEMA_GENERATE_DROP_ORDER);
String dropScript = config.getStringProperty(PropertyNames.PROPERTY_SCHEMA_GENERATE_SCRIPTS_DROP_SOURCE);
if (StringUtils.isWhitespace(dropScript)) {
dropScript = null;
}
if (StringUtils.isWhitespace(dropOrder)) {
dropOrder = (dropScript != null) ? "script" : "metadata";
} else {
if (dropOrder.equals("script") || dropOrder.equals("metadata-then-script") || dropOrder.equals("script-the-metadata")) {
if (dropScript == null) {
NucleusLogger.DATASTORE_SCHEMA.warn("drop order set to " + dropOrder + " but no script defined, so using metadata instead");
dropOrder = "metadata";
}
}
}
if (dropOrder.equals("script")) {
processDatastoreScript(dropScript);
} else if (dropOrder.equals("script-then-metadata")) {
processDatastoreScript(dropScript);
schemaTool.deleteSchemaForClasses(schemaStoreMgr, schemaClassNames);
} else if (dropOrder.equals("metadata-then-script")) {
schemaTool.deleteSchemaForClasses(schemaStoreMgr, schemaClassNames);
processDatastoreScript(dropScript);
} else {
schemaTool.deleteSchemaForClasses(schemaStoreMgr, schemaClassNames);
}
}
} else if (mode == Mode.DELETE_CREATE) {
if (generateScripts) {
// Generate the required scripts
schemaTool.setDdlFile(config.getStringProperty(PropertyNames.PROPERTY_SCHEMA_GENERATE_SCRIPTS_DROP_TARGET));
schemaTool.deleteSchemaForClasses(schemaStoreMgr, schemaClassNames);
schemaTool.setDdlFile(config.getStringProperty(PropertyNames.PROPERTY_SCHEMA_GENERATE_SCRIPTS_CREATE_TARGET));
schemaTool.createSchemaForClasses(schemaStoreMgr, schemaClassNames);
} else {
// Process the required metadata/scripts
String dropOrder = config.getStringProperty(PropertyNames.PROPERTY_SCHEMA_GENERATE_DROP_ORDER);
String dropScript = config.getStringProperty(PropertyNames.PROPERTY_SCHEMA_GENERATE_SCRIPTS_DROP_SOURCE);
if (StringUtils.isWhitespace(dropScript)) {
dropScript = null;
}
if (StringUtils.isWhitespace(dropOrder)) {
dropOrder = (dropScript != null) ? "script" : "metadata";
} else {
if (dropOrder.equals("script") || dropOrder.equals("metadata-then-script") || dropOrder.equals("script-the-metadata")) {
if (dropScript == null) {
NucleusLogger.DATASTORE_SCHEMA.warn("drop order set to " + dropOrder + " but no script defined, so using metadata instead");
dropOrder = "metadata";
}
}
}
if (dropOrder.equals("script")) {
processDatastoreScript(dropScript);
} else if (dropOrder.equals("script-then-metadata")) {
processDatastoreScript(dropScript);
schemaTool.deleteSchemaForClasses(schemaStoreMgr, schemaClassNames);
} else if (dropOrder.equals("metadata-then-script")) {
schemaTool.deleteSchemaForClasses(schemaStoreMgr, schemaClassNames);
processDatastoreScript(dropScript);
} else {
schemaTool.deleteSchemaForClasses(schemaStoreMgr, schemaClassNames);
}
String createOrder = config.getStringProperty(PropertyNames.PROPERTY_SCHEMA_GENERATE_CREATE_ORDER);
String createScript = config.getStringProperty(PropertyNames.PROPERTY_SCHEMA_GENERATE_SCRIPTS_CREATE_SOURCE);
if (StringUtils.isWhitespace(createScript)) {
createScript = null;
}
if (StringUtils.isWhitespace(createOrder)) {
createOrder = (createScript != null) ? "script" : "metadata";
} else {
if (createOrder.equals("script") || createOrder.equals("metadata-then-script") || createOrder.equals("script-the-metadata")) {
if (createScript == null) {
NucleusLogger.DATASTORE_SCHEMA.warn("create order set to " + createOrder + " but no script defined, so using metadata instead");
createOrder = "metadata";
}
}
}
if (createOrder.equals("script")) {
processDatastoreScript(createScript);
} else if (createOrder.equals("script-then-metadata")) {
processDatastoreScript(createScript);
schemaTool.createSchemaForClasses(schemaStoreMgr, schemaClassNames);
} else if (createOrder.equals("metadata-then-script")) {
schemaTool.createSchemaForClasses(schemaStoreMgr, schemaClassNames);
processDatastoreScript(createScript);
} else {
schemaTool.createSchemaForClasses(schemaStoreMgr, schemaClassNames);
}
}
}
String loadScript = config.getStringProperty(PropertyNames.PROPERTY_SCHEMA_GENERATE_SCRIPTS_LOAD_SOURCE);
if (!StringUtils.isWhitespace(loadScript)) {
String scriptContent = getDatastoreScriptForResourceName(loadScript);
if (storeMgr instanceof SchemaScriptAwareStoreManager && !StringUtils.isWhitespace(scriptContent)) {
((SchemaScriptAwareStoreManager) storeMgr).executeScript(scriptContent);
}
}
} else {
if (NucleusLogger.DATASTORE_SCHEMA.isDebugEnabled()) {
NucleusLogger.DATASTORE_SCHEMA.debug(Localiser.msg("008016", StringUtils.toJVMIDString(storeMgr)));
}
}
if (NucleusLogger.DATASTORE_SCHEMA.isDebugEnabled()) {
NucleusLogger.DATASTORE_SCHEMA.debug(Localiser.msg("014043"));
}
}
use of org.datanucleus.store.StoreManager in project datanucleus-core by datanucleus.
the class TypeManagerImpl method createSCOInstance.
/**
* Method to create a new SCO wrapper for member type.
* Will find a wrapper suitable for the instantiated type (if provided), otherwise suitable for the member metadata type.
* @param ownerOP ObjectProvider for the owning object
* @param mmd The MetaData for the related member.
* @param instantiatedType Type to instantiate the member as (if known), otherwise falls back to the type from metadata
* @return The wrapper object of the required type
* @throws NucleusUserException if an error occurred when creating the SCO instance
*/
private SCO createSCOInstance(ObjectProvider ownerOP, AbstractMemberMetaData mmd, Class instantiatedType) {
String typeName = (instantiatedType != null) ? instantiatedType.getName() : mmd.getTypeName();
// Find the SCO wrapper type most suitable
StoreManager storeMgr = ownerOP.getExecutionContext().getStoreManager();
boolean backedWrapper = storeMgr.useBackedSCOWrapperForMember(mmd, ownerOP.getExecutionContext());
Class wrapperType = null;
if (mmd.isSerialized()) {
// If we have all elements serialised into a column then cannot have backing stores
backedWrapper = false;
}
if (backedWrapper) {
wrapperType = getBackedWrapperTypeForType(mmd.getType(), instantiatedType, typeName);
} else {
wrapperType = getSimpleWrapperTypeForType(mmd.getType(), instantiatedType, typeName);
}
if (wrapperType == null) {
throw new NucleusUserException(Localiser.msg("023011", mmd.getTypeName(), typeName, mmd.getFullFieldName()));
}
// Create the SCO wrapper
try {
return (SCO) ClassUtils.newInstance(wrapperType, new Class[] { ObjectProvider.class, AbstractMemberMetaData.class }, new Object[] { ownerOP, mmd });
} catch (UnsupportedOperationException uoe) {
// Can't create backing store? so try simple wrapper
if (backedWrapper) {
NucleusLogger.PERSISTENCE.warn("Creation of backed wrapper for " + mmd.getFullFieldName() + " unsupported, so trying simple wrapper");
wrapperType = getSimpleWrapperTypeForType(mmd.getType(), instantiatedType, typeName);
return (SCO) ClassUtils.newInstance(wrapperType, new Class[] { ObjectProvider.class, AbstractMemberMetaData.class }, new Object[] { ownerOP, mmd });
}
throw uoe;
}
}
Aggregations