use of org.datanucleus.store.StoreData in project datanucleus-core by datanucleus.
the class MetaDataAutoStarter method getAllClassData.
/**
* Accessor for all auto start data for this starter.
* @return The class auto start data. Collection of StoreData elements
* @throws org.datanucleus.exceptions.DatastoreInitialisationException If an error occurs in datastore init
*/
public Collection<StoreData> getAllClassData() throws DatastoreInitialisationException {
if (metaDataFiles == null) {
return Collections.EMPTY_SET;
}
Collection<FileMetaData> fileMetaData = storeMgr.getNucleusContext().getMetaDataManager().loadFiles(metaDataFiles.split(","), clr);
Iterator<FileMetaData> iter = fileMetaData.iterator();
while (iter.hasNext()) {
FileMetaData filemd = iter.next();
for (int i = 0; i < filemd.getNoOfPackages(); i++) {
PackageMetaData pmd = filemd.getPackage(i);
for (int j = 0; j < pmd.getNoOfClasses(); j++) {
ClassMetaData cmd = pmd.getClass(j);
classes.add(new StoreData(cmd.getFullClassName().trim(), null, StoreData.Type.FCO, null));
}
}
}
return classes;
}
use of org.datanucleus.store.StoreData in project datanucleus-rdbms by datanucleus.
the class RDBMSStoreManager method getDatastoreClass.
/**
* Returns the primary datastore table serving as backing for the given class.
* If the class is not yet known to the store manager, {@link #manageClasses} is called
* to add it. Classes which have inheritance strategy of "new-table" and
* "superclass-table" will return a table here, whereas "subclass-table" will
* return null since it doesn't have a table as such.
* <p>
* @param className Name of the class whose table is be returned.
* @param clr The ClassLoaderResolver
* @return The corresponding class table.
* @exception NoTableManagedException If the given class has no table managed in the database.
*/
public DatastoreClass getDatastoreClass(String className, ClassLoaderResolver clr) {
DatastoreClass ct = null;
if (className == null) {
NucleusLogger.PERSISTENCE.error(Localiser.msg("032015"));
return null;
}
schemaLock.readLock().lock();
try {
StoreData sd = storeDataMgr.get(className);
if (sd != null && sd instanceof RDBMSStoreData) {
ct = (DatastoreClass) sd.getTable();
if (ct != null) {
// Class known about
return ct;
}
}
} finally {
schemaLock.readLock().unlock();
}
// Class not known so consider adding it to our list of supported classes.
// Currently we only consider PC classes
boolean toBeAdded = false;
if (clr != null) {
Class cls = clr.classForName(className);
ApiAdapter api = getApiAdapter();
if (cls != null && !cls.isInterface() && api.isPersistable(cls)) {
toBeAdded = true;
}
} else {
toBeAdded = true;
}
boolean classKnown = false;
if (toBeAdded) {
// Add the class to our supported list
manageClasses(clr, className);
// Retry
schemaLock.readLock().lock();
try {
StoreData sd = storeDataMgr.get(className);
if (sd != null && sd instanceof RDBMSStoreData) {
classKnown = true;
ct = (DatastoreClass) sd.getTable();
}
} finally {
schemaLock.readLock().unlock();
}
}
// Note : "subclass-table" inheritance strategies will return null from this method
if (!classKnown && ct == null) {
throw new NoTableManagedException(className);
}
return ct;
}
use of org.datanucleus.store.StoreData in project datanucleus-rdbms by datanucleus.
the class RDBMSStoreManager method getManagedTables.
/**
* Convenience accessor of the Table objects managed in this datastore at this point.
* @param catalog Name of the catalog to restrict the collection by (or null to not restrict)
* @param schema Name of the schema to restrict the collection by (or null to not restrict)
* @return Collection of tables
*/
public Collection<Table> getManagedTables(String catalog, String schema) {
if (storeDataMgr == null) {
return Collections.EMPTY_SET;
}
Collection<Table> tables = new HashSet<>();
for (StoreData sd : storeDataMgr.getManagedStoreData()) {
if (sd.getTable() != null) {
// Catalog/Schema match if either managed table not set, or input requirements not set
DatastoreIdentifier identifier = ((Table) sd.getTable()).getIdentifier();
boolean catalogMatches = true;
boolean schemaMatches = true;
if (catalog != null && identifier.getCatalogName() != null && !catalog.equals(identifier.getCatalogName())) {
catalogMatches = false;
}
if (schema != null && identifier.getSchemaName() != null && !schema.equals(identifier.getSchemaName())) {
schemaMatches = false;
}
if (catalogMatches && schemaMatches) {
tables.add((Table) sd.getTable());
}
}
}
return tables;
}
use of org.datanucleus.store.StoreData in project datanucleus-rdbms by datanucleus.
the class SchemaTable method getAllClasses.
/**
* Accessor for the classes already supported by this Schema Table.
* @param conn Connection for this datastore.
* @return The HashSet of class names (StoreData)
* @throws SQLException Thrown when an error occurs in the process.
*/
public HashSet getAllClasses(ManagedConnection conn) throws SQLException {
HashSet schema_data = new HashSet();
if (storeMgr.getDdlWriter() != null && !tableExists((Connection) conn.getConnection())) {
// do not query non-existing schema table when DDL is only written to file
return schema_data;
}
SQLController sqlControl = storeMgr.getSQLController();
PreparedStatement ps = sqlControl.getStatementForQuery(conn, fetchAllStmt);
try {
ResultSet rs = sqlControl.executeStatementQuery(null, conn, fetchAllStmt, ps);
try {
while (rs.next()) {
StoreData data = new RDBMSStoreData(rs.getString(1), rs.getString(2), rs.getString(4).equals("1") ? true : false, rs.getString(3).equals("FCO") ? StoreData.Type.FCO : StoreData.Type.SCO, rs.getString(6));
schema_data.add(data);
}
} finally {
rs.close();
}
} finally {
sqlControl.closeStatement(conn, ps);
}
return schema_data;
}
use of org.datanucleus.store.StoreData in project datanucleus-core by datanucleus.
the class ClassesAutoStarter method getAllClassData.
/**
* Accessor for all auto start data for this starter.
* @return The class auto start data. Collection of StoreData elements
* @throws DatastoreInitialisationException If an error occurs in datastore init
*/
public Collection<StoreData> getAllClassData() throws DatastoreInitialisationException {
Collection<StoreData> classes = new HashSet<>();
if (classNames == null) {
return classes;
}
StringTokenizer tokeniser = new StringTokenizer(classNames, ",");
while (tokeniser.hasMoreTokens()) {
classes.add(new StoreData(tokeniser.nextToken().trim(), null, StoreData.Type.FCO, null));
}
return classes;
}
Aggregations