Search in sources :

Example 1 with StoreData

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;
}
Also used : PackageMetaData(org.datanucleus.metadata.PackageMetaData) FileMetaData(org.datanucleus.metadata.FileMetaData) ClassMetaData(org.datanucleus.metadata.ClassMetaData) StoreData(org.datanucleus.store.StoreData)

Example 2 with StoreData

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;
}
Also used : ApiAdapter(org.datanucleus.api.ApiAdapter) DatastoreClass(org.datanucleus.store.rdbms.table.DatastoreClass) DatastoreClass(org.datanucleus.store.rdbms.table.DatastoreClass) NoTableManagedException(org.datanucleus.store.rdbms.exceptions.NoTableManagedException) StoreData(org.datanucleus.store.StoreData)

Example 3 with StoreData

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;
}
Also used : Table(org.datanucleus.store.rdbms.table.Table) ProbeTable(org.datanucleus.store.rdbms.table.ProbeTable) JoinTable(org.datanucleus.store.rdbms.table.JoinTable) ClassTable(org.datanucleus.store.rdbms.table.ClassTable) MapTable(org.datanucleus.store.rdbms.table.MapTable) PersistableJoinTable(org.datanucleus.store.rdbms.table.PersistableJoinTable) ArrayTable(org.datanucleus.store.rdbms.table.ArrayTable) CollectionTable(org.datanucleus.store.rdbms.table.CollectionTable) SequenceTable(org.datanucleus.store.rdbms.valuegenerator.SequenceTable) DatastoreIdentifier(org.datanucleus.store.rdbms.identifier.DatastoreIdentifier) HashSet(java.util.HashSet) StoreData(org.datanucleus.store.StoreData)

Example 4 with StoreData

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;
}
Also used : RDBMSStoreData(org.datanucleus.store.rdbms.RDBMSStoreData) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) HashSet(java.util.HashSet) SQLController(org.datanucleus.store.rdbms.SQLController) RDBMSStoreData(org.datanucleus.store.rdbms.RDBMSStoreData) StoreData(org.datanucleus.store.StoreData)

Example 5 with StoreData

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;
}
Also used : StringTokenizer(java.util.StringTokenizer) StoreData(org.datanucleus.store.StoreData) HashSet(java.util.HashSet)

Aggregations

StoreData (org.datanucleus.store.StoreData)7 HashSet (java.util.HashSet)4 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Iterator (java.util.Iterator)1 List (java.util.List)1 StringTokenizer (java.util.StringTokenizer)1 NamingException (javax.naming.NamingException)1 ApiAdapter (org.datanucleus.api.ApiAdapter)1 ClassNotResolvedException (org.datanucleus.exceptions.ClassNotResolvedException)1 DatastoreInitialisationException (org.datanucleus.exceptions.DatastoreInitialisationException)1 NucleusException (org.datanucleus.exceptions.NucleusException)1 NucleusUserException (org.datanucleus.exceptions.NucleusUserException)1 AbstractClassMetaData (org.datanucleus.metadata.AbstractClassMetaData)1 ClassMetaData (org.datanucleus.metadata.ClassMetaData)1 FileMetaData (org.datanucleus.metadata.FileMetaData)1