StringBuilder builder = new StringBuilder(); builder.append("CREATE TABLE "); builder.append(tableInfo.getTableName()); builder.append(Constants.OPEN_ROUND_BRACKET); if (!tableInfo.getTableIdType().isAnnotationPresent(Embeddable.class)) builder.append(tableInfo.getIdColumnName()); builder.append(Constants.SPACE); String idType = tableInfo.getTableIdType().getSimpleName().toLowerCase(); builder.append(OracleNoSQLValidationClassMapper.getValidIdType(idType)); builder.append(Constants.COMMA); for (ColumnInfo columnInfo : tableInfo.getColumnMetadatas()) builder.append(Constants.COMMA); for (EmbeddedColumnInfo embeddedColumnInfo : tableInfo.getEmbeddedColumnMetadatas()) if (tableInfo.getIdColumnName().equals(embeddedColumnInfo.getEmbeddedColumnName())) builder.append(Constants.OPEN_ROUND_BRACKET); if (!tableInfo.getTableIdType().isAnnotationPresent(Embeddable.class)) builder.append(tableInfo.getIdColumnName());
String id = CouchDBConstants.DESIGN + tableInfo.getTableName(); CouchDBDesignDocument designDocument = getDesignDocument(id); designDocument.setLanguage(CouchDBConstants.LANGUAGE); if (views == null) logger.warn("No view exist for table " + tableInfo.getTableName() + "so any query will not produce any result"); return; for (IndexInfo indexInfo : tableInfo.getColumnsToBeIndexed()) + tableInfo.getTableName() + "so any query on column " + indexInfo.getColumnName() + "will not produce any result"); if (views.get(tableInfo.getIdColumnName()) == null) logger.warn("No view exist for id column " + tableInfo.getIdColumnName() + " of table " + tableInfo.getTableName() + "so any query on id column " + tableInfo.getIdColumnName() + "will not produce any result"); logger.warn("No view exist for select all for table " + tableInfo.getTableName() + "so select all query will not produce any result");
/** * Checks if is counter column type. * * @param tableInfo * the table info * @param defaultValidationClass * the default validation class * @return true, if is counter column type */ private boolean isCounterColumnType(TableInfo tableInfo, String defaultValidationClass) { return (csmd != null && csmd.isCounterColumn(databaseName, tableInfo.getTableName())) || (defaultValidationClass != null && (defaultValidationClass.equalsIgnoreCase(CounterColumnType.class.getSimpleName()) || defaultValidationClass .equalsIgnoreCase(CounterColumnType.class.getName())) || (tableInfo.getType() .equals(CounterColumnType.class.getSimpleName()))); } }
/** * Drop inverted index table. * * @param tableInfo * the table info */ private void dropInvertedIndexTable(TableInfo tableInfo) { boolean indexTableRequired = CassandraPropertyReader.csmd.isInvertedIndexingEnabled(databaseName)/* ) */ && !tableInfo.getEmbeddedColumnMetadatas().isEmpty(); if (indexTableRequired) { try { cassandra_client.system_drop_column_family(tableInfo.getTableName() + Constants.INDEX_TABLE_SUFFIX); } catch (Exception ex) { if (log.isWarnEnabled()) { log.warn("Error while dropping inverted index table, Caused by: ", ex); } } } }
/** * @param tableInfo * @return */ private DBObject setCollectionProperties(TableInfo tableInfo) { boolean isCappedCollection = isCappedCollection(tableInfo); DBObject options = new BasicDBObject(); if ((tableInfo.getLobColumnInfo().isEmpty() || tableInfo.getLobColumnInfo() == null) && isCappedCollection) { int collectionSize = MongoDBPropertyReader.msmd != null ? MongoDBPropertyReader.msmd.getCollectionSize( databaseName, tableInfo.getTableName()) : 100000; int max = MongoDBPropertyReader.msmd != null ? MongoDBPropertyReader.msmd.getMaxSize(databaseName, tableInfo.getTableName()) : 100; options.put(MongoDBConstants.CAPPED, isCappedCollection); options.put(MongoDBConstants.SIZE, collectionSize); options.put(MongoDBConstants.MAX, max); } return options; }
private HColumnDescriptor getColumnDescriptor(TableInfo tableInfo) { HColumnDescriptor hColumnDescriptor = new HColumnDescriptor(tableInfo.getTableName()); setColumnFamilyProperties(hColumnDescriptor, tableInfo.getTableName()); return hColumnDescriptor; }
DB db = mongo.getDB(databaseName); DBCollection collection = null; if (tableInfo.getLobColumnInfo().isEmpty()) if (!db.collectionExists(tableInfo.getTableName())) collection = db.createCollection(tableInfo.getTableName(), options); KunderaCoreUtils.printQuery("Create collection: " + tableInfo.getTableName(), showQuery); collection = collection != null ? collection : db.getCollection(tableInfo.getTableName()); if (!db.collectionExists(tableInfo.getTableName() + MongoDBUtils.FILES)) coll = db.createCollection(tableInfo.getTableName() + MongoDBUtils.FILES, options); createUniqueIndexGFS(coll, tableInfo.getIdColumnName()); KunderaCoreUtils.printQuery("Create collection: " + tableInfo.getTableName() + MongoDBUtils.FILES, showQuery); if (!db.collectionExists(tableInfo.getTableName() + MongoDBUtils.CHUNKS)) db.createCollection(tableInfo.getTableName() + MongoDBUtils.CHUNKS, options); KunderaCoreUtils.printQuery("Create collection: " + tableInfo.getTableName() + MongoDBUtils.CHUNKS, showQuery);
if (cfDef.getName().equals(tableInfo.getTableName()) && cfDef.getColumn_type().equals(ColumnFamilyType.getInstanceOf(tableInfo.getType()).name())) for (ColumnInfo columnInfo : tableInfo.getColumnMetadatas())
indexInfo.setMinValue(1); TableInfo tableInfo = new TableInfo("table1", "column family", String.class, "address_id"); tableInfo.addColumnInfo(columnInfo); tableInfo.addToIndexedColumnList(indexInfo); Assert.assertNotNull(tableInfo.getColumnMetadatas()); Assert.assertEquals("address_id",tableInfo.getIdColumnName()); Assert.assertEquals(String.class,tableInfo.getTableIdType()); Assert.assertEquals("column family", tableInfo.getType()); Assert.assertNotNull(tableInfo.toString());
if (!client.tableExists(tableInfo.getTableName())) KuduTable table = client.openTable(tableInfo.getTableName()); AlterTableOptions alterTableOptions = new AlterTableOptions(); AtomicBoolean updated = new AtomicBoolean(false); Schema schema = table.getSchema(); for (ColumnInfo columnInfo : tableInfo.getColumnMetadatas()) for (EmbeddedColumnInfo embColumnInfo : tableInfo.getEmbeddedColumnMetadatas()) client.alterTable(tableInfo.getTableName(), alterTableOptions);
for (EmbeddedColumnInfo embeddedColumnInfo : tableInfo.getEmbeddedColumnMetadatas()) indexQueryBuilder.append(tableInfo.getTableName()); indexQueryBuilder.append("\"(\"$COLUMN_NAME\")"); tableInfo.getColumnsToBeIndexed(); for (IndexInfo indexInfo : tableInfo.getColumnsToBeIndexed()) indexInfo.getColumnName(), tableInfo.getTableName(), ire); throw new SchemaGenerationException("Error occurred while creating indexes on column " + indexInfo.getColumnName() + " of table " + tableInfo.getTableName(), ire, "Cassandra", databaseName);
for (CfDef cfDef : ksDef.getCf_defs()) if (cfDef.getName().equals(tableInfo.getTableName())/* for (ColumnInfo columnInfo : tableInfo.getColumnMetadatas()) throw new SchemaGenerationException("Column family " + tableInfo.getTableName() + " does not exist in keyspace " + databaseName + "", "Cassandra", databaseName, tableInfo.getTableName());
/** * @param tableInfo * @return CfDef object */ private CfDef getTableMetadata(TableInfo tableInfo) { CfDef cfDef = new CfDef(); cfDef.setKeyspace(databaseName); cfDef.setName(tableInfo.getTableName()); cfDef.setKey_validation_class(CassandraValidationClassMapper.getValidationClass(tableInfo.getTableIdType(), isCql3Enabled(tableInfo))); Schema schema = CassandraPropertyReader.csmd.getSchema(databaseName); tables = schema != null ? schema.getTables() : null; Properties cfProperties = getColumnFamilyProperties(tableInfo); String defaultValidationClass = null; if (tableInfo.getType() != null && tableInfo.getType().equals(Type.SUPER_COLUMN_FAMILY.name())) { getSuperColumnFamilyMetadata(tableInfo, cfDef, defaultValidationClass); } else if (tableInfo.getType() != null) { getColumnFamilyMetadata(tableInfo, cfDef, cfProperties); } setColumnFamilyProperties(cfDef, cfProperties, null); return cfDef; }
EntityMetadata m) if (!joinColumn.equals(targetTableInfo.getIdColumnName())) ColumnInfo columnInfoOfJoinColumn = getJoinColumn(targetTableInfo, joinColumn, m.getIdAttribute().getBindableJavaType()); if (!targetTableInfo.getColumnMetadatas().contains(columnInfoOfJoinColumn)) targetTableInfo.addColumnInfo(columnInfoOfJoinColumn); if (!targetTableInfo.getColumnMetadatas().contains(columnInfoOfJoinColumn)) targetTableInfo.addColumnInfo(columnInfoOfJoinColumn);
/** * Creates the index on table. * * @param tableInfo * the table info */ private void createIndexOnTable(TableInfo tableInfo) { List<IndexInfo> indexColumns = tableInfo.getColumnsToBeIndexed(); for (IndexInfo indexInfo : indexColumns) { if (indexInfo.getIndexType() != null && indexInfo.getIndexType().toLowerCase().equals(Constants.COMPOSITE)) { String[] columnNames = indexInfo.getColumnName().split(Constants.COMMA); createIndex(tableInfo.getTableName(), indexInfo.getIndexName(), columnNames); } else { createIndex(tableInfo.getTableName(), indexInfo.getIndexName(), indexInfo.getColumnName()); } } }
public static boolean createIfNeedColumn(Class<? extends Model> type, String column) { boolean isFound = false; TableInfo tableInfo = new TableInfo(type); Collection<Field> columns = tableInfo.getFields(); for (Field f : columns) { if (column.equals(f.getName())) { isFound = true; break; } } if (!isFound) { ActiveAndroid.execSQL("ALTER TABLE " + tableInfo.getTableName() + " ADD COLUMN " + column + " TEXT;"); } return isFound; }
tableInfo.addToIndexedColumnList(indexInfo); attr.getJavaType(), ((Field) ((Field) attr.getJavaMember()))); if (!tableInfo.getEmbeddedColumnMetadatas().contains(embeddedColumnInfo)) tableInfo.addEmbeddedColumnInfo(embeddedColumnInfo); tableInfo.addLobColumnInfo(((AbstractAttribute) attr).getJPAColumnName()); if (!tableInfo.getColumnMetadatas().contains(columnInfo)) tableInfo.addColumnInfo(columnInfo); cci.setGenericClasses(PropertyAccessorHelper.getGenericClasses((Field) attr.getJavaMember())); tableInfo.addCollectionColumnMetadata(cci); tableInfo.addToIndexedColumnList(indexInfo); eci.setGenericClasses(PropertyAccessorHelper.getGenericClasses((Field) attr.getJavaMember())); tableInfo.addElementCollectionMetadata(eci); tableInfo.addToIndexedColumnList(indexInfo);
/** * @param tableInfo * @param collection */ private void createIndexes(TableInfo tableInfo, DBCollection collection) { // index normal column for (ColumnInfo columnInfo : tableInfo.getColumnMetadatas()) { if (columnInfo.isIndexable()) { IndexInfo indexInfo = tableInfo.getColumnToBeIndexed(columnInfo.getColumnName()); indexColumn(indexInfo, collection); } } // index embedded column. for (EmbeddedColumnInfo info : tableInfo.getEmbeddedColumnMetadatas()) { for (ColumnInfo columnInfo : info.getColumns()) { if (columnInfo.isIndexable()) { IndexInfo indexInfo = tableInfo.getColumnToBeIndexed(columnInfo.getColumnName()); indexEmbeddedColumn(indexInfo, info.getEmbeddedColumnName(), collection); } } } }
.getTableName()).getBytes()); boolean columnFamilyFound = false; Boolean f = false; && columnDescriptor.getNameAsString().equalsIgnoreCase(tableInfo.getTableName())) for (CollectionColumnInfo cci : tableInfo.getCollectionColumnMetadatas()) throw new SchemaGenerationException("column " + tableInfo.getTableName() + " does not exist in table " + databaseName + "", "Hbase", databaseName, tableInfo.getTableName());
List<ColumnInfo> columnInfos = tableInfo.getColumnMetadatas(); if (columnInfos != null) if (columnInfo.isIndexable()) IndexInfo indexInfo = tableInfo.getColumnToBeIndexed(columnInfo.getColumnName()); columnDef.setIndex_type(CassandraIndexHelper.getIndexType(indexInfo.getIndexType()));