* The SchemaWriter's {@code write()} call is made after calling this method.
*/
private void createSchema(final ClassMetaData cmd, Class cls, final ClassLoaderResolver clr, ForceStoreManager storeManager) {
synchronized (cmd) {
ForceManagedConnection mconn = storeManager.createConnection();
TableImpl table = storeManager.getTable(cmd);
if (PersistenceUtils.hasNoSchema(cmd)) return; //nothing to create
// only create the table if autoCreateTables is true.
// create the fields without creating the table if the object is already in the organization
if (storeManager.isAutoCreateTables() && (!table.getTableAlreadyExistsInOrg()
|| storeManager.isForDelete()) && !PersistenceUtils.isReadOnlySchema(cmd, true)) {
table.createTableAndFields(cmd, storeManager, mconn);
} else if (table.getTableAlreadyExistsInOrg() && !PersistenceUtils.isReadOnlySchema(cmd, false)) {
table.createFields(cmd, storeManager);
}
// handle the case where autoCreateTables is disabled but the object does not exist in the organization
if (!storeManager.isAutoCreateTables() && !table.getTableAlreadyExistsInOrg()) {
StringBuilder msg = new StringBuilder(256);
msg.append("Table does not exist in force.com and datanucleus.autoCreateTables is false, table: ")
.append(table.getTableName().getForceApiName());
if (storeManager.isAutoCreateWarnOnError()) {
LOGGER.warn(msg.toString());
} else {
throw new NucleusUserException(msg.toString());
}